feat: 跨平台

This commit is contained in:
Zhang Muyu
2023-09-19 00:48:11 +08:00
parent a4d8570078
commit ff0bfad399
2 changed files with 17 additions and 4 deletions

View File

@@ -15,6 +15,7 @@ from reportlab.graphics import renderPM
from utils.font_size import *
from utils.image import *
from utils.platform import *
from components.text import *
from components.rect import *
from components.common_road import *
@@ -23,6 +24,7 @@ from components.express_way import *
from components.exit import *
from settings import *
assert is_windows() or is_darwin()
'''
obj type:
@@ -188,10 +190,13 @@ with open(svg_file_path, 'wb') as f:
f.write(etree.tostring(svg_tree, pretty_print=True))
# save as png
# cairosvg.svg2png(url=svg_file_path, write_to=png_file_path)
drawing = svg2rlg(svg_file_path)
renderPM.drawToFile(drawing, png_file_path, fmt='PNG')
if is_windows():
cairosvg.svg2png(url=svg_file_path, write_to=png_file_path)
elif is_darwin():
drawing = svg2rlg(svg_file_path)
renderPM.drawToFile(drawing, png_file_path, fmt='PNG')
else:
exit(-1)
os.remove(svg_file_path)

8
utils/platform.py Normal file
View File

@@ -0,0 +1,8 @@
import sys
def is_windows():
return sys.platform.startswith('win')
def is_darwin():
return sys.platform.startswith('darwin')