<commit_before>'''
Pango text provider
===================

'''

__all__ = ('LabelPango', )

from kivy.compat import PY2
from kivy.core.text import LabelBase
from kivy.core.text._text_pango import (KivyPangoRenderer, kpango_get_extents,
                                        kpango_get_metrics)


class LabelPango(LabelBase):

    # This is a hack to avoid dealing with glib attrs to configure layout,
    # we just create markup out of the options and let pango set attrs
    def _pango_markup(self, text):
        markup = (text.replace('&', '&amp;')
                      .replace('<', '&lt;')
                      .replace('>', '&gt;'))
        options = self.options
        tags = []
        if options['bold']:
            markup = '<b>{}</b>'.format(markup)
        if options['underline']:
            markup = '<u>{}</u>'.format(markup)
        if options['strikethrough']:
            markup = '<s>{}</s>'.format(markup)

        span_attrs = ''
        if options['font_features']:
            span_attrs += 'font_features="{}" '.format(options['font_features'])
        if options['text_language']:
            span_attrs += 'lang="{}" '.format(options['text_language'])

        return '<span font_size="{}"{}>{}</span>'.format(
                int(self.options['font_size']),
                span_attr,
                markup)

    def get_extents(self, text):
        if not text:
            return (0, 0)
        w, h = kpango_get_extents(self, self._pango_markup(text))
        return (w, h)

    def get_ascent(self):
        return kpango_get_metrics(self)[0]

    def get_descent(self):
        return kpango_get_metrics(self)[1]

    def _render_begin(self):
        self._rdr = KivyPangoRenderer(self._size[0], self._size[1])<commit_msg>text_pango: Fix typo + cleanup span_attrs<commit_after>'''
Pango text provider
===================

'''

__all__ = ('LabelPango', )

from kivy.compat import PY2
from kivy.core.text import LabelBase
from kivy.core.text._text_pango import (KivyPangoRenderer, kpango_get_extents,
                                        kpango_get_metrics)


class LabelPango(LabelBase):

    # This is a hack to avoid dealing with glib attrs to configure layout,
    # we just create markup out of the options and let pango set attrs
    def _pango_markup(self, text):
        markup = (text.replace('&', '&amp;')
                      .replace('<', '&lt;')
                      .replace('>', '&gt;'))
        options = self.options
        tags = []
        if options['bold']:
            markup = '<b>{}</b>'.format(markup)
        if options['underline']:
            markup = '<u>{}</u>'.format(markup)
        if options['strikethrough']:
            markup = '<s>{}</s>'.format(markup)

        span_attrs = ''
        if options['font_features']:
            span_attrs += ' font_features="{}"'.format(options['font_features'])
        if options['text_language']:
            span_attrs += ' lang="{}"'.format(options['text_language'])

        return '<span font_size="{}"{}>{}</span>'.format(
                int(self.options['font_size']),
                span_attrs,
                markup)

    def get_extents(self, text):
        if not text:
            return (0, 0)
        w, h = kpango_get_extents(self, self._pango_markup(text))
        return (w, h)

    def get_ascent(self):
        return kpango_get_metrics(self)[0]

    def get_descent(self):
        return kpango_get_metrics(self)[1]

    def _render_begin(self):
        self._rdr = KivyPangoRenderer(self._size[0], self._size[1])
{'fraction_non_alphanumeric': 0.15181332583637897, 'fraction_numerical': 0.003935901040202418, 'mean_word_length': 2.3128491620111733, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7363464', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1106, 'n_words': 239}