Hi,

[... extracted from the Image Lifecycle Patch ...]

the attached patch adds the OpenOffice drawing format (.odg). With it you can:

-) include in LyX OpenOffice drawings
-) preview them on the screen
-) view them in the final .ps/.pdf output
-) edit them externally via libreoffice, ooffice or soffice.

Notes:
1) It includes a trick to avoid detecting .odg as a zipped format, unfortunately
    I had to replicate it both in Format.cpp and in FileName.cpp.
    Any hint on how to possible make the design better ?

Would adding a method

  static bool FileName::isZippedExtension(string const &ext);

and using it from within Format.cpp be better ?

2) I guess sxd can be handled once the patch for multi-extension formats is cooked.

Thanks,

    T.

Index: src/support/FileName.cpp
===================================================================
--- src/support/FileName.cpp	(revisione 39605)
+++ src/support/FileName.cpp	(copia locale)
@@ -950,6 +950,13 @@
 
 bool FileName::isZippedFile() const
 {
+	string const & ex = extension();
+	bool zipped_format = (ex == "odg" || ex == "sxd"
+		|| ex == "odt" || ex == "sxw" || ex == "docx"
+		|| ex == "ods" || ex == "sxc" || ex == "xlsx"
+		|| ex == "gnumeric" || ex == "dia");
+	if (zipped_format)
+		return false;
 	string const type = guessFormatFromContents();
 	return contains("gzip zip compress", type) && !type.empty();
 }
Index: src/Format.cpp
===================================================================
--- src/Format.cpp	(revisione 39605)
+++ src/Format.cpp	(copia locale)
@@ -129,15 +129,25 @@
 }
 
 
+/// For a zipped format, try the filename extension first, then the contents
+/// (otherwise it is always guessed as zip and we're in trouble)
 string Formats::getFormatFromFile(FileName const & filename) const
 {
 	if (filename.empty())
 		return string();
 
-	string const format = filename.guessFormatFromContents();
-	if (!format.empty())
-		return format;
+	string const & ex = filename.extension();
+	bool zipped_format = (ex == "odg" || ex == "sxd"
+		|| ex == "odt" || ex == "sxw" || ex == "docx"
+		|| ex == "ods" || ex == "sxc" || ex == "xlsx"
+		|| ex == "gnumeric" || ex == "dia");
 
+	if (!zipped_format) {
+		string const format = filename.guessFormatFromContents();
+		if (!format.empty())
+			return format;
+	}
+
 	// try to find a format from the file extension.
 	string const ext = getExtension(filename.absFileName());
 	if (!ext.empty()) {
@@ -152,6 +162,12 @@
 			return cit->name();
 		}
 	}
+
+	if (zipped_format) {
+		string const format = filename.guessFormatFromContents();
+		if (!format.empty())
+			return format;
+	}
 	return string();
 }
 
Index: lib/scripts/libreoffice2ps.sh
===================================================================
--- lib/scripts/libreoffice2ps.sh	(revisione 0)
+++ lib/scripts/libreoffice2ps.sh	(revisione 0)
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+tmpdir=$(mktemp -d)
+fname=$(basename "$1")
+for sfx in odg odt ods odp; do
+    if echo $fname | grep "\\.${sfx}\$"; then
+	fname=${fname%%.$sfx}
+	break;
+    fi;
+done
+
+libreoffice -nologo -convert-to eps -outdir $tmpdir $1
+mv "$tmpdir/$fname.eps" "$2"
+rmdir $tmpdir

Proprietà modificate su: lib/scripts/libreoffice2ps.sh
___________________________________________________________________
Added: svn:executable
   + *

Index: lib/configure.py
===================================================================
--- lib/configure.py	(revisione 39605)
+++ lib/configure.py	(copia locale)
@@ -464,6 +464,9 @@
     checkViewerEditor('a Dia viewer and editor', ['dia'],
         rc_entry = [r'\Format dia        dia     DIA                    "" "%%"	"%%"	"vector"'])
     #
+    checkProg('an OpenOffice drawing viewer and editor', ['libreoffice', 'ooffice', 'soffice'],
+        rc_entry = [r'\Format odg        odg     ODG                    "" "%%"	"%%"	"vector"'])
+    #
     checkViewerEditor('a Grace viewer and editor', ['xmgrace'],
         rc_entry = [r'\Format agr        agr     Grace                  "" "%%"	"%%"	"vector"'])
     #
@@ -827,6 +830,10 @@
 \converter xls latex "ssconvert --export-type=Gnumeric_html:latex $$i $$o" ""''',
 ''])
 
+    # odg to ps
+    checkProg('an OpenOffice drawing -> ps converter', ['libreoffice'],
+       rc_entry = [ r'\converter odg ps "$$s/scripts/libreoffice2ps.sh $$i $$o" ""'])
+
     path, lilypond = checkProg('a LilyPond -> EPS/PDF/PNG converter', ['lilypond'])
     if (lilypond != ''):
         version_string = cmdOutput("lilypond --version")
Index: lib/Makefile.am
===================================================================
--- lib/Makefile.am	(revisione 39605)
+++ lib/Makefile.am	(copia locale)
@@ -1512,7 +1512,8 @@
 	scripts/prefs2prefs_lfuns.py \
 	scripts/prefs2prefs_prefs.py \
 	scripts/tex_copy.py \
-	scripts/TeXFiles.py
+	scripts/TeXFiles.py \
+	scripts/libreoffice2ps.sh
 
 templatesdir = $(pkgdatadir)/templates
 dist_templates_DATA = \
@@ -1578,7 +1579,7 @@
 	templates/springer/svmult_part.lyx \
 	templates/springer/svmult_preface.lyx \
 	templates/springer/svmult_referenc.lyx
-	
+
 thesistemplatesdir = $(pkgdatadir)/templates/thesis
 dist_thesistemplates_DATA = \
 	templates/thesis/Acknowledgments.lyx \

Reply via email to