Skip to content

Conversation

@lrh3321
Copy link

@lrh3321 lrh3321 commented Apr 18, 2024

fix #80

switch runtime.GOOS {
case "windows":
DefaultFontsDirectories = []string{filepath.Join(os.Getenv("windir"), "Fonts")}
case "linux":
Copy link
Contributor

@isabelroses isabelroses Apr 19, 2024

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)

Copy link
Author

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

Copy link
Contributor

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.

@maaslalani
Copy link
Contributor

maaslalani commented Apr 22, 2024

Thank you for this PR, it's very much appreciated ❤️

@remino
Copy link

remino commented Aug 15, 2024

Appreciated, yet never merged.

Wangnov pushed a commit to Wangnov/freeze that referenced this pull request Dec 24, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output blank png image when use custom font family in windows

4 participants