]> git.lyx.org Git - features.git/commitdiff
float2string #2 and insetexternal \sclaebox fix
authorJürgen Spitzmüller <spitz@lyx.org>
Tue, 4 Jan 2005 10:59:49 +0000 (10:59 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Tue, 4 Jan 2005 10:59:49 +0000 (10:59 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9419 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/frontends/gtk/ChangeLog
src/frontends/gtk/GGraphics.C
src/frontends/qt2/ChangeLog
src/frontends/qt2/QExternal.C
src/frontends/qt2/QGraphics.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormExternal.C
src/frontends/xforms/FormGraphics.C
src/insets/ChangeLog
src/insets/ExternalTransforms.C
src/insets/ExternalTransforms.h
src/insets/insetexternal.C
src/insets/insetgraphics.C
src/insets/insetgraphicsParams.C

index 328392af8fb3a2afc904f3d3d17687cb77065141..a7484eb3afda39ffef61a918346d4bda26104c89 100644 (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>
 
index e62422fd10b0c1dd8c1eb839aa464ca970fdef4f..54bb6f8fe44f438a94f89cb25cd4bc0be3e88e19 100644 (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 {
index 1065949fd82cd309c07fb498e5e052edd8a16c89..4bcc46e19dffe034601959582381fc760add91b2 100644 (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>
 
index 992f6933a57247c45e098e3ab6cd043a3941f05b..2aff4929c80ed8b8e76337abfa7a4d501ca9eb3d 100644 (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();
        }
 
index 836bdf203b5ab85c7ccb75ac627af9f67bcb8234..63aed8835cd8196138a3923721c67bf0e133d370 100644 (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 {
index a8e28ea0cc070edc77fe675ee289eca7a11ae346..feff0f1b1d5b84560d16bf2b03157b251156fbb2 100644 (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): 
index b78462e51adcec49e76f17051e576d1b0e94f6d7..fb1de73f1164eff96cfd313f6f2cc6c1e8c1912b 100644 (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();
        }
 
index 3ce01d793f4b881028e1d3556a08100cc89e9d2c..1b6430a7c760138f35a6993324b9549bec008c1d 100644 (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);
 
index 51ae27b11d02cc261b486f2dc617464ff42c0555..60524abc596f548634bce18c3b909a588cc3ebbe 100644 (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>
 
index 3a6059a288c6f4b43327b217cabff08e4df83db7..7d645df7a3946770a0deca37209a19e601d86c69 100644 (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() << ',';
index 5f9a85294bb00d053f6dd7ba96d36d210a599ced..c3ab382a670ae076824136c1ff6d10c19aafbd59 100644 (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_;
 };
 
index 2fb4e943e77dea61bdc760e172279fa0a24f10fd..9c14a299848375695e4dff87a77e369afce4bc70 100644 (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:
index 3ec93e551c99c80eeb2dca07806fd0a705f84dcc..d393a8f4a7152d00adb6f15935287c80e6e4c490 100644 (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()) {
index 8b7981fce0d2305b47ea9d9883514e8fa34d16fa..22ef15bf388110928b327bf3f459d7602035eed7 100644 (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';