]> git.lyx.org Git - lyx.git/commitdiff
Changed to use the Converter class instead of hardcoding ImageMagick.
authorBaruch Even <baruch@lyx.org>
Mon, 2 Apr 2001 19:56:48 +0000 (19:56 +0000)
committerBaruch Even <baruch@lyx.org>
Mon, 2 Apr 2001 19:56:48 +0000 (19:56 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1874 a592a061-630c-0410-9148-cb99ea01b6c8

src/graphics/ChangeLog
src/graphics/GraphicsCacheItem.C
src/graphics/GraphicsCacheItem.h

index 9503de21c670059467ab63f249681f5b4cb887b2..ba29f1ec7349381582c7b5934956a7940f17f337 100644 (file)
@@ -1,3 +1,8 @@
+2001-04-02  Baruch Even  <baruch@lyx.org>
+
+       * GraphicsCacheItem.[Ch]: Changed to used the Converter class instead
+       of hard coding ImageMagick.
+
 2001-03-10  Baruch Even  <baruch@lyx.org>
 
        * GraphicsCache.C: Style change from (*it).field to it->field
index ee227c41116acced737887adb78154fed33bb2bd..c3929c526ad544859740147c077eeda3fdf710d8 100644 (file)
 #include "graphics/GraphicsCacheItem.h"
 #include "frontends/support/LyXImage.h"
 #include "graphics/ImageLoaderXPM.h"
+#include "converter.h"
 #include "support/filetools.h"
 #include "support/lyxlib.h"
-#include "support/syscall.h"
-
+#include "lyx_gui_misc.h"
 #include "debug.h"
+#include "support/LAssert.h"
+#include "gettext.h"
 
 using std::endl;
 
@@ -32,9 +34,12 @@ GraphicsCacheItem::GraphicsCacheItem(string const & filename)
 {
        filename_ = filename;
        
-       renderXPM(filename);
+       bool success = convertImage(filename);
        // For now we do it synchronously
-       imageConverted(0);
+       if (success) 
+               imageConverted(0);
+       else
+               imageStatus_ = ErrorConverting;
 }
 
 
@@ -62,37 +67,64 @@ GraphicsCacheItem::imageConverted(int retval)
                return;
        }
 
-       // Do the actual image loading from XPM to memory.
-       loadXPMImage(); 
+       // Do the actual image loading from file to memory.
+       loadImage();    
+}
+
+
+namespace {
+string const findTargetFormat(string const & from)
+{
+       typedef ImageLoader::FormatList FormatList;
+       FormatList formats = ImageLoaderXPM().loadableFormats();
+       Assert(formats.size() > 0); // There must be a format to load from.
+       
+       FormatList::const_iterator iter = formats.begin();
+       FormatList::const_iterator end  = formats.end();
+
+       for (; iter != end; ++iter) {
+               if (converters.IsReachable(from, *iter))
+                       break;
+       }
+       if (iter == end) {
+               // We do not know how to convert the image to something loadable.
+               lyxerr << "ERROR: Do not know how to convert image." << std::endl;
+
+               string const first(_("Cannot convert image to display format"));
+               string const second1(_("Need converter from "));
+               string const second2(_(" to "));
+               string const second(second1 + from + second2 + formats[0]);
+
+               WriteAlert(first, second);
+               
+               return string();
+       }
+
+       return (*iter);
 }
 
+} // anon namespace
+
        
 bool
-GraphicsCacheItem::renderXPM(string const & filename)
+GraphicsCacheItem::convertImage(string const & filename)
 {
-       // Create the command to do the conversion, this depends on ImageMagicks
-       // convert program.
-       string command = "convert ";
-       command += filename;
-       command += " XPM:";
-
+       string const from = GetExtension(filename);
+       string const to = findTargetFormat(from);
+       if (to.empty()) 
+               return false;
+       
        // Take only the filename part of the file, without path or extension.
        string temp = OnlyFilename(filename);
        temp = ChangeExtension(filename, string());
        
        // Add some stuff to have it a unique temp file.
-       // This tempfile is deleted in loadXPMImage after it is loaded to memory.
+       // This tempfile is deleted in loadImage after it is loaded to memory.
        tempfile = lyx::tempName(string(), temp);
        // Remove the temp file, we only want the name...
        lyx::unlink(tempfile);
-       tempfile = ChangeExtension(tempfile, ".xpm");   
-       
-       command += tempfile;
 
-       // Run the convertor.
-       lyxerr << "Launching convert to xpm, command=" << command << endl;
-       Systemcalls syscall;
-       syscall.startscript(Systemcalls::Wait, command);
+       converters.Convert(0, filename, tempfile, from, to);
 
        return true;
 }
@@ -101,7 +133,7 @@ GraphicsCacheItem::renderXPM(string const & filename)
 // This function gets called from the callback after the image has been
 // converted successfully.
 void
-GraphicsCacheItem::loadXPMImage()
+GraphicsCacheItem::loadImage()
 {
        lyxerr << "Loading XPM Image... ";
 
index 3b5c04128dc00965c684c4ef7f16e89a538ec0fb..f75b9a40db6aa50ceab9405bf2517313d5716b39 100644 (file)
@@ -61,8 +61,8 @@ public:
        void imageConverted(int retval);
 
 private:
-       bool renderXPM(string const & filename);
-       void loadXPMImage();
+       bool convertImage(string const & filename);
+       void loadImage();
 
        /** The filename we refer too.
            This is used when removing ourselves from the cache.