Fix g.wrapString lockup if wrap width is less than the character width

This commit is contained in:
Gordon Williams 2024-01-31 14:40:22 +00:00
parent 99e03e2d8e
commit 372d4afa4a
3 changed files with 10 additions and 1 deletions

View File

@ -16,6 +16,7 @@
Add jsvGet...Child functions to replace common call patterns - saves 280 bytes on Pico
Fix issue with g.wrapString when running on flash-based strings
Fix lock leak when using flat/flash/native strings as object indices
Fix g.wrapString lockup if wrap width is less than the character width
2v20 : Ensure String.charCodeAt returns NaN for out of bounds chars
Bangle.js2: When rendering overlays, *do not* use the current FG/BG color for 1 bit overlays

View File

@ -2428,7 +2428,8 @@ JsVar *jswrap_graphics_wrapString(JsVar *parent, JsVar *str, int maxWidth) {
while (wordStartIdx < currentPos) {
char wordCh = jsvGetCharInString(str, wordStartIdx);
int w = _jswrap_graphics_getCharWidth(&gfx, &info, wordCh);
if (width+w < maxWidth) {
if (width+w < maxWidth || !width) { // add while it fits OR it's the first character
// !width stops us locking up if char width>split width
wordStartIdx++;
wordWidth -= w;
lineWidth -= w;

View File

@ -40,6 +40,11 @@ g.clear().setFont("4x6");
lines = g.wrapString("X", 10);
SHOULD_BE(lines, ["X"]);
// wrapping when the area is too small to show even one char
g.clear().setFont("4x6");
lines = g.wrapString("XYZ", 2);
SHOULD_BE(lines, ["X","Y","Z"]);
// wrap a long word to multiple lines
g.clear().setFont("4x6");
lines = g.wrapString("ABCDEFGHIJ", 10);
@ -114,4 +119,6 @@ require("Storage").erase("x")
SHOULD_BE(lines, ["Compacting...","Takes approx","1 minute"]);
result = ok;