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.
This commit is contained in:
bunnie 2023-07-05 13:37:41 +08:00
parent aab25f2d53
commit ec3fc70a66
7 changed files with 35 additions and 8 deletions

View file

@ -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,

View file

@ -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<usize> for GlyphStyle {
4 => GlyphStyle::Cjk,
5 => GlyphStyle::Large,
6 => GlyphStyle::ExtraLarge,
7 => GlyphStyle::Tall,
_ => GlyphStyle::Regular,
}
}
@ -39,6 +41,7 @@ impl From<GlyphStyle> 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,
}
}

View file

@ -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 {

View file

@ -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;

View file

@ -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)

View file

@ -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 || {

View file

@ -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),