diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-22 03:31:51 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-22 21:40:21 -0700 |
| commit | 33a0aea1fa5b12c817cc299b10f8a359d670c645 (patch) | |
| tree | 1f29b867d49a6158edc679c3cc1521a77f1175d7 /src/x/font_list.rs | |
| parent | efa17e7eb566d81ce821bde459e900d7398a9977 (diff) | |
there are now concepts of font lists and text lines
a "line" is a list of spans much of the layout logic is moved into TextLine, but not yet all of it Change-Id: I2edba34cd9be5a50ac6dc646cd6e2ab2369fca13 Force-Push: yes
Diffstat (limited to 'src/x/font_list.rs')
| -rw-r--r-- | src/x/font_list.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/x/font_list.rs b/src/x/font_list.rs new file mode 100644 index 0000000..d21d8c4 --- /dev/null +++ b/src/x/font_list.rs @@ -0,0 +1,61 @@ +use crate::error::{ Error, Result }; +use crate::x::{ Display, Font }; + +use std::sync::Arc; + + +pub struct FontList { + display: Arc<Display>, + fonts: Vec<Arc<Font>>, +} + +impl FontList { + pub fn new(display: Arc<Display>) -> Result<FontList> { + let fonts = Vec::new(); + + Ok(FontList { display, fonts }) + } + + pub fn append(&mut self, name: &str) -> Result<()> { + let font = Font::new(Arc::clone(&self.display), name)?; + + self.append_font(font); + + Ok(()) + } + + pub fn append_font(&mut self, font: Arc<Font>) { + self.fonts.push(font); + } + + /* The primary font is the first one in the list. Ascribing meaning to this + * is up to the caller. + */ + pub fn primary_font(&self) -> Result<Arc<Font>> { + if self.fonts.len() > 0 { + return Ok(Arc::clone(&self.fonts[0])); + } + + Err(Error::custom("There are no fonts in the list.")) + } + + /* This accepts a Unicode codepoint, and returns a font containing it. At + * least, that's the hope. The xft docs are thin on the topic of what + * encoding the codepoint is in, and it's entirely possible something weird + * happens in fonts for which ISO-10646 is not an explicitly provided + * encoding, or for which it's provided in an unusual way. + * + * If the character isn't found in any font, this returns the primary font, + * on the assumption that's the one whose missing-glyph glyph we want. + */ + pub fn find_codepoint(&self, codepoint: u32) -> Result<Arc<Font>> { + for font in &self.fonts { + if font.check_char_exists(codepoint)? { + return Ok(Arc::clone(&font)); + } + } + + self.primary_font() + } +} + |