Skip to content
This repository
Browse code

add last character width rather than advance when calculating text width

this makes sure we don't chop off part of character in case when advance is smaller than character width (italic text), fixes #13795
  • Loading branch information...
commit 66919a68627640a24dcfaaf55449818e8561e1d9 1 parent 5e98e17
Michal Piechowiak authored December 26, 2012

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

  1. 11  xbmc/guilib/GUIFontTTF.cpp
11  xbmc/guilib/GUIFontTTF.cpp
@@ -423,7 +423,16 @@ float CGUIFontTTFBase::GetTextWidthInternal(vecText::const_iterator start, vecTe
423 423
   while (start != end)
424 424
   {
425 425
     Character *c = GetCharacter(*start++);
426  
-    if (c) width += c->advance;
  426
+    if (c)
  427
+    {
  428
+      // If last character in line, we want to add render width
  429
+      // and not advance distance - this makes sure that italic text isn't
  430
+      // choped on the end (as render width is larger than advance then).
  431
+      if (start == end)
  432
+        width += max(c->right - c->left + c->offsetX, c->advance);
  433
+      else
  434
+        width += c->advance;
  435
+    }
427 436
   }
428 437
   return width;
429 438
 }

0 notes on commit 66919a6

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