|
4 | 4 | from pathlib import Path
|
5 | 5 | import shutil
|
6 | 6 |
|
| 7 | +from loguru import logger |
| 8 | + |
7 | 9 |
|
8 | 10 | class ConvertToPdfError(Exception):
|
9 | 11 | def __init__(self, msg):
|
10 | 12 | self.msg = msg
|
11 | 13 | super().__init__(self.msg)
|
12 | 14 |
|
13 | 15 |
|
14 |
| -# Chinese font list |
15 |
| -REQUIRED_CHS_FONTS = ['SimSun', 'Microsoft YaHei', 'Noto Sans CJK SC'] |
16 |
| - |
17 |
| - |
18 | 16 | def check_fonts_installed():
|
19 | 17 | """Check if required Chinese fonts are installed."""
|
20 | 18 | system_type = platform.system()
|
21 | 19 |
|
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 |
31 | 22 | else:
|
32 |
| - # Linux/macOS: use fc-list |
| 23 | + # Linux: use fc-list |
33 | 24 | try:
|
34 | 25 | 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 |
43 | 34 |
|
44 | 35 |
|
45 | 36 | def get_soffice_command():
|
|
0 commit comments