diff --git a/examples/widgets/label_with_markup.py b/examples/widgets/label_with_markup.py new file mode 100644 index 000000000..a11794d43 --- /dev/null +++ b/examples/widgets/label_with_markup.py @@ -0,0 +1,19 @@ +from kivy.app import App +from kivy.lang import Builder + +root = Builder.load_string(''' +Label: + text: + ('[b]Hello[/b] [color=ff0099]World[/color]\\n' + '[color=ff0099]Hello[/color] [b]World[/b]\\n' + '[b]Hello[/b] [color=ff0099]World[/color]') + markup: True + font_size: '64pt' +''') + +class LabelWithMarkup(App): + def build(self): + return root + +if __name__ == '__main__': + LabelWithMarkup().run() diff --git a/kivy/core/text/markup.py b/kivy/core/text/markup.py index 9fe816220..fabdc922d 100644 --- a/kivy/core/text/markup.py +++ b/kivy/core/text/markup.py @@ -217,14 +217,15 @@ class MarkupLabel(MarkupLabelBase): uw, uh = self.text_size # split the word + default_line_height = get_extents(' ')[1] for part in re.split(r'( |\n)', word): if part == '': - part = ' ' + continue if part == '\n': # put a new line! - line = [0, 0, []] + line = [0, default_line_height, []] lines.append(line) continue @@ -310,26 +311,18 @@ class MarkupLabel(MarkupLabelBase): # create texture is necessary texture = self.texture mipmap = self.options['mipmap'] - if texture is None: - if data is None: - if platform() in ('android', 'ios'): - colorfmt = 'rgba' - else: - colorfmt = 'luminance_alpha' - texture = Texture.create( - size=self.size, colorfmt=colorfmt, - mipmap=mipmap) - else: - texture = Texture.create_from_data(data, mipmap=mipmap) - texture.flip_vertical() - elif self.width != texture.width or self.height != texture.height: - if data is None: - texture = Texture.create(size=self.size, mipmap=mipmap) - else: - texture = Texture.create_from_data(data, mipmap=mipmap) + if texture is None or \ + self.width != texture.width or \ + self.height != texture.height: + texture = Texture.create_from_data(data, mipmap=mipmap) + data = None texture.flip_vertical() + texture.add_reload_observer(self._texture_refresh) + self.texture = texture # update texture - self.texture = texture - self.texture.blit_data(data) + # If the text is 1px width, usually, the data is black. + # Don't blit that kind of data, otherwise, you have a little black bar. + if data is not None and data.width > 1: + texture.blit_data(data) diff --git a/kivy/properties.pxd b/kivy/properties.pxd index 307c0c7ea..b7c19ccc1 100644 --- a/kivy/properties.pxd +++ b/kivy/properties.pxd @@ -1,7 +1,7 @@ cdef class Property: cdef str _name cdef int allownone - cdef object defaultvalue + cdef public object defaultvalue cdef init_storage(self, object obj, dict storage) cpdef link(self, object obj, str name) cpdef link_deps(self, object obj, str name)