Skip to content

Commit af53a46

Browse files
authored
Merge pull request #2264 from myhloli/dev
refactor(office_to_pdf): simplify font checking and add logging
2 parents 4bd3381 + 2e5e55c commit af53a46

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

docker/ascend_npu/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ RUN /bin/bash -c "wget https://gcore.jsdelivr.net/gh/opendatalab/MinerU@master/m
3636
source /opt/mineru_venv/bin/activate && \
3737
pip3 install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple && \
3838
pip3 install torch==2.3.1 torchvision==0.18.1 -i https://mirrors.aliyun.com/pypi/simple && \
39-
pip3 install -U magic-pdf[full] -i https://mirrors.aliyun.com/pypi/simple && \
39+
pip3 install -U magic-pdf[full] 'numpy<2' decorator attrs absl-py cloudpickle ml-dtypes tornado einops -i https://mirrors.aliyun.com/pypi/simple && \
4040
wget https://gitee.com/ascend/pytorch/releases/download/v6.0.rc2-pytorch2.3.1/torch_npu-2.3.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl && \
4141
pip3 install torch_npu-2.3.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"
4242

magic_pdf/utils/office_to_pdf.py

+13-22
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,33 @@
44
from pathlib import Path
55
import shutil
66

7+
from loguru import logger
8+
79

810
class ConvertToPdfError(Exception):
911
def __init__(self, msg):
1012
self.msg = msg
1113
super().__init__(self.msg)
1214

1315

14-
# Chinese font list
15-
REQUIRED_CHS_FONTS = ['SimSun', 'Microsoft YaHei', 'Noto Sans CJK SC']
16-
17-
1816
def check_fonts_installed():
1917
"""Check if required Chinese fonts are installed."""
2018
system_type = platform.system()
2119

22-
if system_type == 'Windows':
23-
# Windows: check fonts via registry or system font folder
24-
font_dir = Path("C:/Windows/Fonts")
25-
installed_fonts = [f.name for f in font_dir.glob("*.ttf")]
26-
if any(font for font in REQUIRED_CHS_FONTS if any(font in f for f in installed_fonts)):
27-
return True
28-
raise EnvironmentError(
29-
f"Missing Chinese font. Please install at least one of: {', '.join(REQUIRED_CHS_FONTS)}"
30-
)
20+
if system_type in ['Windows', 'Darwin']:
21+
pass
3122
else:
32-
# Linux/macOS: use fc-list
23+
# Linux: use fc-list
3324
try:
3425
output = subprocess.check_output(['fc-list', ':lang=zh'], encoding='utf-8')
35-
for font in REQUIRED_CHS_FONTS:
36-
if font in output:
37-
return True
38-
raise EnvironmentError(
39-
f"Missing Chinese font. Please install at least one of: {', '.join(REQUIRED_CHS_FONTS)}"
40-
)
41-
except Exception as e:
42-
raise EnvironmentError(f"Font detection failed. Please install 'fontconfig' and fonts: {str(e)}")
26+
if output.strip(): # 只要有任何输出(非空)
27+
return True
28+
else:
29+
logger.warning(
30+
f"No Chinese fonts were detected, the converted document may not display Chinese content properly."
31+
)
32+
except Exception:
33+
pass
4334

4435

4536
def get_soffice_command():

0 commit comments

Comments
 (0)