-
Notifications
You must be signed in to change notification settings - Fork 81
fix: manually load font file or fonts dirs when use resvg-go #83
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
base: main
Are you sure you want to change the base?
Conversation
| switch runtime.GOOS { | ||
| case "windows": | ||
| DefaultFontsDirectories = []string{filepath.Join(os.Getenv("windir"), "Fonts")} | ||
| case "linux": |
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.
why not make this (the linux case) the default case then it should also be able to handle BSD systems too (at least in theory)
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.
if librsvg was installed, it won't meet this case.it easy for linux / BSD systems user to install librsvg
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.
I wonder if it would be better to do this at build time, rather than runtime? I.e. have font_linux.go, font_darwin.go, font_windows.go files, with the //go:build directives.
|
Thank you for this PR, it's very much appreciated ❤️ |
|
Appreciated, yet never merged. |
This commit adds support for loading system fonts when converting SVG to PNG, which fixes the issue where CJK and other non-ASCII characters are not rendered correctly in PNG output. Changes: - Add platform-specific font directory definitions using build tags: - dirs_darwin.go: macOS system font directories - dirs_linux.go: Linux system font directories - dirs_windows.go: Windows system font directories - dirs_other.go: fallback for unsupported platforms - Modify png.go to load fonts from system directories - Add FREEZE_NO_SYSTEM_FONTS=1 env var to skip system font loading - Warn when font directories fail to load (visible at default log level) - Handle os.UserHomeDir() errors properly Performance note: Font directories are scanned on each conversion. For better performance, set FREEZE_NO_SYSTEM_FONTS=1, use SVG output, or install rsvg-convert. Fixes charmbracelet#93 Related to charmbracelet#83
fix #80