Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def generate_plate(plate_code):
- print('Generating the plate', plate_code)
- inner_id, zone = unpack(plate_code)
- print('Inner ID:', inner_id)
- print('Zone:', zone)
- region = [regions[r]['code'] for r in regions if zone in regions[r]['zones']][0]
- region_name = [r for r in regions if region==regions[r]['code']][0]
- print('Region code:', region, '('+region_name+')')
- colorscheme = get_colorscheme(region)
- print('Color scheme: {}/{} {}/{}'.format(*colorscheme)) # RPFONT, RPBG, IPFONT, IPBG
- ElementTree.register_namespace('dc','http://purl.org/dc/elements/1.1/')
- ElementTree.register_namespace('cc','http://creativecommons.org/ns#')
- ElementTree.register_namespace('rdf','http://www.w3.org/1999/02/22-rdf-syntax-ns#')
- ElementTree.register_namespace('svg','http://www.w3.org/2000/svg')
- ElementTree.register_namespace('','http://www.w3.org/2000/svg')
- ElementTree.register_namespace('xlink','http://www.w3.org/1999/xlink')
- ElementTree.register_namespace('sodipodi','http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd')
- ElementTree.register_namespace('inkscape','http://www.inkscape.org/namespaces/inkscape')
- doc = ElementTree.parse(template_path)
- RPFONT = doc.find('.//*[@id="RPFONT"]')
- RPBG = doc.find('.//*[@id="RPBG"]')
- IPFONT = doc.find('.//*[@id="IPFONT"]')
- IPBG = doc.find('.//*[@id="IPBG"]')
- RPFONT.attrib['style']=re.sub(r'fill:#[0-9a-f]{6}', r'fill:'+colors[colorscheme[0]], RPFONT.attrib['style'])
- RPBG.attrib['style']=re.sub(r'fill:#[0-9a-f]{6}', r'fill:'+colors[colorscheme[1]], RPBG.attrib['style'])
- IPFONT.attrib['style']=re.sub(r'fill:#[0-9a-f]{6}', r'fill:'+colors[colorscheme[2]], IPFONT.attrib['style'])
- IPBG.attrib['style']=re.sub(r'fill:#[0-9a-f]{6}', r'fill:'+colors[colorscheme[3]], IPBG.attrib['style'])
- RP1 = doc.find('.//*[@id="RP1"]')
- RP2 = doc.find('.//*[@id="RP2"]')
- for n,e in enumerate([RP1, RP2]):
- e.attrib['{http://www.w3.org/1999/xlink}href'] = '#smallDigit'+'{:02d}'.format(region)[n]
- IP1 = doc.find('.//*[@id="IP1"]')
- IP2 = doc.find('.//*[@id="IP2"]')
- IP3 = doc.find('.//*[@id="IP3"]')
- IP4 = doc.find('.//*[@id="IP4"]')
- IP5 = doc.find('.//*[@id="IP5"]')
- IP6 = doc.find('.//*[@id="IP6"]')
- IP7 = doc.find('.//*[@id="IP7"]')
- IP8 = doc.find('.//*[@id="IP8"]')
- for n,e in enumerate([IP1, IP2]):
- e.attrib['{http://www.w3.org/1999/xlink}href'] = '#letter'+plate_code[n]
- for n,e in enumerate([IP3, IP4, IP5, IP6]):
- e.attrib['{http://www.w3.org/1999/xlink}href'] = '#digit'+plate_code[n+2]
- for n,e in enumerate([IP7, IP8]):
- e.attrib['{http://www.w3.org/1999/xlink}href'] = '#letter'+plate_code[n+6]
- folder = os.path.dirname(template_path)
- svg_path = os.path.join(folder, 'Plate ({:02d}) {}.svg'.format(region, plate_code))
- png_path = os.path.join(folder, 'Plate ({:02d}) {}.png'.format(region, plate_code))
- print('Saving as:', svg_path)
- doc.write(svg_path, default_namespace=None)
- print('Converting as:', png_path)
- os.system('inkscape "{}" -e "{}"'.format(svg_path, png_path))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement