Repository navigation
feat: PageSVG, an SVG device behind the device seam - #140
Merged
Merged
Conversation
tannevaled
force-pushed
the
svg-device
branch
from
November 22, 2026 12:09
750aaef to
cce1b2b
Compare
This was referenced Nov 22, 2026
Open
PageSVG(d, i, w, SVGOptions) writes a page as SVG through a second implementation of the device interface: paths, clips, images, groups and text (as outlines, one <path> per glyph, <use> per letter). What SVG 1.1 cannot say (tiling and shading patterns, shadings, soft masks, groups under a mask) is drawn by the rasteriser on a white and a black paper and embedded as an <image> where it falls. The document holds only numbers, generated ids and base64: href is #id or a data:image/(png|jpeg);base64, URI, never script, foreignObject, style or on* attributes, never NaN or Inf. Every document the suite draws is also written as SVG and held to that allowlist; FuzzPageSVG does the same for any content stream. Output is bounded by MaxBytes (ErrSVGTooLarge, nothing written), pictures by a pixel cap, time by MaxDuration. Raster output is unchanged: hashes of ten pages are identical to e54313c. Known render bugs are referenced, not fixed (#137, #138). Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The four guards mutsweep could only see as a panic are asserted by tests that sit first in the package and turn a crash into a failure. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ny error The SVG device keeps its open groups as values on a stack and never a *gstate past its run. clipPath ignores the rectangle the seam now carries. PageSVG builds the document in memory, bounded by MaxBytes, and writes it in one call: ErrSVGTooLarge, ErrTimedOut and every other error leave w empty. A test counts the bytes and the calls on each error path. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ns, check the allowlist in production - The rasteriser's clip is narrowed by the SVG device too, so a fallback picture (shading, pattern, soft mask, group) is read back, hashed and embedded over the clip box only, in one reused buffer. - The sh operator painted a grid of the whole page per call; it is now the clip box (pattern.go). Pixels are unchanged: 965 of 965 corpus pages identical to e54313c. - Equal pictures are defined once and used where they fall (sha256 of the pixels). - A rectangle clip inside a rectangle clip is their intersection; other clips nest at most 64 deep (ErrSVGTooDeep, nothing written). - verifySVG reads the finished buffer against the allowlist before it is written, with no allocation but the ids. - MaxDuration defaults to ten seconds. - TestASmallFileCannotAskForMuchMemoryOrOutput asserts allocated and written bytes against stated constants, under default options. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…mutsweep The unterminated-value guard was the same refusal as the one at the end of the element and is removed; the quote guard gets the case that tells it from the code after it. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
tannevaled
force-pushed
the
svg-device
branch
from
November 22, 2026 16:52
b34281a to
1b94d70
Compare
…ts off the wall clock overrun() read the clock only once every 256 operators and never when a page ended, so a page with fewer operators was never measured: a 200- operator page under a 1 ns MaxDuration returned nil on Windows. The page now reads the clock once when it ends (late()), and the deadline and the check go through a replaceable clock, so the test uses a fake clock instead of wall time. TestANestOfRectanglesIsOneClip and the twenty-thousand-clips case test clip collapsing and output bounds, not time; under qemu they ran into the new 10 s default. They now pass MaxDuration: time.Hour. Their clip and allocation assertions are unchanged. Refs #142 (the stride still lets a few expensive operators overrun). Co-Authored-By: Claude Opus 5.5 <[email protected]>
tannevaled
force-pushed
the
svg-device
branch
from
November 22, 2026 17:16
1f341ef to
310e857
Compare
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.
Second of the "PDF to SVG" series, stacked on #139 (base
device-seam; retarget to main once #139 merges).Refs #139, #137, #138
What
render.PageSVG(d, i, w, SVGOptions{MaxBytes, RasterScale, MaxDuration}), written as a second implementation of thedeviceinterface. Paths, clips, images, faded groups and text (outlines, one definition per glyph, a use per letter) become SVG elements. Tiling and shading patterns, shadings, soft masks and groups under a mask are drawn by the rasteriser on a white and a black paper and embedded as an image where they fall.The device is adapted to the seam as it stands in #139 (rebased onto
2edc683): open groups are values on a stack in the device, no*gstateis kept past its run, andclipPathignores the rectangle the seam carries.Security
hrefis#idordata:image/(png|jpeg);base64,; no script, foreignObject, style or on* attribute.verifySVG(svgverify.go) reads the finished buffer, element by element and attribute by attribute (shape of every value, no text, matching tags, unique ids, every reference defined) before it is written, andPageSVGrefuses with nothing written if anything is off it. It is a hand-written scanner over the bytes: 221 allocations for a 35 KB document with 200 ids and 200 references (one per id, none per element or byte; asserted by a test). The independentencoding/xmlchecker stays in the tests and every document the suite draws is held to both.FuzzPageSVGdoes the same for any content stream.ErrSVGTooLarge; embedded pictures are capped at 16 Mpixel; RasterScale defaults to 2; MaxDuration defaults to 10 s (ErrTimedOut); clips nested deeper than 64 giveErrSVGTooDeep.w(except a failing writer): the document is built in memory, bounded by MaxBytes, and written in one call.Review round (cce1b2b to b34281a)
shoperator itself painted a coverage grid of the whole page per call (wholeClip, pattern.go); it is now the clip box. Raster pixels unchanged (965 of 965 corpus pages identical to e54313c, rerun on this head).shunder0 0 1 1 re W n0 0 100 100 re W nTestASmallFileCannotAskForMuchMemoryOrOutputasserts, for these four, allocated <= 16 B per page pixel + 2000 B per input byte, and written <= 4 KiB + 16 B per input byte. About 185 MiB of the allocation is the floor of a 16 Mpixel page (the rasteriser's image, painted grid, white and black papers).wholeClipchanged there, caught).mutool draw -F svg: DEFERRED, 1-minute load was about 25-30 (limit 8). CI has not run on the basedevice-seam.Seam changes
userPath.glyph,gstate.svgClip,renderPageWith(device chosen after the renderer exists), soft-mask forms are always drawn by the rasteriser, andwholeClipis the clip box.Not done, referenced
Text render modes 4-7 (#137) and blend modes (#138) are not handled, as in the rasteriser. Knockout groups are not read. See the README section for the full list.
🤖 Generated with Claude Code