-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
External fonts not working for text object #171
Milestone
Comments
meyfa
added a commit
that referenced
this issue
Dec 28, 2022
Fixes #82, #168, #171. This patch removes the artificial `SVGFont` class as well as the `SVGText::setFont(SVGFont $font)` method. Instead, it is now possible to register TrueType (`.ttf`) font files by calling `SVG::addFont()` with a file path. A TrueType font file parser is implemented based on Microsoft's OpenType specification. This allows us to choose the best matching font file for a given text element automatically, just like a browser would, based on algorithms from CSS. Currently, TTF files are supported in the "Regular", "Bold", "Italic", and "Bold Italic" variants. The simple algorithm implemented here tries to match the font family exactly, if possible, falling back to any other font. Generic font families such as "serif" or "monospace" aren't supported yet and will trigger the fallback. Also, the relative weights "bolder" and "lighter" aren't computed and fall back to normal weight. BREAKING CHANGE: `SVGFont` class and some methods on `SVGText` removed.
meyfa
added a commit
that referenced
this issue
Dec 28, 2022
Fixes #82, #168, #171. This patch removes the artificial `SVGFont` class as well as the `SVGText::setFont(SVGFont $font)` method. Instead, it is now possible to register TrueType (`.ttf`) font files by calling `SVG::addFont()` with a file path. A TrueType font file parser is implemented based on Microsoft's OpenType specification. This allows us to choose the best matching font file for a given text element automatically, just like a browser would, based on algorithms from CSS. Currently, TTF files are supported in the "Regular", "Bold", "Italic", and "Bold Italic" variants. The simple algorithm implemented here tries to match the font family exactly, if possible, falling back to any other font. Generic font families such as "serif" or "monospace" aren't supported yet and will trigger the fallback. Also, the relative weights "bolder" and "lighter" aren't computed and fall back to normal weight. BREAKING CHANGE: `SVGFont` class and some methods on `SVGText` removed.
meyfa
added a commit
that referenced
this issue
Dec 28, 2022
Fixes #82, #168, #171. This patch removes the artificial `SVGFont` class as well as the `SVGText::setFont(SVGFont $font)` method. Instead, it is now possible to register TrueType (`.ttf`) font files by calling `SVG::addFont()` with a file path. A TrueType font file parser is implemented based on Microsoft's OpenType specification. This allows us to choose the best matching font file for a given text element automatically, just like a browser would, based on algorithms from CSS. Currently, TTF files are supported in the "Regular", "Bold", "Italic", and "Bold Italic" variants. The simple algorithm implemented here tries to match the font family exactly, if possible, falling back to any other font. Generic font families such as "serif" or "monospace" aren't supported yet and will trigger the fallback. Also, the relative weights "bolder" and "lighter" aren't computed and fall back to normal weight. BREAKING CHANGE: `SVGFont` class and some methods on `SVGText` removed.
I've implemented a new system for registering fonts statically on the |
meyfa
added a commit
that referenced
this issue
Jan 2, 2023
* feat!: Implement a font registry for text rendering Fixes #82, #168, #171. This patch removes the artificial `SVGFont` class as well as the `SVGText::setFont(SVGFont $font)` method. Instead, it is now possible to register TrueType (`.ttf`) font files by calling `SVG::addFont()` with a file path. A TrueType font file parser is implemented based on Microsoft's OpenType specification. This allows us to choose the best matching font file for a given text element automatically, just like a browser would, based on algorithms from CSS. Currently, TTF files are supported in the "Regular", "Bold", "Italic", and "Bold Italic" variants. The simple algorithm implemented here tries to match the font family exactly, if possible, falling back to any other font. Generic font families such as "serif" or "monospace" aren't supported yet and will trigger the fallback. Also, the relative weights "bolder" and "lighter" aren't computed and fall back to normal weight. BREAKING CHANGE: `SVGFont` class and some methods on `SVGText` removed. * feat: Implement support for the TrueType "OS/2" table for font weight By looking at the "OS/2" TTF table in addition to the "name" table, we can gather additional info about the font weight besides whether a font is bold or not. By doing so, we gain support for every weight level! :) * fix: Add all missing type declarations in TrueTypeFontFile
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
We seen that the system fonts works right, but when we want add an external font ,this is not working.
This is my code:
`<?php
require_once DIR . '/vendor/autoload.php';
use SVG\SVG;
use SVG\Nodes\Structures\SVGFont;
use SVG\Nodes\Texts\SVGText;
$image = new SVG(100, 100);
$doc = $image->getDocument();
$fuente = new SVGFont('fontello', './fontello.ttf',true, "font/ttf" );
$texto = new SVGText("Hello World" , 10, 10);
$texto->setStyle('fill', '#FF00FF');
$texto = $texto->setFont($fuente);
$doc->addChild($texto);
header('Content-Type: image/svg+xml');
echo $image;`
The text was updated successfully, but these errors were encountered: