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' if self.lang: lang = self.lang.code else: lang = 'en' 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': lang, })
def render(self): translated_text = self.get_text(_('translated')) font = get_font(11, False, is_base(translated_text)) translated_width = font.getsize(translated_text)[0] + 12 percent_text = '{0}%'.format(int(self.percent)) 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, } )
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]
def render_text(self, text, lang_text, base_font_size, bold_font, pos_x, pos_y): 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), line, font=font, fill=COLOR_DATA[self.color]['text'] ) offset += layout_size[1]
def render_text(self, text, lang_text, base_font_size, bold_font, pos_x, pos_y): # Use language variant if desired if self.lang is not None and lang_text is not None: text = lang_text if 'English' in text: text = text.replace('English', self.lang.name) # Format text text = text % self.params 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), line, font=font, fill=COLOR_DATA[self.color]['text'] ) offset += layout_size[1]