📄 ucguifontgen.cpp
字号:
// UCGUIFontGen.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "UCGUIFontGen.h"
#include "resource.h"
#include "math.h"
#include "malloc.h"
#include <commdlg.h>
#include <commctrl.h>
//#define fontfile "hzk24h.c"
//#define fontname "Simsun"
#define fontbytes fontsize * byteline //一个点阵所占字节数...
#define Need_Note 1
int fontXDist = 12;
int fontsize = 12;
int byteline = 2; //字体一行的字节数...
char fontname[100];
char fontfile[100];
int OutputCharFlag[300]; //第一位都有于记载位于此位的字符是否输出...
#define FONTKING 15
OutputFontName fontNameStruct[FONTKING] = {
{"宋体", "SimSun"},
{"黑体", "SimHei"},
{"幼圆", "YouYuan"},
{"新宋体", "NewSimSun"},
{"隶书", "LiSu"},
{"楷体_GB2312", "KaiTi"},
{"华文中宋", "STZhongSong"},
{"华文行楷", "STXingKai"},
{"华文新魏", "STXinWei"},
{"华文细黑", "STXiHei"},
{"华文仿宋", "STFangSong"},
{"华文彩云", "STCaiYun"},
{"仿宋_GB2312", "FangSong_GB2312"},
{"方正姚体", "FZYaoTi"},
{"方正舒体", "FZShuTi"}
};
char hzkhead[] = "#include \"..\\core\\GUI.H\" \n\
#ifndef GUI_FLASH \n\
#define GUI_FLASH \n\
#endif \n\
extern GUI_FLASH const GUI_FONT GUI_FontHZ_%s;\n";
char hzktitleinfo[] = "/* %s - %s font for UCGUI font driver */ \n\
/********************************************************************************************************\n\
* UCGUI\n\
* http://www.ucgui.com\n\
*\n\
* (c) Copyright 2005-2006, UCGUI专业论坛, 学习交流UCGUI\n\
*\n\
* ucgui@16.com 2005.07.31\n\
* 作者: ucgui\n\
*********************************************************************************************************\n\
*/\n";
char hzkprefix[] = "GUI_FLASH const unsigned char acFontHZ%s_%02x%2x[%d] = { %s";
char hzkfontexplain[] = "/* %s */";
char hzkprefix_tmp[300];
char hzkprefix_long_tmp[1000];
char hzksuffix[] = "};\n";
char hzkcharinfo[] = "GUI_FLASH const GUI_CHARINFO GUI_FontHZ%s_CharInfo[%d] = {";
#ifdef Need_Note
char hzkcharinfo_2[] = "{ %d, %d, %d, (void GUI_FLASH *)&acFontHZ%s_%02x%2x},/* %s %d */";
#else
char hzkcharinfo_2[] = "{ %d, %d, %d, (void GUI_FLASH *)&acFontHZ%s_%02x%2x},";
#endif
char hzkpropinfo[] = "GUI_FLASH const GUI_FONT_PROP GUI_FontHZ%s_Prop%s= {\n\
0x%02x%02x,\n\
0x%02x%02x,\n\
&GUI_FontHZ%s_CharInfo[%d],\n\
(void *)&GUI_FontHZ%s_Prop%s \n\
};";
char hzkpropascinfo[] = "\nGUI_FLASH const GUI_FONT_PROP GUI_FontHZ%s_Prop%s= {\n\
0x%02x%02x,\n\
0x%02x%02x,\n\
&GUI_FontHZ%s_CharInfo[%d],\n\
(void *)&GUI_FontHZ%s_Prop%s \n\
};";
char hzkproplastinfo[] = "\nGUI_FLASH const GUI_FONT_PROP GUI_FontHZ%s_Prop%s= {\n\
0x%02x%02x,\n\
0x%02x%02x,\n\
&GUI_FontHZ%s_CharInfo[%d],\n\
(void *)%s \n\
};";
char hzkfontinfo[] = "GUI_FLASH const GUI_FONT GUI_FontHZ_%s = {\n\
GUI_FONTTYPE_PROP_SJIS, \n\
%d, \n\
%d, \n\
%d, \n\
%d, \n\
(void GUI_FLASH *)&GUI_FontHZ%s_Prop%s\n\
};";
LRESULT CALLBACK GenAllFontProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK ChooseFontProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
HWND g_hDlg = 0;
HINSTANCE g_hInst = 0;
HDC hDC = 0;
FILE* fp = 0;
int i = 0, j = 0;
BYTE area1 = 0, area2 = 0;
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
g_hInst = (HINSTANCE)hModule;
return TRUE;
}
void WirteHZKFile(char* buf, int len, FILE* fp)
{
fprintf(fp, "%s\n", (unsigned char* )buf);
fflush(fp);
}
///////////////////////////////////////////////////////////////////////
//
// 函数名 : GetAscCharIsOut
// 功能描述 : 获取指定Ascii字符是否输出...
// 参数 : BYTE ascCode
// 返回值 : bool
//
///////////////////////////////////////////////////////////////////////
bool GetAscCharIsOut(BYTE ascCode)
{
int IsOut = 0;
IsOut = OutputCharFlag[(ascCode-0x20)/32];
IsOut = (IsOut & (1 << (ascCode-0x20)%32)) >> ((ascCode-0x20)%32);
if(!IsOut) return 0;
return 1;
}
///////////////////////////////////////////////////////////////////////
//
// 函数名 : GetHZCharIsOut
// 功能描述 : 判断指定汉字字符是否输出...
// 参数 : BYTE area1
// 参数 : BYTE area2
// 返回值 : bool
//
///////////////////////////////////////////////////////////////////////
bool GetHZCharIsOut(BYTE area1, BYTE area2)
{
int IsOut = 0;
int BytePos = 0;
if(area1 < 0xa1 || area2 < 0xa1 ) return 0;
BytePos = (area1-0xa1)*94 + (area2 - 0xa1) + 0x60;
IsOut = OutputCharFlag[BytePos/32];
IsOut = (IsOut & (1 << BytePos%32)) >> (BytePos%32);
if(!IsOut) return 0;
return 1;
}
///////////////////////////////////////////////////////////////////////
//
// 函数名 : GetCharInfoPos
// 功能描述 : 获取指定字符在选定输出的字符中的序列号...
// 参数 : BYTE area1
// 参数 : BYTE area2
// 返回值 : int
//
///////////////////////////////////////////////////////////////////////
int GetCharInfoPos(BYTE area1, BYTE area2)
{
int i = 0;
int IsOut = 0;
int BytePos = 0;
int bppPos = 0;
if(area2 == 0){
if(area1 < 0x20 || area1 > 0x80 ) return 0;
BytePos = area1 - 0x20;
IsOut = OutputCharFlag[BytePos/32];
}
else if(area2 > 0xa0){
if(area1 < 0xa1 || area2 < 0xa1 ) return 0;
BytePos = (area1-0xa1)*94 + (area2 - 0xa1) + 0x60;
IsOut = OutputCharFlag[BytePos/32];
}
else return 0;
for(i = 0; i < BytePos/32; i++){
if(OutputCharFlag[i] == 0) continue;
if(OutputCharFlag[i] == 0xffffffff){
bppPos += 32;
continue;
}
for(int j = 0; j < 32; j++){
if((OutputCharFlag[i] >> j) & 1) bppPos++;
}
}
for(i = 0; i < BytePos%32; i++){
if((IsOut >> i) & 1) bppPos++;
}
return bppPos;
}
bool GenFontInfo(char* lastPropName)
{
if(lastPropName){
sprintf(hzkprefix_tmp, hzkfontinfo, fontname, fontsize, fontsize, 1, 1, fontname, lastPropName);
}
else
sprintf(hzkprefix_tmp, hzkfontinfo, fontname, fontsize, fontsize, 1, 1, fontname);
WirteHZKFile(hzkprefix_tmp, strlen(hzkprefix_tmp), fp);
return 1;
}
char* GenFontPropInfo()
{
char tmpbuf[100];
char* lastPropName = NULL;
int offset = 0, FileLen = 0;
// unsigned char onehz[10];
bool fisrtPropInfo = 0;/*, findFirst = 0;*/
BYTE firstCharacter = 0, lastCharacter = 0;
int charOffsetPos = 0, IsOut = 0;
OutPutCharProp* lpoutPrePropInfo = NULL, *lpoutCurPropInfo = NULL, *lpoutFirstPropInfo = NULL;
memset(hzkprefix_tmp, 0, 300);
int noOutputRange = GetCharInfoPos(0xb0, 0xa1) - GetCharInfoPos(0xa9, 0xff);
for(area1 = 0xf7; area1 > 0xa0; area1--){
if(area1 > 0xa9 && area1 < 0xb0) continue;
for(area2 = 0xfe; area2 > 0xa0; area2--){
IsOut = GetHZCharIsOut(area1, area2);
if(lastCharacter == 0 && IsOut){
lastCharacter = area2;
if(lastCharacter != 0xa1) continue; //分区边界时, 要注意...
}
if(lastCharacter == 0) continue;
if(IsOut && area2 != 0xa1 && lastCharacter != 0xa1) continue; //到达汉字分区时,必须切断...
if(area2 == 0xa1) firstCharacter = area2;
else firstCharacter = area2+1;
if(area1 >= 0xb0){
charOffsetPos = GetCharInfoPos(area1, firstCharacter) - noOutputRange;
}
else{
charOffsetPos = GetCharInfoPos(area1, firstCharacter);
}
sprintf(tmpbuf, "%02x%02x", area1, firstCharacter);
if(fisrtPropInfo == 0)
sprintf(hzkprefix_tmp, hzkproplastinfo, fontname, tmpbuf, area1, firstCharacter, area1, lastCharacter, fontname, charOffsetPos, "0");
else
sprintf(hzkprefix_tmp, hzkpropinfo, fontname, tmpbuf, area1, firstCharacter, area1, lastCharacter, fontname, charOffsetPos, fontname, "%s");
lpoutCurPropInfo = (OutPutCharProp*) malloc(sizeof(OutPutCharProp));
if(!lpoutCurPropInfo) continue;
lpoutCurPropInfo->firstCharacter[0] = area1;
lpoutCurPropInfo->firstCharacter[1] = firstCharacter;
lpoutCurPropInfo->firstCharacter[2] = 0;
lpoutCurPropInfo->lastCharacter[0] = area1;
lpoutCurPropInfo->lastCharacter[1] = lastCharacter;
lpoutCurPropInfo->lastCharacter[2] = 0;
strcpy(lpoutCurPropInfo->propName, tmpbuf);
lpoutCurPropInfo->lpPropChar = (char*) malloc(strlen(hzkprefix_tmp)*sizeof(char)+1);
memcpy(lpoutCurPropInfo->lpPropChar, hzkprefix_tmp, strlen(hzkprefix_tmp));
lpoutCurPropInfo->lpPropChar[strlen(hzkprefix_tmp)] = 0;
memset(hzkprefix_tmp, 0, strlen(hzkprefix_tmp));
lpoutCurPropInfo->lpNext = NULL;
if(lpoutPrePropInfo == NULL){
lpoutPrePropInfo = lpoutCurPropInfo;
lpoutFirstPropInfo = lpoutCurPropInfo; //记住链表头指针...
}
else{
lpoutPrePropInfo->lpNext = lpoutCurPropInfo;
}
lpoutPrePropInfo = lpoutCurPropInfo;
fisrtPropInfo = 1;
lastCharacter = 0; //注意这一点...
}
}
for(area1 = 0; area1 == 0; area1--){
for(area2 = 0x7f; area2 >= 0x20; area2--){
IsOut = GetAscCharIsOut(area2);
if(lastCharacter == 0 && IsOut){
lastCharacter = area2;
continue;
}
if(lastCharacter == 0) continue;
if(IsOut && area2 != 0x20) continue; //到达汉字分区时,必须切断...
if(area2 == 0x20) firstCharacter = area2;
else firstCharacter = area2+1;
charOffsetPos = GetCharInfoPos(area1, firstCharacter);
sprintf(tmpbuf, "%02x%02x", area1, firstCharacter);
sprintf(hzkprefix_tmp, hzkpropinfo, fontname, tmpbuf, area1, firstCharacter, area1, lastCharacter, fontname, charOffsetPos, fontname, "%s");
lpoutCurPropInfo = (OutPutCharProp*) malloc(sizeof(OutPutCharProp));
if(!lpoutCurPropInfo) continue;
lpoutCurPropInfo->firstCharacter[0] = firstCharacter;
lpoutCurPropInfo->firstCharacter[1] = 0;
lpoutCurPropInfo->lastCharacter[0] = lastCharacter;
lpoutCurPropInfo->lastCharacter[1] = 0;
strcpy(lpoutCurPropInfo->propName, tmpbuf);
//注意分配了符串时要多分配1字节, 用于存0表示字符串结束的. 不则strcpy时会占用后面一个字节
//从而破坏了用free此内存的数据结构, 每一分配的内存前后均有用于管理此块内存的数据, 否则free时会出错...
lpoutCurPropInfo->lpPropChar = (char*) malloc(strlen(hzkprefix_tmp)*sizeof(char)+1);
strcpy(lpoutCurPropInfo->lpPropChar, hzkprefix_tmp);
memset(hzkprefix_tmp, 0, strlen(hzkprefix_tmp));
lpoutCurPropInfo->lpNext = NULL;
if(lpoutPrePropInfo == NULL){
lpoutPrePropInfo = lpoutCurPropInfo;
lpoutFirstPropInfo = lpoutCurPropInfo; //记住链表头指针...
}
else{
lpoutPrePropInfo->lpNext = lpoutCurPropInfo;
}
lpoutPrePropInfo = lpoutCurPropInfo;
lastCharacter = 0; //注意这一点...
}
}
if(lpoutCurPropInfo){
lastPropName = (char*) malloc(sizeof(char)*strlen(lpoutCurPropInfo->propName)+1);
strcpy(lastPropName, lpoutCurPropInfo->propName);
}
if(lpoutFirstPropInfo){
if(lpoutFirstPropInfo->lpPropChar){
#ifdef Need_Note
sprintf(hzkprefix_tmp, "/*%s--%s*/", lpoutFirstPropInfo->firstCharacter, lpoutFirstPropInfo->lastCharacter);
WirteHZKFile(hzkprefix_tmp, strlen(hzkprefix_tmp), fp);
memset(hzkprefix_tmp, 0, strlen(hzkprefix_tmp));
#endif
WirteHZKFile(lpoutFirstPropInfo->lpPropChar, strlen(lpoutFirstPropInfo->lpPropChar), fp);
}
lpoutPrePropInfo = lpoutFirstPropInfo;
lpoutFirstPropInfo = lpoutFirstPropInfo->lpNext;
}
for(; lpoutFirstPropInfo != NULL; lpoutFirstPropInfo = lpoutFirstPropInfo->lpNext){
if(lpoutFirstPropInfo->lpPropChar){
#ifdef Need_Note
sprintf(hzkprefix_tmp, "/*%s--%s*/", lpoutFirstPropInfo->firstCharacter, lpoutFirstPropInfo->lastCharacter);
WirteHZKFile(hzkprefix_tmp, strlen(hzkprefix_tmp), fp);
memset(hzkprefix_tmp, 0, strlen(hzkprefix_tmp));
#endif
sprintf(hzkprefix_tmp, lpoutFirstPropInfo->lpPropChar, lpoutPrePropInfo->propName);
WirteHZKFile(hzkprefix_tmp, strlen(hzkprefix_tmp), fp);
}
if(lpoutPrePropInfo){
if(lpoutPrePropInfo->lpPropChar) free(lpoutPrePropInfo->lpPropChar);
free(lpoutPrePropInfo);
}
lpoutPrePropInfo = lpoutFirstPropInfo;
}
if(lpoutPrePropInfo){
if(lpoutPrePropInfo->lpPropChar) free(lpoutPrePropInfo->lpPropChar);
free(lpoutPrePropInfo);
}
return lastPropName;
}
CHARINFO GetOneCharInfo(int area1, int area2)
{
CHARINFO retCharInfo;
SIZE SizeChar;
unsigned char HZ[3];
HZ[0] = area1; HZ[1] = area2; HZ[2] = 0x0;
GetTextExtentPoint(hDC, (LPCTSTR)HZ, strlen((const char *)HZ), &SizeChar);
retCharInfo.XDist = (BYTE)SizeChar.cx;
retCharInfo.XSize = (BYTE)SizeChar.cx;
if(SizeChar.cx % 8) SizeChar.cx = (SizeChar.cx + 7) & 0xffff8;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -