add Font/FontBitmapCache

This commit is contained in:
hyzboy 2020-06-28 22:16:07 +08:00
parent 61648f6dcb
commit 18f68df9be
8 changed files with 213 additions and 3 deletions

2
CMCore

@ -1 +1 @@
Subproject commit b078d6cbdc95da29bdb068e5079e77bfd3745a89
Subproject commit bb66ce1f5a4b1f9dcbe61758813ffdd34ae7c1e3

View File

@ -21,7 +21,10 @@ CreateProject(08.SceneTree SceneTree.cpp)
CreateProject(09.LoadStaticMesh LoadStaticMesh.cpp LoadScene.cpp)
CreateProject(10.InlineGeometryScene InlineGeometryScene.cpp)
CreateProject(11.Atomsphere Atomsphere.cpp)
CreateProject(12.DrawText DrawText.cpp)
#CreateProject(12.PBRBasic PBRBasic.cpp)
#CreateProject(12.Deferred Deferred.cpp)
CreateProject(13.DeferredModel DeferredModel.cpp)
#CreateProject(13.DeferredModel DeferredModel.cpp)
#CreateProject(14.AutoMaterial auto_material.cpp)

View File

@ -0,0 +1,47 @@
#include<hgl/type/StrChar.h>
#include<hgl/type/Map.h>
#include<hgl/graph/font/Font.h>
using namespace hgl;
namespace hgl
{
namespace graph
{
/**
*
*/
class FontBitmapCache
{
/**
*
*/
struct Bitmap
{
int count; //使用次数
int x,y; //图像显示偏移
int w,h; //图像尺寸
int adv_x,adv_y;//字符尺寸
uint8 *data;
};//struct Bitmap
protected:
MapObject<u32char,FontBitmapCache::Bitmap *> chars_bitmap; ///<字符位图
protected:
virtual bool MakeCharBitmap(u32char)=0; ///<产生字体数据
virtual int GetLineHeight()const=0; ///<取得行高
public:
FontBitmapCache(const Font &);
FontBitmapCache::Bitmap *GetCharBitmap(const u32char); ///<取得字符位图数据
};//class FontBitmapCache
}//namespace graph
}//namespace hgl

35
inc/hgl/graph/font/Font.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef HGL_GRAPH_FONT_INCLUDE
#define HGL_GRAPH_FONT_INCLUDE
#include<hgl/CompOperator.h>
#include<string.h>
namespace hgl
{
namespace graph
{
/**
*
*/
struct Font
{
char name[128]; ///<字体名称(utf8)
int width; ///<宽度
int height; ///<高度
bool bold; ///<加粗
bool italic; ///<右斜
bool anti; ///<反矩齿
public:
Font();
Font(const char *,int,int,bool,bool,bool=true);
CompOperatorMemcmp(const Font &); ///<比较操作符重载
};//struct Font
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_FONT_INCLUDE

View File

@ -0,0 +1,54 @@
#ifndef HGL_GRAPH_FONT_BITMAP_CACHE_INCLUDE
#define HGL_GRAPH_FONT_BITMAP_CACHE_INCLUDE
#include<hgl/type/StrChar.h>
#include<hgl/type/Map.h>
#include<hgl/graph/font/Font.h>
using namespace hgl;
namespace hgl
{
namespace graph
{
/**
*
*/
class FontBitmapCache
{
/**
*
*/
struct Bitmap
{
int count; //使用次数
int x,y; //图像显示偏移
int w,h; //图像尺寸
int adv_x,adv_y;//字符尺寸
uint8 *data;
};//struct Bitmap
protected:
Font fnt;
MapObject<u32char,FontBitmapCache::Bitmap> chars_bitmap; ///<字符位图
protected:
virtual bool MakeCharBitmap(FontBitmapCache::Bitmap *,u32char)=0; ///<产生字体数据
virtual int GetLineHeight()const=0; ///<取得行高
public:
FontBitmapCache(const Font &f){fnt=f;}
virtual ~FontBitmapCache()=default;
FontBitmapCache::Bitmap *GetCharBitmap(const u32char &); ///<取得字符位图数据
};//class FontBitmapCache
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_FONT_BITMAP_CACHE_INCLUDE

View File

@ -42,6 +42,11 @@ SET(SCENE_GRAPH_SOURCE RenderList.cpp
#SceneFile.cpp
)
file(GLOB FONT_HEADER ${ROOT_INCLUDE_PATH}/hgl/graph/font/*.*)
file(GLOB FONT_SOURCE font/*.*)
SOURCE_GROUP("Font" FILES ${FONT_HEADER} ${FONT_SOURCE})
SOURCE_GROUP("Header Files" FILES ${SCENE_GRAPH_HEADER})
SOURCE_GROUP("Source Files" FILES ${SCENE_GRAPH_SOURCE})
@ -53,4 +58,7 @@ add_cm_library(ULRE.SceneGraph "ULRE" ${SCENE_GRAPH_HEADER}
${SG_MATERIAL_HEADER}
${SG_MATERIAL_SOURCE}
${SG_VERTEX_SOURCE})
${SG_VERTEX_SOURCE}
${FONT_HEADER}
${FONT_SOURCE})

View File

@ -0,0 +1,27 @@
#include<hgl/graph/font/Font.h>
namespace hgl
{
namespace graph
{
Font::Font()
{
memset(this,0,sizeof(Font));
}
Font::Font(const char *n,int w,int h,bool b,bool i,bool aa)
{
memset(this,0,sizeof(Font));
strcpy(name,n);
width=w;
height=h;
bold=b;
italic=i;
anti=aa;
}
}//namespace graph
}//namespace hgl

View File

@ -0,0 +1,36 @@
#include<hgl/graph/font/FontBitmapCache.h>
namespace hgl
{
namespace graph
{
FontBitmapCache::Bitmap *FontBitmapCache::GetCharBitmap(const u32char &ch)
{
if(!this)
return(nullptr);
if(hgl::isspace(ch))return(nullptr); //不能显示的数据或是空格
FontBitmapCache::Bitmap *bmp;
if(chars_bitmap.Get(ch,bmp))
return bmp;
bmp=new FontBitmapCache::Bitmap;
memset(bmp,0,sizeof(FontBitmapCache::Bitmap));
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