update TextLayout

This commit is contained in:
hyzboy 2020-07-22 20:50:13 +08:00
parent 02d2842a2e
commit 3119c1367d
8 changed files with 133 additions and 48 deletions

View File

@ -13,6 +13,14 @@ namespace hgl
{ {
namespace graph namespace graph
{ {
struct FontAdvInfo
{
int x,y; //图像显示偏移
int w,h; //图像尺寸
int adv_x,adv_y;//字符尺寸
};//struct FontAdvInfo
/** /**
* *
*/ */
@ -20,10 +28,7 @@ namespace hgl
{ {
int count; //使用次数 int count; //使用次数
int x,y; //图像显示偏移 FontAdvInfo adv_info;
int w,h; //图像尺寸
int adv_x,adv_y;//字符尺寸
uint8 *data; uint8 *data;
};//struct FontBitmap };//struct FontBitmap
@ -42,7 +47,7 @@ namespace hgl
virtual ~FontSource()=default; virtual ~FontSource()=default;
virtual FontBitmap *GetCharBitmap (const u32char &)=0; ///<取得字符位图数据 virtual FontBitmap *GetCharBitmap (const u32char &)=0; ///<取得字符位图数据
virtual int GetCharAdvWidth(const u32char &)=0; ///<取得字符绘制宽度 virtual const bool GetCharAdvInfo (FontAdvInfo &,const u32char &); ///<取得字符绘制信息
virtual int GetCharHeight ()const=0; ///<取得字符高度 virtual int GetCharHeight ()const=0; ///<取得字符高度
void RefAcquire(void *); ///<引用请求 void RefAcquire(void *); ///<引用请求
@ -71,7 +76,7 @@ namespace hgl
virtual ~FontSourceSingle()=default; virtual ~FontSourceSingle()=default;
FontBitmap *GetCharBitmap (const u32char &ch) override; ///<取得字符位图数据 FontBitmap *GetCharBitmap (const u32char &ch) override; ///<取得字符位图数据
virtual int GetCharAdvWidth(const u32char &)=0; ///<取得字符绘制宽度 const bool GetCharAdvInfo (FontAdvInfo &,const u32char &); ///<取得字符绘制信息
virtual int GetCharHeight ()const override{return fnt.height;} ///<取得字符高度 virtual int GetCharHeight ()const override{return fnt.height;} ///<取得字符高度
};//class FontSourceSingle:public FontSource };//class FontSourceSingle:public FontSource
@ -106,7 +111,7 @@ namespace hgl
void Remove(FontSource *); void Remove(FontSource *);
FontBitmap *GetCharBitmap (const u32char &ch) override; FontBitmap *GetCharBitmap (const u32char &ch) override;
int GetCharAdvWidth(const u32char &) override; const bool GetCharAdvInfo (FontAdvInfo &,const u32char &); ///<取得字符绘制信息
int GetCharHeight ()const override; ///<取得字符高度 int GetCharHeight ()const override; ///<取得字符高度
};//class FontSourceMulti:public FontSource };//class FontSourceMulti:public FontSource
}//namespace graph }//namespace graph

View File

@ -32,7 +32,6 @@ namespace hgl
{ {
uint vertical:1; ///<是否竖排 uint vertical:1; ///<是否竖排
uint right_to_left:1; ///<是否从右往左 uint right_to_left:1; ///<是否从右往左
uint bottom_to_top:1; ///<是否从下到上
}; };
};//union TextDirection };//union TextDirection
@ -79,7 +78,7 @@ namespace hgl
int TextLayout(RenderableCreater *,const TextLayoutAttributes *,const int max_chars,const UTF16String &); int TextLayout(RenderableCreater *,const TextLayoutAttributes *,const int max_chars,const UTF16String &);
int PlaneTextLayout(RenderableCreater *,FontSource *font_source,const int max_chars,const UTF16String &); int PlaneTextLayout(RenderableCreater *,FontSource *font_source,const int max_chars,const UTF16String &,const uint8 text_direction=0);
}//namespace graph }//namespace graph
}//namespace hgl }//namespace hgl
#endif//HGL_GRAPH_TEXT_LAYOUT_INCLUDE #endif//HGL_GRAPH_TEXT_LAYOUT_INCLUDE

View File

@ -62,8 +62,7 @@ SET(TILE_FONT_SOURCE ${ROOT_INCLUDE_PATH}/hgl/graph/font/TileFont.h
font/TileFont.cpp) font/TileFont.cpp)
SET(FONT_LAYOUT_SOURCE ${ROOT_INCLUDE_PATH}/hgl/graph/font/TextLayout.h SET(FONT_LAYOUT_SOURCE ${ROOT_INCLUDE_PATH}/hgl/graph/font/TextLayout.h
font/TextLayout.cpp font/TextLayout.cpp)
font/TextLayoutPlane.cpp)
SOURCE_GROUP("Font" FILES ${FONT_MANAGE_SOURCE}) SOURCE_GROUP("Font" FILES ${FONT_MANAGE_SOURCE})
SOURCE_GROUP("Font\\Source" FILES ${FONT_SOURCE}) SOURCE_GROUP("Font\\Source" FILES ${FONT_SOURCE})

View File

@ -29,5 +29,16 @@ namespace hgl
return bmp; return bmp;
} }
} }
const bool FontSourceSingle::GetCharAdvInfo(FontAdvInfo &adv_info,const u32char &ch)
{
FontBitmap *bmp=GetCharBitmap(ch);
if(!bmp)
return false;
adv_info=bmp->adv_info;
return(true);
}
}//namespace graph }//namespace graph
}//namespace hgl }//namespace hgl

View File

@ -120,21 +120,21 @@ namespace hgl
GetGlyphOutlineW(hdc,ch,ggo,&gm,buffer_size,buffer,&mat); GetGlyphOutlineW(hdc,ch,ggo,&gm,buffer_size,buffer,&mat);
bmp->w=gm.gmBlackBoxX; bmp->adv_info.w =gm.gmBlackBoxX;
bmp->h=gm.gmBlackBoxY; bmp->adv_info.h =gm.gmBlackBoxY;
bmp->x=gm.gmptGlyphOrigin.x; bmp->adv_info.x =gm.gmptGlyphOrigin.x;
bmp->y=gm.gmptGlyphOrigin.y; bmp->adv_info.y =gm.gmptGlyphOrigin.y;
bmp->adv_x=gm.gmCellIncX; bmp->adv_info.adv_x =gm.gmCellIncX;
bmp->adv_y=gm.gmCellIncY; bmp->adv_info.adv_y =gm.gmCellIncY;
bmp->data=new uint8[bmp->w*bmp->h]; bmp->data=new uint8[bmp->adv_info.w*bmp->adv_info.h];
if(ggo==GGO_GRAY8_BITMAP) if(ggo==GGO_GRAY8_BITMAP)
Convert8BitGrey(bmp->data,buffer,gm.gmBlackBoxX,gm.gmBlackBoxY,size/bmp->h); Convert8BitGrey(bmp->data,buffer,gm.gmBlackBoxX,gm.gmBlackBoxY,size/bmp->adv_info.h);
else else
ConvertBitmap(bmp->data,buffer,gm.gmBlackBoxX,gm.gmBlackBoxY,size/bmp->h); ConvertBitmap(bmp->data,buffer,gm.gmBlackBoxX,gm.gmBlackBoxY,size/bmp->adv_info.h);
return(true); return(true);
} }

View File

@ -27,7 +27,6 @@ namespace hgl
~WinBitmapFont(); ~WinBitmapFont();
bool MakeCharBitmap(FontBitmap *,u32char) override; ///<产生字体数据 bool MakeCharBitmap(FontBitmap *,u32char) override; ///<产生字体数据
int GetCharAdvWidth(const u32char &) override;
};//class WinBitmapFont };//class WinBitmapFont
}//namespace graph }//namespace graph
}//namespace hgl }//namespace hgl

View File

@ -37,6 +37,8 @@ namespace hgl
bool begin_disable; ///<是否行首禁用符号 bool begin_disable; ///<是否行首禁用符号
bool end_disable; ///<是否行尾禁用符号 bool end_disable; ///<是否行尾禁用符号
bool vrotate; ///<竖排时是否需要旋转 bool vrotate; ///<竖排时是否需要旋转
FontAdvInfo adv_info; ///<字符绘制信息
};//struct CharLayoutAttributes };//struct CharLayoutAttributes
/** /**
@ -79,8 +81,21 @@ namespace hgl
TEXT_COORD_TYPE line_height; TEXT_COORD_TYPE line_height;
TEXT_COORD_TYPE paragraph_gap; TEXT_COORD_TYPE paragraph_gap;
protected:
AutoDelete<VB4f> vertex;
public: public:
TextLayoutEngine()
{
rc=nullptr;
tla=nullptr;
direction.text_direction=0;
max_chars=0;
vertex=nullptr;
}
virtual ~TextLayoutEngine()=default; virtual ~TextLayoutEngine()=default;
bool Init(RenderableCreater *_rc,const TextLayoutAttributes *_tla) bool Init(RenderableCreater *_rc,const TextLayoutAttributes *_tla)
@ -167,6 +182,9 @@ namespace hgl
cla->is_emoji =isEmoji(*cp); cla->is_emoji =isEmoji(*cp);
cla->is_punctuation =isPunctuation(*cp); cla->is_punctuation =isPunctuation(*cp);
if(!tla->font_source->GetCharAdvInfo(cla->adv_info,*cp))
hgl_zero(cla->adv_info);
} }
++cp; ++cp;
@ -225,6 +243,81 @@ namespace hgl
return(-4); return(-4);
} }
return 0;
}
protected:
int pl_h_l2r()
{
const int count=chars_attributes.GetCount();
const CLA *cla=chars_attributes.GetData();
int cur_size=0;
for(int i=0;i<count;i++)
{
vertex->Write(x,y
}
}
int pl_h_r2l()
{
return 0;
}
int pl_v_r2l()
{
return 0;
}
int pl_v_l2r()
{
return 0;
}
public:
/**
* <br>
* \r\n换行
*/
int plane_layout(const int mc,const BaseString<T> &str)
{
if(mc<=0
||!str
||!(*str))
return(-1);
max_chars=hgl_min(mc,str.Length());
origin_string=str;
if(preprocess()<=0)
return(-3);
if(!rc->Init(ch_count))
return(-4);
vertex=rc->CreateVADA<VB4f>(VAN::Vertex);
if(!vertex)
return(-5);
if(direction.vertical)
{
if(direction.right_to_left)
return pl_v_r2l();
else
return pl_v_l2r();
}
else
{
if(direction.right_to_left)
return pl_h_r2l();
else
return pl_h_l2r();
}
return 0; return 0;
} }
};//template<typename T> class TextLayoutEngine };//template<typename T> class TextLayoutEngine

View File

@ -1,21 +0,0 @@
#include<hgl/graph/font/TextLayout.h>
namespace hgl
{
namespace graph
{
/**
*
*/
int PlaneTextLayout(RenderableCreater *rc,FontSource *font_source,const int max_chars,const UTF16String &str)
{
if(!rc
||!font_source
||max_chars<=0
||str.IsEmpty())
return 0;
}
}//namespace graph
}//namespace hgl