Commit 4515ffdf authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab Committed by Jonathan Corbet
Browse files

tools/docs: check-variable-fonts.py: split into a lib and an exec file



As we'll be using the actual code inside sphinx-build-wrapper,
split the library from the executable, placing the exec at
the new place we've been using:

	tools/docs

No functional changes.

Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Message-ID: <8adbc22df1d43b1c5a673799d2333cc429ffe9fc.1758196090.git.mchehab+huawei@kernel.org>
Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
parent 75539bec
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ 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)" $(DENY_VF) -C $(BUILDDIR)/$(var)/latex || $(PYTHON3) $(srctree)/scripts/check-variable-fonts.py || exit; \
	   $(MAKE) PDFLATEX="$(PDFLATEX)" LATEXOPTS="$(LATEXOPTS)" $(DENY_VF) -C $(BUILDDIR)/$(var)/latex || $(PYTHON3) $(srctree)/tools/docs/check-variable-fonts.py || exit; \
	   mkdir -p $(BUILDDIR)/$(var)/pdf; \
	   mv $(subst .tex,.pdf,$(wildcard $(BUILDDIR)/$(var)/latex/*.tex)) $(BUILDDIR)/$(var)/pdf/; \
	)
+0 −1
Original line number Diff line number Diff line
@@ -7301,7 +7301,6 @@ 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-fonts.py
F:	scripts/checktransupdate.py
F:	scripts/documentation-file-ref-check
F:	scripts/get_abi.py
+23 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-only
# Copyright (C) Akira Yokosawa, 2024
#
# Ported to Python by (c) Mauro Carvalho Chehab, 2025
#
# pylint: disable=C0103

"""
Detect problematic Noto CJK variable fonts.

or more details, see lib/latex_fonts.py.
"""

import sys

from lib.latex_fonts import LatexFontChecker

msg = LatexFontChecker().check()
if msg:
    print(msg)

sys.exit(1)
+162 −0
Original line number Diff line number Diff line
@@ -3,97 +3,101 @@
# Copyright (C) Akira Yokosawa, 2024
#
# Ported to Python by (c) Mauro Carvalho Chehab, 2025
#
# 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.
#
# 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
#

"""
Detect problematic Noto CJK variable fonts.

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.

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
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".

* 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".
"""

import os
import re
import subprocess
import sys
import textwrap
import sys

class LatexFontChecker:
    """
@@ -156,10 +160,3 @@ class LatexFontChecker:
        msg += "=" * 77

        return msg

if __name__ == "__main__":
    msg = LatexFontChecker().check()
    if msg:
        print(msg)

    sys.exit(1)