ui/fontpick.rs#
Source: lib/ui/fontpick.rs
fontpick -- the system's fonts in the UI: the font database and its rules, loading a
choice, text in such a font, a font picker and a font dialog (their lists, searches and
choices kept per window: WinParts::fonts)
FontSel { family, weight, italic, size, axes } a choice: a family (also a generic one:
"sans-serif", "serif", "monospace" ...), 100..900, italic,
the size in points, axis values of a variable family
(FontSel::new: none; axis / set_axis)
ui.fonts() -> &FontDb the installed fonts, scanned on first use (cache
cache://fontdb.fdb; jfgui_FONTDIRS: these folders, no cache)
ui.font_conf() -> &FontConf generic families, substitutes, the languages' fonts
(text::fontconf: a light fontconfig)
ui.font_load(&sel) -> Option<u32> resolve (FontDb::resolve in the UI language) and load
into ui.text: a font id for set_font / cmd_text; each
family / weight / italic once. A variable face: its
instance (FontDb::load_var): weight -> wght, italic -> ital
/ slnt, the size -> opsz, the axes named win; the instances
of the VAR_KEEP most recent such choices and the app
theme's faces stay loaded (older ones are unloaded, their
ids may be reused)
ui.font_resolved(&sel) -> String the installed family font_load takes ("" none)
ui.font_register(family, weight, italic, font) a font of the app's own (load_mem) under
a family name for font_load; font_registered() lists them
ui.text_in_font(font, size_pt, s) one line of text in a font id at a size in points
ui.font_picker(id, &mut sel) -> EV a drop-down button with the family (a search box and
the families open below it: typing filters and takes
the first match, Up / Down / a click choose) and a size
box in points; EV_ACT when sel changed
ui.font_dialog(id, &open, &mut sel) -> EV a modal dialog window "Schriftart": search,
families, the family's styles, sizes, a preview in the
font, OK / Abbrechen; works on a copy of sel and writes it
back on OK (EV_ACT); closing clears open. A variable
family lists its named instances as styles and gets a
slider and a number box per axis (fvar's range and name;
hidden axes not), opsz with "Automatisch" (follows the size)
font_language() -> String the language the fonts follow: the user's tag of the UI
language (ja-JP, zh-Hant-TW), else its code
The runtime hands font_language() to the system fallback (text::fallback, again when the
UI language changes), so missing Han characters take the forms of the language. Ids:
the scope of the widget's id, then "family", "search", "list", "styles", "size",
"sizes", the axes' "axis" scope with per axis id_n(k) (slider), id_n(k + 100) (number
box), "opsz_auto" (ids.rs).
struct FontSela font choice (see the module header)family: Stringweight: u32italic: boolsize: f64-- pointsaxes: Vec<([u8; 4], f32)>-- axis values of a variable family in user units by tag ((*b"wdth", 87.5)); the axes not named follow weight (wght), italic (ital, slnt) and size (opsz), else their defaults; families that are not variable ignore them
impl FontSel
fn new(family: &str, size: f64) -> FontSelregular, upright, no axis valuesfn axis(&self, tag: [u8; 4]) -> Option<f32>the valueaxesnames for a tag (None: the tag follows weight / italic / size or its default)fn set_axis(&mut self, tag: [u8; 4], v: f32)name an axis value (replacing the tag's); NaN takes the tag out againfn font_language() -> Stringthe language the fonts follow: the user's tag of the UI language, else its code
impl Ui
fn fonts(&mut self) -> &FontDbthe installed fonts (scanned on first use)fn font_conf(&mut self) -> &FontConfthe rules for generic families, substitutes and languagesfn font_load(&mut self, sel: &FontSel) -> Option<u32>the font of a choice loaded into ui.text -> its id (None: no installed font fits)fn font_resolved(&mut self, sel: &FontSel) -> Stringthe installed family font_load takes for a choice ("" none)fn font_register(&mut self, family: &str, weight: u32, italic: bool, font: u32)a font of the app's own (an id of ui.text.load_mem) under a family name: font_load takes it for that family, weight and slant without asking the installed fonts; the rich-text toolbar lists the registered families (rich_edit.rs)fn font_registered(&self) -> Vec<String>the families of font_register, in the order of their first registrationfn text_in_font(&mut self, font: u32, size_pt: f64, s: &str)one line of text in font idfontat size_pt points (the body text colour)fn font_picker(&mut self, id: u32, sel: &mut FontSel) -> u32the font picker (see the module header) -> EV_ACT when sel changedfn font_dialog(&mut self, id: u32, open: &Shared<i32>, sel: &mut FontSel) -> u32the font dialog (see the module header) -> EV_ACT when OK took the choice