From 3c5975715d4a4919b27fc69ca25b90965ad8da4c Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 4 Mar 2025 19:02:45 +0800 Subject: [PATCH] kind of hack to make font rendering work on oled displays so, there is a fundamental abstraction mismatch in the blitstr library. In Precursor, I created a rule that you can't draw text on black backgrounds without some special permissions in highly trusted contexts. For baosec, this restriction is removed because the whole OS can run inside a single chip (i.e. we have eliminated most easy RAM modification attacks, requires probing/glitching; but as a trade-off, we don't have as much RAM so we can't afford the extra abstractions). The compromise is for OLED-type platforms where inverse drawing is very common to save power, all text ops are assumed to be XOR operations (so you're always flipping pixels instead of drawing at a defined color). --- libs/ux-api/src/wordwrap.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libs/ux-api/src/wordwrap.rs b/libs/ux-api/src/wordwrap.rs index e0057a89e..d9a5ebcda 100644 --- a/libs/ux-api/src/wordwrap.rs +++ b/libs/ux-api/src/wordwrap.rs @@ -160,18 +160,20 @@ impl ComposedType { let cr = ClipRect::new(clip_rect.tl().x, clip_rect.tl().y, clip_rect.br().x, clip_rect.br().y); let rawbuf = unsafe { frbuf.raw_mut() }; - if glyph.large { - blitstr2::xor_glyph_large( - rawbuf, - (maybe_x, maybe_y), - glyph, - glyph.invert ^ invert, - cr, - ); - } else if !glyph.double { - blitstr2::xor_glyph(rawbuf, (maybe_x, maybe_y), glyph, glyph.invert ^ invert, cr); + let char_invert = if cfg!(feature = "hosted-baosec") || cfg!(feature = "board-baosec") { + // OLED display background is black for power savings, so all polarities of drawing + // need to be allowed + true } else { - blitstr2::xor_glyph_2x(rawbuf, (maybe_x, maybe_y), glyph, glyph.invert ^ invert, cr); + glyph.invert ^ invert + }; + + if glyph.large { + blitstr2::xor_glyph_large(rawbuf, (maybe_x, maybe_y), glyph, char_invert, cr); + } else if !glyph.double { + blitstr2::xor_glyph(rawbuf, (maybe_x, maybe_y), glyph, char_invert, cr); + } else { + blitstr2::xor_glyph_2x(rawbuf, (maybe_x, maybe_y), glyph, char_invert, cr); } // Platform-dependent cursor inversion because the color scheme for sh1107 doesn't comply // to precursor norms