diff options
author | Chris Xiong <chirs241097@gmail.com> | 2016-05-12 23:25:37 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2016-05-12 23:25:37 +0800 |
commit | 3b2a801f86f4ce7cdca8681b619fe3ff88307ef2 (patch) | |
tree | 1097dea2b40a370df47e1e4a429da98e67cfaff3 | |
parent | 08c898f79acd024718b071f0d08eb32f3f093cbd (diff) | |
download | SMELT-3b2a801f86f4ce7cdca8681b619fe3ff88307ef2.tar.xz |
Allow drawing scaled truetype fonts.
-rw-r--r-- | extensions/smttfont.cpp | 24 | ||||
-rw-r--r-- | include/smttfont.hpp | 4 |
2 files changed, 14 insertions, 14 deletions
diff --git a/extensions/smttfont.cpp b/extensions/smttfont.cpp index cf3ba68..c38440c 100644 --- a/extensions/smttfont.cpp +++ b/extensions/smttfont.cpp @@ -43,13 +43,13 @@ 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) +void smTTChar::render(float x,float y,float z,DWORD col,float scalex,float scaley) { for(int i=0;i<4;++i)quad.v[i].col=col,quad.v[i].z=z; - quad.v[0].x=x+xofs;quad.v[0].y=y-rh+yofs; - quad.v[1].x=x+rw+xofs;quad.v[1].y=y-rh+yofs; - quad.v[2].x=x+rw+xofs;quad.v[2].y=y+yofs; - quad.v[3].x=x+xofs;quad.v[3].y=y+yofs; + 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); } @@ -97,7 +97,7 @@ void smTTFont::updateString(const wchar_t *format,...) } h+=lh; } -void smTTFont::render(float x,float y,float z,DWORD col,int align) +void smTTFont::render(float x,float y,float z,DWORD col,int align,float scalex,float scaley) { float curx,cury,lh; if(align==ALIGN_LEFT) @@ -109,12 +109,12 @@ void smTTFont::render(float x,float y,float z,DWORD col,int align) { if(chars.find(buf[i])!=chars.end()) { - chars[buf[i]].render(curx,cury,z,col); - curx+=chars[buf[i]].w(); + chars[buf[i]].render(curx,cury,z,col,scalex,scaley); + curx+=chars[buf[i]].w()*scalex; lh=chars[buf[i]].h()>lh?chars[buf[i]].h():lh; } } - else cury+=lh,lh=0,curx=x; + else cury+=lh*scaley,lh=0,curx=x; } } if(align==ALIGN_RIGHT) @@ -126,12 +126,12 @@ void smTTFont::render(float x,float y,float z,DWORD col,int align) { if(chars.find(buf[i])!=chars.end()) { - chars[buf[i]].render(curx,cury,z,col); - curx-=chars[buf[i]].w(); + chars[buf[i]].render(curx,cury,z,col,scalex,scaley); + curx-=chars[buf[i]].w()*scalex; lh=chars[buf[i]].h()>lh?chars[buf[i]].h():lh; } } - else cury-=lh,lh=0,curx=x; + else cury-=lh*scaley,lh=0,curx=x; } } } diff --git a/include/smttfont.hpp b/include/smttfont.hpp index 0d90179..608907c 100644 --- a/include/smttfont.hpp +++ b/include/smttfont.hpp @@ -33,7 +33,7 @@ public: float h(){return (float)_h;} void free(); bool setChar(wchar_t c,FT_Face ttface); - void render(float x,float y,float z,DWORD col); + void render(float x,float y,float z,DWORD col,float scalex,float scaley); }; class smTTFont @@ -52,7 +52,7 @@ public: float getWidth(){return w;} float getHeight(){return h;} void updateString(const wchar_t *format,...); - void render(float x,float y,float z,DWORD col,int align); + void render(float x,float y,float z,DWORD col,int align,float scalex=1,float scaley=1); DWORD getCacheSize(); void clearCache(); }; |