From 5020c7a816ca900dc123c3d3b9275caefb40cdd8 Mon Sep 17 00:00:00 2001 From: Keuin Date: Wed, 31 May 2023 03:03:15 +0800 Subject: Configurable CJK font --- main.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index dcf7e58..3ac4aae 100644 --- a/main.py +++ b/main.py @@ -115,9 +115,13 @@ class LatexGenerator: cjk: CJKProvider artist: typing.Optional[str] title: typing.Optional[str] + cjk_font_main: typing.Optional[str] + cjk_font_sans: typing.Optional[str] + cjk_font_mono: typing.Optional[str] def __init__(self): self.artist, self.title = None, None + self.cjk_font_main, self.cjk_font_sans, self.cjk_font_mono = None, None, None def generate_lyric(self, lyric_tokens: typing.Iterator[Token]) -> str: injectors = [] @@ -127,11 +131,11 @@ class LatexGenerator: r'\usepackage{geometry}', r'\geometry{a4paper,left=20mm,right=20mm,top=10mm,bottom=20mm}', ], [])) - injectors.append(LatexDocInjectionInfo([], [ - r'\setCJKmainfont{Noto Serif CJK TC}', - r'\setCJKsansfont{Noto Sans CJK TC}', - r'\setCJKmonofont{Noto Sans Mono CJK TC}', - ], [])) + injectors.append(LatexDocInjectionInfo([], [x for x in [ + r'\setCJKmainfont{%s}' % self.cjk_font_main if self.cjk_font_main else None, + r'\setCJKsansfont{%s}' % self.cjk_font_sans if self.cjk_font_sans else None, + r'\setCJKmonofont{%s}' % self.cjk_font_mono if self.cjk_font_mono else None, + ] if x], [])) injectors.append(LatexDocInjectionInfo([], [ r'\author{%s}' % (self.artist or ''), r'\title{%s}' % (self.title or ''), @@ -197,6 +201,8 @@ def main(): elif k == 'page_song': title = v gen.artist, gen.title = artist, title + # FIXME hardcoded CJK font + gen.cjk_font_main = 'Noto Serif CJK JP' print(gen.generate_lyric(tokens)) -- cgit v1.2.3