Il 18/09/2011 20:37, Julien Rioux ha scritto:
On 18/09/2011 8:22 PM, Tommaso Cucinotta wrote:
Il 18/09/2011 16:03, Tommaso Cucinotta ha scritto:
Please test.
I will later today, thanks.
Made a few tests including a sample dia. If it is included as external
material, then it works.
If it is included as a graphics inset, then it doesn't show on the
screen and I have this
on the console:
convert: no decode delegate for this image format
`/tmp/lyx_tmpdir.hX4836/gconvert0.Wy4836.fB4836' @
error/svg.c/ReadSVGImage/2811.
convert: missing an image filename
`ppm:/tmp/lyx_tmpdir.hX4836/CacheItem.JH4836.ppm' @
error/convert.c/ConvertImageCommand/2970.
/home/tommaso/lyx-trunk-ws/lyx-trunk/lib/scripts/convertDefault.py ERROR
Execution of "convert" failed.
In my $HOME/.lyx/lyxrc.defaults, I got correctly the
"vector,zipped=native" flag on the dia line.
I had also cleaned the whole LyX cache folder, just to be sure, but it
keeps showing the above error.
I also checked that, adding the ODG format and converter (with
native=zipped set), it has the same problem. Therefore, in the sequences
of calls to guessFormatFromContents(), some path is probably out of your
rework (i.e., there's some other ones of those calls that should go
through formats.getFormatFromFile()).
My pure guess is that all those calls to isZipped() from InsetGraphics
are taking the wrong decision now.
../src/insets/InsetGraphics.cpp:493: if (file.isZipped()) {
../src/insets/InsetGraphics.cpp:619: if (params().filename.isZipped()) {
In my last patch, isZipeed() was calling guessFormatFromContents(),
which in the end was returning the real format, not gzip/zip. Instead,
now it returns zip or gzip, and the graphics machinery starts to unzip
and tries to convert.
Bye,
T.
Good catch. Please inspect those calls, and where appropriate change
them to
if (file.isZipped() && !format.zippedNative())
It was not actually InsetGraphics, but rather GraphicsCacheItem (or
maybe both).
Please, find the fix in the attached patch.
I defined a Formats::isZipped() method whose outcome is also cached within a
local cache Formats::zipped_ (following the original FileName::zipped_
purpose).
Actually, I think
a similar cache should be applied to Formats::getFormatFromFile() as
well, or
to FileName::guessFormatFromContents() -- whatever is better.
Would you like to change further things in this patch, or can it be
committed ?
FYI, find below the residual usages of the FileName::isZipped*() methods
(in Buffer.cpp and support/filetools.cpp):
$ find . -name '*.cpp' -exec grep -Hn isZipped {} \;
./src/graphics/GraphicsCacheItem.cpp:362: zipped_ =
formats.isZipped(filename);
./src/support/FileName.cpp:947:bool FileName::isZippedFile() const
./src/support/FileName.cpp:1155:bool DocFileName::isZipped() const
./src/support/FileName.cpp:1158: zipped_ = isZippedFile();
./src/support/filetools.cpp:1006: bool zipped = file.isZippedFile();
./src/Buffer.cpp:937: params().compressed = d->filename.isZippedFile();
./src/insets/InsetGraphics.cpp:493: if (formats.isZipped(file)) {
./src/insets/InsetGraphics.cpp:619: if
(formats.isZipped(params().filename)) {
./src/Format.cpp:194:bool Formats::isZipped(support::FileName const &
filename) const {
Bye,
T.
Index: src/insets/InsetGraphics.cpp
===================================================================
--- src/insets/InsetGraphics.cpp (revisione 39700)
+++ src/insets/InsetGraphics.cpp (copia locale)
@@ -490,7 +490,7 @@
return make_pair(IDENTICAL_PATHS, file_in);
string mangled = file.mangledFileName();
- if (file.isZipped()) {
+ if (formats.isZipped(file)) {
// We need to change _eps.gz to .eps.gz. The mangled name is
// still unique because of the counter in mangledFileName().
// We can't just call mangledFileName() with the zip
@@ -616,7 +616,7 @@
// If the file is compressed and we have specified that it
// should not be uncompressed, then just return its name and
// let LaTeX do the rest!
- if (params().filename.isZipped()) {
+ if (formats.isZipped(params().filename)) {
if (params().noUnzip) {
// We don't know whether latex can actually handle
// this file, but we can't check, because that would
Index: src/graphics/GraphicsCacheItem.cpp
===================================================================
--- src/graphics/GraphicsCacheItem.cpp (revisione 39700)
+++ src/graphics/GraphicsCacheItem.cpp (copia locale)
@@ -359,7 +359,7 @@
return false;
}
- zipped_ = filename_.isZippedFile();
+ zipped_ = formats.isZipped(filename);
if (zipped_) {
unzipped_filename_ = FileName::tempName(
filename_.toFilesystemEncoding());
Index: src/Format.h
===================================================================
--- src/Format.h (revisione 39700)
+++ src/Format.h (copia locale)
@@ -17,8 +17,9 @@
#include "OutputParams.h"
#include <vector>
+#include <map>
+#include <ctime>
-
namespace lyx {
namespace support { class FileName; }
@@ -37,7 +38,9 @@
/// Set if this format can contain vector graphics.
vector = 2,
/// This format should appear in the File > Export menu
- export_menu = 4
+ export_menu = 4,
+ /// This may be a compressed file but doesn't need decompression
+ zipped_native = 8
};
///
Format(std::string const & n, std::string const & e, std::string const & p,
@@ -89,6 +92,8 @@
void setFlags(int v) { flags_ = v; }
///
bool inExportMenu() const { return flags_ & export_menu; }
+ ///
+ bool zippedNative() const { return flags_ & zipped_native; }
private:
/// Internal name. Needs to be unique.
std::string name_;
@@ -138,6 +143,13 @@
* string.
*/
std::string getFormatFromFile(support::FileName const & filename) const;
+ /// Finds a format from a file extension. Returns string() if not found.
+ std::string getFormatFromExtension(std::string const & ext) const;
+ /** Returns true if the file referenced by \p filename is zipped and
+ ** needs to be unzipped for being handled
+ ** @note For natively zipped formats, such as dia/odg, this returns false.
+ **/
+ bool isZipped(support::FileName const & filename) const;
/// Set editor and/or viewer to "auto" for formats that can be
/// opened by the OS.
void setAutoOpen();
@@ -179,6 +191,14 @@
private:
///
FormatList formatlist;
+ /// Used to store last timestamp of file and whether it is (was) zipped
+ struct ZippedInfo {
+ bool zipped; std::time_t timestamp;
+ ZippedInfo(bool zipped, std::time_t timestamp)
+ : zipped(zipped), timestamp(timestamp) { }
+ };
+ ///
+ mutable std::map<std::string, ZippedInfo> zipped_;
};
///
Index: src/support/FileName.cpp
===================================================================
--- src/support/FileName.cpp (revisione 39700)
+++ src/support/FileName.cpp (copia locale)
@@ -933,10 +933,6 @@
format = "fits";
}
- // Dia knows also compressed form
- if ((format == "gzip") && (!compare_ascii_no_case(extension(), "dia")))
- format="dia";
-
if (!format.empty()) {
LYXERR(Debug::GRAPHICS, "Recognised Fileformat: " << format);
return format;
Index: src/Format.cpp
===================================================================
--- src/Format.cpp (revisione 39700)
+++ src/Format.cpp (copia locale)
@@ -95,6 +95,7 @@
editor_(ed), flags_(flags)
{
extension_list_ = getVectorFromString(e, ",");
+ LYXERR(Debug::GRAPHICS, "New Format: n=" << n << ", flags=" << flags);
}
@@ -152,11 +153,28 @@
return string();
string const format = filename.guessFormatFromContents();
+ string const ext = getExtension(filename.absFileName());
+ if ((format == "gzip" || format == "zip") && !ext.empty()) {
+ string const & fmt_name = formats.getFormatFromExtension(ext);
+ LYXERR(Debug::FILES, "ext=" << ext << ", fmt_name=" << fmt_name);
+ if (!fmt_name.empty()) {
+ Format const * p_format = formats.getFormat(fmt_name);
+ if (p_format)
+ LYXERR(Debug::FILES, "zippedNative=" << p_format->zippedNative());
+ if (p_format && p_format->zippedNative())
+ return p_format->name();
+ }
+ }
if (!format.empty())
return format;
// try to find a format from the file extension.
- string const ext = getExtension(filename.absFileName());
+ return getFormatFromExtension(ext);
+}
+
+
+string Formats::getFormatFromExtension(string const & ext) const
+{
if (!ext.empty()) {
// this is ambigous if two formats have the same extension,
// but better than nothing
@@ -173,6 +191,19 @@
}
+bool Formats::isZipped(support::FileName const & filename) const {
+ string const & fname = filename.absFileName();
+ time_t timestamp = filename.lastModified();
+ map<string, ZippedInfo>::iterator it = zipped_.find(fname);
+ if (it != zipped_.end() && it->second.timestamp == timestamp)
+ return it->second.zipped;
+ string const & format = getFormatFromFile(filename);
+ bool zipped = (format == "gzip" || format == "zip");
+ zipped_.insert(pair<string, ZippedInfo>(fname, ZippedInfo(zipped, timestamp)));
+ return zipped;
+}
+
+
static string fixCommand(string const & cmd, string const & ext,
os::auto_open_mode mode)
{
Index: src/LyXRC.cpp
===================================================================
--- src/LyXRC.cpp (revisione 39700)
+++ src/LyXRC.cpp (copia locale)
@@ -55,7 +55,7 @@
namespace {
-static unsigned int const LYXRC_FILEFORMAT = 2;
+static unsigned int const LYXRC_FILEFORMAT = 3;
// when adding something to this array keep it sorted!
LexerKeyword lyxrcTags[] = {
@@ -1118,6 +1118,8 @@
flgs |= Format::document;
else if (flag == "vector")
flgs |= Format::vector;
+ else if (flag == "zipped=native")
+ flgs |= Format::zipped_native;
else if (flag == "menu=export")
flgs |= Format::export_menu;
else
@@ -2750,6 +2752,8 @@
flags.push_back("document");
if (cit->vectorFormat())
flags.push_back("vector");
+ if (cit->zippedNative())
+ flags.push_back("zipped=native");
if (cit->inExportMenu())
flags.push_back("menu=export");
Index: lib/scripts/prefs2prefs_prefs.py
===================================================================
--- lib/scripts/prefs2prefs_prefs.py (revisione 39700)
+++ lib/scripts/prefs2prefs_prefs.py (copia locale)
@@ -20,6 +20,11 @@
# Support for multiple file extensions per format.
# No conversion necessary.
+# Incremented to format 3, r????? by tomasso
+# Support for file formats that are natively (g)zipped.
+# We must add the flag zipped=native to formats that
+# were previously hardcoded in the C++ source: dia.
+
import re
@@ -101,6 +106,18 @@
return (True,
"\\Format %s \"%s,menu=export\"" % (fmat, opts))
+zipre = re.compile(r'^\\[Ff]ormat\s+("?dia"?\s+.*)\s+"([^"]*?)"')
+def zipped_native(line):
+ if not line.lower().startswith("\\format"):
+ return no_match
+ m = zipre.match(line)
+ if not m:
+ return no_match
+ fmat = m.group(1)
+ opts = m.group(2)
+ return (True,
+ "\\Format %s \"%s,zipped=native\"" % (fmat, opts))
+
########################
@@ -113,4 +130,5 @@
language_package
]],
[ 2, []],
+ [ 3, [ zipped_native ]],
]
Index: lib/configure.py
===================================================================
--- lib/configure.py (revisione 39700)
+++ lib/configure.py (copia locale)
@@ -486,7 +486,7 @@
rc_entry = [r'\Format fig fig FIG "" "%%" "%%" "vector"'])
#
checkViewerEditor('a Dia viewer and editor', ['dia'],
- rc_entry = [r'\Format dia dia DIA "" "%%" "%%" "vector"'])
+ rc_entry = [r'\Format dia dia DIA "" "%%" "%%" "vector,zipped=native"'])
#
checkViewerEditor('a Grace viewer and editor', ['xmgrace'],
rc_entry = [r'\Format agr agr Grace "" "%%" "%%" "vector"'])
@@ -1301,7 +1301,7 @@
if __name__ == '__main__':
lyx_check_config = True
outfile = 'lyxrc.defaults'
- lyxrc_fileformat = 2
+ lyxrc_fileformat = 3
rc_entries = ''
lyx_keep_temps = False
version_suffix = ''