From 9fa93fa9d820e19663685b758b0344cd01342b9f Mon Sep 17 00:00:00 2001 From: Zhang Muyu Date: Fri, 22 Sep 2023 00:19:00 +0800 Subject: [PATCH] rename. --- README.md | 6 +- {test => main}/distance.py | 0 {test => main}/main.py | 0 {test => main}/sa_pa.py | 0 test/test.py | 113 ------------------------------------- 5 files changed, 3 insertions(+), 116 deletions(-) rename {test => main}/distance.py (100%) rename {test => main}/main.py (100%) rename {test => main}/sa_pa.py (100%) delete mode 100644 test/test.py diff --git a/README.md b/README.md index 40412fc..0faef61 100644 --- a/README.md +++ b/README.md @@ -21,15 +21,15 @@ ## 使用 - 出口预告/直行标志 ```sh -python ./test/main.py -d filepath +python ./main/main.py -d filepath ``` - 服务区预告标志 ```sh -python ./test/sa_pa.py -d filepath +python ./main/sa_pa.py -d filepath ``` - 地点距离预告标志 ```sh -python ./test/distance.py -d filepath +python ./main/distance.py -d filepath ``` ## 组件介绍 diff --git a/test/distance.py b/main/distance.py similarity index 100% rename from test/distance.py rename to main/distance.py diff --git a/test/main.py b/main/main.py similarity index 100% rename from test/main.py rename to main/main.py diff --git a/test/sa_pa.py b/main/sa_pa.py similarity index 100% rename from test/sa_pa.py rename to main/sa_pa.py diff --git a/test/test.py b/test/test.py deleted file mode 100644 index 638da8f..0000000 --- a/test/test.py +++ /dev/null @@ -1,113 +0,0 @@ -import svgwrite -import cairosvg -import os -import base64 - -from lxml import etree - -import sys -sys.path.append(os.getcwd()) - -from utils.font_size import * - -from components.text import * -from components.rect import * -from components.common_road import * -from components.special_area import * -from components.express_way import * -from components.exit import * - -# config -width = 550 -height = 550 - -# rect -dwg = svgwrite.Drawing('rect.svg', profile='tiny', width=width, height=height) - -exit_r = ExitComponent('428', 'B') -exit_r.draw(dwg, width - exit_r.width(), 0) - -rect = DoubleStrokeRectComponent(width=width, height=height - 50, main_color='#1f963b', stroke_color='#ffffff', stroke_width=4, r=16) -rect.draw(dwg, 0, 50) - -g_road = CommonRoadNationalComponent('G202') -g_road.draw(dwg, 50, 70) - -p_road = CommonRoadProvincialComponent('S210') -p_road.draw(dwg, 50, 130) - -c_road = CommonRoadTownshipComponent('X021') -c_road.draw(dwg, 50, 190) - -t_road = CommonRoadTownshipComponent('Y101') -t_road.draw(dwg, 50, 250) - -street = StreetComponent('北四环西路') -street.draw(dwg, 200, 70) - -tourist = TouristComponent('湖滨旅游区') -tourist.draw(dwg, 200, 130) - -g2501 = NationalExpressWayComponent('G25', '01') -g2501.draw(dwg, 200, 190) - -g1 = NationalExpressWayComponent('G1', '') -g1.draw(dwg, 300, 190) - -g10 = NationalExpressWayComponent('G10', '') -g10.draw(dwg, 375, 190) - -g55 = NationalExpressWayComponent('G55', '') -g55.draw(dwg, 200, 250) - -g11 = NationalExpressWayComponent('G11', '') -g11.draw(dwg, 300, 250) - -g9902 = NationalExpressWayComponent('G99', '02') -g9902.draw(dwg, 375, 250) - -s50 = ProvincialExpressWayComponent('京', 'S50', '') -s50.draw(dwg, 50, 310) - -s3801 = ProvincialExpressWayComponent('京津冀', 'S3801', '') -s3801.draw(dwg, 150, 310) - -s9955 = ProvincialExpressWayComponent('粤', 'S99', '55') -s9955.draw(dwg, 300, 310) - -text_a = TextAComponent('北京', '#ffffff', 50) -text_a.draw(dwg, 50, 370) - -text_b = TextBComponent('Beijing', '#ffffff', 30) -text_b.draw(dwg, 65, 420) - -png_file = open('./resources/exit.png','rb') -png_obj = png_file.read() -s = base64.b64encode(png_obj) -png_file.close() -png_base64 = s.decode('ascii') -image_size = 70 -# dwg.add(dwg.image(insert=((width - image_size) / 2, height - image_size * 1.2), size=(image_size, image_size), href='data:image/png;base64,{0}'.format(png_base64))) - -# 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')