From a273605b422d002e865d885802990cfe7ca6fc34 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 21 Jul 2020 11:48:06 +0800 Subject: [PATCH] delete line_height in FontSource, append char_height attribute. --- inc/hgl/graph/font/FontSource.h | 12 +++++++--- src/SceneGraph/font/FontSourceMulti.cpp | 32 +++++++++++++++++++++++++ src/SceneGraph/font/FontSourceWin.cpp | 3 +-- src/SceneGraph/font/FontSourceWin.h | 6 ----- 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/inc/hgl/graph/font/FontSource.h b/inc/hgl/graph/font/FontSource.h index 9476d29c..d9481533 100644 --- a/inc/hgl/graph/font/FontSource.h +++ b/inc/hgl/graph/font/FontSource.h @@ -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 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 diff --git a/src/SceneGraph/font/FontSourceMulti.cpp b/src/SceneGraph/font/FontSourceMulti.cpp index 9b81db35..39d4dae9 100644 --- a/src/SceneGraph/font/FontSourceMulti.cpp +++ b/src/SceneGraph/font/FontSourceMulti.cpp @@ -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;iright->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(); } } diff --git a/src/SceneGraph/font/FontSourceWin.cpp b/src/SceneGraph/font/FontSourceWin.cpp index 90b48560..024981bb 100644 --- a/src/SceneGraph/font/FontSourceWin.cpp +++ b/src/SceneGraph/font/FontSourceWin.cpp @@ -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, diff --git a/src/SceneGraph/font/FontSourceWin.h b/src/SceneGraph/font/FontSourceWin.h index 0156bd85..60ae2242 100644 --- a/src/SceneGraph/font/FontSourceWin.h +++ b/src/SceneGraph/font/FontSourceWin.h @@ -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