Lars Gullik Bjønnes wrote:
> Do we have to use floats for this, or can we just use a string all the
> time?

I think it will be possible to switch to string in all these cases. However, 
I'd like to proceed in small steps. The attached patch uses strings instead 
of floats for graphics. We have to convert them back to double for some 
calculations, but at least the problem with the decimal values is gone.

If you think this is the way to go, I'll proceed with the other float 
occurrences.

BTW: John S., in the gtk graphics dialog, you cannot enter double values for 
rotation, width/height and scale. This is possible in the other frontends and 
might cause compatibility problems.

Regards,
Jürgen
Index: src/frontends/gtk/GGraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/gtk/GGraphics.C,v
retrieving revision 1.4
diff -u -r1.4 GGraphics.C
--- src/frontends/gtk/GGraphics.C	16 Nov 2004 23:18:45 -0000	1.4
+++ src/frontends/gtk/GGraphics.C	5 Dec 2004 18:06:07 -0000
@@ -28,6 +28,7 @@
 
 #include "support/lyxlib.h"  // for float_equal
 #include "support/lstrings.h"
+#include "support/tostr.h"
 
 #include "debug.h"
 
@@ -37,6 +38,7 @@
 namespace lyx {
 
 using support::float_equal;
+using support::strToDbl;
 using support::token;
 
 namespace frontend {
@@ -265,12 +267,13 @@
 	}
 
 	if (setscalingradio_->get_active()) {
-		igp.scale = outputscalespin_->get_adjustment()->get_value();
-		if (float_equal(igp.scale, 0.0, 0.05))
-			igp.scale = 100.0;
+		float scaleValue = outputscalespin_->get_adjustment()->get_value();
+		igp.scale = tostr(scaleValue);
+		if (float_equal(scaleValue, 0.0, 0.05))
+			igp.scale = string();
 		igp.width = LyXLength();
 	} else {
-		igp.scale = 0.0;
+		igp.scale = string();
 		Glib::ustring const widthunit =
 			(*widthunitscombo_->get_active())[stringcol_];
 		igp.width = LyXLength(widthspin_->get_text() + widthunit);
@@ -326,7 +329,7 @@
 	igp.clip = clipcheck_->get_active();
 
 	// the extra section
-	igp.rotateAngle = anglespin_->get_adjustment()->get_value();
+	igp.rotateAngle = tostr(anglespin_->get_adjustment()->get_value());
 
 	int const origin_pos = origincombo_->get_active_row_number();
 	igp.rotateOrigin = origins_[origin_pos];
@@ -369,7 +372,7 @@
 		displaycombo_->set_active(0);
 	}
 
-	outputscalespin_->get_adjustment()->set_value(igp.scale);
+	outputscalespin_->get_adjustment()->set_value(strToDbl(igp.scale));
 	widthspin_->get_adjustment()->set_value(igp.width.value());
 	unitsComboFromLength(widthunitscombo_, stringcol_,
 	                     igp.width, defaultUnit);
@@ -377,7 +380,7 @@
 	unitsComboFromLength(heightunitscombo_, stringcol_,
 	                     igp.height, defaultUnit);
 
-	if (!float_equal(igp.scale, 0.0, 0.05)) {
+	if (!igp.scale.empty() && igp.scale != "0") {
 		// scaling sizing mode
 		setscalingradio_->set_active(true);
 	} else {
@@ -396,7 +399,7 @@
 	clipcheck_->set_active(igp.clip);
 
 	// the extra section
-	anglespin_->get_adjustment()->set_value(igp.rotateAngle);
+	anglespin_->get_adjustment()->set_value(strToDbl(igp.rotateAngle));
 
 	int origin_pos;
 	if (igp.rotateOrigin.empty()) {
Index: src/frontends/qt2/QGraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/qt2/QGraphics.C,v
retrieving revision 1.50
diff -u -r1.50 QGraphics.C
--- src/frontends/qt2/QGraphics.C	27 Nov 2004 18:47:41 -0000	1.50
+++ src/frontends/qt2/QGraphics.C	5 Dec 2004 18:06:09 -0000
@@ -256,9 +256,8 @@
 	for (int i = 0; i < num_units; i++)
 		dialog_->widthUnit->insertItem(unit_name_gui[i], -1);
 
-	if (!float_equal(igp.scale, 0.0, 0.05)) {
-		// there is a scale value > 0.05
-		dialog_->width->setText(toqstr(tostr(igp.scale)));
+	if (!igp.scale.empty() && igp.scale != "0") {
+		dialog_->width->setText(toqstr(igp.scale));
 		dialog_->widthUnit->setCurrentItem(0);
 	} else {
 		// no scale means default width/height
@@ -280,7 +279,7 @@
 
 	dialog_->aspectratio->setChecked(igp.keepAspectRatio);
 
-	dialog_->angle->setText(toqstr(tostr(igp.rotateAngle)));
+	dialog_->angle->setText(toqstr(igp.rotateAngle));
 
 	dialog_->origin->clear();
 
@@ -364,10 +363,10 @@
 		// width/height combination
 		igp.width = 
 			widgetsToLength(dialog_->width, dialog_->widthUnit);
-		igp.scale = 0.0;
+		igp.scale = string();
 	} else {
 		// scaling instead of a width
-		igp.scale = strToDbl(value);
+		igp.scale = value;
 		igp.width = LyXLength();
 	}
 	value = fromqstr(dialog_->height->text());
@@ -380,10 +379,13 @@
 
 	igp.lyxscale = strToInt(fromqstr(dialog_->displayscale->text()));
 
-	igp.rotateAngle = strToDbl(fromqstr(dialog_->angle->text()));
+	igp.rotateAngle = fromqstr(dialog_->angle->text());
 
-	if (std::abs(igp.rotateAngle) > 360.0)
-		igp.rotateAngle -= 360.0 * floor(igp.rotateAngle / 360.0);
+	float rotAngle = strToDbl(igp.rotateAngle);
+	if (std::abs(rotAngle) > 360.0) {
+		rotAngle -= 360.0 * floor(rotAngle / 360.0);
+		igp.rotateAngle = tostr(rotAngle);
+	}
 
 	// save the latex name for the origin. If it is the default
 	// then origin_ltx returns ""
Index: src/frontends/xforms/FormGraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormGraphics.C,v
retrieving revision 1.126
diff -u -r1.126 FormGraphics.C
--- src/frontends/xforms/FormGraphics.C	19 May 2004 15:11:35 -0000	1.126
+++ src/frontends/xforms/FormGraphics.C	5 Dec 2004 18:06:11 -0000
@@ -330,13 +330,13 @@
 
 	// first item in choice_width means scaling
 	if (fl_get_choice(file_->choice_width) == 1) {
-		igp.scale = strToDbl(getString(file_->input_width));
-		if (float_equal(igp.scale, 0.0, 0.05)) {
-			igp.scale = 100.0;
+		igp.scale = getString(file_->input_width);
+		if (igp.scale.empty() || igp.scale == "0" || igp.scale == "100") {
+			igp.scale = string();
 		}
 		igp.width = LyXLength();
 	} else {
-		igp.scale = 0.0;
+		igp.scale = string();
 		igp.width = LyXLength(getLengthFromWidgets(file_->input_width,
 							   file_->choice_width));
 	}
@@ -406,13 +406,16 @@
 	igp.clip = fl_get_button(bbox_->check_clip);
 
 	// the extra section
-	igp.rotateAngle = strToDbl(getString(extra_->input_rotate_angle));
+	igp.rotateAngle = getString(extra_->input_rotate_angle);
 
 	// map angle into -360 (clock-wise) to +360 (counter clock-wise)
-	if (std::abs(igp.rotateAngle) > 360.0)
-		igp.rotateAngle -= 360.0 * floor(igp.rotateAngle / 360.0);
+	float rotAngle = strToDbl(igp.rotateAngle);
+	if (std::abs(rotAngle) > 360.0) {
+		 rotAngle -= 360.0 * floor(rotAngle / 360.0);
+		 igp.rotateAngle = tostr(rotAngle);
+	}
 
-	fl_set_input(extra_->input_rotate_angle, tostr(igp.rotateAngle).c_str());
+	fl_set_input(extra_->input_rotate_angle, igp.rotateAngle.c_str());
 
 	int const origin_pos = fl_get_choice(extra_->choice_origin);
 	if (origin_pos == 0) {
@@ -456,10 +459,10 @@
 	}
 
 	// set width input fields according to scaling or width/height input
-	if (!float_equal(igp.scale, 0.0, 0.05)) {
+	if (!igp.scale.empty() && igp.scale != "0") {
 		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, tostr(igp.scale).c_str());
+		fl_set_input(file_->input_width, igp.scale.c_str());
 		fl_set_choice(file_->choice_width, 1);
 	} else {
 		fl_set_input_filter(file_->input_width, NULL);
@@ -472,7 +475,7 @@
 				igp.height, defaultUnit);
 
 	// disable height input in case of scaling
-	bool const disable_height = !float_equal(igp.scale, 0.0, 0.05);
+	bool const disable_height = (!igp.scale.empty() && igp.scale != "0");
 	setEnabled(file_->input_height, !disable_height);
 	setEnabled(file_->choice_height, !disable_height);
 
@@ -494,8 +497,7 @@
 	fl_set_button(bbox_->check_clip, igp.clip);
 
 	// the extra section
-	fl_set_input(extra_->input_rotate_angle,
-		     tostr(igp.rotateAngle).c_str());
+	fl_set_input(extra_->input_rotate_angle, igp.rotateAngle.c_str());
 
 	int origin_pos;
 	if (igp.rotateOrigin.empty()) {
Index: src/insets/insetgraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v
retrieving revision 1.266
diff -u -r1.266 insetgraphics.C
--- src/insets/insetgraphics.C	25 Nov 2004 19:13:04 -0000	1.266
+++ src/insets/insetgraphics.C	5 Dec 2004 18:06:14 -0000
@@ -76,7 +76,8 @@
 
 #include "support/filetools.h"
 #include "support/lyxalgo.h" // lyx::count
-#include "support/lyxlib.h" // float_equal
+#include "support/lyxlib.h" // lyx::sum
+#include "support/lstrings.h"
 #include "support/os.h"
 #include "support/systemcall.h"
 
@@ -93,12 +94,12 @@
 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;
 using lyx::support::OnlyFilename;
 using lyx::support::rtrim;
+using lyx::support::strToDbl;
 using lyx::support::subst;
 using lyx::support::Systemcall;
 using lyx::support::unzipFile;
@@ -298,9 +299,9 @@
 	    options << " draft,\n";
 	if (params().clip)
 	    options << " clip,\n";
-	if (!float_equal(params().scale, 0.0, 0.05)) {
-		if (!float_equal(params().scale, 100.0, 0.05))
-			options << " scale=" << params().scale / 100.0
+	if (!params().scale.empty() && params().scale != "0") {
+		if (params().scale != "100")
+			options << " scale=" << strToDbl(params().scale) / 100.0
 				<< ",\n";
 	} else {
 		if (!params().width.zero())
@@ -313,7 +314,7 @@
 
 	// Make sure rotation angle is not very close to zero;
 	// a float can be effectively zero but not exactly zero.
-	if (!float_equal(params().rotateAngle, 0, 0.001)) {
+	if (!params().rotateAngle.empty() && params().rotateAngle != "0") {
 	    options << "  angle=" << params().rotateAngle << ",\n";
 	    if (!params().rotateOrigin.empty()) {
 		options << "  origin=" << params().rotateOrigin[0];
@@ -402,9 +403,10 @@
 	// Right now it only works with my version of db2latex :-)
 
 	ostringstream options;
-	if (!float_equal(params().scale, 0.0, 0.05)) {
-		if (!float_equal(params().scale, 100.0, 0.05))
-			options << " scale=\"" << static_cast<int>( (params().scale) + 0.5 )
+	if (!params().scale.empty() && params().scale != "0") {
+		if (params().scale != "100")
+			options << " scale=\"" 
+				<< static_cast<int>( (strToDbl(params().scale)) + 0.5 )
 				<< "\" ";
 	} else {
 		if (!params().width.zero()) {
Index: src/insets/insetgraphicsParams.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphicsParams.C,v
retrieving revision 1.69
diff -u -r1.69 insetgraphicsParams.C
--- src/insets/insetgraphicsParams.C	13 Oct 2003 21:50:33 -0000	1.69
+++ src/insets/insetgraphicsParams.C	5 Dec 2004 18:06:14 -0000
@@ -66,7 +66,7 @@
 	filename.erase();
 	lyxscale = 100;			// lyx scaling in percentage
 	display = lyx::graphics::DefaultDisplay; // display mode; see preferences
-	scale = 100.0;			// output scaling in percentage
+	scale = string();			// output scaling in percentage
 	width = LyXLength();
 	height = LyXLength();
 	keepAspectRatio = false;	// for LaTeX output
@@ -76,7 +76,7 @@
 	bb = string();			// bounding box
 	clip = false;			// clip image
 
-	rotateAngle = 0.0;		// angle of rotation in degrees
+	rotateAngle = "0";		// angle of rotation in degrees
 	rotateOrigin.erase();		// Origin of rotation
 	subcaption = false;		// subfigure
 	subcaptionText.erase();		// subfigure caption
@@ -124,7 +124,7 @@
 	    left.bb == right.bb &&
 	    left.clip == right.clip &&
 
-	    float_equal(left.rotateAngle, right.rotateAngle, 0.001) &&
+	    left.rotateAngle == right.rotateAngle &&
 	    left.rotateOrigin == right.rotateOrigin &&
 	    left.subcaption == right.subcaption &&
 	    left.subcaptionText == right.subcaptionText &&
@@ -154,8 +154,8 @@
 		os << "\tlyxscale " << lyxscale << '\n';
 	if (display != lyx::graphics::DefaultDisplay)
 		os << "\tdisplay " << lyx::graphics::displayTranslator().find(display) << '\n';
-	if (!float_equal(scale, 0.0, 0.05)) {
-		if (!float_equal(scale, 100.0, 0.05))
+	if (!scale.empty() && scale != "0") {
+		if (scale != "100")
 			os << "\tscale " << scale << '\n';
 	} else {
 		if (!width.zero())
@@ -176,7 +176,7 @@
 	if (clip)			// clip image
 		os << "\tclip\n";
 
-	if (rotateAngle != 0.0)
+	if (!rotateAngle.empty() && rotateAngle != "0")
 		os << "\trotateAngle " << rotateAngle << '\n';
 	if (!rotateOrigin.empty())
 		os << "\trotateOrigin " << rotateOrigin << '\n';
@@ -203,15 +203,15 @@
 		display = lyx::graphics::displayTranslator().find(type);
 	} else if (token == "scale") {
 		lex.next();
-		scale = lex.getFloat();
+		scale = lex.getString();
 	} else if (token == "width") {
 		lex.next();
 		width = LyXLength(lex.getString());
-		scale = 0.0;
+		scale = string();
 	} else if (token == "height") {
 		lex.next();
 		height = LyXLength(lex.getString());
-		scale = 0.0;
+		scale = string();
 	} else if (token == "keepAspectRatio") {
 		keepAspectRatio = true;
 	} else if (token == "draft") {
@@ -230,7 +230,7 @@
 		clip = true;
 	} else if (token == "rotateAngle") {
 		lex.next();
-		rotateAngle = lex.getFloat();
+		rotateAngle = lex.getString();
 	} else if (token == "rotateOrigin") {
 		lex.next();
 		rotateOrigin=lex.getString();
@@ -265,7 +265,7 @@
 	lyx::graphics::Params pars;
 	pars.filename = filename.absFilename();
 	pars.scale = lyxscale;
-	pars.angle = rotateAngle;
+	pars.angle = lyx::support::strToDbl(rotateAngle);
 
 	if (clip) {
 		pars.bb = bb;
Index: src/insets/insetgraphicsParams.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphicsParams.h,v
retrieving revision 1.39
diff -u -r1.39 insetgraphicsParams.h
--- src/insets/insetgraphicsParams.h	6 Oct 2003 15:43:04 -0000	1.39
+++ src/insets/insetgraphicsParams.h	5 Dec 2004 18:06:15 -0000
@@ -37,7 +37,7 @@
 	/// How to display the image inside LyX
 	lyx::graphics::DisplayType display;
 	/// Scaling for output (LaTeX)
-	float scale;
+	std::string scale;
 	/// sizes for output (LaTeX)
 	LyXLength width;
 	///
@@ -55,7 +55,7 @@
 	bool clip;
 
 	/// Rotation angle.
-	float rotateAngle;
+	std::string rotateAngle;
 	/// Origin point of rotation
 	std::string rotateOrigin;
 	/// Do we have a subcaption?

Reply via email to