📄 fontcn.h
字号:
////////////////////////////////////////////////////////
//该类是为了解决 CORE 不支持中文汉字显示的问题而编写,//
//FontCN类的实现原理与原引擎中的Font类模式十分相同,只//
//只是需要使用汉字字模图片生成工具先生成汉字的字模图片//
//与字模图片的信息文件。 //
// //
//注意:该类加载汉字字模或许会因为机器配置原因而时间过//
//长,这点会在以后改进。 //
// //
//微妙的平衡 //
//2006-08-25 //
// //
////////////////////////////////////////////////////////
// 注意:字模图片文件的宽高不能超过 2048 象素,否则字模的宽高将不能被引擎正确读取
#pragma once
#include "baseobject.h"
#include "RenderSprite.h"
#ifndef _FONTCN_H_
#define _FONTCN_H_
#define VALUE_FIX 1
#define HZ_HIGH_MAX 87 + VALUE_FIX // 0xA1~0xF7 汉字编码范围高位(+1是给普通字母与标点符号留位置)
#define HZ_LOW_MAX 95 // 0xA0~0xFE 汉字编码范围底位
#define HZ_HIGH_FIX 0xA1
#define HZ_LOW_FIX 0xA0
#define HZ_HIGH_END 0xF7
#define HZ_LOW_END 0xFE
#define ASCII_FIX 0x20
#define ASCII_END 0x7f
#define ASCII_WIDTH 6
#define IME_WIDTH 12
// 汉字字体文件头
struct st_FontCN_Head
{
char strHead[32]; //文件头
char strImgFileName[32]; //图像文件名
DWORD dwStringCol; //每行的字数
DWORD dwStringRow; //行数
DWORD dwFontWidth; //字体宽度
DWORD dwFontHeight; //字体高度
public:
void SetData(char *head,char *imgfilename,DWORD nCol,DWORD nRow,DWORD nFWidth,DWORD nFHeight)
{
strcpy(strHead,head);
strcpy(strImgFileName,imgfilename);
dwStringCol = nCol;
dwStringRow = nRow;
dwFontWidth = nFWidth;
dwFontHeight = nFHeight;
}
};
// 汉字字体数据
struct st_FontCN_Body
{
BYTE HZ[2];
WORD dwFontX;
WORD dwFontY;
public:
void SetData(BYTE h,BYTE l,WORD fx,WORD fy)
{
HZ[0] = h;
HZ[1] = l;
dwFontX = fx;
dwFontY = fy;
}
};
class FontCN :
public BaseObject
{
public:
FontCN(); ///根据字体文件创建
~FontCN(void);
bool CreateFontCN(CORE* pCORE,const char *filename);
void Render(float x, float y, const char *string); ///绘制字符串
void Printf(float x, float y, const char *format, ...); ///绘制格式字符串
void PrintfEx(DWORD col,float x, float y, const char *format, ...); ///绘制格式字符串
void RenderFontRect(float x,float y,GUIRect* rect); ///绘制字符
void SetColor(DWORD col, int i=-1); ///设置字体颜色
void SetZ(float z, int i=-1); ///设置Z缓冲
void SetBlendMode(int blend); ///设置混和模式
DWORD GetColor(int i=0) const; ///获得颜色
float GetZ(int i=0) const; ///获得Z缓冲
int GetBlendMode() const; ///获得混和模式
float GetHeight() const; ///获得字体高度
float GetStringWidth(const char *string) const; ///获得字符串的象素级宽度
GUIRect* GetFontRect(BYTE chH,BYTE chL) const; ///获得指定的汉字纹理位置
private:
CORE* m_pCORE; ///公用
st_Quad m_Quad; ///缓冲
float m_fTexWidth; ///纹理宽度
float m_fTexHeight; ///纹理高度
GUIRect* m_letters[HZ_HIGH_MAX][HZ_LOW_MAX]; ///字符精灵
float m_fHeight; ///字符高度
};
#endif //_FONTCN_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -