From bd77ef25e9161acb007323f851ba77e106036939 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Mon, 1 Jul 2013 23:40:52 -0400 Subject: Ported "ui/widget/page-sizer.cpp" and "document.cpp" to "Util::Unit" class. (bzr r12380.1.4) --- src/document.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 706710cfc..cc1c519fc 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -49,7 +49,6 @@ #include "display/drawing-item.h" #include "document-private.h" #include "document-undo.h" -#include "helper/units.h" #include "id-clash.h" #include "inkscape-private.h" #include "inkscape-version.h" @@ -87,6 +86,8 @@ static gint doc_count = 0; static unsigned long next_serial = 0; +static Inkscape::Util::UnitTable unit_table; + SPDocument::SPDocument() : keepalive(FALSE), virgin(TRUE), @@ -546,21 +547,22 @@ gdouble SPDocument::getWidth() const return result; } -void SPDocument::setWidth(gdouble width, const SPUnit *unit) +void SPDocument::setWidth(gdouble width, const Inkscape::Util::Unit *unit) { + 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() + sp_units_get_pixels (width, *unit), root->viewBox.bottom())); + root->viewBox.setMax(Geom::Point(root->viewBox.left() + Inkscape::Util::Quantity::convert(width, unit, &px), root->viewBox.bottom())); } else { // set to width= gdouble old_computed = root->width.computed; - root->width.computed = sp_units_get_pixels (width, *unit); + root->width.computed = Inkscape::Util::Quantity::convert(width, unit, &px); /* SVG does not support meters as a unit, so we must translate meters to * cm when writing */ - if (!strcmp(unit->abbr, "m")) { + if (*unit == unit_table.getUnit("m")) { root->width.value = 100*width; root->width.unit = SVGLength::CM; } else { root->width.value = width; - root->width.unit = (SVGLength::Unit) sp_unit_get_svg_unit(unit); + root->width.unit = (SVGLength::Unit) unit->svgUnit(); } if (root->viewBox_set) @@ -582,21 +584,22 @@ gdouble SPDocument::getHeight() const return result; } -void SPDocument::setHeight(gdouble height, const SPUnit *unit) +void SPDocument::setHeight(gdouble height, const Inkscape::Util::Unit *unit) { + 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() + sp_units_get_pixels (height, *unit))); + root->viewBox.setMax(Geom::Point(root->viewBox.right(), root->viewBox.top() + Inkscape::Util::Quantity::convert(height, unit, &px))); } else { // set to height= gdouble old_computed = root->height.computed; - root->height.computed = sp_units_get_pixels (height, *unit); + root->height.computed = Inkscape::Util::Quantity::convert(height, unit, &px); /* SVG does not support meters as a unit, so we must translate meters to * cm when writing */ - if (!strcmp(unit->abbr, "m")) { + if (*unit == unit_table.getUnit("m")) { root->height.value = 100*height; root->height.unit = SVGLength::CM; } else { root->height.value = height; - root->height.unit = (SVGLength::Unit) sp_unit_get_svg_unit(unit); + root->height.unit = (SVGLength::Unit) unit->svgUnit(); } if (root->viewBox_set) @@ -626,7 +629,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) double const h = rect.height(); double const old_height = getHeight(); - SPUnit const &px(sp_unit_get_by_id(SP_UNIT_PX)); + Inkscape::Util::Unit const px = unit_table.getUnit("px"); /* in px */ double margin_top = 0.0; @@ -639,9 +642,10 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) if (with_margins && nv) { if (nv != NULL) { gchar const * const units_abbr = nv->getAttribute("units"); - SPUnit const *margin_units = NULL; + Inkscape::Util::Unit const *margin_units = NULL; if (units_abbr != NULL) { - margin_units = sp_unit_get_by_abbreviation(units_abbr); + Inkscape::Util::Unit mu = unit_table.getUnit(units_abbr); + margin_units = μ } if (margin_units == NULL) { margin_units = &px; -- cgit v1.2.3 From d04405f745da587b2a3ccca8d2ca7bf49edf2d4d Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sat, 6 Jul 2013 11:01:59 -0400 Subject: Switch setWidth and setHeight to use Quantity and switch to forward declaration of Inkscape::Util::Quantity in document.h. (bzr r12380.1.7) --- src/document.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src/document.cpp') 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()) -- cgit v1.2.3 From 4d232a223d1dcb7b2381615de1a64b20b2fb6165 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Tue, 9 Jul 2013 20:46:51 -0400 Subject: Small refactor of align and distribute to reduce complexity. (bzr r12411) --- src/document.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 706710cfc..0e9c43fe4 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -611,6 +611,11 @@ Geom::Point SPDocument::getDimensions() const return Geom::Point(getWidth(), getHeight()); } +Geom::OptRect SPDocument::preferredBounds() const +{ + return Geom::OptRect( Geom::Point(0, 0), getDimensions() ); +} + /** * Given a Geom::Rect that may, for example, correspond to the bbox of an object, * this function fits the canvas to that rect by resizing the canvas -- cgit v1.2.3 From 3772fc428950b2b946a1bd7c7c97e06219c3165f Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 18 Jul 2013 17:21:24 -0400 Subject: Switch unit functions from using pointer arguements to reference arguements. (bzr r12380.1.28) --- src/document.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index 78d7018bb..a024cc790 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -549,17 +549,15 @@ gdouble SPDocument::getWidth() const 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() + width.value(&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 = width.value(&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 (*width.unit == unit_table.getUnit("m")) { - Inkscape::Util::Unit cm = unit_table.getUnit("cm"); - root->width.value = width.value(&cm); + root->width.value = width.value("cm"); root->width.unit = SVGLength::CM; } else { root->width.value = width.quantity; @@ -587,17 +585,15 @@ gdouble SPDocument::getHeight() const 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() + height.value(&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 = height.value(&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 (*height.unit == unit_table.getUnit("m")) { - Inkscape::Util::Unit cm = unit_table.getUnit("cm"); - root->height.value = height.value(&cm); + root->height.value = height.value("cm"); root->height.unit = SVGLength::CM; } else { root->height.value = height.quantity; @@ -669,8 +665,8 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) rect.max() + Geom::Point(margin_right, margin_top)); - setWidth(Inkscape::Util::Quantity(rect_with_margins.width(), &px)); - setHeight(Inkscape::Util::Quantity(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()) -- cgit v1.2.3 From f1cdb3b3f47c7187d9325e8ddd8e630268dc8e8b Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 31 Jul 2013 18:33:03 -0400 Subject: Eliminate "unit-constants.h". (bzr r12380.1.54) --- src/document.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index a024cc790..afd0a6ddc 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -62,7 +62,7 @@ #include "sp-object-repr.h" #include "sp-symbol.h" #include "transf_mat_3x4.h" -#include "unit-constants.h" +#include "util/units.h" #include "xml/repr.h" #include "xml/rebase-hrefs.h" #include "libcroco/cr-cascade.h" @@ -966,7 +966,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 * PX_PER_MM, 297 * PX_PER_MM); + 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->i2vp = Geom::identity(); } -- cgit v1.2.3 From 6ae6c0bea96eef09907091279e0678aa5f83102d Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sun, 4 Aug 2013 18:01:18 -0400 Subject: Switched to global UnitTable. (bzr r12380.1.62) --- src/document.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/document.cpp') diff --git a/src/document.cpp b/src/document.cpp index afd0a6ddc..0b742e491 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -68,6 +68,7 @@ #include "libcroco/cr-cascade.h" using Inkscape::DocumentUndo; +using Inkscape::Util::unit_table; // Higher number means lower priority. #define SP_DOCUMENT_UPDATE_PRIORITY (G_PRIORITY_HIGH_IDLE - 2) @@ -86,8 +87,6 @@ static gint doc_count = 0; static unsigned long next_serial = 0; -static Inkscape::Util::UnitTable unit_table; - SPDocument::SPDocument() : keepalive(FALSE), virgin(TRUE), -- cgit v1.2.3