stew

a monorepo of some sort
git clone git://git.nsmpr.xyz/stew.git
Log | Files | Refs

commit 3cda7456ddbe43411f96c821016a83260f99c8fb
parent eb229cf15844b7edcebfcd2430d3d340f2c60bf8
Author: Pavel Renev <an2qzavok@gmail.com>
Date:   Mon, 13 Jan 2025 17:33:44 +0000

src/boxes: sync

Diffstat:
Msrc/boxes/boxes.c | 45+++++++++++++--------------------------------
1 file changed, 13 insertions(+), 32 deletions(-)

diff --git a/src/boxes/boxes.c b/src/boxes/boxes.c @@ -67,17 +67,16 @@ int arrangerectsv(Rectangle *buf, int height, Rectangle *src, int n); int arrangerectsh(Rectangle *buf, int width, Rectangle *src, int n); int arrangerects(Rectangle *buf, int width, Rectangle *src, int n); int alignrects(Rectangle *buf, Rectangle bnd, Rectangle *src, int n, int t); -int runestringfit(Font *f, Rune *r, int n, int w); -// int stringfit(Font *f, char *s, int n, int w); void calcwidth(TextBlock *tb){ int i, x; tb->width = malloc(sizeof(int) * tb->len); for(x = 0, i = 0; i < tb->len; i++){ - x += runestringnwidth(tb->font, tb->str + i, 1); tb->width[i] = x; + x += runestringnwidth(tb->font, tb->str + i, 1); } + tb->width[i] = x; } void @@ -95,7 +94,7 @@ initdata(void){ calcwidth(&tb1); tb2.ink = plt[5]; - tb2.font = font; + tb2.font = nfont; tb2.str = text2; tb2.len = nelem(text2); calcwidth(&tb2); @@ -110,10 +109,13 @@ redraw(void){ cur = screen->r.min; sp = 0; while(sp < tb1.len){ - for(n = 0; sp + n + 1 < tb1.len; n++){ - if(tb1.width[sp + n + 1] - tb1.width[sp] > Dx(screen->r)) break; + for(n = 0; sp + n <= tb1.len; n++){ + if(tb1.width[sp + n] - tb1.width[sp] > Dx(screen->r)) break; } if(n == 0) break; + + if (n > 1) n--; + runestringn(screen, cur, tb1.ink, ZP, tb1.font, tb1.str + sp, n); sp += n; cur.y += tb1.font->height; @@ -121,10 +123,13 @@ redraw(void){ sp = 0; while(sp < tb2.len){ - for(n = 0; sp + n + 1 < tb2.len; n++){ - if(tb2.width[sp + n + 1] - tb2.width[sp] > Dx(screen->r)) break; + for(n = 0; sp + n <= tb2.len; n++){ + if(tb2.width[sp + n] - tb2.width[sp] > Dx(screen->r)) break; } if(n == 0) break; + + if (n > 1) n--; + runestringn(screen, cur, tb2.ink, ZP, tb2.font, tb2.str + sp, n); sp += n; cur.y += tb2.font->height; @@ -254,27 +259,3 @@ Rectangle recttopt(Rectangle r, Point pt){ return Rpt(pt, addpt(pt, Pt(Dx(r), Dy(r)))); } - -int -runestringfit(Font *f, Rune *r, int n, int w){ - int x, i; - for(x = 0, i = 0; i <= n; i++){ - x += runestringnwidth(f, r + i, 1); - if(x > w) break; - } - return i; -} - -/* TODO: should check for unicode specifics - -int -stringfit(Font *f, char *s, int n, int w){ - int x, i; - for(x = 0, i = 0; i < n; i++){ - if(s[i] == '\0') break; - x += stringnwidth(f, s + i, 1); - if(x > w) break; - } - return i; -} -*/