]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/GraphicsParams.C
Fix crash but problem still remains.
[lyx.git] / src / graphics / GraphicsParams.C
index b130623134be184e9627d0372f50fde920f5b03b..7a5a06c4e16dc24af59f2bdf5d21656d72fc2361 100644 (file)
@@ -36,20 +36,22 @@ GParams::GParams(InsetGraphicsParams const & iparams, string const & filepath)
                bb = iparams.bb;
 
                // Get the original Bounding Box from the file
-               string const bb_orig_str = readBB_from_PSFile(filename);
-               if (!bb_orig_str.empty()) {
-                       BoundingBox bb_orig;
-                       bb_orig.xl = strToInt(token(bb_orig_str, ' ', 0));
-                       bb_orig.yb = strToInt(token(bb_orig_str, ' ', 1));
-                       bb_orig.xr = strToInt(token(bb_orig_str, ' ', 2));
-                       bb_orig.yt = strToInt(token(bb_orig_str, ' ', 3));
-
-                       bb.xl -= bb_orig.xl;
-                       bb.xr -= bb_orig.xl;
-                       bb.yb -= bb_orig.yb;
-                       bb.yt -= bb_orig.yb;
+               string const tmp = readBB_from_PSFile(filename);
+               if (!tmp.empty()) {
+                       int const bb_orig_xl = strToInt(token(tmp, ' ', 0));
+                       int const bb_orig_yb = strToInt(token(tmp, ' ', 1));
+
+                       bb.xl -= bb_orig_xl;
+                       bb.xr -= bb_orig_xl;
+                       bb.yb -= bb_orig_yb;
+                       bb.yt -= bb_orig_yb;
                }
 
+               bb.xl = std::max(0, bb.xl);
+               bb.xr = std::max(0, bb.xr);
+               bb.yb = std::max(0, bb.yb);
+               bb.yt = std::max(0, bb.yt);
+
                // Paranoia check.
                int const width  = bb.xr - bb.xl;
                int const height = bb.yt - bb.yb;