mgieseki / dvisvgm

A fast DVI, EPS, and PDF to SVG converter
https://dvisvgm.de
GNU General Public License v3.0
310 stars 34 forks source link

dvisvgm hangs when converting pdf with tikz pattern to svg #271

Closed samcarter closed 4 months ago

samcarter commented 4 months ago

Consider the following test document:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}

\begin{tikzpicture}
  \draw[
  pattern=fivepointed stars
  ] (0,0) rectangle (1,1);
\end{tikzpicture}

\end{document}

This works fine if processed via the dvi route with latex document.tex ; dvisvgm document.

However if I try to process this via the pdf route (pdflatex document.tex ; dvisvgm --pdf document), dvisvgm seems to hang indefinitely.

If I remove pattern=fivepointed stars, processing via the pdf route works fine as well.

Are there any other workarounds other than switching to the dvi route?


Environment:

muzimuzhi commented 4 months ago

It worked for me.

$ dvisvgm --pdf dvisvgm-gh271-hang-with-tikz-pattern.pdf
processing PDF file
  graphic size: 28.852794pt x 28.852794pt (10.140597mm x 10.140597mm)
  output written to dvisvgm-gh271-hang-with-tikz-pattern.svg
1 of 1 page converted in 4.70509 seconds

dvisvgm-gh271-hang-with-tikz-pattern

My environment:

Do you have mutool installed? If you use Homebrew then just check brew info mupdf.

samcarter commented 4 months ago

@muzimuzhi Thanks for testing!

I have mutool installed from homebrew:

==> mupdf: stable 1.23.11 (bottled), HEAD

dvisvgm -V1 gives

dvisvgm 3.2.2 (aarch64-apple-darwin20.6.0)
------------------------------------------
brotli:      1.1.0
clipper:     6.2.1
freetype:    2.13.2
Ghostscript: 10.03.1
kpathsea:    6.4.0
mutool:      1.23.11
potrace:     1.16
xxhash:      0.8.2
zlib:        1.3.1
samcarter commented 4 months ago

mutool itself seems to be able to access the file, something like mutool clean document.pdf works fine.

mgieseki commented 4 months ago

I can't reproduce the issue at the moment either. As the conversion usually seem to work and only hangs when using patterns, it's probably not an issue with mutool. However, without further insight it's difficult to find out what's causing this behavior.

samcarter commented 4 months ago

@mgieseki Thanks for taking a look!

It's not a very important problem as I have the dvi route as a workaround, but in case you can think of any further tests I could do to narrow down the problem, please let me know!

mgieseki commented 4 months ago

@samcarter Thank you for the offer. Do you have a build environment available and could compile a version of dvisvgm with some additional debug statements in it? That could give me some further insights.

Could you please also post the output of mutool draw -F trace test.pdf 1 where test.pdf is the problematic file? Maybe it contains different things than mine.

samcarter commented 4 months ago

Could you please also post the output of mutool draw -F trace test.pdf 1 where test.pdf is the problematic file? Maybe it contains different things than mine.

If I try with

document.pdf

mutool hangs after the following output:

<?xml version="1.0"?>
<document name="document.pdf">
<page mediabox="0 0 28.745 28.745">
<set_default_colorspaces gray="DeviceGray" rgb="DeviceRGB" cmyk="DeviceCMYK" oi="None"/>
<clip_path winding="nonzero" transform="1 0 0 -1 .199 28.546002">
    <moveto x="0" y="0"/>
    <lineto x="0" y="28.3468"/>
    <lineto x="28.3468" y="28.3468"/>
    <lineto x="28.3468" y="0"/>
    <closepath/>
    <moveto x="28.3468" y="28.3468"/>
</clip_path>
    <tile id="1610859072" area="-3.7859998 -3.7860013 32.5308 32.5308" view="0 8.50403 8.50403 0" xstep="8.50403" ystep="0" transform="1 0 0 -1 0 28.745">
        <fill_path winding="nonzero" colorspace="DeviceRGB" color="0 0 0" ri="1" bp="1" op="0" opm="0" transform="1 0 0 -1 0 28.745">
            <moveto x="5.53061" y="3.71063"/>
            <lineto x=".13872" y="3.71063"/>
            <lineto x="4.50082" y=".54137"/>
            <lineto x="2.83466" y="5.66933"/>
            <lineto x="1.16849" y=".54137"/>
            <closepath/>
        </fill_path>
    </tile>
<pop_clip/>
<stroke_path linewidth=".3985" miterlimit="10" linecap="0,0,0" linejoin="0" colorspace="DeviceGray" color="0" ri="1" bp="1" op="0" opm="0" transform="1 0 0 -1 .199 28.546002">
    <moveto x="0" y="0"/>
    <lineto x="0" y="28.3468"/>
    <lineto x="28.3468" y="28.3468"/>
    <lineto x="28.3468" y="0"/>
    <closepath/>
    <moveto x="28.3468" y="28.3468"/>
</stroke_path>
</page>

It never seems to reach the final </document>.

samcarter commented 4 months ago

@samcarter Thank you for the offer. Do you have a build environment available and could compile a version of dvisvgm with some additional debug statements in it? That could give me some further insights.

Unfortunately my attempt to build dvisvgm failed. When I tried to run autoreconf -fi I get a pop-up with

The "m4" command requires the command line developer tools. Would you like to install the tools now?

even though I already have them installed. Even installing them again does not help. Based on similar reports on the internet, there seem to be a problem with the current version with the command line dev tools. I'll give this another try when after the next update.

mgieseki commented 4 months ago

Ok, thanks for the info. It seems, you have a buggy version of mutool installed. Besides the hanging process, the output data is partly incorrect. The opening tile tag should look like this:

<tile id="0" area="-3.7859998 -3.7860013 32.5308 32.5308" view="0 0 8.50403 8.50403"
  xstep="8.50403" ystep="8.50403" transform="1 0 0 -1 0 28.745">

Especially, the ystep attribute must not be 0. Otherwise, there will be only a single row of tiles with the pattern graphic on it. The view values are in wrong order too. If there's a more recent version available for your system, I suggest to update mutool.

Unfortunately my attempt to build dvisvgm failed.

No problem. Thanks for trying, nonetheless. As the issue seems to be mutool here, it's not necessary to get more debug information from dvisvgm for now.

samcarter commented 4 months ago

Thank you so much for narrowing down the problem! I'll try to reinstall mutool!