1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-01 03:20:17 +02:00

Reduce the differences in text rendering with drivers

Reduce the differences in text rendering with drivers
This commit is contained in:
Oliver Vogel
2024-02-03 15:56:22 +01:00
parent 684f5e6eb6
commit 795b794ee8
4 changed files with 23 additions and 13 deletions

View File

@@ -45,6 +45,16 @@ abstract class AbstractFontProcessor implements FontProcessorInterface
return $lines;
}
/**
* {@inheritdoc}
*
* @see FontProcessorInterface::nativeFontSize()
*/
public function nativeFontSize(FontInterface $font): float
{
return $font->size();
}
/**
* {@inheritdoc}
*

View File

@@ -57,7 +57,17 @@ class FontProcessor extends AbstractFontProcessor
*/
public function nativeFontSize(FontInterface $font): float
{
return floatval(ceil($font->size() * .75));
return floatval(round($font->size() * .76, 6));
}
/**
* {@inheritdoc}
*
* @see FontProcessorInterface::leading()
*/
public function leading(FontInterface $font): int
{
return (int) round(parent::leading($font) * .8);
}
/**

View File

@@ -40,16 +40,6 @@ class FontProcessor extends AbstractFontProcessor
);
}
/**
* {@inheritdoc}
*
* @see FontProcessorInterface::nativeFontSize()
*/
public function nativeFontSize(FontInterface $font): float
{
return $font->size();
}
/**
* Imagick::annotateImage() needs an ImagickDraw object - this method takes
* the font object as the base and adds an optional passed color to the new

View File

@@ -62,7 +62,7 @@ class FontProcessorTest extends TestCase
{
$processor = new FontProcessor();
$size = $processor->nativeFontSize(new Font('5'));
$this->assertEquals(9.0, $size);
$this->assertEquals(9.12, $size);
}
public function testTextBlock(): void
@@ -90,6 +90,6 @@ class FontProcessorTest extends TestCase
{
$processor = new FontProcessor();
$result = $processor->leading(new Font());
$this->assertEquals(10, $result);
$this->assertEquals(8, $result);
}
}