Commit ·
c4e20b0
1
Parent(s): 776e655
Bundle NotoSansJP font for reliable Japanese PDF output
Browse filesCo-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- export/pdf_exporter.py +5 -5
export/pdf_exporter.py
CHANGED
|
@@ -43,7 +43,10 @@ COL_TXT_OFF = colors.HexColor("#9CA3AF") # 休み文字
|
|
| 43 |
def _register_font() -> str:
|
| 44 |
"""日本語フォントを登録。利用不可の場合は Helvetica にフォールバック。"""
|
| 45 |
import glob
|
|
|
|
| 46 |
candidates = [
|
|
|
|
|
|
|
| 47 |
# Windows
|
| 48 |
"C:/Windows/Fonts/meiryo.ttc",
|
| 49 |
"C:/Windows/Fonts/YuGothR.ttc",
|
|
@@ -51,17 +54,14 @@ def _register_font() -> str:
|
|
| 51 |
# macOS
|
| 52 |
"/System/Library/Fonts/ヒラギノ角ゴシック W3.ttc",
|
| 53 |
"/Library/Fonts/Osaka.ttf",
|
| 54 |
-
# Linux
|
| 55 |
"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
|
| 56 |
"/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc",
|
| 57 |
-
"/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc",
|
| 58 |
]
|
| 59 |
-
# Linux glob: fonts-noto-cjk でインストールされるあらゆるパスを検索
|
| 60 |
candidates += sorted(glob.glob("/usr/share/fonts/**/*CJK*.ttc", recursive=True))
|
| 61 |
-
candidates += sorted(glob.glob("/usr/share/fonts/**/*CJK*.otf", recursive=True))
|
| 62 |
-
candidates += sorted(glob.glob("/usr/share/fonts/**/*cjk*.ttc", recursive=True))
|
| 63 |
|
| 64 |
for path in candidates:
|
|
|
|
| 65 |
if os.path.exists(path):
|
| 66 |
try:
|
| 67 |
pdfmetrics.registerFont(TTFont("JpFont", path))
|
|
|
|
| 43 |
def _register_font() -> str:
|
| 44 |
"""日本語フォントを登録。利用不可の場合は Helvetica にフォールバック。"""
|
| 45 |
import glob
|
| 46 |
+
_here = os.path.dirname(os.path.abspath(__file__))
|
| 47 |
candidates = [
|
| 48 |
+
# バンドルフォント(最優先)
|
| 49 |
+
os.path.join(_here, "../static/fonts/NotoSansJP.ttf"),
|
| 50 |
# Windows
|
| 51 |
"C:/Windows/Fonts/meiryo.ttc",
|
| 52 |
"C:/Windows/Fonts/YuGothR.ttc",
|
|
|
|
| 54 |
# macOS
|
| 55 |
"/System/Library/Fonts/ヒラギノ角ゴシック W3.ttc",
|
| 56 |
"/Library/Fonts/Osaka.ttf",
|
| 57 |
+
# Linux
|
| 58 |
"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
|
| 59 |
"/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc",
|
|
|
|
| 60 |
]
|
|
|
|
| 61 |
candidates += sorted(glob.glob("/usr/share/fonts/**/*CJK*.ttc", recursive=True))
|
|
|
|
|
|
|
| 62 |
|
| 63 |
for path in candidates:
|
| 64 |
+
path = os.path.normpath(path)
|
| 65 |
if os.path.exists(path):
|
| 66 |
try:
|
| 67 |
pdfmetrics.registerFont(TTFont("JpFont", path))
|