Fixing text alignment issues. PageBuilder is still incorrectly calculating offsets for yOrigin on verticalList.

This commit is contained in:
emb 2015-02-23 13:00:32 -06:00
parent bf7a347511
commit 2e9f82b16e
3 changed files with 44 additions and 8 deletions

View File

@ -67,26 +67,36 @@ void Text::Draw()
Font::GlyphInfo glyph;
if(FontInst->GetRect(TextData[i], glyph))
{
if(glyph.MinX < 0)
{
imageWidth += glyph.MinX;
}
imageWidth += glyph.Advance;
imageHeight = (imageHeight >= glyph.Rect.h) ? imageHeight : glyph.Rect.h;
}
}
imageHeight = (float)FontInst->GetHeight();
float scale = (float)info->GetFontSize() / (float)imageHeight;
float width = info->GetRawWidth();
float height = info->GetRawHeight();
float oldWidth = info->GetRawWidth();
float oldHeight = info->GetRawHeight();
float oldImageWidth = info->GetImageHeight();
float oldImageHeight = info->GetImageWidth();
info->SetWidth(imageWidth*scale);
info->SetHeight(imageHeight*scale);
info->SetHeight(info->GetFontSize());
info->SetImageWidth(imageWidth);
info->SetImageHeight(imageHeight);
float xOrigin = info->GetXRelativeToOrigin();
float yOrigin = info->GetYRelativeToOrigin();
info->SetWidth(width);
info->SetHeight(height);
info->SetWidth(oldWidth);
info->SetHeight(oldHeight);
info->SetImageWidth(oldImageWidth);
info->SetImageHeight(oldImageHeight);
SDL_Rect rect;
@ -105,7 +115,18 @@ void Text::Draw()
rect.w = static_cast<int>(w);
rect.y = static_cast<int>(yOrigin);
if(glyph.MinX < 0)
{
rect.x += static_cast<int>((float)(glyph.MinX) * scale);
}
if(FontInst->GetAscent() < glyph.MaxY)
{
rect.y += static_cast<int>((FontInst->GetAscent() - glyph.MaxY)*scale);
}
SDL::RenderCopy(t, static_cast<char>(info->GetAlpha() * 255), &charRect, &rect, info->GetAngle());
rect.x += static_cast<int>(glyph.Advance * scale);
if((static_cast<float>(rect.x) - xOrigin) > info->GetMaxWidth())

View File

@ -66,6 +66,8 @@ bool Font::Initialize(std::string fontPath, int fontSize, SDL_Color color)
int y = 0;
int atlasHeight = 0;
int atlasWidth = 0;
Height = TTF_FontHeight(font);
Ascent = TTF_FontAscent(font);
for(unsigned short int i = 32; i < 128; ++i)
{
@ -159,3 +161,13 @@ void Font::DeInitialize()
}
}
int Font::GetHeight()
{
return Height;
}
int Font::GetAscent()
{
return Ascent;
}

View File

@ -38,7 +38,8 @@ public:
void DeInitialize();
SDL_Texture *GetTexture();
bool GetRect(unsigned int charCode, GlyphInfo &glyph);
int GetHeight();
int GetAscent();
private:
struct GlyphInfoBuild
@ -47,6 +48,8 @@ private:
SDL_Surface *Surface;
};
int Height;
int Ascent;
std::map<unsigned int, GlyphInfoBuild *> Atlas;
SDL_Texture *Texture;
};