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

115 lines
2.8 KiB
C
Raw Normal View History

2020-06-29 11:06:47 +08:00
#ifndef HGL_GRAPH_FONT_SOURCE_INCLUDE
#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
{
namespace graph
{
/**
*
*/
struct FontBitmap
{
int count; //使用次数
int x,y; //图像显示偏移
int w,h; //图像尺寸
int adv_x,adv_y;//字符尺寸
uint8 *data;
};//struct FontBitmap
/**
*
*/
class FontSource
{
2020-07-04 14:44:07 +08:00
protected:
Set<void *> ref_object;
public:
virtual ~FontSource()=default;
virtual FontBitmap *GetCharBitmap(const u32char &)=0; ///<取得字符位图数据
2020-07-08 21:56:39 +08:00
virtual int GetCharAdvWidth(const u32char &)=0; ///<取得字符绘制宽度
virtual int GetCharHeight()const=0; ///<取得字符高度
2020-07-04 14:44:07 +08:00
void RefAcquire(void *); ///<引用请求
void RefRelease(void *); ///<引用释放
int RefCount()const{return ref_object.GetCount();} ///<获取引用对象数量
};//class FontSource
/**
*
*/
class FontSourceSingle:public FontSource
{
2020-06-29 11:06:47 +08:00
protected:
Font fnt;
MapObject<u32char,FontBitmap> chars_bitmap; ///<字符位图
protected:
2020-07-08 21:56:39 +08:00
virtual bool MakeCharBitmap(FontBitmap *,u32char)=0; ///<产生字符位图数据
2020-06-29 11:06:47 +08:00
public:
2020-07-04 14:44:07 +08:00
FontSourceSingle(const Font &f){fnt=f;}
virtual ~FontSourceSingle()=default;
2020-06-29 11:06:47 +08:00
FontBitmap *GetCharBitmap(const u32char &ch) override; ///<取得字符位图数据
virtual int GetCharAdvWidth(const u32char &)=0; ///<取得字符绘制宽度
virtual int GetCharHeight()const override{return fnt.height;} ///<取得字符高度
2020-07-04 14:44:07 +08:00
};//class FontSourceSingle:public FontSource
2020-07-04 14:44:07 +08:00
/**
*
*/
class FontSourceMulti:public FontSource
{
using FontSourcePointer=FontSource *;
FontSource *default_source;
Map<UnicodeBlock,FontSourcePointer> source_map;
int max_char_height;
void RefreshMaxCharHeight();
2020-07-08 21:56:39 +08:00
protected:
FontSource *GetFontSource(const u32char &ch);
2020-07-04 14:44:07 +08:00
public:
/**
* @param dfs
*/
FontSourceMulti(FontSource *dfs);
virtual ~FontSourceMulti();
void Add(UnicodeBlock,FontSource *);
void Remove(UnicodeBlock);
void Remove(FontSource *);
FontBitmap *GetCharBitmap(const u32char &ch) override;
2020-07-08 21:56:39 +08:00
int GetCharAdvWidth(const u32char &) override;
int GetCharHeight()const override; ///<取得字符高度
2020-07-04 14:44:07 +08:00
};//class FontSourceMulti:public FontSource
2020-06-29 11:06:47 +08:00
}//namespace graph
}//namespace hgl
2020-07-04 14:44:07 +08:00
#endif//HGL_GRAPH_FONT_SOURCE_INCLUDE