mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
refactor to cleanup font inclusions
allows more degrees of freedom to free up space
This commit is contained in:
parent
a40eba8199
commit
16073c9cf8
4 changed files with 122 additions and 81 deletions
|
|
@ -19,13 +19,18 @@ rkyv = { version = "0.8.8", default-features = false, features = [
|
||||||
] }
|
] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
zh = []
|
||||||
|
ja = []
|
||||||
|
kr = []
|
||||||
|
emoji = []
|
||||||
|
|
||||||
# selection of board settings for display resolution
|
# selection of board settings for display resolution
|
||||||
bao1x = []
|
bao1x = []
|
||||||
board-baosec = []
|
board-baosec = ["emoji", "ja"]
|
||||||
board-baosor = []
|
board-baosor = ["emoji", "ja", "zh", "kr"]
|
||||||
hosted-baosec = []
|
hosted-baosec = ["emoji", "ja", "zh", "kr"]
|
||||||
hosted = []
|
hosted = ["emoji", "ja", "zh", "kr"]
|
||||||
renode = []
|
renode = ["emoji", "ja", "zh", "kr"]
|
||||||
precursor = []
|
precursor = ["emoji", "ja", "zh", "kr"]
|
||||||
|
|
||||||
default = []
|
default = []
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,17 @@
|
||||||
//
|
//
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
pub mod bold;
|
pub mod bold;
|
||||||
|
#[cfg(feature = "emoji")]
|
||||||
pub mod emoji;
|
pub mod emoji;
|
||||||
|
#[cfg(feature = "ja")]
|
||||||
pub mod ja;
|
pub mod ja;
|
||||||
|
#[cfg(feature = "kr")]
|
||||||
pub mod kr;
|
pub mod kr;
|
||||||
pub mod mono;
|
pub mod mono;
|
||||||
pub mod regular;
|
pub mod regular;
|
||||||
pub mod small;
|
pub mod small;
|
||||||
pub mod tall;
|
pub mod tall;
|
||||||
|
#[cfg(feature = "zh")]
|
||||||
pub mod zh;
|
pub mod zh;
|
||||||
|
|
||||||
use crate::GlyphSprite;
|
use crate::GlyphSprite;
|
||||||
|
|
@ -184,6 +188,7 @@ pub fn tall_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "emoji")]
|
||||||
pub fn emoji_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
pub fn emoji_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
||||||
match emoji::CODEPOINTS.binary_search(&(ch as u32)) {
|
match emoji::CODEPOINTS.binary_search(&(ch as u32)) {
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
|
|
@ -208,6 +213,7 @@ pub fn emoji_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "emoji")]
|
||||||
pub fn emoji_large_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
pub fn emoji_large_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
||||||
match emoji::CODEPOINTS.binary_search(&(ch as u32)) {
|
match emoji::CODEPOINTS.binary_search(&(ch as u32)) {
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
|
|
@ -232,6 +238,7 @@ pub fn emoji_large_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "zh")]
|
||||||
pub fn zh_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
pub fn zh_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
||||||
match zh::CODEPOINTS.binary_search(&(ch as u32)) {
|
match zh::CODEPOINTS.binary_search(&(ch as u32)) {
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
|
|
@ -256,6 +263,7 @@ pub fn zh_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "ja")]
|
||||||
pub fn ja_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
pub fn ja_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
||||||
match ja::CODEPOINTS.binary_search(&(ch as u32)) {
|
match ja::CODEPOINTS.binary_search(&(ch as u32)) {
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
|
|
@ -280,6 +288,7 @@ pub fn ja_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "kr")]
|
||||||
pub fn kr_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
pub fn kr_glyph(ch: char) -> Result<GlyphSprite, usize> {
|
||||||
match kr::CODEPOINTS.binary_search(&(ch as u32)) {
|
match kr::CODEPOINTS.binary_search(&(ch as u32)) {
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
|
|
|
||||||
|
|
@ -61,3 +61,28 @@ pub fn glyph_height_hint(g: GlyphStyle) -> usize {
|
||||||
GlyphStyle::Tall => 19,
|
GlyphStyle::Tall => 19,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Find glyph for char using latin regular, emoji, ja, zh, and kr font data
|
||||||
|
pub fn style_glyph(locale: &'static str, ch: char, base_style: &GlyphStyle) -> GlyphSprite {
|
||||||
|
match locale {
|
||||||
|
#[cfg(feature = "zh")]
|
||||||
|
"zh" => {
|
||||||
|
style_wrapper!(zh_rules, base_style, ch)
|
||||||
|
}
|
||||||
|
#[cfg(feature = "ja")]
|
||||||
|
"jp" => {
|
||||||
|
style_wrapper!(jp_rules, base_style, ch)
|
||||||
|
}
|
||||||
|
#[cfg(feature = "kr")]
|
||||||
|
"kr" => {
|
||||||
|
style_wrapper!(kr_rules, base_style, ch)
|
||||||
|
}
|
||||||
|
"en-tts" => {
|
||||||
|
style_wrapper!(en_audio_rules, base_style, ch)
|
||||||
|
}
|
||||||
|
// default to English rules
|
||||||
|
_ => {
|
||||||
|
style_wrapper!(english_rules, base_style, ch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,78 +30,79 @@ macro_rules! style_wrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
#[cfg(feature = "zh")]
|
||||||
macro_rules! zh_rules {
|
macro_rules! zh_rules {
|
||||||
($base_style:expr, $emoji_style:expr, $ch:ident) => {
|
($base_style:expr, $emoji_style:expr, $ch:ident) => {{
|
||||||
match zh_glyph($ch) {
|
// Always-present: zh itself, base, emoji
|
||||||
Ok(g) => g,
|
#[allow(unused_mut)]
|
||||||
_ => match $base_style($ch) {
|
let mut result =
|
||||||
Ok(g) => g,
|
zh_glyph($ch).ok().or_else(|| $base_style($ch).ok()).or_else(|| $emoji_style($ch).ok());
|
||||||
_ => match $emoji_style($ch) {
|
|
||||||
Ok(g) => g,
|
#[cfg(feature = "ja")]
|
||||||
_ => match ja_glyph($ch) {
|
if result.is_none() {
|
||||||
Ok(g) => g,
|
result = ja_glyph($ch).ok();
|
||||||
_ => match kr_glyph($ch) {
|
|
||||||
Ok(g) => g,
|
|
||||||
_ => match $base_style(REPLACEMENT) {
|
|
||||||
Ok(g) => g,
|
|
||||||
_ => NULL_GLYPH_SPRITE,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
#[cfg(feature = "kr")]
|
||||||
|
if result.is_none() {
|
||||||
|
result = kr_glyph($ch).ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always-present: replacement and null sentinel
|
||||||
|
result.or_else(|| $base_style(REPLACEMENT).ok()).unwrap_or(NULL_GLYPH_SPRITE)
|
||||||
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
#[cfg(feature = "ja")]
|
||||||
macro_rules! jp_rules {
|
macro_rules! jp_rules {
|
||||||
($base_style:expr, $emoji_style:expr, $ch:ident) => {
|
($base_style:expr, $emoji_style:expr, $ch:ident) => {{
|
||||||
match ja_glyph($ch) {
|
// Always-present: ja itself, base, emoji
|
||||||
Ok(g) => g,
|
#[allow(unused_mut)]
|
||||||
_ => match $base_style($ch) {
|
let mut result =
|
||||||
Ok(g) => g,
|
ja_glyph($ch).ok().or_else(|| $base_style($ch).ok()).or_else(|| $emoji_style($ch).ok());
|
||||||
_ => match $emoji_style($ch) {
|
|
||||||
Ok(g) => g,
|
// Optional: zh fallback only if zh is in the build
|
||||||
_ => match zh_glyph($ch) {
|
#[cfg(feature = "zh")]
|
||||||
Ok(g) => g,
|
if result.is_none() {
|
||||||
_ => match kr_glyph($ch) {
|
result = zh_glyph($ch).ok();
|
||||||
Ok(g) => g,
|
|
||||||
_ => match $base_style(REPLACEMENT) {
|
|
||||||
Ok(g) => g,
|
|
||||||
_ => NULL_GLYPH_SPRITE,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
// Optional: kr fallback only if kr is in the build
|
||||||
|
#[cfg(feature = "kr")]
|
||||||
|
if result.is_none() {
|
||||||
|
result = kr_glyph($ch).ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always-present: replacement and null sentinel
|
||||||
|
result.or_else(|| $base_style(REPLACEMENT).ok()).unwrap_or(NULL_GLYPH_SPRITE)
|
||||||
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
#[cfg(feature = "kr")]
|
||||||
macro_rules! kr_rules {
|
macro_rules! kr_rules {
|
||||||
($base_style:expr, $emoji_style:expr, $ch:ident) => {
|
($base_style:expr, $emoji_style:expr, $ch:ident) => {{
|
||||||
match kr_glyph($ch) {
|
// Always-present: kr itself, base, emoji
|
||||||
Ok(g) => g,
|
#[allow(unused_mut)]
|
||||||
_ => match $base_style($ch) {
|
let mut result =
|
||||||
Ok(g) => g,
|
kr_glyph($ch).ok().or_else(|| $base_style($ch).ok()).or_else(|| $emoji_style($ch).ok());
|
||||||
_ => match $emoji_style($ch) {
|
|
||||||
Ok(g) => g,
|
// Optional: ja fallback only if ja is in the build
|
||||||
_ => match ja_glyph($ch) {
|
#[cfg(feature = "ja")]
|
||||||
Ok(g) => g,
|
if result.is_none() {
|
||||||
_ => match zh_glyph($ch) {
|
result = ja_glyph($ch).ok();
|
||||||
Ok(g) => g,
|
|
||||||
_ => match $base_style(REPLACEMENT) {
|
|
||||||
Ok(g) => g,
|
|
||||||
_ => NULL_GLYPH_SPRITE,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
// Optional: zh fallback only if zh is in the build
|
||||||
|
#[cfg(feature = "zh")]
|
||||||
|
if result.is_none() {
|
||||||
|
result = zh_glyph($ch).ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always-present: replacement and null sentinel
|
||||||
|
result.or_else(|| $base_style(REPLACEMENT).ok()).unwrap_or(NULL_GLYPH_SPRITE)
|
||||||
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|
@ -150,27 +151,28 @@ macro_rules! english_rules {
|
||||||
// Reflect reduced font space on small-memory footprint devices
|
// Reflect reduced font space on small-memory footprint devices
|
||||||
#[cfg(any(feature = "board-baosec", feature = "hosted-baosec"))]
|
#[cfg(any(feature = "board-baosec", feature = "hosted-baosec"))]
|
||||||
macro_rules! english_rules {
|
macro_rules! english_rules {
|
||||||
($base_style:expr, $emoji_style:expr, $ch:ident) => {
|
($base_style:expr, $emoji_style:expr, $ch:ident) => {{
|
||||||
match $base_style($ch) {
|
// Always-present: base, emoji
|
||||||
Ok(g) => g,
|
#[allow(unused_mut)]
|
||||||
_ => match $emoji_style($ch) {
|
let mut result = $base_style($ch).ok().or_else(|| $emoji_style($ch).ok());
|
||||||
Ok(g) => g,
|
|
||||||
// add more character sets to bao1x target by adding match clauses here
|
// Optional: zh fallback only if zh is in the build
|
||||||
_ => match zh_glyph($ch) {
|
#[cfg(feature = "zh")]
|
||||||
Ok(g) => g,
|
if result.is_none() {
|
||||||
_ => match $base_style(REPLACEMENT) {
|
result = zh_glyph($ch).ok();
|
||||||
Ok(g) => g,
|
|
||||||
_ => NULL_GLYPH_SPRITE,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
// Always-present: replacement and null sentinel
|
||||||
|
result.or_else(|| $base_style(REPLACEMENT).ok()).unwrap_or(NULL_GLYPH_SPRITE)
|
||||||
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use en_audio_rules;
|
pub use en_audio_rules;
|
||||||
pub use english_rules;
|
pub use english_rules;
|
||||||
|
#[cfg(feature = "ja")]
|
||||||
pub use jp_rules;
|
pub use jp_rules;
|
||||||
|
#[cfg(feature = "kr")]
|
||||||
pub use kr_rules;
|
pub use kr_rules;
|
||||||
pub use style_wrapper;
|
pub use style_wrapper;
|
||||||
|
#[cfg(feature = "zh")]
|
||||||
pub use zh_rules;
|
pub use zh_rules;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue