float2string #2 and insetexternal \sclaebox fix

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9419 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2005-01-04 10:59:49 +00:00
parent 2102d461fa
commit b029c3bf80
14 changed files with 98 additions and 57 deletions

View File

@ -1,6 +1,10 @@
2005-04-01 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* GGraphics.C: more precise checks for the value strings.
2004-12-28 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* GGraphics.C: store all values as strings.
* GGraphics.C: store all float/double values as strings.
2004-12-19 Angus Leeming <leeming@lyx.org>

View File

@ -380,7 +380,8 @@ void GGraphics::update() {
unitsComboFromLength(heightunitscombo_, stringcol_,
igp.height, defaultUnit);
if (!igp.scale.empty() && igp.scale != "0") {
if (!igp.scale.empty()
&& !float_equal(strToDbl(igp.scale), 0.0, 0.05)) {
// scaling sizing mode
setscalingradio_->set_active(true);
} else {

View File

@ -1,6 +1,11 @@
2005-01-04 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* QExternal.C: store all float/double values as strings.
* GGraphics.C: more precise checks for the value strings.
2004-12-28 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* QGraphics.C: store all values as strings.
* QGraphics.C: store all float/double values as strings.
2004-12-19 Angus Leeming <leeming@lyx.org>

View File

@ -142,7 +142,7 @@ void setRotation(QLineEdit & angleED, QComboBox & originCO,
external::RotationData const & data)
{
originCO.setCurrentItem(int(data.origin()));
angleED.setText(toqstr(tostr(data.angle())));
angleED.setText(toqstr(data.angle));
}
@ -152,7 +152,7 @@ void getRotation(external::RotationData & data,
typedef external::RotationData::OriginType OriginType;
data.origin(static_cast<OriginType>(originCO.currentItem()));
data.angle(strToDbl(fromqstr(angleED.text())));
data.angle = fromqstr(angleED.text());
}
@ -162,15 +162,15 @@ void setSize(QLineEdit & widthED, QComboBox & widthUnitCO,
external::ResizeData const & data)
{
bool using_scale = data.usingScale();
double scale = data.scale;
std::string scale = data.scale;
if (data.no_resize()) {
// Everything is zero, so default to this!
using_scale = true;
scale = 100;
scale = "100";
}
if (using_scale) {
widthED.setText(toqstr(tostr(scale)));
widthED.setText(toqstr(scale));
widthUnitCO.setCurrentItem(0);
} else {
widthED.setText(toqstr(tostr(data.width.value())));
@ -216,11 +216,11 @@ void getSize(external::ResizeData & data,
else
data.width = LyXLength();
data.scale = 0.0;
data.scale = string();
} else {
// scaling instead of a width
data.scale = strToDbl(width);
data.scale = width;
data.width = LyXLength();
}

View File

@ -256,7 +256,8 @@ void QGraphics::update_contents()
for (int i = 0; i < num_units; i++)
dialog_->widthUnit->insertItem(unit_name_gui[i], -1);
if (!igp.scale.empty() && igp.scale != "0") {
if (!igp.scale.empty()
&& !float_equal(strToDbl(igp.scale), 0.0, 0.05)) {
dialog_->width->setText(toqstr(igp.scale));
dialog_->widthUnit->setCurrentItem(0);
} else {

View File

@ -1,3 +1,8 @@
2005-01-04 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* FormExternal.C: store all float/double values as strings.
* FormGraphics.C: more precise checks for the value strings.
2005-01-03 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* freebrowser.c (browser_cb):

View File

@ -156,7 +156,7 @@ void setRotation(FL_OBJECT * angleED, FL_OBJECT * originCO,
BOOST_ASSERT(originCO && originCO->objclass == FL_CHOICE);
fl_set_choice(originCO, 1 + int(data.origin()));
fl_set_input(angleED, tostr(data.angle()).c_str());
fl_set_input(angleED, data.angle.c_str());
}
@ -169,7 +169,7 @@ void getRotation(external::RotationData & data,
typedef external::RotationData::OriginType OriginType;
data.origin(static_cast<OriginType>(fl_get_choice(originCO) - 1));
data.angle(strToDbl(getString(angleED)));
data.angle = getString(angleED);
}
@ -186,15 +186,15 @@ void setSize(FL_OBJECT * widthED, FL_OBJECT * widthUnitCO,
aspectratioCB->objclass == FL_CHECKBUTTON);
bool using_scale = data.usingScale();
double scale = data.scale;
std::string scale = data.scale;
if (data.no_resize()) {
// Everything is zero, so default to this!
using_scale = true;
scale = 100;
scale = "100";
}
if (using_scale) {
fl_set_input(widthED, tostr(scale).c_str());
fl_set_input(widthED, scale.c_str());
fl_set_choice(widthUnitCO, 1);
} else {
fl_set_input(widthED, tostr(data.width.value()).c_str());
@ -248,11 +248,11 @@ void getSize(external::ResizeData & data,
else
data.width = LyXLength();
data.scale = 0.0;
data.scale = string();
} else {
// scaling instead of a width
data.scale = strToDbl(width);
data.scale = width;
data.width = LyXLength();
}

View File

@ -331,7 +331,9 @@ void FormGraphics::apply()
// first item in choice_width means scaling
if (fl_get_choice(file_->choice_width) == 1) {
igp.scale = getString(file_->input_width);
if (igp.scale.empty() || igp.scale == "0" || igp.scale == "100") {
if (igp.scale.empty()
|| float_equal(strToDbl(igp.scale), 0.0, 0.05)
|| float_equal(strToDbl(igp.scale), 100.0, 0.05)) {
igp.scale = string();
}
igp.width = LyXLength();
@ -459,7 +461,7 @@ void FormGraphics::update() {
}
// set width input fields according to scaling or width/height input
if (!igp.scale.empty() && igp.scale != "0") {
if (!igp.scale.empty() && !float_equal(strToDbl(igp.scale), 0.0, 0.05)) {
fl_set_input_filter(file_->input_width, fl_unsigned_float_filter);
fl_set_input_maxchars(file_->input_width, 0);
fl_set_input(file_->input_width, igp.scale.c_str());
@ -475,7 +477,8 @@ void FormGraphics::update() {
igp.height, defaultUnit);
// disable height input in case of scaling
bool const disable_height = (!igp.scale.empty() && igp.scale != "0");
bool const disable_height = (!igp.scale.empty()
&& !float_equal(strToDbl(igp.scale), 0.0, 0.05));
setEnabled(file_->input_height, !disable_height);
setEnabled(file_->choice_height, !disable_height);

View File

@ -1,3 +1,13 @@
2005-01-04 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* ExternalTransforms.C: fix LaTeX output of \scalebox.
* ExternalTransforms.[Ch]:
* insetexternal.C: store all float/double values as strings.
* insetgraphics.C:
* insetgraphicsParams.C: more precise checks for the value strings.
2004-12-28 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* insettext.C (doDispatch): remove unused variable was_empty
@ -5,7 +15,7 @@
2004-12-28 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* insetgraphics.C:
* insetgraphicsParams.[Ch]: store all values as strings.
* insetgraphicsParams.[Ch]: store all float/double values as strings.
2004-12-17 Alfredo Braunstein <abraunst@lyx.org>

View File

@ -16,6 +16,7 @@
#include "support/lstrings.h"
#include "support/lyxlib.h" // float_equal
#include "support/tostr.h"
#include "support/translator.h"
#include <boost/regex.hpp>
@ -24,6 +25,7 @@
#include <sstream>
using lyx::support::float_equal;
using lyx::support::strToDbl;
using std::string;
@ -52,21 +54,25 @@ bool ResizeData::no_resize() const
bool ResizeData::usingScale() const
{
return !float_equal(scale, 0.0, 0.05);
return (!scale.empty() && !float_equal(strToDbl(scale), 0.0, 0.05));
}
bool RotationData::no_rotation() const
{
return (std::abs(angle()) < 0.1);
return (angle.empty() || std::abs(strToDbl(angle)) < 0.1);
}
void RotationData::angle(double a)
string const RotationData::adjAngle() const
{
// Ensure that angle_ lies in the range -360 < angle_ < 360.
int const multiples = int(a) / 360;
angle_ = a - (multiples * 360);
// Ensure that angle lies in the range -360 < angle < 360
double rotAngle = strToDbl(angle);
if (std::abs(rotAngle) > 360.0) {
rotAngle -= 360.0 * floor(rotAngle / 360.0);
return tostr(rotAngle);
}
return angle;
}
@ -97,8 +103,8 @@ string const ResizeLatexCommand::front_impl() const
std::ostringstream os;
if (data.usingScale()) {
double const scl = data.scale / 100.0;
os << "\\scalebox{" << scl << "}{" << scl << "}{";
double const scl = strToDbl(data.scale) / 100.0;
os << "\\scalebox{" << scl << "}[" << scl << "]{";
} else {
string width = "!";
string height = "!";
@ -194,7 +200,7 @@ string const RotationLatexCommand::front_impl() const
if (data.origin() != RotationData::DEFAULT)
os << "[origin=" << data.origin() << ']';
os << '{' << data.angle() << "}{";
os << '{' << data.angle << "}{";
return os.str();
}
@ -229,8 +235,9 @@ string const ResizeLatexOption::option_impl() const
std::ostringstream os;
if (data.usingScale()) {
if (!float_equal(data.scale, 100.0, 0.05))
os << "scale=" << data.scale / 100.0 << ',';
double scl = strToDbl(data.scale);
if (!float_equal(scl, 100.0, 0.05))
os << "scale=" << scl / 100.0 << ',';
return os.str();
}
@ -251,7 +258,7 @@ string const RotationLatexOption ::option_impl() const
return string();
std::ostringstream os;
os << "angle=" << data.angle() << ',';
os << "angle=" << data.angle << ',';
if (data.origin() != RotationData::DEFAULT)
os << "origin=" << data.origin() << ',';

View File

@ -56,12 +56,12 @@ private:
class ResizeData {
public:
ResizeData() : scale(0), keepAspectRatio(false) {}
ResizeData() : scale(), keepAspectRatio(false) {}
bool no_resize() const;
bool usingScale() const;
float scale;
std::string scale;
LyXLength width;
LyXLength height;
bool keepAspectRatio;
@ -84,11 +84,11 @@ public:
BASELINERIGHT
};
RotationData() : angle_(0), origin_(DEFAULT) {}
RotationData() : angle("0"), origin_(DEFAULT) {}
bool no_rotation() const;
void angle(double a);
double angle() const { return angle_; }
std::string const adjAngle() const;
std::string angle;
void origin(OriginType o) { origin_ = o; }
OriginType origin() const { return origin_; }
@ -97,7 +97,6 @@ public:
std::string const originString() const;
private:
double angle_;
OriginType origin_;
};

View File

@ -220,7 +220,7 @@ void InsetExternalParams::write(Buffer const & buffer, ostream & os) const
}
if (!rotationdata.no_rotation()) {
os << "\trotateAngle " << rotationdata.angle() << '\n';
os << "\trotateAngle " << rotationdata.adjAngle() << '\n';
if (rotationdata.origin() != external::RotationData::DEFAULT)
os << "\trotateOrigin "
<< rotationdata.originString() << '\n';
@ -228,9 +228,9 @@ void InsetExternalParams::write(Buffer const & buffer, ostream & os) const
if (!resizedata.no_resize()) {
using support::float_equal;
if (!float_equal(resizedata.scale, 0.0, 0.05)) {
if (!float_equal(resizedata.scale, 100.0, 0.05))
double scl = support::strToDbl(resizedata.scale);
if (!float_equal(scl, 0.0, 0.05)) {
if (!float_equal(scl, 100.0, 0.05))
os << "\tscale "
<< resizedata.scale << '\n';
} else {
@ -354,7 +354,7 @@ bool InsetExternalParams::read(Buffer const & buffer, LyXLex & lex)
case EX_ROTATEANGLE:
lex.next();
rotationdata.angle(lex.getFloat());
rotationdata.angle = lex.getString();
break;
case EX_ROTATEORIGIN:
@ -364,7 +364,7 @@ bool InsetExternalParams::read(Buffer const & buffer, LyXLex & lex)
case EX_SCALE:
lex.next();
resizedata.scale = lex.getFloat();
resizedata.scale = lex.getString();
break;
case EX_WIDTH:
@ -524,7 +524,7 @@ graphics::Params get_grfx_params(InsetExternalParams const & eparams)
gparams.scale = eparams.lyxscale;
if (eparams.clipdata.clip)
gparams.bb = eparams.clipdata.bbox;
gparams.angle = eparams.rotationdata.angle();
gparams.angle = lyx::support::strToDbl(eparams.rotationdata.adjAngle());
switch (eparams.display) {
case external::DefaultDisplay:

View File

@ -94,6 +94,7 @@ using lyx::support::ChangeExtension;
using lyx::support::compare_timestamps;
using lyx::support::contains;
using lyx::support::FileName;
using lyx::support::float_equal;
using lyx::support::GetExtension;
using lyx::support::IsFileReadable;
using lyx::support::LibFileSearch;
@ -299,9 +300,10 @@ string const InsetGraphics::createLatexOptions() const
options << " draft,\n";
if (params().clip)
options << " clip,\n";
if (!params().scale.empty() && params().scale != "0") {
if (params().scale != "100")
options << " scale=" << strToDbl(params().scale) / 100.0
double const scl = strToDbl(params().scale);
if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
if (!float_equal(scl, 100.0, 0.05))
options << " scale=" << scl / 100.0
<< ",\n";
} else {
if (!params().width.zero())
@ -314,7 +316,8 @@ string const InsetGraphics::createLatexOptions() const
// Make sure rotation angle is not very close to zero;
// a float can be effectively zero but not exactly zero.
if (!params().rotateAngle.empty() && params().rotateAngle != "0") {
if (!params().rotateAngle.empty()
&& !float_equal(strToDbl(params().rotateAngle), 0.0, 0.001)) {
options << " angle=" << params().rotateAngle << ",\n";
if (!params().rotateOrigin.empty()) {
options << " origin=" << params().rotateOrigin[0];
@ -403,10 +406,11 @@ string const InsetGraphics::createDocBookAttributes() const
// Right now it only works with my version of db2latex :-)
ostringstream options;
if (!params().scale.empty() && params().scale != "0") {
if (params().scale != "100")
double const scl = strToDbl(params().scale);
if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
if (!float_equal(scl, 100.0, 0.05))
options << " scale=\""
<< static_cast<int>( (strToDbl(params().scale)) + 0.5 )
<< static_cast<int>( (scl) + 0.5 )
<< "\" ";
} else {
if (!params().width.zero()) {

View File

@ -28,6 +28,7 @@
using lyx::support::float_equal;
using lyx::support::readBB_from_PSFile;
using lyx::support::strToDbl;
using lyx::support::strToInt;
using lyx::support::token;
@ -154,8 +155,8 @@ void InsetGraphicsParams::Write(ostream & os, string const & bufpath) const
os << "\tlyxscale " << lyxscale << '\n';
if (display != lyx::graphics::DefaultDisplay)
os << "\tdisplay " << lyx::graphics::displayTranslator().find(display) << '\n';
if (!scale.empty() && scale != "0") {
if (scale != "100")
if (!scale.empty() && !float_equal(strToDbl(scale), 0.0, 0.05)) {
if (!float_equal(strToDbl(scale), 100.0, 0.05))
os << "\tscale " << scale << '\n';
} else {
if (!width.zero())
@ -176,7 +177,8 @@ void InsetGraphicsParams::Write(ostream & os, string const & bufpath) const
if (clip) // clip image
os << "\tclip\n";
if (!rotateAngle.empty() && rotateAngle != "0")
if (!rotateAngle.empty()
&& !float_equal(strToDbl(rotateAngle), 0.0, 0.001))
os << "\trotateAngle " << rotateAngle << '\n';
if (!rotateOrigin.empty())
os << "\trotateOrigin " << rotateOrigin << '\n';