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:
@@ -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}
|
||||
*
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user