forked from Blendman974/faceclaw
EvenHub compativility fixes: Z-order changes, different text color distribution, text containers scroll
This commit is contained in:
1 parent
c713815694
commit
10a9c85f27
22 files changed
+1545
-610
No files matched your search
@@ -596,6 +596,25 @@ export class GrayImage {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* bakeDeferredDrawsInPlace, but only for the draws whose ink may fall inside
|
||||
* `rect`; the rest stay deferred. For covering part of the image with later
|
||||
* raster (the EvenHub compositor painting an image container over text)
|
||||
* without giving up the deferred wire path for everything else.
|
||||
*/
|
||||
bakeDeferredDrawsWithin(rect: { x: number; y: number; width: number; height: number }): void {
|
||||
if (!this.drawList.length) return;
|
||||
const covered = (b: { x: number; y: number; width: number; height: number } | null) =>
|
||||
!b || (b.x < rect.x + rect.width && rect.x < b.x + b.width && b.y < rect.y + rect.height && rect.y < b.y + b.height);
|
||||
const bake: DeferredDraw[] = [];
|
||||
const keep: DeferredDraw[] = [];
|
||||
for (const placed of this.drawList) (covered(placedDrawBounds(placed)) ? bake : keep).push(placed);
|
||||
if (!bake.length) return;
|
||||
this.drawList.splice(0, this.drawList.length, ...bake);
|
||||
this.bakeDeferredDrawsInPlace();
|
||||
this.drawList.push(...keep);
|
||||
}
|
||||
|
||||
/**
|
||||
* A copy of this image with its brightness scaled by `factor` (0..1):
|
||||
* raster and glyph / firmware-text draws alike, keeping the draws deferred
|
||||
@@ -705,6 +724,35 @@ export function grayToNibble(value: number): number {
|
||||
/** Where rasterizeGlyph writes: an image, or a clipped buffer (paintReplayDraws). */
|
||||
type PixelSink = { setPixel(x: number, y: number, value: number): void };
|
||||
|
||||
/** A deferred draw's ink rectangle, or null when it can't be bounded (treat as anywhere). */
|
||||
function placedDrawBounds(placed: DeferredDraw): { x: number; y: number; width: number; height: number } | null {
|
||||
if (placed.kind === "glyph") {
|
||||
const { glyph } = placed;
|
||||
return {
|
||||
x: placed.x + glyph.bbxX,
|
||||
y: placed.y + placed.font.ascent - (glyph.bbxHeight + glyph.bbxY),
|
||||
width: glyph.bbxWidth,
|
||||
height: glyph.bbxHeight,
|
||||
};
|
||||
}
|
||||
if (placed.kind === "image") {
|
||||
return placed.presentation ? null : { x: placed.x, y: placed.y, width: placed.source.width, height: placed.source.height };
|
||||
}
|
||||
let left = Infinity, top = Infinity, right = -Infinity, bottom = -Infinity;
|
||||
for (const member of placed.glyphs) {
|
||||
if (!member.ink) continue;
|
||||
const wire = placed.font.fwGlyphWireData(member.cp);
|
||||
if (!wire) return null;
|
||||
const x = placed.x + member.dx + wire.ofsX;
|
||||
const y = placed.y + wire.inkTop;
|
||||
left = Math.min(left, x);
|
||||
top = Math.min(top, y);
|
||||
right = Math.max(right, x + wire.boxW);
|
||||
bottom = Math.max(bottom, y + wire.boxH);
|
||||
}
|
||||
return right < left ? { x: placed.x, y: placed.y, width: 0, height: 0 } : { x: left, y: top, width: right - left, height: bottom - top };
|
||||
}
|
||||
|
||||
/** Bake one glyph into an image's pixel buffer (y is the top of the line). */
|
||||
function rasterizeGlyph(
|
||||
target: PixelSink,
|
||||
|
||||
+27
-37
@@ -1,19 +1,21 @@
|
||||
/**
|
||||
* Word wrap for EvenHub text containers, after LVGL's lv_text_get_next_line
|
||||
* as ported by @evenrealities/pretext's measureTextWrap, so soft breaks land
|
||||
* where apps that measure with pretext expect them. The loop mirrors
|
||||
* measureTextWrap's, including rescanning from the break point when it wraps
|
||||
* at an earlier opportunity.
|
||||
* Word wrap for EvenHub text containers, matching the stock firmware's LVGL
|
||||
* labels as measured by running firmware 2.2.9.22 in the g2-firmware-emulator:
|
||||
*
|
||||
* One deliberate difference from pretext: pretext skips leading spaces at the
|
||||
* start of every line, but stock keeps them at the start of the text and after
|
||||
* a '\n'; only a soft-wrapped continuation line loses them. Apps indent with
|
||||
* spaces to clear image containers placed beside their text: Iris Pro indents a
|
||||
* line 11 spaces (44px) past a 40px glyph. Stripping that indent slid the text
|
||||
* under the icon.
|
||||
* - Spaces are kept wherever they fall: at the start of the text, after a
|
||||
* '\n', and on soft-wrapped lines. A space that doesn't fit at the end of a
|
||||
* line starts the next one, so "HHHHHHHH EEEE" in 100px (8 H = 96px,
|
||||
* 5px spaces) wraps with all four spaces indenting the second line.
|
||||
* - A line otherwise breaks after its last space, hyphen or CJK ideograph,
|
||||
* or, with none, before the character that overflows.
|
||||
*
|
||||
* @evenrealities/pretext's measureTextWrap, which apps measure with, differs
|
||||
* in one way: it drops spaces at the start of every line. Apps rely on stock's
|
||||
* behavior, though: Iris Pro indents a line 11 spaces past a 40px glyph placed
|
||||
* beside it, and stripping the indent slid the text under the icon.
|
||||
*/
|
||||
|
||||
/** Wrap opportunities: space, hyphen, and between CJK ideographs (pretext parity). */
|
||||
/** Wrap opportunities: space, hyphen, and between CJK ideographs. */
|
||||
export function isLvglBreakable(cp: number): boolean {
|
||||
if (cp === 32 || cp === 45) return true;
|
||||
return (cp >= 0x2e80 && cp <= 0x9fff) || (cp >= 0xf900 && cp <= 0xfaff) || (cp >= 0xac00 && cp <= 0xd7af);
|
||||
@@ -30,55 +32,43 @@ export function wrapLvglText(text: string, maxWidth: number, advanceOf: (cp: num
|
||||
let line: number[] = [];
|
||||
let lineWidth = 0;
|
||||
// The last break opportunity on this line, as an index into cps, and how
|
||||
// many of `line`'s codepoints a wrap there keeps (a breaking space is dropped).
|
||||
// many of `line`'s codepoints end at it.
|
||||
let lastBreak = -1;
|
||||
let lastBreakKeep = 0;
|
||||
// Whether `line` continues a soft-wrapped line, whose leading spaces are dropped.
|
||||
let continuation = false;
|
||||
|
||||
const endLine = (keep: number[], next: number[], nextWidth: number) => {
|
||||
const endLine = (keep: number[]) => {
|
||||
lines.push(String.fromCodePoint(...keep));
|
||||
line = next;
|
||||
lineWidth = nextWidth;
|
||||
line = [];
|
||||
lineWidth = 0;
|
||||
lastBreak = -1;
|
||||
continuation = true;
|
||||
};
|
||||
|
||||
let i = 0;
|
||||
while (i < cps.length) {
|
||||
const cp = cps[i]!;
|
||||
if (cp === 10) {
|
||||
endLine(line, [], 0);
|
||||
continuation = false;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (continuation && line.length === 0 && cp === 32) {
|
||||
endLine(line);
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
const adv = advanceOf(cp, cps[i + 1] ?? 0);
|
||||
if (lineWidth + adv <= maxWidth) {
|
||||
if (lineWidth + adv <= maxWidth || line.length === 0) {
|
||||
// A character wider than the whole line still takes one to itself.
|
||||
line.push(cp);
|
||||
lineWidth += adv;
|
||||
if (isLvglBreakable(cp)) {
|
||||
lastBreak = i;
|
||||
lastBreakKeep = cp === 32 ? line.length - 1 : line.length;
|
||||
lastBreakKeep = line.length;
|
||||
}
|
||||
i++;
|
||||
} else if (cp === 32) {
|
||||
// The overflowing char is a space: break here and discard it.
|
||||
endLine(line, [], 0);
|
||||
i++;
|
||||
} else if (lastBreak !== -1) {
|
||||
// Wrap at the last break opportunity and rescan from just after it.
|
||||
} else if (cp !== 32 && lastBreak !== -1) {
|
||||
// Wrap after the last break opportunity and rescan from there.
|
||||
const restart = lastBreak + 1;
|
||||
endLine(line.slice(0, lastBreakKeep), [], 0);
|
||||
endLine(line.slice(0, lastBreakKeep));
|
||||
i = restart;
|
||||
} else {
|
||||
// No break opportunity: hard break before the overflowing char.
|
||||
endLine(line, [cp], adv);
|
||||
i++;
|
||||
// An overflowing space, or no break opportunity: this character starts the next line.
|
||||
endLine(line);
|
||||
}
|
||||
}
|
||||
lines.push(String.fromCodePoint(...line));
|
||||
|
||||
Reference in new issue
Block a user