php-svg-lib
php-svg-lib copied to clipboard
Improve support for custom fonts
Currently, in order to specify a custom font you have to:
- specify the path to the font file (using "/" for directory separators) without the file extension
- the font-family must be specified without quotes
- specify only a single font
- the font must be hosted on the same filesystem as the the current working directory
For example, if the DejaVu Sans font file can be found under fonts/DejaVuSans.ttf then the following must be used to select the font:
<svg width="200" height="200"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<style>
.text {
font-family: fonts/DejaVuSans;
}
</style>
<text class="text" x="100" y="100">php-svg-lib</text>
</svg>
There are a few reasons for this requirement:
- This library has no font manager, meaning that font names are not translated to a font file (as required by the PDF backend). So the font-family value must specify the file.
- CSS value lists are generally not supported and so fallback values in the font-family are interpreted as part of the font name (e.g.
font-family: DejaVu Sans, sans-serifwill cause this library to look for a file named "DejaVu Sans, san-serif.ttf"). - CSS strings are not supported, so if the font-family value is quoted then the quotes are interpreted as part of the font name.