Skip to content

Commit

Permalink
PDF bug workaround
Browse files Browse the repository at this point in the history
Added a workaround for rare bug that occurs when certain PDFs are imported
  • Loading branch information
burghoff committed Sep 23, 2022
1 parent 7d42853 commit 852ff61
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 34 deletions.
6 changes: 1 addition & 5 deletions scientific_inkscape/autoexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,11 +1270,7 @@ def Change_Viewbox_To_Page(self,svg,pg):


if __name__ == "__main__":
dh.Version_Check("Autoexporter")
import warnings

warnings.filterwarnings("ignore")
AutoExporter().run()
dh.Run_SI_Extension(AutoExporter(),"Autoexporter")


# Scour calling
Expand Down
3 changes: 1 addition & 2 deletions scientific_inkscape/combine_by_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,4 @@ def effect(self):


if __name__ == "__main__":
dh.Version_Check("Combine by color")
CombineByColor().run()
dh.Run_SI_Extension(CombineByColor(),"Combine by color")
31 changes: 31 additions & 0 deletions scientific_inkscape/dhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,37 @@ def isMask(el):
else:
return isinstance(el, (inkex.Mask))

def Run_SI_Extension(effext,name):
Version_Check(name)
try:
effext.run()
except lxml.etree.XMLSyntaxError:
try:
s = effext;
s.parse_arguments(sys.argv[1:])
if s.options.input_file is None:
s.options.input_file = sys.stdin
elif "DOCUMENT_PATH" not in os.environ:
os.environ["DOCUMENT_PATH"] = s.options.input_file


def overwrite_output(filein,fileout):
try:
os.remove(fileout)
except:
pass
arg2 = [Get_Binary_Loc(),"--export-filename",fileout,filein,]
subprocess_repeat(arg2)
tmpname=s.options.input_file.strip('.svg')+'_tmp.svg'
overwrite_output(s.options.input_file,tmpname);
os.remove(s.options.input_file)
os.rename(tmpname,s.options.input_file)
s.run()
except:
inkex.utils.errormsg(
"Error reading file! Extensions can only run on SVG files.\n\nIf this is a file imported from another format, try saving as an SVG and restarting Inkscape. Alternatively, try pasting the contents into a new document."
)
write_debug()

def vto_xpath(sty):
if (
Expand Down
6 changes: 1 addition & 5 deletions scientific_inkscape/favorite_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,4 @@ def effect(self):


if __name__ == "__main__":
dh.Version_Check("Favorite markers")
import warnings

warnings.filterwarnings("ignore")
FavoriteMarkers().run()
dh.Run_SI_Extension(FavoriteMarkers(),"Favorite markers")
10 changes: 2 additions & 8 deletions scientific_inkscape/flatten_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,5 @@ def effect(self):


if __name__ == "__main__":
dh.Version_Check("Flattener")
try:
s = FlattenPlots().run()
dh.write_debug()
except lxml.etree.XMLSyntaxError:
inkex.utils.errormsg(
"Error parsing XML! Extensions can only run on SVG files. If this is a file imported from another format, try saving as an SVG or pasting the contents into a new SVG."
)
dh.Run_SI_Extension(FlattenPlots(),"Flattener")

3 changes: 1 addition & 2 deletions scientific_inkscape/homogenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,5 +327,4 @@ def effect(self):


if __name__ == "__main__":
dh.Version_Check("Homogenizer")
Homogenizer().run()
dh.Run_SI_Extension(Homogenizer(),"Homogenizer")
8 changes: 1 addition & 7 deletions scientific_inkscape/scale_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,4 @@ def union(self, g,f):


if __name__ == "__main__":
dh.Version_Check("Scale plots")
try:
ScalePlots().run()
except lxml.etree.XMLSyntaxError:
inkex.utils.errormsg(
"Error parsing XML! Extensions can only run on SVG files. If this is a file imported from another format, try saving as an SVG or pasting the contents into a new SVG."
)
dh.Run_SI_Extension(ScalePlots(),"Scale plots")
6 changes: 1 addition & 5 deletions scientific_inkscape/text_ghoster.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,4 @@ def effect(self):


if __name__ == "__main__":
dh.Version_Check("Text ghoster")
import warnings

warnings.filterwarnings("ignore")
TextGhoster().run()
dh.Run_SI_Extension(TextGhoster(),"Text ghoster")

0 comments on commit 852ff61

Please sign in to comment.