diff options
author | Chris Xiong <chirs241097@gmail.com> | 2016-05-28 22:23:15 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2016-05-28 22:23:15 +0800 |
commit | 12ac4db50e8c2b131d992733bb93b554e2cbd7d0 (patch) | |
tree | e1f6072c53f34e449ffb0b836cf5b5b4ec58664d /extensions | |
parent | 2c5a0391c3299ccbb866a0dd33204dbeccfa2b95 (diff) | |
download | SMELT-12ac4db50e8c2b131d992733bb93b554e2cbd7d0.tar.xz |
Fix right-aligned ttf rendering.
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/smttfont.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/extensions/smttfont.cpp b/extensions/smttfont.cpp index c38440c..d800b82 100644 --- a/extensions/smttfont.cpp +++ b/extensions/smttfont.cpp @@ -43,14 +43,24 @@ bool smTTChar::setChar(wchar_t c,FT_Face ttface) quad.v[2].tx=1;quad.v[2].ty=1;quad.v[3].tx=0;quad.v[3].ty=1; return true; } -void smTTChar::render(float x,float y,float z,DWORD col,float scalex,float scaley) +void smTTChar::render(float x,float y,float z,DWORD col,float scalex,float scaley,bool rtl) { for(int i=0;i<4;++i)quad.v[i].col=col,quad.v[i].z=z; - quad.v[0].x=x+xofs*scalex;quad.v[0].y=y+(yofs-rh)*scaley; - quad.v[1].x=x+(rw+xofs)*scalex;quad.v[1].y=y+(yofs-rh)*scaley; - quad.v[2].x=x+(rw+xofs)*scalex;quad.v[2].y=y+yofs*scaley; - quad.v[3].x=x+xofs*scalex;quad.v[3].y=y+yofs*scaley; - sm->smRenderQuad(&quad); + if(!rtl) + { + quad.v[0].x=x+xofs*scalex;quad.v[0].y=y+(yofs-rh)*scaley; + quad.v[1].x=x+(rw+xofs)*scalex;quad.v[1].y=y+(yofs-rh)*scaley; + quad.v[2].x=x+(rw+xofs)*scalex;quad.v[2].y=y+yofs*scaley; + quad.v[3].x=x+xofs*scalex;quad.v[3].y=y+yofs*scaley; + } + else + { + quad.v[0].x=x+(-rw+xofs)*scalex;quad.v[0].y=y+(yofs-rh)*scaley; + quad.v[1].x=x+xofs*scalex;quad.v[1].y=y+(yofs-rh)*scaley; + quad.v[2].x=x+xofs*scalex;quad.v[2].y=y+yofs*scaley; + quad.v[3].x=x+(-rw+xofs)*scalex;quad.v[3].y=y+yofs*scaley; + } +sm->smRenderQuad(&quad); } bool smTTFont::loadTTF(const char* path,int pt) @@ -109,7 +119,7 @@ void smTTFont::render(float x,float y,float z,DWORD col,int align,float scalex,f { if(chars.find(buf[i])!=chars.end()) { - chars[buf[i]].render(curx,cury,z,col,scalex,scaley); + chars[buf[i]].render(curx,cury,z,col,scalex,scaley,false); curx+=chars[buf[i]].w()*scalex; lh=chars[buf[i]].h()>lh?chars[buf[i]].h():lh; } @@ -126,7 +136,7 @@ void smTTFont::render(float x,float y,float z,DWORD col,int align,float scalex,f { if(chars.find(buf[i])!=chars.end()) { - chars[buf[i]].render(curx,cury,z,col,scalex,scaley); + chars[buf[i]].render(curx,cury,z,col,scalex,scaley,true); curx-=chars[buf[i]].w()*scalex; lh=chars[buf[i]].h()>lh?chars[buf[i]].h():lh; } |