summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeuin <[email protected]>2023-05-31 03:03:15 +0800
committerKeuin <[email protected]>2023-05-31 03:03:15 +0800
commit5020c7a816ca900dc123c3d3b9275caefb40cdd8 (patch)
treee0b69cd5cfbddfef1cc2274e866ff893ea511105
parent6e4683716eade6a7254921dc17d7fb5868a5423c (diff)
Configurable CJK font
-rw-r--r--main.py16
1 files 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))