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

Wrong clipping and viewport with multiple pages converted at once #268

Closed michal-h21 closed 3 months ago

michal-h21 commented 3 months ago

I've got a report that code in this answer of mine stopped working correctly. Two TikZ ornaments are produced, but the second one is clipped, so only a small arc is displayed. I've found that if I don't use the dvisvgm_hashes extension provided by make4ht, both pictures look correctly. The difference is that by default, make4ht runs separate call to dvisvgm for each converted picture, but with dvisvgm_hashes, it lists all pages to be converted at one using the -p option.

Here is a MWE:

\documentclass{scrbook}

\usepackage{blindtext}
\usepackage{pgfornament}
\tikzset{
  alt/.store in=\myalt,
  hclass/.store in=\myclass
}
\title{Some Book}
\subtitle{A novel}
\author{Some Author}

\begin{document}

\chapter{Chapter One}
\blindtext{}
\begin{center}
 \begin{tikzpicture}[alt=Separator,hclass=separator]
  \node {\pgfornament[height=1cm]{79}};
 \end{tikzpicture}
\end{center}

\blindtext{}
\begin{center}
 \begin{tikzpicture}[alt=Endmarker,hclass=endmarker]
  \node {\pgfornament[height=1cm]{75}};
 \end{tikzpicture}
\end{center}

\end{document}

OP wants to add a custom alt and class attributes, so I've created a following configuration file, config.cfg:

\Preamble{xhtml}
\begin{document}
\makeatletter
\ConfigureEnv{tikzpicture}{}{}{}{}{}
\def\texfourht@tikz@begin{}
\def\texfourht@tikz@end{}
\AddToHook{env/tikzpicture/begin}{\ifdefined\myalt\ifvmode\Picture*[\myalt]{ class="\myclass"}\else\Picture+[\myalt]{ class="\myclass"}\fi\def\inside@pict@cmd{}\fi}
\AddToHook{env/tikzpicture/end}{\ifdefined\EndPicture\EndPicture\fi}

\makeatother
\EndPreamble

It can be compiled using this command:

$ make4ht  -c config.cfg -f html5+dvisvgm_hashes -m draft -a debug  sample.tex

And this is the result:

image

The images are stored in a special DVI file, sample.idv. The wrong ornament is on page 4.

When I convert this image separately, using this command, I get a correct result:

$ dvisvgm -n -p 4 --exact -c 1.4,1.4  sample.idv
pre-processing DVI file (format version 2)
processing page 4
  graphic size: 123.815633pt x 39.83558pt (43.516218mm x 14.000605mm)
  output written to sample-4.svg
1 of 5 pages converted in 0.650288 seconds

But when I specify more pages with the -p option, the result is wrong:

$ dvisvgm -n -p 2,4 --exact -c 1.4,1.4  sample.idv
pre-processing DVI file (format version 2)
processing page 2
  graphic size: 81.235535pt x 40.444842pt (28.551025mm x 14.214736mm)
  output written to sample-2.svg
processing page 4
  graphic size: 160.108705pt x 917.342326pt (56.271774mm x 322.408954mm)
  output written to sample-4.svg
2 of 5 pages converted in 0.400443 seconds

You can see that especially the height is completely wrong, but only for the second image, the first image is correct.

mgieseki commented 3 months ago

Thank you for reporting this issue. The second page gets wrong extents because the transformation matrix is not re-initialized at the beginning of the page. I'll commit the patch shortly.

michal-h21 commented 3 months ago

Great, thank you!