Offer rendered height and width on text objects#425
Open
petero-dk wants to merge 6 commits into
Open
Conversation
… units rw and rh were computed in raw PDF text-space units rather than viewport pixels, making them ~1.5x too small relative to x/y coordinates. In showText(), canvasWidth, curFontSize, and renderedHeight are all accumulated in PDF text-space (before the viewport transform). x/y come from getCoords_(0,0) which applies the full cumulative canvas matrix (viewport × text matrix), so they ARE in viewport pixels. Fix: multiply the PDF-space components by the viewport scale factor (derived from this.baseTransform) before passing to fillText, so that rw and rh end up in the same coordinate system as x and y. Result for a 20pt×20pt box at (20pt, 20pt): Before: x=1, y=1.199, rw=0.799, rh=0.737 After: x=1, y=1.199, rw=1.198, rh=1.043 (rw≈y, rh≈x as expected) Applied to both the regular-font and Type3-font rendering paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
This pull request introduces improvements to the PDF text rendering pipeline, ensuring more accurate vertical text metrics and enhancing the output data structure. The main changes involve passing and calculating the rendered text height (
renderedHeight) throughout the rendering and data extraction layers, updating method signatures, and reflecting these changes in the output and documentation. Additionally, a new test script is added for verifying hidden field extraction.Rendering and Text Metrics Improvements:
CanvasGraphicsrendering logic inbase/display/canvas.jsto calculate and passrenderedHeightwhen rendering both Type3 and regular fonts, and to compute vertical and horizontal scaling factors for more accurate text box metrics. [1] [2] [3]CanvasRenderingContext2D_class inlib/pdfcanvas.jsto accept and propagate the newrenderedHeightparameter infillTextandstrokeTextmethods. [1] [2]PDFFontclass inlib/pdffont.jsto receiverenderedHeight, calculate horizontal scaling, and output both rendered width (rw) and rendered height (rh) in the text block data. [1] [2]Output Data Structure and Documentation:
readme.mdto describe the newh(rendered text box height) field in theTextsarray, clarifying its meaning and independence from horizontal metrics.Testing:
test/test-hidden-field.cjsto verify extraction and display of text, field, and boxset metrics, including the new rendered width and height fields.