Files I removed to remove and add from the former update.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1458 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Baruch Even 2001-02-08 13:20:24 +00:00
parent 39b3fd44b9
commit 5c867d5e0e
9 changed files with 236 additions and 343 deletions

View File

@ -1,60 +0,0 @@
// -*- 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;
}

View File

@ -1,34 +0,0 @@
// -*- 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

View File

@ -0,0 +1,74 @@
// -*- 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);
}

View File

@ -0,0 +1,77 @@
// -*- 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

View File

@ -6,7 +6,6 @@
* Copyright 1995 Matthias Ettrich.
* Copyright 1995-2000 The LyX Team.
*
* This file Copyright 2000 Baruch Even
* ================================================= */
#ifdef __GNUG__
@ -14,8 +13,9 @@
#endif
#include <config.h>
#include "XPM_Renderer.h"
#include "ImageLoaderXPM.h"
#include "frontends/support/LyXImage.h"
#include "support/filetools.h"
#include FORMS_H_LOCATION
#include XPM_H_LOCATION
@ -28,66 +28,67 @@
using std::endl;
using std::ios;
XPM_Renderer::XPM_Renderer()
: Renderer()
{}
bool XPM_Renderer::renderImage()
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;
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()),
const_cast<char *>(filename.c_str()),
&pixmap, &mask, &attrib);
if (status != XpmSuccess) {
lyxerr << "Error reading XPM file '"
<< XpmGetErrorString(status)
<< endl;
return false;
return ErrorWhileLoading;
}
// This should have been set by the XpmReadFileToPixmap call!
Assert(attrib.valuemask & XpmSize);
setPixmap(new LyXImage(pixmap), attrib.width, attrib.height);
setImage(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;
return OK;
}

View File

@ -0,0 +1,43 @@
// -*- 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

View File

@ -1,91 +0,0 @@
// -*- 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());
}

View File

@ -1,82 +0,0 @@
// -*- 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

View File

@ -1,35 +0,0 @@
// -*- 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