-
-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): safe iface for get_glyph_data
[no changelog]
- Loading branch information
Showing
5 changed files
with
251 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,12 @@ | ||
mod blob; | ||
mod flash; | ||
pub mod flash; | ||
mod generated; | ||
#[cfg(feature = "micropython")] | ||
mod obj; | ||
mod public_keys; | ||
mod translated_string; | ||
|
||
pub use blob::Translations; | ||
pub use translated_string::TranslatedString as TR; | ||
|
||
use crate::ui::display::Font; | ||
pub const DEFAULT_LANGUAGE: &str = "en-US"; | ||
|
||
/// # Safety | ||
/// | ||
/// Returned pointer will only point to valid font data for as long as | ||
/// the flash content is not invalidated by `erase()` or `write()`. | ||
pub unsafe fn get_utf8_glyph(codepoint: u16, font: Font) -> *const u8 { | ||
// SAFETY: Reference is discarded at the end of the function. | ||
// We do return a _pointer_ to the same memory location, but the pointer is | ||
// always valid. | ||
let Ok(translations) = flash::get() else { | ||
return core::ptr::null(); | ||
}; | ||
let Some(tr) = translations.as_ref() else { | ||
return core::ptr::null(); | ||
}; | ||
if let Some(glyph) = tr.font(font as u16).and_then(|t| t.get(codepoint)) { | ||
glyph.as_ptr() | ||
} else { | ||
core::ptr::null() | ||
} | ||
} |
Oops, something went wrong.