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.
This commit is contained in:
Jacob Moody 2025-01-03 00:51:43 +00:00
parent a101561223
commit 9e0913fa71
5 changed files with 8 additions and 4 deletions

View file

@ -80,6 +80,7 @@ struct Memsubfont
short n; /* number of chars in font */ short n; /* number of chars in font */
uchar height; /* height of bitmap */ uchar height; /* height of bitmap */
char ascent; /* top of bitmap to baseline */ char ascent; /* top of bitmap to baseline */
Rune min; /* rune offset for first glyph in subfont */
Fontchar *info; /* n+1 character descriptors */ Fontchar *info; /* n+1 character descriptors */
Memimage *bits; /* of font */ Memimage *bits; /* of font */
}; };
@ -156,7 +157,7 @@ extern int memimageinit(void);
* Subfont management * Subfont management
*/ */
extern Memsubfont* allocmemsubfont(char*, int, int, int, Fontchar*, Memimage*); extern Memsubfont* allocmemsubfont(char*, int, int, int, Fontchar*, Memimage*);
extern Memsubfont* openmemsubfont(char*); extern Memsubfont* openmemsubfont(char*, Rune);
extern void freememsubfont(Memsubfont*); extern void freememsubfont(Memsubfont*);
extern Point memsubfontwidth(Memsubfont*, char*); extern Point memsubfontwidth(Memsubfont*, char*);
extern Memsubfont* getmemdefont(void); extern Memsubfont* getmemdefont(void);

View file

@ -150,7 +150,7 @@ int memlineendsize(int end)
.nf .nf
Memsubfont* allocmemsubfont(char *name, int n, int height, Memsubfont* allocmemsubfont(char *name, int n, int height,
int ascent, Fontchar *info, Memimage *i) int ascent, Fontchar *info, Memimage *i)
Memsubfont* openmemsubfont(char *name) Memsubfont* openmemsubfont(char *name, Rune min)
void freememsubfont(Memsubfont *f) void freememsubfont(Memsubfont *f)
Point memsubfontwidth(Memsubfont *f, char *s) Point memsubfontwidth(Memsubfont *f, char *s)
Memsubfont* getmemdefont(void) Memsubfont* getmemdefont(void)

View file

@ -58,7 +58,7 @@ ginit(void)
#ifdef PLAN9PORT #ifdef PLAN9PORT
smallfont = openmemsubfont(unsharp("#9/font/lucsans/lstr.10")); smallfont = openmemsubfont(unsharp("#9/font/lucsans/lstr.10"));
#else #else
smallfont = openmemsubfont("/lib/font/bit/lucidasans/lstr.10"); smallfont = openmemsubfont("/lib/font/bit/lucidasans/lstr.10", 0);
#endif #endif
black = memblack; black = memblack;
blue = allocrepl(DBlue); blue = allocrepl(DBlue);

View file

@ -4,7 +4,7 @@
#include <memdraw.h> #include <memdraw.h>
Memsubfont* Memsubfont*
openmemsubfont(char *name) openmemsubfont(char *name, Rune min)
{ {
Memsubfont *sf; Memsubfont *sf;
Memimage *i; Memimage *i;
@ -45,6 +45,7 @@ openmemsubfont(char *name)
free(fc); free(fc);
goto Err; goto Err;
} }
sf->min = min;
close(fd); close(fd);
free(p); free(p);
return sf; return sf;

View file

@ -25,6 +25,7 @@ memimagestring(Memimage *b, Point p, Memimage *color, Point cp, Memsubfont *f, c
} }
s += w; s += w;
} }
c -= f->min;
if(c >= f->n) if(c >= f->n)
continue; continue;
i = f->info+c; i = f->info+c;
@ -58,6 +59,7 @@ memsubfontwidth(Memsubfont *f, char *cs)
} }
s += w; s += w;
} }
c -= f->min;
if(c >= f->n) if(c >= f->n)
continue; continue;
i = f->info+c; i = f->info+c;