From ec722f3a48ee7f1c774ef504862dcea8276373df Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Fri, 31 Dec 2021 14:30:09 +0100 Subject: [PATCH] GuiGraphics: read the BB values also for new graphics that aren't in the cache yet. --- src/frontends/qt/GuiGraphics.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/frontends/qt/GuiGraphics.cpp b/src/frontends/qt/GuiGraphics.cpp index 6a651fd380..aefe3d057c 100644 --- a/src/frontends/qt/GuiGraphics.cpp +++ b/src/frontends/qt/GuiGraphics.cpp @@ -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(width) + ' ' + convert(height)); -- 2.39.2