+++ /dev/null
-// -*- C++ -*-
-/* This file is part of
- * =================================================
- *
- * LyX, The Document Processor
- * Copyright 1995 Matthias Ettrich.
- * Copyright 1995-2000 The LyX Team.
- *
- * This file Copyright 2000 Baruch Even
- * ================================================= */
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include <config.h>
-#include "EPS_Renderer.h"
-
-#include FORMS_H_LOCATION
-#include <iostream>
-#include <fstream>
-
-#include "support/LAssert.h"
-#include "debug.h"
-
-using std::endl;
-using std::ios;
-
-
-EPS_Renderer::EPS_Renderer()
- : Renderer()
-{}
-
-
-bool EPS_Renderer::renderImage()
-{
- return false;
-}
-
-
-bool EPS_Renderer::isImageFormatOK(string const & filename) const
-{
- std::ifstream is(filename.c_str());
-
- // The signature of the file without the spaces.
- static const char str[] = "%!PS";
- const char * ptr = str;
-
- do {
- char c;
- is >> c;
-
- if (c != *ptr)
- return false;
-
- ++ptr;
- } while (*ptr != '\0');
-
- return true;
-}
+++ /dev/null
-// -*- C++ -*-
-/* This file is part of
- * =================================================
- *
- * LyX, The Document Processor
- * Copyright 1995 Matthias Ettrich.
- * Copyright 1995-2000 The LyX Team.
- *
- * This file Copyright 2000 Baruch Even
- * ================================================= */
-
-#ifndef EPS_RENDERER_H
-#define EPS_RENDERER_H
-
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-#include "graphics/Renderer.h"
-
-///
-class EPS_Renderer : public Renderer {
-public:
- /// c-tor.
- EPS_Renderer();
-
- /// Load the EPS image and create a pixmap out of it.
- virtual bool renderImage();
-private:
- /// Verify that filename is really an EPS file.
- virtual bool isImageFormatOK(string const & filename) const;
-};
-
-#endif
--- /dev/null
+// -*- C++ -*-
+/* This file is part of
+ * =================================================
+ *
+ * LyX, The Document Processor
+ * Copyright 1995 Matthias Ettrich.
+ * Copyright 1995-2000 The LyX Team.
+ *
+ * ================================================= */
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include <config.h>
+#include "ImageLoader.h"
+#include "frontends/support/LyXImage.h"
+
+#include "support/filetools.h"
+
+ImageLoader::ImageLoader()
+ : image_(0)
+{
+}
+
+ImageLoader::~ImageLoader()
+{
+ freeImage();
+}
+
+bool ImageLoader::isImageFormatOK(string const & /*filename*/) const
+{
+ return false;
+}
+
+void ImageLoader::setImage(LyXImage * image)
+{
+ freeImage();
+
+ image_ = image;
+}
+
+void ImageLoader::freeImage()
+{
+ delete image_;
+ image_ = 0;
+}
+
+ImageLoader::FormatList const
+ImageLoader::loadableFormats() const
+{
+ return FormatList();
+}
+
+ImageLoader::Result
+ImageLoader::loadImage(string const & filename)
+{
+ // Make sure file exists and is readable.
+ if (! IsFileReadable(filename)) {
+ lyxerr << "No XPM file found." << endl;
+ return NoFile;
+ }
+
+ // Verify that the file format is correct.
+ if (! isImageFormatOK(filename)) {
+ lyxerr << "File format incorrect." << endl;
+ return ImageFormatUnknown;
+ }
+
+ freeImage();
+
+ return runImageLoader(filename);
+}
+
--- /dev/null
+// -*- C++ -*-
+/* This file is part of
+ * =================================================
+ *
+ * LyX, The Document Processor
+ * Copyright 1995 Matthias Ettrich.
+ * Copyright 1995-2000 The LyX Team.
+ *
+ * ================================================= */
+
+#ifndef IMAGELOADER_H
+#define IMAGELOADER_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "LString.h"
+#include "boost/utility.hpp"
+#include <vector>
+
+class LyXImage;
+
+/** ImageLoader is a base class for all image loaders. An ImageLoader instance is
+ * platform dependent, and knows how to load some image formats into a memory
+ * representation (LyXImage).
+ *
+ * It may do the image loading asynchronously.
+ *
+ * @Author Baruch Even, <baruch.even@writeme.com>
+ */
+class ImageLoader : public noncopyable {
+public:
+ /// Errors that can be returned from this class.
+ enum Result {
+ OK = 0,
+ ImageFormatUnknown, // This loader doesn't know how to load this file.
+ NoFile, // File doesn't exists.
+ ErrorWhileLoading, // Unknown error when loading.
+ };
+
+ /// A list of supported formats.
+ typedef vector<string> FormatList;
+
+ /// c-tor.
+ ImageLoader();
+ /// d-tor.
+ virtual ~ImageLoader();
+
+ /// Start loading the image file.
+ ImageLoader::Result loadImage(string const & filename);
+
+ /// Get the last rendered pixmap. Returns 0 if no image is ready.
+ LyXImage * getImage() const { return image_; };
+
+ /// Return the list of loadable formats.
+ virtual FormatList const loadableFormats() const;
+
+protected:
+ /// Verify that the file is one that we can handle.
+ virtual bool isImageFormatOK(string const & filename) const = 0;
+
+ /// Do the actual image loading.
+ virtual Result runImageLoader(string const & filename) = 0;
+
+ /// Set the image that was loaded.
+ void setImage(LyXImage * image);
+
+private:
+ /// Free the loaded image.
+ void freeImage();
+
+ /// The loaded image.
+ LyXImage * image_;
+};
+
+#endif
--- /dev/null
+// -*- C++ -*-
+/* This file is part of
+ * =================================================
+ *
+ * LyX, The Document Processor
+ * Copyright 1995 Matthias Ettrich.
+ * Copyright 1995-2000 The LyX Team.
+ *
+ * ================================================= */
+
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include <config.h>
+#include "ImageLoaderXPM.h"
+#include "frontends/support/LyXImage.h"
+#include "support/filetools.h"
+
+#include FORMS_H_LOCATION
+#include XPM_H_LOCATION
+#include <iostream>
+#include <fstream>
+
+#include "support/LAssert.h"
+#include "debug.h"
+
+using std::endl;
+using std::ios;
+
+bool ImageLoaderXPM::isImageFormatOK(string const & filename) const
+{
+ std::ifstream is(filename.c_str(), ios::in);
+
+ // The signature of the file without the spaces.
+ static char const str[] = "/*XPM*/";
+ char const * ptr = str;
+
+ for (; *ptr != '\0'; ++ptr) {
+ char c;
+ is >> c;
+
+ if (c != *ptr)
+ return false;
+ }
+
+ return true;
+}
+
+ImageLoaderXPM::FormatList const
+ImageLoaderXPM::loadableFormats() const
+{
+ FormatList formats;
+ formats.push_back("xpm");
+
+ return formats;
+}
+
+ImageLoader::Result
+ImageLoaderXPM::runImageLoader(string const & filename)
+{
+ Display * display = fl_get_display();
+
+//(BE 2000-08-05)
+#warning This might be a dirty thing, but I dont know any other solution.
+ Screen * screen = ScreenOfDisplay(display, fl_screen);
+
+ Pixmap pixmap;
+ Pixmap mask;
+ XpmAttributes attrib;
+ attrib.valuemask = 0;
+
+ int status = XpmReadFileToPixmap(
+ display,
+ XRootWindowOfScreen(screen),
+ const_cast<char *>(filename.c_str()),
+ &pixmap, &mask, &attrib);
+
+ if (status != XpmSuccess) {
+ lyxerr << "Error reading XPM file '"
+ << XpmGetErrorString(status)
+ << endl;
+ return ErrorWhileLoading;
+ }
+
+ // This should have been set by the XpmReadFileToPixmap call!
+ Assert(attrib.valuemask & XpmSize);
+
+ setImage(new LyXImage(pixmap, attrib.width, attrib.height));
+
+ XpmFreeAttributes(&attrib);
+
+ return OK;
+}
--- /dev/null
+// -*- C++ -*-
+/* This file is part of
+ * =================================================
+ *
+ * LyX, The Document Processor
+ * Copyright 1995 Matthias Ettrich.
+ * Copyright 1995-2000 The LyX Team.
+ *
+ * ================================================= */
+
+#ifndef IMAGELOADER_XPM_H
+#define IMAGELOADER_XPM_H
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "graphics/ImageLoader.h"
+
+/** ImageLoaderXPM is an implementation of ImageLoader that can load XPM images by
+ * using libXPM.
+ *
+ * @Author Baruch Even, <baruch.even@writeme.com>
+ */
+class ImageLoaderXPM : public ImageLoader {
+public:
+ /// c-tor.
+ ImageLoaderXPM() {};
+ /// d-tor.
+ virtual ~ImageLoaderXPM() {};
+
+ /// Return the list of loadable formats.
+ virtual FormatList const loadableFormats() const;
+
+protected:
+ /// Verify that the file is one that we can handle.
+ virtual bool isImageFormatOK(string const & filename) const;
+
+ /// Do the actual image loading.
+ virtual ImageLoader::Result runImageLoader(string const & filename);
+};
+
+#endif
+++ /dev/null
-// -*- C++ -*-
-/* This file is part of
- * =================================================
- *
- * LyX, The Document Processor
- * Copyright 1995 Matthias Ettrich.
- * Copyright 1995-2000 The LyX Team.
- *
- * This file Copyright 2000 Baruch Even
- * ================================================= */
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include <config.h>
-#include "Renderer.h"
-
-#include FORMS_H_LOCATION
-#include "support/filetools.h"
-
-#include "frontends/support/LyXImage.h"
-
-Renderer::Renderer()
- : width_(0), height_(0), pixmapLoaded_(false)
-{}
-
-Renderer::~Renderer()
-{
- freePixmap();
-}
-
-bool Renderer::setFilename(string const & filename)
-{
- // Make sure file exists and is readable.
- if (! IsFileReadable(filename)) {
- return false;
- }
-
- // Verify that the file format is correct.
- if (! isImageFormatOK(filename)) {
- return false;
- }
-
- filename_ = filename;
- return true;
-}
-
-bool Renderer::renderImage()
-{
- return false;
-}
-
-bool Renderer::isImageFormatOK(string const & /*filename*/) const
-{
- return false;
-}
-
-void Renderer::setPixmap(LyXImage * pixmap, unsigned int width, unsigned int height)
-{
- freePixmap();
-
- pixmap_ = pixmap;
- width_ = width;
- height_ = height;
- pixmapLoaded_ = true;
-}
-
-LyXImage * Renderer::getPixmap() const
-{
- return pixmap_;
-}
-
-unsigned int Renderer::getWidth() const
-{ return width_; }
-
-unsigned int Renderer::getHeight() const
-{
- return height_;
-}
-
-string const & Renderer::getFilename() const
-{
- return filename_;
-}
-
-void Renderer::freePixmap()
-{
- if (pixmapLoaded_)
- XFreePixmap(fl_get_display(), pixmap_->getPixmap());
-}
+++ /dev/null
-// -*- C++ -*-
-/* This file is part of
- * =================================================
- *
- * LyX, The Document Processor
- * Copyright 1995 Matthias Ettrich.
- * Copyright 1995-2000 The LyX Team.
- *
- * This file Copyright 2000 Baruch Even
- * ================================================= */
-
-#ifndef RENDERER_H
-#define RENDERER_H
-
-#include <config.h>
-
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-#include "LString.h"
-#include "X11/Xlib.h"
-#include "boost/utility.hpp"
-
-class LyXImage;
-
-/** Renderer is a base class that is used to take an image format, and
- * render it into a Pixmap in order to be able to display it later on
- * in LyX. Essentially it's job is to load an image format and create
- * a Pixmap from it. It also needs to do various transforms on the
- * image, like Rotation, Resize and color reduction.
- *
- * @Author Baruch Even, <baruch.even@writeme.com>
- */
-class Renderer : public noncopyable {
-public:
- /// c-tor.
- Renderer();
- /// d-tor.
- virtual ~Renderer();
-
- /// Set the filename that we will render
- bool setFilename(string const & filename);
-
- /// Render the image, doing the necessary transforms.
- virtual bool renderImage() = 0;
-
- /// Get the last rendered pixmap.
- LyXImage * getPixmap() const;
-
- /// Get the width of the pixmap.
- unsigned int getWidth() const;
-
- /// Get the height of the pixmap.
- unsigned int getHeight() const;
-
-protected:
- /// Verify that the file is one that we can handle.
- virtual bool isImageFormatOK(string const & filename) const = 0;
-
- /// Set the pixmap.
- void setPixmap(LyXImage * pixmap, unsigned int width, unsigned int height);
- ///
- string const & getFilename() const;
-
-private:
- /// Free the loaded pixmap
- void freePixmap();
-
- /// The filename of the image file that we are responsible for.
- string filename_;
- /// The last rendered pixmap.
- LyXImage * pixmap_;
- /// The width of the rendered pixmap.
- unsigned int width_;
- /// The height of the rendered pixmap.
- unsigned int height_;
- /// is Pixmap ready?
- bool pixmapLoaded_;
-};
-
-#endif
+++ /dev/null
-// -*- C++ -*-
-/* This file is part of
- * =================================================
- *
- * LyX, The Document Processor
- * Copyright 1995 Matthias Ettrich.
- * Copyright 1995-2000 The LyX Team.
- *
- * This file Copyright 2000 Baruch Even
- * ================================================= */
-
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include <config.h>
-#include "XPM_Renderer.h"
-#include "frontends/support/LyXImage.h"
-
-#include FORMS_H_LOCATION
-#include XPM_H_LOCATION
-#include <iostream>
-#include <fstream>
-
-#include "support/LAssert.h"
-#include "debug.h"
-
-using std::endl;
-using std::ios;
-
-
-XPM_Renderer::XPM_Renderer()
- : Renderer()
-{}
-
-
-bool XPM_Renderer::renderImage()
-{
- Pixmap pixmap;
- Pixmap mask;
- XpmAttributes attrib;
- attrib.valuemask = 0;
-
- Display * display = fl_get_display();
-
-//(BE 2000-08-05)
-//#warning This might be a dirty thing, but I dont know any other solution.
- Screen * screen = ScreenOfDisplay(display, fl_screen);
-
- int status = XpmReadFileToPixmap(
- display,
- XRootWindowOfScreen(screen),
- const_cast<char *>(getFilename().c_str()),
- &pixmap, &mask, &attrib);
-
- if (status != XpmSuccess) {
- lyxerr << "Error reading XPM file '"
- << XpmGetErrorString(status)
- << endl;
- return false;
- }
-
- // This should have been set by the XpmReadFileToPixmap call!
- Assert(attrib.valuemask & XpmSize);
-
- setPixmap(new LyXImage(pixmap), attrib.width, attrib.height);
-
- XpmFreeAttributes(&attrib);
-
- return true;
-}
-
-
-bool XPM_Renderer::isImageFormatOK(string const & filename) const
-{
- std::ifstream is(filename.c_str(), ios::in);
-
- // The signature of the file without the spaces.
- static const char str[] = "/*XPM*/";
- const char * ptr = str;
-
- do {
- char c;
- is >> c;
-
- if (c != *ptr)
- return false;
-
- ++ptr;
- } while (*ptr != '\0');
-
- return true;
-}
+++ /dev/null
-// -*- C++ -*-
-/* This file is part of
- * =================================================
- *
- * LyX, The Document Processor
- * Copyright 1995 Matthias Ettrich.
- * Copyright 1995-2000 The LyX Team.
- *
- * This file Copyright 2000 Baruch Even
- * ================================================= */
-
-#ifndef XPM_RENDERER_H
-#define XPM_RENDERER_H
-
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-#include "graphics/Renderer.h"
-
-///
-class XPM_Renderer : public Renderer {
-public:
- /// c-tor.
- XPM_Renderer();
-
- /// Load the XPM image and create a pixmap out of it.
- virtual bool renderImage();
-
-private:
- /// Verify that filename is really an XPM file.
- virtual bool isImageFormatOK(string const & filename) const;
-};
-
-#endif