Example #1
0
    def split_text(self, text: str, typo: bool = True):
        """Split the text so that it fits into the images"""
        if typo:
            text_to_process = ru_typus(text).splitlines()
        else:
            text_to_process = text.splitlines()

        parts = []
        lines = []

        text_y = self.base_font_height

        for i_line in text_to_process:
            if self.font.getsize(i_line)[0] <= self._max_width:
                lines.append(i_line.replace(NNBSP, NBSP))
                text_y += self.base_font_height + 2
                if text_y > self.height - self.base_font_height * 2:
                    text_y = self.base_font_height
                    parts.append(lines)
                    lines = []
            else:
                words = i_line.replace(NNBSP, NBSP).split(' ')
                i = 0
                while i < len(words):
                    line = ''
                    while i < len(words) and self.font.getsize(
                            line + words[i])[0] <= self._max_width:
                        line = line + words[i] + " "
                        i += 1
                    if not line:
                        line = words[i]
                        i += 1

                    lines.append(line)
                    text_y += self.base_font_height + 2
                    if text_y > self.height - self.base_font_height * 2:
                        text_y = self.base_font_height
                        parts.append(lines)
                        lines = []

        parts.append(lines)

        return parts
Example #2
0
def render_item(meta: dict, item: dict):
    created = meta[item['id']]
    item.update(
        price=item['price'] and format_price(item['price']),
        title=ru_typus(item['title'].strip('.')),
        norm=normalize(item['title']),
        new=created >= NEW_INT,
        created=created,
    )
    # This must be called after all updates
    # to create valid tags
    item_tags = get_tags(item)
    item.update(
        tags=item_tags,
        for_kids=item_tags[3] & KIDS,
    )

    # fixme: time for pydantic
    item.pop('new')
    return item
Example #3
0
def rutypography(value):
    return ru_typus(value)
Example #4
0
 def test_debug(self):
     self.assertEqual(ru_typus('2mm', debug=True), '2_mm')
Example #5
0
 def test_empty(self, mock_process):
     self.assertEqual(ru_typus(''), '')
     mock_process.assert_not_called()
Example #6
0
 def testcase(text, test, debug=False):
     return self.assertEqual(ru_typus(text, debug), test)