GuiGraphics: read the BB values also for new graphics

that aren't in the cache yet.
This commit is contained in:
Juergen Spitzmueller 2021-12-31 14:30:09 +01:00
parent 0789f2f2ae
commit ec722f3a48

View 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));