Repository navigation
Draw PDF diagrams as vectors through the shapes' own handlers - #638
Merged
Merged
Conversation
Assisted-by: Opus 5.5
Diagrams in PDF exports were pictures. They're now drawn by the shapes' handlers onto jsPDF's context, so their text stays text and they stay sharp at any zoom. pdfCanvasContext fills what jsPDF's context2d does differently from a canvas: paths replayed from RecordedPaths, arcs as cubics, colour alpha and globalAlpha, scaled dashes, exact text sizes, widths, baselines and alignment, maxWidth, and images as PNGs at the export's DPI. Fonts resolve to bundled ones, never jsPDF's Latin-1 built-ins. A label no PDF font can draw is a picture of that label. A diagram that fails part-way is taken back and placed as a picture. Assisted-by: Opus 5.5
# Conflicts: # docs-site/guide/export-import.md
…nd groups Assisted-by: Opus 5.5
Assisted-by: Opus 5.5
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.
What
Diagrams in PDF exports were PNG pictures. They are now drawn by the shapes' own handlers onto jsPDF, so they look like the canvas, stay sharp at any zoom, and their labels can be selected and searched. This builds on the path recorder (#635).
drawExport(exportUtils.ts): the PNG route's drawing, moved into a function both routes share. The PNG route makes the same calls in the same order.pdfCanvasContext(pdfExport/pdfCanvas.ts): a proxy over jsPDF'scontext2dthat fills what it draws differently from a canvas, each found in this work and pinned by a test:measureTextwas about 3.8 times too wide in millimetres, so labels wrapped early. Widths are now the font's own; text the PDF font lacks is measured by the browser.fillText'smaxWidthwrapped text; it now sets an over-long UML or entity name smaller to fit, where the canvas narrows its letters.rgba()colours was recorded and never painted, so group tints came out solid. Colour alpha andglobalAlphanow go through jsPDF's opacity state.arcturned neither its angles nor its radius with a rotation or an uneven scale. Every arc,arcTo,ellipseandroundRectis now drawn as cubics (replayPath's newshimArc).drawImageasked for a JPEG, which loses transparency, and couldn't read SVG icons. Images are now drawn as PNGs at the export's DPI.fill(path),fillRectandstrokeRectno longer disturb the current path, and a path that recorded nothing is an error, not a blank.diagramVectors.ts): every family list the shapes use maps to the bundled font the PDF embeds for it. jsPDF's own fallbacks (built-in Times, Helvetica and Courier, Latin-1 only) map to the document font and the code font.registerCatalogueFontnow registers a known font's missing styles; the code font came in two.saveandrestorewrite to every page) and the diagram is placed as a picture.noNativePath2D.test.tsfails on anynew Path2D(outside the shape picker's on-screen previews. It caughtcreateRoundedRectPath(group backgrounds), now aRecordedPath.AGENTS.mddescribes the vector route and theRecordedPathrule, and its stale line from Print emoji in PDF exports as pictures (DSK-247) #636 (emoji were left out; they're pictures now) is corrected here because it sits in the same paragraph.Accepted differences
saveandrestorealso writeq/Qto every earlier page. They balance; with 100 pages before a 300-shape diagram they add about 31 KB compressed and no measurable time.Verification
pdfCanvas.test.ts(31),diagramVectors.test.ts(9: labels as text on their canvas lines, each label's font, a family the PDF lacks, jsPDF's fallbacks, missing styles, the font wait, the rollback and the next drawing, library shapes with a connector and a group, the clip),RecordedPath.test.ts(+4 for the arc shim), the guard (2).tscclean; 524 files and 5,686 tests before the last two fixes; the PDF export folder passes after them. The golden PDF dumps (documents without diagrams) are unchanged. The OSS leak grep is clean.Not in this PR
Group.getBoundsreads the live store), so a multi-page PDF draws them without their frame.Assisted-by: Opus 5.5