From c3d9923b13168be5b9f0cb1beec34fdc7c5cfe1e Mon Sep 17 00:00:00 2001 From: glenda Date: Sat, 22 Nov 2025 05:49:00 +0000 Subject: [PATCH] load ufx --- ufx2font.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/ufx2font.c b/ufx2font.c index f4e454ab9d4511eef5ad7ecd4f44b8bf2a66e8fb..b92c2a3364e5ae20ac1fddcf641a49c48e9464d1 100644 --- a/ufx2font.c +++ b/ufx2font.c @@ -4,7 +4,7 @@ /* entry has 1 byte in widtab + 8 bytes per tile */ -#define ufxlen(n) (1 + ((n)*(n)*8)) +#define ufxlen(n) ((n)*(n)*8) enum{ @@ -36,13 +36,21 @@ struct MapFile{ }; -uint fwidth, nglyphs; +struct GlyphInfo{ + uchar top, bottom, left, width; +}; + + +uint fwidth, nglyphs, glyphlen; uchar setconv, donaive, doholes; struct MapFile *mapfiles, *lastmf; uchar wasmferr, wasreaderr; +uchar *gbitmaps; +struct GlyphInfo *ginfo; + void bioerr(char *s) @@ -277,6 +285,71 @@ printmapfile(struct MapFile *mf) } +void +sniffdims(char *file) +{ + uint len; + Dir *d; + char c; + + len = strlen(file); + + if(fwidth < 1){ + c = file[len-1]; + file[len-1] = '\0'; + if('1' <= c && c <= '8' && strcmp(file+len-4, ".uf") != 0){ + fwidth = c - '0'; + } + } + if(fwidth < 1) + sysfatal("can't determine glyph width"); + + glyphlen = ufxlen(fwidth); + + d = dirstat(file); + if(d == nil) + sysfatal("%r"); + + if(nglyphs > 0){ + if(d->length % (1+glyphlen) != 0) + sysfatal("can't determine file dimensions"); + nglyphs = d->length / (1+glyphlen); + }else if(nglyphs * (1+glyphlen) > d->length) + sysfatal("file too short"); +} +void +loadufx(char *infile) +{ + Biobuf *b; + uint i, len; + int n; + + len = nglyphs * glyphlen; + gbitmaps = malloc(len); + ginfo = malloc(nglyphs * sizeof(struct GlyphInfo)); + b = Bopen(infile, OREAD); + + for(i = 0; i < nglyphs; i++){ + n = Bgetc(b); + if(n < 0) + sysfatal("%r"); + ginfo[i].width = n; + } + + if(Bread(b, gbitmaps, len) == len) + sysfatal("%r"); + + Bterm(b); +} +void +parseglyphs(void) +{ + uint i; + + sysfatal("TODO"); +} + + void usage(void) { @@ -296,6 +369,8 @@ main(int argc, char **argv) break; case 'x': fwidth = atoi(EARGF(usage())); + if(1 > fwidth || fwidth > 8) + sysfatal("-x: width must be in range 1-8"); break; case 'n': setconv = 1; @@ -324,9 +399,11 @@ main(int argc, char **argv) if(argc != 2) usage(); + infile = argv[0]; + outdir = argv[1]; - // TODO: calculate length etc etc + sniffdims(infile); for(mf = mapfiles; mf != nil; mf = mf->next) parsemapfile(mf); @@ -334,4 +411,6 @@ main(int argc, char **argv) exits("mapfile"); for(mf = mapfiles; mf != nil; mf = mf->next) printmapfile(mf); + + loadufx(infile); }