示例#1
0
文件: widgets.py 项目: ztomaz/weblate
    def render(self):
        translated_text = _('translated')
        font = get_font(11, False, is_base(translated_text))
        translated_width = font.getsize(translated_text)[0] + 12

        percent_text = self.get_percent_text()
        font = get_font(11, False, is_base(percent_text))
        percent_width = font.getsize(percent_text)[0] + 7

        if self.percent >= 90:
            color = '#4c1'
        elif self.percent >= 75:
            color = '#dfb317'
        else:
            color = '#e05d44'

        self.image = render_to_string(
            'badge.svg', {
                'translated_text': translated_text,
                'percent_text': percent_text,
                'translated_width': translated_width,
                'percent_width': percent_width,
                'width': translated_width + percent_width,
                'color': color,
                'translated_offset': translated_width // 2,
                'percent_offset': translated_width + percent_width // 2,
                'lang': get_language(),
            })
示例#2
0
文件: widgets.py 项目: dekoza/weblate
    def render(self):
        translated_text = _('translated')
        font = get_font(11, False, is_base(translated_text))
        translated_width = font.getsize(translated_text)[0] + 12

        percent_text = self.get_percent_text()
        font = get_font(11, False, is_base(percent_text))
        percent_width = font.getsize(percent_text)[0] + 7

        if self.percent >= 90:
            color = '#4c1'
        elif self.percent >= 75:
            color = '#dfb317'
        else:
            color = '#e05d44'

        self.image = render_to_string(
            'badge.svg',
            {
                'translated_text': translated_text,
                'percent_text': percent_text,
                'translated_width': translated_width,
                'percent_width': percent_width,
                'width': translated_width + percent_width,
                'color': color,
                'translated_offset': translated_width // 2,
                'percent_offset': translated_width + percent_width // 2,
                'lang': get_language(),
            }
        )
示例#3
0
文件: widgets.py 项目: ztomaz/weblate
    def render_text(self,
                    text,
                    lang_text,
                    base_font_size,
                    bold_font,
                    pos_x,
                    pos_y,
                    transform=True):
        if transform:
            text = self.get_text(text, lang_text)
        base_font = is_base(text)
        offset = 0

        for line in text.splitlines():

            # Iterate until text fits into widget
            for font_size in range(base_font_size, 3, -1):
                font = get_font(font_size, bold_font, base_font)
                layout_size = font.getsize(line)
                layout_width = layout_size[0]
                if layout_width + pos_x < self.width:
                    break

            # Render text
            self.draw.text((pos_x, pos_y + offset),
                           get_display(line),
                           font=font,
                           fill=COLOR_DATA[self.color]['text'])

            offset += layout_size[1]
示例#4
0
文件: widgets.py 项目: dekoza/weblate
    def render_text(self, text, lang_text, base_font_size, bold_font,
                    pos_x, pos_y, transform=True):
        if transform:
            text = self.get_text(text, lang_text)
        base_font = is_base(text)
        offset = 0

        for line in text.splitlines():

            # Iterate until text fits into widget
            for font_size in range(base_font_size, 3, -1):
                font = get_font(font_size, bold_font, base_font)
                layout_size = font.getsize(line)
                layout_width = layout_size[0]
                if layout_width + pos_x < self.width:
                    break

            # Render text
            self.draw.text(
                (pos_x, pos_y + offset),
                get_display(line),
                font=font,
                fill=COLOR_DATA[self.color]['text']
            )

            offset += layout_size[1]