From ebf35e0014706a6db7c8c8870fdef978f7231c72 Mon Sep 17 00:00:00 2001 From: glenda Date: Sun, 23 Nov 2025 05:40:57 +0000 Subject: [PATCH] =?UTF-8?q?glyph=20=E2=86=92=20image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ufx2font.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/ufx2font.c b/ufx2font.c index 9903fadebeb353a0ebbcb5550f29798deb6af53d..ca48a87f190d9071c1cecd9998123cba3ce8d561 100644 --- a/ufx2font.c +++ b/ufx2font.c @@ -44,6 +44,12 @@ struct GlyphInfo{ }; +struct RawImage{ + char chan[12], minx[12], miny[12], maxx[12], maxy[12]; + uchar data[]; +}; + + uint fwidth, nglyphs, glyphlen, glyphedge, baseline; uchar setconv, donaive, doholes; @@ -52,6 +58,7 @@ struct MapFile *mapfiles, *lastmf; uchar wasmferr, wasreaderr; struct GlyphInfo *glyphs; +struct RawImage *glyphbuf; void @@ -371,6 +378,28 @@ loadwidths(Biobuf *b, char *file) } } +void +allocrawimage(void) +{ + char buf[13]; + uint imglen; + + /* cols * rows */ + imglen = glyphedge * nglyphs*fwidth; + glyphbuf = malloc(sizeof(struct RawImage) + imglen); + + memcpy(glyphbuf->chan, " k1 ", 12); + memcpy(glyphbuf->minx, " 0 ", 12); + memcpy(glyphbuf->miny, " 0 ", 12); + + snprint(buf, 12, "%11d ", nglyphs*fwidth*8); + memcpy(glyphbuf->maxx, buf, 11); + snprint(buf, 12, "%11d ", glyphedge); + memcpy(glyphbuf->maxy, buf, 11); + + memset(glyphbuf->data, 0, imglen); +} + uchar testscanline(uchar *bitmap, int rowlen) { @@ -402,6 +431,19 @@ parseglyph(uchar *bitmap, struct GlyphInfo *ginfo, uint *botfreqs) ginfo->top = top; ginfo->bottom = bot; } void +storeglyph(uint i, uchar *bitmap) +{ + uint y, x; + ulong dstidx, srcidx; + for(x = 0; x < fwidth; x++){ + for(y = 0; y < glyphedge; y++){ + dstidx = (i*fwidth)+x+(y*fwidth*nglyphs); + srcidx = y+(x*glyphedge); + glyphbuf->data[dstidx] = bitmap[srcidx]; + } + } +} +void readglyphs(Biobuf *b, uint *botfreqs) { uint i; @@ -417,6 +459,7 @@ readglyphs(Biobuf *b, uint *botfreqs) if(n != glyphlen) sysfatal("unexpected eof"); parseglyph(bitmap, glyphs+i, botfreqs); + storeglyph(i, bitmap); } free(bitmap); @@ -449,7 +492,9 @@ loadufx(char *infile) glyphs = malloc(nglyphs * sizeof(struct GlyphInfo)); b = Bopen(infile, OREAD); - + + allocrawimage(); + loadwidths(b, infile); loadglyphs(b); @@ -519,4 +564,8 @@ main(int argc, char **argv) sysfatal("-b: baseline must be in range 1-width*8"); loadufx(infile); + + int fd = create(outdir, OWRITE, 0644); + write(fd, glyphbuf, sizeof(struct RawImage) + (glyphedge*nglyphs*fwidth)); + close(fd); }