]> git.lyx.org Git - lyx.git/blobdiff - src/graphics/GraphicsParams.C
Trivial fixes to some warnings thrown up by MSVS.Net 2003.
[lyx.git] / src / graphics / GraphicsParams.C
index f63b28b0b05c1c1398fe51a20ba5ee5874828146..6274ea1d6ba77814ef26152691ef95a333f952ae 100644 (file)
-/*
+/**
  * \file GraphicsParams.C
- * Copyright 2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author Angus Leeming <a.leeming@ic.ac.uk>
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "GraphicsParams.h"
-#include "insets/insetgraphicsParams.h"
-#include "lyxrc.h"
-#include "support/filetools.h"
-#include "support/lstrings.h"
-#include "support/LAssert.h"
-
-namespace grfx {
-
-GParams::GParams(InsetGraphicsParams const & iparams, string const & filepath)
-       : width(0),
-         height(0),
-         scale(0),
+
+#include "lyxlength.h"
+
+#include <sstream>
+
+
+using std::string;
+using std::abs;
+
+
+namespace lyx {
+namespace graphics {
+
+Params::Params()
+       : display(ColorDisplay),
+         scale(100),
          angle(0)
+{}
+
+
+bool operator==(Params const & a, Params const & b)
 {
-       filename = iparams.filename;
-       if (!filepath.empty()) {
-               filename = MakeAbsPath(filename, filepath);
-       }
-
-       if (iparams.clip)
-               bb = iparams.bb;
-
-       if (iparams.rotate)
-               angle = int(iparams.rotateAngle);
-
-       if (iparams.display == InsetGraphicsParams::DEFAULT) {
-
-               if (lyxrc.display_graphics == "mono")
-                       display = MONOCHROME;
-               else if (lyxrc.display_graphics == "gray")
-                       display = GRAYSCALE;
-               else if (lyxrc.display_graphics == "color")
-                       display = COLOR;
-               else
-                       display = NONE;
-
-       } else if (iparams.display == InsetGraphicsParams::NONE) {
-               display = NONE;
-
-       } else if (iparams.display == InsetGraphicsParams::MONOCHROME) {
-               display = MONOCHROME;
-
-       } else if (iparams.display == InsetGraphicsParams::GRAYSCALE) {
-               display = GRAYSCALE;
-
-       } else if (iparams.display == InsetGraphicsParams::COLOR) {
-               display = COLOR;
-       }
-
-       // Override the above if we're not using a gui
-       if (!lyxrc.use_gui) {
-               display = NONE;
-       }
-
-       if (iparams.lyxsize_type == InsetGraphicsParams::SCALE) {
-               scale = iparams.lyxscale;
-
-       } else if (iparams.lyxsize_type == InsetGraphicsParams::WH) {
-               if (!iparams.lyxwidth.zero())
-                       width  = iparams.lyxwidth.inPixels(1, 1);
-               if (!iparams.lyxheight.zero())
-                       height = iparams.lyxheight.inPixels(1, 1);
-
-               // inPixels returns a value scaled by lyxrc.zoom.
-               // We want, therefore, to undo this.
-               double const scaling_factor = 100.0 / double(lyxrc.zoom);
-               width  = uint(scaling_factor * width);
-               height = uint(scaling_factor * height);
-       }
+       return (a.filename == b.filename &&
+               a.display == b.display &&
+               a.bb == b.bb &&
+               a.scale == b.scale &&
+               a.angle == b.angle);
 }
 
 
-bool operator==(GParams const & a, GParams const & b)
+bool operator!=(Params const & a, Params const & b)
 {
-       return (a.filename        == b.filename &&
-               a.display         == b.display &&
-               a.bb              == b.bb &&
-               a.width           == b.width &&
-               a.height          == b.height &&
-               a.scale           == b.scale &&
-               a.angle           == b.angle);
+       return !(a == b);
 }
 
 
-bool operator!=(GParams const & a, GParams const & b)
+std::ostream & operator<<(std::ostream & os, BoundingBox const & bb)
 {
-       return !(a == b);
+       os << bb.xl << ' ' << bb.yb << ' ' << bb.xr << ' ' << bb.yt;
+       return os;
 }
 
 
@@ -114,42 +65,18 @@ BoundingBox::BoundingBox(string const & bb)
        if (bb.empty())
                return;
 
-       string tmp1;
-       string tmp2 = split(bb, tmp1, ' ');
-       if (!isValidLength(tmp1))
-               return;
-
-       LyXLength const length_xl(tmp1);
-
-       tmp2 = split(tmp2, tmp1, ' ');
-       if (!isValidLength(tmp1))
-               return;
+       std::istringstream is(bb.c_str());
+       string a, b, c, d;
+       is >> a >> b >> c >> d;
 
-       LyXLength const length_yb(tmp1);
-
-       tmp2 = split(tmp2, tmp1, ' ');
-       if (!isValidLength(tmp1) || !isValidLength(tmp2))
-               return;
-
-       LyXLength const length_xr(tmp1);
-       LyXLength const length_yt(tmp2);
-
-       // inPixels returns the length in inches, scaled by
-       // lyxrc.dpi and lyxrc.zoom.
-       // We want, therefore, to undo all this lyxrc nonsense because we
-       // want the bounding box in Postscript pixels.
+       // inBP returns the length in Postscript points.
        // Note further that there are 72 Postscript pixels per inch.
-       double const scaling_factor = 7200.0 / (lyxrc.dpi * lyxrc.zoom);
-       unsigned int const xl_tmp =
-               uint(scaling_factor * length_xl.inPixels(1, 1));
-       unsigned int const yb_tmp =
-               uint(scaling_factor * length_yb.inPixels(1, 1));
-       unsigned int const xr_tmp =
-               uint(scaling_factor * length_xr.inPixels(1, 1));
-       unsigned int const yt_tmp =
-               uint(scaling_factor * length_yt.inPixels(1, 1));
-
-       if (xr <= xl || yt <= yb)
+       unsigned int const xl_tmp = abs(LyXLength(a).inBP());
+       unsigned int const yb_tmp = abs(LyXLength(b).inBP());
+       unsigned int const xr_tmp = abs(LyXLength(c).inBP());
+       unsigned int const yt_tmp = abs(LyXLength(d).inBP());
+
+       if (xr_tmp <= xl_tmp || yt_tmp <= yb_tmp)
                return;
 
        xl = xl_tmp;
@@ -179,4 +106,5 @@ bool operator!=(BoundingBox const & a, BoundingBox const & b)
        return !(a == b);
 }
 
-} // namespace grfx
+} // namespace graphics
+} // namespace lyx