From 9e0913fa71697863f3e9ca155e3b1f67a69bdb7c Mon Sep 17 00:00:00 2001 From: Jacob Moody Date: Fri, 3 Jan 2025 00:51:43 +0000 Subject: [PATCH] libmemdraw: change openmemsubfont() to accept rune minimum as argument Subfonts for non ascii characters are offset by some minimum rune, typically specified within the parent font file. Because libmemdraw only deals in subfonts, if we want to have it draw non ascii runes we need some method of providing that base offset. This function is only used in one place, so update the function signature and fix the only caller. --- sys/include/memdraw.h | 3 ++- sys/man/2/memdraw | 2 +- sys/src/cmd/venti/srv/graph.c | 2 +- sys/src/libmemdraw/openmemsubfont.c | 3 ++- sys/src/libmemdraw/string.c | 2 ++ 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sys/include/memdraw.h b/sys/include/memdraw.h index f1bb41e3f..62cc8cae5 100644 --- a/sys/include/memdraw.h +++ b/sys/include/memdraw.h @@ -80,6 +80,7 @@ struct Memsubfont short n; /* number of chars in font */ uchar height; /* height of bitmap */ char ascent; /* top of bitmap to baseline */ + Rune min; /* rune offset for first glyph in subfont */ Fontchar *info; /* n+1 character descriptors */ Memimage *bits; /* of font */ }; @@ -156,7 +157,7 @@ extern int memimageinit(void); * Subfont management */ extern Memsubfont* allocmemsubfont(char*, int, int, int, Fontchar*, Memimage*); -extern Memsubfont* openmemsubfont(char*); +extern Memsubfont* openmemsubfont(char*, Rune); extern void freememsubfont(Memsubfont*); extern Point memsubfontwidth(Memsubfont*, char*); extern Memsubfont* getmemdefont(void); diff --git a/sys/man/2/memdraw b/sys/man/2/memdraw index 0500a561b..865dbdd09 100644 --- a/sys/man/2/memdraw +++ b/sys/man/2/memdraw @@ -150,7 +150,7 @@ int memlineendsize(int end) .nf Memsubfont* allocmemsubfont(char *name, int n, int height, int ascent, Fontchar *info, Memimage *i) -Memsubfont* openmemsubfont(char *name) +Memsubfont* openmemsubfont(char *name, Rune min) void freememsubfont(Memsubfont *f) Point memsubfontwidth(Memsubfont *f, char *s) Memsubfont* getmemdefont(void) diff --git a/sys/src/cmd/venti/srv/graph.c b/sys/src/cmd/venti/srv/graph.c index cbad1ada2..780c674da 100644 --- a/sys/src/cmd/venti/srv/graph.c +++ b/sys/src/cmd/venti/srv/graph.c @@ -58,7 +58,7 @@ ginit(void) #ifdef PLAN9PORT smallfont = openmemsubfont(unsharp("#9/font/lucsans/lstr.10")); #else - smallfont = openmemsubfont("/lib/font/bit/lucidasans/lstr.10"); + smallfont = openmemsubfont("/lib/font/bit/lucidasans/lstr.10", 0); #endif black = memblack; blue = allocrepl(DBlue); diff --git a/sys/src/libmemdraw/openmemsubfont.c b/sys/src/libmemdraw/openmemsubfont.c index 1a17cfde6..22a644c29 100644 --- a/sys/src/libmemdraw/openmemsubfont.c +++ b/sys/src/libmemdraw/openmemsubfont.c @@ -4,7 +4,7 @@ #include Memsubfont* -openmemsubfont(char *name) +openmemsubfont(char *name, Rune min) { Memsubfont *sf; Memimage *i; @@ -45,6 +45,7 @@ openmemsubfont(char *name) free(fc); goto Err; } + sf->min = min; close(fd); free(p); return sf; diff --git a/sys/src/libmemdraw/string.c b/sys/src/libmemdraw/string.c index c0a6dc2de..69b4b5ab5 100644 --- a/sys/src/libmemdraw/string.c +++ b/sys/src/libmemdraw/string.c @@ -25,6 +25,7 @@ memimagestring(Memimage *b, Point p, Memimage *color, Point cp, Memsubfont *f, c } s += w; } + c -= f->min; if(c >= f->n) continue; i = f->info+c; @@ -58,6 +59,7 @@ memsubfontwidth(Memsubfont *f, char *cs) } s += w; } + c -= f->min; if(c >= f->n) continue; i = f->info+c;