Skip to content

fix(pdf): clear a minimum font size per line block, and only where one bites - #753

Merged
andiwand merged 1 commit into
mainfrom
fix/pdf-uniform-run-font-size
Aug 27, 2026
Merged

fix(pdf): clear a minimum font size per line block, and only where one bites#753
andiwand merged 1 commit into
mainfrom
fix/pdf-uniform-run-font-size

Conversation

@andiwand

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

Stacked on #752.

#752 lays a matrix-placed run out large and scales it down, because a producer
writing 1 Tf gets a font-size any minimum clamps. A minimum clamps a
uniform run just the same, so both paths need it — but doing it with a
constant 48 charges every block for it and lays a page of body text out at
400–900pt.

What this does

A line block is laid out at the 24px floor only when its own font-size
falls under it
, and scales back by exactly that much: the uniform path
through a new z class, the matrix path through its own matrix. At or above
the floor the factor is 1 and the block is emitted byte for byte as before —
no transform, no z, nothing.

  • text_local_scale = 48text_floor_pt = 18 (24px, the largest minimum a
    chrome user can set; an android webview defaults to 8px) plus
    local_scale(font_size_pt).
  • run_geometry goes back to the natural matrix and size; each layer applies
    its own block's scale. Size is already in the visual and single-layer flow
    keys, so the factor is constant per block there; the selection layer groups
    by frame rather than size, so it carries the scale as block state and a run
    joining a block is measured in that block's space.
  • .t no longer carries a transform.

The clamp reads the specified size, not the zoomed one — verified against
--blink-settings=minimumFontSize at zoom 1 / 0.5 / 0.25 — so body's fit
zoom does not move the floor.

Verification

Each page rendered with and without a browser minimum font size, diffed
against the unclamped render (the truth):

file minimum before after
with_form.pdf 24px 8.8% of pixels wrong 0.000%, max delta 0
phd-agreement.pdf 24px 31.5% 0.000%, max 0
svg_background_with_page_rotation_issue402.pdf 8px 28.6% 0.000%, max 0
Casio_WVA-M650-7AJF.pdf 24px 20.0% 0.000%, max 0
mova-viax-500-user-manual-de.pdf 24px 4.1% 0.000%, max 0
geneve_1564.pdf 8px 1.0% 0.000%, max 0

With no minimum set, text lands in the same place at the same size; 0.2–0.9% of
pixels differ from glyph rasterization (the browser rasterizes e.g. 18pt scaled
by 0.667 rather than 12pt). A magnified crop confirms identical positions and
metrics.

Against the constant 48 on 978-3-030-65771-0.pdf: max font-size 60pt rather
than 2880pt, html 9.74 MB rather than 10.15 MB, 28 scale classes rather than
one transform on all ~25 000 line blocks. Load, scroll frame times and zoom
steps are unchanged across all three variants.

Note

Nearly every pdf's output changes, so test/data/reference-output needs
regenerating and the pointer advanced.

@andiwand
andiwand force-pushed the fix/pdf-matrix-run-font-size branch 2 times, most recently from 384d4d6 to ee1dcb7 Compare August 27, 2026 21:44
Base automatically changed from fix/pdf-matrix-run-font-size to main August 27, 2026 21:45
…e bites

A minimum font size clamps a uniform run just as it clamps a matrix-placed
one, so both need the blow-up — but a constant 48 charged every block for it,
laying a page of body text out at 400-900pt.

A block is now laid out at the 24px floor only when its own `font-size` falls
under it, and scales back by exactly that much: the uniform path through a `z`
class, the matrix one through its own matrix. At or above the floor the factor
is 1 and the block is emitted byte for byte as it was. The clamp reads the
specified size, so zoom does not move the floor.

Rendered with a minimum font size set, every page checked now matches its own
unclamped render pixel for pixel.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0169dUoxqhqfi7ZU5ei8b9ov
@andiwand
andiwand force-pushed the fix/pdf-uniform-run-font-size branch from abf7cb5 to 2bed5c9 Compare August 27, 2026 21:54
@andiwand
andiwand merged commit ae2b4fb into main Aug 27, 2026
27 checks passed
@andiwand
andiwand deleted the fix/pdf-uniform-run-font-size branch August 27, 2026 21:57
andiwand added a commit that referenced this pull request Aug 28, 2026
#753 lays a line block out at the 24px floor only where its own font size falls
under it, which moved 25 public and 785 private pdf pages. Every one carries the
same text in the same place — only the glyph rasterisation differs, checked page
by page against the old reference. The pins also pick up the comment
`resources/document.css` grew after #748 was regenerated.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KiPhteiEmPp8iPQLBfnthA
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