Il 26/07/2011 17:33, Julien Rioux ha scritto:
You can define a converter from odg to eps in Preferences > File
Handling > Converters. You might first have to define the odg format.
Then you can insert odg files as graphics.
In the attached patch, I just realised what is my "ideal" lifecycle for
working with images.
This is how it works:
a) I'm writing a LyX document
b) I realise I need an image, so: Insert->Image... dialog,
c) I enter a file-name for a vectorial format, like "architecture.odg"
d) I push the "Create/Edit" button, and I confirm I want a new file created
from an empty sample
e) I edit my diagram with LibreOffice, then save it (and/or exit
LibreOffice)
f) Whenever I need to edit it back, I use the [Right Click]->[Edit
Externally] feature,
or I pop-up the properties pane and I press the "Create/Edit" button
again
The key point is that, for creating the new drawing, I don't have to
launch my image editor independently, then pointing it to the same
folder where I have my .lyx file for saving a new file, then back to LyX
and have the file finally inserted as Image in LyX. That's a burden.
With the steps above, it all gets simpler and just gives you the feeling
that the whole image creation/insertion/editing lifecycle is well
integrated with LyX.
Note that I don't have to manually save from OpenOffice to .eps, then
insert in LyX the .eps. I just save the .odg, and LyX converts it for me
(but I didn't try the pdflatex way of generating the output yet -- my
guess is that, once LyX knows how to convert that .odg thing, it will
get the right toolchain automagically).
The only feature I'm missing is that the (non-expert) user doesn't get a
list of possible image formats, something that would be very useful
indeed (a'la Insert->ExternalMaterial dialog combo-box...), with a short
description (mainly the user would need to know/choose whether he/she
needs a raster/bitmap or vectorial image format).
The weird check on the file extensions that you can see in the patch is
needed to avoid that LyX thinks that .odg is a compressed archive and
tries wastefully to uncompress its contents for being able to do nothing
with that later. In such cases, I just need LyX to think that .odg is
.odg and look for converters to other formats for rendering purposes.
Any comments welcome.
Bye,
T.
Index: src/frontends/qt4/GuiGraphics.cpp
===================================================================
--- src/frontends/qt4/GuiGraphics.cpp (revisione 39369)
+++ src/frontends/qt4/GuiGraphics.cpp (copia locale)
@@ -24,6 +24,7 @@
#include "LengthCombo.h"
#include "Length.h"
#include "LyXRC.h"
+#include "Format.h"
#include "graphics/GraphicsCache.h"
#include "graphics/GraphicsCacheItem.h"
@@ -358,6 +359,43 @@
}
+void GuiGraphics::on_createOrEditPB_clicked()
+{
+ printf("Hello world!\n");
+ string const fname = fromqstr(filename->text());
+ FileName dest_fname(FileName(fromqstr(bufferFilePath())), fname);
+ string fmt_name = lyx::formats.getFormatFromFile(FileName(fname));
+ if (fmt_name.empty()) {
+ Alert::warning(_("Format not found"), _("It was not possible to infer the format from the file contents or its name."));
+ return;
+ }
+ if (!dest_fname.exists()) {
+ int create = frontend::Alert::prompt(
+ _("Create ?"), _("File does not exist. Create from empty sample ?"),
+ 0, 1, _("&Yes"), _("&No"));
+ if (create != 0)
+ return;
+
+ Format const *fmt = formats.getFormat(fmt_name);
+ string sample_name = string("sample.") + fmt->extension();
+ if (sample_name.empty()) {
+ Alert::warning(_("Format sample not found"), _("Cannot find a format sample to use as empty file"));
+ return;
+ }
+ FileName sample_fname = libFileSearch(toqstr("samples"), toqstr(sample_name));
+ if (!sample_fname.exists()) {
+ Alert::warning(_("Format sample not found"), _("Cannot find a format sample to use as empty file"));
+ return;
+ }
+ sample_fname.copyTo(dest_fname);
+ frontend::Alert::information(_("Information"), bformat(_("Empty file created from sample: %1$s"), from_utf8(dest_fname.realPath())));
+ dest_fname.refresh();
+ }
+
+ formats.edit(buffer(), dest_fname, fmt_name);
+}
+
+
void GuiGraphics::on_getPB_clicked()
{
getBB();
Index: src/frontends/qt4/GuiGraphics.h
===================================================================
--- src/frontends/qt4/GuiGraphics.h (revisione 39369)
+++ src/frontends/qt4/GuiGraphics.h (copia locale)
@@ -45,6 +45,7 @@
void on_newGroupPB_clicked();
void on_browsePB_clicked();
void on_getPB_clicked();
+ void on_createOrEditPB_clicked();
void on_scaleCB_toggled(bool);
void on_WidthCB_toggled(bool);
void on_HeightCB_toggled(bool);
Index: src/frontends/qt4/ui/GraphicsUi.ui
===================================================================
--- src/frontends/qt4/ui/GraphicsUi.ui (revisione 39369)
+++ src/frontends/qt4/ui/GraphicsUi.ui (copia locale)
@@ -277,6 +277,13 @@
</property>
</widget>
</item>
+ <item row="0" column="4">
+ <widget class="QPushButton" name="createOrEditPB">
+ <property name="text">
+ <string>Create/Edit</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<widget class="QWidget" name="Clipping" >
Index: src/support/FileName.cpp
===================================================================
--- src/support/FileName.cpp (revisione 39369)
+++ 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");
+ 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 39372)
+++ src/Format.cpp (copia locale)
@@ -128,15 +128,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");
+ 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()) {
@@ -151,6 +161,12 @@
return cit->name();
}
}
+
+ if (zipped_format) {
+ string const format = filename.guessFormatFromContents();
+ if (!format.empty())
+ return format;
+ }
return string();
}
Index: lib/samples/sample.ods
===================================================================
Non posso mostrarlo: file indicato come binario.
svn:mime-type = application/octet-stream
Proprietà modificate su: lib/samples/sample.ods
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Index: lib/samples/sample.fig
===================================================================
--- lib/samples/sample.fig (revisione 0)
+++ lib/samples/sample.fig (revisione 0)
@@ -0,0 +1,12 @@
+#FIG 3.2 Produced by xfig version 3.2.5b
+Landscape
+Center
+Metric
+A4
+100.00
+Single
+-2
+1200 2
+2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
+ 3465 2655 5670 2655 5670 3375 3465 3375 3465 2655
+4 0 0 50 -1 0 12 0.0000 4 180 1350 3690 2925 Empty Template\001
Index: lib/samples/sample.odg
===================================================================
Non posso mostrarlo: file indicato come binario.
svn:mime-type = application/octet-stream
Proprietà modificate su: lib/samples/sample.odg
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Index: lib/samples/sample.gnumeric
===================================================================
Non posso mostrarlo: file indicato come binario.
svn:mime-type = application/octet-stream
Proprietà modificate su: lib/samples/sample.gnumeric
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Index: lib/samples/sample.dia
===================================================================
Non posso mostrarlo: file indicato come binario.
svn:mime-type = application/octet-stream
Proprietà modificate su: lib/samples/sample.dia
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Index: lib/configure.py
===================================================================
--- lib/configure.py (revisione 39369)
+++ lib/configure.py (copia locale)
@@ -458,6 +458,9 @@
checkViewerEditor('a Dia viewer and editor', ['dia'],
rc_entry = [r'\Format dia dia DIA "" "%%" "%%" "vector"'])
#
+ checkViewerEditor('an OpenOffice drawing viewer and editor', ['ooffice', 'soffice', 'libreoffice'],
+ rc_entry = [r'\Format odg odg ODG "" "%%" "%%" "vector"'])
+ #
checkViewerEditor('a Grace viewer and editor', ['xmgrace'],
rc_entry = [r'\Format agr agr Grace "" "%%" "%%" "vector"'])
#
@@ -816,6 +819,10 @@
\converter xls latex "ssconvert --export-type=Gnumeric_html:latex $$i $$o" ""''',
''])
+ # odg to eps
+ checkProg('a OpenOffice drawing -> latex converter', ['unoconv'],
+ rc_entry = [ r'\converter odg eps "unoconv --stdout -f eps $$i | ps2eps > $$o" ""'])
+
path, lilypond = checkProg('a LilyPond -> EPS/PDF/PNG converter', ['lilypond'])
if (lilypond != ''):
version_string = cmdOutput("lilypond --version")