1

docs: Detect variable fonts and suggest denylisting them

Fedora and openSUSE has started deploying "variable font" [1] format
Noto CJK fonts [2, 3].  "CJK" here stands for "Chinese, Japanese,
and Korean".

Unfortunately, XeTeX/XeLaTeX doesn't understand those fonts for
historical reasons and builds of translations.pdf end up in errors
if such fonts are present on the build host.

To help developers work around the issue, add a script to check the
presence of "variable font" Noto CJK fonts and to emit suggestions.
The script is invoked in the error path of "make pdfdocs" so that the
suggestions are made only when a PDF build actually fails.

The first suggestion is to denylist those "variable font" files by
activating a per-user and command-local fontconfig setting.

For further info and backgrounds, please refer to the header comment
of scripts/check-variable-font.sh newly added in this commit.

Link: [1] https://en.wikipedia.org/wiki/Variable_font
Link: [2] https://fedoraproject.org/wiki/Changes/Noto_CJK_Variable_Fonts
Link: [3] https://build.opensuse.org/request/show/1157217
Reported-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/8734tqsrt7.fsf@meer.lwn.net/
Reported-by: Иван Иванович <relect@bk.ru>
Link: https://lore.kernel.org/linux-doc/1708585803.600323099@f111.i.mail.ru/
Cc: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/20240406020416.25096-1-akiyks@gmail.com
This commit is contained in:
Akira Yokosawa 2024-04-06 11:04:16 +09:00 committed by Jonathan Corbet
parent 9e192b39a5
commit 1e596d5eff
4 changed files with 129 additions and 5 deletions

View File

@ -28,6 +28,10 @@ BUILDDIR = $(obj)/output
PDFLATEX = xelatex
LATEXOPTS = -interaction=batchmode -no-shell-escape
# For denylisting "variable font" files
# Can be overridden by setting as an env variable
FONTS_CONF_DENY_VF ?= $(HOME)/deny-vf
ifeq ($(findstring 1, $(KBUILD_VERBOSE)),)
SPHINXOPTS += "-q"
endif
@ -151,10 +155,11 @@ pdfdocs:
else # HAVE_PDFLATEX
pdfdocs: DENY_VF = XDG_CONFIG_HOME=$(FONTS_CONF_DENY_VF)
pdfdocs: latexdocs
@$(srctree)/scripts/sphinx-pre-install --version-check
$(foreach var,$(SPHINXDIRS), \
$(MAKE) PDFLATEX="$(PDFLATEX)" LATEXOPTS="$(LATEXOPTS)" -C $(BUILDDIR)/$(var)/latex || exit; \
$(MAKE) PDFLATEX="$(PDFLATEX)" LATEXOPTS="$(LATEXOPTS)" $(DENY_VF) -C $(BUILDDIR)/$(var)/latex || sh $(srctree)/scripts/check-variable-fonts.sh || exit; \
mkdir -p $(BUILDDIR)/$(var)/pdf; \
mv $(subst .tex,.pdf,$(wildcard $(BUILDDIR)/$(var)/latex/*.tex)) $(BUILDDIR)/$(var)/pdf/; \
)

View File

@ -215,11 +215,12 @@
due to the lack of suitable font families and/or the texlive-xecjk
package.
If you want them, please install ``Noto Sans CJK'' font families
along with the texlive-xecjk package by following instructions from
If you want them, please install non-variable ``Noto Sans CJK''
font families along with the texlive-xecjk package by following
instructions from
\sphinxcode{./scripts/sphinx-pre-install}.
Having optional ``Noto Serif CJK'' font families will improve
the looks of those translations.
Having optional non-variable ``Noto Serif CJK'' font families will
improve the looks of those translations.
\end{sphinxadmonition}}
\newcommand{\kerneldocEndSC}{}
\newcommand{\kerneldocBeginTC}[1]{}

View File

@ -6406,6 +6406,7 @@ S: Maintained
P: Documentation/doc-guide/maintainer-profile.rst
T: git git://git.lwn.net/linux.git docs-next
F: Documentation/
F: scripts/check-variable-font.sh
F: scripts/documentation-file-ref-check
F: scripts/kernel-doc
F: scripts/sphinx-pre-install

117
scripts/check-variable-fonts.sh Executable file
View File

@ -0,0 +1,117 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only
# Copyright (C) Akira Yokosawa, 2024
#
# For "make pdfdocs", reports of build errors of translations.pdf started
# arriving early 2024 [1, 2]. It turned out that Fedora and openSUSE
# tumbleweed have started deploying variable-font [3] format of "Noto CJK"
# fonts [4, 5]. For PDF, a LaTeX package named xeCJK is used for CJK
# (Chinese, Japanese, Korean) pages. xeCJK requires XeLaTeX/XeTeX, which
# does not (and likely never will) understand variable fonts for historical
# reasons.
#
# The build error happens even when both of variable- and non-variable-format
# fonts are found on the build system. To make matters worse, Fedora enlists
# variable "Noto CJK" fonts in the requirements of langpacks-ja, -ko, -zh_CN,
# -zh_TW, etc. Hence developers who have interest in CJK pages are more
# likely to encounter the build errors.
#
# This script is invoked from the error path of "make pdfdocs" and emits
# suggestions if variable-font files of "Noto CJK" fonts are in the list of
# fonts accessible from XeTeX.
#
# Assumption:
# File names are not modified from those of upstream Noto CJK fonts:
# https://github.com/notofonts/noto-cjk/
#
# References:
# [1]: https://lore.kernel.org/r/8734tqsrt7.fsf@meer.lwn.net/
# [2]: https://lore.kernel.org/r/1708585803.600323099@f111.i.mail.ru/
# [3]: https://en.wikipedia.org/wiki/Variable_font
# [4]: https://fedoraproject.org/wiki/Changes/Noto_CJK_Variable_Fonts
# [5]: https://build.opensuse.org/request/show/1157217
#
#===========================================================================
# Workarounds for building translations.pdf
#===========================================================================
#
# * Denylist "variable font" Noto CJK fonts.
# - Create $HOME/deny-vf/fontconfig/fonts.conf from template below, with
# tweaks if necessary. Remove leading "# ".
# - Path of fontconfig/fonts.conf can be overridden by setting an env
# variable FONTS_CONF_DENY_VF.
#
# * Template:
# -----------------------------------------------------------------
# <?xml version="1.0"?>
# <!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
# <fontconfig>
# <!--
# Ignore variable-font glob (not to break xetex)
# -->
# <selectfont>
# <rejectfont>
# <!--
# for Fedora
# -->
# <glob>/usr/share/fonts/google-noto-*-cjk-vf-fonts</glob>
# <!--
# for openSUSE tumbleweed
# -->
# <glob>/usr/share/fonts/truetype/Noto*CJK*-VF.otf</glob>
# </rejectfont>
# </selectfont>
# </fontconfig>
# -----------------------------------------------------------------
#
# The denylisting is activated for "make pdfdocs".
#
# * For skipping CJK pages in PDF
# - Uninstall texlive-xecjk.
# Denylisting is not needed in this case.
#
# * For printing CJK pages in PDF
# - Need non-variable "Noto CJK" fonts.
# * Fedora
# - google-noto-sans-cjk-fonts
# - google-noto-serif-cjk-fonts
# * openSUSE tumbleweed
# - Non-variable "Noto CJK" fonts are not available as distro packages
# as of April, 2024. Fetch a set of font files from upstream Noto
# CJK Font released at:
# https://github.com/notofonts/noto-cjk/tree/main/Sans#super-otc
# and at:
# https://github.com/notofonts/noto-cjk/tree/main/Serif#super-otc
# , then uncompress and deploy them.
# - Remember to update fontconfig cache by running fc-cache.
#
# !!! Caution !!!
# Uninstalling "variable font" packages can be dangerous.
# They might be depended upon by other packages important for your work.
# Denylisting should be less invasive, as it is effective only while
# XeLaTeX runs in "make pdfdocs".
# Default per-user fontconfig path (overridden by env variable)
: ${FONTS_CONF_DENY_VF:=$HOME/deny-vf}
export XDG_CONFIG_HOME=${FONTS_CONF_DENY_VF}
vffonts=`fc-list -b | grep -iE 'file: .*noto.*cjk.*-vf' | \
sed -e 's/\tfile:/ file:/' -e 's/(s)$//' | sort | uniq`
if [ "x$vffonts" != "x" ] ; then
echo '============================================================================='
echo 'XeTeX is confused by "variable font" files listed below:'
echo "$vffonts"
echo
echo 'For CJK pages in PDF, they need to be hidden from XeTeX by denylisting.'
echo 'Or, CJK pages can be skipped by uninstalling texlive-xecjk.'
echo
echo 'For more info on denylisting, other options, and variable font, see header'
echo 'comments of scripts/check-variable-fonts.sh.'
echo '============================================================================='
fi
# As this script is invoked from Makefile's error path, always error exit
# regardless of whether any variable font is discovered or not.
exit 1