mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-26 06:15:16 +00:00
Herbert's and my fixes to the graphics inset.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3906 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c3c133bd2e
commit
b9a7e87405
@ -1,3 +1,9 @@
|
||||
2002-04-04 Angus Leeming <a.leeming@ic.ac.uk>
|
||||
|
||||
* ControlGraphics.C (readBB): Don't open the ifstrem and then
|
||||
check the format from the contents (and open a second ifstream in the
|
||||
process. One at a time please.
|
||||
|
||||
2002-03-26 Angus Leeming <a.leeming@ic.ac.uk>
|
||||
|
||||
* ControlRef.C (getBufferNum): squash warning message.
|
||||
|
@ -104,19 +104,22 @@ string const ControlGraphics::Browse(string const & in_name)
|
||||
|
||||
string const ControlGraphics::readBB(string const & file)
|
||||
{
|
||||
// in a file it's an entry like %%BoundingBox:23 45 321 345
|
||||
// the first number can following without a space, so we have
|
||||
// to check a bit more.
|
||||
// on the other hand some plot programs write the bb at the
|
||||
// end of the file. Than we have in the header a
|
||||
// %%BoundingBox: (atend)
|
||||
// In this case we must check until the end.
|
||||
// in a file it's an entry like %%BoundingBox:23 45 321 345
|
||||
// The first number can following without a space, so we have
|
||||
// to be a little careful.
|
||||
// On the other hand some plot programs write the bb at the
|
||||
// end of the file. Than we have in the header:
|
||||
// %%BoundingBox: (atend)
|
||||
// In this case we must check the end.
|
||||
string file_ = file;
|
||||
if (zippedFile(file_))
|
||||
file_ = unzipFile(file_);
|
||||
|
||||
string const format = getExtFromContents(file_);
|
||||
if (format != "eps" && format != "ps")
|
||||
return string();
|
||||
|
||||
std::ifstream is(file_.c_str());
|
||||
if (!contains(getExtFromContents(file_),"ps")) // bb exists?
|
||||
return string();
|
||||
while (is) {
|
||||
string s;
|
||||
is >> s;
|
||||
|
@ -1,3 +1,13 @@
|
||||
2002-04-04 Angus Leeming <a.leeming@ic.ac.uk>
|
||||
|
||||
* xformsGImage.C (clip): ensure that the clipped image has sensible
|
||||
dimensions.
|
||||
|
||||
2002-04-04 Herbert Voss <voss@lyx.org>
|
||||
|
||||
* FormGraphics.C (updateBB): new method to read the BBox when reading
|
||||
a new file or changing an existing one.
|
||||
|
||||
2002-04-03 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||
|
||||
* FormCharacter.C (findPos): add a missing typename
|
||||
|
@ -417,43 +417,7 @@ void FormGraphics::update() {
|
||||
// the bb section
|
||||
// set the bounding box values, if exists. First we need the whole
|
||||
// path, because the controller knows nothing about the doc-dir
|
||||
controller().bbChanged = false;
|
||||
if (igp.bb.empty()) {
|
||||
lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
|
||||
string const fileWithAbsPath =
|
||||
MakeAbsPath(igp.filename, OnlyPath(igp.filename));
|
||||
string const bb = controller().readBB(fileWithAbsPath);
|
||||
if (!bb.empty()) {
|
||||
// get the values from the file
|
||||
// in this case we always have the point-unit
|
||||
fl_set_input(bbox_->input_bb_x0, token(bb,' ',0).c_str());
|
||||
fl_set_input(bbox_->input_bb_y0, token(bb,' ',1).c_str());
|
||||
fl_set_input(bbox_->input_bb_x1, token(bb,' ',2).c_str());
|
||||
fl_set_input(bbox_->input_bb_y1, token(bb,' ',3).c_str());
|
||||
} else { // no bb from file
|
||||
fl_set_input(bbox_->input_bb_x0, bb.c_str());
|
||||
fl_set_input(bbox_->input_bb_y0, bb.c_str());
|
||||
fl_set_input(bbox_->input_bb_x1, bb.c_str());
|
||||
fl_set_input(bbox_->input_bb_y1, bb.c_str());
|
||||
}
|
||||
fl_set_choice(bbox_->choice_bb_units, 1); // "pt"
|
||||
} else { // get the values from the inset
|
||||
lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox" << endl;
|
||||
controller().bbChanged = true;
|
||||
LyXLength anyLength;
|
||||
anyLength = LyXLength(token(igp.bb,' ',0));
|
||||
updateWidgetsFromLength(bbox_->input_bb_x0,
|
||||
bbox_->choice_bb_units,anyLength,"pt");
|
||||
anyLength = LyXLength(token(igp.bb,' ',1));
|
||||
updateWidgetsFromLength(bbox_->input_bb_y0,
|
||||
bbox_->choice_bb_units,anyLength,"pt");
|
||||
anyLength = LyXLength(token(igp.bb,' ',2));
|
||||
updateWidgetsFromLength(bbox_->input_bb_x1,
|
||||
bbox_->choice_bb_units,anyLength,"pt");
|
||||
anyLength = LyXLength(token(igp.bb,' ',3));
|
||||
updateWidgetsFromLength(bbox_->input_bb_y1,
|
||||
bbox_->choice_bb_units,anyLength,"pt");
|
||||
}
|
||||
updateBB(igp.filename, igp.bb);
|
||||
fl_set_button(bbox_->check_clip, igp.clip);
|
||||
|
||||
// the special section
|
||||
@ -461,6 +425,60 @@ void FormGraphics::update() {
|
||||
}
|
||||
|
||||
|
||||
void FormGraphics::updateBB(string const & filename, string const & bb_inset)
|
||||
{
|
||||
// Update dialog with details from inset
|
||||
// set the bounding box values, if exists. First we need the whole
|
||||
// path, because the controller knows nothing about the doc-dir
|
||||
controller().bbChanged = false;
|
||||
if (bb_inset.empty()) {
|
||||
lyxerr[Debug::GRAPHICS] << "update:: no BoundingBox" << endl;
|
||||
string const fileWithAbsPath =
|
||||
MakeAbsPath(filename, OnlyPath(filename));
|
||||
string const bb = controller().readBB(fileWithAbsPath);
|
||||
if (!bb.empty()) {
|
||||
// get the values from the file
|
||||
// in this case we always have the point-unit
|
||||
fl_set_input(bbox_->input_bb_x0,
|
||||
token(bb,' ',0).c_str());
|
||||
fl_set_input(bbox_->input_bb_y0,
|
||||
token(bb,' ',1).c_str());
|
||||
fl_set_input(bbox_->input_bb_x1,
|
||||
token(bb,' ',2).c_str());
|
||||
fl_set_input(bbox_->input_bb_y1,
|
||||
token(bb,' ',3).c_str());
|
||||
|
||||
} else {
|
||||
// no bb from file
|
||||
fl_set_input(bbox_->input_bb_x0, bb.c_str());
|
||||
fl_set_input(bbox_->input_bb_y0, bb.c_str());
|
||||
fl_set_input(bbox_->input_bb_x1, bb.c_str());
|
||||
fl_set_input(bbox_->input_bb_y1, bb.c_str());
|
||||
}
|
||||
// "pt"
|
||||
fl_set_choice(bbox_->choice_bb_units, 1);
|
||||
|
||||
} else {
|
||||
// get the values from the inset
|
||||
lyxerr[Debug::GRAPHICS] << "update:: igp has BoundingBox"
|
||||
<< endl;
|
||||
controller().bbChanged = true;
|
||||
LyXLength anyLength;
|
||||
anyLength = LyXLength(token(bb_inset,' ',0));
|
||||
updateWidgetsFromLength(bbox_->input_bb_x0,
|
||||
bbox_->choice_bb_units,anyLength,"pt");
|
||||
anyLength = LyXLength(token(bb_inset,' ',1));
|
||||
updateWidgetsFromLength(bbox_->input_bb_y0,
|
||||
bbox_->choice_bb_units,anyLength,"pt");
|
||||
anyLength = LyXLength(token(bb_inset,' ',2));
|
||||
updateWidgetsFromLength(bbox_->input_bb_x1,
|
||||
bbox_->choice_bb_units,anyLength,"pt");
|
||||
anyLength = LyXLength(token(bb_inset,' ',3));
|
||||
updateWidgetsFromLength(bbox_->input_bb_y1,
|
||||
bbox_->choice_bb_units,anyLength,"pt");
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool isValid(FL_OBJECT * ob)
|
||||
@ -480,16 +498,12 @@ ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
|
||||
// Get the filename from the dialog
|
||||
string const in_name = getStringFromInput(file_->input_filename);
|
||||
string const out_name = controller().Browse(in_name);
|
||||
lyxerr[Debug::GRAPHICS] << "[FormGraphics]out_name: " << out_name << endl;
|
||||
if (out_name != in_name && !out_name.empty()) {
|
||||
fl_set_input(file_->input_filename, out_name.c_str());
|
||||
}
|
||||
// if (!controller().isFilenameValid(out_name))
|
||||
// return ButtonPolicy::SMI_INVALID;
|
||||
|
||||
// } else if (ob == file_->input_filename) {
|
||||
// string name = getStringFromInput(file_->input_filename);
|
||||
// if (!controller().isFilenameValid(name))
|
||||
// return ButtonPolicy::SMI_INVALID;
|
||||
if (controller().isFilenameValid(out_name))
|
||||
updateBB(out_name, string());
|
||||
|
||||
} else if (ob == file_->check_subcaption) {
|
||||
setEnabled(file_->input_subcaption,
|
||||
|
@ -46,6 +46,8 @@ private:
|
||||
virtual void build();
|
||||
/// Update dialog before/whilst showing it.
|
||||
virtual void update();
|
||||
/// Update the BoundingBox info.
|
||||
void updateBB(string const & filename, string const & bb_inset);
|
||||
/// Filter the inputs on callback from xforms
|
||||
virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
|
||||
|
||||
|
@ -251,7 +251,8 @@ 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 > image_->w || new_height > image_->h)
|
||||
if (new_width <= 0 || new_width > image_->w ||
|
||||
new_height <= 0 || new_height > image_->h)
|
||||
// Bounds are invalid.
|
||||
return;
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
2002-04-04 Angus Leeming <a.leeming@ic.ac.uk>
|
||||
|
||||
* GraphicsParams.C (c-tor): ensure that the member variables are
|
||||
initialised.
|
||||
* GraphicsParams.C (BoundingBox c-tor): ensure that the member
|
||||
variables are initialised. Clean-up parsing of the string (with thanks
|
||||
to Herbert.)
|
||||
|
||||
2002-03-26 Angus Leeming <a.leeming@ic.ac.uk>
|
||||
|
||||
|
@ -114,25 +114,16 @@ BoundingBox::BoundingBox(string const & bb)
|
||||
if (bb.empty())
|
||||
return;
|
||||
|
||||
string tmp1;
|
||||
string tmp2 = split(bb, tmp1, ' ');
|
||||
if (!isValidLength(tmp1))
|
||||
return;
|
||||
std::istringstream is(bb.c_str());
|
||||
string a, b, c, d;
|
||||
is >> a >> b >> c >> d;
|
||||
|
||||
LyXLength const length_xl(tmp1);
|
||||
|
||||
tmp2 = split(tmp2, tmp1, ' ');
|
||||
if (!isValidLength(tmp1))
|
||||
return;
|
||||
|
||||
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);
|
||||
// Don't need to check that the strings are valid LyXLength's
|
||||
// because this is done in the LyXLength c-tor.
|
||||
LyXLength const length_xl(a);
|
||||
LyXLength const length_yb(b);
|
||||
LyXLength const length_xr(c);
|
||||
LyXLength const length_yt(d);
|
||||
|
||||
// inPixels returns the length in inches, scaled by
|
||||
// lyxrc.dpi and lyxrc.zoom.
|
||||
@ -149,7 +140,7 @@ BoundingBox::BoundingBox(string const & bb)
|
||||
unsigned int const yt_tmp =
|
||||
uint(scaling_factor * length_yt.inPixels(1, 1));
|
||||
|
||||
if (xr <= xl || yt <= yb)
|
||||
if (xr_tmp <= xl_tmp || yt_tmp <= yb_tmp)
|
||||
return;
|
||||
|
||||
xl = xl_tmp;
|
||||
|
Loading…
Reference in New Issue
Block a user