summaryrefslogtreecommitdiffstats
path: root/src/svg
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2015-03-14 12:02:49 +0000
committertavmjong-free <tavmjong@free.fr>2015-03-14 12:02:49 +0000
commit772eb991389fc1b8bdbf7cabb4ecde1be3243e3c (patch)
tree172ded6d8b7ccabdc4bebaa8c348cfa87bd268f4 /src/svg
parentRemove 'Active Desktop' calls from Perspective/Envelope and Lattice2 LPE, add... (diff)
downloadinkscape-772eb991389fc1b8bdbf7cabb4ecde1be3243e3c.tar.gz
inkscape-772eb991389fc1b8bdbf7cabb4ecde1be3243e3c.zip
Partial fix for bug 1430873. Rectangles should behave properly with % values.
(bzr r14004)
Diffstat (limited to 'src/svg')
-rw-r--r--src/svg/svg-length.cpp52
-rw-r--r--src/svg/svg-length.h8
2 files changed, 58 insertions, 2 deletions
diff --git a/src/svg/svg-length.cpp b/src/svg/svg-length.cpp
index ea235b2e4..edbc59c36 100644
--- a/src/svg/svg-length.cpp
+++ b/src/svg/svg-length.cpp
@@ -14,6 +14,7 @@
#include <cstring>
#include <string>
#include <glib.h>
+#include <iostream>
#include "svg.h"
#include "stringstream.h"
@@ -462,6 +463,51 @@ unsigned int sp_svg_length_read_ldd(gchar const *str, SVGLength::Unit *unit, dou
return r;
}
+std::string const SVGLength::write()
+{
+ return sp_svg_length_write_with_units(*this);
+}
+
+void SVGLength::set(SVGLength::Unit u, float v)
+{
+ _set = true;
+ unit = u;
+ Glib::ustring hack("px");
+ switch( unit ) {
+ case NONE:
+ case PX:
+ case EM:
+ case EX:
+ case PERCENT:
+ break;
+ case PT:
+ hack = "pt";
+ break;
+ case PC:
+ hack = "pc";
+ break;
+ case MM:
+ hack = "pt";
+ break;
+ case CM:
+ hack = "pt";
+ break;
+ case INCH:
+ hack = "pt";
+ break;
+ case FOOT:
+ hack = "pt";
+ break;
+ case MITRE:
+ hack = "m";
+ break;
+ default:
+ break;
+ }
+ value = v;
+ computed = Inkscape::Util::Quantity::convert(v, hack, "px");
+}
+
void SVGLength::set(SVGLength::Unit u, float v, float c)
{
_set = true;
@@ -478,6 +524,12 @@ void SVGLength::unset(SVGLength::Unit u, float v, float c)
computed = c;
}
+void SVGLength::scale(double scale)
+{
+ value *= scale;
+ computed *= scale;
+}
+
void SVGLength::update(double em, double ex, double scale)
{
if (unit == EM) {
diff --git a/src/svg/svg-length.h b/src/svg/svg-length.h
index 1e6b4c96c..84056dd5f 100644
--- a/src/svg/svg-length.h
+++ b/src/svg/svg-length.h
@@ -57,9 +57,13 @@ public:
bool read(char const *str);
void readOrUnset(char const *str, Unit u = NONE, float v = 0, float c = 0);
bool readAbsolute(char const *str);
- void set(Unit u, float v, float c);
+ std::string const write();
+ // To set 'v' use '='
+ void set(Unit u, float v); // Sets computed value based on u and v.
+ void set(Unit u, float v, float c); // Sets all three values.
void unset(Unit u = NONE, float v = 0, float c = 0);
- void update(double em, double ex, double scale);
+ void scale(double scale); // Scales length (value, computed), leaving unit alone.
+ void update(double em, double ex, double scale); // Updates computed value
};
#endif // SEEN_SP_SVG_LENGTH_H