📄 uifont.c
字号:
/*********************************************************************/
// 文 件 名: uiFont.cpp
// 程序说明: 字体管理
// 程序设计: 张学平
// 2001.10.23 设计完成 说明文档:R004-S231-0001
// 程序审查: 宋军霞
// 2002.01.22 审查完成 说明文档:R004-S231-0001
// 项目编号: R004-S231
// 版 本: V1.0
// 版 权: Reality Plus Technology (ShenZhen) Co.,Ltd.
/*********************************************************************/
#include <string.h>
#include <uiFont.h>
#include <uiGraph.h>
#include <uiUtility.h>
#include <SysVar.h>
short gFontType; // 当前字体
short gOldFontType;
/*
0x9D,0x40,0x57,0xE0,0x15,0x40,0x9C,0xA0,0x57,0x60,0x5C,
0x00,0x35,0x40,0x37,0xE0,0x5D,0x40,0xC9,0xA0,0x56,0xE1
*/
// 初始化字体系统
void guiInitFont(void)
{
int i;
gFontType = GUI_DEFAULT_FONT; //系统当前字体与控件缺省字体相同
gOldFontType = GUI_DEFAULT_FONT;
guiUserInitfont(); //调用户字体初始化程序
}
// 设置当前字体
DLL_EXP(int) guiSetFont(int type)
{
int langType;
if(!(gShowFont[type].ShowChar)&&(!gShowFont[type].ShowWord))
return STATUS_ERR; // 在字符和文字显示函数均为空时,表示该字体无效
langType = guiQueryLanguageType();
if((type!=FONT_ENG12_BIG12)&&(langType==LANGUAGE_CHT))
return STATUS_ERR;
gFontType = type;
return STATUS_OK;
}
// 获取当前字体类型
DLL_EXP(int) guiGetFont(void)
{
return gFontType;
}
// 保存当前字体类型,并将新字体设置为当前字体
STATUS guiPushFont(int type)
{
int langType;
gOldFontType = gFontType;
if(!(gShowFont[type].ShowChar)&&(!gShowFont[type].ShowWord))
return STATUS_ERR; // 在字符和文字显示函数均为空时,表示该字体无效
langType = guiQueryLanguageType();
if((type!=FONT_ENG12_BIG12)&&(langType==LANGUAGE_CHT))
return STATUS_ERR;
gFontType = type;
return STATUS_OK;
}
// 将被保存的字体恢复为当前字体
STATUS guiPopFont(void)
{
/*
int langType;
langType = guiQueryLanguageType();
if((gOldFontType!=FONT_ENG12_BIG12)&&(langType==LANGUAGE_CHT))
return STATUS_ERR;
*/
gFontType = gOldFontType;
return STATUS_OK;
}
// 设置字体操作函数
DLL_EXP(void) guiSetFontOps(int type, TShowFont tShowFont)
{
gShowFont[type] = tShowFont;
}
// 显示字符
DLL_EXP(void) guiShowChar(HNDL handle, const char ascii, int x, int y, int color, int style)
{
(gShowFont[gFontType].ShowChar)(handle, ascii, x, y, color, style);
}
// 在矩形区域内显示字符
void _guiShowCharInView(TRect *rect, const char ascii, int x, int y, int color, int style)
{
(gShowFont[gFontType].ShowCharInView)(rect, ascii, x, y, color, style);
}
// 获取字符宽度
DLL_EXP(short) guiGetCharWidth(const char ascii)
{
return (gShowFont[gFontType].GetCharWidth)(ascii);
}
// 获取字符高度
DLL_EXP(short) guiGetCharHeight(void)
{
return (gShowFont[gFontType].GetCharHeight)();
}
// 显示汉字
DLL_EXP(void) guiShowWord(HNDL handle, const char *pCode, int x, int y, int color, int style)
{
(gShowFont[gFontType].ShowWord)(handle, pCode, x, y, color, style);
}
// 在矩形区域内显示汉字
void _guiShowWordInView(TRect *rect, const char *pCode, int x, int y, int color, int style)
{
(gShowFont[gFontType].ShowWordInView)(rect, pCode, x, y, color, style);
}
// 获取汉字宽度
DLL_EXP(short) guiGetWordWidth(void)
{
return (gShowFont[gFontType].GetWordWidth)();
}
// 获取汉字高度
DLL_EXP(short) guiGetWordHeight(void)
{
return (gShowFont[gFontType].GetWordHeight)();
}
// 获取字符串高度
DLL_EXP(int) guiGetStringHeight(void)
{
int wordHeight, charHeight, strHeight;
wordHeight = guiGetWordHeight();
charHeight = guiGetCharHeight();
strHeight = wordHeight>charHeight?wordHeight:charHeight;
return strHeight;
}
// 获取字符串宽度
DLL_EXP(int) guiGetStringWidth(const char *string)
{
int i, len, iflag;
BYTE *p;
len = 0;
p = (BYTE *)string;
iflag = 0;
while(*p)
{
if(iflag)
{
len += guiGetWordWidth()+FONT_CHAR_GAP;
iflag = 0;
}
else
{
if(*p<0x80)
{
len += guiGetCharWidth(*p)+FONT_CHAR_GAP;
}
else
{
iflag = 1;
}
}
p++;
}
if(len)
len -= FONT_CHAR_GAP;
return(len);
}
// 在一个矩形区域内显示字符串,并自动换行
DLL_EXP(void) guiShowStringInArea(HNDL handle, const char *string,int x1, int y1, int x2, int y2, int color, int style)
{
unsigned char ch1, ch2;
unsigned char *pText;
int left, top, right, bottom;
int xPos, yPos, iRet;
int wordHeight, charHeight, strHeight;
TRect ViewRect;
int ViewLeft, ViewTop, ViewRight, ViewBottom;
int i;
// 获取裁剪区座标
iRet = _guiGetHandleView(handle, &ViewLeft, &ViewTop, &ViewRight, &ViewBottom);
if(iRet != STATUS_OK)
return;
ViewRect.left = ViewLeft; ViewRect.top = ViewTop;
ViewRect.right = ViewRight; ViewRect.bottom = ViewBottom;
left = x1;
top = y1;
right = x2;
bottom = y2;
_guiConvertXY(handle, &left, &top); //将相对座标转为绝对座标
_guiConvertXY(handle, &right, &bottom);
xPos = left; //显示位置
yPos = top;
wordHeight = guiGetWordHeight();
charHeight = guiGetCharHeight();
strHeight = wordHeight>charHeight?wordHeight:charHeight;
pText = (unsigned char *)string;
while(*pText)
{
ch1 = *pText;
if(ch1<0x80)
{
if((xPos+guiGetCharWidth(ch1))>right) // 不足以显示完一个字符时,换行
{
if(style) // 不透明显示
{
for(i=xPos;i<=right;i++) // 清除最后的显示
_guiDrawVLineInView(&ViewRect,i,yPos,yPos+strHeight-1,color>>8);
yPos+=strHeight;
for(i=0;i<FONT_LINE_GAP;i++) // 清除行间的显示
_guiDrawHLineInView(&ViewRect,left,right,yPos++,color>>8);
}
else // 透明显示
yPos += strHeight+FONT_LINE_GAP;
if((yPos+strHeight)>bottom) //y座标超出裁剪区时,停止显示
break;
xPos = left;
}
_guiShowCharInView(&ViewRect, ch1, xPos, yPos, color, style);
pText++;
xPos += guiGetCharWidth(ch1);
}
else
{
if((xPos+guiGetWordWidth())>right) // 不足以显示完一个汉字时,换行
{
if(style) // 不透明显示
{
for(i=xPos;i<=right;i++) // 清除最后的显示
_guiDrawVLineInView(&ViewRect,i,yPos,yPos+strHeight-1,color>>8);
yPos+=strHeight;
for(i=0;i<FONT_LINE_GAP;i++) // 清除行间的显示
_guiDrawHLineInView(&ViewRect,left,right,yPos++,color>>8);
}
else // 透明显示
yPos += strHeight+FONT_LINE_GAP;
if((yPos+strHeight)>bottom) //y座标超出裁剪区时,停止显示
break;
xPos = left;
}
_guiShowWordInView(&ViewRect, (const char *)pText, xPos, yPos, color, style);
pText+=2;
xPos += guiGetWordWidth();
}
if(*pText && style)
{
for(i=0;i<FONT_CHAR_GAP;i++)
_guiDrawVLineInView(&ViewRect,xPos++,yPos,yPos+guiGetWordHeight(),color>>8);
}
else
xPos+=FONT_CHAR_GAP;
}
}
// 显示字符串,并作相对于其所属区域裁剪,不会自动换行
DLL_EXP(void) guiShowString(HNDL handle, const char *string,int x,int y, int color, int style)
{
unsigned char ch1, ch2;
unsigned char *pText;
int left, top, iRet;
TRect ViewRect;
int i;
int ViewLeft, ViewTop, ViewRight, ViewBottom;
iRet = _guiGetHandleView(handle, &ViewLeft, &ViewTop, &ViewRight, &ViewBottom);
if(iRet!=STATUS_OK)
return;
ViewRect.left = ViewLeft; ViewRect.top = ViewTop;
ViewRect.right = ViewRight; ViewRect.bottom = ViewBottom;
left = x;
top = y;
_guiConvertXY(handle, &left, &top);
pText = (unsigned char *)string;
while(*pText)
{
ch1 = *pText;
if(ch1<0x80)
{
_guiShowCharInView(&ViewRect, ch1, left, top, color, style);
pText++;
left += guiGetCharWidth(ch1);
}
else
{
_guiShowWordInView(&ViewRect, (const char *)pText, left, top, color, style);
pText+=2;
left += guiGetWordWidth();
}
if( style && *pText)
{
for(i=0;i<FONT_CHAR_GAP;i++)
_guiDrawVLineInView(&ViewRect,left++,top,top+guiGetWordHeight(),color>>8);
}
else
left+=FONT_CHAR_GAP;
}
}
DLL_EXP(unsigned short *)guiGetWordBitmap(const char *pCode)
{
return (gShowFont[gFontType].GetWordBitmap)(pCode);
}
DLL_EXP(unsigned short *)guiGetCharBitmap(const char ascii)
{
return (gShowFont[gFontType].GetCharBitmap)(ascii);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -