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 00000000..330e9198 Binary files /dev/null and b/tests/resources/test.ttf differ