~aleteoryx/9c

4a9ae0e567a0a6af406b6705c6592803ce84da51 — glenda 12 days ago c3d9923
first attempt, broken
1 files changed, 85 insertions(+), 12 deletions(-)

M ufx2font.c
M ufx2font.c => ufx2font.c +85 -12
@@ 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);
}