This repository has been archived on 2023-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
mightyscape-1.1-deprecated/extensions/fablabchemnitz_inkcut.py

58 lines
1.9 KiB
Python
Raw Normal View History

2020-07-30 01:16:18 +02:00
#!/usr/bin/env python3
"""
Inkcut, Plot HPGL directly from Inkscape.
inkcut.py
Copyright 2018 The Inkcut Team
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
"""
import os
import inkex
from lxml import etree
from subprocess import Popen, PIPE
from shutil import copy2
from distutils.spawn import find_executable
def contains_text(nodes):
for node in nodes:
tag = node.tag[node.tag.rfind("}")+1:]
if tag == 'text':
return True
return False
def convert_objects_to_paths(file, document):
tempfile = os.path.splitext(file)[0] + "-prepare.svg"
# tempfile is needed here only because we want to force the extension to be .svg
# so that we can open and close it silently
copy2(file, tempfile)
2020-08-30 11:23:01 +02:00
command = "inkscape " + tempfile + ' --actions="EditSelectAllInAllLayers;EditUnlinkClone;ObjectToPath;FileSave;FileQuit"'
2020-07-30 01:16:18 +02:00
if find_executable('xvfb-run'):
command = 'xvfb-run -a ' + command
p = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
(out, err) = p.communicate()
if p.returncode != 0:
2020-08-20 13:12:34 +02:00
inkex.errormsg("Failed to convert objects to paths. Continued without converting.")
2020-07-30 01:16:18 +02:00
inkex.errormsg(out)
inkex.errormsg(err)
return document.getroot()
else:
2020-08-30 11:23:01 +02:00
return etree.parse(tempfile).getroot()