aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2020-02-15 01:55:22 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2020-02-15 01:55:22 +0800
commitb47fce544c1c5ec98b326f69b56c916ba5be1c68 (patch)
tree779005e94af86f69cc71799d258d0962f5f3ed0b
parent41250bda2a3e3383b8825a31610102826c32c486 (diff)
downloadSMELT-b47fce544c1c5ec98b326f69b56c916ba5be1c68.tar.xz
Right-aligned texts are now correctly spaced. Line spacing is now more consistent.
-rw-r--r--extensions/smttfont.cpp40
1 files changed, 17 insertions, 23 deletions
diff --git a/extensions/smttfont.cpp b/extensions/smttfont.cpp
index 566aab1..dc0b8ad 100644
--- a/extensions/smttfont.cpp
+++ b/extensions/smttfont.cpp
@@ -29,7 +29,7 @@ public:
float h(){return (float)_h;}
void free();
bool setChar(wchar_t c,FT_Face ttface,smTTFont* par);
- void render(float x,float y,float z,DWORD col,float scalex,float scaley,bool rtl);
+ void render(float x,float y,float z,DWORD col,float scalex,float scaley);
};
SMELT *_smTTChar::sm=NULL;
@@ -71,23 +71,13 @@ bool _smTTChar::setChar(wchar_t c,FT_Face ttface,smTTFont* par)
quad.v[3].tx=1.*dx/par->texw;quad.v[3].ty=1.*(rh+dy)/par->texh;
return true;
}
-void _smTTChar::render(float x,float y,float z,DWORD col,float scalex,float scaley,bool rtl)
+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;
- 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;
- }
+ 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);
}
@@ -201,34 +191,38 @@ void smTTFont::render(float x,float y,float z,DWORD col,int align,float scalex,f
{
curx=x;cury=y;lh=0;
for(int i=0;buf[i]!=L'\0';++i)
+ if(chars.find(buf[i])!=chars.end())
+ if(chars[buf[i]]->h()>lh)lh=chars[buf[i]]->h();
+ for(int i=0;buf[i]!=L'\0';++i)
{
if(buf[i]!=L'\n')
{
if(chars.find(buf[i])!=chars.end())
{
- chars[buf[i]]->render(curx,cury,z,col,scalex,scaley,false);
+ 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*scaley,lh=0,curx=x;
+ else cury+=lh*scaley,curx=x;
}
}
if(align==ALIGN_RIGHT)
{
curx=x;cury=y;lh=0;
for(int i=wcslen(buf)-1;i>=0;--i)
+ if(chars.find(buf[i])!=chars.end())
+ if(chars[buf[i]]->h()>lh)lh=chars[buf[i]]->h();
+ for(int i=wcslen(buf)-1;i>=0;--i)
{
if(buf[i]!=L'\n')
{
if(chars.find(buf[i])!=chars.end())
{
- 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;
+ chars[buf[i]]->render(curx,cury,z,col,scalex,scaley);
+ if(i&&buf[i-1]!=L'\n')curx-=chars[buf[i-1]]->w()*scalex;
}
}
- else cury-=lh*scaley,lh=0,curx=x;
+ else cury-=lh*scaley,curx=x;
}
}
}