fix(xlsx): resolve worksheet drawing fonts through the workbook theme#467
Merged
Conversation
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>
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.
Summary
<a:latin typeface=...>, including the+mj-ltand+mn-lttheme placeholders<a:fontScheme>alongside the color palette it already loadsRelated 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 onlysz,b, andi, 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_familiesinspected a sheet page's header, footer, and table but never itstext_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.pdffontson the regression fixture, before and after:LibertinusSerif-RegularLibertinusSerif-Regular,CalibriThe remaining Libertinus face is the unstyled A1 title cell, tracked in #462.
Testing
cargo fmt --all -- --checkcargo test --workspacecargo clippy --workspace --all-targets --all-featurespdffontsbefore/after comparison ontests/fixtures/xlsx/theme_color_drawing.xlsxpdftoppm -r 150rendering, matched full-resolution label crops, andmagick compare -metric AE -fuzz 5%Visual impact
Visual audit
tests/fixtures/xlsx/theme_color_drawing.xlsxpdftoppm, 150 DPIfixassets/bugfixes/issue-461/gt.jpgassets/bugfixes/issue-461/before.jpgassets/bugfixes/issue-461/after.jpgThe 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
Required inspection
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
accent1in 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
<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 ExcelChecklist
Signed-off-byline