Skip to content
This repository
Browse code

Merge pull request #2037 from jmarshallnz/outline_alignment

fix horizontal alignment of outlined text
  • Loading branch information...
commit ea0f2ef26d86b0a751c23c2dd95d5828e2ae2495 2 parents ed80802 + d167e0b
jmarshallnz authored January 07, 2013

Showing 1 changed file with 13 additions and 1 deletion. Show diff stats Hide diff stats

  1. 14  xbmc/guilib/GUITextLayout.cpp
14  xbmc/guilib/GUITextLayout.cpp
@@ -168,8 +168,20 @@ void CGUITextLayout::RenderOutline(float x, float y, color_t color, color_t outl
168 168
       uint32_t align = alignment;
169 169
       if (align & XBFONT_JUSTIFIED && string.m_carriageReturn)
170 170
         align &= ~XBFONT_JUSTIFIED;
  171
+      // text centered horizontally must be computed using the original font, not the bordered
  172
+      // font, as the bordered font will be wider, and thus will end up uncentered.
  173
+      // TODO: We should really have a better way to handle text extent - at the moment we assume
  174
+      //       that text is rendered from a posx, posy, width, and height which isn't enough to
  175
+      //       accurately position text. We need a vertical and horizontal offset of the baseline
  176
+      //       and cursor as well.
  177
+      float bx = x;
  178
+      if (align & XBFONT_CENTER_X)
  179
+      {
  180
+        bx -= m_font->GetTextWidth(string.m_text) * 0.5f;
  181
+        align &= ~XBFONT_CENTER_X;
  182
+      }
171 183
 
172  
-      m_borderFont->DrawText(x, by, outlineColors, 0, string.m_text, align, maxWidth);
  184
+      m_borderFont->DrawText(bx, by, outlineColors, 0, string.m_text, align, maxWidth);
173 185
       by += m_borderFont->GetLineHeight();
174 186
     }
175 187
     m_borderFont->End();

0 notes on commit ea0f2ef

Please sign in to comment.
Something went wrong with that request. Please try again.