]> git.lyx.org Git - features.git/commitdiff
(Herbert): discover the "Bounding Box" of non-(e)ps graphics files, and
authorAngus Leeming <leeming@lyx.org>
Thu, 11 Apr 2002 17:40:44 +0000 (17:40 +0000)
committerAngus Leeming <leeming@lyx.org>
Thu, 11 Apr 2002 17:40:44 +0000 (17:40 +0000)
use it in the graphics dialog.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3973 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlGraphics.C
src/graphics/ChangeLog
src/graphics/GraphicsCache.C
src/graphics/GraphicsCache.h
src/graphics/GraphicsCacheItem.C
src/graphics/GraphicsCacheItem.h

index 1bd150619df755cbd26e0cc87e65edff77e110c3..b36b1bc88dc85667f3dcb7ae1dc8bd8260cab75b 100644 (file)
@@ -1,3 +1,7 @@
+2002-04-11  Herbert Voss  <voss@perce.de>
+
+       * ControlGraphics.C: read BoundingBox also from non (e)ps files.
+
 2002-04-08  Adrien Rebollo  <adrien.rebollo@gmx.fr>
 
        * ControlAboutlyx.C (getVersion): two _() forgotten
index 8c459d13eecee161c89bcdfafde89dd0c8eeb55a..4437f0f7819ea6a7a95d5e0c8739530ee991caaf 100644 (file)
@@ -23,6 +23,9 @@
 #include "ButtonControllerBase.h"
 #include "ControlGraphics.h"
 #include "ControlInset.tmpl"
+
+#include "helper_funcs.h"
+
 #include "buffer.h"
 #include "BufferView.h"
 #include "Dialogs.h"
 #include "gettext.h"
 #include "lyxrc.h"
 
+#include "graphics/GraphicsCache.h"
+
 #include "insets/insetgraphics.h"
-#include "insets/insetgraphicsParams.h" // need operator!=()
+#include "insets/insetgraphicsParams.h"
 
-#include "support/FileInfo.h"  // for FileInfo
-#include "helper_funcs.h"
 #include "support/lstrings.h"
-#include "support/filetools.h" // for AddName, zippedFile
+#include "support/filetools.h"
+#include "support/FileInfo.h"
+
 
 using std::pair;
 using std::make_pair;
 using std::ifstream;
-
 ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
        : ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
 {
@@ -104,7 +109,18 @@ string const ControlGraphics::Browse(string const & in_name)
 
 string const ControlGraphics::readBB(string const & file)
 {
-       return readBB_from_PSFile(MakeAbsPath(file, lv_.buffer()->filePath()));
+       string const abs_file = MakeAbsPath(file, lv_.buffer()->filePath());
+
+       string const from = getExtFromContents(abs_file);       
+       // Check if we have a Postscript file, then it's easy
+       if (contains(from, "ps"))
+               return readBB_from_PSFile(abs_file);
+
+       // we don't, so ask the Graphics Cache if it has loaded the file
+       grfx::GCache & gc = grfx::GCache::get();
+       return ("0 0 " + 
+               tostr(gc.raw_width(abs_file)) + ' ' + 
+               tostr(gc.raw_height(abs_file)));
 }
 
 
index 67be3c9a291ed784a25cadbdaca9673f0f4d3119..f8dea4bd094cc422d165feced8b3d1651b314070 100644 (file)
@@ -1,3 +1,9 @@
+2002-04-10  Herbert Voss  <voss@perce.de>
+
+       * GraphicsCache.[Ch]:
+       * GraphicsCacheItem.[Ch]: add width/height functions from Angus
+       to read the "Bounding Box" from non (e)ps files.
+
 2002-04-08  Angus Leeming  <a.leeming@ic.ac.uk>
 
        * GraphicsParams.C (c-tor): if clipping, then check the Bounding Box of
index 9e37111ec99d72084ceb80357c8c3985693dc8b7..562b4d214ba526374c98111d7f2538f5c8020a65 100644 (file)
@@ -165,4 +165,25 @@ GCache::find(InsetGraphics const & inset) const
        return cache->end();
 }
 
+
+unsigned int GCache::raw_width(string const & filename) const
+{
+       CacheType::const_iterator it = cache->find(filename);
+       if (it == cache->end())
+               return 0;
+
+       return it->second->raw_width();
+}
+
+
+unsigned int GCache::raw_height(string const & filename) const
+{
+       CacheType::const_iterator it = cache->find(filename);
+       if (it == cache->end())
+               return 0;
+
+       return it->second->raw_height();
+}
+
 } // namespace grfx
+
index dadec6c150d8ee54815dedf3ffab5d249e8e5a03..ed2d9bb20fc20ec6bf823e3b3fc9205783b5d045 100644 (file)
@@ -67,6 +67,11 @@ public:
        /// How far have we got in loading the image?
        ImageStatus status(InsetGraphics const &) const;
 
+       // Used to ascertain the Bounding Box of non (e)ps files.
+       unsigned int raw_width(string const & filename) const;
+       ///
+       unsigned int raw_height(string const & filename) const;
+       
 private:
        /** Make the c-tor private so we can control how many objects
         *  are instantiated.
index baa5485ce2db12cc4ccd674fa5730432ba2c9bc1..54fbfdf4a3ce26239f70eb5ff3a2b5226b9bb0a7 100644 (file)
@@ -392,6 +392,24 @@ void GCacheItem::imageLoaded(bool success)
 }
 
 
+unsigned int GCacheItem::raw_width() const
+{
+       if (!image_.get())
+               return 0;
+
+       return image_->getWidth();
+}
+
+
+unsigned int GCacheItem::raw_height() const
+{
+       if (!image_.get())
+               return 0;
+
+       return image_->getHeight();
+}
+
+
 namespace {
 
 string const findTargetFormat(string const & from)
index 94e1e2808889183cf660f778f9ee5bd43b1ffbfd..70b326221812e72188ab0557cb9f085f031c5504 100644 (file)
@@ -89,6 +89,11 @@ public:
         */
        void changeDisplay(bool changed_background);
 
+       /// Used to ascertain the Bounding Box of non (e)ps files.
+       unsigned int raw_width() const;
+       ///
+       unsigned int raw_height() const;
+       
 private:
        /** Start the image conversion process, checking first that it is
         *  necessary. If it is necessary, then a conversion task is started.