Repository navigation
Description
Description
When a PDF image contains two tiling patterns whose stream dictionaries are byte-identical but whose content streams differ, and both are painted under the same transformation, SVG export fills both areas with the first pattern.
The problem seems isolated to SVG. PDF and PNG export render the image correctly.
Here's my attempt at a minimal reproducible example (the PDF is embedded as bytes so there are no external dependencies).
#set page(width: auto, height: auto, margin: 0pt)
#image(bytes("%PDF-1.7
1 0 obj
<< /Type /Catalog /Pages 2 0 R >>
endobj
2 0 obj
<< /Type /Pages /Kids [3 0 R] /Count 1 >>
endobj
3 0 obj
<< /Type /Page /Parent 2 0 R /MediaBox [0 0 130 60] /Resources << /Pattern << /P1 5 0 R /P2 6 0 R >> >> /Contents 4 0 R >>
endobj
4 0 obj
<< /Length 70 >>
stream
/Pattern cs /P1 scn 0 0 60 60 re f
/Pattern cs /P2 scn 70 0 60 60 re f
endstream
endobj
5 0 obj
<< /Type /Pattern /PatternType 1 /PaintType 1 /TilingType 1 /BBox [0 0 10 10] /XStep 10 /YStep 10 /Resources << >> /Length 23 >>
stream
1 0 0 rg 0 0 10 10 re f
endstream
endobj
6 0 obj
<< /Type /Pattern /PatternType 1 /PaintType 1 /TilingType 1 /BBox [0 0 10 10] /XStep 10 /YStep 10 /Resources << >> /Length 23 >>
stream
0 0 1 rg 0 0 10 10 re f
endstream
endobj
xref
0 7
0000000000 65535 f
0000000009 00000 n
0000000058 00000 n
0000000115 00000 n
0000000253 00000 n
0000000373 00000 n
0000000558 00000 n
trailer
<< /Size 7 /Root 1 0 R >>
startxref
743
%%EOF
"))The same is also attached as patterns.pdf:
The page has two squares. The left one is filled with tiling pattern /P1, which paints red, and the right one with /P2, which paints blue. The two pattern dictionaries are identical, including /Length 23; only the color operator in their content streams differs (1 0 0 rg vs. 0 0 1 rg).
typst compile --format svg repro.typ out.svg produces an SVG in which both squares are red: the nested SVG that Typst emits for the image defines a single <pattern> (red), and both squares' paths are filled with it. typst compile repro.typ out.pdf and typst compile --format png repro.typ out.png show a red and a blue square, and so does MuPDF when rendering patterns.pdf directly.
Left: PNG export. Right: SVG export, rendered with resvg.
In a variant where the content stream of /P2 has one trailing space, so that its /Length is 24 and the dictionaries differ, the SVG output is correct.
I ran into this with a matplotlib-generated PDF: its hatch patterns are compressed tiling patterns whose streams also paint the bar's face color. Two of them (face colors #8AE08D and #E08BAA) had compressed streams of the same length and otherwise byte-identical dictionaries, and in SVG export the bars with the second hatch pattern were drawn with the first.
My best guess of the cause is hayro. Typst 0.15.1 uses hayro-svg 0.7.0 and hayro-interpret 0.7.0. hayro-svg caches tiling patterns by (pattern, inverse_transform).cache_key(), and a TilingPattern's key is its stream's key. In hayro-interpret 0.7.0, impl CacheKey for Stream hashes only the stream's dictionary, so two pattern streams with identical dictionaries painted under the same transformation get the same key, which matches the single <pattern> in the output.
LaurenzV/hayro#1592 changed the stream key to the object identifier; that change is in hayro-interpret 0.9.0. I have not tested whether it fixes this reproduction. Typst main (as of 84cca40) pins hayro at LaurenzV/hayro@a728f7cb, which predates that PR. I have only tested Typst 0.15.1 (Homebrew build) on macOS.
Operating system
macOS
Typst version
- I am using the latest version of Typst
Activity
LaurenzV commentedon Nov 14, 2026
Yep seems like it's already fixed in hayro.