Fix mkfont for actual fixed-width fonts.

This commit is contained in:
Marisa the Magician 2022-09-22 17:48:26 +02:00
commit 212d870a09

View file

@ -444,14 +444,21 @@ int main( int argc, char **argv )
// third pass to compute the maximum cell size (for memory allocation) // third pass to compute the maximum cell size (for memory allocation)
if ( autosize ) if ( autosize )
{ {
h = pxsiz+1; // should be fine h = fnt->size->metrics.height>>6;
for ( uint32_t i=range[0]; i<=range[1]; i++ ) if ( FT_IS_FIXED_WIDTH(fnt) )
{
w = fnt->size->metrics.max_advance>>6;
autosize = 0; // don't readjust per-glyph
}
else for ( uint32_t i=range[0]; i<=range[1]; i++ )
{ {
FT_UInt glyph = FT_Get_Char_Index(fnt,i); FT_UInt glyph = FT_Get_Char_Index(fnt,i);
if ( !glyph || FT_Load_Glyph(fnt,glyph,LOADFLAGS) ) continue; if ( !glyph || FT_Load_Glyph(fnt,glyph,LOADFLAGS) ) continue;
FT_Render_Glyph(fnt->glyph,RENDERMODE); FT_Render_Glyph(fnt->glyph,RENDERMODE);
int adv = fnt->glyph->linearHoriAdvance>>16; int adv = fnt->glyph->linearHoriAdvance>>16;
if ( adv > w ) w = adv; int gw = fnt->glyph->bitmap.width+fnt->glyph->bitmap_left;
if ( gw > adv ) adv = gw;
if ( (adv+rightshift) > w ) w = adv+rightshift;
} }
fprintf(stderr,"info: max cell size is %dx%d.\n",w,h); fprintf(stderr,"info: max cell size is %dx%d.\n",w,h);
} }
@ -480,7 +487,7 @@ int main( int argc, char **argv )
{ {
// readjust cell width (but not height) for this character // readjust cell width (but not height) for this character
int adv = fnt->glyph->linearHoriAdvance>>16; int adv = fnt->glyph->linearHoriAdvance>>16;
w = adv; w = adv+rightshift;
iw = w+((gradient&4)?2:1); iw = w+((gradient&4)?2:1);
} }
int xx = rightshift; int xx = rightshift;