Skip to content

Draw no stroke for an empty or missing /C, as Acrobat does - #104

Merged
bobsingor merged 1 commit into
embedpdf/mainfrom
embedpdf/feature/no-stroke
Nov 3, 2026
Merged

bobsingor merged 1 commit into
embedpdf/mainfrom
embedpdf/feature/no-stroke

Conversation

@bobsingor

Copy link
Copy Markdown
Contributor

A square, circle, polygon, line, polyline or ink whose /C is the empty array (ISO 32000's "no colour; transparent") or left out now draws no stroke. The appearance generator used to stroke both in black whenever the border width was above 0. That's what lets the engine offer color: null, a shape without a line, written as /C [].

Checked in Acrobat against a grid of shapes with no appearance stream, one row per stroke case:

  • No stroke, for /C [] and for /C left out alike. The fill stays inset half the border width, where the stroke's middle would be. A line keeps only its filled closed endings, sized by its width. Ink paints nothing but keeps its points and /Rect.
  • Width 0 (/BS /W 0 or /Border [0 0 0]): a line, polyline or ink is a hairline (0 w, the thinnest line the device draws), with the endings a 1 pt line has. Ink at width 0 used to get no appearance at all, and a line a 1 pt one. A square, circle or polygon at width 0 still has no outline.
  • A dimension line with no stroke colour draws its filled endings and caption, without segments or leaders.

Every stroke that has a colour is written byte for byte as before.

EPDFAnnot_SetNoColor() writes a colour entry as the empty array. EPDFAnnot_ClearColor() removes the entry instead, and Preview draws a stroke without /C in black; an empty /C is no stroke in Acrobat and Preview alike.

Tests

  • The empty array written and read back as no colour; an overlay colour refused outside a redaction.
  • No stroke for a square, circle and polygon with /C left out and empty, the fill inset half the width.
  • A line with no stroke colour: only its filled endings, and nothing without a fill.
  • Hairlines at width 0 for a line, a polyline and ink, with a 1 pt line's endings.
  • Ink with no colour paints nothing and keeps its /Rect.
  • The C API list, and the five new tests recorded as layer-mode writers.
  • Eight stroke-geometry tests and the measurement tests' line helper built shapes without a /C; they now set one, so their output is the same as before.

On macOS, the full embedder suite and the pixel tests fail the same tests as main (12 embedder, 51 pixel goldens). Linux CI hasn't run yet.

The engine side (color: null on the stroked kinds, the reader, the viewer's style panel, docs and SDKs) is in embedpdf/embed-pdf-viewer feature/no-stroke. It needs this released and pinned.

A square, circle, polygon, line, polyline or ink whose /C is the empty array (ISO 32000's "no colour; transparent") or left out now draws no stroke. The generator used to stroke both in black whenever the border width was above 0. Checked against Acrobat with annotations that have no appearance stream:

- No stroke: the fill alone, still inset half the border width, where the stroke's middle would be. A line keeps only its filled closed endings, sized by its width; ink paints nothing but keeps its points (and /Rect).
- /BS /W 0 (or /Border [0 0 0]) on a line, polyline or ink is a hairline (0 w, the thinnest line the device draws), with the endings a 1 pt line has. Ink at width 0 used to get no appearance and a line a 1 pt one. A square, circle or polygon at width 0 still has no outline.
- A dimension line with no stroke colour draws its filled endings and caption, without segments or leaders.

Every stroke that has a colour is written byte for byte as before.

EPDFAnnot_SetNoColor() writes a colour entry as the empty array. EPDFAnnot_ClearColor() removes the entry instead, which Preview draws in black for a stroke; an empty /C is no stroke in Acrobat and Preview alike.

Tests: the empty array written and read back as no colour; no stroke for a square, circle and polygon with /C left out and empty, the fill inset; a line's filled endings only; hairlines at width 0 for a line, polyline and ink; ink with no colour paints nothing and keeps its /Rect; the C API list; layer-mode writers. Eight stroke-geometry tests and the measurement tests' line helper built shapes without a /C and now set one. On macOS the full embedder suite and the pixel tests fail the same tests as main.
@bobsingor
bobsingor merged commit 986db17 into embedpdf/main Nov 3, 2026
1 check passed
@bobsingor
bobsingor deleted the embedpdf/feature/no-stroke branch November 3, 2026 19:41
roanutil pushed a commit to roanutil/embed-pdf-viewer that referenced this pull request Nov 4, 2026
A square, circle, polygon, polyline, line or ink annotation takes `color: null` for no stroke and keeps its `strokeWidth`. The engine writes it as `/C []`, the empty colour ISO 32000 defines as no colour, and reads an empty or missing `/C` as `null`: that's how Acrobat draws both (checked with a grid of shapes without appearance streams). A missing `/C` used to read as red.

- Engine: the stroked kinds' `color` is nullable; the reader drops its red default; the writer uses the runtime's new `EPDFAnnot_SetNoColor`. `runNoStrokeConformance` checks reads, writes, creates and pixels on both engines, from the Acrobat grid's cases.
- Viewer: `Style.color` may be `null` and the scene paints no stroke for it. A line, polyline or ink at width 0 is a hairline (`Paint.hairline`, one pixel at any zoom) with a 1 pt line's endings, as the runtime and Acrobat draw it; it drew nothing before.
- Style panel: a colour property's `allowsNone` offers "none". On a shape's or line's stroke and fill, a text box's background, a redaction's fill and a form field's border and background; never on ink or markup, which would just vanish. Tool defaults take `color: null` too.
- Docs: "Without a line" on the shapes page, the style section and the style-panel property table; the style-panel samples use `allowsNone`. Synced to both sites.
- Contract and SDK: `color` is nullable on the six kinds (`pnpm api:sync`). API snapshots, changesets.

Runtime: embedpdf/runtime#104 (`EPDFAnnot_SetNoColor`), in the pinned f2dd40897.
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