Exemple #1
0
 def test_should_find_lines_of_page_without_blocks(self):
     lines = [
         SVG_TEXT_LINE(),
         SVG_TEXT_LINE()
     ]
     doc = SvgStructuredDocument(
         E.svg(
             *lines
         )
     )
     page = doc.get_pages()[0]
     assert list(doc.get_lines_of_page(page)) == lines
Exemple #2
0
def svg_page_to_blockified_png_bytes(svg_page, color_map, image_size=None):
    structured_document = SvgStructuredDocument(svg_page)
    blocks = expand_blocks(
        merge_blocks(
            annotation_document_page_to_annotation_blocks(
                structured_document,
                structured_document.get_pages()[0]
            )
        )
    )
    viewbox = svg_page.attrib.get('viewBox')
    if not viewbox:
        raise RuntimeError(
            'viewbox missing on svg, available attributes: %s' % svg_page.attrib.keys()
        )
    _, _, width, height = viewbox.split()
    image = annotated_blocks_to_image(
        blocks, color_map,
        width=float(width), height=float(height), background='white',
        scale_to_size=image_size
    )
    out = BytesIO()
    image.save(out, 'png')
    return out.getvalue()
Exemple #3
0
 def test_should_return_root_as_pages(self):
     root = E.svg()
     doc = SvgStructuredDocument(root)
     assert list(doc.get_pages()) == [root]