mirror of
https://github.com/Intervention/image.git
synced 2025-08-23 05:52:47 +02:00
Add font processor tests
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
BIN
tests/resources/test.ttf
Normal file
BIN
tests/resources/test.ttf
Normal file
Binary file not shown.
Reference in New Issue
Block a user