From 3aa46c1ae72caec7fc85f4dc3407a8cd4c26f274 Mon Sep 17 00:00:00 2001 From: Ties Stuij Date: Mon, 19 Oct 2026 16:20:10 +0100 Subject: [PATCH] Fix not specifying a default PDF font MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We currently don't specify what font we should use for the PDF documents, and so we use a fallback font. But it depends on your specific environment which font is picked. This doesn't just impact the look of the text. Some fonts don't have glyphs for certain characters. For example Verdana on MacOs doesn't have glyphs for →, ⊂ and ⊆. This was because stdFont and stdBold were not defined in the stylesheet. So we set those to DejaVu Sans, which is what we use in CI, which fixes the above problems. --- tools/rst2pdf/generate-pdfs.sh | 17 +++++++++++++++++ tools/rst2pdf/rst2pdf-abi.style | 13 +++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tools/rst2pdf/generate-pdfs.sh b/tools/rst2pdf/generate-pdfs.sh index 7fd32209..50c9a569 100755 --- a/tools/rst2pdf/generate-pdfs.sh +++ b/tools/rst2pdf/generate-pdfs.sh @@ -27,6 +27,22 @@ CURR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" ABI_ROOT="${CURR_DIR}/../.." OUTPUT_DIR=$1 +# Use matplotlib's bundled font dir as we can't trust the standard host paths +# to contain the font we want. +FONT_DIR="$(python3 -c 'from pathlib import Path; import matplotlib; print(Path(matplotlib.get_data_path()) / "fonts" / "ttf")')" + +if [ ! -d "${FONT_DIR}" ]; then + echo "error: PDF font directory does not exist: ${FONT_DIR}" + exit 1 +fi + +for font in DejaVuSans.ttf DejaVuSans-Bold.ttf DejaVuSans-Oblique.ttf DejaVuSans-BoldOblique.ttf; do + if [ ! -r "${FONT_DIR}/${font}" ]; then + echo "error: required PDF font is missing: ${FONT_DIR}/${font}" + exit 1 + fi +done + mkdir -p "${OUTPUT_DIR}" declare -a docs=( # 32-bit @@ -60,6 +76,7 @@ for doc in "${docs[@]}"; do ( set -x; rst2pdf "${ABI_ROOT}/${doc}/${doc}.rst" \ -s "${CURR_DIR}/rst2pdf-abi.style" \ + --font-path "${FONT_DIR}" \ --repeat-table-rows \ --default-dpi=110 \ -c \ diff --git a/tools/rst2pdf/rst2pdf-abi.style b/tools/rst2pdf/rst2pdf-abi.style index 8cd4fa42..28b8a988 100644 --- a/tools/rst2pdf/rst2pdf-abi.style +++ b/tools/rst2pdf/rst2pdf-abi.style @@ -13,6 +13,19 @@ # See the License for the specific language governing permissions and # limitations under the License. +embeddedFonts: [] + [DejaVuSans.ttf, DejaVuSans-Bold.ttf, DejaVuSans-Oblique.ttf, DejaVuSans-BoldOblique.ttf] + +fontsAlias: + stdFont: DejaVuSans + stdBold: DejaVuSans-Bold + stdItalic: DejaVuSans-Oblique + stdBoldItalic: DejaVuSans-BoldOblique + fontSans: DejaVuSans + fontSansBold: DejaVuSans-Bold + fontSansItalic: DejaVuSans-Oblique + fontSansBoldItalic: DejaVuSans-BoldOblique + pageTemplates: oneColumn: defaultFooter : ".. class:: center\n\n###Page###\n\n.. class:: center\n\n|footer|"