|
楼主 |
发表于 2012-11-3 10:24:55
|
显示全部楼层
关于如何生成, 其实原理比较简单,但要理解生成了之后是如何应用显示文字(E文与中文),那么还要深入了解UCGUI,
近期我将写一篇这个文章, 时间太紧, 本来好几篇文章都理解得差不多了,就是没有动手, 近期请关注...
这里我先贴上一位网友自己写的生成程序, 其实我也想写一个的, 主要是两点要理解:
1. 汉字库的结构.如HZK16,HZK24等, 了解他是为了找到指定机内码的汉字的点阵.
2. UCGUI中关于文字显示的.C源文件的结构, 这个可以参照已经有的.
下面是一位网友的生成.C文件的代码.
先分析一下他生成的文件,虽然字体结构没对,但他的其他声名都是可以的,首先找到
unicode----内码对照表(我就是用他生成一个二维数组),在gui.h中把笔画定义来过来用,
根据内码查询ucdos汉字库(我用的hz16k)或windows字库(还没研究 : (),这是我写的一个的程序实现,请各位大虾指正
void CHanziDlg::OnCreatefontdot()
{
CFile fhz;
unsigned char bv,bv1,tmpbv;
DWORD offset;
CString strftmp,strFont;
int i;
char font[100];
char filepath[]=".\\\\hz16_16h.c";
char Title[]="/* C-file generated by uc/GUI-FontConvert \\rCompiled: Jul 23 2003 at 13:13:49\\r\\n (c)
2003 Xiang_xudong, Inc.\\rwww.superxxd.com\\r\\n (c) 2003~ Superxxd\\r
Source file: Fonthz16_16.c\\r Font: HZK16\\r Height: 16点阵\\r*/";
m_FontList.ResetContent();
m_FontList.AddString("生成开始...");
log(filepath,Title);
log(filepath,"#include \\"GUI.H\\" ");
log(filepath,"#ifndef GUI_FLASH");
log(filepath," #define GUI_FLASH");
log(filepath,"#endif");
log(filepath,"/*");
log(filepath,"The following line needs to be included in any file selecting the");
log(filepath,"font. A good place would be GUIConf.H");
log(filepath,"*/");
log(filepath,"extern GUI_FLASH const GUI_FONT GUI_FontHZ16_16H;");
log(filepath,"/* Start of unicode area <Basic Latin> */");
if(!fhz.Open("hzk16",CFile::modeRead))
{
MessageBox("File open failed");
return ;
}
char Unicode[100];
char tempbuf[10];
char buf[10];
char buf1[10];
DWORD lenth=fhz.GetLength();
CString csGuiFontProp;
CString csGuiFontCharInfo;
CString temp_Prop;
//GUI_Font_PropN.
int n=1;
int countProp=1;
BOOL bSetFirst=FALSE;
BOOL bWriteProp=FALSE;
int StartNMnumber=1;
int ENDNMnumber=25415;
// for(;;)
for(int ii=0;ii<25415;ii++)
// while(TRUE)
{
if (UNICODE_TO_NM_TABLE[ii].NM==NULL)
{
if(bSetFirst==TRUE)
{
bSetFirst=FALSE;
temp_Prop.Format("0x%s%s",buf1,buf);
csGuiFontProp.Replace("NULL",temp_Prop);
GUI_Font_PropN.AddHead(csGuiFontProp);
countProp+=1;
}
continue;
}
bv1=GetLowBytes(UNICODE_TO_NM_TABLE[ii].NM);
bv=GetHiBytes(UNICODE_TO_NM_TABLE[ii].NM);
//if(bv1==0)
if((bv1==0xa1) && (bv==0xa2))
{
int i_iii=0;
}
if( bv1<0xa1||bv1>0xfe )
{
if(bSetFirst==TRUE)
{
bSetFirst=FALSE;
temp_Prop.Format("0x%s%s",buf1,buf);
csGuiFontProp.Replace("NULL",temp_Prop);
GUI_Font_PropN.AddHead(csGuiFontProp);
countProp+=1;
}
continue;
}
if( bv<0xa1||bv>0xfe )
{
if(bSetFirst==TRUE)
{
bSetFirst=FALSE;
temp_Prop.Format("0x%s%s",buf1,buf);
csGuiFontProp.Replace("NULL",temp_Prop);
GUI_Font_PropN.AddHead(csGuiFontProp);
countProp+=1;
}
continue;
}
offset=((bv-161)*94+(bv1-161))*32;
if(offset>lenth)
continue;
fhz.Seek(offset,CFile::begin);
m_FontList.ResetContent();
itoa(GetHiBytes(UNICODE_TO_NM_TABLE[ii].UNICODE),tempbuf,16);
if(GetHiBytes(UNICODE_TO_NM_TABLE[ii].UNICODE)<0x10)
sprintf(buf1,"0%s",tempbuf);
else
sprintf(buf1,"%s",tempbuf);
itoa(GetLowBytes(UNICODE_TO_NM_TABLE[ii].UNICODE),tempbuf,16);
if(GetLowBytes(UNICODE_TO_NM_TABLE[ii].UNICODE)<0x10)
sprintf(buf,"0%s",tempbuf);
else
sprintf(buf,"%s",tempbuf);
tmpbv=bv;
int zero_count=0;
/*for(i=1;i<=32;i++)
{
fhz.Read(&tmpbv,sizeof(tmpbv));
if(tmpbv==0)
zero_count++;
}
if(zero_count==32)
continue;
*/
sprintf(Unicode,"GUI_FLASH const unsigned char acFontHZ16_16_%s%s[32] = {/*code %s%s */",buf1,buf,buf1,buf);
log(filepath,Unicode);
for(i=1;i<=32;i++)
{
fhz.Read(&bv,sizeof(bv));
strftmp.Format("%s\\0",FontData[bv]);
if(i!=32)
strftmp+=",";
if(!(i%2))
strftmp+="\\0\\r\\x0a";
strFont+=strftmp;
if(!(i%2))
{
sprintf(font,"%s",strFont);
log(filepath,font);
m_FontList.AddString(strFont);
strFont.Empty();
}
}
csGuiFontCharInfo.Format("{ 16, 16, 2, (void GUI_FLASH*)&acFontHZ16_16_%s%s}, /* code %s%s */",buf1,buf,buf1,buf);
GUI_FONT_CharInfo.AddTail(csGuiFontCharInfo);
if(bSetFirst==FALSE)
{
bSetFirst=TRUE;
csGuiFontProp.Format("GUI_FLASH const GUI_FONT_PROP GUI_FontHZ16_16_Prop%d = {",countProp);
temp_Prop.Format(" 0x%s%s /*first character */",buf1,buf);
csGuiFontProp+="\\r";
csGuiFontProp+=temp_Prop;
csGuiFontProp+="\\r";
csGuiFontProp+=" ,NULL /* last character */";
csGuiFontProp+="\\r";
temp_Prop.Format(" ,&GUI_FontHZ16_16_CharInfo[ %d] /* address of first character */",n-1);
csGuiFontProp+=temp_Prop;
csGuiFontProp+="\\r";
if(ii<ENDNMnumber-1)
temp_Prop.Format(" ,(void GUI_FLASH *)&GUI_FontHZ16_16_Prop%d /* pointer to next GUI_FONT_PROP */",countProp+1);
else
temp_Prop.Format(" ,(void *)0/* pointer to next GUI_FONT_PROP */",countProp+1);
csGuiFontProp+=temp_Prop;
csGuiFontProp+="\\r";
csGuiFontProp+="};";
}
n+=1;
log(filepath,"};");
log(filepath,"\\r");
UpdateData(false);
//Sleep(100);
}
fhz.Close();
if(bSetFirst==TRUE)
{
bSetFirst=FALSE;
temp_Prop.Format("0x%s%s",buf1,buf);
csGuiFontProp.Replace("NULL",temp_Prop);
GUI_Font_PropN.AddHead(csGuiFontProp);
}
csGuiFontProp=_T("GUI_FLASH const GUI_FONT GUI_FontHZ16_16 = {");
csGuiFontProp+="\\r";
csGuiFontProp+=" GUI_FONTTYPE_PROP /* type of font */";
csGuiFontProp+="\\r";
csGuiFontProp+=",16 /* height of font */";
csGuiFontProp+="\\r";
csGuiFontProp+=",16 /* space of font y */";
csGuiFontProp+="\\r";
csGuiFontProp+=",1 /* magnification x */";
csGuiFontProp+="\\r";
csGuiFontProp+=",1 /* magnification y */";
csGuiFontProp+="\\r";
csGuiFontProp+=",(void GUI_FLASH *)&GUI_FontHZ16_16_Prop1";
csGuiFontProp+="\\r";
csGuiFontProp+="};";
GUI_Font_PropN.AddTail(csGuiFontProp);
csGuiFontCharInfo.Format("GUI_FLASH const GUI_CHARINFO GUI_FontHZ16_16_CharInfo[%d] = {",n-1);
GUI_FONT_CharInfo.AddHead(csGuiFontCharInfo);
char tempstr[300];
int iii=0;
POSITION pos = GUI_FONT_CharInfo.GetHeadPosition();
for(iii=0;iii<GUI_FONT_CharInfo.GetCount();iii++)
{
csGuiFontCharInfo=GUI_FONT_CharInfo.GetNext(pos);
strcpy(tempstr,csGuiFontCharInfo);
log(filepath,tempstr);
}
log(filepath,"};");
pos = GUI_Font_PropN.GetHeadPosition();
for(iii=0;iii<GUI_Font_PropN.GetCount();iii++)
{
csGuiFontCharInfo=GUI_Font_PropN.GetNext(pos);
strcpy(tempstr,csGuiFontCharInfo);
log(filepath,tempstr);
log(filepath,"\\r");
}
} |
|