Skip to content
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

Allow specifying font index when loading a font file #853

Closed
7sDream opened this issue Oct 29, 2021 · 6 comments · Fixed by #873
Closed

Allow specifying font index when loading a font file #853

7sDream opened this issue Oct 29, 2021 · 6 comments · Fixed by #873
Labels
feature New feature or request

Comments

@7sDream
Copy link

7sDream commented Oct 29, 2021

I try to let my egui app to use system font.

I can use some font query/loading library to find the font location and read it as binary data, however, it's a ttc file(for example, Microsoft YaHei), so egui report the data a invalid when parsing.

It seems ab_glyph do support collection, by using FontRef::try_from_slice_and_index, so any idea how can I use ttc/otc ffont file as custom font in egui?

update

Maybe there is some bug in the font loading library I used.

I changed from font-loader to fontdb, and now it's working, no invalid font report.

But, IIRC, font loading library gives whole file content, and because I can't pass the font face index to egui, current it will always using the font face at index 0, which means when using ttc/otf, the render result may not be as expected.

For example, Helvetica Neue(Normal style) is in index 10
@7sDream 7sDream changed the title Load ttc/otc font data Use ttc/otc file as custom font Oct 29, 2021
@7sDream 7sDream changed the title Use ttc/otc file as custom font Issue when using ttc/otc file as custom font Oct 29, 2021
@emilk
Copy link
Owner

emilk commented Nov 1, 2021

If you could specify the face index in epaint::FontDefinitions (together with the FontData), would that solve the problem for you?

@7sDream
Copy link
Author

7sDream commented Nov 2, 2021

Yes, I think add a font_face_index: HashMap<String, usize> field in FontDefinitions (with the same key in font_data, values is the index) is a feasible solution.

Considering compatibility, a default value of 0 can be used when the index cannot be found in this field.

@emilk
Copy link
Owner

emilk commented Nov 2, 2021

It seems ab_glyph::FontArc lacks the convenience of try_from_vec_and_index and try_from_slice_and_index. If you make a PR to ab_glyph to add those I can hook them up in egui later!

@parasyte
Copy link
Contributor

parasyte commented Nov 3, 2021

FontArc does implement From<FontRef> though. That should be enough?

@emilk emilk changed the title Issue when using ttc/otc file as custom font Allow specifying font index when loading a font file Nov 3, 2021
@emilk emilk added the feature New feature or request label Nov 3, 2021
@emilk
Copy link
Owner

emilk commented Nov 3, 2021

Good point @parasyte - I made a PR; please try it out @7sDream !

@7sDream
Copy link
Author

7sDream commented Nov 4, 2021

Thank you! I can try this pr tonight, after work

@emilk emilk closed this as completed in #873 Nov 7, 2021
emilk added a commit that referenced this issue Nov 7, 2021
When using a custom font you can now specify a font index

Closes #853
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants