Skip to content

Commit

Permalink
feat(fonts): map italic font to kai
Browse files Browse the repository at this point in the history
- add LXGWWenKai-Regular.ttf to the assets list
- update fontmap to include kai font and use it for italic characters

chore(project): bump version to 0.0.1a18

- update project version in pyproject.toml
  • Loading branch information
awwaawwa committed Jan 17, 2025
1 parent db5ab7c commit d610aaa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "yadt"
version = "0.0.1a17"
version = "0.0.1a18"
description = "Yet Another Document Translator"
license = "AGPL-3.0"
readme = "README.md"
Expand Down
7 changes: 7 additions & 0 deletions yadt/document_il/utils/fontmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ def __init__(self, translation_config: TranslationConfig):
self.base_font = pymupdf.Font(fontfile=self.base_font_path)
self.fallback_font = pymupdf.Font(fontfile=self.fallback_font_path)

self.kai_font_path = get_cache_file_path("LXGWWenKai-Regular.ttf")
self.kai_font = pymupdf.Font(fontfile=self.kai_font_path)

self.base_font.font_id = "base"
self.fallback_font.font_id = "fallback"
self.kai_font.font_id = "kai"

def map(self, original_font: PdfFont, char_unicode: str):
char_unicode = ord(char_unicode)
if original_font.italic and self.kai_font.has_glyph(char_unicode):
return self.kai_font
for k, font in self.fonts.items():
if not font.has_glyph(char_unicode):
continue
Expand All @@ -51,6 +57,7 @@ def add_font(self, doc_zh: pymupdf.Document, il: il_version_1.Document):
font_list = [
("base", self.base_font_path),
("fallback", self.fallback_font_path),
("kai", self.kai_font_path),
]
font_list.extend(
[
Expand Down
5 changes: 5 additions & 0 deletions yadt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ def download_font_assets():
"SourceHanSansSC-Bold.ttf",
"https://github.com/iizyd/SourceHanSansCN-TTF-Min"
"/raw/refs/heads/main/source-file/ttf/SourceHanSansSC-Bold.ttf"
),
(
'LXGWWenKai-Regular.ttf',
'https://github.com/lxgw/LxgwWenKai'
'/raw/refs/heads/main/fonts/TTF/LXGWWenKai-Regular.ttf'
)
]
for name, url in assets:
Expand Down

0 comments on commit d610aaa

Please sign in to comment.