Skip to content

Drawing export: a sheet's PNG draws its text, filled like the SVG's (#4890) - #12355

Merged
bherbruck merged 1 commit into
tangency-labs:drawingsfrom
CamWight:png-text-4890
Nov 5, 2026
Merged

bherbruck merged 1 commit into
tangency-labs:drawingsfrom
CamWight:png-text-4890

Conversation

@CamWight

@CamWight CamWight commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Change

A drawing sheet can be exported as a PNG picture. Text on a sheet (a dimension's number, a title block's values) is set as filled glyph outlines, and the PNG writer refused any sheet with text on it, by name. Now it draws the text: each line's glyph outlines are filled where the sheet puts them, the same outlines the SVG export writes.

Part of #4890, into drawings. Please merge this before the dimension text and title block text PRs (opened next, as drafts): each of them puts text on a sheet, so without this a dimensioned sheet, or any sheet with a title block, is refused as a PNG.

Changes a default: no
No setting, command or saved data changes; sheets without text export as before.

What it does

In crates/io/src/paper/png.rs:

  • The text arm traces each run's glyph outlines and fills them with the nonzero rule, as glyphs are drawn. The outlines come from the paper grid (TextRun::outlines), the same function the SVG writer uses, so PNG and SVG can't disagree on where a glyph is.
  • Filled shapes and text both turn outlines into one path through one helper (Sheet::traced); only the fill rule differs, even-odd for a filled shape and nonzero for a glyph.
  • Text counts toward the sheet's point cap like any line, so huge text is refused with the same message as huge lines. Bands and every colour mode (grey, black and white, RGB, transparent, coloured paper) apply to text as to lines.

A finding about bands. The writer draws tall sheets in horizontal bands, to keep memory low. Its notes said the bytes are the same whatever the band. Text showed that isn't exact. Where a band's edge cuts a glyph, tiny-skia can cover an edge pixel one anti-aliasing step (one sixteenth) differently, and in black and white such a pixel can fall on the other side of the threshold. No seam shows. Exports use one band height, so a sheet exported twice gives the same bytes, and the background PNG writer (#10431) uses the same bands. The module notes now say so. Making it exact would mean cutting paths at band edges ourselves; that's left for later.

Validation

Local, Windows, --profile ci, on drawings 69709bd: cargo check --all-targets of geom, sketch, doc, io and engine; fmt; clippy -D warnings; io paper tests: 45 passed. The same code was also checked in a group with the text PRs above it: sketch paper_text 47, geom paper 72, doc drawing 90, engine drawing 337, schema 191, and the engine's wasm build.

Tests (in png_tests.rs):

  • A made-up glyph of two overlapping boxes is filled where the scene puts it, inside each box and where they overlap (nonzero), and nowhere outside.
  • Real text in the drawing font, "Ø12 ±0.1 30°" and a line in Hebrew, darkens the sheet only within its outlines. The export equals the writer at its default band height. The same sheet drawn again gives the same bytes, at the default band and at bands of 1, 3 and 7 rows, in every colour. Across band heights, at most 32 samples differ, each by one step. Moved by a millimetre, its pixels leave those outlines.
  • Text's points add up over the sheet: one run of 600 huge glyphs at 2400 dpi is drawn, and two runs are refused with the cap's message.

Planted faults, each caught by a failing test, then a clean run: text not drawn; text filled even-odd; text's points not counted across runs.

Screenshots of the behavior

A sheet with dimensions and the built-in title block, exported as a PNG at 300 dpi (A3). Before this change, the PNG export of this sheet is refused. (The sheet's text comes from the dimension text and title block text PRs, applied on top.)

The L-shaped plate's sheet exported as a PNG at 300 dpi: four dimensions with their numbers, and the title block with its labels and values

Integration status

One commit on drawings 69709bd (the latest when pushed). Our #10431 (the PNG written in the background) moves the writer's item loop; whichever merges second carries the text arm (one line) across. @0xlillith's #12071 adds tests at the end of png_tests.rs: at most a textual conflict there.

A sheet's text is drawn from the same glyph outlines the SVG writer fills,
filled nonzero so a glyph's overlapping contours fill whole, where the PNG
writer refused any text before. Text counts toward the point cap and is
drawn band by band like any fill, in every colour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions github-actions Bot added the area:io import/export and file formats (STEP, IGES, 3MF, glTF, designs) label Nov 5, 2026
@bherbruck
bherbruck merged commit 2c052b4 into tangency-labs:drawings Nov 5, 2026
35 checks passed
@CamWight
CamWight deleted the png-text-4890 branch November 5, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:io import/export and file formats (STEP, IGES, 3MF, glTF, designs)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants