Skip to content

Commit 58ff89e

Browse files
suluyanasuluyan
andauthored
fix: video gen chinese char (#855)
Co-authored-by: suluyan <suluyan.sly@alibaba-inc.com>
1 parent f1d54bc commit 58ff89e

File tree

1 file changed

+15
-4
lines changed
  • projects/singularity_cinema/create_background

1 file changed

+15
-4
lines changed

projects/singularity_cinema/create_background/agent.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,23 @@ def __init__(self,
2828
self.slogan = getattr(self.config, 'slogan', [])
2929

3030
def get_font(self, size):
31-
for font_name in self.fonts:
31+
candidates = list(self.fonts)
32+
import subprocess
33+
for name in candidates:
3234
try:
33-
font_path = fm.findfont(fm.FontProperties(family=font_name))
34-
return ImageFont.truetype(font_path, size)
35-
except OSError or ValueError:
35+
font_path = subprocess.check_output(
36+
['fc-match', '-f', '%{file}\n', name], text=True).strip()
37+
38+
font = ImageFont.truetype(font_path, size)
39+
font.getmask('中')
40+
41+
logger.info(f"Using font '{name}' -> {font_path}")
42+
return font
43+
except Exception as e:
44+
logger.warning(f"Font '{name}' not usable: {e}")
3645
continue
46+
47+
logger.error('No Chinese font found, falling back to default.')
3748
return ImageFont.load_default()
3849

3950
async def execute_code(self, messages, **kwargs):

0 commit comments

Comments
 (0)