summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Petroff <matthew@mpetroff.net>2013-07-06 15:01:59 +0000
committerMatthew Petroff <matthew@mpetroff.net>2013-07-06 15:01:59 +0000
commitd04405f745da587b2a3ccca8d2ca7bf49edf2d4d (patch)
tree6ff9bee696703f2de19e81a1a4727e4dbbae8e46
parentPorted measure-context.cpp (to do: port widgets/measure-toolbar.cpp so unit s... (diff)
downloadinkscape-d04405f745da587b2a3ccca8d2ca7bf49edf2d4d.tar.gz
inkscape-d04405f745da587b2a3ccca8d2ca7bf49edf2d4d.zip
Switch setWidth and setHeight to use Quantity and switch to forward declaration of Inkscape::Util::Quantity in document.h.
(bzr r12380.1.7)
-rw-r--r--src/document.cpp34
-rw-r--r--src/document.h8
-rw-r--r--src/ui/widget/page-sizer.cpp4
-rw-r--r--src/util/units.cpp2
-rw-r--r--src/util/units.h4
5 files changed, 28 insertions, 24 deletions
diff --git a/src/document.cpp b/src/document.cpp
index cc1c519fc..ed3d8e21b 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -547,22 +547,23 @@ gdouble SPDocument::getWidth() const
return result;
}
-void SPDocument::setWidth(gdouble width, const Inkscape::Util::Unit *unit)
+void SPDocument::setWidth(const Inkscape::Util::Quantity &width)
{
Inkscape::Util::Unit px = unit_table.getUnit("px");
if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox=
- root->viewBox.setMax(Geom::Point(root->viewBox.left() + Inkscape::Util::Quantity::convert(width, unit, &px), root->viewBox.bottom()));
+ root->viewBox.setMax(Geom::Point(root->viewBox.left() + width.value(&px), root->viewBox.bottom()));
} else { // set to width=
gdouble old_computed = root->width.computed;
- root->width.computed = Inkscape::Util::Quantity::convert(width, unit, &px);
+ root->width.computed = width.value(&px);
/* SVG does not support meters as a unit, so we must translate meters to
* cm when writing */
- if (*unit == unit_table.getUnit("m")) {
- root->width.value = 100*width;
+ if (*width.unit == unit_table.getUnit("m")) {
+ Inkscape::Util::Unit cm = unit_table.getUnit("cm");
+ root->width.value = width.value(&cm);
root->width.unit = SVGLength::CM;
} else {
- root->width.value = width;
- root->width.unit = (SVGLength::Unit) unit->svgUnit();
+ root->width.value = width.quantity;
+ root->width.unit = (SVGLength::Unit) width.unit->svgUnit();
}
if (root->viewBox_set)
@@ -584,22 +585,23 @@ gdouble SPDocument::getHeight() const
return result;
}
-void SPDocument::setHeight(gdouble height, const Inkscape::Util::Unit *unit)
+void SPDocument::setHeight(const Inkscape::Util::Quantity &height)
{
Inkscape::Util::Unit px = unit_table.getUnit("px");
if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) { // set to viewBox=
- root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + Inkscape::Util::Quantity::convert(height, unit, &px)));
+ root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + height.value(&px)));
} else { // set to height=
gdouble old_computed = root->height.computed;
- root->height.computed = Inkscape::Util::Quantity::convert(height, unit, &px);
+ root->height.computed = height.value(&px);
/* SVG does not support meters as a unit, so we must translate meters to
* cm when writing */
- if (*unit == unit_table.getUnit("m")) {
- root->height.value = 100*height;
+ if (*height.unit == unit_table.getUnit("m")) {
+ Inkscape::Util::Unit cm = unit_table.getUnit("cm");
+ root->height.value = height.value(&cm);
root->height.unit = SVGLength::CM;
} else {
- root->height.value = height;
- root->height.unit = (SVGLength::Unit) unit->svgUnit();
+ root->height.value = height.quantity;
+ root->height.unit = (SVGLength::Unit) height.unit->svgUnit();
}
if (root->viewBox_set)
@@ -662,8 +664,8 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
rect.max() + Geom::Point(margin_right, margin_top));
- setWidth(rect_with_margins.width(), &px);
- setHeight(rect_with_margins.height(), &px);
+ setWidth(Inkscape::Util::Quantity(rect_with_margins.width(), &px));
+ setHeight(Inkscape::Util::Quantity(rect_with_margins.height(), &px));
Geom::Translate const tr(
Geom::Point(0, old_height - rect_with_margins.height())
diff --git a/src/document.h b/src/document.h
index c2334bbc3..c584c3beb 100644
--- a/src/document.h
+++ b/src/document.h
@@ -26,7 +26,6 @@
#include "gc-anchored.h"
#include <glibmm/ustring.h>
#include <vector>
-#include "util/units.h"
namespace Avoid {
class Router;
@@ -47,6 +46,9 @@ namespace Inkscape {
struct Document;
class Node;
}
+ namespace Util {
+ class Quantity;
+ }
}
class SPDefs;
@@ -228,8 +230,8 @@ public:
gdouble getWidth() const;
gdouble getHeight() const;
Geom::Point getDimensions() const;
- void setWidth(gdouble width, const Inkscape::Util::Unit *unit);
- void setHeight(gdouble height, const Inkscape::Util::Unit *unit);
+ void setWidth(const Inkscape::Util::Quantity &width);
+ void setHeight(const Inkscape::Util::Quantity &height);
void requestModified();
gint ensureUpToDate();
bool addResource(const gchar *key, SPObject *object);
diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp
index cceb3f600..884f9ea0a 100644
--- a/src/ui/widget/page-sizer.cpp
+++ b/src/ui/widget/page-sizer.cpp
@@ -480,8 +480,8 @@ PageSizer::setDim (double w, double h, bool changeList)
if (SP_ACTIVE_DESKTOP && !_widgetRegistry->isUpdating()) {
SPDocument *doc = sp_desktop_document(SP_ACTIVE_DESKTOP);
double const old_height = doc->getHeight();
- doc->setWidth (w, &_px_unit);
- doc->setHeight (h, &_px_unit);
+ doc->setWidth (Inkscape::Util::Quantity(w, &_px_unit));
+ doc->setHeight (Inkscape::Util::Quantity(h, &_px_unit));
// The origin for the user is in the lower left corner; this point should remain stationary when
// changing the page size. The SVG's origin however is in the upper left corner, so we must compensate for this
Geom::Translate const vert_offset(Geom::Point(0, (old_height - h)));
diff --git a/src/util/units.cpp b/src/util/units.cpp
index d0e4e7941..a51eb2570 100644
--- a/src/util/units.cpp
+++ b/src/util/units.cpp
@@ -386,7 +386,7 @@ void UnitsSAXHandler::_endElement(xmlChar const *xname)
}
/** Initialize a quantity. */
-Quantity::Quantity(Unit *u, double q) {
+Quantity::Quantity(double q, const Unit *u) {
unit = u;
quantity = q;
}
diff --git a/src/util/units.h b/src/util/units.h
index 7ef7001bb..0ea84bfbb 100644
--- a/src/util/units.h
+++ b/src/util/units.h
@@ -93,10 +93,10 @@ class UnitTable {
class Quantity {
public:
- Unit *unit;
+ const Unit *unit;
double quantity;
- Quantity(Unit *u, double q); // constructor
+ Quantity(double q, const Unit *u); // constructor
bool compatibleWith(const Unit *u) const;
double value(Unit *u) const;