finished draw text example,and tested ok.

This commit is contained in:
hyzboy 2020-08-04 02:23:22 +08:00
parent cea2f8da9e
commit 824c1b0fcd
10 changed files with 62 additions and 21 deletions

2
CMCore

@ -1 +1 @@
Subproject commit c2c7c42cd43759a9a613b6ad2c890a2e1d948b37
Subproject commit 3895fbbd4dac907c12fecc88576ac8c55ad8f9fb

View File

@ -57,7 +57,7 @@ private:
bool InitTileFont()
{
Font fnt(OS_TEXT("Consolas"),0,CHAR_BITMAP_SIZE);
Font fnt(OS_TEXT("微软雅黑"),0,CHAR_BITMAP_SIZE);
tile_font=device->CreateTileFont(fnt);
return(true);
@ -145,7 +145,8 @@ private:
if(!tl_engine.Init())
return(false);
UTF16String str=U16_TEXT("道可道,非常道。名可名,非常名。无名天地之始。有名万物之母。故常无欲以观其妙。常有欲以观其徼。此两者同出而异名,同谓之玄。玄之又玄,众妙之门。");
UTF16String str;
LoadStringFromTextFile(str,OS_TEXT("res/text/DaoDeBible.txt"));
if(tl_engine.SimpleLayout(tile_font,str)>0)
{

View File

@ -52,7 +52,7 @@ namespace hgl
/**
*
*/
struct CharLayoutAttributes:public CharAttributes
struct CharLayoutAttributes
{
CharAttributes *attr; ///<字符基本信息

View File

@ -121,8 +121,9 @@ namespace hgl
int sl_v_r2l();
int sl_v_l2r();
template<typename T>
int SimpleLayout (TileFont *,const BaseString<T> &); ///<简易排版
template<typename T> int SimpleLayout(TileFont *,const BaseString<T> &); ///<简易排版
// template<typename T> int SimpleLayout(TileFont *,const StringList<BaseString<T>> &); ///<简易排版
protected:
@ -168,6 +169,9 @@ namespace hgl
int SimpleLayout (TileFont *,const UTF16String &); ///<简易排版
int SimpleLayout (TileFont *,const UTF32String &); ///<简易排版
// int SimpleLayout (TileFont *,const UTF16StringList &); ///<简易排版
// int SimpleLayout (TileFont *,const UTF32StringList &); ///<简易排版
};//class TextLayout
}//namespace graph
}//namespace hgl

2
res

@ -1 +1 @@
Subproject commit 8e31af94c83e4114673e19db2ea7593522bae16e
Subproject commit f8af997de769b0d535dc933d2ee48984834b32d0

View File

@ -17,10 +17,7 @@ VK_NAMESPACE_BEGIN
*/
TileFont *Device::CreateTileFont(const Font &f,int limit_count)
{
int height=(f.height+3)>>2;
height<<=2; //保证可以被4整除
height+=2; //上下左右各空一个象素
int height=((f.height+2+3)>>2)<<2; //上下左右各空一个象素并保证可以被4整除
if(limit_count<=0)
{

View File

@ -88,6 +88,10 @@ namespace hgl
cla->visible=(cla->metrics.w>0&&cla->metrics.h>0);
}
}
else
{
cla->visible=false;
}
cla_cache.Add(ch,cla);
return cla;

View File

@ -136,6 +136,7 @@ namespace hgl
bmp->metrics_info.adv_y =gm.gmCellIncY;
bmp->data=new uint8[bmp->metrics_info.w*bmp->metrics_info.h];
memset(bmp->data,0,bmp->metrics_info.w*bmp->metrics_info.h);
if(ggo==GGO_GRAY8_BITMAP)
Convert8BitGrey(bmp->data,bmp->metrics_info.w,buffer,gm.gmBlackBoxX,gm.gmBlackBoxY,size/gm.gmBlackBoxY);

View File

@ -97,7 +97,7 @@ namespace hgl
for(int i=0;i<str_length;i++)
{
alone_chars_uv.Get((*cda)->cla->ch,(*cda)->uv);
alone_chars_uv.Get((*cda)->cla->attr->ch,(*cda)->uv);
++cda;
}
@ -181,19 +181,37 @@ namespace hgl
if((*cda)->cla->visible)
{
tp=WriteRect( tp,
left,
top,
left+(*cda)->cla->metrics.x,
top -(*cda)->cla->metrics.y+font_source->GetCharHeight(),
(*cda)->cla->metrics.w,
(*cda)->cla->metrics.h);
tcp=WriteRect(tcp,(*cda)->uv);
left+=(*cda)->cla->metrics.adv_x;
}
else
{
{
if((*cda)->cla->attr->ch==' ')
left+=tla.space_size;
else
if((*cda)->cla->attr->ch==HGL_FULL_SPACE)
left+=tla.full_space_size;
else
if((*cda)->cla->attr->ch=='\t')
left+=tla.tab_size;
else
if((*cda)->cla->attr->ch=='\n')
{
left=0;
top+=font_source->GetCharHeight()+tla.line_gap;
}
else
{
left+=(*cda)->cla->metrics.adv_x;
}
}
left+=(*cda)->cla->metrics.adv_x;
++cda;
}
@ -251,5 +269,13 @@ namespace hgl
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);}
//template<typename T>
//int TextLayout::SimpleLayout(TileFont *tf,const StringList<BaseString<T>> &sl)
//{
//}
//int TextLayout::SimpleLayout(TileFont *tf,const UTF16StringList &sl){return this->SimpleLayout<u16char>(tf,sl);}
//int TextLayout::SimpleLayout(TileFont *tf,const UTF32StringList &sl){return this->SimpleLayout<u32char>(tf,sl);}
}//namespace graph
}//namespace hgl

View File

@ -58,11 +58,19 @@ namespace hgl
if(!to_res.Get(*cp,to))
{
bmp=source->GetCharBitmap(*cp);
to=tile_data->Commit( bmp->data,
bmp->metrics_info.w*bmp->metrics_info.h,
bmp->metrics_info.w,bmp->metrics_info.h);
to_res.Add(*cp,to);
if(bmp)
{
to=tile_data->Commit( bmp->data,
bmp->metrics_info.w*bmp->metrics_info.h,
bmp->metrics_info.w,bmp->metrics_info.h);
to_res.Add(*cp,to);
}
else
{
}
}
uv_map.Add(*cp,to->uv_float);