⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convfnt.c

📁 将字体文件转成microwindows可用的内建字体的.c档
💻 C
📖 第 1 页 / 共 2 页
字号:
			char sample[1024];			sprintf(sample, "Converting font \"%s\", Height %d, Width %d, Style \"%s\" ", Font_Name, Font_Height, Font_Width, Font_Style_String);			TextOut(hdc, 0, 150, sample, strlen(sample));			wsprintf(outfile, "win%s%dx%d.c", fontname,			         AVE_WIDTH, CHAR_HEIGHT);			sprintf(sample,			        "To file \"%s\" (%dx%d is Width x Height)",			        outfile, AVE_WIDTH, CHAR_HEIGHT);			TextOut(hdc, 0, 200, sample, strlen(sample));			fp = fopen(outfile, "wt");			doit(hdc);			fclose(fp);			TextOut(hdc, 0, 250, " DONE! ", 7);		}		else		{			char *usage = "Usage:  convfnt.exe  \"fontname\"  [ pixel_height  [pixel_width]  [bold]  [italic] ] ";			TextOut(hdc, 0, 0, usage, strlen(usage));			usage = "Example:  convfnt.exe  \"my font\"  25  12  bold  italic ";			TextOut(hdc, 0, 30, usage, strlen(usage));		}		EndPaint(hwnd, &ps);		break;	case WM_LBUTTONDOWN:		break;	default:		return DefWindowProc( hwnd, msg, wp, lp);	}	return( 0);}voidconvfnt(HDC hdc){	SIZE	size;   	unsigned char	ch;	int		i;	int		x, y, w;	int		word_width;	IMAGEBITS mask_value;	IMAGEBITS *image_ptr;	IMAGEBITS c;	IMAGEBITS	image[MAX_BITS_HEIGHT * IMAGE_WORDS(MAX_BITS_WIDTH)];	static IMAGEBITS mask[IMAGE_BITSPERIMAGE * IMAGE_WORDS(MAX_BITS_WIDTH)] = { 		0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,		0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001,		0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,		0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001,		0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,		0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001,		0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,		0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001,		0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,		0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001	};	for(i = FIRST_CHAR; i < LAST_CHAR; ++i)	{		ch = i;		TextOut(hdc, 0, 0, &ch, 1);		GetTextExtentPoint32(hdc, &ch, 1, &size);		if (size.cx > MAX_BITS_WIDTH)		{			offsets[ch] = curoff;			widths[ch] = 0;		}		else if (size.cx > MAX_WIDTH)			MAX_WIDTH = size.cx;		word_width = IMAGE_WORDS(size.cx);		for(y = 0; y < size.cy; ++y)		{			for (w = 0; w < word_width; w++)			{				image_ptr = &(image[(y * word_width) + w]);				*image_ptr = 0;				for(x=IMAGE_BITSPERIMAGE * w;				    x < (int)((IMAGE_BITSPERIMAGE * w) + 16) && x < size.cx;				    ++x)				{					c = GetPixel(hdc, x, y)? 0: 1;					mask_value = mask[x];					*image_ptr = (*image_ptr & ~mask_value)					             | (c << (15 - (x % 16)));				}			}		}		offsets[ch] = curoff;		widths[ch] = size.cx;		print_char(ch, image, size.cx, size.cy);		print_bits(image, size.cx, size.cy);		curoff += (size.cy * word_width);		fprintf(fp, "\n");	}}voiddoit(HDC hdc){	int		i;	fprintf(fp, "/* Generated by convfnt.exe*/\n");	fprintf(fp, "#include \"device.h\"\n\n");	fprintf(fp, "/* Windows %s %dx%d Font */\n",		fontname, AVE_WIDTH, CHAR_HEIGHT);	fprintf(fp, "/* Originated from: \"%s\", Height %d, Width %d, Style \"%s\" */\n\n",		Font_Name, Font_Height, Font_Width, Font_Style_String);	fprintf(fp, "static MWIMAGEBITS win%s%dx%d_bits[] = {\n\n",		fontname, AVE_WIDTH, CHAR_HEIGHT);	convfnt(hdc);	fprintf(fp, "};\n\n");	fprintf(fp, "/* Character->glyph data. */\n");	fprintf(fp, "static unsigned long win%s%dx%d_offset[] = {\n",		fontname, AVE_WIDTH, CHAR_HEIGHT);////*short---->long*/	for(i=FIRST_CHAR; i<LAST_CHAR; ++i)		fprintf(fp, "  %d,\t /* %c (0x%02x) */\n", offsets[i], i<' '? ' ':i , i);	fprintf(fp, "};\n\n");	fprintf(fp, "/* Character width data. */\n");	fprintf(fp, "static unsigned char win%s%dx%d_width[] = {\n",		fontname, AVE_WIDTH, CHAR_HEIGHT);	for(i=FIRST_CHAR; i<LAST_CHAR; ++i)		fprintf(fp, "  %d,\t /* %c (0x%02x) */\n", widths[i], i<' '? ' ':i , i);	fprintf(fp, "};\n\n");	fprintf(fp, "/* Exported structure definition. */\n"		"MWCFONT font_win%s%dx%d = {\n",		fontname, AVE_WIDTH, CHAR_HEIGHT);	fprintf(fp, "\t\"win%s%dx%d\",\n", fontname, AVE_WIDTH, CHAR_HEIGHT);	fprintf(fp, "\t%d,\n", MAX_WIDTH);	fprintf(fp, "\t%d,\n", CHAR_HEIGHT);	fprintf(fp, "\t%d,\n", CHAR_ASCENT);	fprintf(fp, "\t%d,\n\t%d,\n", FIRST_CHAR, LAST_CHAR-FIRST_CHAR);	fprintf(fp, "\twin%s%dx%d_bits,\n", fontname, AVE_WIDTH, CHAR_HEIGHT);	fprintf(fp, "\twin%s%dx%d_offset,\n", fontname, AVE_WIDTH, CHAR_HEIGHT);	fprintf(fp, "\twin%s%dx%d_width,\n", fontname, AVE_WIDTH, CHAR_HEIGHT);	fprintf(fp, "};\n");}/* Character ! (0x21):   ht=16, width=8   +----------------+   |                |   |                |   | *              |   | *              |   | *              |   | *              |   | *              |   | *              |   |                |   | *              |   |                |   |                |   +----------------+ */voidprint_char(int ch,IMAGEBITS *bits, int width, int height){	int 		x, word_width;	int 		bitcount;	/* number of bits left in bitmap word */	IMAGEBITS	bitvalue;	/* bitmap word value */	fprintf(fp, "/* Character %c (0x%02x):\n", (ch < ' '? ' ': ch), ch);	fprintf(fp, "   ht=%d, width=%d\n", height, width);	fprintf(fp, "   +");	for(x = 0; x < width; ++x)		fprintf(fp, "-");	fprintf(fp, "+\n");	x = 0;	bitcount = 0;	word_width = IMAGE_WORDS(width);	while (height > 0)	{	    if (bitcount <= 0)	    {		    fprintf(fp, "   |");		    bitcount = IMAGE_BITSPERIMAGE * word_width;		    bitvalue = *bits++;	    }	    if (IMAGE_TESTBIT(bitvalue))	    	fprintf(fp, "*");	    else	    	fprintf(fp, " ");	    bitvalue = IMAGE_SHIFTBIT(bitvalue);	    --bitcount;	    if (bitcount > 0 && (bitcount % IMAGE_BITSPERIMAGE) == 0)	    	bitvalue = *bits++;	    if (x++ == width-1)	    {	    	x = 0;	    	--height;	    	bitcount = 0;	    	fprintf(fp, "|\n");	    }	}	fprintf(fp, "   +");	for(x=0; x<width; ++x)		fprintf(fp, "-");	fprintf(fp, "+ */\n");}#define	IMAGE_GETBIT4(m)	(((m) & 0xf000) >> 12)#define	IMAGE_SHIFTBIT4(m)	((IMAGEBITS) ((m) << 4))voidprint_bits(IMAGEBITS *bits, int width, int height){	int 		x, word_width;	int 		bitcount;	/* number of bits left in bitmap word */	IMAGEBITS	bitvalue;	/* bitmap word value */	x = 0;	bitcount = 0;	word_width = IMAGE_WORDS(width);	while (height > 0)	{	    if (bitcount <= 0)	    {	    	fprintf(fp, "0x");	    	bitcount = IMAGE_BITSPERIMAGE * word_width;	    	bitvalue = *bits++;	    }	    fprintf(fp, "%x", IMAGE_GETBIT4(bitvalue));	    bitvalue = IMAGE_SHIFTBIT4(bitvalue);	    bitcount -= 4;	    if (bitcount > 0 && (bitcount % IMAGE_BITSPERIMAGE) == 0)	    {	    	fprintf(fp, ",0x");	    	bitvalue = *bits++;	    }		x += 4;	    if (x >= width)	    {	    	if(IMAGE_BITSPERIMAGE > (width % IMAGE_BITSPERIMAGE)	    	   && (width % IMAGE_BITSPERIMAGE) != 0)	    		for(x = IMAGE_BITSPERIMAGE - (width % IMAGE_BITSPERIMAGE);	    		    x > 3; x -= 4)	    	{	    		fprintf(fp, "0");	    	}	    	x = 0;	    	--height;	    	bitcount = 0;	    	fprintf(fp, ",\n");	    }	}}/* * WIN Draw Library * * GetFont style bits: *			01 bold *			02 italic * fontSize > 0		points (must pass hDC for non-screen font) * fontSize < 0		pixels (no HDC needed) */HFONT WINAPIGetFont(HDC hDC, LPSTR fontName,int fontSize,int fontWidth,int fontStyle){	return GetFontEx(hDC, fontName, fontSize, fontWidth,	                 fontStyle, ANSI_CHARSET);}HFONT WINAPIGetFontEx(HDC hDC, LPSTR fontName,int fontSize,int fontWidth,          int fontStyle,int charset){	LOGFONT	lf;	HDC		hdc;	memset( &lf, 0, sizeof(LOGFONT));	if( fontSize < 0 || hDC)		hdc = hDC;	else hdc = GetDC( GetDesktopWindow());	/* calculate font size from passed point size*/	if( fontSize < 0)		lf.lfHeight = -fontSize;	else lf.lfHeight = -MulDiv( fontSize,				GetDeviceCaps( hdc, LOGPIXELSY), 72);	if( fontName)		strncpy( lf.lfFaceName, fontName, LF_FACESIZE);	else lf.lfFaceName[ 0] = '\0';	lf.lfWeight = (fontStyle & 01)? FW_BOLD: FW_NORMAL;	if( fontStyle & 02)		lf.lfItalic = 1;	lf.lfCharSet = charset;	lf.lfWidth = fontWidth;	if( fontSize > 0 && !hDC)		ReleaseDC( GetDesktopWindow(), hdc);	return CreateFontIndirect( &lf);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -