From 159fba56626c14106be835eaa1763fc6385e96e4 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sun, 10 Mar 2024 11:04:15 +0100 Subject: [PATCH] Add font processor tests --- tests/Unit/Drivers/Gd/FontProcessorTest.php | 49 ++++++++++++++++++ .../Drivers/Imagick/FontProcessorTest.php | 49 ++++++++++++++++++ tests/resources/test.ttf | Bin 0 -> 1956 bytes 3 files changed, 98 insertions(+) create mode 100644 tests/resources/test.ttf diff --git a/tests/Unit/Drivers/Gd/FontProcessorTest.php b/tests/Unit/Drivers/Gd/FontProcessorTest.php index a5bcaa47..977146b5 100644 --- a/tests/Unit/Drivers/Gd/FontProcessorTest.php +++ b/tests/Unit/Drivers/Gd/FontProcessorTest.php @@ -58,6 +58,15 @@ final class FontProcessorTest extends BaseTestCase $this->assertEquals(16, $size->height()); } + public function testBoxSizeTtf(): void + { + $processor = new FontProcessor(); + $size = $processor->boxSize('ABC', new Font($this->getTestResourcePath('test.ttf'))); + $this->assertInstanceOf(SizeInterface::class, $size); + $this->assertEquals(17, $size->width()); + $this->assertEquals(4, $size->height()); + } + public function testNativeFontSize(): void { $processor = new FontProcessor(); @@ -92,4 +101,44 @@ final class FontProcessorTest extends BaseTestCase $result = $processor->leading(new Font()); $this->assertEquals(8, $result); } + + public function testNativeFontSizeTtf(): void + { + $processor = new FontProcessor(); + $size = $processor->nativeFontSize($this->testFont()); + $this->assertEquals(9.12, $size); + } + + public function testTextBlockTtf(): void + { + $processor = new FontProcessor(); + $result = $processor->textBlock('test', $this->testFont(), new Point(0, 0)); + $this->assertInstanceOf(TextBlock::class, $result); + } + + public function testTypographicalSizeTtf(): void + { + $processor = new FontProcessor(); + $result = $processor->typographicalSize($this->testFont()); + $this->assertEquals(10, $result); + } + + public function testCapHeightTtf(): void + { + $processor = new FontProcessor(); + $result = $processor->capHeight($this->testFont()); + $this->assertEquals(10, $result); + } + + public function testLeadingTtf(): void + { + $processor = new FontProcessor(); + $result = $processor->leading($this->testFont()); + $this->assertEquals(10, $result); + } + + private function testFont(): Font + { + return new Font($this->getTestResourcePath('test.ttf')); + } } diff --git a/tests/Unit/Drivers/Imagick/FontProcessorTest.php b/tests/Unit/Drivers/Imagick/FontProcessorTest.php index 7feb5c90..063dc973 100644 --- a/tests/Unit/Drivers/Imagick/FontProcessorTest.php +++ b/tests/Unit/Drivers/Imagick/FontProcessorTest.php @@ -5,11 +5,23 @@ declare(strict_types=1); namespace Intervention\Image\Tests\Unit\Drivers\Imagick; use Intervention\Image\Drivers\Imagick\FontProcessor; +use Intervention\Image\Geometry\Point; +use Intervention\Image\Interfaces\SizeInterface; use Intervention\Image\Tests\BaseTestCase; use Intervention\Image\Typography\Font; +use Intervention\Image\Typography\TextBlock; final class FontProcessorTest extends BaseTestCase { + public function testBoxSizeTtf(): void + { + $processor = new FontProcessor(); + $size = $processor->boxSize('ABC', $this->testFont()); + $this->assertInstanceOf(SizeInterface::class, $size); + $this->assertEquals(16, $size->width()); + $this->assertEquals(7, $size->height()); + } + public function testNativeFontSize(): void { $processor = new FontProcessor(); @@ -18,4 +30,41 @@ final class FontProcessorTest extends BaseTestCase $size = $processor->nativeFontSize($font); $this->assertEquals(14.2, $size); } + + public function testTextBlock(): void + { + $processor = new FontProcessor(); + $result = $processor->textBlock( + 'test', + $this->testFont(), + new Point(0, 0), + ); + $this->assertInstanceOf(TextBlock::class, $result); + } + + public function testTypographicalSize(): void + { + $processor = new FontProcessor(); + $result = $processor->typographicalSize($this->testFont()); + $this->assertEquals(7, $result); + } + + public function testCapHeight(): void + { + $processor = new FontProcessor(); + $result = $processor->capHeight($this->testFont()); + $this->assertEquals(7, $result); + } + + public function testLeading(): void + { + $processor = new FontProcessor(); + $result = $processor->leading($this->testFont()); + $this->assertEquals(9, $result); + } + + private function testFont(): Font + { + return new Font($this->getTestResourcePath('test.ttf')); + } } diff --git a/tests/resources/test.ttf b/tests/resources/test.ttf new file mode 100644 index 0000000000000000000000000000000000000000..330e9198205ca70acdee7c9c24a914f309f72ef0 GIT binary patch literal 1956 zcmdUwO-vI(6vzLw+jjYuDxzo)D*{myP%09G955=j2uez02qDOV{U9l&fr6kH4;~ER zK#U}43@2l}=}i+aCSJUlcreirqX}LbPhRw3l=`3D;X@Q8+U+6gOkInSo14JkF-u^)=G9lv zv=>jQ`w~O_7W#0P_6MjJ4_f0XoI?@cOMhn48jM_f_i8)ezh;T1hDOrxqm|>!_eUV- z#xnUN(0yrJ<5%SC8Ma_yhv{3Xv)@HVFQuLXO}0{Kqnla!(CC|L#`Yv}NesKiK)$k( zmcnjpQeAX0E2iP5k4fzr+oqgad_=8S8b@{g-FqhmO)zoFiGi_s*ip^}Vp{aDG9eg~ zEuxLpOD9q>16|y=o4JN^9pO{HTd7G8KDf9pa;{6WLCJ!M@w^ zfnZB~Q@((5F}Jc|+;3;|1iUz;SYyPkigoP8lwudkcru;-Zf4A)Vh?r+zhY*-IIlQ| z99Eo5?oymb?p2&mmNS%6Ku#zwBo8YtB9ALBhIcuBFAVWqX09uj)^f!i7AWVLa9HDg z(5P5PJ;I7zya^sEcC+_4#U9i!iyd17nrKnX^B~$4=aMff&Lej#=4lswiVMhb#f9Xg z;v#ZdaWVJes$wsS#ABF{{~(e`BZ6U!@hN!#L#$0kAHfK91e58=@K_|79vDiR;Rr7_ zg!nFoQ6yl|5}`xEU{s9!r>@d5w< literal 0 HcmV?d00001