Ejemplo n.º 1
0
	def generate_test_svg_ted(self, ted_string, filepath=FILE_DIR + '/../temp/test.svg'):
		unique = 1
		filename = str(unique) + 'barcode.svg'
		filepath = FILE_DIR + '/../temp/' + filename
		codes = pdf417.encode(ted_string, security_level=5)
		svg = pdf417.render_svg(codes, scale=3, ratio=3)  # ElementTree object
		svg.write(filepath)
		return filename
Ejemplo n.º 2
0
def test_render_svg():
    scale = 2
    ratio = 4
    description = "hi there"

    tree = render_svg(codes, scale=scale, ratio=ratio, description=description)
    assert isinstance(tree, ElementTree)
    assert tree.findtext("description") == description

    # Test expected size
    width, height = barcode_size(codes)

    root = tree.getroot()

    assert root.get("width") == str(width * scale)
    assert root.get("height") == str(height * scale * ratio)
    assert root.get("version") == "1.1"
    assert root.get("xmlns") == "http://www.w3.org/2000/svg"

    # Check number of rendered modules (only visible ones)
    expected_module_count = len([v for x, y, v in modules(codes) if v])
    actual_module_count = len(root.findall('g/rect'))

    assert expected_module_count == actual_module_count
def xml_to_svg(xml_text):
    codes = encode(xml_text, columns=11)
    svg = render_svg(codes)
    svg.write('./templates/barcode.svg')
Ejemplo n.º 4
0
	def _generate_svg_ted(self, ted_string):
		codes = pdf417.encode(ted_string, security_level=5)
		svg = pdf417.render_svg(codes, scale=3, ratio=3)  # ElementTree object
		return svg