?? bitfont.c
字號:
/* 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 + -