[RFC PATCH 2/3] docs: pdfdocs: Add font settings for CJK ascii-art

From: Akira Yokosawa
Date: Thu Jun 24 2021 - 08:11:40 EST


This is irrelevant to those who don't care translations docs.

Current font choice of "DejaVu Sans Mono" and "Noto Sans CJK SC" for
monospace fonts generates misaligned ascii-art figures in translations.

Using "Noto Sans Mono CJK SC" for both the monofont and CJKmonofont
choices is a better option.

As for Korean translation, there remain character width mismatches.

Hangul characters in "Noto Sans Mono CJK SC" are slightly narrower than
Chinese and Japanese characters, despite the "Mono" in the font name.

This results in mis-aligned ascii-art figures in Korean translation
of memory-barriers.txt.

Proper width Hangul characters are available in "Unifont", although with
degraded look of CJK characters due to Unifont's bitmap-font nature.

So "Unifont" is used only when it is found on the system.

Note 1: Unifont can be installed by:
(Ubuntu) apt-get install ttf-unifont
(Fedora) dnf install unifont-fonts

Note 2: Let us know if there is a better monospace font choice for Hangul.

Note 3: Sphinx itself is confused by tabs behind CJK characters. Korean
translation of memory-barriers.txt needs a couple of fixes to this
effect, of which a follow up change takes care.

Signed-off-by: Akira Yokosawa <akiyks@xxxxxxxxx>
---
Documentation/conf.py | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/Documentation/conf.py b/Documentation/conf.py
index 22f083bafaae..a95bd2123da1 100644
--- a/Documentation/conf.py
+++ b/Documentation/conf.py
@@ -363,12 +363,19 @@ latex_elements['preamble'] += '''
% This is needed for translations
\\usepackage{xeCJK}
\\setCJKmainfont{Noto Sans CJK SC}
+ \\setCJKsansfont{Noto Sans CJK SC}
+ \\setCJKmonofont{Noto Sans Mono CJK SC}
+ \\setmonofont{Noto Sans Mono CJK SC}
% Define custom macros to on/off CJK
\\newcommand{\\kerneldocCJKon}{\\makexeCJKactive}
\\newcommand{\\kerneldocCJKoff}{\\makexeCJKinactive}
% Inactivate CJK after tableofcontents (using etoolbox)
\\usepackage{etoolbox}
\\apptocmd{\\sphinxtableofcontents}{\\kerneldocCJKoff}{}{}
+ \\IfFontExistsTF{Unifont}{
+ % For alinged Korean ascii-art
+ \\setCJKmonofont{Unifont}
+ }{}
}{ % No CJK font
% Custom macros to on/off CJK (Dummy)
\\newcommand{\\kerneldocCJKon}{}
--
2.17.1