emilk / egui

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
https://www.egui.rs/
Apache License 2.0
21.57k stars 1.56k forks source link

add Fontweight to fontid #3218

Open Omicronlawful opened 1 year ago

Omicronlawful commented 1 year ago

It would be usefull if the font weight could be set when creating a fontid. Im not sure if there is another way, like it is solved for italics, but i would put it into fontid

abey79 commented 1 year ago

In particular, support for variable font weight would be nice.

emilk commented 1 year ago

First of all: italics in epaint is a hack. We just skew the glyphs when we paint them. Ideally we should instead switch to an italic font of the same family instead.

To fully support font weights and italics we need to have better support for selecting font families. For example: Inter is a font family with many different fonts for different weights and styles (Thin, Thin Italics, Bold, Bold Italics, etc).

A font family can be stored in several .ttf files, or in the same one. To know what we have loaded, we would need to read it at some sort of font meta-data (was the loaded font thin, italics, …?). I don't think ab_glyph supports this at the moment: https://docs.rs/ab_glyph/latest/ab_glyph/trait.Font.html

Once that all is done, then yes, FontId would be the right place to add weight and italics.

So: if someone is interested in working on this, please help research how we can read the style metadata out of a .ttf file (i.e. thin vs bold, and italics vs normal), and maybe add that feature to ab_glyph!

abey79 commented 1 year ago

I believe there are actually two stories here:

The latter would be very nice to have as I understand designers rely on it more and more. As it turns out, the font we're using for Rerun is variable (https://fonts.google.com/specimen/Inter).

JustFrederik commented 10 months ago

@emilk not sure if this is helpful, but ttf parser has an example for handling metadata: https://github.com/RazrFalcon/ttf-parser/blob/master/examples/font-info.rs