From 9ada0e7d4dea3286837e069ad1a4e4ababf350ee Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Mon, 22 Jul 2024 23:06:13 +0400 Subject: [PATCH] Change font handling in Latex --- README.md | 5 +++-- src/main.cpp | 17 +++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9ae9334..5f600de 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,10 @@ Goals: Requirements: - * `xelatex` compiler ([XeTeX](https://tug.org/xetex/)), * C++20 compiler, - * CMake version 3.30 or higher. + * CMake version 3.30 or higher, + * `xelatex` compiler ([XeTeX](https://tug.org/xetex/)), + * [Doulos SIL](https://software.sil.org/doulos/download/) font. To get a PDF file with the alphabet, run diff --git a/src/main.cpp b/src/main.cpp index 3cd0de3..e691479 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -100,7 +100,7 @@ class TikzPainter : public Painter { stream << "\\usepackage[utf8]{inputenc}" << std::endl; stream << "\\usepackage{tikz}" << std::endl; stream << "\\usepackage{fontspec}" << std::endl; - stream << "\\setmainfont{Doulos SIL}" << std::endl; + stream << "\\newfontface\\doulos{Doulos SIL}" << std::endl; stream << "\\usetikzlibrary{positioning}" << std::endl; stream << "\\begin{document}" << std::endl; @@ -552,7 +552,10 @@ void drawTikz( center + Vector(-0.8, 0.25), center + Vector(0.2, -0.25), "draw=black"); - painter->text(center - Vector(0.8, 0), ipaSymbol, "anchor=west"); + painter->text( + center - Vector(0.8, 0), + "\\doulos{" + ipaSymbol + "}", + "anchor=west"); } else if (isImpossible) { painter->rectangle( center + Vector(-0.8, 0.25), @@ -607,10 +610,7 @@ void parseConsonants( for (int i = 0; i < headers.size(); i++) { std::string tex = std::regex_replace(headers[i], std::regex("_"), " "); tex = std::regex_replace(tex, std::regex(";"), ", "); - painter->text( - Vector(x - 0.5, y + 0.5), - "{\\fontfamily{cmr}\\selectfont " + tex + "}", - "anchor=west, rotate=30"); + painter->text(Vector(x - 0.5, y + 0.5), tex, "anchor=west, rotate=30"); x += 1; } x = 0.0f; @@ -622,10 +622,7 @@ void parseConsonants( std::string tex = std::regex_replace(row[0], std::regex("_"), " "); tex = std::regex_replace(tex, std::regex(";"), ", "); - painter->text( - Vector(x - 6, y), - "{\\fontfamily{cmr}\\selectfont " + tex + "}", - "anchor=west"); + painter->text(Vector(x - 6, y), tex, "anchor=west"); for (int i = 1; i < row.size(); i++) {