File:  [RetroPC.NET] / mkfont32 / mkfntx1.c
Revision 1.1: download - view: text, annotated - select for diffs
Mon Jun 7 15:05:33 2004 JST (21 years, 4 months ago) by yui
Branches: MAIN
CVS tags: HEAD
fix x1 fonts (T.Yui)

#include	"compiler.h"
#include	"parts.h"
#include	"dosio.h"
#include	"fontmng.h"
#include	"mkfnt.h"
#include	"fntdat.h"

static const char fnt0808x1[] = "FNT0808.X1";
static const char fnt0816x1[] = "FNT0816.X1";
static const char fnt1616x1[] = "FNT1616.X1";

static void setank(BYTE *ptr, void *fnt, UINT from, UINT to) {

	char	work[2];
	FNTDAT	dat;
const BYTE	*p;
	BYTE	*q;
	int		width;
	int		height;
	BYTE	bit;
	int		i;

	ptr += (from * 16);
	work[1] = '\0';
	while(from < to) {
		work[0] = (char)from;
		dat = fontmng_get(fnt, work);
		if (dat) {
			width = min(dat->width, 8);
			height = min(dat->height, 16);
			p = (BYTE *)(dat + 1);
			q = ptr;
			while(height > 0) {
				height--;
				bit = 0;
				for (i=0; i<width; i++) {
					if (p[i]) {
						bit |= (0x80 >> i);
					}
				}
				*q++ = bit;
				p += dat->width;
			}
		}
		from++;
		ptr += 16;
	}
}

static void patchank(BYTE *ptr, const BYTE *fnt, UINT from, UINT count) {

	ptr += (from * 16);
	CopyMemory(ptr, fnt, count * 16);
}

static void setjis(BYTE *ptr, void *fnt) {

	char	work[4];
	UINT16	h;
	UINT16	l;
	UINT16	jis;
	UINT16	sjis;
	BYTE	*q;
	FNTDAT	dat;
const BYTE	*p;
	int		width;
	int		height;
	UINT16	bit;
	int		i;

	work[2] = '\0';
	for (h=0x2100; h<0x7400; h+=0x100) {
		for (l=0x21; l<0x7f; l++) {
			jis = h + l;
			if (isjis78(jis)) {
				sjis = jis2sjis(jis);
				q = NULL;
				if (sjis >= 0x8140 && sjis < 0x84c0) {
					q = ptr + 0x00000 + ((UINT32)(sjis - 0x8140) << 5);
				}
				else if (sjis >= 0x8890 && sjis < 0xa000) {
					q = ptr + 0x07000 + ((UINT32)(sjis - 0x8890) << 5);
				}
				else if (sjis >= 0xe040 && sjis < 0xeab0) {
					q = ptr + 0x35e00 + ((UINT32)(sjis - 0xe040) << 5);
				}
				if (q) {
					sjis = jis2sjis(jiscnv7890(jis));
					work[0] = (BYTE)(sjis >> 8);
					work[1] = (BYTE)sjis;
					dat = fontmng_get(fnt, work);
					if (dat) {
						width = min(dat->width, 16);
						height = min(dat->height, 16);
						p = (BYTE *)(dat + 1);
						while(height > 0) {
							height--;
							bit = 0;
							for (i=0; i<width; i++) {
								if (p[i]) {
									bit |= (0x8000 >> i);
								}
							}
							q[0] = (BYTE)(bit >> 8);
							q[1] = (BYTE)bit;
							p += dat->width;
							q += 2;
						}
					}
				}
			}
		}
	}
}

void makex1font(const char *dirname, const TCHAR *fontface) {

	void	*fnt;
	BYTE	*ptr;
	char	path[MAX_PATH];
	FILEH	fh;
	BOOL	r;

	fnt = fontmng_create(16, 0, fontface);
	if (fnt == NULL) {
		goto mfnt_err1;
	}
	ptr = (BYTE *)_MALLOC(306176, fnt1616x1);
	if (ptr == NULL) {
		goto mfnt_err2;
	}

	ZeroMemory(ptr, 0x800);
	CopyMemory(ptr + 0x20*8, cmn_8 + 0x00*8, 0x60*8);
	CopyMemory(ptr + 0xa0*8, cmn_8 + 0x60*8, 0x40*8);
	CopyMemory(ptr + 0x00*8, x1_8 + 0x00*8, 0x20*8);
	CopyMemory(ptr + 0x80*8, x1_8 + 0x20*8, 0x20*8);
	CopyMemory(ptr + 0xe0*8, x1_8 + 0x40*8, 0x20*8);
	CopyMemory(ptr + 0x7f*8, pi_8, 8);
	file_cpyname(path, dirname, sizeof(path));
	file_setseparator(path, sizeof(path));
	file_catname(path, fnt0808x1, sizeof(path));
	fh = file_create(path);
	if (fh != FILEH_INVALID) {
		r = (file_write(fh, ptr, 0x800) == 0x800);
		file_close(fh);
		if (!r) {
			file_delete(path);
		}
	}

	ZeroMemory(ptr, 0x1000);
	setank(ptr, fnt, 0x20, 0x7f);
	setank(ptr, fnt, 0xa1, 0xe0);
	patchank(ptr, x1_16 + 0*32*16, 0x00, 0x20);
	patchank(ptr, x1_16 + 1*32*16, 0x80, 0x20);
	patchank(ptr, x1_16 + 2*32*16, 0xe0, 0x20);
	patchank(ptr, pi_16, 0x7f, 1);
	file_cpyname(path, dirname, sizeof(path));
	file_setseparator(path, sizeof(path));
	file_catname(path, fnt0816x1, sizeof(path));
	fh = file_create(path);
	if (fh != FILEH_INVALID) {
		r = (file_write(fh, ptr, 0x1000) == 0x1000);
		file_close(fh);
		if (!r) {
			file_delete(path);
		}
	}

	ZeroMemory(ptr, 306176);
	setjis(ptr, fnt);
	file_cpyname(path, dirname, sizeof(path));
	file_setseparator(path, sizeof(path));
	file_catname(path, fnt1616x1, sizeof(path));
	fh = file_create(path);
	if (fh != FILEH_INVALID) {
		r = (file_write(fh, ptr, 306176) == 306176);
		file_close(fh);
		if (!r) {
			file_delete(path);
		}
	}
	_MFREE(ptr);

mfnt_err2:
	fontmng_destroy(fnt);

mfnt_err1:
	return;
}


RetroPC.NET-CVS <cvs@retropc.net>