Skip to content

Commit 0462ab6

Browse files
committed
chg: remove fonts from submodules, on-demand download if needed
1 parent d5e472b commit 0462ab6

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
[submodule "pymisp/data/misp-objects"]
22
path = pymisp/data/misp-objects
33
url = https://github.com/MISP/misp-objects
4-
[submodule "pymisp/tools/pdf_fonts"]
5-
path = pymisp/tools/pdf_fonts
6-
url = https://github.com/MISP/pdf_fonts

pymisp/tools/pdf_fonts

Lines changed: 0 additions & 1 deletion
This file was deleted.

pymisp/tools/reportlab_generator.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import sys
1313
import os
1414

15+
import requests
16+
1517
if sys.version_info.major >= 3:
1618
from html import escape
1719
else:
@@ -410,18 +412,28 @@ def internationalize_font(config=None):
410412
NotoSansCJKtc - Medium.ttf
411413
'''
412414
font_path = Path(sys.modules['pymisp'].__file__).parent / 'tools' / 'pdf_fonts' / 'Noto_TTF'
413-
414415
noto_bold = font_path / "NotoSansCJKtc-Bold.ttf"
415416
noto = font_path / "NotoSansCJKtc-DemiLight.ttf"
416417

418+
if not font_path.is_dir() or not noto_bold.is_file() or not noto.is_file():
419+
font_path.mkdir(parents=True, exist_ok=True)
420+
if not noto_bold.is_file():
421+
bf = requests.get('https://github.com/MISP/pdf_fonts/raw/refs/heads/master/Noto_TTF/NotoSansCJKtc-Bold.ttf')
422+
with open(noto_bold, 'wb') as f:
423+
f.write(bf.content)
424+
if not noto.is_file():
425+
rf = requests.get('https://github.com/MISP/pdf_fonts/raw/refs/heads/master/Noto_TTF/NotoSansCJKtc-DemiLight.ttf')
426+
with open(noto, 'wb') as f:
427+
f.write(rf.content)
428+
417429
if noto_bold.is_file() and noto.is_file():
418430
registerFont(TTFont("Noto", noto))
419431
registerFont(TTFont("Noto-bold", noto_bold))
420432

421433
FIRST_COL_FONT = 'Noto-bold'
422434
SECOND_COL_FONT = 'Noto'
423435
else:
424-
logger.error(f"Trying to load a custom (internationalization) font, unable to access the file: {noto_bold}")
436+
logger.error(f"Trying to load a custom (internationalization) font, unable to access the file: {noto_bold} / {noto}")
425437

426438

427439
def get_table_styles():

0 commit comments

Comments
 (0)