From ff0bfad399cd4ce72e39e2d7d9ef5958336d79bc Mon Sep 17 00:00:00 2001 From: Zhang Muyu Date: Tue, 19 Sep 2023 00:48:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B7=A8=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/main.py | 13 +++++++++---- utils/platform.py | 8 ++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 utils/platform.py diff --git a/test/main.py b/test/main.py index 48e7f1c..4ab4efa 100644 --- a/test/main.py +++ b/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) diff --git a/utils/platform.py b/utils/platform.py new file mode 100644 index 0000000..8dd3060 --- /dev/null +++ b/utils/platform.py @@ -0,0 +1,8 @@ +import sys + + +def is_windows(): + return sys.platform.startswith('win') + +def is_darwin(): + return sys.platform.startswith('darwin') \ No newline at end of file