summaryrefslogtreecommitdiffstats
path: root/src/document.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/document.cpp')
-rw-r--r--src/document.cpp41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/document.cpp b/src/document.cpp
index ec831745c..967d049c2 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -548,16 +548,20 @@ SPDocument *SPDocument::doUnref()
return NULL;
}
-gdouble SPDocument::getWidth() const
+Inkscape::Util::Quantity SPDocument::getWidth() const
{
- g_return_val_if_fail(this->priv != NULL, 0.0);
- g_return_val_if_fail(this->root != NULL, 0.0);
+ g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit()));
+ g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit()));
- gdouble result = root->width.computed;
+ gdouble result = root->width.value;
+ SVGLength::Unit u = root->width.unit;
if (root->width.unit == SVGLength::PERCENT && root->viewBox_set) {
result = root->viewBox.width();
}
- return result;
+ if (u == SVGLength::NONE) {
+ u = SVGLength::PX;
+ }
+ return Inkscape::Util::Quantity(result, unit_table.getUnit(u));
}
void SPDocument::setWidth(const Inkscape::Util::Quantity &width)
@@ -584,16 +588,20 @@ void SPDocument::setWidth(const Inkscape::Util::Quantity &width)
root->updateRepr();
}
-gdouble SPDocument::getHeight() const
+Inkscape::Util::Quantity SPDocument::getHeight() const
{
- g_return_val_if_fail(this->priv != NULL, 0.0);
- g_return_val_if_fail(this->root != NULL, 0.0);
+ g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit()));
+ g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit()));
- gdouble result = root->height.computed;
+ gdouble result = root->height.value;
+ SVGLength::Unit u = root->height.unit;
if (root->height.unit == SVGLength::PERCENT && root->viewBox_set) {
result = root->viewBox.height();
}
- return result;
+ if (u == SVGLength::NONE) {
+ u = SVGLength::PX;
+ }
+ return Inkscape::Util::Quantity(result, unit_table.getUnit(u));
}
void SPDocument::setHeight(const Inkscape::Util::Quantity &height)
@@ -620,9 +628,16 @@ void SPDocument::setHeight(const Inkscape::Util::Quantity &height)
root->updateRepr();
}
+void SPDocument::setViewBox(const Geom::Rect &viewBox)
+{
+ root->viewBox_set = true;
+ root->viewBox = viewBox;
+ root->updateRepr();
+}
+
Geom::Point SPDocument::getDimensions() const
{
- return Geom::Point(getWidth(), getHeight());
+ return Geom::Point(getWidth().value("px"), getHeight().value("px"));
}
Geom::OptRect SPDocument::preferredBounds() const
@@ -644,7 +659,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins)
double const w = rect.width();
double const h = rect.height();
- double const old_height = getHeight();
+ double const old_height = getHeight().value("px");
Inkscape::Util::Unit const px = unit_table.getUnit("px");
/* in px */
@@ -979,7 +994,7 @@ void SPDocument::setupViewport(SPItemCtx *ctx)
if (root->viewBox_set) { // if set, take from viewBox
ctx->viewport = root->viewBox;
} else { // as a last resort, set size to A4
- ctx->viewport = Geom::Rect::from_xywh(0, 0, 210 * Inkscape::Util::Quantity::convert(1, "mm", "px"), 297 * Inkscape::Util::Quantity::convert(1, "mm", "px"));
+ ctx->viewport = Geom::Rect::from_xywh(0, 0, Inkscape::Util::Quantity::convert(210, "mm", "px"), Inkscape::Util::Quantity::convert(297, "mm", "px"));
}
ctx->i2vp = Geom::identity();
}