mgieseki / dvisvgm

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

Wrong text in svg output when using Renderer = OpenType with lualatex #218

Closed zmanji closed 4 months ago

zmanji commented 1 year ago

Here is an example document

\documentclass[dvisvgm,preview]{standalone}

\usepackage{fontspec}

\setmainfont{OpenSans-Regular.ttf}

\begin{document}
Hello
\end{document}

On a latest tex live 2022 with dvisvgm 3.0.1 Running the following:

$ latexmk -dvilua -interaction=nonstopmode -halt-on-error

$ dvisvgm --zoom=-1 \
    --bbox=preview \
    --font-format=woff2,autohint \
    test.dvi

Produces a correct looking svg.

Screen Shot 2023-01-15 at 3 23 56 PM

However changing the document to use HarfBuzz:

\documentclass[dvisvgm,preview]{standalone}

\usepackage{fontspec}

\setmainfont[Renderer = OpenType]{OpenSans-Regular.ttf}

\begin{document}
Hello
\end{document}
$ latexmk -dvilua -interaction=nonstopmode -halt-on-error

$ dvisvgm --zoom=-1 \
    --bbox=preview \
    --font-format=woff2,autohint \
    test.dvi

Produces an svg that uses the wrong glyphs

Screen Shot 2023-01-15 at 3 25 46 PM
mgieseki commented 1 year ago

The reason for this is the following font definition present in the DVI file of the second example:

fntdef: [OpenSans-Regular.ttf]:mode=harf;shaper=ot;script=latn;language=dflt;+tlig; at 10pt

This is a LuaTeX-specific fntdef format that dvisvgm doesn't support. LuaTeX needed to resolve the character encodings and write the glyph indices to the DVI file, as done for the first example. Otherwise, dvisvgm can't process the file correctly.

zmanji commented 1 year ago

I have sent the following message:

I have run into a bug when using HarfBuzz and dvilualatex.

When the following document is compiled with dvilualatex

\documentclass{minimal}
\usepackage{fontspec}
\setmainfont[Renderer = OpenType]{OpenSans-Regular.ttf
}
\begin{document}
Hello
\end{document}

The produced DVI file cannot be handled by dvipdfmx. Running dvipdfmx produces
the following error:

dvipdfmx:fatal: Unable to find TFM file
"[OpenSans-Regular.ttf]:mode=harf;shaper=ot;script=latn;language=dflt;+tlig;".

Removing '[Render = OpenType]' and running dvipdfmx on the resulting
dvi file works fine.

to the dev-luatex@ntg.nl mailing list. Hopefully once this message is approved someone will respond to this issue.