From 10115489f8988cf6a649707202a51757708883a2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 00:59:53 -0300 Subject: svg: an image that is an SVG document in a data URI is drawn Typst places an SVG image, and a PDF page imported with image(), as an whose href is the document in base64; svg.zig skipped every , so any Typst object holding one silently lost it. The parser now decodes such a document and walks it into the same drawing, mapped into the image's x, y, width and height (stretched with preserveAspectRatio="none", else fitted and centered, as SVG says), with its own ids, gradients and percentages and nothing inherited from around it but opacity. It is not clipped to its box (a PDF page never draws outside itself, and a clip per shape costs the renderers a pass over every contour). Raster images still draw nothing. The root's view box and size come from one function both documents use. Tests: a unit test at the end of svg.zig (ids of its own, stretched and fitted corners, a PNG skipped); two corpus cases for zig build diff, image.svg (two data-URI images, one stretched and turned, beside an outer gradient that shares an id with an inner one) and typst-image.typ (two SVGs placed by Typst): both renderers match resvg (mean 0.09-0.11). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- test/svg/image.svg | 9 +++++++++ test/svg/typst-image.typ | 6 ++++++ 2 files changed, 15 insertions(+) create mode 100644 test/svg/image.svg create mode 100644 test/svg/typst-image.typ (limited to 'test/svg') diff --git a/test/svg/image.svg b/test/svg/image.svg new file mode 100644 index 0000000..f5a5d8e --- /dev/null +++ b/test/svg/image.svg @@ -0,0 +1,9 @@ + + + + + + + diff --git a/test/svg/typst-image.typ b/test/svg/typst-image.typ new file mode 100644 index 0000000..2c88207 --- /dev/null +++ b/test/svg/typst-image.typ @@ -0,0 +1,6 @@ +// An SVG placed by Typst: an with the document as a data URI. +#set page(width: auto, height: auto, margin: 6pt, fill: none) +#stack(dir: ltr, spacing: 8pt, + image("use.svg", width: 120pt), + image("gradients.svg", width: 80pt, height: 60pt, fit: "stretch"), +) -- cgit v1.3