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 */
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);

View file

@ -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)

View file

@ -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);

View file

@ -4,7 +4,7 @@
#include <memdraw.h>
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;

View file

@ -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;