feat: 出口组件
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -161,4 +161,5 @@ cython_debug/
|
||||
|
||||
*.png
|
||||
*.svg
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
.VSCodeCounter/
|
||||
43
components/exit.py
Normal file
43
components/exit.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from utils.font_size import FontSize
|
||||
from components.text import *
|
||||
from components.rect import *
|
||||
|
||||
|
||||
class ExitComponent:
|
||||
|
||||
def __init__(self, seq, sub) -> None:
|
||||
self.seq = seq
|
||||
self.sub = sub
|
||||
self.p_height = 50
|
||||
self.name = '出口'
|
||||
self.name_size = 20
|
||||
self.seq_size = 40
|
||||
self.sub_size = int(self.seq_size * 0.6)
|
||||
self.name_width = FontSize.get_font_width(self.name, 'resources/A.ttf', self.name_size)
|
||||
self.inset = 6
|
||||
self.seq_width = FontSize.get_font_width(self.seq, 'resources/B.ttf', self.seq_size)
|
||||
self.sub_width = FontSize.get_font_width(self.sub, 'resources/B.ttf', self.sub_size)
|
||||
self.rx = max(40, (self.seq_width + self.sub_width) / 2 + self.inset * 2)
|
||||
self.ry = (self.p_height - 2 * self.inset) / 2
|
||||
|
||||
def width(self):
|
||||
return self.name_width + 2 * self.rx + 3 * self.inset
|
||||
|
||||
def height(self):
|
||||
return self.p_height
|
||||
|
||||
def draw(self, container, x, y):
|
||||
rect = DoubleStrokeRectComponent(self.width(), self.p_height, '#1f963b', '#ffffff', 2, 8)
|
||||
rect.draw(container, x, y)
|
||||
|
||||
name = TextAComponent(self.name, '#ffffff', self.name_size)
|
||||
name.draw(container, x + self.inset, y + (self.p_height - self.name_size) / 2)
|
||||
|
||||
container.add(container.ellipse(center=(x + self.inset * 2 + self.rx + self.name_width, y + self.p_height / 2), r=(self.rx, self.ry), fill='#ffffff'))
|
||||
|
||||
seq = TextBComponent(self.seq, '#1f963b', self.seq_size)
|
||||
seq.draw(container, x + 2 * self.inset + self.name_width + (self.rx * 2 - self.seq_width - self.sub_width) / 2, y + (self.p_height - self.seq_size) / 2)
|
||||
|
||||
if len(self.sub):
|
||||
sub = TextBComponent(self.sub, '#1f963b', self.sub_size)
|
||||
sub.draw(container, x + 2 * self.inset + self.name_width + (self.rx * 2 - self.seq_width - self.sub_width) / 2 + self.seq_width, y + (self.p_height - self.sub_size * 0.6) / 2)
|
||||
19
test/main.py
Normal file
19
test/main.py
Normal file
@@ -0,0 +1,19 @@
|
||||
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 *
|
||||
|
||||
61
test/test.py
61
test/test.py
@@ -1,6 +1,7 @@
|
||||
import svgwrite
|
||||
import cairosvg
|
||||
import os
|
||||
import base64
|
||||
|
||||
from lxml import etree
|
||||
|
||||
@@ -14,67 +15,79 @@ 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 = 500
|
||||
height = 500
|
||||
width = 550
|
||||
height = 550
|
||||
|
||||
# rect
|
||||
dwg = svgwrite.Drawing('rect.svg', profile='tiny', width=width, height=height)
|
||||
|
||||
rect = DoubleStrokeRectComponent(width=width, height=height, main_color='#1f963b', stroke_color='#ffffff', stroke_width=4, r=16)
|
||||
rect.draw(dwg, 0, 0)
|
||||
exit_r = ExitComponent('428', 'B')
|
||||
exit_r.draw(dwg, width - exit_r.width(), 0)
|
||||
|
||||
g_road = CommonRoadNationalComponent('G503')
|
||||
g_road.draw(dwg, 50, 20)
|
||||
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, 80)
|
||||
p_road.draw(dwg, 50, 130)
|
||||
|
||||
c_road = CommonRoadTownshipComponent('X021')
|
||||
c_road.draw(dwg, 50, 140)
|
||||
c_road.draw(dwg, 50, 190)
|
||||
|
||||
t_road = CommonRoadTownshipComponent('Y101')
|
||||
t_road.draw(dwg, 50, 200)
|
||||
t_road.draw(dwg, 50, 250)
|
||||
|
||||
street = StreetComponent('北四环西路')
|
||||
street.draw(dwg, 200, 20)
|
||||
street.draw(dwg, 200, 70)
|
||||
|
||||
tourist = TouristComponent('湖滨旅游区')
|
||||
tourist.draw(dwg, 200, 80)
|
||||
tourist.draw(dwg, 200, 130)
|
||||
|
||||
g2501 = NationalExpressWayComponent('G25', '01')
|
||||
g2501.draw(dwg, 200, 140)
|
||||
g2501.draw(dwg, 200, 190)
|
||||
|
||||
g1 = NationalExpressWayComponent('G1', '')
|
||||
g1.draw(dwg, 300, 140)
|
||||
g1.draw(dwg, 300, 190)
|
||||
|
||||
g10 = NationalExpressWayComponent('G10', '')
|
||||
g10.draw(dwg, 375, 140)
|
||||
g10.draw(dwg, 375, 190)
|
||||
|
||||
g55 = NationalExpressWayComponent('G55', '')
|
||||
g55.draw(dwg, 200, 200)
|
||||
g55.draw(dwg, 200, 250)
|
||||
|
||||
g11 = NationalExpressWayComponent('G11', '')
|
||||
g11.draw(dwg, 300, 200)
|
||||
g11.draw(dwg, 300, 250)
|
||||
|
||||
g9902 = NationalExpressWayComponent('G99', '02')
|
||||
g9902.draw(dwg, 375, 200)
|
||||
g9902.draw(dwg, 375, 250)
|
||||
|
||||
s50 = ProvincialExpressWayComponent('京', 'S50', '')
|
||||
s50.draw(dwg, 50, 260)
|
||||
s50.draw(dwg, 50, 310)
|
||||
|
||||
s3801 = ProvincialExpressWayComponent('京津冀', 'S3801', '')
|
||||
s3801.draw(dwg, 150, 260)
|
||||
s3801.draw(dwg, 150, 310)
|
||||
|
||||
s9955 = ProvincialExpressWayComponent('粤', 'S99', '55')
|
||||
s9955.draw(dwg, 300, 260)
|
||||
s9955.draw(dwg, 300, 310)
|
||||
|
||||
text_a = TextAComponent('北京', '#ffffff', 50)
|
||||
text_a.draw(dwg, 50, 320)
|
||||
text_a.draw(dwg, 50, 370)
|
||||
|
||||
text_b = TextBComponent('X201363', '#ffffff', 50)
|
||||
text_b.draw(dwg, 50, 380)
|
||||
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()
|
||||
@@ -97,4 +110,4 @@ 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')
|
||||
# os.remove('rect.svg')
|
||||
|
||||
Reference in New Issue
Block a user