fix draw text example.
This commit is contained in:
parent
346d8b3279
commit
cea2f8da9e
2
CMCore
2
CMCore
@ -1 +1 @@
|
|||||||
Subproject commit 2d6883be633abae7f0f10810e2b61367175bcfc4
|
Subproject commit c2c7c42cd43759a9a613b6ad2c890a2e1d948b37
|
@ -1,4 +1,4 @@
|
|||||||
// DrawTile
|
// DrawTile
|
||||||
// 该示例使用TileData,演示多个tile图片在一张纹理上
|
// 该示例使用TileData,演示多个tile图片在一张纹理上
|
||||||
|
|
||||||
#include<hgl/type/StringList.h>
|
#include<hgl/type/StringList.h>
|
||||||
@ -15,13 +15,6 @@
|
|||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
using namespace hgl::graph;
|
using namespace hgl::graph;
|
||||||
|
|
||||||
/**
|
|
||||||
* 文本绘制技术流程:
|
|
||||||
*
|
|
||||||
* 1.由TextLayout模块排版所有的字符,并向FontSource获取所有字符的Bitmap。生成文本可渲染对象的vertex position数据
|
|
||||||
* 2.由TextLayout向TileData提交需要渲染的所有字符的Bitmap,并得到每个Bitmap对应的UV数据。生成文本可渲染对象的uv数据
|
|
||||||
*/
|
|
||||||
|
|
||||||
constexpr uint32_t SCREEN_WIDTH =1280;
|
constexpr uint32_t SCREEN_WIDTH =1280;
|
||||||
constexpr uint32_t SCREEN_HEIGHT=960;
|
constexpr uint32_t SCREEN_HEIGHT=960;
|
||||||
|
|
||||||
@ -32,6 +25,8 @@ class TestApp:public VulkanApplicationFramework
|
|||||||
{
|
{
|
||||||
Camera cam;
|
Camera cam;
|
||||||
|
|
||||||
|
Color4f color;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
vulkan::Material * material =nullptr;
|
vulkan::Material * material =nullptr;
|
||||||
@ -39,6 +34,7 @@ private:
|
|||||||
vulkan::MaterialInstance * material_instance =nullptr;
|
vulkan::MaterialInstance * material_instance =nullptr;
|
||||||
vulkan::Renderable * render_obj =nullptr;
|
vulkan::Renderable * render_obj =nullptr;
|
||||||
vulkan::Buffer * ubo_world_matrix =nullptr;
|
vulkan::Buffer * ubo_world_matrix =nullptr;
|
||||||
|
vulkan::Buffer * ubo_color =nullptr;
|
||||||
|
|
||||||
vulkan::Pipeline * pipeline =nullptr;
|
vulkan::Pipeline * pipeline =nullptr;
|
||||||
|
|
||||||
@ -71,7 +67,7 @@ private:
|
|||||||
{
|
{
|
||||||
material=shader_manage->CreateMaterial( OS_TEXT("res/shader/DrawRect2D.vert"),
|
material=shader_manage->CreateMaterial( OS_TEXT("res/shader/DrawRect2D.vert"),
|
||||||
OS_TEXT("res/shader/DrawRect2D.geom"),
|
OS_TEXT("res/shader/DrawRect2D.geom"),
|
||||||
OS_TEXT("res/shader/FlatTexture.frag"));
|
OS_TEXT("res/shader/FlatLumTexture.frag"));
|
||||||
if(!material)
|
if(!material)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
@ -81,6 +77,7 @@ private:
|
|||||||
|
|
||||||
material_instance->BindSampler("tex",tile_font->GetTexture(),sampler);
|
material_instance->BindSampler("tex",tile_font->GetTexture(),sampler);
|
||||||
material_instance->BindUBO("world",ubo_world_matrix);
|
material_instance->BindUBO("world",ubo_world_matrix);
|
||||||
|
material_instance->BindUBO("color_material",ubo_color);
|
||||||
material_instance->Update();
|
material_instance->Update();
|
||||||
|
|
||||||
db->Add(material);
|
db->Add(material);
|
||||||
@ -102,6 +99,13 @@ private:
|
|||||||
if(!ubo_world_matrix)
|
if(!ubo_world_matrix)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
|
color.One();
|
||||||
|
|
||||||
|
ubo_color=db->CreateUBO(sizeof(Color4f),&color);
|
||||||
|
|
||||||
|
if(!ubo_color)
|
||||||
|
return(false);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,6 +134,7 @@ private:
|
|||||||
|
|
||||||
text_rc=new RenderableCreater(db,material);
|
text_rc=new RenderableCreater(db,material);
|
||||||
|
|
||||||
|
tl_engine.Set(tile_font->GetFontSource());
|
||||||
tl_engine.Set(text_rc);
|
tl_engine.Set(text_rc);
|
||||||
tl_engine.Set(&tla);
|
tl_engine.Set(&tla);
|
||||||
tl_engine.SetTextDirection(0);
|
tl_engine.SetTextDirection(0);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// DrawTile
|
// DrawTile
|
||||||
// 该示例使用TileData,演示多个tile图片在一张纹理上
|
// 该示例使用TileData,演示多个tile图片在一张纹理上
|
||||||
|
|
||||||
#include<hgl/type/StringList.h>
|
#include<hgl/type/StringList.h>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// 2.RectanglePrimivate
|
// 2.RectanglePrimivate
|
||||||
// 该示例是texture_rect的进化,演示使用GeometryShader画矩形
|
// 该示例是texture_rect的进化,演示使用GeometryShader画矩形
|
||||||
|
|
||||||
#include"VulkanAppFramework.h"
|
#include"VulkanAppFramework.h"
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include<hgl/graph/SceneDB.h>
|
#include<hgl/graph/SceneDB.h>
|
||||||
#include<hgl/graph/VertexAttribDataAccess.h>
|
#include<hgl/graph/VertexAttribDataAccess.h>
|
||||||
|
#include<hgl/graph/vulkan/VKShaderModule.h>
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
|
@ -79,7 +79,7 @@ namespace hgl
|
|||||||
virtual ~FontSource()=default;
|
virtual ~FontSource()=default;
|
||||||
|
|
||||||
virtual FontBitmap *GetCharBitmap (const u32char &)=0; ///<取得字符位图数据
|
virtual FontBitmap *GetCharBitmap (const u32char &)=0; ///<取得字符位图数据
|
||||||
virtual const bool GetCharMetrics (CharMetricsInfo &,const u32char &); ///<取得字符绘制信息
|
virtual const bool GetCharMetrics (CharMetricsInfo &,const u32char &)=0; ///<取得字符绘制信息
|
||||||
const CLA * GetCLA (const u32char &); ///<取得字符排版信息
|
const CLA * GetCLA (const u32char &); ///<取得字符排版信息
|
||||||
virtual int GetCharHeight ()const=0; ///<取得字符高度
|
virtual int GetCharHeight ()const=0; ///<取得字符高度
|
||||||
|
|
||||||
@ -109,11 +109,11 @@ namespace hgl
|
|||||||
virtual ~FontSourceSingle()=default;
|
virtual ~FontSourceSingle()=default;
|
||||||
|
|
||||||
FontBitmap *GetCharBitmap (const u32char &ch) override; ///<取得字符位图数据
|
FontBitmap *GetCharBitmap (const u32char &ch) override; ///<取得字符位图数据
|
||||||
const bool GetCharMetrics (CharMetricsInfo &,const u32char &); ///<取得字符绘制信息
|
const bool GetCharMetrics (CharMetricsInfo &,const u32char &)override;///<取得字符绘制信息
|
||||||
virtual int GetCharHeight ()const override{return fnt.height;} ///<取得字符高度
|
virtual int GetCharHeight ()const override{return fnt.height;} ///<取得字符高度
|
||||||
};//class FontSourceSingle:public FontSource
|
};//class FontSourceSingle:public FontSource
|
||||||
|
|
||||||
FontSourceSingle *CreateFontSource(const Font &f);
|
FontSource *CreateFontSource(const Font &f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文字位图多重数据源
|
* 文字位图多重数据源
|
||||||
@ -148,7 +148,7 @@ namespace hgl
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
FontBitmap *GetCharBitmap (const u32char &ch) override;
|
FontBitmap *GetCharBitmap (const u32char &ch) override;
|
||||||
const bool GetCharMetrics (CharMetricsInfo &,const u32char &); ///<取得字符绘制信息
|
const bool GetCharMetrics (CharMetricsInfo &,const u32char &)override; ///<取得字符绘制信息
|
||||||
int GetCharHeight ()const override; ///<取得字符高度
|
int GetCharHeight ()const override; ///<取得字符高度
|
||||||
};//class FontSourceMulti:public FontSource
|
};//class FontSourceMulti:public FontSource
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
|
@ -85,6 +85,7 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
FontSource *font_source;
|
||||||
RenderableCreater *rc;
|
RenderableCreater *rc;
|
||||||
TextLayoutAttributes tla;
|
TextLayoutAttributes tla;
|
||||||
|
|
||||||
@ -102,13 +103,13 @@ namespace hgl
|
|||||||
|
|
||||||
struct CharDrawAttr
|
struct CharDrawAttr
|
||||||
{
|
{
|
||||||
CLA *cla;
|
const CLA *cla;
|
||||||
TileUVFloat uv;
|
TileUVFloat uv;
|
||||||
};
|
};
|
||||||
|
|
||||||
ObjectList<CharDrawAttr> draw_chars_list; ///<所有字符属性列表
|
ObjectList<CharDrawAttr> draw_chars_list; ///<所有字符属性列表
|
||||||
|
|
||||||
template<typename T> int preprocess(const T *,const int);
|
template<typename T> bool preprocess(TileFont *,const T *,const int);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -120,6 +121,9 @@ namespace hgl
|
|||||||
int sl_v_r2l();
|
int sl_v_r2l();
|
||||||
int sl_v_l2r();
|
int sl_v_l2r();
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
int SimpleLayout (TileFont *,const BaseString<T> &); ///<简易排版
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
TEXT_COORD_TYPE x,y;
|
TEXT_COORD_TYPE x,y;
|
||||||
@ -134,8 +138,8 @@ namespace hgl
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
AutoDelete<VB4f> vertex,
|
VB4f *vertex;
|
||||||
tex_coord;
|
VB4f *tex_coord;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -154,7 +158,7 @@ namespace hgl
|
|||||||
|
|
||||||
void Set (RenderableCreater *_rc) {if(_rc)rc=_rc;}
|
void Set (RenderableCreater *_rc) {if(_rc)rc=_rc;}
|
||||||
void Set (const TextLayoutAttributes *_tla) {if(_tla)memcpy(&tla,_tla,sizeof(TextLayoutAttributes));}
|
void Set (const TextLayoutAttributes *_tla) {if(_tla)memcpy(&tla,_tla,sizeof(TextLayoutAttributes));}
|
||||||
void Set (FontSource *fs) {if(fs)tla.font_source=fs;}
|
void Set (FontSource *fs) {if(fs)font_source=fs;}
|
||||||
void SetTextDirection (const uint8 &td) {tla.text_direction=td;}
|
void SetTextDirection (const uint8 &td) {tla.text_direction=td;}
|
||||||
void Set (const TextAlign &ta) {tla.align=ta;}
|
void Set (const TextAlign &ta) {tla.align=ta;}
|
||||||
void SetMaxWidth (const float mw) {tla.max_width=mw;}
|
void SetMaxWidth (const float mw) {tla.max_width=mw;}
|
||||||
@ -162,10 +166,8 @@ namespace hgl
|
|||||||
|
|
||||||
virtual bool Init (); ///<初始化排版
|
virtual bool Init (); ///<初始化排版
|
||||||
|
|
||||||
// virtual int Layout (const int max_chars,const BaseString<T> &)=0; ///<排版
|
int SimpleLayout (TileFont *,const UTF16String &); ///<简易排版
|
||||||
|
int SimpleLayout (TileFont *,const UTF32String &); ///<简易排版
|
||||||
template<typename T>
|
|
||||||
int SimpleLayout (TileFont *,const BaseString<T> &); ///<简易排版
|
|
||||||
};//class TextLayout
|
};//class TextLayout
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
@ -72,8 +72,8 @@ public:
|
|||||||
* 获取输入流绑定点,需要注意的时,这里获取的binding并非是shader中的binding/location,而是绑定顺序的序列号。对应vkCmdBindVertexBuffer的缓冲区序列号
|
* 获取输入流绑定点,需要注意的时,这里获取的binding并非是shader中的binding/location,而是绑定顺序的序列号。对应vkCmdBindVertexBuffer的缓冲区序列号
|
||||||
*/
|
*/
|
||||||
const int GetStageInputBinding(const AnsiString &name)const{return shader_resource->GetStageInputBinding(name);}
|
const int GetStageInputBinding(const AnsiString &name)const{return shader_resource->GetStageInputBinding(name);}
|
||||||
const ShaderStage * GetStageInput(const AnsiString &name)const{return shader_resource->GetStageInput(name);}
|
const ShaderStage * GetStageInput (const AnsiString &name)const{return shader_resource->GetStageInput(name);}
|
||||||
const uint GetStageInputCount()const{return shader_resource->GetStageInputCount();}
|
const uint GetStageInputCount () const{return shader_resource->GetStageInputCount();}
|
||||||
|
|
||||||
const uint32_t GetAttrCount()const{return attr_count;}
|
const uint32_t GetAttrCount()const{return attr_count;}
|
||||||
|
|
||||||
|
@ -426,7 +426,7 @@ Device *CreateRenderDevice(VkInstance inst,const PhysicalDevice *physical_device
|
|||||||
if(!device_attr->pipeline_cache)
|
if(!device_attr->pipeline_cache)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
auto_delete.Clear();
|
auto_delete.Discard();
|
||||||
|
|
||||||
return(new Device(device_attr));
|
return(new Device(device_attr));
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include<hgl/graph/font/TileFont.h>
|
#include<hgl/graph/font/TileFont.h>
|
||||||
#include<hgl/graph/vulkan/VKDevice.h>
|
#include<hgl/graph/vulkan/VKDevice.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include<hgl/graph/font/FontSource.h>
|
#include<hgl/graph/font/FontSource.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
|
@ -6,43 +6,48 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
void Convert8BitGrey(uint8 *dst,uint8 *src,int w,int h,int line_bytes)
|
void Convert8BitGrey(uint8 *dst,int dst_w,uint8 *src,int src_w,int src_h,int src_line_bytes)
|
||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
uint8 *sp=src,*p;
|
uint8 *sp=src,*p;
|
||||||
|
uint8 *tp;
|
||||||
|
|
||||||
while(h--)
|
while(src_h--)
|
||||||
{
|
{
|
||||||
pos=w;
|
pos=src_w;
|
||||||
p=sp;
|
p=sp;
|
||||||
|
tp=dst;
|
||||||
|
|
||||||
while(pos--)
|
while(pos--)
|
||||||
{
|
{
|
||||||
if(*p==64)*dst=255;
|
if(*p==64)*tp=255;
|
||||||
else *dst=(*p)<<2;
|
else *tp=(*p)<<2;
|
||||||
|
|
||||||
dst++;
|
tp++;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
sp+=line_bytes;
|
sp+=src_line_bytes;
|
||||||
|
dst+=dst_w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConvertBitmap(uint8 *dst,uint8 *src,int w,int h,int line_bytes)
|
void ConvertBitmap(uint8 *dst,int dst_w,uint8 *src,int src_w,int src_h,int src_line_bytes)
|
||||||
{
|
{
|
||||||
uint8 *sp=src,*p;
|
uint8 *sp=src,*p;
|
||||||
|
uint8 *tp;
|
||||||
uint8 bit;
|
uint8 bit;
|
||||||
|
|
||||||
while(h--)
|
while(src_h--)
|
||||||
{
|
{
|
||||||
p=sp;
|
p=sp;
|
||||||
|
tp=dst;
|
||||||
|
|
||||||
bit=1<<7;
|
bit=1<<7;
|
||||||
|
|
||||||
for(int i=0;i<w;i++)
|
for(int i=0;i<src_w;i++)
|
||||||
{
|
{
|
||||||
*dst++=(*p&bit)?255:0;
|
*tp++=(*p&bit)?255:0;
|
||||||
|
|
||||||
if(bit==0x01)
|
if(bit==0x01)
|
||||||
{
|
{
|
||||||
@ -52,7 +57,8 @@ namespace hgl
|
|||||||
else bit>>=1;
|
else bit>>=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sp+=line_bytes;
|
sp+=src_line_bytes;
|
||||||
|
dst+=dst_w;
|
||||||
}//while(h--)
|
}//while(h--)
|
||||||
}
|
}
|
||||||
}//namespace
|
}//namespace
|
||||||
@ -120,8 +126,8 @@ namespace hgl
|
|||||||
|
|
||||||
GetGlyphOutlineW(hdc,ch,ggo,&gm,buffer_size,buffer,&mat);
|
GetGlyphOutlineW(hdc,ch,ggo,&gm,buffer_size,buffer,&mat);
|
||||||
|
|
||||||
bmp->metrics_info.w =gm.gmBlackBoxX;
|
bmp->metrics_info.w =((gm.gmBlackBoxX+3)>>2)<<2;
|
||||||
bmp->metrics_info.h =gm.gmBlackBoxY;
|
bmp->metrics_info.h =((gm.gmBlackBoxY+3)>>2)<<2;
|
||||||
|
|
||||||
bmp->metrics_info.x =gm.gmptGlyphOrigin.x;
|
bmp->metrics_info.x =gm.gmptGlyphOrigin.x;
|
||||||
bmp->metrics_info.y =gm.gmptGlyphOrigin.y;
|
bmp->metrics_info.y =gm.gmptGlyphOrigin.y;
|
||||||
@ -132,14 +138,14 @@ namespace hgl
|
|||||||
bmp->data=new uint8[bmp->metrics_info.w*bmp->metrics_info.h];
|
bmp->data=new uint8[bmp->metrics_info.w*bmp->metrics_info.h];
|
||||||
|
|
||||||
if(ggo==GGO_GRAY8_BITMAP)
|
if(ggo==GGO_GRAY8_BITMAP)
|
||||||
Convert8BitGrey(bmp->data,buffer,gm.gmBlackBoxX,gm.gmBlackBoxY,size/bmp->metrics_info.h);
|
Convert8BitGrey(bmp->data,bmp->metrics_info.w,buffer,gm.gmBlackBoxX,gm.gmBlackBoxY,size/gm.gmBlackBoxY);
|
||||||
else
|
else
|
||||||
ConvertBitmap(bmp->data,buffer,gm.gmBlackBoxX,gm.gmBlackBoxY,size/bmp->metrics_info.h);
|
ConvertBitmap(bmp->data,bmp->metrics_info.w,buffer,gm.gmBlackBoxX,gm.gmBlackBoxY,size/gm.gmBlackBoxY);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
FontSourceSingle *CreateFontSource(const Font &f)
|
FontSource *CreateFontSource(const Font &f)
|
||||||
{
|
{
|
||||||
return(new WinBitmapFont(f));
|
return(new WinBitmapFont(f));
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include<hgl/graph/font/TextLayout.h>
|
#include<hgl/graph/font/TextLayout.h>
|
||||||
|
#include<hgl/graph/font/TileFont.h>
|
||||||
#include<hgl/type/Extent.h>
|
#include<hgl/type/Extent.h>
|
||||||
#include<hgl/type/UnicodeBlocks.h>
|
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
@ -9,8 +9,8 @@ namespace hgl
|
|||||||
bool TextLayout::Init()
|
bool TextLayout::Init()
|
||||||
{
|
{
|
||||||
if(!rc
|
if(!rc
|
||||||
||!tla.font_source
|
||(!tla.font_source&&!font_source)
|
||||||
||!tla.char_attributes)
|
||!tla.char_layout_attr)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
direction.text_direction=tla.text_direction;
|
direction.text_direction=tla.text_direction;
|
||||||
@ -26,7 +26,10 @@ namespace hgl
|
|||||||
splite_line_max_limit = tla.max_height;
|
splite_line_max_limit = tla.max_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float origin_char_height=tla.font_source->GetCharHeight();
|
if(!font_source)
|
||||||
|
font_source=tla.font_source;
|
||||||
|
|
||||||
|
const float origin_char_height=font_source->GetCharHeight();
|
||||||
|
|
||||||
x=y=0;
|
x=y=0;
|
||||||
char_height =ceil(origin_char_height);
|
char_height =ceil(origin_char_height);
|
||||||
@ -45,36 +48,42 @@ namespace hgl
|
|||||||
* 预处理所有的字符,获取所有字符的宽高,以及是否标点符号等信息
|
* 预处理所有的字符,获取所有字符的宽高,以及是否标点符号等信息
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int TextLayout::preprocess(const T *str,const int str_length)
|
bool TextLayout::preprocess(TileFont *tile_font,const T *str,const int str_length)
|
||||||
{
|
{
|
||||||
if(!str||!*str||str_length<=0)
|
if(!tile_font
|
||||||
return 0;
|
||!str||!*str||str_length<=0
|
||||||
|
||!font_source)
|
||||||
|
return(false);
|
||||||
|
|
||||||
draw_chars_count=0;
|
//遍历所有字符,取得每一个字符的基本绘制信息
|
||||||
alone_chars.ClearData();
|
|
||||||
|
|
||||||
draw_chars_list.ClearData();
|
|
||||||
draw_chars_list.SetCount(str_length);
|
|
||||||
|
|
||||||
CharDrawAttr **cda=draw_chars_list.GetData();
|
|
||||||
const T *cp=str;
|
|
||||||
|
|
||||||
for(int i=0;i<count;i++)
|
|
||||||
{
|
{
|
||||||
(*cda)->cla=tla->font_source.GetCLA(*cp);
|
draw_chars_count=0;
|
||||||
|
alone_chars.ClearData();
|
||||||
|
draw_chars_list.ClearData();
|
||||||
|
|
||||||
if((*cda)->cla->visible)
|
const T *cp=str;
|
||||||
|
CharDrawAttr *cda;
|
||||||
|
|
||||||
|
for(int i=0;i<str_length;i++)
|
||||||
{
|
{
|
||||||
alone_chars.Add(*cp); //统计所有不重复字符
|
cda=new CharDrawAttr;
|
||||||
++draw_chars_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
++cp;
|
cda->cla=font_source->GetCLA(*cp);
|
||||||
++cda;
|
|
||||||
|
if(cda->cla->visible)
|
||||||
|
{
|
||||||
|
alone_chars.Add(*cp); //统计所有不重复字符
|
||||||
|
++draw_chars_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_chars_list.Add(cda);
|
||||||
|
|
||||||
|
++cp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//注册不重复字符给tile font系统,获取所有字符的UV
|
//注册不重复字符给tile font系统,获取所有字符的UV
|
||||||
if(!tf->Registry(alone_chars_uv,alone_chars.GetData(),alone_chars.GetCount()))
|
if(!tile_font->Registry(alone_chars_uv,alone_chars.GetData(),alone_chars.GetCount()))
|
||||||
{
|
{
|
||||||
draw_chars_list.ClearData();
|
draw_chars_list.ClearData();
|
||||||
alone_chars.ClearData();
|
alone_chars.ClearData();
|
||||||
@ -83,15 +92,18 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
//为可绘制字符列表中的字符获取UV
|
//为可绘制字符列表中的字符获取UV
|
||||||
cda=draw_chars_list.GetData();
|
|
||||||
for(int i=0;i<count;i++)
|
|
||||||
{
|
{
|
||||||
alone_chars_uv.Get((*cda)->cla->ch,(*cda)->uv);
|
CharDrawAttr **cda=draw_chars_list.GetData();
|
||||||
|
|
||||||
++cda;
|
for(int i=0;i<str_length;i++)
|
||||||
|
{
|
||||||
|
alone_chars_uv.Get((*cda)->cla->ch,(*cda)->uv);
|
||||||
|
|
||||||
|
++cda;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,8 +173,8 @@ namespace hgl
|
|||||||
int cur_size=0;
|
int cur_size=0;
|
||||||
int left=0,top=0;
|
int left=0,top=0;
|
||||||
|
|
||||||
float *tp=vertex->Begin();
|
float *tp=vertex->Get();
|
||||||
float *tcp=tex_coord->Begin();
|
float *tcp=tex_coord->Get();
|
||||||
|
|
||||||
for(int i=0;i<count;i++)
|
for(int i=0;i<count;i++)
|
||||||
{
|
{
|
||||||
@ -204,14 +216,14 @@ namespace hgl
|
|||||||
if(!tf||str.IsEmpty())
|
if(!tf||str.IsEmpty())
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
||||||
if(preprocess<T>(str.c_str(),str.Length())<=0)
|
if(!preprocess<T>(tf,str.c_str(),str.Length()))
|
||||||
return(-3);
|
return(-2);
|
||||||
|
|
||||||
if(draw_chars_count<=0) //可绘制字符为0???这是全空格?
|
if(draw_chars_count<=0) //可绘制字符为0???这是全空格?
|
||||||
return(-4);
|
return(-3);
|
||||||
|
|
||||||
if(!rc->Init(draw_chars_count)) //创建
|
if(!rc->Init(draw_chars_count)) //创建
|
||||||
return(-5);
|
return(-4);
|
||||||
|
|
||||||
vertex =rc->CreateVADA<VB4f>(VAN::Vertex);
|
vertex =rc->CreateVADA<VB4f>(VAN::Vertex);
|
||||||
tex_coord =rc->CreateVADA<VB4f>(VAN::TexCoord);
|
tex_coord =rc->CreateVADA<VB4f>(VAN::TexCoord);
|
||||||
@ -222,19 +234,22 @@ namespace hgl
|
|||||||
if(direction.vertical)
|
if(direction.vertical)
|
||||||
{
|
{
|
||||||
if(direction.right_to_left)
|
if(direction.right_to_left)
|
||||||
return pl_v_r2l();
|
return sl_v_r2l();
|
||||||
else
|
else
|
||||||
return pl_v_l2r();
|
return sl_v_l2r();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(direction.right_to_left)
|
if(direction.right_to_left)
|
||||||
return pl_h_r2l();
|
return sl_h_r2l();
|
||||||
else
|
else
|
||||||
return pl_h_l2r();
|
return sl_h_l2r();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TextLayout::SimpleLayout(TileFont *tf,const UTF16String &str){return this->SimpleLayout<u16char>(tf,str);}
|
||||||
|
int TextLayout::SimpleLayout(TileFont *tf,const UTF32String &str){return this->SimpleLayout<u32char>(tf,str);}
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user