|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SixtyNine\Cloud\Tests\Builder; |
|
4
|
|
|
|
|
5
|
|
|
use SixtyNine\Cloud\Factory\FontsFactory; |
|
6
|
|
|
use SixtyNine\Cloud\FontMetrics; |
|
7
|
|
|
|
|
8
|
|
|
class FontMetricsTest extends \PHPUnit_Framework_TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
public function testMetricsHorizontal() |
|
11
|
|
|
{ |
|
12
|
|
|
$factory = FontsFactory::create(__DIR__ . '/fixtures/fonts'); |
|
13
|
|
|
$calc = new FontMetrics($factory); |
|
14
|
|
|
|
|
15
|
|
|
$size1 = $calc->calculateSize('abc', 'Arial.ttf', 10); |
|
16
|
|
|
$size2 = $calc->calculateSize('abc', 'Arial.ttf', 12); |
|
17
|
|
|
$size3 = $calc->calculateSize('abc', 'Arial.ttf', 1); |
|
18
|
|
|
$size4 = $calc->calculateSize('a', 'Arial.ttf', 1); |
|
19
|
|
|
|
|
20
|
|
|
$this->assertTrue($size1->getWidth() < $size2->getWidth()); |
|
21
|
|
|
$this->assertTrue($size1->getHeight() < $size2->getHeight()); |
|
22
|
|
|
$this->assertTrue($size3->getWidth() < $size1->getWidth()); |
|
23
|
|
|
$this->assertTrue($size3->getHeight() < $size1->getHeight()); |
|
24
|
|
|
$this->assertTrue($size4->getWidth() < $size3->getWidth()); |
|
25
|
|
|
$this->assertEquals($size4->getHeight(), $size3->getHeight()); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testMetricsVertical() |
|
29
|
|
|
{ |
|
30
|
|
|
$factory = FontsFactory::create(__DIR__ . '/fixtures/fonts'); |
|
31
|
|
|
$calc = new FontMetrics($factory); |
|
32
|
|
|
|
|
33
|
|
|
$size1 = $calc->calculateSize('abc', 'Arial.ttf', 10, 270); |
|
34
|
|
|
$size2 = $calc->calculateSize('abc', 'Arial.ttf', 12, 270); |
|
35
|
|
|
$size3 = $calc->calculateSize('abc', 'Arial.ttf', 1, 270); |
|
36
|
|
|
$size4 = $calc->calculateSize('a', 'Arial.ttf', 1, 270); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertTrue($size1->getWidth() < $size2->getWidth()); |
|
39
|
|
|
$this->assertTrue($size1->getHeight() < $size2->getHeight()); |
|
40
|
|
|
$this->assertTrue($size3->getWidth() < $size1->getWidth()); |
|
41
|
|
|
$this->assertTrue($size3->getHeight() < $size1->getHeight()); |
|
42
|
|
|
$this->assertEquals($size4->getWidth(), $size3->getWidth()); |
|
43
|
|
|
$this->assertTrue($size4->getHeight() < $size3->getHeight()); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testLoadSingleFont() |
|
47
|
|
|
{ |
|
48
|
|
|
$factory = FontsFactory::create(__DIR__ . '/fixtures/fonts/Arial.ttf', false); |
|
49
|
|
|
$calc = new FontMetrics($factory); |
|
50
|
|
|
$size1 = $calc->calculateSize('abc', 'Arial.ttf', 10, 270); |
|
51
|
|
|
$size2 = $calc->calculateSize('abc', 'Arial.ttf', 12, 270); |
|
52
|
|
|
$this->assertTrue($size1->getWidth() < $size2->getWidth()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testLoadMultipleFonts() |
|
56
|
|
|
{ |
|
57
|
|
|
$factory = FontsFactory::create([__DIR__ . '/fixtures/fonts/Arial.ttf'], false); |
|
|
|
|
|
|
58
|
|
|
$calc = new FontMetrics($factory); |
|
59
|
|
|
$size1 = $calc->calculateSize('abc', 'Arial.ttf', 10, 270); |
|
60
|
|
|
$size2 = $calc->calculateSize('abc', 'Arial.ttf', 12, 270); |
|
61
|
|
|
$this->assertTrue($size1->getWidth() < $size2->getWidth()); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: