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

📄 convfnt.c

📁 将字体文件转成microwindows可用的内建字体的.c档
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 1999 Greg Haerr <greg@censoft.com> * * Modified by Tom Walton at Altia, Jan. 2002. to: * 1.  Handle fonts with widths up to 80 pixels. * 2.  Support passing command line arguments for the *     font name, pixel height, average pixel width (optional), *     bold (optional), and italic (optional).  If the font *     name has spaces, enclose it in double-quotes ("myfont"). * 3.  Use the average width in the output file name *     instead of the maximum width.  And, the max width is *     computed dynamically as characters are converted.  This *     max width is the value assigned to the data structure's *     maxwidth element. * 4.  The window created for converting fonts remains open and *     displays information about what is being converted, *     what the output file name is, and when the conversion *     is done.  The window is closed like any regular Windows *     application after it reports that the conversion is done. * * MS Windows Font Grabber for Micro-Windows * * Usage: convfnt32 [1|2|3|4] *        convfnt32 "fontname" [pixel_height [pixel_width] [bold] [italic]] * Example:  convfnt32 "my font" 25 12 * * Note: a Microsoft License is required to use MS Fonts */#define FONT_NORMAL 0#define FONT_BOLD 1#define FONT_ITALIC 2#define FONT_BOLDITALIC (FONT_BOLD | FONT_ITALIC)static char *Font_Name = "MS Sans Serif";static int Font_Height = 20;static int Font_Width = 0;static int Font_Style = FONT_NORMAL;static char *Font_Style_String = "normal";#define WIN32_LEAN_AND_MEAN#include <windows.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX_BITS_HEIGHT	48	/* max character height*/#define MAX_BITS_WIDTH 	80	/* max character width*/typedef unsigned short	IMAGEBITS;	/* bitmap image unit size*//* IMAGEBITS macros*/#define	IMAGE_SIZE(width, height)  ((height) * (((width) + sizeof(IMAGEBITS) * 8 - 1) / (sizeof(IMAGEBITS) * 8)))#define IMAGE_WORDS(x)		(((x)+15)/16)#define	IMAGE_BITSPERIMAGE	(sizeof(IMAGEBITS) * 8)#define	IMAGE_FIRSTBIT		((IMAGEBITS) 0x8000)#define	IMAGE_NEXTBIT(m)	((IMAGEBITS) ((m) >> 1))#define	IMAGE_TESTBIT(m)	((m) & IMAGE_FIRSTBIT)	  /* use with shiftbit*/#define	IMAGE_SHIFTBIT(m)	((IMAGEBITS) ((m) << 1))  /* for testbit*//* global data*/HINSTANCE	ghInstance;char 		APPWINCLASS[] = "convfnt";int 		MAX_WIDTH = 0;int 		AVE_WIDTH;int 		CHAR_HEIGHT;int		CHAR_ASCENT;char 		fontname[64];FILE *		fp;HFONT		hfont;int 		FIRST_CHAR = ' ';int 		LAST_CHAR = 256;int 		curoff = 0;int 		offsets[256];int 		widths[256];int			haveArgs = 0;/* forward decls*/LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wp,LPARAM lp);HWND InitApp(void);int  InitClasses(void);void doit(HDC hdc);void convfnt(HDC hdc);void print_char(int ch,IMAGEBITS *b, int w, int h);void print_bits(IMAGEBITS *bits, int width, int height);HFONT WINAPI GetFont(HDC hDC, LPSTR name, int height, int width, int style);HFONT WINAPI GetFontEx(HDC hDC, LPSTR name, int height, int width, int style,		int charset);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,	int nShowCmd){	MSG     msg;	HDC     hdc;	int     i;	char    *argv[10];	int     argc;	char    cmdLine[1024];	char    *cmdLinePtr;	ghInstance = hInstance;	InitClasses();	InitApp();	strncpy(cmdLine, lpCmdLine, 1024);	cmdLine[1023] = '\0';	i = atoi(cmdLine);	hdc = GetDC(NULL);	switch(i) {	case 0:		if(*cmdLine == 0)		{			haveArgs = 0;			strcpy(cmdLine, "\"MS Sans Serif\"");		}		else			haveArgs = 1;		argc = 0;		cmdLinePtr = cmdLine;		do		{			while (*cmdLinePtr != '\0'			       && (*cmdLinePtr == ' ' || *cmdLinePtr == '\t'))				cmdLinePtr++;			if (*cmdLinePtr != '\0')			{				if(*cmdLinePtr == '"' || *cmdLinePtr == '\'')				{					cmdLinePtr++;					argv[argc] = cmdLinePtr;					argc++;					while (*cmdLinePtr != '\0' && *cmdLinePtr != '"'					       && *cmdLinePtr != '\t')						cmdLinePtr++;					if (*cmdLinePtr == '\0')						break;					else						*cmdLinePtr++ = '\0';				}				else				{					argv[argc] = cmdLinePtr;					argc++;					while (*cmdLinePtr != '\0' && *cmdLinePtr != ' '					       && *cmdLinePtr != '\t')						cmdLinePtr++;					if (*cmdLinePtr == '\0')						break;					else						*cmdLinePtr++ = '\0';				}			}		} while (argc < 10 && *cmdLinePtr != '\0');		if (argc == 0)			haveArgs = 0;		if (argc >= 1)			Font_Name = argv[0];		if (argc >= 2)			Font_Height = atoi(argv[1]);		if (argc >= 3 && *(argv[2]) >= '0' && *(argv[2]) <= '9')			Font_Width = atoi(argv[2]);		if (Font_Width < 0)			Font_Width = 0;		for (i = 2; i < argc; i++)		{			if (stricmp(argv[i], "italic") == 0)				Font_Style |= FONT_ITALIC;			else if (stricmp(argv[i], "bold") == 0)				Font_Style |= FONT_BOLD;		}		switch(Font_Style)		{			case FONT_BOLD:				Font_Style_String = "bold";				break;			case FONT_ITALIC:				Font_Style_String = "italic";				break;			case FONT_BOLD | FONT_ITALIC:				Font_Style_String = "bold italic";				break;		}		hfont = GetFont(hdc, Font_Name, -Font_Height,		                Font_Width, Font_Style);		break;	case 1:		hfont = GetStockObject(DEFAULT_GUI_FONT);	/* winMSSansSerif11x13 */		break;	case 2:		hfont = GetStockObject(SYSTEM_FONT);		/* winSystem14x16 */		break;	case 3:		hfont = GetStockObject(OEM_FIXED_FONT);	/* winTerminal8x12 */		break;	case 4:		hfont = GetStockObject(ANSI_VAR_FONT);	/* winMSSansSerif11x13 */		break;	}	ReleaseDC(NULL, hdc);	while(GetMessage(&msg, NULL, 0, 0)) {		TranslateMessage(&msg);		DispatchMessage(&msg);	}	return 0;}intInitClasses(void){	WNDCLASS	wc;	wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;	wc.lpfnWndProc = (WNDPROC)WndProc;	wc.cbClsExtra = 0;	wc.cbWndExtra = 0;	wc.hInstance = ghInstance;	wc.hIcon = LoadIcon(ghInstance, MAKEINTRESOURCE( 1));	wc.hCursor = LoadCursor(NULL, IDC_ARROW);	wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);	wc.lpszMenuName = NULL;	wc.lpszClassName =  APPWINCLASS;	return RegisterClass( &wc);}HWNDInitApp(void){	HWND	hwnd;	hwnd = CreateWindowEx( 0L, APPWINCLASS,		"Font Grabber",		WS_OVERLAPPEDWINDOW,		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,		NULL,		NULL,		ghInstance,		NULL);	if( hwnd == NULL)		return( 0);	ShowWindow( hwnd, SW_SHOW);	return hwnd;}LRESULT CALLBACKWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp){	PAINTSTRUCT		ps;	HDC				hdc;	LOGFONT			lf;	TEXTMETRIC		tm;	char			outfile[64];	char 			*p, *q;	switch( msg) {	case WM_CREATE:		break;	case WM_DESTROY:		PostQuitMessage(0);		break;	case WM_PAINT:		hdc = BeginPaint(hwnd, &ps);		SelectObject(hdc, hfont);		GetObject(hfont, sizeof(lf), &lf);		GetTextMetrics(hdc, &tm);		MAX_WIDTH = 0; /* was tm.tmMaxCharWidth, now we compute it */		AVE_WIDTH = tm.tmAveCharWidth;		CHAR_HEIGHT = tm.tmHeight;		CHAR_ASCENT = tm.tmAscent;		FIRST_CHAR = tm.tmFirstChar;		LAST_CHAR = tm.tmLastChar + 1;		strcpy(fontname, lf.lfFaceName);		q = p = fontname;		/**/		while(*p) {			if((*p != ' ')&&(*p != '.'))				*q++ = *p;			++p;		}		*q = 0;		/*		while(*p) {			if(*p != ' ')				*q++ = *p;			++p;		}		*q = 0;		*/		if (haveArgs)		{

⌨️ 快捷键说明

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