]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt/GuiGraphics.cpp
GuiGraphics: read the BB values also for new graphics
[features.git] / src / frontends / qt / GuiGraphics.cpp
index 6a651fd380ec86e9fdd5dfa07f94f25799fb6d46..aefe3d057ce120d226ef444328ad79b2569f2c3f 100644 (file)
@@ -794,16 +794,17 @@ string GuiGraphics::readBoundingBox(string const & file)
 {
        FileName const abs_file = support::makeAbsPath(file, fromqstr(bufferFilePath()));
 
-       // try to get it from the file, if possible. Zipped files are
-       // unzipped in the readBB_from_PSFile-Function
+       // With (E)PS files, try to get it from the file, if possible.
+       // Zipped files are unzipped in the readBB_from_PSFile-Function
        string const bb = graphics::readBB_from_PSFile(abs_file);
        if (!bb.empty())
                return bb;
 
-       // we don't, so ask the Graphics Cache if it has loaded the file
+       // With other formats, we try to read the file dimensions
        int width = 0;
        int height = 0;
 
+       // First ask the Graphics Cache if it has loaded the file
        graphics::Cache & gc = graphics::Cache::get();
        if (gc.inCache(abs_file)) {
                graphics::Image const * image = gc.item(abs_file)->image();
@@ -812,6 +813,13 @@ string GuiGraphics::readBoundingBox(string const & file)
                        width  = image->width();
                        height = image->height();
                }
+       } else {
+               // If not, construct a QImage and get the values from that
+               QImage image(toqstr(abs_file.absoluteFilePath()));
+               if (!image.isNull()) {
+                       width  = image.width();
+                       height = image.height();
+               }
        }
 
        return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));