From 4a9ae0e567a0a6af406b6705c6592803ce84da51 Mon Sep 17 00:00:00 2001 From: glenda Date: Sat, 22 Nov 2025 21:53:00 +0000 Subject: [PATCH] first attempt, broken --- ufx2font.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 85 insertions(+), 12 deletions(-) diff --git a/ufx2font.c b/ufx2font.c index b92c2a3364e5ae20ac1fddcf641a49c48e9464d1..7f1ee919996e922a7bb2a6fa37c394a0379525c2 100644 --- a/ufx2font.c +++ b/ufx2font.c @@ -41,7 +41,7 @@ struct GlyphInfo{ }; -uint fwidth, nglyphs, glyphlen; +uint fwidth, nglyphs, glyphlen, glyphedge; uchar setconv, donaive, doholes; struct MapFile *mapfiles, *lastmf; @@ -296,26 +296,26 @@ sniffdims(char *file) if(fwidth < 1){ c = file[len-1]; - file[len-1] = '\0'; - if('1' <= c && c <= '8' && strcmp(file+len-4, ".uf") != 0){ + if('1' <= c && c <= '8' && strncmp(file+len-4, ".uf", 3) == 0){ fwidth = c - '0'; } } if(fwidth < 1) - sysfatal("can't determine glyph width"); + sysfatal("%s: can't determine glyph width", file); - glyphlen = ufxlen(fwidth); + glyphlen = ufxlen(fwidth); + glyphedge = fwidth * 8; d = dirstat(file); if(d == nil) sysfatal("%r"); - if(nglyphs > 0){ + if(nglyphs == 0){ if(d->length % (1+glyphlen) != 0) - sysfatal("can't determine file dimensions"); + sysfatal("%s: can't determine file dimensions", file); nglyphs = d->length / (1+glyphlen); }else if(nglyphs * (1+glyphlen) > d->length) - sysfatal("file too short"); + sysfatal("%s: file too short", file); } void loadufx(char *infile) @@ -336,17 +336,89 @@ loadufx(char *infile) ginfo[i].width = n; } - if(Bread(b, gbitmaps, len) == len) + if(Bread(b, gbitmaps, len) != len) sysfatal("%r"); Bterm(b); } void -parseglyphs(void) +testcol(uchar len, uint offset, uchar *top, uchar *bot) { - uint i; + uchar mask; - sysfatal("TODO"); + if(len > 8) + len = 8; + mask = 0xff<<(8-len); + + for(*top = 0; *top < glyphedge; (*top)++){ + print("gbitmaps[off+top]=%2ux; mask=%2ux\n", gbitmaps[offset + *top], mask); + if(gbitmaps[offset + *top] & mask != 0) + break; + } + + for(*bot = (glyphedge - 1); *bot >= *top; (*bot)--) + if(gbitmaps[offset + *bot] & mask != 0) + break; +} +/* +uchar +highbit(uchar b) +{ + uchar i = 0; + while(b != 0){ + i++; + b >>= 1; + } + + return 8 - i; // returns 8 if b == 0 +} +uchar +findleft(uint offset) +{ + uchar left = 0; +} +*/ +void +parseglyphs(char *file) +{ + uint i, offset; + int rowlen; + uchar top, bot; + + for(i = 0; i < nglyphs; i++){ + rowlen = ginfo[i].width; + if(rowlen == 0) + continue; + if(rowlen > glyphedge){ + fprint(2, "%s: %s: 0x%2x: bad width %dpx, truncating\n", argv0, file, i, rowlen); + rowlen = glyphedge; + } + + offset = glyphlen * i; + ginfo[i].top = glyphedge; + ginfo[i].bottom = 0; + + while(rowlen > 0){ + testcol(rowlen, offset, &top, &bot); + if(top < ginfo[i].top) + ginfo[i].top = top; + if(bot > ginfo[i].bottom) + ginfo[i].bottom = bot; + + // TODO: calculate .left, maybe? + + offset += glyphedge; + rowlen -= 8; + } + + if(ginfo[i].top == glyphedge){ + // blank glyph + ginfo[i].top = 0; + ginfo[i].bottom = glyphedge - 1; + } + + print("glyphs[%2x]: rowlen=%02d top=%02d bottom=%02d\n", i, ginfo[i].width, ginfo[i].top, ginfo[i].bottom); + } } @@ -413,4 +485,5 @@ main(int argc, char **argv) printmapfile(mf); loadufx(infile); + parseglyphs(infile); }