add FontSourceSingle/Multi.cpp
This commit is contained in:
parent
b417b08f59
commit
57a0326ee8
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit 2e076881513560dd8111d3f101222dc2fd0b333e
|
||||
Subproject commit 02cb4bb8b3f086321c8dd5773cc6355e72a5c8cb
|
@ -1,26 +0,0 @@
|
||||
#ifndef HGL_GRAPH_FONT_MULTI_SOURCE_INCLUDE
|
||||
#define HGL_GRAPH_FONT_MULTI_SOURCE_INCLUDE
|
||||
|
||||
#include<hgl/graph/font/FontSource.h>
|
||||
#include<hgl/type/UnicodeBlocks.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class FontMultiSource:public FontSource
|
||||
{
|
||||
using FontSourcePointer=FontSource *;
|
||||
using FontSourceTable=FontSourcePointer[(size_t)UnicodeBlock::RANGE_SIZE];
|
||||
|
||||
FontSourceTable source_map;
|
||||
|
||||
public:
|
||||
|
||||
FontMultiSource();
|
||||
virtual ~FontMultiSource();
|
||||
|
||||
void Add(UnicodeBlock,FontSource *);
|
||||
};//class FontMultiSource:public FontSource
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_FONT_MULTI_SOURCE_INCLUDE
|
@ -5,6 +5,7 @@
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/Set.h>
|
||||
#include<hgl/graph/font/Font.h>
|
||||
#include<hgl/type/UnicodeBlocks.h>
|
||||
|
||||
using namespace hgl;
|
||||
|
||||
@ -32,14 +33,32 @@ namespace hgl
|
||||
*/
|
||||
class FontSource
|
||||
{
|
||||
protected:
|
||||
|
||||
Set<void *> ref_object;
|
||||
|
||||
public:
|
||||
|
||||
virtual ~FontSource()=default;
|
||||
|
||||
virtual FontBitmap *GetCharBitmap(const u32char &)=0; ///<取得字符位图数据
|
||||
|
||||
void RefAcquire(void *); ///<引用请求
|
||||
void RefRelease(void *); ///<引用释放
|
||||
int RefCount()const{return ref_object.GetCount();} ///<获取引用对象数量
|
||||
};//class FontSource
|
||||
|
||||
/**
|
||||
* 文字位图单一数据源
|
||||
*/
|
||||
class FontSourceSingle:public FontSource
|
||||
{
|
||||
protected:
|
||||
|
||||
Font fnt;
|
||||
|
||||
MapObject<u32char,FontBitmap> chars_bitmap; ///<字符位图
|
||||
|
||||
Set<void *> ref_object;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool MakeCharBitmap(FontBitmap *,u32char)=0; ///<产生字体数据
|
||||
@ -47,15 +66,36 @@ namespace hgl
|
||||
|
||||
public:
|
||||
|
||||
FontSource(const Font &f){fnt=f;}
|
||||
virtual ~FontSource()=default;
|
||||
FontSourceSingle(const Font &f){fnt=f;}
|
||||
virtual ~FontSourceSingle()=default;
|
||||
|
||||
FontBitmap *GetCharBitmap(const u32char &); ///<取得字符位图数据
|
||||
FontBitmap *GetCharBitmap(const u32char &ch) override;
|
||||
};//class FontSourceSingle:public FontSource
|
||||
|
||||
void RefAcquire(void *); ///<引用请求
|
||||
void RefRelease(void *); ///<引用释放
|
||||
int RefCount()const{return ref_object.GetCount();} ///<获取引用对象数量
|
||||
};//class FontSource
|
||||
/**
|
||||
* 文字位图多重数据源
|
||||
*/
|
||||
class FontSourceMulti:public FontSource
|
||||
{
|
||||
using FontSourcePointer=FontSource *;
|
||||
|
||||
FontSource *default_source;
|
||||
Map<UnicodeBlock,FontSourcePointer> source_map;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @param dfs 缺省字符数据源
|
||||
*/
|
||||
FontSourceMulti(FontSource *dfs);
|
||||
virtual ~FontSourceMulti();
|
||||
|
||||
void Add(UnicodeBlock,FontSource *);
|
||||
void Remove(UnicodeBlock);
|
||||
void Remove(FontSource *);
|
||||
|
||||
FontBitmap *GetCharBitmap(const u32char &ch) override;
|
||||
};//class FontSourceMulti:public FontSource
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_FONT_SOURCE_INCLUDE
|
||||
#endif//HGL_GRAPH_FONT_SOURCE_INCLUDE
|
||||
|
@ -43,10 +43,25 @@ SET(SCENE_GRAPH_SOURCE RenderList.cpp
|
||||
)
|
||||
|
||||
file(GLOB FONT_HEADER ${ROOT_INCLUDE_PATH}/hgl/graph/font/*.*)
|
||||
file(GLOB FONT_SOURCE font/*.*)
|
||||
|
||||
SET(FONT_SOURCE font/Font.cpp
|
||||
font/FontSource.cpp
|
||||
font/FontSourceSingle.cpp
|
||||
font/FontSourceMulti.cpp
|
||||
font/FontSourceManage.cpp
|
||||
font/TileFont.cpp)
|
||||
|
||||
SOURCE_GROUP("Font" FILES ${FONT_HEADER} ${FONT_SOURCE})
|
||||
|
||||
IF(WIN32)
|
||||
SET(FONT_SOURCE_OS font/FontSourceWin.cpp
|
||||
font/FontSourceWin.h)
|
||||
|
||||
SOURCE_GROUP("Font\\Windows" FILES ${FONT_SOURCE_OS})
|
||||
|
||||
SET(FONT_SOURCE ${FONT_SOURCE} ${FONT_SOURCE_OS})
|
||||
ENDIF(WIN32)
|
||||
|
||||
SOURCE_GROUP("Header Files" FILES ${SCENE_GRAPH_HEADER})
|
||||
SOURCE_GROUP("Source Files" FILES ${SCENE_GRAPH_SOURCE})
|
||||
|
||||
|
@ -3,36 +3,7 @@
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
FontBitmap *FontSource::GetCharBitmap(const u32char &ch)
|
||||
{
|
||||
if(!this)
|
||||
return(nullptr);
|
||||
|
||||
if(hgl::isspace(ch))return(nullptr); //不能显示的数据或是空格
|
||||
|
||||
FontBitmap *bmp;
|
||||
|
||||
if(chars_bitmap.Get(ch,bmp))
|
||||
return bmp;
|
||||
|
||||
bmp=new FontBitmap;
|
||||
|
||||
memset(bmp,0,sizeof(FontBitmap));
|
||||
|
||||
if(!MakeCharBitmap(bmp,ch))
|
||||
{
|
||||
delete bmp;
|
||||
chars_bitmap.Add(ch,nullptr);
|
||||
return(nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
chars_bitmap.Add(ch,bmp);
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
void FontSource::RefAcquire(void *ptr)
|
||||
{
|
||||
if(!ptr)return;
|
||||
|
75
src/SceneGraph/font/FontSourceMulti.cpp
Normal file
75
src/SceneGraph/font/FontSourceMulti.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
#include<hgl/graph/font/FontSource.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
FontSourceMulti::FontSourceMulti(FontSource *fs)
|
||||
{
|
||||
default_source=fs;
|
||||
|
||||
if(fs)
|
||||
fs->RefAcquire(this);
|
||||
}
|
||||
|
||||
FontSourceMulti::~FontSourceMulti()
|
||||
{
|
||||
if(default_source)
|
||||
default_source->RefRelease(this);
|
||||
}
|
||||
|
||||
void FontSourceMulti::Add(UnicodeBlock ub,FontSource *fs)
|
||||
{
|
||||
if(ub<UnicodeBlock::BEGIN_RANGE
|
||||
||ub>UnicodeBlock::END_RANGE
|
||||
||!fs
|
||||
||fs==default_source)return;
|
||||
|
||||
source_map.Update(ub,fs);
|
||||
}
|
||||
|
||||
void FontSourceMulti::Remove(UnicodeBlock ub)
|
||||
{
|
||||
FontSourcePointer fsp;
|
||||
|
||||
if(source_map.Get(ub,fsp))
|
||||
{
|
||||
fsp->RefRelease(this);
|
||||
source_map.DeleteByKey(ub);
|
||||
}
|
||||
}
|
||||
|
||||
void FontSourceMulti::Remove(FontSource *fs)
|
||||
{
|
||||
if(!fs)return;
|
||||
if(fs==default_source)return;
|
||||
|
||||
if(source_map.ValueExist(fs))
|
||||
{
|
||||
fs->RefRelease(this);
|
||||
source_map.DeleteByValue(fs);
|
||||
}
|
||||
}
|
||||
|
||||
FontBitmap *FontSourceMulti::GetCharBitmap(const u32char &ch)
|
||||
{
|
||||
if(hgl::isspace(ch))return(nullptr); //不能显示的数据或是空格
|
||||
|
||||
const auto count=source_map.GetCount();
|
||||
auto **fsp=source_map.GetDataList();
|
||||
|
||||
for(int i=0;i<count;i++)
|
||||
{
|
||||
if(IsInUnicodeBlock((*fsp)->left,ch))
|
||||
return (*fsp)->right->GetCharBitmap(ch);
|
||||
|
||||
++fsp;
|
||||
}
|
||||
|
||||
if(default_source)
|
||||
return default_source->GetCharBitmap(ch);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
33
src/SceneGraph/font/FontSourceSingle.cpp
Normal file
33
src/SceneGraph/font/FontSourceSingle.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include<hgl/graph/font/FontSource.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
FontBitmap *FontSourceSingle::GetCharBitmap(const u32char &ch)
|
||||
{
|
||||
if(hgl::isspace(ch))return(nullptr); //不能显示的数据或是空格
|
||||
|
||||
FontBitmap *bmp;
|
||||
|
||||
if(chars_bitmap.Get(ch,bmp))
|
||||
return bmp;
|
||||
|
||||
bmp=new FontBitmap;
|
||||
|
||||
memset(bmp,0,sizeof(FontBitmap));
|
||||
|
||||
if(!MakeCharBitmap(bmp,ch))
|
||||
{
|
||||
delete bmp;
|
||||
chars_bitmap.Add(ch,nullptr);
|
||||
return(nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
chars_bitmap.Add(ch,bmp);
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
@ -57,7 +57,7 @@ namespace hgl
|
||||
}
|
||||
}//namespace
|
||||
|
||||
WinBitmapFont::WinBitmapFont(const Font &f):FontSource(f)
|
||||
WinBitmapFont::WinBitmapFont(const Font &f):FontSourceSingle(f)
|
||||
{
|
||||
hdc=CreateCompatibleDC(0);
|
||||
|
||||
@ -103,13 +103,13 @@ namespace hgl
|
||||
if(ch>0xFFFF)
|
||||
return(false);
|
||||
|
||||
memset(&gm,0,sizeof(GLYPHMETRICS));
|
||||
memset(&mat,0,sizeof(MAT2));
|
||||
hgl_zero(gm);
|
||||
hgl_zero(mat);
|
||||
|
||||
mat.eM11.value = 1;
|
||||
mat.eM22.value = 1;
|
||||
|
||||
const int size=GetGlyphOutline(hdc,ch,ggo,&gm,0,0,&mat);
|
||||
const int size=GetGlyphOutlineW(hdc,ch,ggo,&gm,0,0,&mat);
|
||||
|
||||
if(size<=0)return(false);
|
||||
|
||||
@ -121,7 +121,7 @@ namespace hgl
|
||||
buffer=new uint8[buffer_size];
|
||||
}
|
||||
|
||||
GetGlyphOutline(hdc,ch,ggo,&gm,buffer_size,buffer,&mat);
|
||||
GetGlyphOutlineW(hdc,ch,ggo,&gm,buffer_size,buffer,&mat);
|
||||
|
||||
bmp->w=gm.gmBlackBoxX;
|
||||
bmp->h=gm.gmBlackBoxY;
|
||||
|
@ -8,7 +8,7 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class WinBitmapFont:public FontSource
|
||||
class WinBitmapFont:public FontSourceSingle
|
||||
{
|
||||
HDC hdc;
|
||||
HFONT hfont;
|
||||
@ -18,7 +18,7 @@ namespace hgl
|
||||
|
||||
uint ggo;
|
||||
|
||||
unsigned char *buffer;
|
||||
uint8 *buffer;
|
||||
int buffer_size;
|
||||
|
||||
protected:
|
||||
|
Loading…
x
Reference in New Issue
Block a user