Skip to content

Inherit dominant-baseline into nested <tspan> elements#1070

Open
StefanoD wants to merge 1 commit into
linebender:mainfrom
StefanoD:fix/864-dominant-baseline-inheritance
Open

Inherit dominant-baseline into nested <tspan> elements#1070
StefanoD wants to merge 1 commit into
linebender:mainfrom
StefanoD:fix/864-dominant-baseline-inheritance

Conversation

@StefanoD

Copy link
Copy Markdown

dominant-baseline was listed in is_non_inheritable, so usvg only let a <tspan> pick up the value from its direct parent element. For a nested <tspan> whose immediate parent does not carry the property, the value of an ancestor <text> was therefore lost and the span fell back to auto (alphabetic baseline). The nested run then sat on a different baseline than its siblings — the "weird" positioning reported in #864.

dominant-baseline is actually an inherited property, unlike its siblings alignment-baseline and baseline-shift:

Removing it from is_non_inheritable makes find_attribute/resolve_inherit walk the full ancestor chain, matching Chrome's rendering (verified by comparison) and the spec.

Fixes #864.

Generated with Claude

`dominant-baseline` was listed in `is_non_inheritable`, so usvg only let a
`<tspan>` pick up the value from its *direct* parent element. For a nested
`<tspan>` whose immediate parent does not carry the property, the value of an
ancestor `<text>` was therefore lost and the span fell back to `auto`
(alphabetic baseline). The nested run then sat on a different baseline than its
siblings — the "weird" positioning reported in linebender#864.

`dominant-baseline` is actually an *inherited* property, unlike its siblings
`alignment-baseline` and `baseline-shift`:

- SVG 2 / CSS Inline Layout Module Level 3 define it with "Inherited: yes".
  https://www.w3.org/TR/SVG2/text.html#BaselineAlignmentProperties
- Chromium marks it `inherited: true` (field group `svginherited`), while
  `alignment-baseline` and `baseline-shift` are not inherited:
  https://github.com/chromium/chromium/blob/main/third_party/blink/renderer/core/css/css_properties.json5
  (`name: "dominant-baseline" ... inherited: true`)
- Inkscape declares it as an inheriting `SPIEnum` (default `inherits = true`).

Removing it from `is_non_inheritable` makes `find_attribute`/`resolve_inherit`
walk the full ancestor chain, matching Chrome's rendering (verified by
comparison) and the spec.

Fixes linebender#864.

Tests:
- usvg: `nested_tspan_inherits_dominant_baseline` and the override variant
  assert the resolved baseline on the spans; they fail before the fix
  (`Auto` vs `TextAfterEdge`).
- resvg: render test `text/dominant-baseline/inherited-through-nested-tspan`
  (reference PNG optimized with oxipng). All existing baseline tests are
  unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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 this pull request may close these issues.

Nested tspan positioning is weird

1 participant