1
0
Fork 0

docs: conf.py: only use CJK if the font is available

If we try to build a book with asian characters with XeLaTeX
and the font is not available, it will produce an error.

So, instead, add a logic at conf.py to detect if the proper
font is installed.

This will avoid an error while building the document, although
the result may not be readable.

Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
alistair/sunxi64-5.4-dsi
Mauro Carvalho Chehab 2019-07-14 07:16:18 -03:00
parent 24889dad3d
commit e0de2b59e2
1 changed files with 11 additions and 2 deletions

View File

@ -16,6 +16,8 @@ import sys
import os import os
import sphinx import sphinx
from subprocess import check_output
# Get Sphinx version # Get Sphinx version
major, minor, patch = sphinx.version_info[:3] major, minor, patch = sphinx.version_info[:3]
@ -276,13 +278,20 @@ latex_elements = {
\\setsansfont{DejaVu Sans} \\setsansfont{DejaVu Sans}
\\setromanfont{DejaVu Serif} \\setromanfont{DejaVu Serif}
\\setmonofont{DejaVu Sans Mono} \\setmonofont{DejaVu Sans Mono}
'''
}
# At least one book (translations) may have Asian characters
# with are only displayed if xeCJK is used
cjk_cmd = check_output(['fc-list', '--format="%{family[0]}\n"']).decode('utf-8', 'ignore')
if cjk_cmd.find("Noto Sans CJK SC") >= 0:
print ("enabling CJK for LaTeX builder")
latex_elements['preamble'] += '''
% This is needed for translations % This is needed for translations
\\usepackage{xeCJK} \\usepackage{xeCJK}
\\setCJKmainfont{Noto Sans CJK SC} \\setCJKmainfont{Noto Sans CJK SC}
''' '''
}
# Fix reference escape troubles with Sphinx 1.4.x # Fix reference escape troubles with Sphinx 1.4.x
if major == 1 and minor > 3: if major == 1 and minor > 3: