Bug 695988 - SVG should use a pattern fill instead of large number of separate elements
Summary: SVG should use a pattern fill instead of large number of separate elements
Status: RESOLVED WONTFIX
Alias: None
Product: MuPDF
Classification: Unclassified
Component: svg output (show other bugs)
Version: 1.6
Hardware: PC Linux
: P4 normal
Assignee: Robin Watts
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-13 21:27 UTC by Ofir
Modified: 2018-07-06 18:11 UTC (History)
0 users

See Also:
Customer:
Word Size: ---


Attachments
PDF with a pattern fill (250.24 KB, application/pdf)
2015-05-13 21:27 UTC, Ofir
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ofir 2015-05-13 21:27:03 UTC
Created attachment 11682 [details]
PDF with a pattern fill

The attached 250KB PDF is converted to a 45MB SVG because a pattern fill is converted to a large number of separate identical elements instead of using a pattern.

Tested with mupdf-tools 1.6.1, Ubuntu 15.04
mudraw -o test.svg Flow-background.pdf
Comment 1 Robin Watts 2015-06-12 10:35:25 UTC
This doesn't look to be a pattern fill to me.
Comment 2 Ofir 2015-07-15 11:32:35 UTC
@Robin, it might not be a pattern fill issue but there is an issue here.
A 250KB PDF is converted to a 45MB SVG.
SVG viewers trying to display it choke.
Comment 3 Robin Watts 2018-07-06 18:11:04 UTC
The original PDF file contains many, many instances of an image (Img4), with a softmask implicit in it. An excerpt from the content stream:

q 2.4 0 0 2.4 36.1 592.6 cm
/Im4 Do Q

repeated many hundred times.

Within SVG this converts to:

<mask id="ma23">
<g transform="matrix(.48000003,0,0,.48000003,45.8,.000024318695)">
<use xlink:href="#im3" x="0" y="0" width="5" height="5"/>
</g>
</mask>
<g mask="url(#ma23)">
<g transform="matrix(.48000003,0,0,.48000003,45.8,.000024318695)">
<use xlink:href="#im4" x="0" y="0" width="5" height="5"/>
</g>
</g>

i.e. it sets up the mask and then applies it to the image.

The textual version in SVG is clearly larger than that in the PDF, and the stream in the PDF gets compressed to save space. That alone explains the differences.

It is possible that we could come up with some way to shrink the SVG a bit by spotting that the mask and image are always used together, and to emit a smaller chunk of text (maybe 50% smaller) each time, but a) this isn't easy because of the architecture of MuPDF, and b) this wouldn't make it any easier for SVG renderers to cope with.

Fundamentally, the problem is with the way the original file was authored.

I don't think there is much we can do here.