add FontSourceManage,FontMultiSource,TileFont.cpp
This commit is contained in:
parent
592a9343f4
commit
c667e026ec
@ -1,16 +1,13 @@
|
||||
#ifndef HGL_GRAPH_FONT_MANAGE_INCLUDE
|
||||
#define HGL_GRAPH_FONT_MANAGE_INCLUDE
|
||||
|
||||
#include<hgl/graph/font/Font.h>
|
||||
#include<hgl/graph/font/FontSource.h>
|
||||
#include<hgl/graph/font/TileFont.h>
|
||||
#include<hgl/type/Map.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
struct FontConfig
|
||||
{
|
||||
};//
|
||||
|
||||
/**
|
||||
* 字体管理模块,包括所有的字体数据源,以及字符绘制器。<br>
|
||||
* 在可期的未来,我们会增加对字体、字符的使用情况统计信息
|
||||
@ -19,7 +16,7 @@ namespace hgl
|
||||
{
|
||||
MapObject<Font,FontSource> sources;
|
||||
|
||||
TileFont *
|
||||
MapObject<FontConfig,TileFont> tilefonts;
|
||||
};//class FontManage
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
26
inc/hgl/graph/font/FontMultiSource.h
Normal file
26
inc/hgl/graph/font/FontMultiSource.h
Normal file
@ -0,0 +1,26 @@
|
||||
#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
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include<hgl/type/StrChar.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/Set.h>
|
||||
#include<hgl/graph/font/Font.h>
|
||||
|
||||
using namespace hgl;
|
||||
@ -37,6 +38,8 @@ namespace hgl
|
||||
|
||||
MapObject<u32char,FontBitmap> chars_bitmap; ///<字符位图
|
||||
|
||||
Set<void *> ref_object;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool MakeCharBitmap(FontBitmap *,u32char)=0; ///<产生字体数据
|
||||
@ -48,6 +51,10 @@ namespace hgl
|
||||
virtual ~FontSource()=default;
|
||||
|
||||
FontBitmap *GetCharBitmap(const u32char &); ///<取得字符位图数据
|
||||
|
||||
void RefAcquire(void *); ///<引用请求
|
||||
void RefRelease(void *); ///<引用释放
|
||||
int RefCount()const{return ref_object.GetCount();} ///<获取引用对象数量
|
||||
};//class FontSource
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@ -15,22 +15,14 @@ namespace hgl
|
||||
*/
|
||||
class TileFont
|
||||
{
|
||||
using FontSourcePointer=FontSource *;
|
||||
using FontSourceTable=FontSourcePointer[(size_t)UnicodeBlock::RANGE_SIZE];
|
||||
|
||||
FontSourceTable source_map;
|
||||
|
||||
TileData *tile_data;
|
||||
|
||||
public:
|
||||
|
||||
TileFont()
|
||||
{
|
||||
hgl_zero(source_map);
|
||||
}
|
||||
TileFont(TileData *td,FontSource *fs);
|
||||
virtual ~TileFont();
|
||||
};//class TileFont
|
||||
|
||||
TileFont *CreateTileFont(const Font &,const int=-1);
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_TILE_FONT_INCLUDE
|
||||
|
@ -32,5 +32,21 @@ namespace hgl
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
|
||||
void FontSource::RefAcquire(void *ptr)
|
||||
{
|
||||
if(!ptr)return;
|
||||
|
||||
ref_object.Add(ptr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void FontSource::RefRelease(void *ptr)
|
||||
{
|
||||
if(!ptr)return;
|
||||
|
||||
ref_object.Delete(ptr);
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
24
src/SceneGraph/font/FontSourceManage.cpp
Normal file
24
src/SceneGraph/font/FontSourceManage.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include<hgl/graph/font/FontSource.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
FontSource *CreateFontSource(const Font &f); //各平台独立提供
|
||||
|
||||
static MapObject<Font,FontSource> FontStorage;
|
||||
|
||||
FontSource *AcquireFontSource(const Font &f)
|
||||
{
|
||||
FontSource *source;
|
||||
|
||||
if(!FontStorage.Get(f,source))
|
||||
{
|
||||
source=CreateFontSource(f);
|
||||
|
||||
FontStorage.Add(f,source);
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
@ -57,11 +57,6 @@ namespace hgl
|
||||
}
|
||||
}//namespace
|
||||
|
||||
FontSource *CreateWinBitmapFont(const Font &f)
|
||||
{
|
||||
return(new WinBitmapFont(f));
|
||||
}
|
||||
|
||||
WinBitmapFont::WinBitmapFont(const Font &f):FontSource(f)
|
||||
{
|
||||
hdc=CreateCompatibleDC(0);
|
||||
@ -146,5 +141,10 @@ namespace hgl
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
FontSource *CreateFontSource(const Font &f)
|
||||
{
|
||||
return(new WinBitmapFont(f));
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
65
src/SceneGraph/font/TileFont.cpp
Normal file
65
src/SceneGraph/font/TileFont.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
#include<hgl/graph/font/TileFont.h>
|
||||
#include<hgl/graph/vulkan/VKDevice.h>
|
||||
#include<hgl/graph/vulkan/VKFormat.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
FontSource *AcquireFontSource(const Font &f);
|
||||
|
||||
TileFont::TileFont(TileData *td,FontSource *fs)
|
||||
{
|
||||
hgl_zero(source_map);
|
||||
tile_data=td;
|
||||
|
||||
for(uint i=0;i<(uint)UnicodeBlock::RANGE_SIZE;i++)
|
||||
source_map[i]=fs;
|
||||
|
||||
fs->RefAcquire(this);
|
||||
}
|
||||
|
||||
TileFont::~TileFont()
|
||||
{
|
||||
for(uint i=0;i<(uint)UnicodeBlock::RANGE_SIZE;i++)
|
||||
{
|
||||
if(source_map[i])
|
||||
source_map[i]->RefRelease(this);
|
||||
}
|
||||
|
||||
SAFE_CLEAR(tile_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建只使用一种字符的Tile字符管理对象
|
||||
* @param f 字体需求信息
|
||||
* @param limit_count 缓冲字符数量上限
|
||||
*/
|
||||
TileFont *CreateTileFont(VK_NAMESPACE::Device *device,const Font &f,int limit_count=-1)
|
||||
{
|
||||
int height=(f.height+3)>>2;
|
||||
|
||||
height<<=2; //保证可以被4整除
|
||||
height+=2; //上下左右各空一个象素
|
||||
|
||||
if(limit_count<=0)
|
||||
{
|
||||
const VkExtent2D &ext=device->GetSwapchainSize();
|
||||
|
||||
limit_count=(ext.width/height)*(ext.height/height); //按全屏幕放满不一样的字符为上限
|
||||
}
|
||||
|
||||
FontSource *fs=AcquireFontSource(f);
|
||||
|
||||
if(!fs)
|
||||
return(nullptr);
|
||||
|
||||
TileData *td=device->CreateTileData(UFMT_R8,height,height,limit_count);
|
||||
|
||||
if(!td)
|
||||
return nullptr;
|
||||
|
||||
return(new TileFont(td,fs));
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
Loading…
x
Reference in New Issue
Block a user