diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 01:04:17 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 01:04:17 +0300 |
| commit | eab46d9be33596b6c689a7a34b90837a89400a89 (patch) | |
| tree | 2afc2ca857882830247349c5db1708137d9772f4 /crates/fparkan-font/src/bitmap.rs | |
| parent | 6c9fe794cda795b101825091aee4644efd9422f8 (diff) | |
| download | fparkan-eab46d9be33596b6c689a7a34b90837a89400a89.tar.xz fparkan-eab46d9be33596b6c689a7a34b90837a89400a89.zip | |
feat(ui): show the original mission loading screen
Diffstat (limited to 'crates/fparkan-font/src/bitmap.rs')
| -rw-r--r-- | crates/fparkan-font/src/bitmap.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/fparkan-font/src/bitmap.rs b/crates/fparkan-font/src/bitmap.rs index 039e3b9f..6360b367 100644 --- a/crates/fparkan-font/src/bitmap.rs +++ b/crates/fparkan-font/src/bitmap.rs @@ -131,6 +131,18 @@ impl BitmapFont { self.centered_line_bytes(&bytes, width, height) } + /// Text extent in native atlas pixels, including character spacing. + pub fn line_metrics(&self, text: &str) -> Result<[u16; 2], String> { + let (bytes, _, unmappable) = WINDOWS_1251.encode(text); + if unmappable { + return Err("game text contains characters outside CP1251".into()); + } + let width = bytes.iter().map(|&byte| self.advance(byte)).sum::<usize>(); + let width = u16::try_from(width).map_err(|_| "game text is too wide")?; + let height = u16::try_from(self.glyph_height).map_err(|_| "game font is too tall")?; + Ok([width, height]) + } + /// Composes a single line from a game resource's original CP1251 bytes. pub fn centered_line_bytes( &self, |
