Skip to content

Text loose ends: font shorthand, alignment-baseline inherit, text filter regions - #224

Merged
swhitty merged 1 commit into
mainfrom
claude/text-loose-ends
Nov 17, 2026
Merged

swhitty merged 1 commit into
mainfrom
claude/text-loose-ends

Conversation

@swhitty

@swhitty swhitty commented Nov 17, 2026

Copy link
Copy Markdown
Owner

The last PR of the text series. Branched from main (1118887).

Changes

  • CSS font shorthand. Applies in style="" and in stylesheets: [style] [variant] [weight] [stretch] size[/line-height] family.
    • Omitted parts are reset to normal, as CSS requires.
    • Variant, stretch and line-height are checked for validity, then dropped.
    • An invalid value is ignored.
    • System keywords (caption, menu…) become 13px sans-serif.
    • As in SVG 2 §6.6 and browsers, it is not a presentation attribute.
    • This covers matplotlib's svg.fonttype='none' output (style="font: 10px 'DejaVu Sans'").
  • alignment-baseline="inherit" takes the parent's value; dominant-baseline="inherit" is accepted too.
  • Filter regions of text.
    • Where a <text> has a filter, or a filtered ancestor, the builder stores the text's SVG 2 bounding box (makeTextBounds) on its layer. CommandGenerator.makeBounds uses it for objectBoundingBox regions and units.
    • Before this, filtered text and groups containing text were drawn unfiltered. Text without a measured box (textPath, or no CoreText) still is.
  • Weight matching of installed families. Faces are chosen by CSS Fonts 4 §5.2 rules, as @font-face already was:
    • normal width first, then slant, then weight;
    • between 400 and 500, heavier faces up to 500 come first; above 500, heavier faces come first.
    • For example, Helvetica Neue 550 now uses Bold, not Medium.
    • No existing sample changes.
  • Samples: text-font-shorthand.svg (a matplotlib-style chart) and text-filter.svg. Both pass against resvg; WebKit matches the shorthand sample.

resvg text/ suite (387 files, swiftdraw-diff compare --base main --resvg)

verdict main this PR
pass 107 108
pass, WebKit differs 147 150
pass, resvg differs 17 17
SwiftDraw bug 116 112

No regressions. Now passing:

  • font/font-shorthand
  • alignment-baseline/inherit
  • text/filter-bbox
  • letter-spacing/filter-bbox

These listed files are unchanged on purpose; each already matches WebKit and CSS, or fails for an out-of-scope reason:

  • font-size/negative-size: resvg draws nothing. We keep the inherited size, as WebKit does.
  • font-size/named-value-without-a-parent: resvg scales named sizes by 1.2 per step (xx-large is 27.6px). CSS Fonts 4 and WebKit use 32px, and so do we.
  • font-weight/650: we draw Times-Bold, as WebKit does. resvg draws the regular face of its fallback font.
  • dominant-baseline/hanging: placed right, but the Devanagari fallback font differs.
  • tspan/nested: resvg moves the collapsed space into the bold tspan. We keep it in the first one, as WebKit does.
  • tspan/tspan-bbox-2: only the underline is missing (text-decoration).

Checks

  • swift test passes.
  • ./container-run-tests.sh passes, on Swift 6.4 and on SWIFT_VERSION=6.2.
  • swiftdraw-diff compare --base main --resvg Samples.bundle: no regressions. 179 of 181 files are unchanged; the 2 new samples go from SwiftDraw bug to pass.

🤖 Generated with Claude Code

…ter regions, CSS weight matching

- Expand the CSS `font` shorthand (style, weight, size, family; omitted parts reset) in style
  attributes and stylesheets, with system font keywords; it is not a presentation attribute.
- Support `alignment-baseline: inherit` (and `dominant-baseline: inherit`).
- Measure the text's bounding box for objectBoundingBox filter regions of filtered text and
  groups containing text, instead of drawing them unfiltered.
- Match installed family faces by CSS Fonts 4 weight rules over normal-width faces.
- Add text-font-shorthand (matplotlib style) and text-filter samples.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@swhitty
swhitty merged commit 7a54105 into main Nov 17, 2026
15 of 18 checks passed
@swhitty
swhitty deleted the claude/text-loose-ends branch November 17, 2026 20:13
@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.03150% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.25%. Comparing base (1118887) to head (611fea7).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...tDraw/Sources/Renderer/Renderer.CoreGraphics.swift 87.87% 4 Missing ⚠️
DOM/Sources/Parser.XML.FontShorthand.swift 98.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #224      +/-   ##
==========================================
- Coverage   95.28%   95.25%   -0.04%     
==========================================
  Files         294      296       +2     
  Lines       31052    31260     +208     
==========================================
+ Hits        29588    29776     +188     
- Misses       1464     1484      +20     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant