-
Notifications
You must be signed in to change notification settings - Fork 483
fix: video gen chinese char #855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,12 +28,23 @@ def __init__(self, | |
| self.slogan = getattr(self.config, 'slogan', []) | ||
|
|
||
| def get_font(self, size): | ||
| for font_name in self.fonts: | ||
| candidates = list(self.fonts) | ||
| import subprocess | ||
| for name in candidates: | ||
| try: | ||
| font_path = fm.findfont(fm.FontProperties(family=font_name)) | ||
| return ImageFont.truetype(font_path, size) | ||
| except OSError or ValueError: | ||
| font_path = subprocess.check_output( | ||
| ['fc-match', '-f', '%{file}\n', name], text=True).strip() | ||
|
Comment on lines
+35
to
+36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
|
|
||
| font = ImageFont.truetype(font_path, size) | ||
| font.getmask('中') | ||
|
|
||
| logger.info(f"Using font '{name}' -> {font_path}") | ||
| return font | ||
| except Exception as e: | ||
| logger.warning(f"Font '{name}' not usable: {e}") | ||
| continue | ||
|
Comment on lines
+43
to
45
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catching a general except (FileNotFoundError, subprocess.CalledProcessError, OSError, ValueError) as e:
logger.warning(f"Font '{name}' not usable: {e}")
continue |
||
|
|
||
| logger.error('No Chinese font found, falling back to default.') | ||
| return ImageFont.load_default() | ||
|
|
||
| async def execute_code(self, messages, **kwargs): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
import subprocessstatement should be moved to the top of the file with other module imports. Importing modules inside a function can lead to performance overhead as the module is re-imported every time the function is called. It also improves code readability and organization.