Skip to content
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

Closed
borjagarciab opened this issue May 27, 2022 · 1 comment · Fixed by #191
Closed

External fonts not working for text object #171

borjagarciab opened this issue May 27, 2022 · 1 comment · Fixed by #191
Milestone

Comments

@borjagarciab
Copy link

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;`

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.
@meyfa
Copy link
Owner

meyfa commented Dec 28, 2022

I've implemented a new system for registering fonts statically on the SVG class. The font to use for rendering is then automatically chosen as the best match. See PR #191 and please let me know what you think!

@meyfa meyfa added this to the v0.14.0 milestone Dec 28, 2022
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
@meyfa meyfa closed this as completed in #191 Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants