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

📄 bitfont.c

📁 中日韩点阵字库 Chinese Japanese Korea
💻 C
📖 第 1 页 / 共 2 页
字号:
/* BitFont
 * Written by Larry Li[Wuhan], 2003.1.21
 * 点阵字库查看程序 -- 李峰制作
 */

#include <windows.h>
#include <windowsx.h>
#include "BitFont.h"

/* 这个程序老早就完成,大概在两个星期前。
 * 给 sunwen 一份拷贝,他一看就叫到:怎么没有注释?
 * 这是我背得滚瓜乱熟的东西,所以就什么都没有了。
 */

/* 程序实现很简单,显示一个点阵字库的内容。
 * 支持的点阵字库应该是位显示的,就是一个位(Bit)对应一个点。
 * 那么,一个字节(Byte)就是八个点,如果点阵大小不是 8 的倍数,
 * 也应该使用一个字节的大小。用行话说就是按字节对齐。
 * 支持的字体格式是不受限制的,只要连续存放一个个字的点阵就够了。
 */

/* 关于汉字点阵的一点说明
	ASC16    4096   1[8] x 16 x 256
	CHS16  261696  2[16] x 16 x 8178
	HZK16  267616  2[16] x 16 x 8363
	HZK16F 267776  2[16] x 16 x 8368

GB2312
(h1, h2) [A1, F8], [A1, FE]
 1 区: 94 个符号
 2 区: 72 个数字
 3 区: 94 个满宽度 GB 1988-89 字符(ASCII)
 4 区: 83 个日文平假名
 5 区: 86 个日文片假名
 6 区: 48 个大写和小写希腊字母
 7 区: 66 个大写和小写斯拉夫(俄语)字母
 8 区: 26 个拼音和 37 个注音字符
 9 区: 76 个制表符(4 - 79)
 10 - 15 区: 空区(UCDOS 使用)
 16 - 55 区: 3755 个汉字(一级汉字;最后一个是 55:89)
 56 - 87 区: 3008 个汉字(二级汉字;最后一个是 87:94)
 87 x 94 = 8178

GBK
(h1, h2) [81, FE], [40, FE]
 GBK 在 GB2312 上进行进行扩充,所以 GBK 包含 GB2312 的所有内容。
 81 - FE : 40 - FE
 32 + 87 + 7 = 126
 96 + 94 = 190
 126 * 190 = 23940
 23940 * 32 = 766080
*/

/* 默认的字库文件信息配置文件
 * 本程序所支持的点阵字库的相关信息都保存在这个文件里
 */
TCHAR szFonIni[] = TEXT("\\FON.INI");

/* 点阵位图 */
unsigned char *BitFont;

/* 字库信息 */
TCHAR szFonName[MAX_PATH];	/* 字库名称 */
TCHAR szFileName[MAX_PATH];
TCHAR szName[MAX_PATH];
TCHAR szComment[MAX_PATH];
int CharSet;
int Bit;					/* 位显示参数;1 表示当前位是 1 时显示点,0 表示当前位是 0 时显示点 */
int Print;					/* 是否是打印字库,打印字库根据打印机的特性是横向排列的;1 是,0 是显示字库 */
int ByteWidth;				/* 横向占用字节数;13 占用 2 字节,32 占用 4 字节 */
int Height;					/* 高度 */
int LineNum;				/* 每行显示几个字 */
int PageNum;				/* 每页显示多少字 */
int Pages;					/* 总共有多少页 */
const int Byte = 8;			/* 一个字节的位数 */
const int Spacing = 4;		/* 字间距,因为可以使用 12 点阵字库,所以 4 是最小值 */
int Count;					/* 总共计数 */
int cWidth;					/* 调整间距后的宽度 */
int cHeight;				/* 调整间距后的高度 */

/*------------------------------------------------------------------------
 Procedure:     FreeFont ID:1
 Purpose:       释放字库位图使用的空间
 Input:         指向字库位图空间的指针
 Output:        没有返回值
 Errors:
------------------------------------------------------------------------*/
void FreeFont(unsigned char *font)
{
	if (font)
		free(font);
	font = NULL;
}

/*------------------------------------------------------------------------
 Procedure:     DrawFont2 ID:1
 Purpose:       显示一个指定的字
 Input:         HDC hdc: Win32 绘图句柄
                int x, y: 显示字的坐标
                unsigned char *fon: 使用的字库位图空间指针
                int num: 要显示的字的内部编号
 Output:        没有返回值
 Errors:
------------------------------------------------------------------------*/
void DrawFont2(HDC hdc, int x, int y, unsigned char *fon, int num)
{
	int i, j, k;
	unsigned char *p;

	/* 检查编号是否越界 */
	if (num < 0 && num > Count)
		return;
	/* 定位当前字的位图空间地址 */
	p = fon + num * ByteWidth * Height;
	/* 根据是否打印字库和位显示参数调整显示方式 */
	if (Print) {
		if (Bit) {
			for (i = 0; i < Height; i++)
				for (j = 0; j < ByteWidth; j++)
					for (k = 0; k < Byte; k++)
						if ((p[i * ByteWidth + j] >> (Byte - k - 1)) & 1)
							SetPixel(hdc, x + i, y + j * Byte + k, 0);
		} else {
			for (i = 0; i < Height; i++)
				for (j = 0; j < ByteWidth; j++)
					for (k = 0; k < Byte; k++)
						if (!((p[i * ByteWidth + j] >> (Byte - k - 1)) & 1))
							SetPixel(hdc, x + i, y + j * Byte + k, 0);
		}
	} else {
		if (Bit) {
			for (i = 0; i < Height; i++)
				for (j = 0; j < ByteWidth; j++)
					for (k = 0; k < Byte; k++)
						if ((p[i * ByteWidth + j] >> (Byte - k - 1)) & 1)
							SetPixel(hdc, x + j * Byte + k, y + i, 0);
		} else {
			for (i = 0; i < Height; i++)
				for (j = 0; j < ByteWidth; j++)
					for (k = 0; k < Byte; k++)
						if (!((p[i * ByteWidth + j] >> (Byte - k - 1)) & 1))
							SetPixel(hdc, x + j * Byte + k, y + i, 0);
		}
	}
}

/*------------------------------------------------------------------------
 Procedure:     DrawFont ID:1
 Purpose:       显示一页字
 Input:         HDC hdc: Win32 画图句柄
                unsigned char *fon: 使用的字库位图空间指针
                int page: 要显示的页号
 Output:        没有返回值
 Errors:
------------------------------------------------------------------------*/
void DrawFont(HDC hdc, unsigned char *fon, int page)
{
	int i, j, k;

	if (fon) {
		for (i = k = 0; k < PageNum; i++) {
			for (j = 0; j < LineNum && k < PageNum; j++, k++)
				DrawFont2(hdc, Spacing + j * cWidth, Spacing + i * cHeight, fon, page  * PageNum + k);
		}
	}

}

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

/*------------------------------------------------------------------------
 Procedure:     WinMain ID:1
 Purpose:       主函数
 Input:         Win32 默认
 Output:        Win32 默认
 Errors:
------------------------------------------------------------------------*/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	HWND hwnd;
	MSG msg;
	WNDCLASS wc;
	TCHAR *chg;
	TCHAR szAppName[] = TEXT("BitFont");

	/* 计算配置文件名称 */
	GetModuleFileName(hInstance, szFonName, sizeof(szFonName));
	chg = szFonName;
	while (*chg)
		chg++;
	while (*chg != TEXT('\\') && chg != szFonName)
		chg--;
	*chg = TEXT('\0');
	lstrcat(szFonName, szFonIni);

	ZeroMemory(&wc, sizeof(wc));
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = WndProc;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDOK));
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName = szAppName;
	wc.lpszClassName = szAppName;

	if (!RegisterClass(&wc)) {
		MessageBox(NULL, TEXT("This program requies Windows NT!"), szAppName, MB_ICONERROR);
		return 0;
	}

	hwnd = CreateWindow(szAppName, TEXT("点阵字库显示"),
						WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX
//						| WS_SIZEBOX | WS_MAXIMIZEBOX
						| WS_VSCROLL,
						CW_USEDEFAULT, 0,
						300, 100,
						NULL, NULL, hInstance, NULL);

	ShowWindow(hwnd, iCmdShow);
	UpdateWindow(hwnd);

	while (GetMessage(&msg, NULL, 0, 0)) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}

/*------------------------------------------------------------------------
 Procedure:     OpenBitFontFile ID:1
 Purpose:       打开一个点阵字库
 Input:         HWND hwnd: 程序窗口句柄
 Output:        TRUE: 成功
                FALSE: 失败
 Errors:
------------------------------------------------------------------------*/
BOOL OpenBitFontFile(HWND hwnd)
{
	OPENFILENAME ofn;
	TCHAR *chg, szName[MAX_PATH] = TEXT("\0");;
	TCHAR *szRead, szBuf[640] = TEXT("支持的点阵字体文件");

	/* 读取打开文件类型的列表 */
	szRead = szBuf + lstrlen(szBuf) + 1;
	if (!GetPrivateProfileSectionNames(szRead, sizeof(szBuf) - lstrlen(szBuf) - 2, szFonName)) {
		MessageBox(hwnd, TEXT("没有找到字库信息配置文件 FON.INI!"), NULL, MB_ICONSTOP);
		ExitProcess(-1);
	}
	chg = szRead;
	while (*chg != TEXT('\0') || *(chg + 1) != TEXT('\0')) {
		if (*chg == TEXT('\0'))
			*chg = TEXT(';');
		chg++;

⌨️ 快捷键说明

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