Am Dienstag, 10. Januar 2006 15:14 schrieb Jean-Marc Lasgouttes: > Georg> http://bugzilla.lyx.org/show_bug.cgi?id=2192 x > > Can you describe what you do? I cannot guess it from the patch.
We have no format information for a file if getFormatFromContents() does not recognize the file format. This was no problem in the old days when formats and extenions were mixed, but we currently need a format even if the default converter is used. The patch removes this requirement by adding some hardcoded decisions if the format is unknown: Convert to ppm for on-screen display, assume bitmap data (png) in insetgraphics for determining the target format, and simply leave out the format prefix when calling convert, i. e. don't call convert png:x.png eps:x.eps, but convert x.png eps:x.eps > Wouldn't it be easier for now to just recognize XCF? I don't know how easy XCF files can be recognized in getFormatFromContents(). And of course the problem would only be fixed for XCF, this patch fixes it for all unknown formats. In the long run we should replace getFormatFromContents() by a mimetype-based solution, maybe using file --mime or other existing file type databases. > The src/ChageLog entry is wrong BTW. Indeed. I attach an updated patch. Georg
Index: src/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v retrieving revision 1.2353 diff -u -p -r1.2353 ChangeLog --- src/ChangeLog 9 Jan 2006 21:00:22 -0000 1.2353 +++ src/ChangeLog 10 Jan 2006 20:10:13 -0000 @@ -1,3 +1,7 @@ +2006-01-10 Georg Baum <[EMAIL PROTECTED]> + + * converter.C (convert): handle unknown formats + 2006-01-07 Georg Baum <[EMAIL PROTECTED]> * outputparams.[Ch]: add new flag inComment Index: src/converter.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/converter.C,v retrieving revision 1.107 diff -u -p -r1.107 converter.C --- src/converter.C 16 Jul 2005 16:57:53 -0000 1.107 +++ src/converter.C 10 Jan 2006 20:10:13 -0000 @@ -294,7 +300,9 @@ bool Converters::convert(Buffer const * if (try_default) { // if no special converter defined, then we take the // default one from ImageMagic. - string const from_ext = formats.extension(from_format); + string const from_ext = from_format.empty() ? + GetExtension(from_file) : + formats.extension(from_format); string const command = "sh " + QuoteName(LibFileSearch("scripts", "convertDefault.sh")) + Index: src/insets/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v retrieving revision 1.1211 diff -u -p -r1.1211 ChangeLog --- src/insets/ChangeLog 9 Jan 2006 21:00:23 -0000 1.1211 +++ src/insets/ChangeLog 10 Jan 2006 20:10:15 -0000 @@ -1,3 +1,39 @@ +2006-01-10 Georg Baum <[EMAIL PROTECTED]> + + * insetgraphics.C (prepareFile): handle unknown formats + 2006-01-07 Georg Baum <[EMAIL PROTECTED]> * ExternalSupport.[Ch] (updateExternal): add external_in_comment flag Index: src/insets/insetgraphics.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v retrieving revision 1.283 diff -u -p -r1.283 insetgraphics.C --- src/insets/insetgraphics.C 9 Jan 2006 21:00:23 -0000 1.283 +++ src/insets/insetgraphics.C 10 Jan 2006 20:10:16 -0000 @@ -661,9 +661,8 @@ string const InsetGraphics::prepareFile( if (from.empty()) { lyxerr[Debug::GRAPHICS] << "\tCould not get file format." << endl; - return orig_file; } - string const to = findTargetFormat(from, runparams); + string const to = findTargetFormat(from.empty() ? "png" : from, runparams); string const ext = formats.extension(to); lyxerr[Debug::GRAPHICS] << "\t we have: from " << from << " to " << to << '\n'; Index: src/graphics/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/ChangeLog,v retrieving revision 1.221 diff -u -p -r1.221 ChangeLog --- src/graphics/ChangeLog 2 Nov 2005 20:11:36 -0000 1.221 +++ src/graphics/ChangeLog 10 Jan 2006 20:10:16 -0000 @@ -1,3 +1,9 @@ +2006-01-10 Georg Baum <[EMAIL PROTECTED]> + + * GraphicsCacheItem.C (convertToDisplayFormat): handle unknown + formats + * GraphicsConverter.C (Impl, build_script): ditto + 2005-11-02 Angus Leeming <[EMAIL PROTECTED]> * GraphicsCacheItem.C: trivial fix to a MSVS warning. Index: src/graphics/GraphicsCacheItem.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/GraphicsCacheItem.C,v retrieving revision 1.66 diff -u -p -r1.66 GraphicsCacheItem.C --- src/graphics/GraphicsCacheItem.C 2 Nov 2005 20:11:36 -0000 1.66 +++ src/graphics/GraphicsCacheItem.C 10 Jan 2006 20:10:16 -0000 @@ -335,8 +335,10 @@ string const findTargetFormat(string con typedef lyx::graphics::Image::FormatList FormatList; FormatList const formats = lyx::graphics::Image::loadableFormats(); - // There must be a format to load from. - BOOST_ASSERT(!formats.empty()); + // Use the standard converter if we don't know the format to load + // from. + if (!formats.empty()) + return string("ppm"); // First ascertain if we can load directly with no conversion FormatList::const_iterator it = formats.begin(); @@ -408,7 +410,6 @@ void CacheItem::Impl::convertToDisplayFo setStatus(ErrorConverting); lyxerr[Debug::GRAPHICS] << "\tCould not determine file format." << endl; - return; } lyxerr[Debug::GRAPHICS] << "\n\tThe file contains " << from << " format data." << endl; Index: src/graphics/GraphicsConverter.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/GraphicsConverter.C,v retrieving revision 1.50 diff -u -p -r1.50 GraphicsConverter.C --- src/graphics/GraphicsConverter.C 26 Apr 2005 11:12:18 -0000 1.50 +++ src/graphics/GraphicsConverter.C 10 Jan 2006 20:10:16 -0000 @@ -169,8 +169,8 @@ Converter::Impl::Impl(string const & fro script_command_ = "sh " + QuoteName(LibFileSearch("scripts", "convertDefault.sh")) + - ' ' + - QuoteName(from_format + ':' + from_file) + + ' ' + + QuoteName((from_format.empty() ? "" : from_format + ':') + from_file) + ' ' + QuoteName(to_format + ':' + to_file_); @@ -282,6 +282,9 @@ bool build_script(string const & from_fi { lyxerr[Debug::GRAPHICS] << "build_script ... "; typedef Converters::EdgePath EdgePath; + + if (from_format.empty()) + return false; // we do not use ChangeExtension because this is a basename // which may nevertheless contain a '.'