move GuiImage::loadableFormats() to support/imagetools.{h,cpp} and simplify this whole stuff. What a mess!

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25161 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-06-06 11:34:49 +00:00
parent c6ecad82c9
commit 20b45450f6
13 changed files with 133 additions and 81 deletions

View File

@ -302,6 +302,7 @@ src_support_header_files = Split('''
foreach.h foreach.h
gettext.h gettext.h
gzstream.h gzstream.h
imagetools.h
lassert.h lassert.h
limited_stack.h limited_stack.h
lstrings.h lstrings.h
@ -336,8 +337,9 @@ src_support_files = Split('''
docstring.cpp docstring.cpp
environment.cpp environment.cpp
filetools.cpp filetools.cpp
gzstream.cpp
gettext.cpp gettext.cpp
gzstream.cpp
imagetools.cpp
kill.cpp kill.cpp
lassert.cpp lassert.cpp
lstrings.cpp lstrings.cpp

View File

@ -676,7 +676,6 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
using namespace lyx::graphics; using namespace lyx::graphics;
Image::newImage = boost::bind(&GuiImage::newImage); Image::newImage = boost::bind(&GuiImage::newImage);
Image::loadableFormats = boost::bind(&GuiImage::loadableFormats);
// needs to be done before reading lyxrc // needs to be done before reading lyxrc
QWidget w; QWidget w;

View File

@ -39,67 +39,6 @@ Image * GuiImage::newImage()
} }
/// Return the list of loadable formats.
Image::FormatList GuiImage::loadableFormats()
{
static FormatList fmts;
if (!fmts.empty())
return fmts;
// The formats recognised by LyX
Formats::const_iterator begin = formats.begin();
Formats::const_iterator end = formats.end();
//LYXERR(Debug::GRAPHICS,
// "D:/msys/home/yns/src/lyx-devel/lib/images/banner.png mis of format: "
// << Pic.pictureFormat("D:/msys/.../banner.png"))
//if (Pic.pictureFormat("D:/msys/.../banner.png"))
// LYXERR(Debug::GRAPHICS, "pictureFormat not returned NULL\n"
// << "Supported formats are: " << Pic.inputFormats());
QList<QByteArray> qt_formats = QImageReader::supportedImageFormats();
LYXERR(Debug::GRAPHICS,
"\nThe image loader can load the following directly:\n");
if (qt_formats.empty())
LYXERR(Debug::GRAPHICS, "\nQt4 Problem: No Format available!");
for (QList<QByteArray>::const_iterator it = qt_formats.begin(); it != qt_formats.end(); ++it) {
LYXERR(Debug::GRAPHICS, (const char *) *it << ", ");
string ext = ascii_lowercase((const char *) *it);
// special case
if (ext == "jpeg")
ext = "jpg";
for (Formats::const_iterator fit = begin; fit != end; ++fit)
if (fit->extension() == ext) {
fmts.push_back(fit->name());
break;
}
}
if (lyxerr.debugging()) {
LYXERR(Debug::GRAPHICS, "Of these, LyX recognises the following formats:");
FormatList::const_iterator fbegin = fmts.begin();
FormatList::const_iterator fend = fmts.end();
for (FormatList::const_iterator fit = fbegin; fit != fend; ++fit) {
if (fit != fbegin)
LYXERR(Debug::GRAPHICS, ", ");
LYXERR(Debug::GRAPHICS, *fit);
}
LYXERR(Debug::GRAPHICS, '\n');
}
return fmts;
}
GuiImage::GuiImage(GuiImage const & other) GuiImage::GuiImage(GuiImage const & other)
: Image(other), original_(other.original_), : Image(other), original_(other.original_),
transformed_(other.transformed_), transformed_(other.transformed_),

View File

@ -27,9 +27,6 @@ public:
/// Access to this class is through this static method. /// Access to this class is through this static method.
static Image * newImage(); static Image * newImage();
/// Return the list of loadable formats.
static FormatList loadableFormats();
/// Retrieve the buffered pixmap. /// Retrieve the buffered pixmap.
QPixmap const & qpixmap() const { return transformed_pixmap_; } QPixmap const & qpixmap() const { return transformed_pixmap_; }

View File

@ -15,9 +15,12 @@
#include "GraphicsCacheItem.h" #include "GraphicsCacheItem.h"
#include "GraphicsImage.h" #include "GraphicsImage.h"
#include "Format.h"
#include "support/debug.h" #include "support/debug.h"
#include "support/FileName.h" #include "support/FileName.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/imagetools.h"
#include <map> #include <map>
@ -59,9 +62,44 @@ Cache::~Cache()
} }
vector<string> Cache::loadableFormats() const vector<string> const & Cache::loadableFormats() const
{ {
return Image::loadableFormats(); static vector<string> fmts;
if (!fmts.empty())
return fmts;
// The formats recognised by LyX
Formats::const_iterator begin = formats.begin();
Formats::const_iterator end = formats.end();
// The formats natively loadable.
vector<string> nformat = loadableImageFormats();
vector<string>::const_iterator it = nformat.begin();
for (; it != nformat.end(); ++it) {
for (Formats::const_iterator fit = begin; fit != end; ++fit) {
if (fit->extension() == *it) {
fmts.push_back(fit->name());
break;
}
}
}
if (lyxerr.debugging()) {
LYXERR(Debug::GRAPHICS, "LyX recognises the following image formats:");
vector<string>::const_iterator fbegin = fmts.begin();
vector<string>::const_iterator fend = fmts.end();
for (vector<string>::const_iterator fit = fbegin; fit != fend; ++fit) {
if (fit != fbegin)
LYXERR(Debug::GRAPHICS, ", ");
LYXERR(Debug::GRAPHICS, *fit);
}
LYXERR(Debug::GRAPHICS, '\n');
}
return fmts;
} }

View File

@ -44,7 +44,7 @@ public:
* Other formats can be loaded if a converter to a loadable format * Other formats can be loaded if a converter to a loadable format
* can be defined. * can be defined.
*/ */
std::vector<std::string> loadableFormats() const; std::vector<std::string> const & loadableFormats() const;
/// Add a graphics file to the cache. /// Add a graphics file to the cache.
void add(support::FileName const & file) const; void add(support::FileName const & file) const;

View File

@ -13,6 +13,8 @@
#include <config.h> #include <config.h>
#include "GraphicsCacheItem.h" #include "GraphicsCacheItem.h"
#include "GraphicsCache.h"
#include "GraphicsConverter.h" #include "GraphicsConverter.h"
#include "GraphicsImage.h" #include "GraphicsImage.h"
@ -320,8 +322,8 @@ void CacheItem::Impl::imageLoaded(bool success)
static string const findTargetFormat(string const & from) static string const findTargetFormat(string const & from)
{ {
typedef lyx::graphics::Image::FormatList FormatList; typedef vector<string> FormatList;
FormatList const formats = lyx::graphics::Image::loadableFormats(); FormatList const & formats = Cache::get().loadableFormats();
// There must be a format to load from. // There must be a format to load from.
LASSERT(!formats.empty(), /**/); LASSERT(!formats.empty(), /**/);

View File

@ -25,10 +25,6 @@ namespace graphics {
// instance of a viable derived class. // instance of a viable derived class.
boost::function<Image *()> Image::newImage; boost::function<Image *()> Image::newImage;
/// Return the list of loadable formats.
boost::function<Image::FormatList()> Image::loadableFormats;
Dimension Image::scaledDimension(Params const & params) const Dimension Image::scaledDimension(Params const & params) const
{ {
// scale only when value > 0 // scale only when value > 0

View File

@ -46,11 +46,6 @@ public:
*/ */
static boost::function<Image *()> newImage; static boost::function<Image *()> newImage;
///
typedef std::vector<std::string> FormatList;
/// Return the list of loadable formats.
static boost::function<FormatList()> loadableFormats;
/// ///
virtual ~Image() {} virtual ~Image() {}

View File

@ -73,7 +73,7 @@ lyx::Converter const * setConverter()
typedef vector<string> FmtList; typedef vector<string> FmtList;
typedef lyx::graphics::Cache GCache; typedef lyx::graphics::Cache GCache;
FmtList const loadableFormats = GCache::get().loadableFormats(); FmtList const & loadableFormats = GCache::get().loadableFormats();
FmtList::const_iterator it = loadableFormats.begin(); FmtList::const_iterator it = loadableFormats.begin();
FmtList::const_iterator const end = loadableFormats.end(); FmtList::const_iterator const end = loadableFormats.end();

View File

@ -62,6 +62,8 @@ liblyxsupport_la_SOURCES = \
gettext.h \ gettext.h \
gzstream.cpp \ gzstream.cpp \
gzstream.h \ gzstream.h \
imagetools.cpp \
imagetools.h \
kill.cpp \ kill.cpp \
lassert.h \ lassert.h \
lassert.cpp \ lassert.cpp \

View File

@ -0,0 +1,55 @@
/**
* \file imagetools.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Abdelrazak Younes
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "support/debug.h"
#include "support/imagetools.h"
#include "support/lstrings.h"
#include <QByteArray>
#include <QImageReader>
#include <QList>
using namespace std;
namespace lyx {
namespace support {
/// Return the list of loadable formats.
vector<string> loadableImageFormats()
{
vector<string> fmts;
QList<QByteArray> qt_formats = QImageReader::supportedImageFormats();
LYXERR(Debug::GRAPHICS,
"\nThe image loader can load the following directly:\n");
if (qt_formats.empty())
LYXERR(Debug::GRAPHICS, "\nQt4 Problem: No Format available!");
for (QList<QByteArray>::const_iterator it = qt_formats.begin(); it != qt_formats.end(); ++it) {
LYXERR(Debug::GRAPHICS, (const char *) *it << ", ");
string ext = ascii_lowercase((const char *) *it);
// special case
if (ext == "jpeg")
ext = "jpg";
fmts.push_back(ext);
}
return fmts;
}
} // namespace support
} // namespace lyx

27
src/support/imagetools.h Normal file
View File

@ -0,0 +1,27 @@
// -*- C++ -*-
/**
* \file imagetools.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author João Luis M. Assirati
*
* Full author contact details are available in file CREDITS.
*/
#ifndef IMAGETOOLS_H
#define IMAGETOOLS_H
#include <string>
#include <vector>
namespace lyx {
namespace support {
/// Return the list of loadable formats.
std::vector<std::string> loadableImageFormats();
} // namespace support
} // namespace lyx
#endif // IMAGETOOLS_H