delete line_height in FontSource, append char_height attribute.

This commit is contained in:
hyzboy 2020-07-21 11:48:06 +08:00
parent 94cfcd322c
commit a273605b42
4 changed files with 42 additions and 11 deletions

View File

@ -43,6 +43,7 @@ namespace hgl
virtual FontBitmap *GetCharBitmap(const u32char &)=0; ///<取得字符位图数据
virtual int GetCharAdvWidth(const u32char &)=0; ///<取得字符绘制宽度
virtual int GetCharHeight()const=0; ///<取得字符高度
void RefAcquire(void *); ///<引用请求
void RefRelease(void *); ///<引用释放
@ -69,9 +70,9 @@ namespace hgl
FontSourceSingle(const Font &f){fnt=f;}
virtual ~FontSourceSingle()=default;
FontBitmap * GetCharBitmap(const u32char &ch) override; ///<取得字符位图数据
virtual int GetCharAdvWidth(const u32char &)=0; ///<取得字符绘制宽度
virtual int GetLineHeight()const=0; ///<取得行高
FontBitmap *GetCharBitmap(const u32char &ch) override; ///<取得字符位图数据
virtual int GetCharAdvWidth(const u32char &)=0; ///<取得字符绘制宽度
virtual int GetCharHeight()const override{return fnt.height;} ///<取得字符高度
};//class FontSourceSingle:public FontSource
/**
@ -84,6 +85,10 @@ namespace hgl
FontSource *default_source;
Map<UnicodeBlock,FontSourcePointer> source_map;
int max_char_height;
void RefreshMaxCharHeight();
protected:
FontSource *GetFontSource(const u32char &ch);
@ -102,6 +107,7 @@ namespace hgl
FontBitmap *GetCharBitmap(const u32char &ch) override;
int GetCharAdvWidth(const u32char &) override;
int GetCharHeight()const override; ///<取得字符高度
};//class FontSourceMulti:public FontSource
}//namespace graph
}//namespace hgl

View File

@ -10,6 +10,8 @@ namespace hgl
if(fs)
fs->RefAcquire(this);
max_char_height=fs->GetCharHeight();
}
FontSourceMulti::~FontSourceMulti()
@ -25,8 +27,28 @@ namespace hgl
||!fs
||fs==default_source)return;
if(fs->GetCharHeight()>max_char_height)
max_char_height=fs->GetCharHeight();
source_map.Update(ub,fs);
}
void FontSourceMulti::RefreshMaxCharHeight()
{
max_char_height=0;
const int count=source_map.GetCount();
const auto **fsp=source_map.GetDataList();
for(int i=0;i<count;i++)
{
if((*fsp)->right->GetCharHeight()>max_char_height)
max_char_height=(*fsp)->right->GetCharHeight();
++fsp;
}
}
void FontSourceMulti::Remove(UnicodeBlock ub)
{
@ -34,8 +56,13 @@ namespace hgl
if(source_map.Get(ub,fsp))
{
const bool refresh=(fsp->GetCharHeight()==max_char_height);
fsp->RefRelease(this);
source_map.DeleteByKey(ub);
if(refresh)
RefreshMaxCharHeight();
}
}
@ -46,8 +73,13 @@ namespace hgl
if(source_map.ValueExist(fs))
{
const bool refresh=(fs->GetCharHeight()==max_char_height);
fs->RefRelease(this);
source_map.DeleteByValue(fs);
if(refresh)
RefreshMaxCharHeight();
}
}

View File

@ -61,8 +61,7 @@ namespace hgl
{
hdc=CreateCompatibleDC(0);
LineHeight=(fnt.height*GetDeviceCaps(hdc,LOGPIXELSY))/72;
LineDistance=(LineHeight-fnt.height)/2;
CharHeight=fnt.height;
hfont=CreateFont( -fnt.height,
fnt.width,

View File

@ -21,18 +21,12 @@ namespace hgl
uint8 *buffer;
int buffer_size;
protected:
int LineHeight;
int LineDistance;
public:
WinBitmapFont(const Font &);
~WinBitmapFont();
bool MakeCharBitmap(FontBitmap *,u32char) override; ///<产生字体数据
int GetLineHeight()const override{return LineHeight;} ///<取得行高
int GetCharAdvWidth(const u32char &) override;
};//class WinBitmapFont
}//namespace graph