From b029c3bf800a63786ce017b4d12bde5f8abb37de Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Tue, 4 Jan 2005 10:59:49 +0000 Subject: [PATCH] float2string #2 and insetexternal \sclaebox fix git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9419 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/gtk/ChangeLog | 6 +++++- src/frontends/gtk/GGraphics.C | 3 ++- src/frontends/qt2/ChangeLog | 7 ++++++- src/frontends/qt2/QExternal.C | 14 ++++++------- src/frontends/qt2/QGraphics.C | 3 ++- src/frontends/xforms/ChangeLog | 5 +++++ src/frontends/xforms/FormExternal.C | 14 ++++++------- src/frontends/xforms/FormGraphics.C | 9 ++++++--- src/insets/ChangeLog | 12 ++++++++++- src/insets/ExternalTransforms.C | 31 ++++++++++++++++++----------- src/insets/ExternalTransforms.h | 11 +++++----- src/insets/insetexternal.C | 14 ++++++------- src/insets/insetgraphics.C | 18 ++++++++++------- src/insets/insetgraphicsParams.C | 8 +++++--- 14 files changed, 98 insertions(+), 57 deletions(-) diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index 328392af8f..a7484eb3af 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,6 +1,10 @@ +2005-04-01 Jürgen Spitzmüller + + * GGraphics.C: more precise checks for the value strings. + 2004-12-28 Jürgen Spitzmüller - * GGraphics.C: store all values as strings. + * GGraphics.C: store all float/double values as strings. 2004-12-19 Angus Leeming diff --git a/src/frontends/gtk/GGraphics.C b/src/frontends/gtk/GGraphics.C index e62422fd10..54bb6f8fe4 100644 --- a/src/frontends/gtk/GGraphics.C +++ b/src/frontends/gtk/GGraphics.C @@ -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 { diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 1065949fd8..4bcc46e19d 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,6 +1,11 @@ +2005-01-04 Jürgen Spitzmüller + + * 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 - * QGraphics.C: store all values as strings. + * QGraphics.C: store all float/double values as strings. 2004-12-19 Angus Leeming diff --git a/src/frontends/qt2/QExternal.C b/src/frontends/qt2/QExternal.C index 992f6933a5..2aff4929c8 100644 --- a/src/frontends/qt2/QExternal.C +++ b/src/frontends/qt2/QExternal.C @@ -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(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(); } diff --git a/src/frontends/qt2/QGraphics.C b/src/frontends/qt2/QGraphics.C index 836bdf203b..63aed8835c 100644 --- a/src/frontends/qt2/QGraphics.C +++ b/src/frontends/qt2/QGraphics.C @@ -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 { diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index a8e28ea0cc..feff0f1b1d 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2005-01-04 Jürgen Spitzmüller + + * FormExternal.C: store all float/double values as strings. + * FormGraphics.C: more precise checks for the value strings. + 2005-01-03 Jean-Marc Lasgouttes * freebrowser.c (browser_cb): diff --git a/src/frontends/xforms/FormExternal.C b/src/frontends/xforms/FormExternal.C index b78462e51a..fb1de73f11 100644 --- a/src/frontends/xforms/FormExternal.C +++ b/src/frontends/xforms/FormExternal.C @@ -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(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(); } diff --git a/src/frontends/xforms/FormGraphics.C b/src/frontends/xforms/FormGraphics.C index 3ce01d793f..1b6430a7c7 100644 --- a/src/frontends/xforms/FormGraphics.C +++ b/src/frontends/xforms/FormGraphics.C @@ -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); diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 51ae27b11d..60524abc59 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,13 @@ +2005-01-04 Jürgen Spitzmüller + + * 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 * insettext.C (doDispatch): remove unused variable was_empty @@ -5,7 +15,7 @@ 2004-12-28 Jürgen Spitzmüller * insetgraphics.C: - * insetgraphicsParams.[Ch]: store all values as strings. + * insetgraphicsParams.[Ch]: store all float/double values as strings. 2004-12-17 Alfredo Braunstein diff --git a/src/insets/ExternalTransforms.C b/src/insets/ExternalTransforms.C index 3a6059a288..7d645df7a3 100644 --- a/src/insets/ExternalTransforms.C +++ b/src/insets/ExternalTransforms.C @@ -16,6 +16,7 @@ #include "support/lstrings.h" #include "support/lyxlib.h" // float_equal +#include "support/tostr.h" #include "support/translator.h" #include @@ -24,6 +25,7 @@ #include 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() << ','; diff --git a/src/insets/ExternalTransforms.h b/src/insets/ExternalTransforms.h index 5f9a85294b..c3ab382a67 100644 --- a/src/insets/ExternalTransforms.h +++ b/src/insets/ExternalTransforms.h @@ -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_; }; diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index 2fb4e943e7..9c14a29984 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -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: diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 3ec93e551c..d393a8f4a7 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -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( (strToDbl(params().scale)) + 0.5 ) + << static_cast( (scl) + 0.5 ) << "\" "; } else { if (!params().width.zero()) { diff --git a/src/insets/insetgraphicsParams.C b/src/insets/insetgraphicsParams.C index 8b7981fce0..22ef15bf38 100644 --- a/src/insets/insetgraphicsParams.C +++ b/src/insets/insetgraphicsParams.C @@ -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'; -- 2.39.2