Skip to content

fix(xlsx): resolve worksheet drawing fonts through the workbook theme#467

Merged
developer0hye merged 1 commit into
mainfrom
fix/xlsx-drawing-theme-font
Jul 25, 2026
Merged

fix(xlsx): resolve worksheet drawing fonts through the workbook theme#467
developer0hye merged 1 commit into
mainfrom
fix/xlsx-drawing-theme-font

Conversation

@developer0hye

Copy link
Copy Markdown
Owner

Summary

  • parse a worksheet drawing run's <a:latin typeface=...>, including the +mj-lt and +mn-lt theme placeholders
  • fall back to the theme's minor Latin font for runs that name no typeface, as DrawingML specifies
  • read the theme's <a:fontScheme> alongside the color palette it already loads
  • traverse a sheet page's drawing text boxes when deciding whether to resolve the font search context

Related issue

Fixes #461

Details

Excel writes a shape label's run properties as <a:rPr lang="en-US" sz="1100"/> with no typeface at all. DrawingML resolves an absent <a:latin> to the theme's minor Latin font, but the drawing parser read only sz, b, and i, so every worksheet drawing label rendered in Typst's serif default.

Fixing the parser alone does not change the rendered PDF, because the second half of the same path was also missing. document_requests_font_families inspected a sheet page's header, footer, and table but never its text_boxes. A workbook whose only font request comes from a shape label therefore skipped font-context resolution entirely, and the Typst compile never received the macOS Office font directories that hold Calibri — so the family office2pdf had just asked for silently fell back to the serif default. Both halves are needed for the labels to reach the page in the workbook's font, so both are here.

pdffonts on the regression fixture, before and after:

before after
embedded faces LibertinusSerif-Regular LibertinusSerif-Regular, Calibri

The remaining Libertinus face is the unstyled A1 title cell, tracked in #462.

Testing

  • cargo fmt --all -- --check
  • cargo test --workspace
  • cargo clippy --workspace --all-targets --all-features
  • pdffonts before/after comparison on tests/fixtures/xlsx/theme_color_drawing.xlsx
  • pdftoppm -r 150 rendering, matched full-resolution label crops, and magick compare -metric AE -fuzz 5%

Visual impact

  • No rendered PDF change
  • Rendered PDF change or visual evidence added
  • Reason: worksheet drawing labels now render in the workbook theme font.

Visual audit

The GT is the native Microsoft Excel export already captured for this fixture in #434, reused unchanged: same workbook, same page, same renderer, same 150 DPI.

Visual comparison

GT Before After
GT Before After

Required inspection

  • Rendered all evidence at 150 DPI or higher
  • Stored progressive JPEG quality 86 assets with metadata stripped
  • Inspected matched region crops at full resolution
  • Ran the 5% fuzz pixel-difference sweep
  • Inventoried hairlines and border dash styles
  • Inventoried font weight, italic, and underline emphasis

The 5% fuzz sweep against the size-normalized GT is 290,449 differing pixels before and 290,500 after: the drawing geometry defects tracked in #459 and #460 displace all three shapes and dominate the count, so a font-only change cannot move it. The matched label crops at full resolution show the change directly — the GT and the after image both render accent1 in Calibri, the before image in a serif face. The fixture contains no hairlines, borders, or dashed strokes, and every run is regular weight with no italic or underline.

Deviation audit

Check Result
Page count/order Remaining: #459 - Excel emits one page; office2pdf adds a blank second page
Element presence Matches GT - the title and all three drawing labels are present
Position/size Remaining: #459 tracks same-row vertical stacking; #460 tracks undersized anchor bounds and cumulative horizontal drift
Rotation/flip No deviation observed - the fixture contains no rotated or flipped elements
Fill Matches GT - all three RGB values match Excel exactly after #430
Stroke/border No deviation observed - the shapes intentionally have no outline or hairline
Text content Matches GT - all four strings are preserved
Font family/weight/style Remaining: #462 - the unstyled A1 title keeps the serif default; #466 - a self-closing <a:rPr/> still drops the run size, bold, and italic. The family defect this PR targets is fixed: the three drawing labels now render Calibri, as in Excel
Text color Matches GT - all text remains black
Alignment Matches GT - drawing labels remain horizontally and vertically centered
Line/paragraph spacing No deviation observed - each text region is one regular single-line paragraph
Clipping/overflow Remaining: #459 - flow-height reservation spills onto a blank second page; no page-1 glyph clipping was found

Checklist

  • Commits include a Signed-off-by line
  • PR scope contains one root cause
  • Remaining visual deviations each reference an open issue

Excel writes a shape label's run properties as `<a:rPr lang="en-US"
sz="1100"/>` with no typeface at all. DrawingML resolves an absent
`<a:latin>` to the theme's minor Latin font, but the drawing parser read
only sz/b/i and never looked at a typeface or the theme, so every worksheet
drawing label rendered in Typst's serif default instead of the workbook's
sans-serif face.

Parse `<a:latin typeface=...>` on a run, resolve the `+mj-lt` and `+mn-lt`
placeholders against a new `ThemeFontScheme` read from the same theme part
the color palette already comes from, and fall back to the minor Latin font
for runs that name no typeface.

That alone does not change the rendered PDF, because the second half of the
same path was also missing: `document_requests_font_families` inspected a
sheet page's header, footer, and table but never its drawing text boxes. A
workbook whose only font request comes from a shape label therefore skipped
font-context resolution entirely, and the Typst compile never received the
macOS Office font directories that hold Calibri - so the family office2pdf
had just asked for silently fell back to the serif default. Traverse the
text boxes too.

The regression fixture's three labels now embed and render Calibri, matching
the native Excel export.

Fixes #461

Signed-off-by: Yonghye Kwon <developer.0hye@gmail.com>
@developer0hye
developer0hye merged commit 7c04f13 into main Jul 25, 2026
17 checks passed
@developer0hye
developer0hye deleted the fix/xlsx-drawing-theme-font branch July 25, 2026 17:39
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.

XLSX: worksheet drawing text runs ignore theme font inheritance

1 participant