diff --git a/RetroFE/Source/Graphics/Component/Text.cpp b/RetroFE/Source/Graphics/Component/Text.cpp index 02ae5b0..ed0a311 100644 --- a/RetroFE/Source/Graphics/Component/Text.cpp +++ b/RetroFE/Source/Graphics/Component/Text.cpp @@ -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(w); rect.y = static_cast(yOrigin); + if(glyph.MinX < 0) + { + rect.x += static_cast((float)(glyph.MinX) * scale); + } + if(FontInst->GetAscent() < glyph.MaxY) + { + rect.y += static_cast((FontInst->GetAscent() - glyph.MaxY)*scale); + } + + SDL::RenderCopy(t, static_cast(info->GetAlpha() * 255), &charRect, &rect, info->GetAngle()); + rect.x += static_cast(glyph.Advance * scale); if((static_cast(rect.x) - xOrigin) > info->GetMaxWidth()) diff --git a/RetroFE/Source/Graphics/Font.cpp b/RetroFE/Source/Graphics/Font.cpp index 68d90d7..8a03921 100644 --- a/RetroFE/Source/Graphics/Font.cpp +++ b/RetroFE/Source/Graphics/Font.cpp @@ -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; +} + diff --git a/RetroFE/Source/Graphics/Font.h b/RetroFE/Source/Graphics/Font.h index a9d0561..550b010 100644 --- a/RetroFE/Source/Graphics/Font.h +++ b/RetroFE/Source/Graphics/Font.h @@ -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 Atlas; SDL_Texture *Texture; };