fix: prescan loses outer CTM context for deeply nested text#267
Closed
bsickler wants to merge 5 commits intoyfedoseev:mainfrom
Closed
fix: prescan loses outer CTM context for deeply nested text#267bsickler wants to merge 5 commits intoyfedoseev:mainfrom
bsickler wants to merge 5 commits intoyfedoseev:mainfrom
Conversation
… and multiple depths
Contributor
Author
|
I also ran |
yfedoseev
added a commit
that referenced
this pull request
Apr 3, 2026
Merged PRs: - #251 fix: prevent panic on multi-byte UTF-8 in log slicing (@hansmrtn) - #273 fix: markdown mode drops spaces around styled text (@jorlow) - #266 fix: apply Form XObject /Matrix and correct text matrix advance (@bsickler) - #267 fix: prescan loses outer CTM context for deeply nested text (@bsickler) - #261 feat: expose path operations in extract_paths() Python (@willywg) WASM DevEx alignment: - Added operations array to extractPaths() WASM output, matching Python (previously only had operations_count)
5 tasks
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.
Description
The SIMD prescan optimization for large content streams (>256KB) scans backwards
up to 4KB from each BT operator to capture graphics state context. For deeply
nested text (e.g., chart axis labels inside scaled coordinate systems), the outer
scaling
cmoperators are beyond 4KB and get lost, producing extreme coordinates(e.g., x=132,145 on a 612-wide page).
This PR adds a lightweight forward CTM scan that tracks
q/Q/cm/Tfacrossthe full stream and records the correct graphics state at each BT/Do position.
This is much cheaper than full parsing because it only recognizes four operator types
and skips all path, color, and text operators. The prescan performance optimization
is preserved while producing correct coordinates.
When the forward scan cannot be used, the code falls back to full stream parsing
for correctness.
Type of Change
Related Issue
Fixes #265
Testing
Checklist