Repository navigation
SVG: resolve a relative font-size against the inherited one - #2155
Merged
andersonhc merged 5 commits intoNov 12, 2026
Merged
Conversation
RavSinghChandan
force-pushed
the
svg-relative-font-size
branch
from
November 10, 2026 13:05
a1b8132 to
e47d5f9
Compare
andersonhc
reviewed
Nov 10, 2026
RavSinghChandan
force-pushed
the
svg-relative-font-size
branch
from
November 10, 2026 14:08
e47d5f9 to
ffd55e4
Compare
Author
|
Thanks, you're right: _get_pattern_paint() collects the font properties of the pattern's ancestors as they are written, so the root's font-size="2em" reached build_group() still relative. Each ancestor's font-size is now resolved against the size inherited so far, as in build_group(). Your SVG works now, and test_svg_relative_font_size_in_pattern covers it, plus a text in the pattern under 2em and 50% ancestors, which gets 6pt; both fail without the change. Rebased on master. |
# Conflicts: # CHANGELOG.md # fpdf/svg.py # test/svg/test_svg.py
andersonhc
approved these changes
Nov 12, 2026
andersonhc
reviewed
Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
font-sizeinem,exor%fails withValueError: 0.8em uses unsupported relative length em. spaCy's displaCy writes<text dy="1.25em" style="font-size: 0.8em">for its dependency arc labels, under a root<svg style="font-size: 20px">, so its diagrams cannot be converted; seven of the displaCy images in spaCy's website (website/public/images/displacy*.svg) fail this way.dxanddyin em were already supported. A new_resolve_relative_font_size()turns a relativefont-sizeinto an absolute one, against the inherited font size (16px if none, the default fpdf2 already uses for text), where a group, a<switch>, a<text>or a<tspan>merges its style over the inherited one. Descendants then inherit the computed size, as in CSS, so nested relative sizes multiply.With this change, the seven displaCy images render.
Added
test_svg_relative_font_size(displaCy's case, a percentage, nested em, ex in a<tspan>, and inheritance from a group); it fails on master. The full test suite passes excepttest_image_with_explicit_dimensions, which also fails on master in my environment; black, pylint, mypy and pyright pass