From 3faa7231bb10eaa22fa180c9ba4b5a5b8c8fdfb3 Mon Sep 17 00:00:00 2001 From: Qua-non Date: Thu, 9 Aug 2012 05:08:00 +0530 Subject: [PATCH] Core: markup and text allow for blanks lines when using \n for empty lines should fix issue #619 --- kivy/core/text/__init__.py | 2 ++ kivy/core/text/markup.py | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/kivy/core/text/__init__.py b/kivy/core/text/__init__.py index fc3155c67..90d869d67 100644 --- a/kivy/core/text/__init__.py +++ b/kivy/core/text/__init__.py @@ -287,6 +287,8 @@ class LabelBase(object): # calculate the word width ww, wh = 0, 0 + if word == '': + ww, wh = get_extents(' ') for glyph in word: gw, gh = cache[glyph] ww += gw diff --git a/kivy/core/text/markup.py b/kivy/core/text/markup.py index 46e41ea35..092d89eda 100644 --- a/kivy/core/text/markup.py +++ b/kivy/core/text/markup.py @@ -198,6 +198,7 @@ class MarkupLabel(MarkupLabelBase): # verify that each glyph have size glyphs = list(set(word)) + glyphs.append(' ') get_extents = self.get_extents for glyph in glyphs: if not glyph in cache: @@ -219,7 +220,7 @@ class MarkupLabel(MarkupLabelBase): for part in re.split(r'( |\n)', word): if part == '': - continue + part = ' ' if part == '\n': # put a new line! @@ -266,7 +267,7 @@ class MarkupLabel(MarkupLabelBase): y = 0 w, h = self._size refs = self._refs - no_of_lines = len(self._lines) + txt_height = sum(line[1] for line in self._lines) for line in self._lines: lh = line[1] @@ -283,9 +284,9 @@ class MarkupLabel(MarkupLabelBase): # vertical alignement if y == 0: if av == 1: - y = int((h - (lh*no_of_lines))/2) + y = int((h - txt_height)/2) elif av == 2: - y = h - (lh*(no_of_lines)) + y = h - (txt_height) for pw, ph, part, options in line[2]: