From eab46d9be33596b6c689a7a34b90837a89400a89 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 02:04:17 +0400 Subject: feat(ui): show the original mission loading screen --- crates/fparkan-font/src/bitmap.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/fparkan-font/src/bitmap.rs') 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::(); + 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, -- cgit v1.2.3