diff --git a/.gitignore b/.gitignore index 68bc17f..e1440cd 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,6 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +*.png +*.svg \ No newline at end of file diff --git a/resources/A.ttf b/resources/A.ttf new file mode 100644 index 0000000..22ea22b Binary files /dev/null and b/resources/A.ttf differ diff --git a/resources/B.ttf b/resources/B.ttf new file mode 100644 index 0000000..ca37cd5 Binary files /dev/null and b/resources/B.ttf differ diff --git a/resources/C.ttf b/resources/C.ttf new file mode 100644 index 0000000..2ec40c0 Binary files /dev/null and b/resources/C.ttf differ diff --git a/test/test_rect.py b/test/test_rect.py new file mode 100644 index 0000000..20a8eb3 --- /dev/null +++ b/test/test_rect.py @@ -0,0 +1,40 @@ +import svgwrite +import cairosvg +import os + +from lxml import etree +from utils.font_size import FontSize +from utils.factory import TextFactory +from utils.factory import RectFactory + +# config +width = 250 +height = 250 + +# rect +dwg = svgwrite.Drawing('rect.svg', profile='tiny', width=width, height=height) + +RectFactory.double_stroke_rect(container=dwg, width=250, height=250, main_color='#1f963b', stroke_color='#ffffff', stroke_width=4, r=16, x=0, y=0) + +# export +dwg.save() + +# 解析SVG文件 +svg_file = 'rect.svg' +with open(svg_file, 'rb') as f: + svg_data = f.read() + parser = etree.XMLParser(remove_blank_text=True) + svg_tree = etree.fromstring(svg_data, parser) + +for element in svg_tree.iter(): + if 'height' in element.attrib: + element.attrib['height'] = element.attrib['height'].replace('100%', '{}'.format(height)) + if 'width' in element.attrib: + element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width)) + +# 保存修改后的SVG文件 +with open('rect.svg', 'wb') as f: + f.write(etree.tostring(svg_tree, pretty_print=True)) + +cairosvg.svg2png(url='rect.svg', write_to='rect.png') +os.remove('rect.svg') diff --git a/test/test_text.py b/test/test_text.py new file mode 100644 index 0000000..518d976 --- /dev/null +++ b/test/test_text.py @@ -0,0 +1,51 @@ +import svgwrite +import cairosvg +import os + +from lxml import etree +from utils.font_size import FontSize +from utils.factory import TextFactory + +''' +字号字高比=1:1; 下沉20% +''' + +text = '测试0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' +text_size = 50 +text_width = FontSize.get_font_width(text, 'utils/A.ttf', text_size) +print(text_width) + +# config +width = text_width +height = text_size + +# rect +dwg = svgwrite.Drawing('./{}.svg'.format(text), profile='tiny', width=width, height=height) +dwg.add(dwg.rect(insert=(0, 0), size=(width, height), rx=0, ry=0, fill='red')) + +# text +dwg.add(TextFactory.type_a_text(dwg, text, 'white', text_size, 0, 0)) + +# export +dwg.save() + +# 解析SVG文件 +svg_file = './{}.svg'.format(text) +with open(svg_file, 'rb') as f: + svg_data = f.read() + parser = etree.XMLParser(remove_blank_text=True) + svg_tree = etree.fromstring(svg_data, parser) + +for element in svg_tree.iter(): + if 'height' in element.attrib: + element.attrib['height'] = element.attrib['height'].replace('100%', '{}'.format(height)) + if 'width' in element.attrib: + element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width)) + +# 保存修改后的SVG文件 +with open('./{}.svg'.format(text), 'wb') as f: + f.write(etree.tostring(svg_tree, pretty_print=True)) + +cairosvg.svg2png(url='./{}.svg'.format(text), write_to='./{}.png'.format(text)) +os.remove('./{}.svg'.format(text)) +print('{}标志生成完成'.format(text)) diff --git a/test/utils/A.ttf b/test/utils/A.ttf new file mode 100644 index 0000000..22ea22b Binary files /dev/null and b/test/utils/A.ttf differ diff --git a/test/utils/B.ttf b/test/utils/B.ttf new file mode 100644 index 0000000..ca37cd5 Binary files /dev/null and b/test/utils/B.ttf differ diff --git a/test/utils/C.ttf b/test/utils/C.ttf new file mode 100644 index 0000000..2ec40c0 Binary files /dev/null and b/test/utils/C.ttf differ diff --git a/test/utils/__init__.py b/test/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/utils/factory.py b/test/utils/factory.py new file mode 100644 index 0000000..daa7975 --- /dev/null +++ b/test/utils/factory.py @@ -0,0 +1,26 @@ +import svgwrite + +class TextFactory: + + def type_a_text(container, text, color, size, x, y): + return TextFactory.text(container, text, 'A型交通标志专用字体', color, size, x, y) + + def type_b_text(container, text, color, size, x, y): + return TextFactory.text(container, text, 'B型交通标志专用字体', color, size, x, y) + + def text(container, text, font, color, size, x, y): + x_loc = x + y_loc = y + size * 0.8 + return container.text(text, insert=(x_loc, y_loc), fill=color, font_family=font, font_size=size) + + +class RectFactory: + + def single_stroke_rect(container, width, height, main_color, stroke_color, stroke_width, r, x, y): + container.add(container.rect(insert=(x, y), size=(width, height), rx=r, ry=r, fill=stroke_color)) + container.add(container.rect(insert=(x + stroke_width, y + stroke_width), size=(width - 2 * stroke_width, height - 2 * stroke_width), rx=r - stroke_width, ry=r - stroke_width, fill=main_color)) + + def double_stroke_rect(container, width, height, main_color, stroke_color, stroke_width, r, x, y): + container.add(container.rect(insert=(x, y), size=(width, height), rx=r, ry=r, fill=main_color)) + container.add(container.rect(insert=(x + stroke_width, y + stroke_width), size=(width - 2 * stroke_width, height - 2 * stroke_width), rx=r - stroke_width, ry=r - stroke_width, fill=stroke_color)) + container.add(container.rect(insert=(x + 2 * stroke_width, y + 2 * stroke_width), size=(width - 4 * stroke_width, height - 4 * stroke_width), rx=r - 2 * stroke_width, ry=r - 2 * stroke_width, fill=main_color)) \ No newline at end of file diff --git a/test/utils/font_size.py b/test/utils/font_size.py new file mode 100644 index 0000000..f857a0a --- /dev/null +++ b/test/utils/font_size.py @@ -0,0 +1,15 @@ +from PIL import ImageFont + +class FontSize: + def get_font_width(text, font, size): + return sum([ImageFont.truetype(font, size, 0).getsize(char)[0] for char in text]) + + def font_size_width_dict(font, size): + dict = {} + for char in range(ord('0'), ord('9') + 1): + dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size + for char in range(ord('A'), ord('Z') + 1): + dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size + for char in range(ord('a'), ord('z') + 1): + dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size + return dict \ No newline at end of file diff --git a/test/utils/width.json b/test/utils/width.json new file mode 100644 index 0000000..d4400be --- /dev/null +++ b/test/utils/width.json @@ -0,0 +1,64 @@ +{ + "0": 0.52, + "1": 0.3, + "2": 0.5, + "3": 0.46, + "4": 0.48, + "5": 0.5, + "6": 0.5, + "7": 0.46, + "8": 0.5, + "9": 0.5, + "A": 0.5, + "B": 0.48, + "C": 0.5, + "D": 0.5, + "E": 0.42, + "F": 0.42, + "G": 0.5, + "H": 0.52, + "I": 0.22, + "J": 0.46, + "K": 0.48, + "L": 0.44, + "M": 0.58, + "N": 0.52, + "O": 0.54, + "P": 0.48, + "Q": 0.54, + "R": 0.48, + "S": 0.44, + "T": 0.38, + "U": 0.52, + "V": 0.46, + "W": 0.54, + "X": 0.48, + "Y": 0.5, + "Z": 0.44, + "a": 0.4, + "b": 0.42, + "c": 0.34, + "d": 0.42, + "e": 0.38, + "f": 0.22, + "g": 0.4, + "h": 0.4, + "i": 0.22, + "j": 0.2, + "k": 0.38, + "l": 0.2, + "m": 0.6, + "n": 0.4, + "o": 0.4, + "p": 0.42, + "q": 0.42, + "r": 0.28, + "s": 0.34, + "t": 0.26, + "u": 0.4, + "v": 0.38, + "w": 0.5, + "x": 0.38, + "y": 0.42, + "z": 0.36 +} \ No newline at end of file diff --git a/中国国家公路网-县道、乡道/XYXXX.py b/中国国家公路网-县道、乡道/XYXXX.py new file mode 100644 index 0000000..f6d70a1 --- /dev/null +++ b/中国国家公路网-县道、乡道/XYXXX.py @@ -0,0 +1,56 @@ +import svgwrite +import cairosvg +from lxml import etree +import os +from utils.font_size import FontSize + +# config +width = 1920 +height = 960 +stroke_width = 40 +out_r = stroke_width * 4 +mid_r = stroke_width * 3 +in_r = stroke_width * 2 + +for prefix in ['X', 'Y']: + for num in range(1, 1000): + text = '{}{}'.format(prefix, str(num).zfill(3)) + text_h = 880 + text_full_width = FontSize.get_font_width(text, './utils/B.ttf', text_h) + + # rect + dwg = svgwrite.Drawing('./{}.svg'.format(text), profile='tiny', width=width, height=height) + dwg.add(dwg.rect(insert=(0, 0), size=(width, height), rx=out_r, ry=out_r, fill="white")) + dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width - stroke_width * 2, height - stroke_width * 2), rx=mid_r, ry=mid_r, fill="black")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 4, height - stroke_width * 4), rx=in_r, ry=in_r, fill="white")) + + # text + y_offset = -180 + text_x = (width - text_full_width) / 2 + text_y = (height + text_h) / 2 + y_offset + dwg.add(dwg.text(text, insert=(text_x, text_y), fill="black", font_family="B型交通标志专用字体",font_size=text_h)) + + # export + dwg.save() + + # 解析SVG文件 + svg_file = './{}.svg'.format(text) + with open(svg_file, 'rb') as f: + svg_data = f.read() + parser = etree.XMLParser(remove_blank_text=True) + svg_tree = etree.fromstring(svg_data, parser) + + for element in svg_tree.iter(): + if 'height' in element.attrib: + element.attrib['height'] = element.attrib['height'].replace('100%', '{}'.format(height + stroke_width * 2)) + if 'width' in element.attrib: + element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2)) + + # 保存修改后的SVG文件 + with open('./{}.svg'.format(text), 'wb') as f: + f.write(etree.tostring(svg_tree, pretty_print=True)) + + cairosvg.svg2png(url='./{}.svg'.format(text), write_to='./{}.png'.format(text)) + os.remove('./{}.svg'.format(text)) + print('{}标志生成完成'.format(text)) + \ No newline at end of file diff --git a/中国国家公路网-县道、乡道/utils/A.ttf b/中国国家公路网-县道、乡道/utils/A.ttf new file mode 100644 index 0000000..22ea22b Binary files /dev/null and b/中国国家公路网-县道、乡道/utils/A.ttf differ diff --git a/中国国家公路网-县道、乡道/utils/B.ttf b/中国国家公路网-县道、乡道/utils/B.ttf new file mode 100644 index 0000000..ca37cd5 Binary files /dev/null and b/中国国家公路网-县道、乡道/utils/B.ttf differ diff --git a/中国国家公路网-县道、乡道/utils/C.ttf b/中国国家公路网-县道、乡道/utils/C.ttf new file mode 100644 index 0000000..2ec40c0 Binary files /dev/null and b/中国国家公路网-县道、乡道/utils/C.ttf differ diff --git a/中国国家公路网-县道、乡道/utils/__init__.py b/中国国家公路网-县道、乡道/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/中国国家公路网-县道、乡道/utils/factory.py b/中国国家公路网-县道、乡道/utils/factory.py new file mode 100644 index 0000000..29520e5 --- /dev/null +++ b/中国国家公路网-县道、乡道/utils/factory.py @@ -0,0 +1,14 @@ +import svgwrite + +class TextFactory: + + def type_a_text(container, text, color, size, x, y): + return TextFactory.text(container, text, 'A型交通标志专用字体', color, size, x, y) + + def type_b_text(container, text, color, size, x, y): + return TextFactory.text(container, text, 'B型交通标志专用字体', color, size, x, y) + + def text(container, text, font, color, size, x, y): + x_loc = x + y_loc = y + size * 0.8 + return container.text(text, insert=(x_loc, y_loc), fill=color, font_family=font, font_size=size) \ No newline at end of file diff --git a/中国国家公路网-县道、乡道/utils/font_size.py b/中国国家公路网-县道、乡道/utils/font_size.py new file mode 100644 index 0000000..f857a0a --- /dev/null +++ b/中国国家公路网-县道、乡道/utils/font_size.py @@ -0,0 +1,15 @@ +from PIL import ImageFont + +class FontSize: + def get_font_width(text, font, size): + return sum([ImageFont.truetype(font, size, 0).getsize(char)[0] for char in text]) + + def font_size_width_dict(font, size): + dict = {} + for char in range(ord('0'), ord('9') + 1): + dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size + for char in range(ord('A'), ord('Z') + 1): + dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size + for char in range(ord('a'), ord('z') + 1): + dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size + return dict \ No newline at end of file diff --git a/中国国家公路网-县道、乡道/utils/width.json b/中国国家公路网-县道、乡道/utils/width.json new file mode 100644 index 0000000..d4400be --- /dev/null +++ b/中国国家公路网-县道、乡道/utils/width.json @@ -0,0 +1,64 @@ +{ + "0": 0.52, + "1": 0.3, + "2": 0.5, + "3": 0.46, + "4": 0.48, + "5": 0.5, + "6": 0.5, + "7": 0.46, + "8": 0.5, + "9": 0.5, + "A": 0.5, + "B": 0.48, + "C": 0.5, + "D": 0.5, + "E": 0.42, + "F": 0.42, + "G": 0.5, + "H": 0.52, + "I": 0.22, + "J": 0.46, + "K": 0.48, + "L": 0.44, + "M": 0.58, + "N": 0.52, + "O": 0.54, + "P": 0.48, + "Q": 0.54, + "R": 0.48, + "S": 0.44, + "T": 0.38, + "U": 0.52, + "V": 0.46, + "W": 0.54, + "X": 0.48, + "Y": 0.5, + "Z": 0.44, + "a": 0.4, + "b": 0.42, + "c": 0.34, + "d": 0.42, + "e": 0.38, + "f": 0.22, + "g": 0.4, + "h": 0.4, + "i": 0.22, + "j": 0.2, + "k": 0.38, + "l": 0.2, + "m": 0.6, + "n": 0.4, + "o": 0.4, + "p": 0.42, + "q": 0.42, + "r": 0.28, + "s": 0.34, + "t": 0.26, + "u": 0.4, + "v": 0.38, + "w": 0.5, + "x": 0.38, + "y": 0.42, + "z": 0.36 +} \ No newline at end of file diff --git a/中国国家公路网-国道/GXXX.py b/中国国家公路网-国道/GXXX.py new file mode 100644 index 0000000..28360c1 --- /dev/null +++ b/中国国家公路网-国道/GXXX.py @@ -0,0 +1,55 @@ +import svgwrite +import cairosvg +import os +from lxml import etree +from utils.font_size import FontSize + +# config +width = 1920 +height = 960 +stroke_width = 40 +out_r = stroke_width * 4 +mid_r = stroke_width * 3 +in_r = stroke_width * 2 + +for num in range(101, 1000): + text = 'G{}'.format(num) + text_h = 880 + text_full_width = FontSize.get_font_width(text, './utils/B.ttf', text_h) + + # rect + dwg = svgwrite.Drawing('./{}.svg'.format(text), profile='tiny', width=width, height=height) + dwg.add(dwg.rect(insert=(0, 0), size=(width, height), rx=out_r, ry=out_r, fill="red")) + dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width - stroke_width * 2, height - stroke_width * 2), rx=mid_r, ry=mid_r, fill="white")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 4, height - stroke_width * 4), rx=in_r, ry=in_r, fill="#e71420")) + + # text + y_offset = -180 + text_x = (width - text_full_width) / 2 + text_y = (height + text_h) / 2 + y_offset + dwg.add(dwg.text(text, insert=(text_x, text_y), fill="white", font_family="B型交通标志专用字体",font_size=text_h)) + + # export + dwg.save() + + # 解析SVG文件 + svg_file = './{}.svg'.format(text) + with open(svg_file, 'rb') as f: + svg_data = f.read() + parser = etree.XMLParser(remove_blank_text=True) + svg_tree = etree.fromstring(svg_data, parser) + + for element in svg_tree.iter(): + if 'height' in element.attrib: + element.attrib['height'] = element.attrib['height'].replace('100%', '{}'.format(height + stroke_width * 2)) + if 'width' in element.attrib: + element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2)) + + # 保存修改后的SVG文件 + with open('./{}.svg'.format(text), 'wb') as f: + f.write(etree.tostring(svg_tree, pretty_print=True)) + + cairosvg.svg2png(url='./{}.svg'.format(text), write_to='./{}.png'.format(text)) + os.remove('./{}.svg'.format(text)) + print('{}标志生成完成'.format(text)) + \ No newline at end of file diff --git a/中国国家公路网-国道/utils/A.ttf b/中国国家公路网-国道/utils/A.ttf new file mode 100644 index 0000000..22ea22b Binary files /dev/null and b/中国国家公路网-国道/utils/A.ttf differ diff --git a/中国国家公路网-国道/utils/B.ttf b/中国国家公路网-国道/utils/B.ttf new file mode 100644 index 0000000..ca37cd5 Binary files /dev/null and b/中国国家公路网-国道/utils/B.ttf differ diff --git a/中国国家公路网-国道/utils/C.ttf b/中国国家公路网-国道/utils/C.ttf new file mode 100644 index 0000000..2ec40c0 Binary files /dev/null and b/中国国家公路网-国道/utils/C.ttf differ diff --git a/中国国家公路网-国道/utils/__init__.py b/中国国家公路网-国道/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/中国国家公路网-国道/utils/factory.py b/中国国家公路网-国道/utils/factory.py new file mode 100644 index 0000000..29520e5 --- /dev/null +++ b/中国国家公路网-国道/utils/factory.py @@ -0,0 +1,14 @@ +import svgwrite + +class TextFactory: + + def type_a_text(container, text, color, size, x, y): + return TextFactory.text(container, text, 'A型交通标志专用字体', color, size, x, y) + + def type_b_text(container, text, color, size, x, y): + return TextFactory.text(container, text, 'B型交通标志专用字体', color, size, x, y) + + def text(container, text, font, color, size, x, y): + x_loc = x + y_loc = y + size * 0.8 + return container.text(text, insert=(x_loc, y_loc), fill=color, font_family=font, font_size=size) \ No newline at end of file diff --git a/中国国家公路网-国道/utils/font_size.py b/中国国家公路网-国道/utils/font_size.py new file mode 100644 index 0000000..f857a0a --- /dev/null +++ b/中国国家公路网-国道/utils/font_size.py @@ -0,0 +1,15 @@ +from PIL import ImageFont + +class FontSize: + def get_font_width(text, font, size): + return sum([ImageFont.truetype(font, size, 0).getsize(char)[0] for char in text]) + + def font_size_width_dict(font, size): + dict = {} + for char in range(ord('0'), ord('9') + 1): + dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size + for char in range(ord('A'), ord('Z') + 1): + dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size + for char in range(ord('a'), ord('z') + 1): + dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size + return dict \ No newline at end of file diff --git a/中国国家公路网-国道/utils/width.json b/中国国家公路网-国道/utils/width.json new file mode 100644 index 0000000..d4400be --- /dev/null +++ b/中国国家公路网-国道/utils/width.json @@ -0,0 +1,64 @@ +{ + "0": 0.52, + "1": 0.3, + "2": 0.5, + "3": 0.46, + "4": 0.48, + "5": 0.5, + "6": 0.5, + "7": 0.46, + "8": 0.5, + "9": 0.5, + "A": 0.5, + "B": 0.48, + "C": 0.5, + "D": 0.5, + "E": 0.42, + "F": 0.42, + "G": 0.5, + "H": 0.52, + "I": 0.22, + "J": 0.46, + "K": 0.48, + "L": 0.44, + "M": 0.58, + "N": 0.52, + "O": 0.54, + "P": 0.48, + "Q": 0.54, + "R": 0.48, + "S": 0.44, + "T": 0.38, + "U": 0.52, + "V": 0.46, + "W": 0.54, + "X": 0.48, + "Y": 0.5, + "Z": 0.44, + "a": 0.4, + "b": 0.42, + "c": 0.34, + "d": 0.42, + "e": 0.38, + "f": 0.22, + "g": 0.4, + "h": 0.4, + "i": 0.22, + "j": 0.2, + "k": 0.38, + "l": 0.2, + "m": 0.6, + "n": 0.4, + "o": 0.4, + "p": 0.42, + "q": 0.42, + "r": 0.28, + "s": 0.34, + "t": 0.26, + "u": 0.4, + "v": 0.38, + "w": 0.5, + "x": 0.38, + "y": 0.42, + "z": 0.36 +} \ No newline at end of file diff --git a/中国国家公路网-省道/SXXX.py b/中国国家公路网-省道/SXXX.py new file mode 100644 index 0000000..2f3764e --- /dev/null +++ b/中国国家公路网-省道/SXXX.py @@ -0,0 +1,55 @@ +import svgwrite +import cairosvg +from lxml import etree +import os +from utils.font_size import FontSize + +# config +width = 1920 +height = 960 +stroke_width = 40 +out_r = stroke_width * 4 +mid_r = stroke_width * 3 +in_r = stroke_width * 2 + +for num in range(1, 1000): + text = 'S{}'.format(str(num).zfill(3)) + text_h = 880 + text_full_width = FontSize.get_font_width(text, './utils/B.ttf', text_h) + + # rect + dwg = svgwrite.Drawing('./{}.svg'.format(text), profile='tiny', width=width, height=height) + dwg.add(dwg.rect(insert=(0, 0), size=(width, height), rx=out_r, ry=out_r, fill="yellow")) + dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width - stroke_width * 2, height - stroke_width * 2), rx=mid_r, ry=mid_r, fill="black")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 4, height - stroke_width * 4), rx=in_r, ry=in_r, fill="#f4ec17")) + + # text + y_offset = -180 + text_x = (width - text_full_width) / 2 + text_y = (height + text_h) / 2 + y_offset + dwg.add(dwg.text(text, insert=(text_x, text_y), fill="black", font_family="B型交通标志专用字体",font_size=text_h)) + + # export + dwg.save() + + # 解析SVG文件 + svg_file = './{}.svg'.format(text) + with open(svg_file, 'rb') as f: + svg_data = f.read() + parser = etree.XMLParser(remove_blank_text=True) + svg_tree = etree.fromstring(svg_data, parser) + + for element in svg_tree.iter(): + if 'height' in element.attrib: + element.attrib['height'] = element.attrib['height'].replace('100%', '{}'.format(height + stroke_width * 2)) + if 'width' in element.attrib: + element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2)) + + # 保存修改后的SVG文件 + with open('./{}.svg'.format(text), 'wb') as f: + f.write(etree.tostring(svg_tree, pretty_print=True)) + + cairosvg.svg2png(url='./{}.svg'.format(text), write_to='./{}.png'.format(text)) + os.remove('./{}.svg'.format(text)) + print('{}标志生成完成'.format(text)) + \ No newline at end of file diff --git a/中国国家公路网-省道/utils/A.ttf b/中国国家公路网-省道/utils/A.ttf new file mode 100644 index 0000000..22ea22b Binary files /dev/null and b/中国国家公路网-省道/utils/A.ttf differ diff --git a/中国国家公路网-省道/utils/B.ttf b/中国国家公路网-省道/utils/B.ttf new file mode 100644 index 0000000..ca37cd5 Binary files /dev/null and b/中国国家公路网-省道/utils/B.ttf differ diff --git a/中国国家公路网-省道/utils/C.ttf b/中国国家公路网-省道/utils/C.ttf new file mode 100644 index 0000000..2ec40c0 Binary files /dev/null and b/中国国家公路网-省道/utils/C.ttf differ diff --git a/中国国家公路网-省道/utils/__init__.py b/中国国家公路网-省道/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/中国国家公路网-省道/utils/factory.py b/中国国家公路网-省道/utils/factory.py new file mode 100644 index 0000000..29520e5 --- /dev/null +++ b/中国国家公路网-省道/utils/factory.py @@ -0,0 +1,14 @@ +import svgwrite + +class TextFactory: + + def type_a_text(container, text, color, size, x, y): + return TextFactory.text(container, text, 'A型交通标志专用字体', color, size, x, y) + + def type_b_text(container, text, color, size, x, y): + return TextFactory.text(container, text, 'B型交通标志专用字体', color, size, x, y) + + def text(container, text, font, color, size, x, y): + x_loc = x + y_loc = y + size * 0.8 + return container.text(text, insert=(x_loc, y_loc), fill=color, font_family=font, font_size=size) \ No newline at end of file diff --git a/中国国家公路网-省道/utils/font_size.py b/中国国家公路网-省道/utils/font_size.py new file mode 100644 index 0000000..f857a0a --- /dev/null +++ b/中国国家公路网-省道/utils/font_size.py @@ -0,0 +1,15 @@ +from PIL import ImageFont + +class FontSize: + def get_font_width(text, font, size): + return sum([ImageFont.truetype(font, size, 0).getsize(char)[0] for char in text]) + + def font_size_width_dict(font, size): + dict = {} + for char in range(ord('0'), ord('9') + 1): + dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size + for char in range(ord('A'), ord('Z') + 1): + dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size + for char in range(ord('a'), ord('z') + 1): + dict[chr(char)] = ImageFont.truetype(font, size, 0).getsize(chr(char))[0] / size + return dict \ No newline at end of file diff --git a/中国国家公路网-省道/utils/width.json b/中国国家公路网-省道/utils/width.json new file mode 100644 index 0000000..d4400be --- /dev/null +++ b/中国国家公路网-省道/utils/width.json @@ -0,0 +1,64 @@ +{ + "0": 0.52, + "1": 0.3, + "2": 0.5, + "3": 0.46, + "4": 0.48, + "5": 0.5, + "6": 0.5, + "7": 0.46, + "8": 0.5, + "9": 0.5, + "A": 0.5, + "B": 0.48, + "C": 0.5, + "D": 0.5, + "E": 0.42, + "F": 0.42, + "G": 0.5, + "H": 0.52, + "I": 0.22, + "J": 0.46, + "K": 0.48, + "L": 0.44, + "M": 0.58, + "N": 0.52, + "O": 0.54, + "P": 0.48, + "Q": 0.54, + "R": 0.48, + "S": 0.44, + "T": 0.38, + "U": 0.52, + "V": 0.46, + "W": 0.54, + "X": 0.48, + "Y": 0.5, + "Z": 0.44, + "a": 0.4, + "b": 0.42, + "c": 0.34, + "d": 0.42, + "e": 0.38, + "f": 0.22, + "g": 0.4, + "h": 0.4, + "i": 0.22, + "j": 0.2, + "k": 0.38, + "l": 0.2, + "m": 0.6, + "n": 0.4, + "o": 0.4, + "p": 0.42, + "q": 0.42, + "r": 0.28, + "s": 0.34, + "t": 0.26, + "u": 0.4, + "v": 0.38, + "w": 0.5, + "x": 0.38, + "y": 0.42, + "z": 0.36 +} \ No newline at end of file diff --git a/中国国家高速公路网/中国国家高速公路网-东西横线和南北纵线/GXX.py b/中国国家高速公路网/中国国家高速公路网-东西横线和南北纵线/GXX.py new file mode 100644 index 0000000..d983442 --- /dev/null +++ b/中国国家高速公路网/中国国家高速公路网-东西横线和南北纵线/GXX.py @@ -0,0 +1,108 @@ +import svgwrite +import cairosvg +from lxml import etree +import os + +# config +width = 1800 +height = 1600 +top_height = 250 +stroke_width = 30 +out_r = stroke_width * 3 +in_r = stroke_width * 2 + +highway_map = { + 11: '鹤大', + 15: '沈海', + 25: '长深', + 35: '济广', + 45: '大广', + 55: '二广', + 59: '呼北', + 65: '包茂', + 69: '银百', + 75: '兰海', + 85: '银昆', + 10: '绥满', + 12: '珲乌', + 16: '丹锡', + 18: '荣乌', + 20: '青银', + 22: '青兰', + 30: '连霍', + 36: '宁洛', + 40: '沪陕', + 42: '沪蓉', + 50: '沪渝', + 56: '杭瑞', + 60: '沪昆', + 70: '福银', + 72: '泉南', + 76: '厦蓉', + 78: '汕昆', + 80: '广昆', +} + +for num, name in highway_map.items(): + text = 'G{}'.format(num) + text_h = 1000 + text_full_width = 0 + for n in text: + if n == '1': + text_full_width += text_h * 0.3 + else: + text_full_width += text_h * 0.5 + + # rect + dwg = svgwrite.Drawing('./{}.svg'.format(text), profile='tiny', width=width, height=height) + dwg.add(dwg.rect(insert=(0, 0), size=(width + 2 * stroke_width, height + 2 * stroke_width), rx=out_r, ry=out_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width, height), rx=out_r, ry=out_r, fill="white")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, top_height), rx=in_r, ry=in_r, fill="red")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2 + top_height / 2), size=(width - stroke_width * 2, top_height / 2), fill="red")) + + # top text + top_text = '国  家  高  速' + top_text_size = 150 + top_text_x = (width - top_text_size * len(top_text)) / 2 + 380 + top_text_y = (top_height + top_text_size) / 2 + stroke_width - 25 + dwg.add(dwg.text(top_text, insert=(stroke_width + top_text_x, stroke_width + top_text_y), fill="white", font_family="A型交通标志专用字体",font_size=top_text_size)) + + # num + y_offset = -240 + text_x = (width - text_full_width) / 2 + text_y = (height + text_h + top_height) / 2 + y_offset - 200 + dwg.add(dwg.text(text, insert=(stroke_width + text_x, stroke_width + text_y), fill="white", font_family="B型交通标志专用字体",font_size=text_h)) + + # name + name_text = ' '.join(name + '高速') + name_text_size = 280 + name_text_x = (width - name_text_size * len(name_text)) / 2 + 300 + name_text_y = top_text_y + top_text_size + 1000 + dwg.add(dwg.text(name_text, insert=(stroke_width + name_text_x, stroke_width + name_text_y), fill="white", font_family="A型交通标志专用字体",font_size=name_text_size)) + + # export + dwg.save() + + # 解析SVG文件 + svg_file = './{}.svg'.format(text) + with open(svg_file, 'rb') as f: + svg_data = f.read() + parser = etree.XMLParser(remove_blank_text=True) + svg_tree = etree.fromstring(svg_data, parser) + + for element in svg_tree.iter(): + if 'height' in element.attrib: + element.attrib['height'] = element.attrib['height'].replace('100%', '{}'.format(height + stroke_width * 2)) + if 'width' in element.attrib: + element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2)) + + # 保存修改后的SVG文件 + with open('./{}.svg'.format(text), 'wb') as f: + f.write(etree.tostring(svg_tree, pretty_print=True)) + + cairosvg.svg2png(url='./{}.svg'.format(text), write_to='./{}.png'.format(text)) + os.remove('./{}.svg'.format(text)) + print('{}标志生成完成'.format(text)) + \ No newline at end of file diff --git a/中国国家高速公路网/中国国家高速公路网-地区环线/G9X.py b/中国国家高速公路网/中国国家高速公路网-地区环线/G9X.py new file mode 100644 index 0000000..dc84e54 --- /dev/null +++ b/中国国家高速公路网/中国国家高速公路网-地区环线/G9X.py @@ -0,0 +1,85 @@ +import svgwrite +import cairosvg +from lxml import etree +import os + +# config +width = 2000 +height = 1600 +top_height = 250 +stroke_width = 30 +out_r = stroke_width * 3 +in_r = stroke_width * 2 + +highway_map = { + 91: '辽中环线', + 92: '杭州湾环线', + 93: '成渝环线', + 94: '珠三角环线', + 95: '首都环线', + 98: '海南环岛' +} + +for num, name in highway_map.items(): + text = 'G{}'.format(num) + text_h = 1000 + text_full_width = 0 + for n in text: + if n == '1': + text_full_width += text_h * 0.3 + else: + text_full_width += text_h * 0.5 + + # rect + dwg = svgwrite.Drawing('./{}.svg'.format(text), profile='tiny', width=width, height=height) + dwg.add(dwg.rect(insert=(0, 0), size=(width + 2 * stroke_width, height + 2 * stroke_width), rx=out_r, ry=out_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width, height), rx=out_r, ry=out_r, fill="white")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, top_height), rx=in_r, ry=in_r, fill="red")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2 + top_height / 2), size=(width - stroke_width * 2, top_height / 2), fill="red")) + + # top text + top_text = '国  家  高  速' + top_text_size = 150 + top_text_x = (width - top_text_size * len(top_text)) / 2 + 380 + top_text_y = (top_height + top_text_size) / 2 + stroke_width - 25 + dwg.add(dwg.text(top_text, insert=(stroke_width + top_text_x, stroke_width + top_text_y), fill="white", font_family="A型交通标志专用字体",font_size=top_text_size)) + + # num + y_offset = -240 + text_x = (width - text_full_width) / 2 + text_y = (height + text_h + top_height) / 2 + y_offset - 200 + dwg.add(dwg.text(text, insert=(stroke_width + text_x, stroke_width + text_y), fill="white", font_family="B型交通标志专用字体",font_size=text_h)) + + # name + name_text = name + '高速' + name_text_size = 260 + name_text_x = (width - name_text_size * len(name_text)) / 2 + 10 + name_text_y = top_text_y + top_text_size + 1000 + dwg.add(dwg.text(name_text, insert=(stroke_width + name_text_x, stroke_width + name_text_y), fill="white", font_family="A型交通标志专用字体",font_size=name_text_size)) + + # export + dwg.save() + + # 解析SVG文件 + svg_file = './{}.svg'.format(text) + with open(svg_file, 'rb') as f: + svg_data = f.read() + parser = etree.XMLParser(remove_blank_text=True) + svg_tree = etree.fromstring(svg_data, parser) + + for element in svg_tree.iter(): + if 'height' in element.attrib: + element.attrib['height'] = element.attrib['height'].replace('100%', '{}'.format(height + stroke_width * 2)) + if 'width' in element.attrib: + element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2)) + + # 保存修改后的SVG文件 + with open('./{}.svg'.format(text), 'wb') as f: + f.write(etree.tostring(svg_tree, pretty_print=True)) + + cairosvg.svg2png(url='./{}.svg'.format(text), write_to='./{}.png'.format(text)) + os.remove('./{}.svg'.format(text)) + print('{}标志生成完成'.format(text)) + \ No newline at end of file diff --git a/中国国家高速公路网/中国国家高速公路网-绕城高速/GXX0X.py b/中国国家高速公路网/中国国家高速公路网-绕城高速/GXX0X.py new file mode 100644 index 0000000..0232a78 --- /dev/null +++ b/中国国家高速公路网/中国国家高速公路网-绕城高速/GXX0X.py @@ -0,0 +1,106 @@ +import svgwrite +import cairosvg +from lxml import etree +import os +import csv + +# config +width = 2000 +height = 1400 +top_height = 250 +stroke_width = 30 +out_r = stroke_width * 3 +in_r = stroke_width * 2 + +highway_map = {} +with open('data.csv', 'r') as file: + reader = csv.DictReader(file) + for row in reader: + highway_map[row['num']] = row['name'] + +for num, name in highway_map.items(): + file_name = num + name; + # G+前两位 + big_text = num[:3] + # 后两位 + small_text = num[3:] + + big_text_h = 900 + small_text_h = 600 + + + big_full_width = 0 + small_full_width = 0 + for n in big_text: + if n == '1': + big_full_width += big_text_h * 0.3 + else: + big_full_width += big_text_h * 0.5 + + for n in small_text: + if n == '1': + small_full_width += small_text_h * 0.3 + else: + small_full_width += small_text_h * 0.5 + text_full_width = big_full_width + small_full_width + + # rect + dwg = svgwrite.Drawing('./{}.svg'.format(file_name), profile='tiny', width=width, height=height) + dwg.add(dwg.rect(insert=(0, 0), size=(width + 2 * stroke_width, height + 2 * stroke_width), rx=out_r, ry=out_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width, height), rx=out_r, ry=out_r, fill="white")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, top_height), rx=in_r, ry=in_r, fill="red")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2 + top_height / 2), size=(width - stroke_width * 2, top_height / 2), fill="red")) + + # top text + top_text = '国  家  高  速' + top_text_size = 150 + top_text_x = (width - top_text_size * len(top_text)) / 2 + 380 + top_text_y = (top_height + top_text_size) / 2 + stroke_width - 25 + dwg.add(dwg.text(top_text, insert=(stroke_width + top_text_x, stroke_width + top_text_y), fill="white", font_family="A型交通标志专用字体",font_size=top_text_size)) + + # num + y_offset = -360 + big_text_x = (width - text_full_width) / 2 + big_text_y = (height + big_text_h + top_height) / 2 + y_offset + dwg.add(dwg.text(big_text, insert=(stroke_width + big_text_x, stroke_width + big_text_y), fill="white", font_family="B型交通标志专用字体",font_size=big_text_h)) + + small_text_x = (width - text_full_width) / 2 + big_full_width + dwg.add(dwg.text(small_text, insert=(stroke_width + small_text_x, stroke_width + big_text_y), fill="white", font_family="B型交通标志专用字体",font_size=small_text_h)) + + + # name + name_text = name + if len(name_text) < 8: + name_text_size = 260 + else: + name_text_size = 230 + name_text_x = (width - name_text_size * len(name)) / 2 + name_text_y = top_text_y + top_text_size + 880 + dwg.add(dwg.text(name_text, insert=(stroke_width + name_text_x, stroke_width + name_text_y), fill="white", font_family="A型交通标志专用字体",font_size=name_text_size)) + + # export + dwg.save() + + # 解析SVG文件 + svg_file = './{}.svg'.format(file_name) + with open(svg_file, 'rb') as f: + svg_data = f.read() + parser = etree.XMLParser(remove_blank_text=True) + svg_tree = etree.fromstring(svg_data, parser) + + for element in svg_tree.iter(): + if 'height' in element.attrib: + element.attrib['height'] = element.attrib['height'].replace('100%', '{}'.format(height + stroke_width * 2)) + if 'width' in element.attrib: + element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2)) + + # 保存修改后的SVG文件 + with open('./{}.svg'.format(file_name), 'wb') as f: + f.write(etree.tostring(svg_tree, pretty_print=True)) + + cairosvg.svg2png(url='./{}.svg'.format(file_name), write_to='./{}.png'.format(file_name)) + os.remove('./{}.svg'.format(file_name)) + print('{}标志生成完成'.format(file_name)) + \ No newline at end of file diff --git a/中国国家高速公路网/中国国家高速公路网-绕城高速/data.csv b/中国国家高速公路网/中国国家高速公路网-绕城高速/data.csv new file mode 100644 index 0000000..47e9ae4 --- /dev/null +++ b/中国国家高速公路网/中国国家高速公路网-绕城高速/data.csv @@ -0,0 +1,31 @@ +num,name +G0401,ɳƳǸ +G0601,ƳǸ +G1501,ƳǸ +G1503,ϺƳǸ +G1504,ƳǸ +G1505,ƳǸ +G1508,ƳǸ +G2501,ƳǸ +G2502,ƳǸ +G2503,ϾƳǸ +G2504,ƳǸ +G4501,ƳǸ +G5901,ͺƳǸ +G1001,ƳǸ +G2001,ƳǸ +G2002,ʯׯƳǸ +G2003,̫ԭƳǸ +G2004,ƳǸ +G2201,ƳǸ +G3001,֣ƳǸ +G3002,ƳǸ +G3003,³ľƳǸ +G4001,ϷƳǸ +G4201,人ƳǸ +G4202,ɶƳǸ +G5001,ƳǸ +G5601,ƳǸ +G6001,ϲƳǸ +G6002,ƳǸ +G7201,ƳǸ diff --git a/中国国家高速公路网/中国国家高速公路网-绕城高速/data.xlsx b/中国国家高速公路网/中国国家高速公路网-绕城高速/data.xlsx new file mode 100644 index 0000000..f6e40b0 Binary files /dev/null and b/中国国家高速公路网/中国国家高速公路网-绕城高速/data.xlsx differ diff --git a/中国国家高速公路网/中国国家高速公路网-联络线和并行线/GXXXX.py b/中国国家高速公路网/中国国家高速公路网-联络线和并行线/GXXXX.py new file mode 100644 index 0000000..42d5582 --- /dev/null +++ b/中国国家高速公路网/中国国家高速公路网-联络线和并行线/GXXXX.py @@ -0,0 +1,103 @@ +import svgwrite +import cairosvg +from lxml import etree +import os +import csv + +# config +width = 2000 +height = 1400 +top_height = 250 +stroke_width = 30 +out_r = stroke_width * 3 +in_r = stroke_width * 2 + +highway_map = {} +with open('data.csv', 'r') as file: + reader = csv.DictReader(file) + for row in reader: + highway_map[row['num']] = row['name'] + +for num, name in highway_map.items(): + file_name = num + name; + # G+前两位 + big_text = num[:3] + # 后两位 + small_text = num[3:] + + big_text_h = 900 + small_text_h = 600 + + + big_full_width = 0 + small_full_width = 0 + for n in big_text: + if n == '1': + big_full_width += big_text_h * 0.3 + else: + big_full_width += big_text_h * 0.5 + + for n in small_text: + if n == '1': + small_full_width += small_text_h * 0.3 + else: + small_full_width += small_text_h * 0.5 + text_full_width = big_full_width + small_full_width + + # rect + dwg = svgwrite.Drawing('./{}.svg'.format(file_name), profile='tiny', width=width, height=height) + dwg.add(dwg.rect(insert=(0, 0), size=(width + 2 * stroke_width, height + 2 * stroke_width), rx=out_r, ry=out_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width, height), rx=out_r, ry=out_r, fill="white")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, top_height), rx=in_r, ry=in_r, fill="red")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2 + top_height / 2), size=(width - stroke_width * 2, top_height / 2), fill="red")) + + # top text + top_text = '国  家  高  速' + top_text_size = 150 + top_text_x = (width - top_text_size * len(top_text)) / 2 + 380 + top_text_y = (top_height + top_text_size) / 2 + stroke_width - 25 + dwg.add(dwg.text(top_text, insert=(stroke_width + top_text_x, stroke_width + top_text_y), fill="white", font_family="A型交通标志专用字体",font_size=top_text_size)) + + # num + y_offset = -360 + big_text_x = (width - text_full_width) / 2 + big_text_y = (height + big_text_h + top_height) / 2 + y_offset + dwg.add(dwg.text(big_text, insert=(stroke_width + big_text_x, stroke_width + big_text_y), fill="white", font_family="B型交通标志专用字体",font_size=big_text_h)) + + small_text_x = (width - text_full_width) / 2 + big_full_width + dwg.add(dwg.text(small_text, insert=(stroke_width + small_text_x, stroke_width + big_text_y), fill="white", font_family="B型交通标志专用字体",font_size=small_text_h)) + + + # name + name_text = ' '.join(name) + name_text_size = 280 + name_text_x = (width - name_text_size * len(name) * 1.2) / 2 + name_text_y = top_text_y + top_text_size + 880 + dwg.add(dwg.text(name_text, insert=(stroke_width + name_text_x, stroke_width + name_text_y), fill="white", font_family="A型交通标志专用字体",font_size=name_text_size)) + + # export + dwg.save() + + # 解析SVG文件 + svg_file = './{}.svg'.format(file_name) + with open(svg_file, 'rb') as f: + svg_data = f.read() + parser = etree.XMLParser(remove_blank_text=True) + svg_tree = etree.fromstring(svg_data, parser) + + for element in svg_tree.iter(): + if 'height' in element.attrib: + element.attrib['height'] = element.attrib['height'].replace('100%', '{}'.format(height + stroke_width * 2)) + if 'width' in element.attrib: + element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2)) + + # 保存修改后的SVG文件 + with open('./{}.svg'.format(file_name), 'wb') as f: + f.write(etree.tostring(svg_tree, pretty_print=True)) + + cairosvg.svg2png(url='./{}.svg'.format(file_name), write_to='./{}.png'.format(file_name)) + os.remove('./{}.svg'.format(file_name)) + print('{}标志生成完成'.format(file_name)) + \ No newline at end of file diff --git a/中国国家高速公路网/中国国家高速公路网-联络线和并行线/data.csv b/中国国家高速公路网/中国国家高速公路网-联络线和并行线/data.csv new file mode 100644 index 0000000..45447b8 --- /dev/null +++ b/中国国家高速公路网/中国国家高速公路网-联络线和并行线/data.csv @@ -0,0 +1,195 @@ +num,name +G0111,ر +G0112,ɸ +G0121,ظ +G0122, +G0211,ʯ +G0212, +G0311,ĸ +G0321,ϸ +G0322,¸ +G0323,úϸ +G0411, +G0412,ϸ +G0413,ø +G0421, +G0422, +G0423,ֹ +G0424, +G0425,ĸ +G0511,¶ +G0512,ָ +G0513,ƽ +G0611, +G0612,͸ +G0613, +G0615,¿ +G0616,ڸʸ +G0711, +G0712,߸ +G1111,׹ +G1112,˫ +G1113, +G1115, +G1116, +G1117,籱 +G1118, +G1119,ٸ +G1131,ĵӸ +G1511, +G1512, +G1513, +G1514,ϸ +G1515,ξ +G1516, +G1517,׸ +G1518,ΰ +G1519, +G1521,θ +G1522,̨ +G1523,ݸ +G1531,ȸ +G1532,Ȫ÷ +G1533,Ȫ +G1534,ý +G1535,ϸ +G1536,ݸ +G2511,³ +G2512, +G2513, +G2515,³ +G2516, +G2517,ɳø +G2518,᯸ +G2519, +G2531,ϸ +G3511,ʱ +G3512,ѰӸ +G4511,Ӹ +G4512,˫۸ +G4513,Ӫ +G4515, +G5511, +G5512,¸ +G5513,Ÿ +G5515,ϸ +G5516,Ÿ +G5517, +G5518, +G5911,˷̫ +G5912, +G6511, +G6512,Ӹ +G6517, +G6521, +G6522, +G6911, +G7511,ն +G7512,ظ +G7521, +G7522, +G8511,ĥ +G8512, +G8513,ƽ +G8515, +G8516,ظ +G8517,˸ +G1011,ͬ +G1012,ڸ +G1013,Ÿ +G1015,Ƹ +G1016,˫ +G1017,Ӹ +G1211,ڸ +G1212,򼪸 +G1213,Į +G1215,ɳ +G1216,ڰ +G1221,ӳ +G1611,˳и +G1612, +G1811,ʯ +G1812,ܸ +G1813, +G1815,Ϋո +G1816, +G1817, +G1818,¸ +G2011,¸ +G2012, +G2211,Ӹ +G3011, +G3012,º͸ +G3013, +G3014, +G3015, +G3016, +G3017, +G3018, +G3019, +G3021,˸ +G3031,̸̹ +G3032, +G3033, +G3035,¸ +G3036, +G3611,Ÿ +G3612,ƽ˸ +G3613,ڸ +G3615,¬ +G4011, +G4012, +G4013,ָ +G4015, +G4211,߸ +G4212,ϰ +G4213,鰲 +G4215, +G4216, +G4217,ز +G4218,Ҷ +G4219,˸ +G4221, +G4222, +G4223, +G4231,Ÿ +G5011,ߺϸ +G5012, +G5013,ظ +G5015, +G5016,˻ +G5021,ʯ +G5611, +G5612,ٸ +G5613, +G5615, +G5616, +G5617,¸ +G5618, +G5621, +G6011,ظ +G6012,ָ +G6021, +G6022,¦ +G6023,Ϸ +G6025, +G7011,ʮ +G7012, +G7013,ɳϸ +G7021, +G7211,Ѹ +G7212, +G7221,ϸ +G7611, +G7612,˸ +G8011,Ӹ +G8012,ֳ +G8013,ĸ +G9111, +G9211,۸ +G9221, +G9411,ݸ +G9511,䵸 +G9811,ָ +G9812, +G9813, diff --git a/中国国家高速公路网/中国国家高速公路网-联络线和并行线/data.xlsx b/中国国家高速公路网/中国国家高速公路网-联络线和并行线/data.xlsx new file mode 100644 index 0000000..fb48bc3 Binary files /dev/null and b/中国国家高速公路网/中国国家高速公路网-联络线和并行线/data.xlsx differ diff --git a/中国国家高速公路网/中国国家高速公路网-都市圈环线/G99XX.py b/中国国家高速公路网/中国国家高速公路网-都市圈环线/G99XX.py new file mode 100644 index 0000000..9900f72 --- /dev/null +++ b/中国国家高速公路网/中国国家高速公路网-都市圈环线/G99XX.py @@ -0,0 +1,110 @@ +import svgwrite +import cairosvg +from lxml import etree +import os + +# config +width = 2000 +height = 1400 +top_height = 250 +stroke_width = 30 +out_r = stroke_width * 3 +in_r = stroke_width * 2 + +highway_map = { + 'G9901': '哈尔滨都市圈环线', + 'G9902': '长春都市圈环线', + 'G9903': '杭州都市圈环线', + 'G9904': '南京都市圈环线', + 'G9905': '郑州都市圈环线', + 'G9906': '武汉都市圈环线', + 'G9907': '长株潭都市圈环线', + 'G9908': '西安都市圈环线', + 'G9909': '重庆都市圈环线', + 'G9910': '成都都市圈环线', + 'G9911': '济南都市圈环线', + 'G9912': '合肥都市圈环线' +} + +for num, name in highway_map.items(): + file_name = num + name; + # G+前两位 + big_text = num[:3] + # 后两位 + small_text = num[3:] + + big_text_h = 850 + small_text_h = 570 + + + big_full_width = 0 + small_full_width = 0 + for n in big_text: + if n == '1': + big_full_width += big_text_h * 0.3 + else: + big_full_width += big_text_h * 0.5 + + for n in small_text: + if n == '1': + small_full_width += small_text_h * 0.3 + else: + small_full_width += small_text_h * 0.5 + text_full_width = big_full_width + small_full_width + + # rect + dwg = svgwrite.Drawing('./{}.svg'.format(file_name), profile='tiny', width=width, height=height) + dwg.add(dwg.rect(insert=(0, 0), size=(width + 2 * stroke_width, height + 2 * stroke_width), rx=out_r, ry=out_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width, height), rx=out_r, ry=out_r, fill="white")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, top_height), rx=in_r, ry=in_r, fill="red")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2 + top_height / 2), size=(width - stroke_width * 2, top_height / 2), fill="red")) + + # top text + top_text = '国  家  高  速' + top_text_size = 150 + top_text_x = (width - top_text_size * len(top_text)) / 2 + 380 + top_text_y = (top_height + top_text_size) / 2 + stroke_width - 25 + dwg.add(dwg.text(top_text, insert=(stroke_width + top_text_x, stroke_width + top_text_y), fill="white", font_family="A型交通标志专用字体",font_size=top_text_size)) + + # num + y_offset = -360 + big_text_x = (width - text_full_width) / 2 + big_text_y = (height + big_text_h + top_height) / 2 + y_offset + dwg.add(dwg.text(big_text, insert=(stroke_width + big_text_x, stroke_width + big_text_y), fill="white", font_family="B型交通标志专用字体",font_size=big_text_h)) + + small_text_x = (width - text_full_width) / 2 + big_full_width + dwg.add(dwg.text(small_text, insert=(stroke_width + small_text_x, stroke_width + big_text_y), fill="white", font_family="B型交通标志专用字体",font_size=small_text_h)) + + + # name + name_text_size = 220 + name_text_x = (width - name_text_size * len(name)) / 2 + name_text_y = top_text_y + top_text_size + 880 + dwg.add(dwg.text(name, insert=(stroke_width + name_text_x, stroke_width + name_text_y), fill="white", font_family="A型交通标志专用字体",font_size=name_text_size)) + + # export + dwg.save() + + # 解析SVG文件 + svg_file = './{}.svg'.format(file_name) + with open(svg_file, 'rb') as f: + svg_data = f.read() + parser = etree.XMLParser(remove_blank_text=True) + svg_tree = etree.fromstring(svg_data, parser) + + for element in svg_tree.iter(): + if 'height' in element.attrib: + element.attrib['height'] = element.attrib['height'].replace('100%', '{}'.format(height + stroke_width * 2)) + if 'width' in element.attrib: + element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2)) + + # 保存修改后的SVG文件 + with open('./{}.svg'.format(file_name), 'wb') as f: + f.write(etree.tostring(svg_tree, pretty_print=True)) + + cairosvg.svg2png(url='./{}.svg'.format(file_name), write_to='./{}.png'.format(file_name)) + os.remove('./{}.svg'.format(file_name)) + print('{}标志生成完成'.format(file_name)) + \ No newline at end of file diff --git a/中国国家高速公路网/中国国家高速公路网-首都放射线/GX.py b/中国国家高速公路网/中国国家高速公路网-首都放射线/GX.py new file mode 100644 index 0000000..e243123 --- /dev/null +++ b/中国国家高速公路网/中国国家高速公路网-首都放射线/GX.py @@ -0,0 +1,90 @@ +import svgwrite +import cairosvg +from lxml import etree +import os + +# config +width = 1600 +height = 1600 +top_height = 250 +stroke_width = 30 +out_r = stroke_width * 3 +in_r = stroke_width * 2 + +highway_map = { + 1: '哈', + 2: '沪', + 3: '台', + 4: '港澳', + 5: '昆', + 6: '藏', + 7: '新' +} + +for num, name in highway_map.items(): + text = 'G{}'.format(num) + text_h = 1000 + text_full_width = 0 + for n in text: + if n == '1': + text_full_width += text_h * 0.3 + else: + text_full_width += text_h * 0.5 + + # rect + dwg = svgwrite.Drawing('./{}.svg'.format(text), profile='tiny', width=width, height=height) + dwg.add(dwg.rect(insert=(0, 0), size=(width + 2 * stroke_width, height + 2 * stroke_width), rx=out_r, ry=out_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width, stroke_width), size=(width, height), rx=out_r, ry=out_r, fill="white")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, height - stroke_width * 2), rx=in_r, ry=in_r, fill="green")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2), size=(width - stroke_width * 2, top_height), rx=in_r, ry=in_r, fill="red")) + dwg.add(dwg.rect(insert=(stroke_width * 2, stroke_width * 2 + top_height / 2), size=(width - stroke_width * 2, top_height / 2), fill="red")) + + # top text + top_text = '国  家  高  速' + top_text_size = 150 + top_text_x = (width - top_text_size * len(top_text)) / 2 + 380 + top_text_y = (top_height + top_text_size) / 2 + stroke_width - 25 + dwg.add(dwg.text(top_text, insert=(stroke_width + top_text_x, stroke_width + top_text_y), fill="white", font_family="A型交通标志专用字体",font_size=top_text_size)) + + # num + y_offset = -240 + text_x = (width - text_full_width) / 2 + text_y = (height + text_h + top_height) / 2 + y_offset - 200 + dwg.add(dwg.text(text, insert=(stroke_width + text_x, stroke_width + text_y), fill="white", font_family="B型交通标志专用字体",font_size=text_h)) + + # name + name_text_size = 260 + if len(name) == 1: + name_text = ' '.join('京{}高速'.format(name)) + name_text_x = (width - name_text_size * len(name_text) * 0.69) / 2 + else: + name_text = '京{}高速'.format(name) + name_text_x = (width - name_text_size * len(name_text)) / 2 + name_text_y = top_text_y + top_text_size + 1000 + dwg.add(dwg.text(name_text, insert=(stroke_width + name_text_x, stroke_width + name_text_y), fill="white", font_family="A型交通标志专用字体",font_size=name_text_size)) + + # export + dwg.save() + + # 解析SVG文件 + svg_file = './{}.svg'.format(text) + with open(svg_file, 'rb') as f: + svg_data = f.read() + parser = etree.XMLParser(remove_blank_text=True) + svg_tree = etree.fromstring(svg_data, parser) + + for element in svg_tree.iter(): + if 'height' in element.attrib: + element.attrib['height'] = element.attrib['height'].replace('100%', '{}'.format(height + stroke_width * 2)) + if 'width' in element.attrib: + element.attrib['width'] = element.attrib['width'].replace('100%', '{}'.format(width + stroke_width * 2)) + + # 保存修改后的SVG文件 + with open('./{}.svg'.format(text), 'wb') as f: + f.write(etree.tostring(svg_tree, pretty_print=True)) + + cairosvg.svg2png(url='./{}.svg'.format(text), write_to='./{}.png'.format(text)) + os.remove('./{}.svg'.format(text)) + print('{}标志生成完成'.format(text)) + \ No newline at end of file