meyfa / php-svg

Vector graphics (SVG) library for PHP
https://packagist.org/packages/meyfa/php-svg
MIT License
509 stars 91 forks source link

Rendering 'italic' or 'oblique' text misses fonts with 'Oblique' subfamily #235

Closed Tontyna closed 3 months ago

Tontyna commented 3 months ago

When TextRenderer.prepareRenderParams() sees a fontStyle of italic or oblique the FontRegistry only looks for a TrueTypeFontFile where isItalic() is True, i.e. whre the subfamily is 'Italic'.

So cursive fonts like DejaVuSans-Oblique.ttf or DejaVuSans-BoldOblique.ttf are not detected and the text is rendered 'normal'.

The spec says, that 'italic' should fall back to an 'oblique' font and 'oblique' should fall back to an 'italic' one. Not talking about creating an artficially cursive simulation,

I think a TrueTypeFontFile->isOblique() function should be introduced and FontRegistry.findMatchingFont() should look for the fallback. Of course, its bool $italic parameter has to be adapted accordingly.

Tontyna commented 3 months ago

And TrueTypeFontFile->getWeight() should check for $this->subfamily === 'Bold Oblique', too.

meyfa commented 3 months ago

I suppose you are referring to the following part of the CSS specification: https://www.w3.org/TR/css-fonts-4/#font-style-prop

The implementation you describe sounds reasonable to me. Would you like to send a pull request with those changes? :)

Tontyna commented 3 months ago

PR in preparation ...