From 20b45450f6abbeaceafebebc4aaacb692abf63f9 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 6 Jun 2008 11:34:49 +0000 Subject: [PATCH] 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 --- development/scons/scons_manifest.py | 4 +- src/frontends/qt4/GuiApplication.cpp | 1 - src/frontends/qt4/GuiImage.cpp | 61 ---------------------------- src/frontends/qt4/GuiImage.h | 3 -- src/graphics/GraphicsCache.cpp | 42 ++++++++++++++++++- src/graphics/GraphicsCache.h | 2 +- src/graphics/GraphicsCacheItem.cpp | 6 ++- src/graphics/GraphicsImage.cpp | 4 -- src/graphics/GraphicsImage.h | 5 --- src/graphics/PreviewLoader.cpp | 2 +- src/support/Makefile.am | 2 + src/support/imagetools.cpp | 55 +++++++++++++++++++++++++ src/support/imagetools.h | 27 ++++++++++++ 13 files changed, 133 insertions(+), 81 deletions(-) create mode 100644 src/support/imagetools.cpp create mode 100644 src/support/imagetools.h diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index ab30a4b0d0..af81ae3ffe 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -302,6 +302,7 @@ src_support_header_files = Split(''' foreach.h gettext.h gzstream.h + imagetools.h lassert.h limited_stack.h lstrings.h @@ -336,8 +337,9 @@ src_support_files = Split(''' docstring.cpp environment.cpp filetools.cpp - gzstream.cpp gettext.cpp + gzstream.cpp + imagetools.cpp kill.cpp lassert.cpp lstrings.cpp diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 4757da8954..161000a5af 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -676,7 +676,6 @@ GuiApplication::GuiApplication(int & argc, char ** argv) using namespace lyx::graphics; Image::newImage = boost::bind(&GuiImage::newImage); - Image::loadableFormats = boost::bind(&GuiImage::loadableFormats); // needs to be done before reading lyxrc QWidget w; diff --git a/src/frontends/qt4/GuiImage.cpp b/src/frontends/qt4/GuiImage.cpp index a308429147..4e747808b2 100644 --- a/src/frontends/qt4/GuiImage.cpp +++ b/src/frontends/qt4/GuiImage.cpp @@ -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 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::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) : Image(other), original_(other.original_), transformed_(other.transformed_), diff --git a/src/frontends/qt4/GuiImage.h b/src/frontends/qt4/GuiImage.h index 675053619f..57406188ce 100644 --- a/src/frontends/qt4/GuiImage.h +++ b/src/frontends/qt4/GuiImage.h @@ -27,9 +27,6 @@ public: /// Access to this class is through this static method. static Image * newImage(); - /// Return the list of loadable formats. - static FormatList loadableFormats(); - /// Retrieve the buffered pixmap. QPixmap const & qpixmap() const { return transformed_pixmap_; } diff --git a/src/graphics/GraphicsCache.cpp b/src/graphics/GraphicsCache.cpp index 89c5053cb6..d36de0fbe2 100644 --- a/src/graphics/GraphicsCache.cpp +++ b/src/graphics/GraphicsCache.cpp @@ -15,9 +15,12 @@ #include "GraphicsCacheItem.h" #include "GraphicsImage.h" +#include "Format.h" + #include "support/debug.h" #include "support/FileName.h" #include "support/filetools.h" +#include "support/imagetools.h" #include @@ -59,9 +62,44 @@ Cache::~Cache() } -vector Cache::loadableFormats() const +vector const & Cache::loadableFormats() const { - return Image::loadableFormats(); + static vector 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 nformat = loadableImageFormats(); + + vector::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::const_iterator fbegin = fmts.begin(); + vector::const_iterator fend = fmts.end(); + for (vector::const_iterator fit = fbegin; fit != fend; ++fit) { + if (fit != fbegin) + LYXERR(Debug::GRAPHICS, ", "); + LYXERR(Debug::GRAPHICS, *fit); + } + LYXERR(Debug::GRAPHICS, '\n'); + } + + return fmts; } diff --git a/src/graphics/GraphicsCache.h b/src/graphics/GraphicsCache.h index a422623933..0eb35a36fb 100644 --- a/src/graphics/GraphicsCache.h +++ b/src/graphics/GraphicsCache.h @@ -44,7 +44,7 @@ public: * Other formats can be loaded if a converter to a loadable format * can be defined. */ - std::vector loadableFormats() const; + std::vector const & loadableFormats() const; /// Add a graphics file to the cache. void add(support::FileName const & file) const; diff --git a/src/graphics/GraphicsCacheItem.cpp b/src/graphics/GraphicsCacheItem.cpp index 13d42a2bfe..7448f2318e 100644 --- a/src/graphics/GraphicsCacheItem.cpp +++ b/src/graphics/GraphicsCacheItem.cpp @@ -13,6 +13,8 @@ #include #include "GraphicsCacheItem.h" + +#include "GraphicsCache.h" #include "GraphicsConverter.h" #include "GraphicsImage.h" @@ -320,8 +322,8 @@ void CacheItem::Impl::imageLoaded(bool success) static string const findTargetFormat(string const & from) { - typedef lyx::graphics::Image::FormatList FormatList; - FormatList const formats = lyx::graphics::Image::loadableFormats(); + typedef vector FormatList; + FormatList const & formats = Cache::get().loadableFormats(); // There must be a format to load from. LASSERT(!formats.empty(), /**/); diff --git a/src/graphics/GraphicsImage.cpp b/src/graphics/GraphicsImage.cpp index ee0274e09f..2009032b92 100644 --- a/src/graphics/GraphicsImage.cpp +++ b/src/graphics/GraphicsImage.cpp @@ -25,10 +25,6 @@ namespace graphics { // instance of a viable derived class. boost::function Image::newImage; -/// Return the list of loadable formats. -boost::function Image::loadableFormats; - - Dimension Image::scaledDimension(Params const & params) const { // scale only when value > 0 diff --git a/src/graphics/GraphicsImage.h b/src/graphics/GraphicsImage.h index 08dfd40391..28eef96647 100644 --- a/src/graphics/GraphicsImage.h +++ b/src/graphics/GraphicsImage.h @@ -46,11 +46,6 @@ public: */ static boost::function newImage; - /// - typedef std::vector FormatList; - /// Return the list of loadable formats. - static boost::function loadableFormats; - /// virtual ~Image() {} diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp index 67798581f0..3c3fd9d38a 100644 --- a/src/graphics/PreviewLoader.cpp +++ b/src/graphics/PreviewLoader.cpp @@ -73,7 +73,7 @@ lyx::Converter const * setConverter() typedef vector FmtList; 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 const end = loadableFormats.end(); diff --git a/src/support/Makefile.am b/src/support/Makefile.am index 1c1f8a038d..983dc36cbf 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -62,6 +62,8 @@ liblyxsupport_la_SOURCES = \ gettext.h \ gzstream.cpp \ gzstream.h \ + imagetools.cpp \ + imagetools.h \ kill.cpp \ lassert.h \ lassert.cpp \ diff --git a/src/support/imagetools.cpp b/src/support/imagetools.cpp new file mode 100644 index 0000000000..00551d133a --- /dev/null +++ b/src/support/imagetools.cpp @@ -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 + +#include "support/debug.h" +#include "support/imagetools.h" +#include "support/lstrings.h" + +#include +#include +#include + +using namespace std; + +namespace lyx { +namespace support { + +/// Return the list of loadable formats. +vector loadableImageFormats() +{ + vector fmts; + + QList 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::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 diff --git a/src/support/imagetools.h b/src/support/imagetools.h new file mode 100644 index 0000000000..c9317ef520 --- /dev/null +++ b/src/support/imagetools.h @@ -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 +#include + +namespace lyx { +namespace support { + +/// Return the list of loadable formats. +std::vector loadableImageFormats(); + +} // namespace support +} // namespace lyx + +#endif // IMAGETOOLS_H -- 2.39.5