2

If I process the file

\documentclass{standalone}
\usepackage{DejaVuSans}
\renewcommand*\familydefault{\sfdefault}
\usepackage[T1]{fontenc}
\begin{document}
\fontsize{9mm}{10mm}\selectfont
{\bfseries aceimnorsuvwxz}
\end{document}

using the Makefile

run:
    xelatex --no-pdf file
    dvisvgm file.xdv
    open file.svg

I get a troublesome SVG file that:

  • is clipped at the baseline, due to an incorrect viewBox
  • looks almost fine with Safari,

safari

but wrong with Chrome.

chrome

How can I fix both problems?

The presence of descenders lowers the clipping line, but the two issues remain.

Using: - dvisvgm 2.1.3 - XeTeX, Version 3.14159265-2.6-0.99998 (TeX Live 2017) - macOS 10.13.6

Calaf
  • 1,471

1 Answers1

1

The FAQ of dvisvgm mentions the following:

The generated SVG is most likely valid but your SVG viewer/editor probably doesn’t support embedded fonts. Actually, only few SVG renderers, e.g. Apache Batik and the Opera web browser evaluate embedded fonts properly (also see the screenshots). You can run dvisvgm with option --no-fonts to replace the fonts with path elements. Most viewers should render the resulting SVG files correctly. As a drawback, you get bigger files, and the information about the text (characters, baselines, …) gets lost.

As of version 2.0, dvisvgm provides the command-line option --font-format that allows to change the format used for embedded fonts from SVG to WOFF, WOFF2 or TrueType. If you call dvisvgm with option --font-format=woff, you should get SVG files that render correctly in almost all recent web browsers. Moreover, and in contrast to option --no-fonts, all text properties are retained.

Indeed I could reproduce your issue with Chrome, but with WOFF the output was correct.

MWE:

\documentclass{standalone}
\usepackage{DejaVuSans}
\renewcommand*\familydefault{\sfdefault}
\usepackage[T1]{fontenc}
\begin{document}
\fontsize{9mm}{10mm}\selectfont
{\bfseries aceimnorsuvwxz}aceimnorsuvwxz
\end{document}

Command line:

dvisvgm --font-format=woff xdvconv.xdv

Note that I used version 2.8 of dvisvgm, but according to the FAQ it should work with earlier versions as well.

Result:

enter image description here

Marijn
  • 37,699
  • 2
    Also add option--exact, as it enlarges the document BBox to completely encompass the glyphs. (By default, dvisvgm's automatic BBox calculation is based on glyph box dimensions which often tend to be smaller than the glyphs themselves.) This makes the border document option redundant. – AlexG Nov 10 '19 at 18:31
  • @Calaf With --font-formt=woff, text is searchable and copiable. – AlexG Nov 10 '19 at 21:23