split CharAttributes from CharLayoutAttributes. use in all FontSource

This commit is contained in:
hyzboy 2020-08-03 17:51:24 +08:00
parent 85dac21d87
commit bb1484ae98
3 changed files with 56 additions and 36 deletions

2
CMCore

@ -1 +1 @@
Subproject commit 339ee9a5614211383999d725cd90e4278c9e1594 Subproject commit 2d6883be633abae7f0f10810e2b61367175bcfc4

View File

@ -32,18 +32,13 @@ namespace hgl
uint8 *data; uint8 *data;
};//struct FontBitmap };//struct FontBitmap
/** struct CharAttributes
*
*/
struct CharLayoutAttributes
{ {
u32char ch; ///<字符 u32char ch; ///<字符
bool visible; ///<是否可显示字符 bool space; ///<是否属于空格
int size; ///<字符排版尺寸(一般为宽)
bool is_cjk; ///<是否是中日韩文字 bool is_cjk; ///<是否是中日韩文字
bool is_emoji; ///<是否是表情符号 bool is_emoji; ///<是否是表情符号
@ -51,9 +46,19 @@ namespace hgl
bool begin_disable; ///<是否行首禁用符号 bool begin_disable; ///<是否行首禁用符号
bool end_disable; ///<是否行尾禁用符号 bool end_disable; ///<是否行尾禁用符号
bool vrotate; ///<竖排时是否需要旋转 bool vrotate; ///<竖排时是否需要旋转
};//
/**
*
*/
struct CharLayoutAttributes:public CharAttributes
{
CharAttributes *attr; ///<字符基本信息
CharMetricsInfo adv_info; ///<字符绘制信息 bool visible; ///<在当前字体下是否需要绘制
CharMetricsInfo metrics; ///<字符绘制信息
};//struct CharLayoutAttributes };//struct CharLayoutAttributes
using CLA=CharLayoutAttributes; using CLA=CharLayoutAttributes;

View File

@ -31,6 +31,8 @@ namespace hgl
constexpr int EndSymbolsCount =(sizeof(EndSymbols) /sizeof(u16char))-1; constexpr int EndSymbolsCount =(sizeof(EndSymbols) /sizeof(u16char))-1;
constexpr int CurrencySymbolsCount=(sizeof(CurrencySymbols)/sizeof(u16char))-1; constexpr int CurrencySymbolsCount=(sizeof(CurrencySymbols)/sizeof(u16char))-1;
constexpr int VRotateSymbolsCount =(sizeof(VRotateSymbols) /sizeof(u16char))-1; constexpr int VRotateSymbolsCount =(sizeof(VRotateSymbols) /sizeof(u16char))-1;
MapObject<u32char,CharAttributes> all_char_attrs;
}//namespace }//namespace
const CLA *FontSource::GetCLA(const u32char &ch) const CLA *FontSource::GetCLA(const u32char &ch)
@ -40,37 +42,50 @@ namespace hgl
if(cla_cache.Get(ch,cla)) if(cla_cache.Get(ch,cla))
return cla; return cla;
cla=new CLA; CharAttributes *attr;
cla->ch=ch; const int pos=all_char_attrs.GetValueAndSerial(ch,attr);
if(hgl::isspace(ch)) if(pos<0)
{ {
cla->visible=false; attr=new CharAttributes;
}
else attr->ch=ch;
{
cla->visible=true;
cla->begin_disable =hgl::strchr(BeginSymbols, ch,BeginSymbolsCount ); attr->space=hgl::isspace(ch);
cla->end_disable =hgl::strchr(EndSymbols, ch,EndSymbolsCount );
if(!cla->end_disable) //货币符号同样行尾禁用 if(!attr->space)
cla->end_disable =hgl::strchr(CurrencySymbols, ch,CurrencySymbolsCount );
cla->vrotate =hgl::strchr(VRotateSymbols, ch,VRotateSymbolsCount );
cla->is_cjk =isCJK(ch);
cla->is_emoji =isEmoji(ch);
cla->is_punctuation =isPunctuation(ch);
if(!GetCharMetrics(cla->adv_info,ch))
hgl_zero(cla->adv_info);
else
if(cla->adv_info.w>0&&cla->adv_info.h>0)
{ {
cla->size=ceil(cla->adv_info.adv_x); attr->begin_disable =hgl::strchr(BeginSymbols, ch,BeginSymbolsCount );
attr->end_disable =hgl::strchr(EndSymbols, ch,EndSymbolsCount );
if(!attr->end_disable) //货币符号同样行尾禁用
attr->end_disable =hgl::strchr(CurrencySymbols, ch,CurrencySymbolsCount );
attr->vrotate =hgl::strchr(VRotateSymbols, ch,VRotateSymbolsCount );
attr->is_cjk =isCJK(ch);
attr->is_emoji =isEmoji(ch);
attr->is_punctuation=isPunctuation(ch);
}
all_char_attrs.Add(ch,attr);
}
cla=new CLA;
cla->attr=attr;
if(!attr->space)
{
if(!GetCharMetrics(cla->metrics,ch))
{
cla->visible=false;
hgl_zero(cla->metrics);
}
else
{
cla->visible=(cla->metrics.w>0&&cla->metrics.h>0);
} }
} }