From 0462ab62c0444a8d2e364ad9cc3ef4dabd855d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Mon, 11 Nov 2024 12:31:14 +0100 Subject: [PATCH] chg: remove fonts from submodules, on-demand download if needed --- .gitmodules | 3 --- pymisp/tools/pdf_fonts | 1 - pymisp/tools/reportlab_generator.py | 16 ++++++++++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) delete mode 160000 pymisp/tools/pdf_fonts diff --git a/.gitmodules b/.gitmodules index a1fe528..d0e9062 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "pymisp/data/misp-objects"] path = pymisp/data/misp-objects url = https://github.com/MISP/misp-objects -[submodule "pymisp/tools/pdf_fonts"] - path = pymisp/tools/pdf_fonts - url = https://github.com/MISP/pdf_fonts diff --git a/pymisp/tools/pdf_fonts b/pymisp/tools/pdf_fonts deleted file mode 160000 index 7ff2220..0000000 --- a/pymisp/tools/pdf_fonts +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7ff222022e6ad99e11a201f62d57da4bff1337ee diff --git a/pymisp/tools/reportlab_generator.py b/pymisp/tools/reportlab_generator.py index dc4f507..96efc7b 100644 --- a/pymisp/tools/reportlab_generator.py +++ b/pymisp/tools/reportlab_generator.py @@ -12,6 +12,8 @@ from pathlib import Path import sys import os +import requests + if sys.version_info.major >= 3: from html import escape else: @@ -410,10 +412,20 @@ def internationalize_font(config=None): NotoSansCJKtc - Medium.ttf ''' font_path = Path(sys.modules['pymisp'].__file__).parent / 'tools' / 'pdf_fonts' / 'Noto_TTF' - noto_bold = font_path / "NotoSansCJKtc-Bold.ttf" noto = font_path / "NotoSansCJKtc-DemiLight.ttf" + if not font_path.is_dir() or not noto_bold.is_file() or not noto.is_file(): + font_path.mkdir(parents=True, exist_ok=True) + if not noto_bold.is_file(): + bf = requests.get('https://github.com/MISP/pdf_fonts/raw/refs/heads/master/Noto_TTF/NotoSansCJKtc-Bold.ttf') + with open(noto_bold, 'wb') as f: + f.write(bf.content) + if not noto.is_file(): + rf = requests.get('https://github.com/MISP/pdf_fonts/raw/refs/heads/master/Noto_TTF/NotoSansCJKtc-DemiLight.ttf') + with open(noto, 'wb') as f: + f.write(rf.content) + if noto_bold.is_file() and noto.is_file(): registerFont(TTFont("Noto", noto)) registerFont(TTFont("Noto-bold", noto_bold)) @@ -421,7 +433,7 @@ def internationalize_font(config=None): FIRST_COL_FONT = 'Noto-bold' SECOND_COL_FONT = 'Noto' else: - logger.error(f"Trying to load a custom (internationalization) font, unable to access the file: {noto_bold}") + logger.error(f"Trying to load a custom (internationalization) font, unable to access the file: {noto_bold} / {noto}") def get_table_styles():