feat: 跨平台
This commit is contained in:
13
test/main.py
13
test/main.py
@@ -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
8
utils/platform.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import sys
|
||||
|
||||
|
||||
def is_windows():
|
||||
return sys.platform.startswith('win')
|
||||
|
||||
def is_darwin():
|
||||
return sys.platform.startswith('darwin')
|
||||
Reference in New Issue
Block a user