Skip to content

Add fill support to rectangles - #10

Open
nagieeb0 wants to merge 1 commit into
code-supply:mainfrom
nagieeb0:filled-shapes
Open

Add fill support to rectangles#10
nagieeb0 wants to merge 1 commit into
code-supply:mainfrom
nagieeb0:filled-shapes

Conversation

@nagieeb0

Copy link
Copy Markdown

Rectangles currently always emit re followed by S, so shapes can only be outlined:

20 20 60 60 re
S

That rules out anything built from solid colour — table header backgrounds, status badges, bar charts, and QR codes. A QR drawn as stroked outlines is unscannable, which is what led me here: I needed ZATCA (Saudi VAT) QR codes on invoices.

Changes

Path.Rectangle gains :fill:

Path.rectangle(path, lower_left: {10, 10}, dimensions: {40, 20}, fill: {0, 0.5, 1})
#=> q / 0 0.5 1 rg / 10 10 40 20 re / f / Q

rg sets the non-stroking colour, f paints the interior. Adding stroke: true emits B instead, filling and stroking in one operation so the two stay aligned:

Path.rectangle(path,
  lower_left: {10, 10}, dimensions: {40, 20},
  fill: {1, 1, 0}, colour: {0, 0, 0}, stroke: true, line_width: 2
)
#=> q / 1 1 0 rg / 0 0 0 RG / 2 w / 10 10 40 20 re / B / Q

stroke is an explicit flag rather than inferred from :colour, since :colour already defaults to black and there would be no way to tell "fill only" from "fill and outline in black".

Default behaviour is unchanged — without :fill, rectangles stroke exactly as before, and there is a test asserting that.

Verification

Four new tests in drawing_test.exs covering fill-only, fill+stroke, the unchanged stroke-only path, and many filled rectangles composing (the QR / bar-chart shape). test/drawing_test.exs is green: 12 tests, 0 failures.

The wider suite shows 21 failures both with and without this change on my machine — I am outside the Nix shell and substituted Google Fonts builds of Libre Bodoni/Franklin, whose metrics differ from the pinned ones. No new failures are introduced.

Happy to add Path.Line fill or a general close-and-fill in a follow-up if you would like the shape of it to be different.

🤖 Generated with Claude Code

Rectangles currently always emit `re` followed by `S`, so shapes can
only be outlined. That rules out anything built from solid colour:
table header backgrounds, status badges, bar charts, and QR codes —
a QR drawn as stroked outlines is unscannable.

Adds `:fill` to Path.Rectangle. With it, `rg` sets the non-stroking
colour and `f` paints the interior. `stroke: true` alongside it emits
`B` instead, filling and stroking in one operation so the two stay
aligned.

Default behaviour is unchanged: without `:fill`, rectangles stroke
exactly as before.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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