diff options
author | anssih <anssih@svn> | 2010-07-10 22:37:29 +0000 |
---|---|---|
committer | anssih <anssih@svn> | 2010-07-10 22:37:29 +0000 |
commit | b33a9614ab0bf28238ce0a98e18aba2f92d7e322 (patch) | |
tree | 8d8f0858d48c7cc78b393c8306bf49e7fef169be | |
parent | 06fc8c10f87717201a3e7ad3e1667b690a7de6e4 (diff) |
fixed: scale text outline to match text scaling
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@31705 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
-rw-r--r-- | guilib/GUIFont.cpp | 10 | ||||
-rw-r--r-- | guilib/GUIFont.h | 7 | ||||
-rw-r--r-- | guilib/GUIFontManager.cpp | 2 | ||||
-rw-r--r-- | guilib/GUIFontTTF.h | 1 | ||||
-rw-r--r-- | guilib/GUITextLayout.cpp | 7 |
5 files changed, 24 insertions, 3 deletions
diff --git a/guilib/GUIFont.cpp b/guilib/GUIFont.cpp index 5d3b7cd1ab..f52f3c65fd 100644 --- a/guilib/GUIFont.cpp +++ b/guilib/GUIFont.cpp @@ -46,13 +46,15 @@ float CScrollInfo::GetPixelsPerFrame() return pixelSpeed * m_averageFrameTime; } -CGUIFont::CGUIFont(const CStdString& strFontName, uint32_t style, color_t textColor, color_t shadowColor, float lineSpacing, CGUIFontTTFBase *font) +CGUIFont::CGUIFont(const CStdString& strFontName, uint32_t style, color_t textColor, + color_t shadowColor, float lineSpacing, float origHeight, CGUIFontTTFBase *font) { m_strFontName = strFontName; m_style = style & 3; m_textColor = textColor; m_shadowColor = shadowColor; m_lineSpacing = lineSpacing; + m_origHeight = origHeight; m_font = font; if (m_font) @@ -260,6 +262,12 @@ float CGUIFont::GetLineHeight() const return m_font->GetLineHeight(m_lineSpacing) * g_graphicsContext.GetGUIScaleY(); } +float CGUIFont::GetScaleFactor() const +{ + if (!m_font) return 1.0f; + return m_font->GetFontHeight() / m_origHeight; +} + void CGUIFont::Begin() { if (!m_font) return; diff --git a/guilib/GUIFont.h b/guilib/GUIFont.h index a1db8e0389..935dfad9e9 100644 --- a/guilib/GUIFont.h +++ b/guilib/GUIFont.h @@ -110,7 +110,8 @@ private: class CGUIFont { public: - CGUIFont(const CStdString& strFontName, uint32_t style, color_t textColor, color_t shadowColor, float lineSpacing, CGUIFontTTFBase *font); + CGUIFont(const CStdString& strFontName, uint32_t style, color_t textColor, + color_t shadowColor, float lineSpacing, float origHeight, CGUIFontTTFBase *font); virtual ~CGUIFont(); CStdString& GetFontName(); @@ -134,6 +135,9 @@ public: float GetTextHeight(int numLines) const; float GetLineHeight() const; + //! get font scale factor (rendered height / original height) + float GetScaleFactor() const; + void Begin(); void End(); @@ -154,6 +158,7 @@ protected: color_t m_shadowColor; color_t m_textColor; float m_lineSpacing; + float m_origHeight; CGUIFontTTFBase *m_font; // the font object has the size information private: diff --git a/guilib/GUIFontManager.cpp b/guilib/GUIFontManager.cpp index 700477130a..db1c7d4a31 100644 --- a/guilib/GUIFontManager.cpp +++ b/guilib/GUIFontManager.cpp @@ -126,7 +126,7 @@ CGUIFont* GUIFontManager::LoadTTF(const CStdString& strFontName, const CStdStrin } // font file is loaded, create our CGUIFont - CGUIFont *pNewFont = new CGUIFont(strFontName, iStyle, textColor, shadowColor, lineSpacing, pFontFile); + CGUIFont *pNewFont = new CGUIFont(strFontName, iStyle, textColor, shadowColor, lineSpacing, iSize, pFontFile); m_vecFonts.push_back(pNewFont); // Store the original TTF font info in case we need to reload it in a different resolution diff --git a/guilib/GUIFontTTF.h b/guilib/GUIFontTTF.h index 277c1378c1..e39455946f 100644 --- a/guilib/GUIFontTTF.h +++ b/guilib/GUIFontTTF.h @@ -92,6 +92,7 @@ protected: float GetCharWidthInternal(character_t ch); float GetTextHeight(float lineSpacing, int numLines) const; float GetLineHeight(float lineSpacing) const; + float GetFontHeight() const { return m_height; } void DrawTextInternal(float x, float y, const vecColors &colors, const vecText &text, uint32_t alignment, float maxPixelWidth, bool scrolling); diff --git a/guilib/GUITextLayout.cpp b/guilib/GUITextLayout.cpp index 9f581f4748..84a6a24126 100644 --- a/guilib/GUITextLayout.cpp +++ b/guilib/GUITextLayout.cpp @@ -569,6 +569,13 @@ void CGUITextLayout::DrawOutlineText(CGUIFont *font, float x, float y, color_t c void CGUITextLayout::DrawOutlineText(CGUIFont *font, float x, float y, const vecColors &colors, color_t outlineColor, uint32_t outlineWidth, const vecText &text, uint32_t align, float maxWidth) { + if (outlineWidth) + { + outlineWidth = outlineWidth * font->GetScaleFactor() + 0.5f; + if (outlineWidth < 2) + outlineWidth = 2; + } + for (unsigned int i = 1; i < outlineWidth; i++) { unsigned int ymax = (unsigned int)(sqrt((float)outlineWidth*outlineWidth - i*i) + 0.5f); |