[LyX/2.3.x] Add support for inkscape 1.0

Juergen Spitzmueller spitz at lyx.org
Mon May 18 11:06:23 UTC 2020


commit 733389677fc269336bb361001f75fe5b546557a3
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Fri May 15 14:08:46 2020 +0200

    Add support for inkscape 1.0
    
    Command line syntax has changed. We now check for the version and use
    the appropriate cl options.
    
    Fixes #11742
    
    (cherry picked from commit 74f831e06d7502578b104a25580618f90503153e)
---
 lib/configure.py          |  108 +++++++++++++++++++++++++++++++++------------
 lib/scripts/svg2pdftex.py |   29 ++++++++++---
 lib/scripts/svg2pstex.py  |   24 ++++++++--
 3 files changed, 121 insertions(+), 40 deletions(-)

diff --git a/lib/configure.py b/lib/configure.py
index 602e090..8f70066 100644
--- a/lib/configure.py
+++ b/lib/configure.py
@@ -551,6 +551,15 @@ def checkInkscape():
         except EnvironmentError:
             return 'inkscape'
 
+def checkInkscapeStable():
+    ''' Check whether we use Inkscape >= 1.0 '''
+    version_string = cmdOutput("inkscape --version")
+    if version_string.find('0.9') > 0:
+        return False
+    else:
+        return True
+
+
 def checkLatex(dtl_tools):
     ''' Check latex, return lyx_check_config '''
     path, LATEX = checkProg('a Latex2e program', ['latex $$i', 'latex2e $$i'])
@@ -1022,13 +1031,22 @@ def checkConverterEntries():
 \converter fig        pdftex     "python -tt $$s/scripts/fig2pdftex.py $$i $$o"	""
 \converter fig        pstex      "python -tt $$s/scripts/fig2pstex.py $$i $$o"	""''')
     #
-    checkProg('a SVG -> PDFTeX converter', [inkscape_cl],
-        rc_entry = [ r'\converter svg        pdftex     "python -tt $$s/scripts/svg2pdftex.py %% $$p$$i $$p$$o" ""'],
-        path = [inkscape_path])
-    #
-    checkProg('a SVG -> PSTeX converter', [inkscape_cl],
-        rc_entry = [ r'\converter svg        pstex     "python -tt $$s/scripts/svg2pstex.py %% $$p$$i $$p$$o" ""'],
-        path = [inkscape_path])
+    if inkscape_stable:
+        checkProg('a SVG -> PDFTeX converter', [inkscape_cl],
+            rc_entry = [ r'\converter svg        pdftex     "python -tt $$s/scripts/svg2pdftex.py %% $$p$$i $$p$$o" ""'],
+            path = [inkscape_path])
+        #
+        checkProg('a SVG -> PSTeX converter', [inkscape_cl],
+            rc_entry = [ r'\converter svg        pstex     "python -tt $$s/scripts/svg2pstex.py %% $$p$$i $$p$$o" ""'],
+            path = [inkscape_path])
+    else:
+        checkProg('a SVG -> PDFTeX converter', [inkscape_cl],
+            rc_entry = [ r'\converter svg        pdftex     "python -tt $$s/scripts/svg2pdftex.py --unstable %% $$p$$i $$p$$o" ""'],
+            path = [inkscape_path])
+        #
+        checkProg('a SVG -> PSTeX converter', [inkscape_cl],
+            rc_entry = [ r'\converter svg        pstex     "python -tt $$s/scripts/svg2pstex.py --unstable %% $$p$$i $$p$$o" ""'],
+            path = [inkscape_path])
     #
     checkProg('a TIFF -> PS converter', ['tiff2ps $$i > $$o'],
         rc_entry = [ r'\converter tiff       eps        "%%"	""'])
@@ -1039,17 +1057,31 @@ def checkConverterEntries():
 \converter tgif       png        "tgif -print -color -png -o $$d $$i"	""
 \converter tgif       pdf6       "tgif -print -color -pdf -stdout $$i > $$o"	""'''])
     #
-    checkProg('a WMF -> EPS converter', ['metafile2eps $$i $$o', 'wmf2eps -o $$o $$i', inkscape_cl + ' --file=$$i --export-area-drawing --without-gui --export-eps=$$o'],
-        rc_entry = [ r'\converter wmf        eps        "%%"	""'])
-    #
-    checkProg('an EMF -> EPS converter', ['metafile2eps $$i $$o', inkscape_cl + ' --file=$$i --export-area-drawing --without-gui --export-eps=$$o'],
-        rc_entry = [ r'\converter emf        eps        "%%"	""'])
-    #
-    checkProg('a WMF -> PDF converter', [inkscape_cl + ' --file=$$i --export-area-drawing --without-gui --export-pdf=$$o'],
-        rc_entry = [ r'\converter wmf        pdf6        "%%"	""'])
-    #
-    checkProg('an EMF -> PDF converter', [inkscape_cl + ' --file=$$i --export-area-drawing --without-gui --export-pdf=$$o'],
-        rc_entry = [ r'\converter emf        pdf6        "%%"	""'])
+    # inkscape 1.0 has changed cl options
+    if inkscape_stable:
+        checkProg('a WMF -> EPS converter', ['metafile2eps $$i $$o', 'wmf2eps -o $$o $$i', inkscape_cl + ' $$i --export-area-drawing --export-filename=$$o'],
+            rc_entry = [ r'\converter wmf        eps        "%%"	""'])
+        #
+        checkProg('an EMF -> EPS converter', ['metafile2eps $$i $$o', inkscape_cl + ' $$i --export-area-drawing --export-filename=$$o'],
+            rc_entry = [ r'\converter emf        eps        "%%"	""'])
+        #
+        checkProg('a WMF -> PDF converter', [inkscape_cl + ' $$i --export-area-drawing --export-filename=$$o'],
+            rc_entry = [ r'\converter wmf        pdf6        "%%"	""'])
+        #
+        checkProg('an EMF -> PDF converter', [inkscape_cl + ' $$i --export-area-drawing --export-filename=$$o'],
+            rc_entry = [ r'\converter emf        pdf6        "%%"	""'])
+    else:
+        checkProg('a WMF -> EPS converter', ['metafile2eps $$i $$o', 'wmf2eps -o $$o $$i', inkscape_cl + ' --file=$$i --export-area-drawing --without-gui --export-eps=$$o'],
+            rc_entry = [ r'\converter wmf        eps        "%%"	""'])
+        #
+        checkProg('an EMF -> EPS converter', ['metafile2eps $$i $$o', inkscape_cl + ' --file=$$i --export-area-drawing --without-gui --export-eps=$$o'],
+            rc_entry = [ r'\converter emf        eps        "%%"	""'])
+        #
+        checkProg('a WMF -> PDF converter', [inkscape_cl + ' --file=$$i --export-area-drawing --without-gui --export-pdf=$$o'],
+            rc_entry = [ r'\converter wmf        pdf6        "%%"	""'])
+        #
+        checkProg('an EMF -> PDF converter', [inkscape_cl + ' --file=$$i --export-area-drawing --without-gui --export-pdf=$$o'],
+            rc_entry = [ r'\converter emf        pdf6        "%%"	""'])
     # Only define a converter to pdf6 for graphics
     checkProg('an EPS -> PDF converter', ['epstopdf'],
         rc_entry = [ r'\converter eps        pdf6       "epstopdf --outfile=$$o $$i"	""'])
@@ -1094,20 +1126,37 @@ def checkConverterEntries():
         rc_entry = [ r'\converter svg        svgz       "%%"	""'])
     # Only define a converter to pdf6 for graphics
     # Prefer rsvg-convert over inkscape since it is faster (see http://www.lyx.org/trac/ticket/9891)
-    checkProg('a SVG -> PDF converter', ['rsvg-convert -f pdf -o $$o $$i', inkscape_cl + ' --file=$$i --export-area-drawing --without-gui --export-pdf=$$o'],
-        rc_entry = [ r'''\converter svg        pdf6       "%%"    ""
+    # inkscape 1.0 has changed cl options
+    if inkscape_stable:
+        checkProg('a SVG -> PDF converter', ['rsvg-convert -f pdf -o $$o $$i', inkscape_cl + ' $$i --export-area-drawing --export-filename=$$o'],
+            rc_entry = [ r'''\converter svg        pdf6       "%%"    ""
 \converter svgz       pdf6       "%%"    ""'''],
-        path = ['', inkscape_path])
-    #
-    checkProg('a SVG -> EPS converter', ['rsvg-convert -f ps -o $$o $$i', inkscape_cl + ' --file=$$i --export-area-drawing --without-gui --export-eps=$$o'],
-        rc_entry = [ r'''\converter svg        eps        "%%"    ""
+            path = ['', inkscape_path])
+        #
+        checkProg('a SVG -> EPS converter', ['rsvg-convert -f ps -o $$o $$i', inkscape_cl + ' $$i --export-area-drawing --export-filename=$$o'],
+            rc_entry = [ r'''\converter svg        eps        "%%"    ""
 \converter svgz       eps        "%%"    ""'''],
-        path = ['', inkscape_path])
-    #
-    checkProg('a SVG -> PNG converter', ['rsvg-convert -f png -o $$o $$i', inkscape_cl + ' --without-gui --file=$$i --export-png=$$o'],
-        rc_entry = [ r'''\converter svg        png        "%%"    "",
+            path = ['', inkscape_path])
+        #
+        checkProg('a SVG -> PNG converter', ['rsvg-convert -f png -o $$o $$i', inkscape_cl + ' $$i --export-filename=$$o'],
+            rc_entry = [ r'''\converter svg        png        "%%"    "",
+\converter svgz       png        "%%"    ""'''],
+            path = ['', inkscape_path])
+    else:
+        checkProg('a SVG -> PDF converter', ['rsvg-convert -f pdf -o $$o $$i', inkscape_cl + ' --file=$$i --export-area-drawing --without-gui --export-pdf=$$o'],
+            rc_entry = [ r'''\converter svg        pdf6       "%%"    ""
+\converter svgz       pdf6       "%%"    ""'''],
+            path = ['', inkscape_path])
+        #
+        checkProg('a SVG -> EPS converter', ['rsvg-convert -f ps -o $$o $$i', inkscape_cl + ' --file=$$i --export-area-drawing --without-gui --export-eps=$$o'],
+            rc_entry = [ r'''\converter svg        eps        "%%"    ""
+\converter svgz       eps        "%%"    ""'''],
+            path = ['', inkscape_path])
+        #
+        checkProg('a SVG -> PNG converter', ['rsvg-convert -f png -o $$o $$i', inkscape_cl + ' --without-gui --file=$$i --export-png=$$o'],
+            rc_entry = [ r'''\converter svg        png        "%%"    "",
 \converter svgz       png        "%%"    ""'''],
-        path = ['', inkscape_path])
+            path = ['', inkscape_path])
     #
     checkProg('Gnuplot', ['gnuplot'], 
         rc_entry = [ r'''\Format gnuplot     "gp, gnuplot"    "Gnuplot"     "" "" ""  "vector"	"text/plain"
@@ -1887,6 +1936,7 @@ Format %i
     # On Windows, we need to call the "inkscape.com" wrapper
     # for command line purposes. Other OSes do not differentiate.
     inkscape_cl = inkscape_gui
+    inkscape_stable = checkInkscapeStable()
     if os.name == 'nt':
         inkscape_cl = inkscape_gui.replace('.exe', '.com')
     # On MacOSX, Inkscape requires full path file arguments. This
diff --git a/lib/scripts/svg2pdftex.py b/lib/scripts/svg2pdftex.py
index d1e0bf3..2fe62df 100644
--- a/lib/scripts/svg2pdftex.py
+++ b/lib/scripts/svg2pdftex.py
@@ -15,11 +15,12 @@
 # with pdflatex into high quality PDF. It requires Inkscape.
 
 # Usage:
-#   python svg2pdftex.py [inkscape_command] inputfile.svg outputfile.pdf_tex
+#   python svg2pdftex.py [--unstable] [inkscape_command] inputfile.svg outputfile.pdf_tex
 # This command generates
 #   1. outputfile.pdf     -- the converted PDF file (text from SVG stripped)
 #   2. outputfile.pdf_tex -- a TeX file that can be included in your
 #                             LaTeX document using '\input{outputfile.pdf_text}'
+# use --unstable for inkscape < 1.0
 #
 # Note:
 #   Do not use this command as
@@ -43,16 +44,29 @@ def runCommand(cmd):
 InkscapeCmd = "inkscape"
 InputFile = ""
 OutputFile = ""
+unstable = False
 
-# We expect two or three args: the names of the input and output files
-# and optionally the inkscape command (with path if needed).
+# We expect two to four args: the names of the input and output files
+# and optionally the inkscape command (with path if needed) and --unstable.
 args = len(sys.argv)
 if args == 3:
     # Two args: input and output file only
     InputFile, OutputFile = sys.argv[1:]
 elif args == 4:
-    # Three args: first arg is inkscape command
-    InkscapeCmd, InputFile, OutputFile = sys.argv[1:]
+    # Three args: check whether we have --unstable as first arg
+    if sys.argv[1] == "--unstable":
+        unstable = True
+        InputFile, OutputFile = sys.argv[2:]
+    else:
+        InkscapeCmd, InputFile, OutputFile = sys.argv[1:]
+elif args == 5:
+    # Four args: check whether we have --unstable as first arg
+    if sys.argv[1] != "--unstable":
+        # Invalid number of args. Exit with error.
+        sys.exit(1)
+    else:
+        unstable = True
+        InkscapeCmd, InputFile, OutputFile = sys.argv[2:]
 else:
     # Invalid number of args. Exit with error.
     sys.exit(1)
@@ -68,7 +82,10 @@ OutBase = os.path.splitext(OutputFile)[0]
 # while outsourcing the text to a LaTeX file ${OutBase}.pdf_tex which includes and overlays
 # the PDF image and can be \input to LaTeX files. We rename the latter file to ${OutputFile}
 # (although this is probably the name it already has).
-runCommand([r'%s' % InkscapeCmd, '--file=%s' % InputFile, '--export-pdf=%s.pdf' % OutBase, '--export-latex'])
+if unstable:
+    runCommand([r'%s' % InkscapeCmd, '--file=%s' % InputFile, '--export-pdf=%s.pdf' % OutBase, '--export-latex'])
+else:
+    runCommand([r'%s' % InkscapeCmd, '%s' % InputFile, '--export-filename=%s.pdf' % OutBase, '--export-latex'])
 
 os.rename('%s.pdf_tex' % OutBase, OutputFile)
 
diff --git a/lib/scripts/svg2pstex.py b/lib/scripts/svg2pstex.py
index 97d6ae1..acb0322 100644
--- a/lib/scripts/svg2pstex.py
+++ b/lib/scripts/svg2pstex.py
@@ -15,11 +15,12 @@
 # with latex into high quality DVI/PostScript. It requires Inkscape.
 
 # Usage:
-#   python svg2pstex.py [inkscape_command] inputfile.svg outputfile.eps_tex
+#   python svg2pstex.py [--unstable] [inkscape_command] inputfile.svg outputfile.eps_tex
 # This command generates
 #   1. outputfile.eps     -- the converted EPS file (text from SVG stripped)
 #   2. outputfile.eps_tex -- a TeX file that can be included in your
 #                             LaTeX document using '\input{outputfile.eps_text}'
+# use --unstable for inkscape < 1.0
 #
 # Note:
 #   Do not use this command as
@@ -46,16 +47,29 @@ def runCommand(cmd):
 InkscapeCmd = "inkscape"
 InputFile = ""
 OutputFile = ""
+unstable = False
 
-# We expect two or three args: the names of the input and output files
-# and optionally the inkscape command (with path if needed).
+# We expect two to four args: the names of the input and output files
+# and optionally the inkscape command (with path if needed) and --unstable.
 args = len(sys.argv)
 if args == 3:
     # Two args: input and output file only
     InputFile, OutputFile = sys.argv[1:]
 elif args == 4:
-    # Three args: first arg is inkscape command
-    InkscapeCmd, InputFile, OutputFile = sys.argv[1:]
+    # Three args: check whether we have --unstable as first arg
+    if sys.argv[1] == "--unstable":
+        unstable = True
+        InputFile, OutputFile = sys.argv[2:]
+    else:
+        InkscapeCmd, InputFile, OutputFile = sys.argv[1:]
+elif args == 5:
+    # Four args: check whether we have --unstable as first arg
+    if sys.argv[1] != "--unstable":
+        # Invalid number of args. Exit with error.
+        sys.exit(1)
+    else:
+        unstable = True
+        InkscapeCmd, InputFile, OutputFile = sys.argv[2:]
 else:
     # Invalid number of args. Exit with error.
     sys.exit(1)


More information about the lyx-cvs mailing list