Repository navigation
Place text on its dominant and alignment baselines, with baseline-shift - #222
Merged
Merged
Conversation
dominant-baseline (inherited) and alignment-baseline (not inherited, overriding it for its own element) take every common value: auto, alphabetic, middle, central, hanging, mathematical, ideographic, text-before-edge and text-after-edge, with the CSS Inline 3 and SVG 1.1 aliases (text-top, text-bottom, before-edge, after-edge, baseline, use-script; no-change and reset-size keep the parent's). Each comes from the font's ascent, descent and x-height in makeYOffset, as resvg derives them. The sign of hanging, which lifted the text instead of hanging it, is fixed. baseline-shift applies to tspans: sub and super from the font's OS/2 script offsets, lengths, and percentages of the font-size they are declared at. Shifts of nested tspans add up; baseline adds nothing, and inherit takes the parent's value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## claude/text-length #222 +/- ##
======================================================
+ Coverage 95.24% 95.29% +0.04%
======================================================
Files 293 294 +1
Lines 30893 31042 +149
======================================================
+ Hits 29425 29581 +156
+ Misses 1468 1461 -7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Step 6 of the text series, and the last planned: the common baselines and
baseline-shift.Based on #221 (
claude/text-length, itself based on #220). Neither has merged yet, so this PR targets that branch. Retarget it once they merge.Changes
dominant-baseline(inherited) andalignment-baselinetakeauto,alphabetic,middle,central,hanging,mathematical,ideographic,text-before-edgeandtext-after-edge.alignment-baselineis not inherited, and overrides the dominant baseline for its own element. That's how resvg treatsalignment-baselineon a tspan.text-top,text-bottom,before-edge,after-edge,baselineanduse-script.no-changeandreset-sizekeep the parent's baseline.text-topused to be rejected;Parser.TolerantTestsnow uses a value that is really invalid.makeYOffset, which stays the one place that asks CoreText for them.hangingfixed. Its sign was wrong: the text was lifted aboveyinstead of hanging from it.centralused half the cap height; it's now the middle of the em box.<text>itself or<g>, as resvg does.subandsupercome from the font's OS/2 script offsets, throughCTFontCopyTable.emare supported. Percentages are of the font size the shift is declared at.baselineadds nothing, andinherittakes the parent's value.makeBaselineOffset, so it reaches text, glyph runs, outlines,<textPath>and the text's bounding box.resvg tests
dominant-baseline,alignment-baselineandbaseline-shift(63 files, against #221):WebKit's
<img>path ignores most of these properties, so "pass, WebKit differs" is the expected verdict.The 5 that remain are out of scope:
alignment-baseline/hanging-on-verticalneeds vertical text.alignment-baseline/hanging-with-underline(23% → 9%) needs text-decoration.alignment-baseline/two-textPath-with-middle-on-first(41% → 20%) is a textPath case.dominant-baseline/hanging(50% → 33%) needs a Devanagari font that isn't installed.alignment-baseline/inheritneedsinheriton a non-inherited property.text/suite (387 files):No regressions. Over steps 4–6 together (#220, #221 and this PR), SwiftDraw bugs in
text/go from 174 onmainto 116.Among the files that now pass: all the
baseline-shiftlength, percentage, sub, super and nested cases;baseline-shift/with-rotate; anddominant-baseline/inherited-through-nested-tspan. Those last two were among the files #214 and #216 made worse.Checks
swiftdraw-diff compare --base origin/main --resvg Samples.bundleshows no regressions. Existing samples are unchanged.text-baselines.svgis at 0.47% against resvg, a pass. It has each baseline against a guide line,alignment-baselineon a tspan,E = mc²,H₂O, a nested superscript, and percentage and length shifts.swift testpasses on macOS../container-run-tests.shpasses with Swift 6.4 and withSWIFT_VERSION=6.2.LayerTreeTextBaselineTests.dominant-baselinebut notalignment-baseline, nested shifts adding up, shifts ignored on<text>and<g>,inherit, and length shifts.🤖 Generated with Claude Code