From ec3fc70a66a2071b19bed44adea8054836f87a6f Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 5 Jul 2023 13:37:41 +0800 Subject: [PATCH] rework the font rendering engine and style macros to support Tall this reworks the necessary routines on the font rendering engine and within the style selection macros to support the new Tall font. --- services/graphics-server/src/api/blitstr2.rs | 2 ++ services/graphics-server/src/api/glyphstyle.rs | 4 ++++ services/graphics-server/src/blitstr2/blit.rs | 16 ++++++++++++---- services/graphics-server/src/fontmap.rs | 6 ++++-- services/graphics-server/src/style_macros.rs | 3 +++ services/graphics-server/src/testing.rs | 2 +- services/graphics-server/src/wordwrap.rs | 10 +++++++++- 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/services/graphics-server/src/api/blitstr2.rs b/services/graphics-server/src/api/blitstr2.rs index c1f6a69cb..1f0eacd1f 100644 --- a/services/graphics-server/src/api/blitstr2.rs +++ b/services/graphics-server/src/api/blitstr2.rs @@ -30,6 +30,8 @@ pub struct GlyphSprite { pub insert: bool, // 2x flag for the back-end rendering (wide/high should be pre-computed to match this) pub double: bool, + // flag for 32-bit wide glyph sets + pub large: bool, } /// A TypesetWord is a Word that has beet turned into sprites and placed at a specific location on the canvas, diff --git a/services/graphics-server/src/api/glyphstyle.rs b/services/graphics-server/src/api/glyphstyle.rs index 7c8679c0c..4ca7523f0 100644 --- a/services/graphics-server/src/api/glyphstyle.rs +++ b/services/graphics-server/src/api/glyphstyle.rs @@ -8,6 +8,7 @@ pub enum GlyphStyle { Cjk = 4, Large = 5, ExtraLarge = 6, + Tall = 7, } /// Convert number to style for use with register-based message passing sytems @@ -22,6 +23,7 @@ impl From for GlyphStyle { 4 => GlyphStyle::Cjk, 5 => GlyphStyle::Large, 6 => GlyphStyle::ExtraLarge, + 7 => GlyphStyle::Tall, _ => GlyphStyle::Regular, } } @@ -39,6 +41,7 @@ impl From for usize { GlyphStyle::Cjk => 4, GlyphStyle::Large => 5, GlyphStyle::ExtraLarge => 6, + GlyphStyle::Tall => 7, } } } @@ -57,5 +60,6 @@ pub fn glyph_to_height_hint(g: GlyphStyle) -> usize { GlyphStyle::Cjk => 16, // crate::blistr2::fonts::emoji::MAX_HEIGHT as usize, GlyphStyle::Large => 24, // 2x of small GlyphStyle::ExtraLarge => 30, // 2x of regular + GlyphStyle::Tall => 19, } } \ No newline at end of file diff --git a/services/graphics-server/src/blitstr2/blit.rs b/services/graphics-server/src/blitstr2/blit.rs index 58a34a601..96b2322c8 100644 --- a/services/graphics-server/src/blitstr2/blit.rs +++ b/services/graphics-server/src/blitstr2/blit.rs @@ -139,7 +139,12 @@ pub fn xor_glyph_large(fb: &mut FrBuf, p: &Point, gs: GlyphSprite, xor: bool, cr let x1 = p.x + (wide << 1) - 1; if x1 < cr.min.x as i16 { log::trace!("out the left"); return } // out the left hand side let dest_low_word = x0 >> 5; - let dest_high_word = x1 >> 5; + let mut dest_high_word = x1 >> 5; + // fixup case where a glyph is very narrow and and gs.wide / 2 is rounded down to 0. + // this happens on things like '.' and '1'. + if dest_high_word == dest_low_word { + dest_high_word += 1; + } let px_in_dest_low_word = 32 - (x0 & 0x1f); // Blit it (use glyph height to avoid blitting empty rows) let mut row_base = p.y * WORDS_PER_LINE as i16; @@ -173,7 +178,7 @@ pub fn xor_glyph_large(fb: &mut FrBuf, p: &Point, gs: GlyphSprite, xor: bool, cr } else { fb[(row_base + dest_low_word) as usize] &= 0xffff_ffff ^ ((src << (32 - px_in_dest_low_word)) & partial_mask_lo); } - if (wide << 1) > px_in_dest_low_word { + if (wide << 1) >= px_in_dest_low_word { if xor { fb[(row_base + dest_high_word) as usize] ^= (src >> px_in_dest_low_word) & partial_mask_hi; } else { @@ -213,7 +218,10 @@ pub fn xor_glyph_2x(fb: &mut FrBuf, p: &Point, gs: GlyphSprite, xor: bool, cr: C let x1 = p.x + (wide << 1) - 1; if x1 < cr.min.x as i16 { log::trace!("out the left"); return } // out the left hand side let dest_low_word = x0 >> 5; - let dest_high_word = x1 >> 5; + let mut dest_high_word = x1 >> 5; + if dest_high_word == dest_low_word { + dest_high_word += 1; + } let px_in_dest_low_word = 32 - (x0 & 0x1f); // Blit it (use glyph height to avoid blitting empty rows) let mut row_base = p.y * WORDS_PER_LINE as i16; @@ -260,7 +268,7 @@ pub fn xor_glyph_2x(fb: &mut FrBuf, p: &Point, gs: GlyphSprite, xor: bool, cr: C } else { fb[(row_base + dest_low_word) as usize] &= 0xffff_ffff ^ ((src << (32 - px_in_dest_low_word)) & partial_mask_lo); } - if (wide << 1) > px_in_dest_low_word { + if (wide << 1) >= px_in_dest_low_word { if xor { fb[(row_base + dest_high_word) as usize] ^= (src >> px_in_dest_low_word) & partial_mask_hi; } else { diff --git a/services/graphics-server/src/fontmap.rs b/services/graphics-server/src/fontmap.rs index 103922cfe..2e231753b 100644 --- a/services/graphics-server/src/fontmap.rs +++ b/services/graphics-server/src/fontmap.rs @@ -17,6 +17,8 @@ pub const MONO_OFFSET: usize = 0x1042a0; pub const MONO_LEN: usize = 0x19e0; pub const REGULAR_OFFSET: usize = 0x105c80; pub const REGULAR_LEN: usize = 0x19e0; -pub const SMALL_OFFSET: usize = 0x107660; +pub const TALL_OFFSET: usize = 0x107660; +pub const TALL_LEN: usize = 0x6780; +pub const SMALL_OFFSET: usize = 0x10dde0; pub const SMALL_LEN: usize = 0x19e0; -pub const FONT_TOTAL_LEN: usize = 0x109040; +pub const FONT_TOTAL_LEN: usize = 0x10f7c0; diff --git a/services/graphics-server/src/style_macros.rs b/services/graphics-server/src/style_macros.rs index 247fcac1e..463ee366c 100644 --- a/services/graphics-server/src/style_macros.rs +++ b/services/graphics-server/src/style_macros.rs @@ -18,6 +18,9 @@ macro_rules! style_wrapper { GlyphStyle::ExtraLarge => { $rule!(extra_large_glyph, emoji_large_glyph, $ch) } + GlyphStyle::Tall => { + $rule!(tall_glyph, emoji_glyph, $ch) + } // default to regular _ => { $rule!(regular_glyph, emoji_glyph, $ch) diff --git a/services/graphics-server/src/testing.rs b/services/graphics-server/src/testing.rs index 5e9158c67..0234de717 100644 --- a/services/graphics-server/src/testing.rs +++ b/services/graphics-server/src/testing.rs @@ -14,7 +14,7 @@ enum TestType { Insert = 6, End = 7, } -const TEST_STYLE: GlyphStyle = GlyphStyle::Regular; +const TEST_STYLE: GlyphStyle = GlyphStyle::Tall; pub fn tests() { let _ = std::thread::spawn({ move || { diff --git a/services/graphics-server/src/wordwrap.rs b/services/graphics-server/src/wordwrap.rs index 0116146bf..9bebcdf52 100644 --- a/services/graphics-server/src/wordwrap.rs +++ b/services/graphics-server/src/wordwrap.rs @@ -141,7 +141,15 @@ impl ComposedType { clip_rect.tl().x, clip_rect.tl().y, clip_rect.br().x, clip_rect.br().y ); - if !glyph.double { + if glyph.large { + blitstr2::xor_glyph_large( + frbuf, + &Point::new(maybe_x, maybe_y), + *glyph, + glyph.invert ^ invert, + cr + ); + } else if !glyph.double { blitstr2::xor_glyph( frbuf, &Point::new(maybe_x, maybe_y),