def test_should_use_viewbox_if_available(self): bounding_box = BoundingBox(11, 12, 101, 102) page = E.svg({ SVG_VIEWBOX_ATTRIB: format_bounding_box(bounding_box) }) doc = SvgStructuredDocument(page) assert doc.get_bounding_box(page) == bounding_box
def test_should_not_return_bounding_box_if_font_size_is_missing(self): text = SVG_TEXT({ 'x': '10', 'y': '11' }) doc = SvgStructuredDocument(E.svg(SVG_TEXT_LINE(text))) assert doc.get_bounding_box(text) is None
def test_should_calculate_default_bounding_box(self): text = SVG_TEXT('a', { 'x': '10', 'y': '11', 'font-size': '100' }) doc = SvgStructuredDocument(E.svg(SVG_TEXT_LINE(text))) assert doc.get_bounding_box(text) == BoundingBox(10, 11, 100 * 0.8, 100)
def test_should_use_bounding_box_if_available(self): bounding_box = BoundingBox(11, 12, 101, 102) text = SVG_TEXT('a', { 'x': '10', 'y': '11', 'font-size': '100', SVGE_BOUNDING_BOX: format_bounding_box(bounding_box) }) doc = SvgStructuredDocument(E.svg(SVG_TEXT_LINE(text))) assert doc.get_bounding_box(text) == bounding_box
def test_should_estimate_width_based_on_number_of_characters(self): s = 'abc' text = SVG_TEXT(s, { 'x': '10', 'y': '11', 'font-size': '100' }) doc = SvgStructuredDocument(E.svg(SVG_TEXT_LINE(text))) assert doc.get_bounding_box(text) == BoundingBox( 10, 11, 100 * 0.8 * len(s), 100 )