int FontBuilder::FTSystem::CalcWidth(FTFont *font,int size,String *str) { int width=0; int len=str->length(); for(int i=0;i<len;i++) { unsigned int c=(unsigned int)ubyte(str->at(i)); if(c==32) { width+=size<<1; continue; }; FTFont::GlyphEntry *e=font->FindCharIndex(c,size); if(!e) { CacheCharacter(font,c,size,Vector3(1.0f,1.0f,1.0f)); e=font->FindCharIndex(c,size); if(!e) {e=font->FindCharIndex(ubyte('?'),size);}; }; width+=e->advx; }; return width; };
// 根据字符获取轮廓 unsigned int GdiFont::GetGlyphByCharacter( wchar_t c ) { unsigned int idx = (unsigned int)c; if (NULL == (m_FontGlyphs[idx].t)) CacheCharacter(idx,c); return idx; }
bool FontBuilder::FTSystem::Fill(FTFont *font,void *buffer,int size,unsigned int &pos,float x,float y,float z,unsigned int color,String *str) { if(font==nullptr||buffer==nullptr||str==nullptr) {return false;}; bool tag=false; TextVertex *vertices=(TextVertex*)buffer; int len=str->length(); for(int i=0;i<len;i++) { /*if(!tag) { if(str->at(i)=='<') { tag=true; }; } else { if(str->at(i)=='>') { tag=false; }; };*/ if(/*!tag&&*/str->at(i)==' ') { x+=(float)size*1.25f; continue; }; unsigned int c=(unsigned int)ubyte(str->at(i)); FTFont::GlyphEntry *e=font->FindCharIndex(c,size); if(!e) { CacheCharacter(font,c,size,Vector3(1.0f,1.0f,1.0f)); e=font->FindCharIndex(c,size); if(!e) {e=font->FindCharIndex(ubyte('?'),size);}; }; float pw=(float)e->width; float ph=(float)e->height; float px=x+float(e->offx); float py=y+float(e->offy); float ux=e->uv[0].x; float uy=e->uv[0].y; float uw=e->uv[1].x; float uh=e->uv[1].y; vertices[pos+0].m_position=Vector3(px,py,z); vertices[pos+0].m_texcoord=Vector2(ux,uy); vertices[pos+0].m_color=color; vertices[pos+1].m_position=Vector3(px+pw,py,z); vertices[pos+1].m_texcoord=Vector2(ux+uw,uy); vertices[pos+1].m_color=color; vertices[pos+2].m_position=Vector3(px+pw,py+ph,z); vertices[pos+2].m_texcoord=Vector2(ux+uw,uy+uh); vertices[pos+2].m_color=color; vertices[pos+3].m_position=Vector3(px+pw,py+ph,z); vertices[pos+3].m_texcoord=Vector2(ux+uw,uy+uh); vertices[pos+3].m_color=color; vertices[pos+4].m_position=Vector3(px,py+ph,z); vertices[pos+4].m_texcoord=Vector2(ux,uy+uh); vertices[pos+4].m_color=color; vertices[pos+5].m_position=Vector3(px,py,z); vertices[pos+5].m_texcoord=Vector2(ux,uy); vertices[pos+5].m_color=color; pos+=6; x+=e->advx; }; return true; };