Store BoundingBox relative to original.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3948 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2002-04-08 16:51:46 +00:00
parent 3e39bef2c1
commit 727b3cab86
5 changed files with 54 additions and 15 deletions

View File

@ -1,3 +1,8 @@
2002-04-08 Angus Leeming <a.leeming@ic.ac.uk>
* xformsGImage.C (clip): no need to check if the width, height are > 0
because the BoundingBox would be empty() in this case.
2002-04-08 Lars Gullik Bjønnes <larsbj@birdstep.com>
* forms/Makefile.am (SUFFIXES): instead of .SUFFIXES

View File

@ -251,8 +251,9 @@ void xformsGImage::clip(GParams const & params)
int const new_width = params.bb.xr - params.bb.xl;
int const new_height = params.bb.yt - params.bb.yb;
if (new_width <= 0 || new_width > image_->w ||
new_height <= 0 || new_height > image_->h)
// No need to check if the width, height are > 0 because the
// Bounding Box would be empty() in this case.
if (new_width > image_->w || new_height > image_->h)
// Bounds are invalid.
return;

View File

@ -1,3 +1,9 @@
2002-04-08 Angus Leeming <a.leeming@ic.ac.uk>
* GraphicsParams.C (c-tor): if clipping, then check the Bounding Box of
the EPS file too, to ensure that the clipped Bounding Box is relative
to the original. (From Herbert.)
2002-04-04 Angus Leeming <a.leeming@ic.ac.uk>
* GraphicsParams.C (BoundingBox c-tor): ensure that the member

View File

@ -32,9 +32,36 @@ GParams::GParams(InsetGraphicsParams const & iparams, string const & filepath)
filename = MakeAbsPath(filename, filepath);
}
if (iparams.clip)
if (iparams.clip) {
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;
}
// Paranoia check.
int const width = bb.xr - bb.xl;
int const height = bb.yt - bb.yb;
if (width < 0 || height < 0) {
bb.xl = 0;
bb.xr = 0;
bb.yb = 0;
bb.yt = 0;
}
}
if (iparams.rotate)
angle = int(iparams.rotateAngle);
@ -131,14 +158,10 @@ BoundingBox::BoundingBox(string const & bb)
// want the bounding box in Postscript pixels.
// 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));
int const xl_tmp = int(scaling_factor * length_xl.inPixels(1, 1));
int const yb_tmp = int(scaling_factor * length_yb.inPixels(1, 1));
int const xr_tmp = int(scaling_factor * length_xr.inPixels(1, 1));
int const yt_tmp = int(scaling_factor * length_yt.inPixels(1, 1));
if (xr_tmp <= xl_tmp || yt_tmp <= yb_tmp)
return;

View File

@ -38,10 +38,10 @@ struct BoundingBox {
/// 0 0 0 0 is empty!
bool empty() const;
unsigned int xl;
unsigned int yb;
unsigned int xr;
unsigned int yt;
int xl;
int yb;
int xr;
int yt;
};
bool operator==(BoundingBox const &, BoundingBox const &);
@ -65,6 +65,10 @@ struct GParams
/// The image filename.
string filename;
/** Note that the BoundingBox is always relative to the BoundingBox
* as stored in the EPS file.
* Ie, bb.xl and bb.yb == 0 if that corner is not moved.
*/
BoundingBox bb;
/** The size of the view inside lyx in pixels or the scaling of the