📄 fontmng.c
字号:
{ FONT16_ITALIC_FONT, LARDIN, 8, 16, FONTSAVETYPE_DATA, 0, 0x8120,0x913F},
{ FONT16_ITALIC_FONT, LDZZZ, 8, 16, FONTSAVETYPE_DATA, 0, 0xF020,0xF02C}
};
#endif*/
/********************************************************************
Function: fontmng initial
Input: none
Output: True is success, False is fail
Notes: 默认是12*12字体
Update:
Date Name Description
============ ============ ===================================
2007-3-29 lichao v1.1 modified
2007-04-09 Liang Ruhui modify
********************************************************************/
void SetPcFontInfo(UINT16 wFontlibID);
BOOL FontMngInitialize(void)
{
INT i,j;
UINT8 chCodeStart[4],chCodeEnd[4];
wFontStyle = 0;
wCurrentFontLib = SYSTLIB;
memset(wFontCodeWidth,0,FONTLIBNUM*4*sizeof(UINT32));
for(i = 0;i < FONTLIBNUM;i++){
memcpy(chCodeStart,&aPrjFontLib[i].wCodeStart,4);
memcpy(chCodeEnd,&aPrjFontLib[i].wCodeEnd,4);
aPrjFontLib[i].pCodeWidth[0] = 1;
for(j = 0;j < 3;j++){
UINT offset = chCodeEnd[j] - chCodeStart[j] + 1;
if((j == 0) && (chCodeStart[j] < 0x7F) && (chCodeEnd[j] > 0x7F)){ //0x7F无编码
offset--;
}
aPrjFontLib[i].pCodeWidth[j+1] = offset*aPrjFontLib[i].pCodeWidth[j];
}
}
/* {
UINT32 start = 0x81308130,end = 0x8139EE39;
UINT32 count;
memcpy(chCodeEnd,&end,4);
memcpy(chCodeStart,&start,4);
count = 0;
for(j = 0;j < 4;j++){
UINT offset = chCodeEnd[j] - chCodeStart[j];
// if((chCodeStart[j] < 0x7F) && (chCodeEnd[j] > 0x7F)){
// offset--;
// }
count += offset*aPrjFontLib[11].pCodeWidth[j];
}
}*/
#ifdef WIN32
// SetPcFontInfo(FONT12_NORMAL_FONT);
#endif
return TRUE;
}
/********************************************************************\
Function: set current font library
Input: id - font library indentifier
Output: TRUE - set success
FALSE - set faile (there isn't the font library in system)
Notes:
Update:
Date Name Description
============ ============ ===================================
2007-04-11 Liang Ruhui modify
\********************************************************************/
UINT16 FontSetLib(UINT16 wFontlibID)
{
UINT16 bRet = -1;
if(wFontlibID < FONT_TOTAL){
bRet = wCurrentFontLib;
wCurrentFontLib = wFontlibID;
}
return bRet;
}
/********************************************************************\
Function: get current font library
Input: none
Output: id - font library indentifier
Notes:
Update:
Date Name Description
============ ============ ===================================
2007-04-11 Liang Ruhui modify
\********************************************************************/
UINT16 FontGetLib (VOID)
{
return wCurrentFontLib;
}
/********************************************************************\
Function: get library font height
Input: fontlibID
Output: high of font, 0 shows that input parameter is wrong
Notes:
Update:
Date Name Description
============ ============ ===================================
2007-04-09 Liang Ruhui Modify v1.1
\********************************************************************/
UINT FontGetHeight(UINT16 wFontLibID)
{
UINT wRet = 0;
if(wFontLibID < FONT_TOTAL)
{
INT index = wFontLibID*FONTLIBNUM;
wRet = aPrjFontLib[index].uFontHeight;
}
return wRet;
}
/********************************************************************\
Function: get char index in block
Input: wCode: font code
wCodeStart: block start code
wCodeEnd: block end code
Output: char index nub
Notes: output is -1 shows that char is not in the block
Update:
Date Name Description
============ ============ ===================================
2007-04-10 Liang Ruhui modify
\********************************************************************/
INT GetBlockIndex(FontLibInfo *FontInfo, UINT32 wCode, UINT32 *Num)
{
UINT8 byCodeStart[4]; // = (UINT8)wCode;
UINT8 byCodeIndex[4];
UINT8 byCodeEnd[4]; // = (UINT8)(wCode>>8);
INT index = -1;
UINT i,j;
memcpy(byCodeIndex,&wCode,4);
for(i = 0; i < FONTLIBNUM; i++){
memcpy(byCodeStart,&FontInfo[i].wCodeStart,4);
memcpy(byCodeEnd,&FontInfo[i].wCodeEnd,4);
if(((byCodeIndex[0] >= byCodeStart[0]) && (byCodeIndex[0] <= byCodeEnd[0])) &&
((byCodeIndex[1] >= byCodeStart[1]) && (byCodeIndex[1] <= byCodeEnd[1])) &&
((byCodeIndex[2] >= byCodeStart[2]) && (byCodeIndex[2] <= byCodeEnd[2])) &&
((byCodeIndex[3] >= byCodeStart[3]) && (byCodeIndex[3] <= byCodeEnd[3])))
{
*Num = i;
index = 0;
for(j = 0;j < 4;j++){
UINT offset = byCodeIndex[j] - byCodeStart[j];
if((j == 0) && (byCodeStart[j] < 0x7F) && (byCodeIndex[j] > 0x7F)){ //0x7F没有编码
offset--;
}
index += offset*FontInfo[i].pCodeWidth[j];
}
index -= (INT)FontInfo[i].wCodeOffset;
break;
}
}
return index;
}
/********************************************************************\
Function: get font information
Input: wFontLibID: fontlib id
wCode: font code
pFontInfo: pointer to FontInfo structure which will return
the font information
lpDotArray: the font dot array
Output: TRUE - success
FALSE - font not exist
Notes: if lpDotArray == 0 then just return the font information
Update:
Date Name Description
============ ============ ===================================
2007-04-09 Liang Ruhui Modified(增加下划线、反白支持)
\********************************************************************/
//UINT GetBlockIndex(FontLibInfo *FontInfo, UINT32 wCode, UINT32 *Num);
BOOL FontGetCharInfo(UINT16 wFontLibID, UINT32 wCode, FontInfo *pFontInfo,UINT8 *lpDotArray)
{
INT index;
INT uBytes;
UINT32 Num;
FontLibInfo *pTemp;
if(wFontLibID >= FONT_TOTAL || pFontInfo == NULL)
return FALSE;
pTemp = (FontLibInfo*)&aPrjFontLib[wFontLibID*FONTLIBNUM]; //用临时指针而不是
if(pTemp[0].uLibSaveType == FONTSAVETYPE_DATA)
{
// if fontlib save in ROM or Norflash
index = GetBlockIndex(pTemp, wCode, &Num);
if(index < 0)
return FALSE;
if(lpDotArray != NULL)
{
if(pTemp[Num].uFontWidth != pTemp[Num].uFontHeight) //半角字符
{
// to calculate the bytes of the dot line
uBytes = (pTemp[Num].uFontWidth + 7)>>3;
// to calculate the bytes of the char
uBytes *= pTemp[Num].uFontHeight;
if(pTemp[Num].pFontLibAddr != NULL){
memcpy(lpDotArray,pTemp[Num].pFontLibAddr + index*uBytes,uBytes);
}
else{
memset(lpDotArray,0x00,uBytes);
}
}
else
{
if(pTemp[Num].uFontHeight == FONTLIB_GBk12)
{ //12×12 chinese character is compress
UINT8 j,k,DotArray[18];
UINT8 *pDotArraybk;
uBytes = 18;
if(pTemp[Num].pFontLibAddr != NULL){
memcpy(DotArray,pTemp[Num].pFontLibAddr + index*uBytes,uBytes);
}
else{
memset(DotArray,0x00,uBytes);
}
pDotArraybk =lpDotArray;
memset(pDotArraybk, 0x00, 24);
//convert 18 bytes to 24 bytes
k = 0;
for(j = 0 ; j < uBytes;)
{
pDotArraybk[ k ] = DotArray[ j ];
pDotArraybk[ k+1 ] = DotArray[ j+1 ] & 0xf0;
//
pDotArraybk[ k+2 ] = ((DotArray[ j+1 ] << 4 ) & 0xf0 ) | (( DotArray[ j+2 ] >> 4 ) & 0x0f );
pDotArraybk[ k+3 ] = ((DotArray[ j+2 ] << 4 ) & 0xf0 ) ;
j += 3;
k += 4;
}
uBytes = 24;
}
else if(pTemp[Num].uFontHeight == FONTLIB_GBk16)
{
uBytes = 32;
if(pTemp[Num].pFontLibAddr != NULL){
memcpy(lpDotArray,pTemp[Num].pFontLibAddr + index*uBytes,uBytes);
}
else{
memset(lpDotArray,0x00,uBytes);
}
}
else if(pTemp[Num].uFontHeight == FONTLIB_GBK24)
{
uBytes = 72;
if(pTemp[Num].pFontLibAddr != NULL){
memcpy(lpDotArray,pTemp[Num].pFontLibAddr + index*uBytes,uBytes);
}
else{
memset(lpDotArray,0x00,uBytes);
}
}
}
}
// copy FontInfo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -