Skip to content

fix: support TTC font face selection via fontconfig index#498

Merged
RobertMueller2 merged 1 commit into
Satty-org:mainfrom
sitiyou:fix-ttc
May 7, 2026
Merged

fix: support TTC font face selection via fontconfig index#498
RobertMueller2 merged 1 commit into
Satty-org:mainfrom
sitiyou:fix-ttc

Conversation

@sitiyou
Copy link
Copy Markdown
Contributor

@sitiyou sitiyou commented May 6, 2026

See #495 for more information.

Satty currently loads fonts through Canvas::add_font, which always uses face index 0 internally.

This PR changed the font initialization flow to:

  • create a TextContext first
  • load the matched font through TextContext::add_shared_font_with_index
  • initialize the canvas with Canvas::new_with_text_context(...)

By doing so, Satty can use the face index returned by fontconfig and load the correct TTC face instead of always falling back to face 0


close #495

@sitiyou
Copy link
Copy Markdown
Contributor Author

sitiyou commented May 6, 2026

I have fixed the ci linter errors

@RobertMueller2
Copy link
Copy Markdown
Member

Thank you looking into this and for the PR. I first thought this was a femtovg bug, but this change looks almost like we're not using it correctly?

I haven't tested the change fully yet, but I've got two remarks.

  • can you use eprintln! instead of println! please? we're trying to correct this in fix: replace println! with eprintln! #479 for all the other places
  • the two match arms do almost the same. Perhaps this could be deduplicated with a helper function e.g. with is_fallback bool parameter? What do you think?

@sitiyou
Copy link
Copy Markdown
Contributor Author

sitiyou commented May 7, 2026

I first thought this was a femtovg bug, but this change looks almost like we're not using it correctly?

I agree this is not really a femtovg bug.
Canvas::add_font as a simple high-level API is reasonable even without a face_index parameter, since TextContext already provides the full font-loading API.

I haven't tested the change fully yet, but I've got two remarks.

I have replaced my println! with eprintln!, and created a load_font closure that consolidates all font loading logic.

I also changed loaded_paths from HashSet<PathBuf> to HashSet<(PathBuf, u32)>, using (path, face_index) as the deduplication key so different faces in the same TTC file are not mistaken for the same font.


It now works great on my system. I'm happy to help with testing if you need it.

@RobertMueller2
Copy link
Copy Markdown
Member

Makes sense and looks good to me.

@RobertMueller2 RobertMueller2 merged commit 772edbc into Satty-org:main May 7, 2026
3 checks passed
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.

font error

2 participants