update TileFont....

This commit is contained in:
2020-07-31 18:01:28 +08:00
parent 4dc060e05f
commit 1f80f793ac
18 changed files with 512 additions and 380 deletions

View File

@@ -27,7 +27,7 @@ namespace hgl
public:
Font();
Font(const os_char *,int,int,bool,bool,bool=true);
Font(const os_char *,int,int,bool b=false,bool i=false,bool=true);
CompOperatorMemcmp(const Font &); ///<比较操作符重载
};//struct Font

View File

@@ -11,111 +11,141 @@ using namespace hgl;
namespace hgl
{
namespace graph
{
struct CharMetricsInfo
{
int x,y; //图像显示偏移
int w,h; //图像尺寸
namespace graph
{
struct CharMetricsInfo
{
int x,y; //图像显示偏移
int w,h; //图像尺寸
int adv_x,adv_y;//字符尺寸
};//struct CharMetricsInfo
int adv_x,adv_y;//字符尺寸
};//struct CharMetricsInfo
/**
* 字体位图数据
*/
struct FontBitmap
{
int count; //使用次数
/**
* 字体位图数据
*/
struct FontBitmap
{
int count; //使用次数
CharMetricsInfo metrics_info;
CharMetricsInfo metrics_info;
uint8 *data;
};//struct FontBitmap
uint8 *data;
};//struct FontBitmap
/**
* 字符排版属性
*/
struct CharLayoutAttributes
{
u32char ch; ///<字符
/**
* 文字位图数据源
*/
class FontSource
{
protected:
bool visible; ///<是否可显示字符
int size; ///<字符排版尺寸(一般为宽)
Set<void *> ref_object;
bool is_cjk; ///<是否是中日韩文字
bool is_emoji; ///<是否是表情符号
public:
bool is_punctuation; ///<是否是标点符号
virtual ~FontSource()=default;
bool begin_disable; ///<是否行首禁用符号
bool end_disable; ///<是否行尾禁用符号
bool vrotate; ///<竖排时是否需要旋转
virtual FontBitmap *GetCharBitmap (const u32char &)=0; ///<取得字符位图数据
virtual const bool GetCharMetrics (CharMetricsInfo &,const u32char &); ///<取得字符绘制信息
virtual int GetCharHeight ()const=0; ///<取得字符高度
CharMetricsInfo adv_info; ///<字符绘制信息
};//struct CharLayoutAttributes
void RefAcquire(void *); ///<引用请求
void RefRelease(void *); ///<引用释放
int RefCount()const{return ref_object.GetCount();} ///<获取引用对象数量
};//class FontSource
using CLA=CharLayoutAttributes;
/**
* 文字位图数据源
*/
class FontSource
{
protected:
/**
* 文字位图单一数据源
*/
class FontSourceSingle:public FontSource
{
protected:
Set<void *> ref_object;
Font fnt;
MapObject<u32char,CLA> cla_cache;
MapObject<u32char,FontBitmap> chars_bitmap; ///<字符位图
public:
protected:
virtual ~FontSource()=default;
virtual bool MakeCharBitmap(FontBitmap *,u32char)=0; ///<产生字符位图数据
virtual FontBitmap *GetCharBitmap (const u32char &)=0; ///<取得字符位图数据
virtual const bool GetCharMetrics (CharMetricsInfo &,const u32char &); ///<取得字符绘制信息
const CLA * GetCLA (const u32char &); ///<取得字符排版信息
virtual int GetCharHeight ()const=0; ///<取得字符高度
public:
void RefAcquire(void *); ///<引用请求
void RefRelease(void *); ///<引用释放
int RefCount()const{return ref_object.GetCount();} ///<获取引用对象数量
};//class FontSource
FontSourceSingle(const Font &f){fnt=f;}
virtual ~FontSourceSingle()=default;
/**
* 文字位图单一数据源
*/
class FontSourceSingle:public FontSource
{
protected:
FontBitmap *GetCharBitmap (const u32char &ch) override; ///<取得字符位图数据
const bool GetCharMetrics (CharMetricsInfo &,const u32char &); ///<取得字符绘制信息
virtual int GetCharHeight ()const override{return fnt.height;} ///<取得字符高度
};//class FontSourceSingle:public FontSource
Font fnt;
/**
* 文字位图多重数据源
*/
MapObject<u32char,FontBitmap> chars_bitmap; ///<字符位图
protected:
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);
/**
* 文字位图多重数据源
*/
class FontSourceMulti:public FontSource
{
using FontSourcePointer=FontSource *;
FontSource *default_source;
Map<UnicodeBlock,FontSourcePointer> source_map;
FontSource *default_source;
Map<UnicodeBlock,FontSourcePointer> source_map;
int max_char_height;
int max_char_height;
void RefreshMaxCharHeight();
void RefreshMaxCharHeight();
protected:
protected:
FontSource *GetFontSource(const u32char &ch);
FontSource *GetFontSource(const u32char &ch);
public:
/**
* @param dfs 缺省字符数据源
*/
/**
* @param dfs 缺省字符数据源
*/
FontSourceMulti(FontSource *dfs);
virtual ~FontSourceMulti();
void Add(UnicodeBlock,FontSource *);
void Remove(UnicodeBlock);
void Remove(FontSource *);
void Remove(UnicodeBlock);
void Remove(FontSource *);
public:
public:
FontBitmap *GetCharBitmap (const u32char &ch) override;
const bool GetCharMetrics (CharMetricsInfo &,const u32char &); ///<取得字符绘制信息
int GetCharHeight ()const override; ///<取得字符高度
FontBitmap *GetCharBitmap (const u32char &ch) override;
const bool GetCharMetrics (CharMetricsInfo &,const u32char &); ///<取得字符绘制信息
int GetCharHeight ()const override; ///<取得字符高度
};//class FontSourceMulti:public FontSource
}//namespace graph
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_FONT_SOURCE_INCLUDE

View File

@@ -82,30 +82,6 @@ namespace hgl
class TextLayout
{
protected:
struct CharLayoutAttributes
{
u32char ch; ///<字符
int size; ///<字符排版尺寸(一般为宽)
bool visible; ///<是否可显示字符
bool is_cjk; ///<是否是中日韩文字
bool is_emoji; ///<是否是表情符号
bool is_punctuation; ///<是否是标点符号
bool begin_disable; ///<是否行首禁用符号
bool end_disable; ///<是否行尾禁用符号
bool vrotate; ///<竖排时是否需要旋转
CharMetricsInfo adv_info; ///<字符绘制信息
};//struct CharLayoutAttributes
using CLA=CharLayoutAttributes;
protected:
RenderableCreater *rc;
@@ -119,14 +95,15 @@ namespace hgl
float splite_line_max_limit;
int max_chars; ///<总字符数量
int draw_chars_count; ///<可绘制字符数量
List<CLA> chars_attributes;
Set<u32char> alone_chars; ///<不重复字符统计缓冲区
List<CLA *> cla_list; ///<所有字符属性列表
protected:
template<typename T> int preprocess(const BaseString<T> &origin_string);
template<typename T> int plane_preprocess(const BaseString<T> &origin_string);
template<typename T> int stat_chars(const T *,const int);
template<typename T> int preprocess(const T *,const int);
bool h_splite_to_lines(float view_limit);
bool v_splite_to_lines(float view_limit);
@@ -162,7 +139,6 @@ namespace hgl
direction.text_direction=0;
max_chars =0;
draw_chars_count =0;
vertex =nullptr;
tex_coord =nullptr;

View File

@@ -3,12 +3,28 @@
#include<hgl/graph/TileData.h>
#include<hgl/graph/font/FontSource.h>
#include<hgl/type/UnicodeBlocks.h>
#include<hgl/type/ResPoolManage.h>
namespace hgl
{
namespace graph
{
class TileObjectPool
{
TileData *tile_data;
public:
TileObject *Acquire();
void Release(TileObject *);
public:
TileObjectPool(TileData *td):tile_data(td);
};
using TileObjectManage=_ResPoolManage<u32char,TileObject *,TileObjectPool>;
/**
* Tile字符管理<br>
* 本模块允许有多个字符数据来源每个来源也可以对应多个unicode块, 但一个unicode块只能对应一个字体数据来源
@@ -18,10 +34,21 @@ namespace hgl
FontSource *source;
TileData *tile_data;
TileObjectPool *tile_pool;
TileObjectManage *ch_tile_pool;
public:
FontSource *GetFontSource (){return source;}
TileData * GetTileData (){return tile_data;}
public:
TileFont(TileData *td,FontSource *fs);
virtual ~TileFont();
bool Registry(List<RectScope2f> &,const List<u32char> &); ///<注册要使用的字符
void Unregistry(const List<u32char> &); ///<注销要使用的字符
};//class TileFont
}//namespace graph
}//namespace hgl