ULRE/inc/hgl/graph/font/FontSource.h

152 lines
4.5 KiB
C
Raw Normal View History

2020-07-29 01:00:25 +08:00
#ifndef HGL_GRAPH_FONT_SOURCE_INCLUDE
2020-06-29 11:06:47 +08:00
#define HGL_GRAPH_FONT_SOURCE_INCLUDE
#include<hgl/type/StrChar.h>
#include<hgl/type/Map.h>
#include<hgl/type/Set.h>
2020-06-29 11:06:47 +08:00
#include<hgl/graph/font/Font.h>
2020-07-04 14:44:07 +08:00
#include<hgl/type/UnicodeBlocks.h>
2020-06-29 11:06:47 +08:00
using namespace hgl;
namespace hgl
{
2020-07-31 18:01:28 +08:00
namespace graph
{
struct CharMetricsInfo
{
int x,y; //图像显示偏移
int w,h; //图像尺寸
int adv_x,adv_y;//字符尺寸
};//struct CharMetricsInfo
/**
*
*/
struct FontBitmap
{
int count; //使用次数
2020-07-22 20:50:13 +08:00
2020-07-31 18:01:28 +08:00
CharMetricsInfo metrics_info;
2020-07-22 20:50:13 +08:00
2020-07-31 18:01:28 +08:00
uint8 *data;
};//struct FontBitmap
/**
*
*/
struct CharLayoutAttributes
{
u32char ch; ///<字符
2020-06-29 11:06:47 +08:00
2020-07-31 18:01:28 +08:00
bool visible; ///<是否可显示字符
int size; ///<字符排版尺寸(一般为宽)
2020-06-29 11:06:47 +08:00
2020-07-31 18:01:28 +08:00
bool is_cjk; ///<是否是中日韩文字
bool is_emoji; ///<是否是表情符号
2020-06-29 11:06:47 +08:00
2020-07-31 18:01:28 +08:00
bool is_punctuation; ///<是否是标点符号
2020-07-04 14:44:07 +08:00
2020-07-31 18:01:28 +08:00
bool begin_disable; ///<是否行首禁用符号
bool end_disable; ///<是否行尾禁用符号
bool vrotate; ///<竖排时是否需要旋转
2020-07-04 14:44:07 +08:00
2020-07-31 18:01:28 +08:00
CharMetricsInfo adv_info; ///<字符绘制信息
};//struct CharLayoutAttributes
2020-07-04 14:44:07 +08:00
2020-07-31 18:01:28 +08:00
using CLA=CharLayoutAttributes;
/**
*
*/
class FontSource
{
protected:
2020-07-04 14:44:07 +08:00
2020-07-31 18:01:28 +08:00
Set<void *> ref_object;
2020-07-04 14:44:07 +08:00
2020-07-31 18:01:28 +08:00
MapObject<u32char,CLA> cla_cache;
2020-07-04 14:44:07 +08:00
2020-07-31 18:01:28 +08:00
public:
2020-06-29 11:06:47 +08:00
2020-07-31 18:01:28 +08:00
virtual ~FontSource()=default;
2020-06-29 11:06:47 +08:00
2020-07-31 18:01:28 +08:00
virtual FontBitmap *GetCharBitmap (const u32char &)=0; ///<取得字符位图数据
virtual const bool GetCharMetrics (CharMetricsInfo &,const u32char &); ///<取得字符绘制信息
const CLA * GetCLA (const u32char &); ///<取得字符排版信息
virtual int GetCharHeight ()const=0; ///<取得字符高度
2020-06-29 11:06:47 +08:00
2020-07-31 18:01:28 +08:00
void RefAcquire(void *); ///<引用请求
void RefRelease(void *); ///<引用释放
int RefCount()const{return ref_object.GetCount();} ///<获取引用对象数量
};//class FontSource
2020-06-29 11:06:47 +08:00
2020-07-31 18:01:28 +08:00
/**
*
*/
class FontSourceSingle:public FontSource
{
protected:
2020-06-29 11:06:47 +08:00
2020-07-31 18:01:28 +08:00
Font fnt;
2020-06-29 11:06:47 +08:00
2020-07-31 18:01:28 +08:00
MapObject<u32char,FontBitmap> chars_bitmap; ///<字符位图
2020-06-29 11:06:47 +08:00
2020-07-31 18:01:28 +08:00
protected:
2020-07-31 18:01:28 +08:00
virtual bool MakeCharBitmap(FontBitmap *,u32char)=0; ///<产生字符位图数据
public:
FontSourceSingle(const Font &f){fnt=f;}
virtual ~FontSourceSingle()=default;
FontBitmap *GetCharBitmap (const u32char &ch) override; ///<取得字符位图数据
const bool GetCharMetrics (CharMetricsInfo &,const u32char &); ///<取得字符绘制信息
virtual int GetCharHeight ()const override{return fnt.height;} ///<取得字符高度
};//class FontSourceSingle:public FontSource
FontSourceSingle *CreateFontSource(const Font &f);
/**
*
*/
2020-07-04 14:44:07 +08:00
class FontSourceMulti:public FontSource
{
using FontSourcePointer=FontSource *;
2020-07-31 18:01:28 +08:00
FontSource *default_source;
Map<UnicodeBlock,FontSourcePointer> source_map;
2020-07-04 14:44:07 +08:00
2020-07-31 18:01:28 +08:00
int max_char_height;
2020-07-31 18:01:28 +08:00
void RefreshMaxCharHeight();
2020-07-31 18:01:28 +08:00
protected:
2020-07-08 21:56:39 +08:00
2020-07-31 18:01:28 +08:00
FontSource *GetFontSource(const u32char &ch);
2020-07-08 21:56:39 +08:00
2020-07-04 14:44:07 +08:00
public:
2020-07-31 18:01:28 +08:00
/**
* @param dfs
*/
2020-07-04 14:44:07 +08:00
FontSourceMulti(FontSource *dfs);
virtual ~FontSourceMulti();
void Add(UnicodeBlock,FontSource *);
2020-07-31 18:01:28 +08:00
void Remove(UnicodeBlock);
void Remove(FontSource *);
2020-07-04 14:44:07 +08:00
2020-07-31 18:01:28 +08:00
public:
2020-07-31 18:01:28 +08:00
FontBitmap *GetCharBitmap (const u32char &ch) override;
const bool GetCharMetrics (CharMetricsInfo &,const u32char &); ///<取得字符绘制信息
int GetCharHeight ()const override; ///<取得字符高度
2020-07-04 14:44:07 +08:00
};//class FontSourceMulti:public FontSource
2020-07-31 18:01:28 +08:00
}//namespace graph
2020-06-29 11:06:47 +08:00
}//namespace hgl
2020-07-04 14:44:07 +08:00
#endif//HGL_GRAPH_FONT_SOURCE_INCLUDE