belluzj / fantasque-sans

A font family with a great monospaced variant for programmers.
http://openfontlibrary.org/en/font/fantasque-sans-mono
SIL Open Font License 1.1
6.97k stars 154 forks source link

PDF/A validation fails with OTF fonts #162

Open lenoleno opened 1 year ago

lenoleno commented 1 year ago

Compiling a LaTeX document using Fantasque Sans Mono font with the LuaLaTeX engine, the output fails PDF/A validation with the veraPDF software when using (any of the) OTF font variants in the LaTeX document. It works using (any of the) TTF font variants, though.

Symptom:

veraPDF seems to complain about inconsistent font metrics (see last line):

Specification: ISO 19005-1:2005, Clause: 6.3.6, Test number: 1
For every font embedded in a conforming file and used for rendering, the glyph width information in the font dictionary and in the embedded font program shall be consistent. Failed 4 occurrences
Glyph renderingMode == 3 || widthFromFontProgram == null || widthFromDictionary == null || Math.abs(widthFromFontProgram - widthFromDictionary) <= 1
root/document[0]/pages[0](5 0 obj PDPage)/contentStream[0](7 0 obj PDContentStream)/operators[11]/usedGlyphs[1](CGGIZD+FantasqueSansMono-Regular CGGIZD+FantasqueSansMono-Regular 70 0 0) Glyph width 1060 in the embedded font program is not consistent with the Widths entry of the font dictionary (value 517.6)

System:

Steps to reproduce:

  1. Install TeXLive: The attached LaTeX document uses the LuaLaTeX engine and package pdfx to output PDF/A compliant files. Make sure, the following Ubuntu packages are installed (plus additional dependencies):

    • texlive-latex-base
    • texlive-luatex
    • texlive-latex-recommended
    • texlive-latex-extra

    Be warned that total installation size may be more than 500 MB!

  2. Install Java Runtime: E.g. via command apt install openjdk-11-jre.

  3. Install the free PDF validation software veraPDF (requires Java):

    1. Download installation package from here.

      Note, there are two flavours of the veraPDF validation engine, greenfield (gf) and pdfbox. Stick to the greenfield flavour, which is the more recent one.

    2. Unzip the downloaded veraPDF ZIP archive.

    3. Run the extracted verapdf-install script in a terminal.

    4. Follow the installation procedure. (Install veraPDF into any user-writable directory, e.g., $HOME/veraPDF-<version>-gf/. Uninstallation is as easy as removing the installation directory. Default installation "packs" selection is OK.)

  4. Compile the attached LaTeX document:

    E.g., via command

    $ lualatex bug-pdfa.tex

    Note, at the end of terminal output, the actual paths font files where taken from are shown, e.g.:

    </usr/share/fonts/opentype/fantasque-sans/Normal/OTF/FantasqueSansMono-Regular.
    otf>
  5. Validate PDF/A conformance:

    $ $HOME/verapdf-<version>-gf/verapdf --format text bug-pdfa.pdf
    FAIL bug-pdfa.pdf

    Note, the --format text option only shows a FAIL or PASS message. To see the actual error message, try with different --format option arguments (see verapdf --help) or use the verapdf-gui programme (from the veraPDF installation directory), which lets you easily open a HTML report in the browser.

  6. Repeat the last two steps with varying Path arguments in the .tex source file. The .tex file contains 16 alternative Extension/Path argument lines for the four OTF font variants, four TTF font variants (all picked-up from a system-wide installation), and then the same eight font variants picked-up from the local repository. Please run make all in the top-level repository directory first, if you want to try the latter. Adjust all Path arguments in the .tex source file as needed.

    Note, for repeated tests on the shell, I use the following invocation:

    $ lualatex bug-pdfa.tex | tail -20 | awk "/^</,/^Output/" && verapdf --format text bug-pdfa.pdf

    which just extracts font paths from LaTeX terminal output and does PDF/A validation in one go. For this to work, I actually have a link from the verapdf binary to $HOME/bin/verapdf. But you can as well apply the full path to your verapdf binary in the command.

Can anyone reproduce this?

lenoleno commented 1 year ago

Here's the LaTeX source file. Save as bug-pdfa.tex.

Thank you, Microsoft, for banning .tex files from GitHub!

\documentclass[a4paper]{article}
\usepackage[a-1b]{pdfx}
\usepackage{fontspec}
\setmainfont[
  % All OTF fonts fail PDF/A validation.
  %
  % Paths from Ubuntu package fonts-fantasque-sans:
  %  Extension = .otf, Path=/usr/share/fonts/opentype/fantasque-sans/LargeLineHeight/OTF/,
  %  Extension = .otf, Path=/usr/share/fonts/opentype/fantasque-sans/LargeLineHeight-NoLoopK/OTF/,
  Extension = .otf, Path=/usr/share/fonts/opentype/fantasque-sans/Normal/OTF/,
  %  Extension = .otf, Path=/usr/share/fonts/opentype/fantasque-sans/NoLoopK/OTF/,
  % Local paths:
  %  Extension = .otf, Path=../Variants/LargeLineHeight/OTF/,
  %  Extension = .otf, Path=../Variants/LargeLineHeight-NoLoopK/OTF/,
  %  Extension = .otf, Path=../Variants/Normal/OTF/,
  %  Extension = .otf, Path=../Variants/NoLoopK/OTF/,
  %
  % All TTF fonts pass PDF/A validation.
  %
  % Paths from Ubuntu package fonts-fantasque-sans:
  %  Extension = .ttf, Path=/usr/share/fonts/truetype/fantasque-sans/LargeLineHeight/TTF/,
  %  Extension = .ttf, Path=/usr/share/fonts/truetype/fantasque-sans/LargeLineHeight-NoLoopK/TTF/,
  %  Extension = .ttf, Path=/usr/share/fonts/truetype/fantasque-sans/Normal/TTF/,
  %  Extension = .ttf, Path=/usr/share/fonts/truetype/fantasque-sans/NoLoopK/TTF/,
  % Local paths:
  %  Extension = .ttf, Path=../Variants/LargeLineHeight/TTF/,
  %  Extension = .ttf, Path=../Variants/LargeLineHeight-NoLoopK/TTF/,
  %  Extension = .ttf, Path=../Variants/Normal/TTF/,
  %  Extension = .ttf, Path=../Variants/NoLoopK/TTF/,
  %
  UprightFont = *-Regular,
  ItalicFont = *-Italic,
  BoldFont = *-Bold,
  BoldItalicFont = *-BoldItalic,
]{Fantasque Sans Mono}
\begin{document}
text
\end{document}
lenoleno commented 1 year ago

As shown in the .tex file, with LuaLaTeX (or the LaTeX fontspec package), one can determine which font format to use and the exact path from which to take font files.

The situation becomes worse when using GUI text processors, like LibreOffice, where you have hard time directing the application what font file to pick if more than one files exist with the same font name.

One workaround is manually removing all OTF files after installation of Ubuntu package fonts-fantasque-sans. Which requires administrator privileges and knowledge about system font installation paths and may not be a smooth task for Joe Average.