mgieseki / dvisvgm

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

Issues with the "focused ion beam system" example #225

Closed rfdonnelly closed 1 year ago

rfdonnelly commented 1 year ago

Hello, I am having issues with converting this example: https://texample.net/tikz/examples/focused-ion-beam-system/

The FAQ shows that it renders correctly for Chrome:

chrome_ywC5mKxpx6

But I get this instead:

I get a similarly bad (if not the same) result in Firefox.

More Results

I tried various combinations of dvisvgm version and ghostscript version. All have the same issue.

Type alpine-3.16-dvisvgm-3.0.2-gs-9.56.1.svg alpine-3.17-dvisvgm-3.0.2-gs-10.00.0.svg texlive-docker-dvisvgm-2.13.3-gs-10.00.0.svg
SVG
PNG Screenshot (Chrome 109.0.5414.120)

Steps to Reproduce

  1. Copy the example from https://texample.net/tikz/examples/focused-ion-beam-system/ verbatim into input.tex
  2. latex input.tex
  3. dvisvgm --font-format=woff input.dvi
muzimuzhi commented 1 year ago

Just after step 1, adding class option dvisvgm to \documentclass{minimal} works for me on macOS with latest texlive 2022 and dvisvgm 2.13.3.

The reason is, tikz need to know the name of backend. See related tikz doc https://tikz.dev/drivers#sec-10.2.4 (html but unofficial).

mgieseki commented 1 year ago

It seems, TikZ changed some internals which now create different PostScript code. The background shading applied in the example is now realized by axial shading patterns which dvisvgm don't support yet. Formerly, the gradients were approximated by sequences of differently colored lines or rectangles. I still have an old DVI file of this TikZ example and were able to compare the two files:

Here's an excerpt of the affected parts:

Old PS code:

100.00128 100.00128 pgfV 75.00096 0.6 0.6 0.6 0.6 0.6 0.6 pgfshade 50.00064 0.6 0.6 0.6 0.75 0.75 0.75 pgfshade 25.00032 0.75 0.75 0.75 0.9 0.9 0.9 pgfshade 0.0 0.9 0.9 0.9 0.9 0.9 0.9 pgfshade  pop

New PS code:

100.00128 100.00128 0 0 pgfe << /PatternType 2 /Shading << /ShadingType 2 /ColorSpace /DeviceRGB /Domain [0.0 100.00128] /Coords [0 0.0 0 100.00128] /Function << /FunctionType 3 /Domain [0.0 100.00128] /Functions [ << /FunctionType 2 /Domain [0.0 100.00128] /C0 [0.9 0.9 0.9] /C1 [0.9 0.9 0.9] /N 1 >>  << /FunctionType 2 /Domain [0.0 100.00128] /C0 [0.9 0.9 0.9] /C1 [0.75 0.75 0.75] /N 1 >>  << /FunctionType 2 /Domain [0.0 100.00128] /C0 [0.75 0.75 0.75] /C1 [0.6 0.6 0.6] /N 1 >>  << /FunctionType 2 /Domain [0.0 100.00128] /C0 [0.6 0.6 0.6] /C1 [0.6 0.6 0.6] /N 1 >>  ] /Bounds [ 25.00032 50.00064 75.00096] /Encode [0 1  0 1 0 1 0 1] >> >> >> matrix makepattern setpattern fill

As @muzimuzhi wrote above, you can get proper results with document class option dvisvgm.

rfdonnelly commented 1 year ago

Thank you @muzimuzhi and @mgieseki! That fixed it. I just read that section of the TikZ doc too but didn't think to try it.

To be explicit, here are the revised steps:

  1. Copy the example from https://texample.net/tikz/examples/focused-ion-beam-system/ verbatim into input.tex

  2. Modify as follows:

    --- a/examples/focused-ion-beam-system/input.tex
    +++ b/examples/focused-ion-beam-system/input.tex
    @@ -2,7 +2,7 @@
    
    % Focused ion beam system
    % Author: Clemens Helfmeier
    -\documentclass{minimal}
    +\documentclass[dvisvgm]{minimal}
    \usepackage[utf8]{inputenc}
    \usepackage{tikz}
    \usetikzlibrary{arrows,decorations.pathmorphing}
  3. latex input.tex

  4. dvisvgm --font-format=woff input.dvi

rfdonnelly commented 1 year ago

Side note: Both pdf2svg and pdftocairo produce an SVG that is 1.4MB while dvisvgm produces an SVG that is 70KB. Amazing!

muzimuzhi commented 1 year ago

It seems, TikZ changed some internals which now create different PostScript code.

@mgieseki Seems it took place in https://github.com/pgf-tikz/pgf/pull/907 and was shipped with pgf-tikz v3.1.6 (Sep 29, 2020).

agrahn commented 1 year ago

It seems, TikZ changed some internals which now create different PostScript code. The background shading applied in the example is now realized by axial shading patterns which dvisvgm don't support yet.

Yes, that's my fault. I implemented PS-3 shadings into the dvips driver code of pgf in August 2020. I did this for their better visual quality and smaller file size.

mgieseki commented 1 year ago

It's not a fault, of course. 😀 Since there is now a dedicated dvisvgm backend for TikZ, the changes in the PS backend don't really matter any longer, and the real gradients actually look much better than the old approximated ones.