From 1c06fa5e2552b291534f0b96542070f00fd0778b Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Mon, 24 Jun 2013 20:47:57 -0400 Subject: Added length class. (bzr r12380.1.1) --- src/util/units.cpp | 39 ++++++++++++++++++++++++++++++++++++++- src/util/units.h | 12 ++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/util/units.cpp b/src/util/units.cpp index f822d01de..3bcbabf89 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -334,10 +334,47 @@ void UnitsSAXHandler::_endElement(xmlChar const *xname) } } +/** Initialize a length. */ +Length::Length(Unit *u, double l) { + unit = u; + length = l; +} + +/** Checks if a length is compatible with the specified unit. */ +bool Length::compatibleWith(Unit *u) { + // Percentages + if (unit->type == UNIT_TYPE_DIMENSIONLESS || u->type == UNIT_TYPE_DIMENSIONLESS) { + return true; + } + + // Other units with same type + if (unit->type == u->type) { + return true; + } + + // Different, incompatible types + return false; +} + +/** Return the length's value in the specified unit. */ +double Length::value(Unit *u) { + return convert(length, unit, u); +} + +/** Convert distances. */ +double Length::convert(double from_dist, Unit *from, Unit *to) const { + // Incompatible units + if (from->type != to->type) { + return -1; + } + + // Compatible units + return from_dist / from->factor * to->factor; +} + } // namespace Util } // namespace Inkscape - /* Local Variables: mode:c++ diff --git a/src/util/units.h b/src/util/units.h index b22bdb1f2..46680bf35 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -84,6 +84,18 @@ class UnitTable { }; +class Length { +public: + Unit *unit; + double length; + + Length(Unit *u, double l); // constructor + bool compatibleWith(Unit *u); + double value(Unit *u); + + double convert(double from_dist, Unit *from, Unit *to) const; +}; + } // namespace Util } // namespace Inkscape -- cgit v1.2.3 From e921e43e62cc68aaf29079b26392b17208689568 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Mon, 1 Jul 2013 23:39:15 -0400 Subject: Renamed Length class to Quantity class, fixed bugs, and added functions. (bzr r12380.1.3) --- src/util/units.cpp | 84 ++++++++++++++++++++++++++++++++++++++++-------------- src/util/units.h | 19 ++++++++---- 2 files changed, 75 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/util/units.cpp b/src/util/units.cpp index 3bcbabf89..d0e4e7941 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -55,6 +55,57 @@ int Unit::defaultDigits() const { } } +/** Checks if a unit is compatible with the specified unit. */ +bool Unit::compatibleWith(const Unit *u) const { + // Percentages + if (type == UNIT_TYPE_DIMENSIONLESS || u->type == UNIT_TYPE_DIMENSIONLESS) { + return true; + } + + // Other units with same type + if (type == u->type) { + return true; + } + + // Different, incompatible types + return false; +} + +/** Check if units are equal. */ +bool operator== (const Unit &u1, const Unit &u2) { + return (u1.type == u2.type && u1.name.compare(u2.name) == 0); +} + +/** Check if units are not equal. */ +bool operator!= (const Unit &u1, const Unit &u2) { + return !(u1 == u2); +} + +/** Temporary - get SVG unit. */ +int Unit::svgUnit() const { + if (!abbr.compare("px")) + return 1; + if (!abbr.compare("pt")) + return 2; + if (!abbr.compare("pc")) + return 3; + if (!abbr.compare("mm")) + return 4; + if (!abbr.compare("cm")) + return 5; + if (!abbr.compare("in")) + return 6; + if (!abbr.compare("ft")) + return 7; + if (!abbr.compare("em")) + return 8; + if (!abbr.compare("ex")) + return 9; + if (!abbr.compare("%")) + return 10; + return 0; +} + /** * Initializes the unit tables and identifies the primary unit types. * @@ -334,42 +385,31 @@ void UnitsSAXHandler::_endElement(xmlChar const *xname) } } -/** Initialize a length. */ -Length::Length(Unit *u, double l) { +/** Initialize a quantity. */ +Quantity::Quantity(Unit *u, double q) { unit = u; - length = l; + quantity = q; } -/** Checks if a length is compatible with the specified unit. */ -bool Length::compatibleWith(Unit *u) { - // Percentages - if (unit->type == UNIT_TYPE_DIMENSIONLESS || u->type == UNIT_TYPE_DIMENSIONLESS) { - return true; - } - - // Other units with same type - if (unit->type == u->type) { - return true; - } - - // Different, incompatible types - return false; +/** Checks if a quantity is compatible with the specified unit. */ +bool Quantity::compatibleWith(const Unit *u) const { + return unit->compatibleWith(u); } -/** Return the length's value in the specified unit. */ -double Length::value(Unit *u) { - return convert(length, unit, u); +/** Return the quantity's value in the specified unit. */ +double Quantity::value(Unit *u) const { + return convert(quantity, unit, u); } /** Convert distances. */ -double Length::convert(double from_dist, Unit *from, Unit *to) const { +double Quantity::convert(const double from_dist, const Unit *from, const Unit *to) { // Incompatible units if (from->type != to->type) { return -1; } // Compatible units - return from_dist / from->factor * to->factor; + return from_dist * from->factor / to->factor; } } // namespace Util diff --git a/src/util/units.h b/src/util/units.h index 46680bf35..7ef7001bb 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -47,6 +47,13 @@ class Unit { bool isAbsolute() const { return type != UNIT_TYPE_DIMENSIONLESS; } int defaultDigits() const; + bool compatibleWith(const Unit *u) const; + + friend bool operator== (const Unit &u1, const Unit &u2); + friend bool operator!= (const Unit &u1, const Unit &u2); + + // temporary + int svgUnit() const; }; class UnitTable { @@ -84,16 +91,16 @@ class UnitTable { }; -class Length { +class Quantity { public: Unit *unit; - double length; + double quantity; - Length(Unit *u, double l); // constructor - bool compatibleWith(Unit *u); - double value(Unit *u); + Quantity(Unit *u, double q); // constructor + bool compatibleWith(const Unit *u) const; + double value(Unit *u) const; - double convert(double from_dist, Unit *from, Unit *to) const; + static double convert(const double from_dist, const Unit *from, const Unit *to); }; } // namespace Util -- cgit v1.2.3 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 +++++---- src/document.h | 8 +-- src/measure-context.cpp | 2 +- src/sp-namedview.cpp | 11 +-- src/sp-namedview.h | 3 +- src/ui/widget/page-sizer.cpp | 159 +++++++++++++++++++++---------------------- src/ui/widget/page-sizer.h | 9 +-- 7 files changed, 114 insertions(+), 110 deletions(-) (limited to 'src') 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; diff --git a/src/document.h b/src/document.h index 606a83be8..c2334bbc3 100644 --- a/src/document.h +++ b/src/document.h @@ -26,6 +26,7 @@ #include "gc-anchored.h" #include #include +#include "util/units.h" namespace Avoid { class Router; @@ -35,7 +36,6 @@ class SPItem; class SPObject; struct SPGroup; struct SPRoot; -struct SPUnit; namespace Inkscape { struct Application; @@ -228,8 +228,8 @@ public: gdouble getWidth() const; gdouble getHeight() const; Geom::Point getDimensions() const; - void setWidth(gdouble width, const SPUnit *unit); - void setHeight(gdouble height, const SPUnit *unit); + void setWidth(gdouble width, const Inkscape::Util::Unit *unit); + void setHeight(gdouble height, const Inkscape::Util::Unit *unit); void requestModified(); gint ensureUpToDate(); bool addResource(const gchar *key, SPObject *object); @@ -253,8 +253,6 @@ private: void setupViewport(SPItemCtx *ctx); }; -struct SPUnit; - /* * Ideas: How to overcome style invalidation nightmare * diff --git a/src/measure-context.cpp b/src/measure-context.cpp index dc23cf5c6..9d60d38e8 100644 --- a/src/measure-context.cpp +++ b/src/measure-context.cpp @@ -13,7 +13,7 @@ #include #include -#include "helper/units.h" +#include "util/units.h" #include "macros.h" #include "display/curve.h" #include "sp-shape.h" diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 452f57425..5184d37a9 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -1101,20 +1101,23 @@ bool SPNamedView::getGuides() * \return the margin size in px, else 0.0 if anything is invalid. */ double SPNamedView::getMarginLength(gchar const * const key, - SPUnit const * const margin_units, - SPUnit const * const return_units, + Inkscape::Util::Unit const * const margin_units, + Inkscape::Util::Unit const * const return_units, double const width, double const height, bool const use_width) { double value; + static Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit percent = unit_table.getUnit("%"); if(!this->storeAsDouble(key,&value)) { return 0.0; } - if (margin_units == &sp_unit_get_by_id (SP_UNIT_PERCENT)) { + if (*margin_units == percent) { return (use_width)? width * value : height * value; } - if (!sp_convert_distance (&value, margin_units, return_units)) { +// if (!sp_convert_distance (&value, margin_units, return_units)) { + if (!margin_units->compatibleWith(return_units)) { return 0.0; } return value; diff --git a/src/sp-namedview.h b/src/sp-namedview.h index 8191ef6d6..a84368c86 100644 --- a/src/sp-namedview.h +++ b/src/sp-namedview.h @@ -24,6 +24,7 @@ #include "sp-metric.h" #include "snap.h" #include "document.h" +#include "util/units.h" G_BEGIN_DECLS @@ -94,7 +95,7 @@ struct SPNamedView : public SPObjectGroup { bool getGuides(); private: - double getMarginLength(gchar const * const key,SPUnit const * const margin_units,SPUnit const * const return_units,double const width,double const height,bool const use_width); + double getMarginLength(gchar const * const key,Inkscape::Util::Unit const * const margin_units,Inkscape::Util::Unit const * const return_units,double const width,double const height,bool const use_width); friend class SPDocument; }; diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index fa3f8e3a1..cceb3f600 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -36,7 +36,7 @@ #include "document.h" #include "desktop.h" #include "helper/action.h" -#include "helper/units.h" +#include "util/units.h" #include "inkscape.h" #include "sp-namedview.h" #include "sp-root.h" @@ -46,6 +46,8 @@ #include "xml/node.h" #include "xml/repr.h" +static Inkscape::Util::UnitTable unit_table; + using std::pair; namespace Inkscape { @@ -95,7 +97,7 @@ struct PaperSizeRec { char const * const name; //name double const smaller; //lesser dimension double const larger; //greater dimension - SPUnitId const unit; //units + Inkscape::Util::Unit const unit; //units }; // list of page formats that should be in landscape automatically @@ -113,31 +115,31 @@ fill_landscape_papers() { } static PaperSizeRec const inkscape_papers[] = { - { "A4", 210, 297, SP_UNIT_MM }, - { "US Letter", 8.5, 11, SP_UNIT_IN }, - { "US Legal", 8.5, 14, SP_UNIT_IN }, - { "US Executive", 7.25, 10.5, SP_UNIT_IN }, - { "A0", 841, 1189, SP_UNIT_MM }, - { "A1", 594, 841, SP_UNIT_MM }, - { "A2", 420, 594, SP_UNIT_MM }, - { "A3", 297, 420, SP_UNIT_MM }, - { "A5", 148, 210, SP_UNIT_MM }, - { "A6", 105, 148, SP_UNIT_MM }, - { "A7", 74, 105, SP_UNIT_MM }, - { "A8", 52, 74, SP_UNIT_MM }, - { "A9", 37, 52, SP_UNIT_MM }, - { "A10", 26, 37, SP_UNIT_MM }, - { "B0", 1000, 1414, SP_UNIT_MM }, - { "B1", 707, 1000, SP_UNIT_MM }, - { "B2", 500, 707, SP_UNIT_MM }, - { "B3", 353, 500, SP_UNIT_MM }, - { "B4", 250, 353, SP_UNIT_MM }, - { "B5", 176, 250, SP_UNIT_MM }, - { "B6", 125, 176, SP_UNIT_MM }, - { "B7", 88, 125, SP_UNIT_MM }, - { "B8", 62, 88, SP_UNIT_MM }, - { "B9", 44, 62, SP_UNIT_MM }, - { "B10", 31, 44, SP_UNIT_MM }, + { "A4", 210, 297, unit_table.getUnit("mm") }, + { "US Letter", 8.5, 11, unit_table.getUnit("in") }, + { "US Legal", 8.5, 14, unit_table.getUnit("in") }, + { "US Executive", 7.25, 10.5, unit_table.getUnit("in") }, + { "A0", 841, 1189, unit_table.getUnit("mm") }, + { "A1", 594, 841, unit_table.getUnit("mm") }, + { "A2", 420, 594, unit_table.getUnit("mm") }, + { "A3", 297, 420, unit_table.getUnit("mm") }, + { "A5", 148, 210, unit_table.getUnit("mm") }, + { "A6", 105, 148, unit_table.getUnit("mm") }, + { "A7", 74, 105, unit_table.getUnit("mm") }, + { "A8", 52, 74, unit_table.getUnit("mm") }, + { "A9", 37, 52, unit_table.getUnit("mm") }, + { "A10", 26, 37, unit_table.getUnit("mm") }, + { "B0", 1000, 1414, unit_table.getUnit("mm") }, + { "B1", 707, 1000, unit_table.getUnit("mm") }, + { "B2", 500, 707, unit_table.getUnit("mm") }, + { "B3", 353, 500, unit_table.getUnit("mm") }, + { "B4", 250, 353, unit_table.getUnit("mm") }, + { "B5", 176, 250, unit_table.getUnit("mm") }, + { "B6", 125, 176, unit_table.getUnit("mm") }, + { "B7", 88, 125, unit_table.getUnit("mm") }, + { "B8", 62, 88, unit_table.getUnit("mm") }, + { "B9", 44, 62, unit_table.getUnit("mm") }, + { "B10", 31, 44, unit_table.getUnit("mm") }, @@ -149,63 +151,63 @@ static PaperSizeRec const inkscape_papers[] = { don't know what D and E series are used for. */ - { "C0", 917, 1297, SP_UNIT_MM }, - { "C1", 648, 917, SP_UNIT_MM }, - { "C2", 458, 648, SP_UNIT_MM }, - { "C3", 324, 458, SP_UNIT_MM }, - { "C4", 229, 324, SP_UNIT_MM }, - { "C5", 162, 229, SP_UNIT_MM }, - { "C6", 114, 162, SP_UNIT_MM }, - { "C7", 81, 114, SP_UNIT_MM }, - { "C8", 57, 81, SP_UNIT_MM }, - { "C9", 40, 57, SP_UNIT_MM }, - { "C10", 28, 40, SP_UNIT_MM }, - { "D1", 545, 771, SP_UNIT_MM }, - { "D2", 385, 545, SP_UNIT_MM }, - { "D3", 272, 385, SP_UNIT_MM }, - { "D4", 192, 272, SP_UNIT_MM }, - { "D5", 136, 192, SP_UNIT_MM }, - { "D6", 96, 136, SP_UNIT_MM }, - { "D7", 68, 96, SP_UNIT_MM }, - { "E3", 400, 560, SP_UNIT_MM }, - { "E4", 280, 400, SP_UNIT_MM }, - { "E5", 200, 280, SP_UNIT_MM }, - { "E6", 140, 200, SP_UNIT_MM }, + { "C0", 917, 1297, unit_table.getUnit("mm") }, + { "C1", 648, 917, unit_table.getUnit("mm") }, + { "C2", 458, 648, unit_table.getUnit("mm") }, + { "C3", 324, 458, unit_table.getUnit("mm") }, + { "C4", 229, 324, unit_table.getUnit("mm") }, + { "C5", 162, 229, unit_table.getUnit("mm") }, + { "C6", 114, 162, unit_table.getUnit("mm") }, + { "C7", 81, 114, unit_table.getUnit("mm") }, + { "C8", 57, 81, unit_table.getUnit("mm") }, + { "C9", 40, 57, unit_table.getUnit("mm") }, + { "C10", 28, 40, unit_table.getUnit("mm") }, + { "D1", 545, 771, unit_table.getUnit("mm") }, + { "D2", 385, 545, unit_table.getUnit("mm") }, + { "D3", 272, 385, unit_table.getUnit("mm") }, + { "D4", 192, 272, unit_table.getUnit("mm") }, + { "D5", 136, 192, unit_table.getUnit("mm") }, + { "D6", 96, 136, unit_table.getUnit("mm") }, + { "D7", 68, 96, unit_table.getUnit("mm") }, + { "E3", 400, 560, unit_table.getUnit("mm") }, + { "E4", 280, 400, unit_table.getUnit("mm") }, + { "E5", 200, 280, unit_table.getUnit("mm") }, + { "E6", 140, 200, unit_table.getUnit("mm") }, //#endif - { "CSE", 462, 649, SP_UNIT_PT }, - { "US #10 Envelope", 4.125, 9.5, SP_UNIT_IN }, + { "CSE", 462, 649, unit_table.getUnit("pt") }, + { "US #10 Envelope", 4.125, 9.5, unit_table.getUnit("in") }, /* See http://www.hbp.com/content/PCR_envelopes.cfm for a much larger list of US envelope sizes. */ - { "DL Envelope", 110, 220, SP_UNIT_MM }, - { "Ledger/Tabloid", 11, 17, SP_UNIT_IN }, + { "DL Envelope", 110, 220, unit_table.getUnit("mm") }, + { "Ledger/Tabloid", 11, 17, unit_table.getUnit("in") }, /* Note that `Folio' (used in QPrinter/KPrinter) is deliberately absent from this list, as it means different sizes to different people: different people may expect the width to be either 8, 8.25 or 8.5 inches, and the height to be either 13 or 13.5 inches, even restricting our interpretation to foolscap folio. If you wish to introduce a folio-like page size to the list, then please consider using a name more specific than just `Folio' or `Foolscap Folio'. */ - { "Banner 468x60", 60, 468, SP_UNIT_PX }, - { "Icon 16x16", 16, 16, SP_UNIT_PX }, - { "Icon 32x32", 32, 32, SP_UNIT_PX }, - { "Icon 48x48", 48, 48, SP_UNIT_PX }, + { "Banner 468x60", 60, 468, unit_table.getUnit("px") }, + { "Icon 16x16", 16, 16, unit_table.getUnit("px") }, + { "Icon 32x32", 32, 32, unit_table.getUnit("px") }, + { "Icon 48x48", 48, 48, unit_table.getUnit("px") }, /* business cards */ - { "Business Card (ISO 7810)", 53.98, 85.60, SP_UNIT_MM }, - { "Business Card (US)", 2, 3.5, SP_UNIT_IN }, - { "Business Card (Europe)", 55, 85, SP_UNIT_MM }, - { "Business Card (Aus/NZ)", 55, 90, SP_UNIT_MM }, + { "Business Card (ISO 7810)", 53.98, 85.60, unit_table.getUnit("mm") }, + { "Business Card (US)", 2, 3.5, unit_table.getUnit("in") }, + { "Business Card (Europe)", 55, 85, unit_table.getUnit("mm") }, + { "Business Card (Aus/NZ)", 55, 90, unit_table.getUnit("mm") }, // Start Arch Series List - { "Arch A", 9, 12, SP_UNIT_IN }, // 229 x 305 mm - { "Arch B", 12, 18, SP_UNIT_IN }, // 305 x 457 mm - { "Arch C", 18, 24, SP_UNIT_IN }, // 457 x 610 mm - { "Arch D", 24, 36, SP_UNIT_IN }, // 610 x 914 mm - { "Arch E", 36, 48, SP_UNIT_IN }, // 914 x 1219 mm - { "Arch E1", 30, 42, SP_UNIT_IN }, // 762 x 1067 mm + { "Arch A", 9, 12, unit_table.getUnit("in") }, // 229 x 305 mm + { "Arch B", 12, 18, unit_table.getUnit("in") }, // 305 x 457 mm + { "Arch C", 18, 24, unit_table.getUnit("in") }, // 457 x 610 mm + { "Arch D", 24, 36, unit_table.getUnit("in") }, // 610 x 914 mm + { "Arch E", 36, 48, unit_table.getUnit("in") }, // 914 x 1219 mm + { "Arch E1", 30, 42, unit_table.getUnit("in") }, // 762 x 1067 mm /* * The above list of Arch sizes were taken from the following site: @@ -216,7 +218,7 @@ static PaperSizeRec const inkscape_papers[] = { * September 2009 - DAK */ - { NULL, 0, 0, SP_UNIT_PX }, + { NULL, 0, 0, unit_table.getUnit("px") }, }; @@ -226,7 +228,7 @@ static PaperSizeRec const inkscape_papers[] = { //######################################################################## //The default unit for this widget and its calculations -static const SPUnit _px_unit = sp_unit_get_by_id (SP_UNIT_PX); +static Inkscape::Util::Unit _px_unit = unit_table.getUnit("px"); /** @@ -279,12 +281,7 @@ PageSizer::PageSizer(Registry & _wr) char formatBuf[80]; snprintf(formatBuf, 79, "%0.1f x %0.1f", p->smaller, p->larger); Glib::ustring desc = formatBuf; - if (p->unit == SP_UNIT_IN) - desc.append(" in"); - else if (p->unit == SP_UNIT_MM) - desc.append(" mm"); - else if (p->unit == SP_UNIT_PX) - desc.append(" px"); + desc.append(" " + p->unit.abbr); PaperSize paper(name, p->smaller, p->larger, p->unit); _paperSizeTable[name] = paper; Gtk::TreeModel::Row row = *(_paperSizeListStore->append()); @@ -568,9 +565,9 @@ PageSizer::find_paper_size (double w, double h) const for (iter = _paperSizeTable.begin() ; iter != _paperSizeTable.end() ; ++iter) { PaperSize paper = iter->second; - SPUnit const &i_unit = sp_unit_get_by_id(paper.unit); - double smallX = sp_units_get_pixels(paper.smaller, i_unit); - double largeX = sp_units_get_pixels(paper.larger, i_unit); + Inkscape::Util::Unit const &i_unit = paper.unit; + double smallX = Inkscape::Util::Quantity::convert(paper.smaller, &i_unit, &_px_unit); + double largeX = Inkscape::Util::Quantity::convert(paper.larger, &i_unit, &_px_unit); g_return_val_if_fail(smallX <= largeX, _paperSizeListStore->children().end()); @@ -661,9 +658,9 @@ PageSizer::on_paper_size_list_changed() _landscape = _landscapeButton.get_active(); } - SPUnit const &src_unit = sp_unit_get_by_id (paper.unit); - sp_convert_distance (&w, &src_unit, &_px_unit); - sp_convert_distance (&h, &src_unit, &_px_unit); + Inkscape::Util::Unit const &src_unit = paper.unit; + w = Inkscape::Util::Quantity::convert(w, &src_unit, &_px_unit); + h = Inkscape::Util::Quantity::convert(h, &src_unit, &_px_unit); if (_landscape) setDim (h, w, false); diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h index d1fbb56e0..fc8edeeac 100644 --- a/src/ui/widget/page-sizer.h +++ b/src/ui/widget/page-sizer.h @@ -18,7 +18,7 @@ #include "ui/widget/registered-widget.h" #include -#include "helper/units.h" +#include "util/units.h" #include #include @@ -64,7 +64,7 @@ public: PaperSize(const Glib::ustring &nameArg, double smallerArg, double largerArg, - SPUnitId unitArg) + Inkscape::Util::Unit unitArg) { name = nameArg; smaller = smallerArg; @@ -108,7 +108,7 @@ public: /** * The units (px, pt, mm, etc) of this specification */ - SPUnitId unit; + Inkscape::Util::Unit unit; private: @@ -117,7 +117,8 @@ private: name = ""; smaller = 0.0; larger = 0.0; - unit = SP_UNIT_PX; + static Inkscape::Util::UnitTable unit_table; + unit = unit_table.getUnit("px"); } void assign(const PaperSize &other) -- cgit v1.2.3 From dd961a4de274306767c27756e80630d57f75ee0c Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sat, 6 Jul 2013 10:03:42 -0400 Subject: Ported measure-context.cpp (to do: port widgets/measure-toolbar.cpp so unit selector works again). (bzr r12380.1.6) --- src/measure-context.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/measure-context.cpp b/src/measure-context.cpp index 9d60d38e8..6e7709d56 100644 --- a/src/measure-context.cpp +++ b/src/measure-context.cpp @@ -515,8 +515,13 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv std::sort(intersections.begin(), intersections.end(), GeomPointSortPredicate); } - SPUnitId unitid = static_cast(prefs->getInt("/tools/measure/unitid", SP_UNIT_PX)); - SPUnit unit = sp_unit_get_by_id(unitid); + Inkscape::Util::UnitTable unit_table; + Glib::ustring unit_name = prefs->getString("/tools/measure/unit"); + if (!unit_name.compare("")) { + unit_name = "px"; + } + Inkscape::Util::Unit unit = unit_table.getUnit(unit_name); + Inkscape::Util::Unit px = unit_table.getUnit("px"); double fontsize = prefs->getInt("/tools/measure/fontsize"); @@ -527,7 +532,7 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv for (size_t idx = 1; idx < intersections.size(); ++idx) { LabelPlacement placement; placement.lengthVal = (intersections[idx] - intersections[idx - 1]).length(); - sp_convert_distance(&placement.lengthVal, &sp_unit_get_by_id(SP_UNIT_PX), &unit); + placement.lengthVal = Inkscape::Util::Quantity::convert(placement.lengthVal, &px, &unit); placement.offset = DIMENSION_OFFSET; placement.start = desktop->doc2dt( (intersections[idx - 1] + intersections[idx]) / 2 ); placement.end = placement.start - (normal * placement.offset); @@ -543,7 +548,7 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv LabelPlacement &place = *it; // TODO cleanup memory, Glib::ustring, etc.: - gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit.abbr); + gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit.abbr.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, place.end, @@ -584,10 +589,10 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv { double totallengthval = (end_point - start_point).length(); - sp_convert_distance(&totallengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit); + totallengthval = Inkscape::Util::Quantity::convert(totallengthval, &px, &unit); // TODO cleanup memory, Glib::ustring, etc.: - gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr); + gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), @@ -605,10 +610,10 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv if (intersections.size() > 2) { double totallengthval = (intersections[intersections.size()-1] - intersections[0]).length(); - sp_convert_distance(&totallengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit); + totallengthval = Inkscape::Util::Quantity::convert(totallengthval, &px, &unit); // TODO cleanup memory, Glib::ustring, etc.: - gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr); + gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * 60, -- 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 ++++++++++++++++++---------------- src/document.h | 8 +++++--- src/ui/widget/page-sizer.cpp | 4 ++-- src/util/units.cpp | 2 +- src/util/units.h | 4 ++-- 5 files changed, 28 insertions(+), 24 deletions(-) (limited to 'src') 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 #include -#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; -- cgit v1.2.3 From 9dc7b786c9ef31060012ea4ae13a8188548b4f62 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Tue, 9 Jul 2013 16:42:04 -0400 Subject: Ported sp-namedview.cpp (todo: fix a bunch of things). (bzr r12380.1.8) --- src/sp-namedview.cpp | 27 +++++++++++++++------------ src/sp-namedview.h | 11 ++++++----- src/ui/dialog/clonetiler.cpp | 2 +- src/ui/dialog/document-properties.cpp | 4 ++-- src/ui/dialog/export.cpp | 4 ++-- src/ui/dialog/guides.cpp | 2 +- src/ui/widget/page-sizer.cpp | 4 ++-- src/ui/widget/selected-style.cpp | 2 +- src/util/units.cpp | 21 +++++++++++++++++++++ src/util/units.h | 1 + src/widgets/desktop-widget.cpp | 10 +++++----- src/widgets/lpe-toolbar.cpp | 2 +- src/widgets/measure-toolbar.cpp | 2 +- src/widgets/node-toolbar.cpp | 2 +- src/widgets/rect-toolbar.cpp | 2 +- src/widgets/select-toolbar.cpp | 2 +- src/widgets/stroke-style.cpp | 6 +++--- src/widgets/text-toolbar.cpp | 2 +- 18 files changed, 66 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 5184d37a9..c7301f9bd 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -22,7 +22,7 @@ #include "display/canvas-grid.h" #include "display/guideline.h" -#include "helper/units.h" +#include "util/units.h" #include "svg/svg-color.h" #include "xml/repr.h" #include "attributes.h" @@ -287,6 +287,8 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va { SPNamedView *nv = SP_NAMEDVIEW(object); + static Inkscape::Util::UnitTable unit_table; + switch (key) { case SP_ATTR_VIEWONLY: nv->editable = (!value); @@ -549,18 +551,19 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va * in that they aren't in general absolute units as currently required by * doc_units. */ - SPUnit const *new_unit = &sp_unit_get_by_id(SP_UNIT_PX); + static Inkscape::Util::Unit px = unit_table.getUnit("px"); + Inkscape::Util::Unit const *new_unit = &px; if (value) { - SPUnit const *const req_unit = sp_unit_get_by_abbreviation(value); - if ( req_unit == NULL ) { + Inkscape::Util::Unit u = unit_table.getUnit(value); + Inkscape::Util::Unit const *const req_unit = &u; + if ( !unit_table.hasUnit(value) ) { g_warning("Unrecognized unit `%s'", value); /* fixme: Document errors should be reported in the status bar or * the like (e.g. as per * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing); g_log * should be only for programmer errors. */ - } else if ( req_unit->base == SP_UNIT_ABSOLUTE || - req_unit->base == SP_UNIT_DEVICE ) { + } else if ( req_unit->isAbsolute() ) { new_unit = req_unit; } else { g_warning("Document units must be absolute like `mm', `pt' or `px', but found `%s'", @@ -573,18 +576,18 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va break; } case SP_ATTR_UNITS: { - SPUnit const *new_unit = NULL; + Inkscape::Util::Unit const *new_unit = NULL; if (value) { - SPUnit const *const req_unit = sp_unit_get_by_abbreviation(value); - if ( req_unit == NULL ) { + Inkscape::Util::Unit u = unit_table.getUnit(value); + Inkscape::Util::Unit const *const req_unit = &u; + if ( !unit_table.hasUnit(value) ) { g_warning("Unrecognized unit `%s'", value); /* fixme: Document errors should be reported in the status bar or * the like (e.g. as per * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing); g_log * should be only for programmer errors. */ - } else if ( req_unit->base == SP_UNIT_ABSOLUTE || - req_unit->base == SP_UNIT_DEVICE ) { + } else if ( req_unit->isAbsolute() ) { new_unit = req_unit; } else { g_warning("Document units must be absolute like `mm', `pt' or `px', but found `%s'", @@ -1130,7 +1133,7 @@ double SPNamedView::getMarginLength(gchar const * const key, SPMetric SPNamedView::getDefaultMetric() const { if (doc_units) { - return sp_unit_get_metric(doc_units); + return (SPMetric) doc_units->metric(); } else { return SP_PT; } diff --git a/src/sp-namedview.h b/src/sp-namedview.h index a84368c86..f9629f0c6 100644 --- a/src/sp-namedview.h +++ b/src/sp-namedview.h @@ -28,10 +28,11 @@ G_BEGIN_DECLS -struct SPUnit; - namespace Inkscape { -class CanvasGrid; + class CanvasGrid; + namespace Util { + class Unit; + } } enum { @@ -59,8 +60,8 @@ struct SPNamedView : public SPObjectGroup { GSList * grids; bool grids_visible; - SPUnit const *doc_units; - SPUnit const *units; + Inkscape::Util::Unit const *doc_units; + Inkscape::Util::Unit const *units; GQuark default_layer_id; diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index 753320ab9..00bb6f0e2 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -1093,7 +1093,7 @@ CloneTiler::CloneTiler (void) : // unitmenu GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); - sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units); + //sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units); { // Width spinbutton diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index d335fb303..af462a1df 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -1431,8 +1431,8 @@ void DocumentProperties::update() _rcp_bord.setRgba32 (nv->bordercolor); _rcb_shad.setActive (nv->showpageshadow); - if (nv->doc_units) - _rum_deflt.setUnit (nv->doc_units); + //if (nv->doc_units) + // _rum_deflt.setUnit (nv->doc_units); double const doc_w_px = sp_desktop_document(dt)->getWidth(); double const doc_h_px = sp_desktop_document(dt)->getHeight(); diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index a851503fe..25300cfc0 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -200,8 +200,8 @@ Export::Export (void) : earlier than that */ unit_selector = Glib::wrap(sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE)); SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (desktop) - sp_unit_selector_set_unit (SP_UNIT_SELECTOR(unit_selector->gobj()), sp_desktop_namedview(desktop)->doc_units); + //if (desktop) + // sp_unit_selector_set_unit (SP_UNIT_SELECTOR(unit_selector->gobj()), sp_desktop_namedview(desktop)->doc_units); unitbox.pack_end(*unit_selector, false, false, 0); unitbox.pack_end(units_label, false, false, 3); diff --git a/src/ui/dialog/guides.cpp b/src/ui/dialog/guides.cpp index 51bbc7d9a..9a7b19c35 100644 --- a/src/ui/dialog/guides.cpp +++ b/src/ui/dialog/guides.cpp @@ -230,7 +230,7 @@ void GuidelinePropertiesDialog::_setup() { _unit_menu.setUnitType(UNIT_TYPE_LINEAR); _unit_menu.setUnit("px"); if (_desktop->namedview->doc_units) { - _unit_menu.setUnit( sp_unit_get_abbreviation(_desktop->namedview->doc_units) ); + //_unit_menu.setUnit( sp_unit_get_abbreviation(_desktop->namedview->doc_units) ); } _spin_angle.setUnit(_angle_unit_status); diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index 884f9ea0a..14e280f6d 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -316,9 +316,9 @@ PageSizer::PageSizer(Registry & _wr) SPNamedView *nv = sp_desktop_namedview(dt); _wr.setUpdating (true); if (nv->units) { - _dimensionUnits.setUnit(nv->units); + //_dimensionUnits.setUnit(nv->units); } else if (nv->doc_units) { - _dimensionUnits.setUnit(nv->doc_units); + //_dimensionUnits.setUnit(nv->doc_units); } _wr.setUpdating (false); diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index 18dbb984b..d6e2406c9 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -476,7 +476,7 @@ SelectedStyle::setDesktop(SPDesktop *desktop) this ) )); - _sw_unit = const_cast(sp_desktop_namedview(desktop)->doc_units); + //_sw_unit = const_cast(sp_desktop_namedview(desktop)->doc_units); // Set the doc default unit active in the units list gint length = g_slist_length(_unit_mis); diff --git a/src/util/units.cpp b/src/util/units.cpp index a51eb2570..6c225f717 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -106,6 +106,27 @@ int Unit::svgUnit() const { return 0; } +/** Temporary - get metric. */ +int Unit::metric() const { + if (!abbr.compare("mm")) + return 1; + if (!abbr.compare("cm")) + return 2; + if (!abbr.compare("in")) + return 3; + if (!abbr.compare("ft")) + return 4; + if (!abbr.compare("pt")) + return 5; + if (!abbr.compare("pc")) + return 6; + if (!abbr.compare("px")) + return 7; + if (!abbr.compare("m")) + return 8; + return 0; +} + /** * Initializes the unit tables and identifies the primary unit types. * diff --git a/src/util/units.h b/src/util/units.h index 0ea84bfbb..64eb4a665 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -54,6 +54,7 @@ class Unit { // temporary int svgUnit() const; + int metric() const; }; class UnitTable { diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 814298041..7d3bbc44a 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -1672,7 +1672,7 @@ SPDesktopWidget* SPDesktopWidget::createInstance(SPNamedView *namedview) { SPDesktopWidget *dtw = static_cast(g_object_new(SP_TYPE_DESKTOP_WIDGET, NULL)); - dtw->dt2r = 1.0 / namedview->doc_units->unittobase; + dtw->dt2r = 1.0 / namedview->doc_units->factor; dtw->ruler_origin = Geom::Point(0,0); //namedview->gridorigin; Why was the grid origin used here? @@ -1744,7 +1744,7 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags) SPNamedView *nv=SP_NAMEDVIEW(obj); if (flags & SP_OBJECT_MODIFIED_FLAG) { - this->dt2r = 1.0 / nv->doc_units->unittobase; + this->dt2r = 1.0 / nv->doc_units->factor; this->ruler_origin = Geom::Point(0,0); //nv->gridorigin; Why was the grid origin used here? sp_ruler_set_unit(SP_RULER (this->vruler), nv->getDefaultMetric()); @@ -1778,14 +1778,14 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags) if (tracker == NULL) // it's null when inkscape is first opened continue; - tracker->setActiveUnit( nv->doc_units ); + // tracker->setActiveUnit( nv->doc_units ); } // grandchildren } // if child is a container } // children } // if aux_toolbox is a container - gtk_widget_set_tooltip_text(this->hruler_box, gettext(sp_unit_get_plural (nv->doc_units))); - gtk_widget_set_tooltip_text(this->vruler_box, gettext(sp_unit_get_plural (nv->doc_units))); + gtk_widget_set_tooltip_text(this->hruler_box, gettext(nv->doc_units->name_plural.c_str())); + gtk_widget_set_tooltip_text(this->vruler_box, gettext(nv->doc_units->name_plural.c_str())); sp_desktop_widget_update_rulers(this); ToolboxFactory::updateSnapToolbox(this->desktop, 0, this->snap_toolbox); diff --git a/src/widgets/lpe-toolbar.cpp b/src/widgets/lpe-toolbar.cpp index 3126175b3..8c481d2f1 100644 --- a/src/widgets/lpe-toolbar.cpp +++ b/src/widgets/lpe-toolbar.cpp @@ -294,7 +294,7 @@ static void lpetool_open_lpe_dialog(GtkToggleAction *act, gpointer data) void sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { UnitTracker* tracker = new UnitTracker(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); - tracker->setActiveUnit(sp_desktop_namedview(desktop)->doc_units); + //tracker->setActiveUnit(sp_desktop_namedview(desktop)->doc_units); g_object_set_data(holder, "tracker", tracker); SPUnit const *unit = tracker->getActiveUnit(); diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 21df4c6d9..387dbbeae 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -91,7 +91,7 @@ static void measure_unit_changed(GtkAction* /*act*/, GObject* tbl) void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObject* holder) { UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); - tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); + //tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); g_object_set_data( holder, "tracker", tracker ); EgeAdjustmentAction *eact = 0; diff --git a/src/widgets/node-toolbar.cpp b/src/widgets/node-toolbar.cpp index 849de874d..d6de74817 100644 --- a/src/widgets/node-toolbar.cpp +++ b/src/widgets/node-toolbar.cpp @@ -340,7 +340,7 @@ static void sp_node_toolbox_sel_modified(Inkscape::Selection *selection, guint / void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); - tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); + //tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); g_object_set_data( holder, "tracker", tracker ); Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 8c1a735c5..5fa96289f 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -304,7 +304,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); //tracker->addUnit( SP_UNIT_PERCENT, 0 ); // fixme: add % meaning per cent of the width/height - tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); + //tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); g_object_set_data( holder, "tracker", tracker ); /* W */ diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index 549581610..693fc870b 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -488,7 +488,7 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb // Create the units menu. UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); tracker->addUnit( SP_UNIT_PERCENT, 0 ); - tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); + //tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); g_object_set_data( G_OBJECT(spw), "tracker", tracker ); g_signal_connect( G_OBJECT(spw), "destroy", G_CALLBACK(destroy_tracker), spw ); diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 0a5b3781b..17e3984bb 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -193,8 +193,8 @@ StrokeStyle::StrokeStyle() : Gtk::Widget *us = manage(Glib::wrap(unitSelector)); SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (desktop) - sp_unit_selector_set_unit (SP_UNIT_SELECTOR(unitSelector), sp_desktop_namedview(desktop)->doc_units); + //if (desktop) + // sp_unit_selector_set_unit (SP_UNIT_SELECTOR(unitSelector), sp_desktop_namedview(desktop)->doc_units); sp_unit_selector_add_unit(SP_UNIT_SELECTOR(unitSelector), &sp_unit_get_by_id(SP_UNIT_PERCENT), 0); g_signal_connect ( G_OBJECT (unitSelector), "set_unit", G_CALLBACK (StrokeStyle::setStrokeWidthUnit), this ); us->show(); @@ -884,7 +884,7 @@ StrokeStyle::updateLine() } else { // same width, or only one object; no sense to keep percent, switch to absolute if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) { - sp_unit_selector_set_unit(SP_UNIT_SELECTOR(unitSelector), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units); + //sp_unit_selector_set_unit(SP_UNIT_SELECTOR(unitSelector), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units); } } diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 87cb54d10..144a2a3e8 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -1219,7 +1219,7 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje // Is this used? UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); - tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); + //tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); g_object_set_data( holder, "tracker", tracker ); /* Font family */ -- cgit v1.2.3 From 3174f1abec451e06ff36bf8f4d9a1e5992ee0382 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Tue, 16 Jul 2013 20:10:36 -0400 Subject: Added new UnitTracker class. (bzr r12380.1.9) --- src/ui/widget/Makefile_insert | 4 +- src/ui/widget/unit-tracker.cpp | 255 +++++++++++++++++++++++++++++++++++++++++ src/ui/widget/unit-tracker.h | 75 ++++++++++++ 3 files changed, 333 insertions(+), 1 deletion(-) create mode 100644 src/ui/widget/unit-tracker.cpp create mode 100644 src/ui/widget/unit-tracker.h (limited to 'src') diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert index 2de954674..710b95c2b 100644 --- a/src/ui/widget/Makefile_insert +++ b/src/ui/widget/Makefile_insert @@ -79,5 +79,7 @@ ink_common_sources += \ ui/widget/tolerance-slider.cpp \ ui/widget/tolerance-slider.h \ ui/widget/unit-menu.cpp \ - ui/widget/unit-menu.h + ui/widget/unit-menu.h \ + ui/widget/unit-tracker.h \ + ui/widget/unit-tracker.cpp diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp new file mode 100644 index 000000000..b701c785e --- /dev/null +++ b/src/ui/widget/unit-tracker.cpp @@ -0,0 +1,255 @@ +/* + * Inkscape::UI::Widget::UnitTracker + * Simple mediator to synchronize changes to unit menus + * + * Authors: + * Jon A. Cruz + * Matthew Petroff + * + * Copyright (C) 2007 Jon A. Cruz + * Copyright (C) 2013 Matthew Petroff + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "unit-tracker.h" +#include "ege-select-one-action.h" + +#define COLUMN_STRING 0 + +namespace Inkscape { +namespace UI { +namespace Widget { + +UnitTracker::UnitTracker(UnitType unit_type) : + _active(0), + _isUpdating(false), + _activeUnitInitialized(false), + _store(0), + _unitList(0), + _actionList(0), + _adjList(0), + _priorValues() +{ + _store = gtk_list_store_new(1, G_TYPE_STRING); + static Inkscape::Util::UnitTable unit_table; + + GtkTreeIter iter; + UnitTable::UnitMap m = _unit_table.units(unit_type); + UnitTable::UnitMap::iterator m_iter = m.begin(); + while(m_iter != m.end()) { + Glib::ustring text = (*m_iter).first; + m_iter++; + gtk_list_store_append(_store, &iter); + gtk_list_store_set(_store, &iter, COLUMN_STRING, text.c_str(), -1); + } + gint count = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(_store), 0); + if ((count > 0) && (_active > count)) { + _setActive(--count); + } else { + _setActive(_active); + } +} + +UnitTracker::~UnitTracker() +{ + // Unhook weak references to GtkActions + while (_actionList) { + g_signal_handlers_disconnect_by_func(G_OBJECT(_actionList->data), (gpointer) _unitChangedCB, this); + g_object_weak_unref(G_OBJECT(_actionList->data), _actionFinalizedCB, this); + _actionList = g_slist_delete_link(_actionList, _actionList); + } + + // Unhook weak references to GtkAdjustments + while (_adjList) { + g_object_weak_unref(G_OBJECT(_adjList->data), _adjustmentFinalizedCB, this); + _adjList = g_slist_delete_link(_adjList, _adjList); + } +} + +bool UnitTracker::isUpdating() const +{ + return _isUpdating; +} + +Inkscape::Util::Unit UnitTracker::getActiveUnit() const +{ + return _activeUnit; +} + +void UnitTracker::setActiveUnit(Inkscape::Util::Unit const *unit) +{ + if (unit) { + GtkTreeIter iter; + int index = 0; + gboolean found = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(_store), &iter); + while (found) { + gchar *storedUnit = 0; + gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &storedUnit, -1); + if (storedUnit && (!unit->abbr.compare(storedUnit))) { + _setActive(index); + break; + } + + found = gtk_tree_model_iter_next(GTK_TREE_MODEL(_store), &iter); + index++; + } + } +} + +void UnitTracker::setActiveUnitByAbbr(gchar const *abbr) +{ + Inkscape::Util::Unit u = _unit_table.getUnit(abbr); + setActiveUnit(&u); +} + +void UnitTracker::addAdjustment(GtkAdjustment *adj) +{ + if (!g_slist_find(_adjList, adj)) { + g_object_weak_ref(G_OBJECT(adj), _adjustmentFinalizedCB, this); + _adjList = g_slist_append(_adjList, adj); + } +} + +void UnitTracker::setFullVal(GtkAdjustment *adj, gdouble val) +{ + _priorValues[adj] = val; +} + +GtkAction *UnitTracker::createAction(gchar const *name, gchar const *label, gchar const *tooltip) +{ + EgeSelectOneAction *act1 = ege_select_one_action_new(name, label, tooltip, NULL, GTK_TREE_MODEL(_store)); + ege_select_one_action_set_label_column(act1, COLUMN_STRING); + if (_active) { + ege_select_one_action_set_active(act1, _active); + } + + ege_select_one_action_set_appearance(act1, "minimal"); + g_object_weak_ref(G_OBJECT(act1), _actionFinalizedCB, this); + g_signal_connect(G_OBJECT(act1), "changed", G_CALLBACK(_unitChangedCB), this); + _actionList = g_slist_append(_actionList, act1); + + return GTK_ACTION(act1); +} + +void UnitTracker::_unitChangedCB(GtkAction *action, gpointer data) +{ + if (action && data) { + EgeSelectOneAction *act = EGE_SELECT_ONE_ACTION(action); + gint active = ege_select_one_action_get_active(act); + UnitTracker *self = reinterpret_cast(data); + self->_setActive(active); + } +} + +void UnitTracker::_actionFinalizedCB(gpointer data, GObject *where_the_object_was) +{ + if (data && where_the_object_was) { + UnitTracker *self = reinterpret_cast(data); + self->_actionFinalized(where_the_object_was); + } +} + +void UnitTracker::_adjustmentFinalizedCB(gpointer data, GObject *where_the_object_was) +{ + if (data && where_the_object_was) { + UnitTracker *self = reinterpret_cast(data); + self->_adjustmentFinalized(where_the_object_was); + } +} + +void UnitTracker::_actionFinalized(GObject *where_the_object_was) +{ + GSList *target = g_slist_find(_actionList, where_the_object_was); + if (target) { + _actionList = g_slist_remove(_actionList, where_the_object_was); + } else { + g_warning("Received a finalization callback for unknown object %p", where_the_object_was); + } +} + +void UnitTracker::_adjustmentFinalized(GObject *where_the_object_was) +{ + GSList *target = g_slist_find(_adjList, where_the_object_was); + if (target) { + _adjList = g_slist_remove(_adjList, where_the_object_was); + } else { + g_warning("Received a finalization callback for unknown object %p", where_the_object_was); + } +} + +void UnitTracker::_setActive(gint active) +{ + if ( active != _active || !_activeUnitInitialized ) { + gint oldActive = _active; + + GtkTreeIter iter; + gboolean found = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(_store), &iter, NULL, oldActive); + if (found) { + gchar *abbr; + gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &abbr, -1); + Inkscape::Util::Unit unit = _unit_table.getUnit(abbr); + + found = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(_store), &iter, NULL, active); + if (found) { + gchar *newAbbr; + gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &newAbbr, -1); + Inkscape::Util::Unit newUnit = _unit_table.getUnit(newAbbr); + _activeUnit = newUnit; + + if (_adjList) { + _fixupAdjustments(unit, newUnit); + } + + } else { + g_warning("Did not find new unit"); + } + } else { + g_warning("Did not find old unit"); + } + + _active = active; + + for ( GSList *cur = _actionList ; cur ; cur = g_slist_next(cur) ) { + if (IS_EGE_SELECT_ONE_ACTION(cur->data)) { + EgeSelectOneAction *act = EGE_SELECT_ONE_ACTION(cur->data); + ege_select_one_action_set_active(act, active); + } + } + + _activeUnitInitialized = true; + } +} + +void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape::Util::Unit const newUnit) +{ + _isUpdating = true; + Inkscape::Util::Unit px = _unit_table.getUnit("px"); + for ( GSList *cur = _adjList ; cur ; cur = g_slist_next(cur) ) { + GtkAdjustment *adj = GTK_ADJUSTMENT(cur->data); + gdouble oldVal = gtk_adjustment_get_value(adj); + gdouble val = oldVal; + + if ( (oldUnit.type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) + && (newUnit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) ) + { + val = 1.0 / newUnit.factor; + _priorValues[adj] = Inkscape::Util::Quantity::convert(oldVal, &oldUnit, &px); + } else if ( (oldUnit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) + && (newUnit.type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) ) + { + if (_priorValues.find(adj) != _priorValues.end()) { + val = Inkscape::Util::Quantity::convert(_priorValues[adj], &newUnit, &px); + } + } else { + val = Inkscape::Util::Quantity::convert(oldVal, &oldUnit, &newUnit); + } + + gtk_adjustment_set_value(adj, val); + } + _isUpdating = false; +} + +} // namespace Widget +} // namespace UI +} // namespace Inkscape diff --git a/src/ui/widget/unit-tracker.h b/src/ui/widget/unit-tracker.h new file mode 100644 index 000000000..521fe50c8 --- /dev/null +++ b/src/ui/widget/unit-tracker.h @@ -0,0 +1,75 @@ +/* + * Inkscape::UI::Widget::UnitTracker + * Simple mediator to synchronize changes to unit menus + * + * Authors: + * Jon A. Cruz + * Matthew Petroff + * + * Copyright (C) 2007 Jon A. Cruz + * Copyright (C) 2013 Matthew Petroff + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef INKSCAPE_UI_WIDGET_UNIT_TRACKER_H +#define INKSCAPE_UI_WIDGET_UNIT_TRACKER_H + +#include +#include + +#include "util/units.h" + +using Inkscape::Util::Unit; +using Inkscape::Util::UnitTable; +using Inkscape::Util::UnitType; + +namespace Inkscape { +namespace UI { +namespace Widget { + +class UnitTracker { +public: + UnitTracker(UnitType unit_type); + virtual ~UnitTracker(); + + bool isUpdating() const; + + void setActiveUnit(Inkscape::Util::Unit const *unit); + void setActiveUnitByAbbr(gchar const *abbr); + Inkscape::Util::Unit getActiveUnit() const; + + void addAdjustment(GtkAdjustment *adj); + void setFullVal(GtkAdjustment *adj, gdouble val); + + GtkAction *createAction(gchar const *name, gchar const *label, gchar const *tooltip); + +protected: + UnitTable _unit_table; + UnitType _type; + +private: + static void _unitChangedCB(GtkAction *action, gpointer data); + static void _actionFinalizedCB(gpointer data, GObject *where_the_object_was); + static void _adjustmentFinalizedCB(gpointer data, GObject *where_the_object_was); + void _setActive(gint index); + void _fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape::Util::Unit const newUnit); + void _actionFinalized(GObject *where_the_object_was); + void _adjustmentFinalized(GObject *where_the_object_was); + + gint _active; + bool _isUpdating; + Inkscape::Util::Unit _activeUnit; + bool _activeUnitInitialized; + GtkListStore *_store; + GSList *_unitList; + GSList *_actionList; + GSList *_adjList; + std::map _priorValues; +}; + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +#endif // INKSCAPE_UI_WIDGET_UNIT_TRACKER_H -- cgit v1.2.3 From 64bc8cf145b55d33469ef1b84e18ca8df580eda8 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Tue, 16 Jul 2013 20:42:12 -0400 Subject: Removed unused unit includes. (bzr r12380.1.10) --- src/widgets/arc-toolbar.cpp | 4 ---- src/widgets/calligraphy-toolbar.cpp | 4 ---- src/widgets/connector-toolbar.cpp | 4 ---- src/widgets/dropper-toolbar.cpp | 4 ---- src/widgets/erasor-toolbar.cpp | 4 ---- src/widgets/measure-toolbar.cpp | 22 ++++++++++++++-------- src/widgets/pencil-toolbar.cpp | 5 ----- src/widgets/spiral-toolbar.cpp | 4 ---- src/widgets/spray-toolbar.cpp | 4 ---- src/widgets/star-toolbar.cpp | 4 ---- src/widgets/tweak-toolbar.cpp | 4 ---- src/widgets/zoom-toolbar.cpp | 4 ---- 12 files changed, 14 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index 809050ad9..e3f3a8c79 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -56,14 +56,10 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../sp-ellipse.h" #include "../mod360.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; diff --git a/src/widgets/calligraphy-toolbar.cpp b/src/widgets/calligraphy-toolbar.cpp index 4cb4813b5..7c2d6bf19 100644 --- a/src/widgets/calligraphy-toolbar.cpp +++ b/src/widgets/calligraphy-toolbar.cpp @@ -56,13 +56,9 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index 7c72f8e0c..293f1184d 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -55,9 +55,6 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../sp-namedview.h" #include "../conn-avoid-ref.h" @@ -66,7 +63,6 @@ #include "../sp-path.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; diff --git a/src/widgets/dropper-toolbar.cpp b/src/widgets/dropper-toolbar.cpp index cf58aa507..054955d8f 100644 --- a/src/widgets/dropper-toolbar.cpp +++ b/src/widgets/dropper-toolbar.cpp @@ -54,13 +54,9 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../tools-switch.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; diff --git a/src/widgets/erasor-toolbar.cpp b/src/widgets/erasor-toolbar.cpp index 2e074490d..44c79d5f3 100644 --- a/src/widgets/erasor-toolbar.cpp +++ b/src/widgets/erasor-toolbar.cpp @@ -55,13 +55,9 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 387dbbeae..c72cb8fa3 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -52,13 +52,12 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../sp-namedview.h" +#include "ui/widget/unit-tracker.h" -using Inkscape::UnitTracker; +using Inkscape::UI::Widget::UnitTracker; +using Inkscape::Util::Unit; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -83,15 +82,20 @@ sp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl) static void measure_unit_changed(GtkAction* /*act*/, GObject* tbl) { UnitTracker* tracker = reinterpret_cast(g_object_get_data(tbl, "tracker")); - SPUnit const *unit = tracker->getActiveUnit(); + Glib::ustring const unit = tracker->getActiveUnit().abbr; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt("/tools/measure/unitid", unit->unit_id); + prefs->setString("/tools/measure/unit", unit); } void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObject* holder) { - UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); - //tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); + UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + tracker->setActiveUnitByAbbr(prefs->getString("/tools/measure/unit").c_str()); + + //tracker->setUnitType(UNIT_TYPE_LINEAR); + //tracker->setUnit("px"); + g_object_set_data( holder, "tracker", tracker ); EgeAdjustmentAction *eact = 0; @@ -121,8 +125,10 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G // units menu { GtkAction* act = tracker->createAction( "MeasureUnitsAction", _("Units:"), _("The units to be used for the measurements") ); + //EgeOutputAction* act = ege_output_action_new( "MeasureUnitsAction", _("Units:"), _("The units to be used for the measurements"), 0 ); g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(measure_unit_changed), holder ); gtk_action_group_add_action( mainActions, act ); + //gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); } } // end of sp_measure_toolbox_prep() diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index e0cf67bd0..e38b54b5d 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -67,15 +67,10 @@ //#include "../ui/tool/multi-path-manipulator.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" - #include "../pen-context.h" //#include "../sp-namedview.h" #include "../tools-switch.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp index 08d26f3d1..48b509acc 100644 --- a/src/widgets/spiral-toolbar.cpp +++ b/src/widgets/spiral-toolbar.cpp @@ -53,13 +53,9 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../sp-spiral.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 06850d261..bdc700aa8 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -52,13 +52,9 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../spray-context.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index 8c07c6473..545256061 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -53,14 +53,10 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../sp-star.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; diff --git a/src/widgets/tweak-toolbar.cpp b/src/widgets/tweak-toolbar.cpp index beb527a17..e96418957 100644 --- a/src/widgets/tweak-toolbar.cpp +++ b/src/widgets/tweak-toolbar.cpp @@ -52,13 +52,9 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../tweak-context.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; diff --git a/src/widgets/zoom-toolbar.cpp b/src/widgets/zoom-toolbar.cpp index 7d7f2c774..9cdbc3d6a 100644 --- a/src/widgets/zoom-toolbar.cpp +++ b/src/widgets/zoom-toolbar.cpp @@ -51,14 +51,10 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../tweak-context.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; -- cgit v1.2.3 From a2b755108f544e938705a364d2573b049e21f26f Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 17 Jul 2013 00:15:06 -0400 Subject: Ported "widgets/text-toolbar.cpp" and "widgets/paintbucket.cpp" (bzr r12380.1.11) --- src/widgets/paintbucket-toolbar.cpp | 17 +++++++++-------- src/widgets/text-toolbar.cpp | 9 +++------ 2 files changed, 12 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/widgets/paintbucket-toolbar.cpp b/src/widgets/paintbucket-toolbar.cpp index 73815b86d..2c782da70 100644 --- a/src/widgets/paintbucket-toolbar.cpp +++ b/src/widgets/paintbucket-toolbar.cpp @@ -54,9 +54,8 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" +#include "util/units.h" +#include "ui/widget/unit-tracker.h" #include "../pen-context.h" #include "../sp-namedview.h" #include "../flood-context.h" @@ -64,7 +63,7 @@ #include -using Inkscape::UnitTracker; +using Inkscape::UI::Widget::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -97,13 +96,13 @@ static void paintbucket_autogap_changed(EgeSelectOneAction* act, GObject * /*tbl static void paintbucket_offset_changed(GtkAdjustment *adj, GObject *tbl) { UnitTracker* tracker = static_cast(g_object_get_data( tbl, "tracker" )); - SPUnit const *unit = tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); // Don't adjust the offset value because we're saving the // unit and it'll be correctly handled on load. prefs->setDouble("/tools/paintbucket/offset", (gdouble)gtk_adjustment_get_value(adj)); - prefs->setString("/tools/paintbucket/offsetunits", sp_unit_get_abbreviation(unit)); + prefs->setString("/tools/paintbucket/offsetunits", unit.abbr); } static void paintbucket_defaults(GtkWidget *, GObject *tbl) @@ -175,10 +174,12 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions } // Create the units menu. - UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); + UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); + Inkscape::Util::UnitTable unit_table; Glib::ustring stored_unit = prefs->getString("/tools/paintbucket/offsetunits"); if (!stored_unit.empty()) { - tracker->setActiveUnit(sp_unit_get_by_abbreviation(stored_unit.data())); + Unit u = unit_table.getUnit(stored_unit); + tracker->setActiveUnit(&u); } g_object_set_data( holder, "tracker", tracker ); { diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 144a2a3e8..4dd44bb8d 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -56,9 +56,6 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "../pen-context.h" #include "../sp-namedview.h" #include "../svg/css-ostringstream.h" @@ -72,7 +69,6 @@ #include "widgets/font-selector.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -1218,9 +1214,10 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); // Is this used? - UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); + /*UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); //tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); - g_object_set_data( holder, "tracker", tracker ); + tracker->setActiveUnit(&sp_unit_get_by_id(SP_UNIT_PX)); + g_object_set_data( holder, "tracker", tracker );*/ /* Font family */ { -- cgit v1.2.3 From c28e6d2bdeb2983698a4e4789de15570e0f3d161 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 17 Jul 2013 00:25:40 -0400 Subject: Fixed conversion factors and missed unit include removal. (bzr r12380.1.12) --- src/ui/widget/unit-tracker.cpp | 2 +- src/widgets/box3d-toolbar.cpp | 5 ----- src/widgets/desktop-widget.cpp | 4 ++-- 3 files changed, 3 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp index b701c785e..df78e21dd 100644 --- a/src/ui/widget/unit-tracker.cpp +++ b/src/ui/widget/unit-tracker.cpp @@ -233,7 +233,7 @@ void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape if ( (oldUnit.type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) && (newUnit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) ) { - val = 1.0 / newUnit.factor; + val = newUnit.factor; _priorValues[adj] = Inkscape::Util::Quantity::convert(oldVal, &oldUnit, &px); } else if ( (oldUnit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) && (newUnit.type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) ) diff --git a/src/widgets/box3d-toolbar.cpp b/src/widgets/box3d-toolbar.cpp index e8b330375..2d40b996b 100644 --- a/src/widgets/box3d-toolbar.cpp +++ b/src/widgets/box3d-toolbar.cpp @@ -58,16 +58,11 @@ #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" - #include "../pen-context.h" #include "../box3d-context.h" #include "../box3d.h" -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 7d3bbc44a..57f655033 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -1672,7 +1672,7 @@ SPDesktopWidget* SPDesktopWidget::createInstance(SPNamedView *namedview) { SPDesktopWidget *dtw = static_cast(g_object_new(SP_TYPE_DESKTOP_WIDGET, NULL)); - dtw->dt2r = 1.0 / namedview->doc_units->factor; + dtw->dt2r = namedview->doc_units.factor; dtw->ruler_origin = Geom::Point(0,0); //namedview->gridorigin; Why was the grid origin used here? @@ -1744,7 +1744,7 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags) SPNamedView *nv=SP_NAMEDVIEW(obj); if (flags & SP_OBJECT_MODIFIED_FLAG) { - this->dt2r = 1.0 / nv->doc_units->factor; + this->dt2r = nv->doc_units.factor; this->ruler_origin = Geom::Point(0,0); //nv->gridorigin; Why was the grid origin used here? sp_ruler_set_unit(SP_RULER (this->vruler), nv->getDefaultMetric()); -- cgit v1.2.3 From ed0b9d91e08cf55287745636608bddd5ebd5ea34 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 17 Jul 2013 00:29:41 -0400 Subject: Added copyright header and name to AUTHORS. (bzr r12380.1.13) --- src/util/units.cpp | 11 +++++++++++ src/util/units.h | 11 +++++++++++ 2 files changed, 22 insertions(+) (limited to 'src') diff --git a/src/util/units.cpp b/src/util/units.cpp index 6c225f717..e120207c9 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -1,3 +1,14 @@ +/* + * Inkscape Units + * + * Authors: + * Matthew Petroff + * + * Copyright (C) 2013 Matthew Petroff + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + #ifdef HAVE_CONFIG_H # include #endif diff --git a/src/util/units.h b/src/util/units.h index 64eb4a665..f275d7c3a 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -1,3 +1,14 @@ +/* + * Inkscape Units + * + * Authors: + * Matthew Petroff + * + * Copyright (C) 2013 Matthew Petroff + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + /* This is a rough draft of a global 'units' thingee, to allow dialogs and the ruler to share info about unit systems... Dunno if this is the -- cgit v1.2.3 From c99f5b02fce8b98463d7868c61bc77f8bf675665 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 17 Jul 2013 00:48:43 -0400 Subject: Fixed memory corruption introduced in a previous commit. (bzr r12380.1.14) --- src/sp-namedview.cpp | 6 +++--- src/widgets/desktop-widget.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index c7301f9bd..0833d93bf 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -552,11 +552,11 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va * doc_units. */ static Inkscape::Util::Unit px = unit_table.getUnit("px"); - Inkscape::Util::Unit const *new_unit = &px; + Inkscape::Util::Unit const *new_unit = new Inkscape::Util::Unit(px); if (value) { Inkscape::Util::Unit u = unit_table.getUnit(value); - Inkscape::Util::Unit const *const req_unit = &u; + Inkscape::Util::Unit const *const req_unit = new Inkscape::Util::Unit(u); if ( !unit_table.hasUnit(value) ) { g_warning("Unrecognized unit `%s'", value); /* fixme: Document errors should be reported in the status bar or @@ -580,7 +580,7 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va if (value) { Inkscape::Util::Unit u = unit_table.getUnit(value); - Inkscape::Util::Unit const *const req_unit = &u; + Inkscape::Util::Unit const *const req_unit = new Inkscape::Util::Unit(u); if ( !unit_table.hasUnit(value) ) { g_warning("Unrecognized unit `%s'", value); /* fixme: Document errors should be reported in the status bar or diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 57f655033..f1e4458ff 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -1672,7 +1672,7 @@ SPDesktopWidget* SPDesktopWidget::createInstance(SPNamedView *namedview) { SPDesktopWidget *dtw = static_cast(g_object_new(SP_TYPE_DESKTOP_WIDGET, NULL)); - dtw->dt2r = namedview->doc_units.factor; + dtw->dt2r = namedview->doc_units->factor; dtw->ruler_origin = Geom::Point(0,0); //namedview->gridorigin; Why was the grid origin used here? @@ -1744,7 +1744,7 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags) SPNamedView *nv=SP_NAMEDVIEW(obj); if (flags & SP_OBJECT_MODIFIED_FLAG) { - this->dt2r = nv->doc_units.factor; + this->dt2r = nv->doc_units->factor; this->ruler_origin = Geom::Point(0,0); //nv->gridorigin; Why was the grid origin used here? sp_ruler_set_unit(SP_RULER (this->vruler), nv->getDefaultMetric()); -- cgit v1.2.3 From 9711852491cd6eb2992039f286ce3ced50b83d06 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 17 Jul 2013 00:53:51 -0400 Subject: Ported "widgets/node-toolbar.cpp". (bzr r12380.1.15) --- src/widgets/node-toolbar.cpp | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/widgets/node-toolbar.cpp b/src/widgets/node-toolbar.cpp index d6de74817..50880f481 100644 --- a/src/widgets/node-toolbar.cpp +++ b/src/widgets/node-toolbar.cpp @@ -58,13 +58,14 @@ #include "../ui/tool/node-tool.h" #include "../ui/tool/multi-path-manipulator.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" +#include "util/units.h" +#include "ui/widget/unit-tracker.h" #include "../lpe-tool-context.h" #include "../sp-namedview.h" -using Inkscape::UnitTracker; +using Inkscape::UI::Widget::UnitTracker; +using Inkscape::Util::Unit; +using Inkscape::Util::Quantity; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -238,7 +239,7 @@ static void sp_node_toolbox_coord_changed(gpointer /*shape_editor*/, GObject *tb if (!tracker) { return; } - SPUnit const *unit = tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); InkNodeTool *nt = get_node_tool(); if (!nt || nt->_selected_nodes->empty()) { @@ -248,15 +249,17 @@ static void sp_node_toolbox_coord_changed(gpointer /*shape_editor*/, GObject *tb } else { gtk_action_set_sensitive(xact, TRUE); gtk_action_set_sensitive(yact, TRUE); - Geom::Coord oldx = sp_units_get_pixels(gtk_adjustment_get_value(xadj), *unit); - Geom::Coord oldy = sp_units_get_pixels(gtk_adjustment_get_value(xadj), *unit); + Inkscape::Util::UnitTable unit_table; + Unit px = unit_table.getUnit("px"); + Geom::Coord oldx = Quantity::convert(gtk_adjustment_get_value(xadj), &unit, &px); + Geom::Coord oldy = Quantity::convert(gtk_adjustment_get_value(yadj), &unit, &px); Geom::Point mid = nt->_selected_nodes->pointwiseBounds()->midpoint(); if (oldx != mid[Geom::X]) { - gtk_adjustment_set_value(xadj, sp_pixels_get_units(mid[Geom::X], *unit)); + gtk_adjustment_set_value(xadj, Quantity::convert(mid[Geom::X], &px, &unit)); } if (oldy != mid[Geom::Y]) { - gtk_adjustment_set_value(yadj, sp_pixels_get_units(mid[Geom::Y], *unit)); + gtk_adjustment_set_value(yadj, Quantity::convert(mid[Geom::Y], &px, &unit)); } } @@ -272,11 +275,14 @@ static void sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::D if (!tracker) { return; } - SPUnit const *unit = tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); + + Inkscape::Util::UnitTable unit_table; + Unit px = unit_table.getUnit("px"); if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { prefs->setDouble(Glib::ustring("/tools/nodes/") + (d == Geom::X ? "x" : "y"), - sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit)); + Quantity::convert(gtk_adjustment_get_value(adj), &unit, &px)); } // quit if run by the attr_changed listener @@ -289,7 +295,7 @@ static void sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::D InkNodeTool *nt = get_node_tool(); if (nt && !nt->_selected_nodes->empty()) { - double val = sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit); + double val = Quantity::convert(gtk_adjustment_get_value(adj), &unit, &px); double oldval = nt->_selected_nodes->pointwiseBounds()->midpoint()[d]; Geom::Point delta(0,0); delta[d] = val - oldval; @@ -339,8 +345,9 @@ static void sp_node_toolbox_sel_modified(Inkscape::Selection *selection, guint / void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { - UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); - //tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); + UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); + Unit doc_units = *sp_desktop_namedview(desktop)->doc_units; + tracker->setActiveUnit(&doc_units); g_object_set_data( holder, "tracker", tracker ); Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); -- cgit v1.2.3 From 7af2b98550f3389d08773addca07cd943ec6e2bb Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 17 Jul 2013 01:00:49 -0400 Subject: Temporary fixes/kludges. (bzr r12380.1.16) --- src/helper/unit-tracker.cpp | 4 ++-- src/ui/widget/selected-style.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/helper/unit-tracker.cpp b/src/helper/unit-tracker.cpp index 609c2f292..7345660e6 100644 --- a/src/helper/unit-tracker.cpp +++ b/src/helper/unit-tracker.cpp @@ -94,7 +94,7 @@ SPUnit const* UnitTracker::getActiveUnit() const void UnitTracker::setActiveUnit( SPUnit const *unit ) { - if ( unit ) { + /*if ( unit ) { GtkTreeIter iter; int index = 0; gboolean found = gtk_tree_model_get_iter_first( GTK_TREE_MODEL(_store), &iter ); @@ -109,7 +109,7 @@ void UnitTracker::setActiveUnit( SPUnit const *unit ) found = gtk_tree_model_iter_next( GTK_TREE_MODEL(_store), &iter ); index++; } - } + }*/ } void UnitTracker::addAdjustment( GtkAdjustment* adj ) diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index d6e2406c9..102132158 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -477,6 +477,7 @@ SelectedStyle::setDesktop(SPDesktop *desktop) )); //_sw_unit = const_cast(sp_desktop_namedview(desktop)->doc_units); + _sw_unit = const_cast(&sp_unit_get_by_id(SP_UNIT_PX)); // Set the doc default unit active in the units list gint length = g_slist_length(_unit_mis); -- cgit v1.2.3 From 63071dedd65d63cfac2041399dab0191e3753b42 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 17 Jul 2013 01:31:18 -0400 Subject: Fixed botched merge. (bzr r12380.1.18) --- src/util/units.cpp | 5 ----- src/util/units.h | 10 ++-------- 2 files changed, 2 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/util/units.cpp b/src/util/units.cpp index f6350d569..d485f6aef 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -196,11 +196,6 @@ int Unit::metric() const { return 0; } -/** - * Initializes the unit tables and identifies the primary unit types. - * - * The primary unit's conversion factor is required to be 1.00 - */ UnitTable::UnitTable() { // if we swich to the xml file, don't forget to force locale to 'C' diff --git a/src/util/units.h b/src/util/units.h index ead49d3b4..c6f124203 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -65,20 +65,14 @@ class Unit { */ int defaultDigits() const; + bool compatibleWith(const Unit *u) const; + UnitType type; double factor; Glib::ustring name; Glib::ustring name_plural; Glib::ustring abbr; Glib::ustring description; - - UnitType type; - - double factor; - - bool isAbsolute() const { return type != UNIT_TYPE_DIMENSIONLESS; } - int defaultDigits() const; - bool compatibleWith(const Unit *u) const; friend bool operator== (const Unit &u1, const Unit &u2); friend bool operator!= (const Unit &u1, const Unit &u2); -- cgit v1.2.3 From 10067e713619333f20201c7d01c99e302464f6b2 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 17 Jul 2013 09:53:18 -0400 Subject: Port remaining files away from "helper/unit-tracker.h". (bzr r12380.1.19) --- src/widgets/desktop-widget.cpp | 8 +++--- src/widgets/lpe-toolbar.cpp | 21 +++++++------- src/widgets/rect-toolbar.cpp | 32 +++++++++++++--------- src/widgets/select-toolbar.cpp | 62 +++++++++++++++++++++++------------------- src/widgets/toolbox.cpp | 3 -- 5 files changed, 68 insertions(+), 58 deletions(-) (limited to 'src') diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index fbef9bbce..1c6852f35 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -43,8 +43,8 @@ #include "file.h" #include "helper/action.h" #include "helper/action-context.h" -#include "helper/units.h" -#include "helper/unit-tracker.h" +#include "util/units.h" +#include "ui/widget/unit-tracker.h" #include "inkscape-private.h" #include "interface.h" #include "macros.h" @@ -79,7 +79,7 @@ using Inkscape::round; #endif -using Inkscape::UnitTracker; +using Inkscape::UI::Widget::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::UI::ToolboxFactory; using ege::AppearTimeTracker; @@ -1780,7 +1780,7 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags) if (tracker == NULL) // it's null when inkscape is first opened continue; - // tracker->setActiveUnit( nv->doc_units ); + tracker->setActiveUnit( nv->doc_units ); } // grandchildren } // if child is a container } // children diff --git a/src/widgets/lpe-toolbar.cpp b/src/widgets/lpe-toolbar.cpp index 65bb46e32..55cce90cd 100644 --- a/src/widgets/lpe-toolbar.cpp +++ b/src/widgets/lpe-toolbar.cpp @@ -57,9 +57,8 @@ #include "../ui/icon-names.h" #include "../helper/action.h" #include "../helper/action-context.h" -#include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" +#include "util/units.h" +#include "ui/widget/unit-tracker.h" #include "../pen-context.h" #include "../sp-namedview.h" #include "../tools-switch.h" @@ -67,7 +66,9 @@ #include "../live_effects/lpe-angle_bisector.h" #include "../lpe-tool-context.h" -using Inkscape::UnitTracker; +using Inkscape::UI::Widget::UnitTracker; +using Inkscape::Util::Unit; +using Inkscape::Util::Quantity; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; @@ -197,9 +198,9 @@ static void lpetool_toggle_show_measuring_info(GtkToggleAction *act, GObject *tb static void lpetool_unit_changed(GtkAction* /*act*/, GObject* tbl) { UnitTracker* tracker = reinterpret_cast(g_object_get_data(tbl, "tracker")); - SPUnit const *unit = tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt("/tools/lpetool/unitid", unit->unit_id); + prefs->setString("/tools/lpetool/unit", unit.abbr); SPDesktop *desktop = static_cast(g_object_get_data( tbl, "desktop" )); if (SP_IS_LPETOOL_CONTEXT(desktop->event_context)) { @@ -295,13 +296,13 @@ static void lpetool_open_lpe_dialog(GtkToggleAction *act, gpointer data) void sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { - UnitTracker* tracker = new UnitTracker(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); - //tracker->setActiveUnit(sp_desktop_namedview(desktop)->doc_units); + UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); + tracker->setActiveUnit(sp_desktop_namedview(desktop)->doc_units); g_object_set_data(holder, "tracker", tracker); - SPUnit const *unit = tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt("/tools/lpetool/unitid", unit->unit_id); + prefs->setString("/tools/lpetool/unit", unit.abbr); /** Automatically create a list of LPEs that get added to the toolbar **/ { diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 5fa96289f..359bc48e0 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -54,17 +54,19 @@ #include "ui/uxmanager.h" #include "../ui/icon-names.h" #include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" +#include "util/units.h" +#include "ui/widget/unit-tracker.h" #include "../pen-context.h" #include "../sp-namedview.h" #include "../sp-rect.h" -using Inkscape::UnitTracker; +using Inkscape::UI::Widget::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; using Inkscape::UI::PrefPusher; +using Inkscape::Util::Unit; +using Inkscape::Util::Quantity; //######################## @@ -91,12 +93,14 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * SPDesktop *desktop = static_cast(g_object_get_data( tbl, "desktop" )); UnitTracker* tracker = reinterpret_cast(g_object_get_data( tbl, "tracker" )); - SPUnit const *unit = tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); + Inkscape::Util::UnitTable unit_table; + Unit const px = unit_table.getUnit("px"); if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble(Glib::ustring("/tools/shapes/rect/") + value_name, - sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit)); + Quantity::convert(gtk_adjustment_get_value(adj), &unit, &px)); } // quit if run by the attr_changed listener @@ -113,7 +117,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * if (SP_IS_RECT(items->data)) { if (gtk_adjustment_get_value(adj) != 0) { setter(SP_RECT(items->data), - sp_units_get_pixels(gtk_adjustment_get_value(adj), *unit)); + Quantity::convert(gtk_adjustment_get_value(adj), &unit, &px)); } else { SP_OBJECT(items->data)->getRepr()->setAttribute(value_name, NULL); } @@ -184,32 +188,34 @@ static void rect_tb_event_attr_changed(Inkscape::XML::Node * /*repr*/, gchar con g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); UnitTracker* tracker = reinterpret_cast( g_object_get_data( tbl, "tracker" ) ); - SPUnit const *unit = tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); + Inkscape::Util::UnitTable unit_table; + Unit const px = unit_table.getUnit("px"); gpointer item = g_object_get_data( tbl, "item" ); if (item && SP_IS_RECT(item)) { { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "rx" ) ); gdouble rx = sp_rect_get_visible_rx(SP_RECT(item)); - gtk_adjustment_set_value(adj, sp_pixels_get_units(rx, *unit)); + gtk_adjustment_set_value(adj, Quantity::convert(rx, &px, &unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "ry" ) ); gdouble ry = sp_rect_get_visible_ry(SP_RECT(item)); - gtk_adjustment_set_value(adj, sp_pixels_get_units(ry, *unit)); + gtk_adjustment_set_value(adj, Quantity::convert(ry, &px, &unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "width" ) ); gdouble width = sp_rect_get_visible_width (SP_RECT(item)); - gtk_adjustment_set_value(adj, sp_pixels_get_units(width, *unit)); + gtk_adjustment_set_value(adj, Quantity::convert(width, &px, &unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "height" ) ); gdouble height = sp_rect_get_visible_height (SP_RECT(item)); - gtk_adjustment_set_value(adj, sp_pixels_get_units(height, *unit)); + gtk_adjustment_set_value(adj, Quantity::convert(height, &px, &unit)); } } @@ -301,10 +307,10 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje } // rx/ry units menu: create - UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); + UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); //tracker->addUnit( SP_UNIT_PERCENT, 0 ); // fixme: add % meaning per cent of the width/height - //tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); + tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); g_object_set_data( holder, "tracker", tracker ); /* W */ diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index c0018751c..ffab3deab 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -39,8 +39,7 @@ #include #include "helper/action.h" #include "helper/action-context.h" -#include "helper/unit-menu.h" -#include "helper/units.h" +#include "util/units.h" #include "inkscape.h" #include "verbs.h" #include "selection.h" @@ -48,7 +47,7 @@ #include "sp-item-transform.h" #include "message-stack.h" #include "display/sp-canvas.h" -#include "helper/unit-tracker.h" +#include "ui/widget/unit-tracker.h" #include "ege-adjustment-action.h" #include "ege-output-action.h" #include "ink-action.h" @@ -56,7 +55,9 @@ #include "ui/icon-names.h" #include "select-toolbar.h" -using Inkscape::UnitTracker; +using Inkscape::UI::Widget::UnitTracker; +using Inkscape::Util::Unit; +using Inkscape::Util::Quantity; using Inkscape::DocumentUndo; static void @@ -78,7 +79,7 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel) Geom::OptRect const bbox(sel->bounds(bbox_type)); if ( bbox ) { UnitTracker *tracker = reinterpret_cast(g_object_get_data(G_OBJECT(spw), "tracker")); - SPUnit const &unit = *tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); struct { char const *key; double val; } const keyval[] = { { "X", bbox->min()[X] }, @@ -87,17 +88,19 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel) { "height", bbox->dimensions()[Y] } }; - if (unit.base == SP_UNIT_DIMENSIONLESS) { - double const val = 1. / unit.unittobase; + if (unit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) { + double const val = unit.factor; for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) { GtkAdjustment *a = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(spw), keyval[i].key)); gtk_adjustment_set_value(a, val); tracker->setFullVal( a, keyval[i].val ); } } else { + Inkscape::Util::UnitTable unit_table; + Unit px = unit_table.getUnit("px"); for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) { GtkAdjustment *a = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(spw), keyval[i].key)); - gtk_adjustment_set_value(a, sp_pixels_get_units(keyval[i].val, unit)); + gtk_adjustment_set_value(a, Quantity::convert(keyval[i].val, &px, &unit)); } } } @@ -183,28 +186,31 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw) gdouble y1 = 0; gdouble xrel = 0; gdouble yrel = 0; - SPUnit const &unit = *tracker->getActiveUnit(); + Unit const unit = tracker->getActiveUnit(); GtkAdjustment* a_x = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "X" ) ); GtkAdjustment* a_y = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "Y" ) ); GtkAdjustment* a_w = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "width" ) ); GtkAdjustment* a_h = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "height" ) ); - if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) { - x0 = sp_units_get_pixels (gtk_adjustment_get_value (a_x), unit); - y0 = sp_units_get_pixels (gtk_adjustment_get_value (a_y), unit); - x1 = x0 + sp_units_get_pixels (gtk_adjustment_get_value (a_w), unit); - xrel = sp_units_get_pixels (gtk_adjustment_get_value (a_w), unit) / bbox_user->dimensions()[Geom::X]; - y1 = y0 + sp_units_get_pixels (gtk_adjustment_get_value (a_h), unit); - yrel = sp_units_get_pixels (gtk_adjustment_get_value (a_h), unit) / bbox_user->dimensions()[Geom::Y]; + Inkscape::Util::UnitTable unit_table; + Unit px = unit_table.getUnit("px"); + + if (unit.type == Inkscape::Util::UNIT_TYPE_LINEAR) { + x0 = Quantity::convert(gtk_adjustment_get_value(a_x), &unit, &px); + y0 = Quantity::convert(gtk_adjustment_get_value(a_y), &unit, &px); + x1 = x0 + Quantity::convert(gtk_adjustment_get_value(a_w), &unit, &px); + xrel = Quantity::convert(gtk_adjustment_get_value(a_w), &unit, &px) / bbox_user->dimensions()[Geom::X]; + y1 = y0 + Quantity::convert(gtk_adjustment_get_value(a_h), &unit, &px);; + yrel = Quantity::convert(gtk_adjustment_get_value(a_h), &unit, &px) / bbox_user->dimensions()[Geom::Y]; } else { - double const x0_propn = gtk_adjustment_get_value (a_x) * unit.unittobase; + double const x0_propn = gtk_adjustment_get_value (a_x) * unit.factor; x0 = bbox_user->min()[Geom::X] * x0_propn; - double const y0_propn = gtk_adjustment_get_value (a_y) * unit.unittobase; + double const y0_propn = gtk_adjustment_get_value (a_y) * unit.factor; y0 = y0_propn * bbox_user->min()[Geom::Y]; - xrel = gtk_adjustment_get_value (a_w) * unit.unittobase; + xrel = gtk_adjustment_get_value (a_w) * unit.factor; x1 = x0 + xrel * bbox_user->dimensions()[Geom::X]; - yrel = gtk_adjustment_get_value (a_h) * unit.unittobase; + yrel = gtk_adjustment_get_value (a_h) * unit.factor; y1 = y0 + yrel * bbox_user->dimensions()[Geom::Y]; } @@ -225,11 +231,11 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw) double sv = fabs(y1 - bbox_user->max()[Geom::Y]); // unless the unit is %, convert the scales and moves to the unit - if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) { - mh = sp_pixels_get_units (mh, unit); - sh = sp_pixels_get_units (sh, unit); - mv = sp_pixels_get_units (mv, unit); - sv = sp_pixels_get_units (sv, unit); + if (unit.type == Inkscape::Util::UNIT_TYPE_LINEAR) { + mh = Quantity::convert(mh, &px, &unit); + sh = Quantity::convert(sh, &px, &unit); + mv = Quantity::convert(mv, &px, &unit); + sv = Quantity::convert(sv, &px, &unit); } // do the action only if one of the scales/moves is greater than half the last significant @@ -488,9 +494,9 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb gtk_container_add(GTK_CONTAINER(spw), vb); // Create the units menu. - UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); - tracker->addUnit( SP_UNIT_PERCENT, 0 ); - //tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); + UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); + //tracker->addUnit( SP_UNIT_PERCENT, 0 ); + tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); g_object_set_data( G_OBJECT(spw), "tracker", tracker ); g_signal_connect( G_OBJECT(spw), "destroy", G_CALLBACK(destroy_tracker), spw ); diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index ca593976f..687f62420 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -50,8 +50,6 @@ #include "../helper/action.h" #include "../helper/action-context.h" #include "../helper/unit-menu.h" -#include "../helper/units.h" -#include "../helper/unit-tracker.h" #include "icon.h" #include "../ink-action.h" #include "../ink-comboboxentry-action.h" @@ -101,7 +99,6 @@ //#define DEBUG_TEXT -using Inkscape::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::PrefPusher; -- cgit v1.2.3 From 2a882b8a362a56dc24f94b00d2034e9abc848585 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 17 Jul 2013 10:02:56 -0400 Subject: Removed "helper/unit-tracker.*". (bzr r12380.1.20) --- src/helper/Makefile_insert | 2 - src/helper/unit-tracker.cpp | 267 -------------------------------------------- src/helper/unit-tracker.h | 75 ------------- 3 files changed, 344 deletions(-) delete mode 100644 src/helper/unit-tracker.cpp delete mode 100644 src/helper/unit-tracker.h (limited to 'src') diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index 790d87b14..0008936dd 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -20,8 +20,6 @@ ink_common_sources += \ helper/sp-marshal.h \ helper/unit-menu.cpp \ helper/unit-menu.h \ - helper/unit-tracker.cpp \ - helper/unit-tracker.h \ helper/units.cpp \ helper/units.h \ helper/window.cpp \ diff --git a/src/helper/unit-tracker.cpp b/src/helper/unit-tracker.cpp deleted file mode 100644 index 7345660e6..000000000 --- a/src/helper/unit-tracker.cpp +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Inkscape::UnitTracker - Simple mediator to synchronize changes to a set - * of possible units - * - * Authors: - * Jon A. Cruz - * - * Copyright (C) 2007 Jon A. Cruz - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include - -#include "unit-tracker.h" -#include "ege-select-one-action.h" - -namespace Inkscape { - -enum { - COLUMN_STRING, - COLUMN_SPUNIT, - N_COLUMNS -}; - -UnitTracker::UnitTracker( guint bases ) : - _active(0), - _isUpdating(false), - _activeUnit(0), - _store(0), - _unitList(0), - _actionList(0), - _adjList(0), - _priorValues() -{ - _store = gtk_list_store_new( N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER ); - setBase( bases ); -} - -UnitTracker::~UnitTracker() -{ - if ( _unitList ) { - sp_unit_free_list( _unitList ); - } - - // Unhook weak references to GtkActions - while ( _actionList ) { - g_signal_handlers_disconnect_by_func( G_OBJECT(_actionList->data), (gpointer)_unitChangedCB, this ); - g_object_weak_unref( G_OBJECT(_actionList->data), _actionFinalizedCB, this ); - _actionList = g_slist_delete_link( _actionList, _actionList ); - } - - // Unhook wek references to GtkAdjustments - while ( _adjList ) { - g_object_weak_unref( G_OBJECT(_adjList->data), _adjustmentFinalizedCB, this ); - _adjList = g_slist_delete_link( _adjList, _adjList ); - } -} - -void UnitTracker::setBase( guint bases ) -{ - GtkTreeIter iter; - _unitList = sp_unit_get_list( bases ); - for ( GSList* cur = _unitList; cur; cur = g_slist_next(cur) ) { - SPUnit* unit = static_cast(cur->data); - gtk_list_store_append( _store, &iter ); - gtk_list_store_set( _store, &iter, COLUMN_STRING, unit->abbr, COLUMN_SPUNIT, unit, -1 ); - } - gint count = gtk_tree_model_iter_n_children( GTK_TREE_MODEL(_store), 0 ); - if ( (count > 0) && (_active > count) ) { - _setActive( count - 1 ); - } else { - _setActive( _active ); - } -} - -void UnitTracker::addUnit( SPUnitId id, gint index ) -{ - GtkTreeIter iter; - const SPUnit* percentUnit = &sp_unit_get_by_id( id ); - gtk_list_store_insert( _store, &iter, index ); - gtk_list_store_set( _store, &iter, COLUMN_STRING, percentUnit->abbr, COLUMN_SPUNIT, percentUnit, -1 ); -} - -bool UnitTracker::isUpdating() const -{ - return _isUpdating; -} - -SPUnit const* UnitTracker::getActiveUnit() const -{ - return _activeUnit; -} - -void UnitTracker::setActiveUnit( SPUnit const *unit ) -{ - /*if ( unit ) { - GtkTreeIter iter; - int index = 0; - gboolean found = gtk_tree_model_get_iter_first( GTK_TREE_MODEL(_store), &iter ); - while ( found ) { - SPUnit* storedUnit = 0; - gtk_tree_model_get( GTK_TREE_MODEL(_store), &iter, COLUMN_SPUNIT, &storedUnit, -1 ); - if ( storedUnit && (storedUnit->unit_id == unit->unit_id) ) { - _setActive(index); - break; - } - - found = gtk_tree_model_iter_next( GTK_TREE_MODEL(_store), &iter ); - index++; - } - }*/ -} - -void UnitTracker::addAdjustment( GtkAdjustment* adj ) -{ - if ( !g_slist_find( _adjList, adj ) ) { - g_object_weak_ref( G_OBJECT(adj), _adjustmentFinalizedCB, this ); - _adjList = g_slist_append( _adjList, adj ); - } -} - -void UnitTracker::setFullVal( GtkAdjustment* adj, gdouble val ) -{ - _priorValues[adj] = val; -} - -GtkAction* UnitTracker::createAction( gchar const* name, gchar const* label, gchar const* tooltip ) -{ - EgeSelectOneAction* act1 = ege_select_one_action_new( name, label, tooltip, NULL, GTK_TREE_MODEL(_store) ); - ege_select_one_action_set_label_column( act1, COLUMN_STRING ); - if ( _active ) { - ege_select_one_action_set_active( act1, _active ); - } - - ege_select_one_action_set_appearance( act1, "minimal" ); - g_object_weak_ref( G_OBJECT(act1), _actionFinalizedCB, this ); - g_signal_connect( G_OBJECT(act1), "changed", G_CALLBACK( _unitChangedCB ), this ); - _actionList = g_slist_append( _actionList, act1 ); - - return GTK_ACTION(act1); -} - -void UnitTracker::_unitChangedCB( GtkAction* action, gpointer data ) -{ - if ( action && data ) { - EgeSelectOneAction* act = EGE_SELECT_ONE_ACTION(action); - gint active = ege_select_one_action_get_active( act ); - UnitTracker* self = reinterpret_cast(data); - self->_setActive(active); - } -} - -void UnitTracker::_actionFinalizedCB( gpointer data, GObject *where_the_object_was ) -{ - if ( data && where_the_object_was ) { - UnitTracker* self = reinterpret_cast(data); - self->_actionFinalized( where_the_object_was ); - } -} - -void UnitTracker::_adjustmentFinalizedCB( gpointer data, GObject *where_the_object_was ) -{ - if ( data && where_the_object_was ) { - UnitTracker* self = reinterpret_cast(data); - self->_adjustmentFinalized( where_the_object_was ); - } -} - -void UnitTracker::_actionFinalized( GObject *where_the_object_was ) -{ - GSList* target = g_slist_find( _actionList, where_the_object_was ); - if ( target ) { - _actionList = g_slist_remove( _actionList, where_the_object_was ); - } else { - g_warning("Received a finalization callback for unknown object %p", where_the_object_was ); - } -} - -void UnitTracker::_adjustmentFinalized( GObject *where_the_object_was ) -{ - GSList* target = g_slist_find( _adjList, where_the_object_was ); - if ( target ) { - _adjList = g_slist_remove( _adjList, where_the_object_was ); - } else { - g_warning("Received a finalization callback for unknown object %p", where_the_object_was ); - } -} - -void UnitTracker::_setActive( gint active ) -{ - if ( active != _active || (_activeUnit == 0) ) { - gint oldActive = _active; - - GtkTreeIter iter; - gboolean found = gtk_tree_model_iter_nth_child( GTK_TREE_MODEL(_store), &iter, NULL, oldActive ); - if ( found ) { - SPUnit* unit = 0; - gtk_tree_model_get( GTK_TREE_MODEL(_store), &iter, COLUMN_SPUNIT, &unit, -1 ); - - found = gtk_tree_model_iter_nth_child( GTK_TREE_MODEL(_store), &iter, NULL, active ); - if ( found ) { - SPUnit* newUnit = 0; - gtk_tree_model_get( GTK_TREE_MODEL(_store), &iter, COLUMN_SPUNIT, &newUnit, -1 ); - _activeUnit = newUnit; - - if ( _adjList ) { - _fixupAdjustments( unit, newUnit ); - } - - } else { - g_warning("Did not find new unit"); - } - } else { - g_warning("Did not find old unit"); - } - - _active = active; - - for ( GSList* cur = _actionList; cur; cur = g_slist_next(cur) ) { - if ( IS_EGE_SELECT_ONE_ACTION( cur->data ) ) { - EgeSelectOneAction* act = EGE_SELECT_ONE_ACTION( cur->data ); - ege_select_one_action_set_active( act, active ); - } - } - } -} - -void UnitTracker::_fixupAdjustments( SPUnit const* oldUnit, SPUnit const *newUnit ) -{ - _isUpdating = true; - for ( GSList* cur = _adjList; cur; cur = g_slist_next(cur) ) { - GtkAdjustment* adj = GTK_ADJUSTMENT(cur->data); - gdouble oldVal = gtk_adjustment_get_value(adj); - gdouble val = oldVal; - - if ((oldUnit->base == SP_UNIT_ABSOLUTE || oldUnit->base == SP_UNIT_DEVICE) - && (newUnit->base == SP_UNIT_DIMENSIONLESS)) - { - val = 1.0 / newUnit->unittobase; - _priorValues[adj] = sp_units_get_pixels( oldVal, *oldUnit ); - } else if ((oldUnit->base == SP_UNIT_DIMENSIONLESS) - && (newUnit->base == SP_UNIT_ABSOLUTE || newUnit->base == SP_UNIT_DEVICE)) { - if ( _priorValues.find(adj) != _priorValues.end() ) { - val = sp_pixels_get_units( _priorValues[adj], *newUnit ); - } - } else { - val = sp_convert_distance_full( oldVal, *oldUnit, *newUnit ); - } - - gtk_adjustment_set_value( adj, val ); - } - _isUpdating = false; -} - -} - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/helper/unit-tracker.h b/src/helper/unit-tracker.h deleted file mode 100644 index a15a0a6ca..000000000 --- a/src/helper/unit-tracker.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Inkscape::UnitTracker - Simple mediator to synchronize changes to a set - * of possible units - * - * Authors: - * Jon A. Cruz - * - * Copyright (C) 2007 Jon A. Cruz - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifndef SEEN_INKSCAPE_UNIT_TRACKER_H -#define SEEN_INKSCAPE_UNIT_TRACKER_H - -#include - -#include - -#include "helper/units.h" - -namespace Inkscape { - -class UnitTracker -{ -public: - UnitTracker( guint bases = (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE) ); - virtual ~UnitTracker(); - - void setBase( guint bases ); // SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE - void addUnit( SPUnitId id, gint index ); - - bool isUpdating() const; - - void setActiveUnit( SPUnit const *unit ); - SPUnit const* getActiveUnit() const; - - void addAdjustment( GtkAdjustment* adj ); - void setFullVal( GtkAdjustment* adj, gdouble val ); - - GtkAction* createAction( gchar const* name, gchar const* label, gchar const* tooltip ); - -private: - static void _unitChangedCB( GtkAction* action, gpointer data ); - static void _actionFinalizedCB( gpointer data, GObject *where_the_object_was ); - static void _adjustmentFinalizedCB( gpointer data, GObject *where_the_object_was ); - void _setActive( gint index ); - void _fixupAdjustments( SPUnit const* oldUnit, SPUnit const *newUnit ); - void _actionFinalized( GObject *where_the_object_was ); - void _adjustmentFinalized( GObject *where_the_object_was ); - - gint _active; - bool _isUpdating; - SPUnit* _activeUnit; - GtkListStore* _store; - GSList* _unitList; - GSList* _actionList; - GSList* _adjList; - std::map _priorValues; -}; - -} - -#endif // SEEN_INKSCAPE_UNIT_TRACKER_H - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3 From c60177d361dd435e58caa902a395fa21c9415f51 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 17 Jul 2013 18:12:31 -0400 Subject: Removed "helper/unit.*" dependency from "ui/widget/registered-widget.*". (bzr r12380.1.21) --- src/display/canvas-axonomgrid.cpp | 2 +- src/display/canvas-grid.cpp | 2 +- src/live_effects/parameter/unit.cpp | 2 +- src/ui/widget/registered-widget.cpp | 5 ++--- src/ui/widget/registered-widget.h | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 1eadd3fd2..59d2bb36d 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -419,7 +419,7 @@ _wr.setUpdating (false); attach_all (*table, widget_array, sizeof(widget_array)); // set widget values - _rumg->setUnit (gridunit); + _rumg->setUnit (gridunit->abbr); gdouble val; val = origin[Geom::X]; diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index ee5ad0945..9fbb5f907 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -802,7 +802,7 @@ CanvasXYGrid::newSpecificWidget() attach_all (*table, widget_array, sizeof(widget_array)); // set widget values - _rumg->setUnit (gridunit); + _rumg->setUnit (gridunit->abbr); gdouble val; val = origin[Geom::X]; diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp index 602d806a0..fffbabb1d 100644 --- a/src/live_effects/parameter/unit.cpp +++ b/src/live_effects/parameter/unit.cpp @@ -74,7 +74,7 @@ UnitParam::param_newWidget() param_effect->getRepr(), param_effect->getSPDoc())); - unit_menu->setUnit(unit); + unit_menu->setUnit(unit->abbr); unit_menu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change unit parameter")); return dynamic_cast (unit_menu); diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index ea2bac867..ae6a7d1e0 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -27,7 +27,6 @@ #include "ui/widget/random.h" #include "widgets/spinbutton-events.h" -#include "helper/units.h" #include "xml/repr.h" #include "svg/svg-color.h" #include "svg/stringstream.h" @@ -118,9 +117,9 @@ RegisteredUnitMenu::RegisteredUnitMenu (const Glib::ustring& label, const Glib:: } void -RegisteredUnitMenu::setUnit (const SPUnit* unit) +RegisteredUnitMenu::setUnit (Glib::ustring unit) { - getUnitMenu()->setUnit (sp_unit_get_abbreviation (unit)); + getUnitMenu()->setUnit(unit); } void diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index fa35b815e..491ca6050 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -166,7 +166,7 @@ public: Inkscape::XML::Node* repr_in = NULL, SPDocument *doc_in = NULL ); - void setUnit (const SPUnit*); + void setUnit (const Glib::ustring); Unit getUnit() const { return static_cast(_widget)->getUnit(); }; UnitMenu* getUnitMenu() const { return static_cast(_widget); }; sigc::connection _changed_connection; -- cgit v1.2.3 From 64e66e01886be870fc9615e65416097e64ad544b Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 17 Jul 2013 18:13:19 -0400 Subject: Ported "ui/dialog/export.*". (bzr r12380.1.22) --- src/ui/dialog/export.cpp | 74 ++++++++++++++++++------------------------------ src/ui/dialog/export.h | 8 +++++- 2 files changed, 35 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 25300cfc0..61fb6e4ee 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -48,8 +48,8 @@ #include #include -#include "helper/unit-menu.h" -#include "helper/units.h" +#include "ui/widget/unit-menu.h" +#include "util/units.h" #include "unit-constants.h" #include "helper/window.h" #include "inkscape-private.h" @@ -198,10 +198,13 @@ Export::Export (void) : /* Units box */ /* gets added to the vbox later, but the unit selector is needed earlier than that */ - unit_selector = Glib::wrap(sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE)); + unit_selector = new Inkscape::UI::Widget::UnitMenu(); + unit_selector->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR); + unitChangedConn = unit_selector->signal_changed().connect(sigc::mem_fun(*this, &Export::onUnitChanged)); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; - //if (desktop) - // sp_unit_selector_set_unit (SP_UNIT_SELECTOR(unit_selector->gobj()), sp_desktop_namedview(desktop)->doc_units); + if (desktop) + unit_selector->setUnit(sp_desktop_namedview(desktop)->doc_units->abbr); unitbox.pack_end(*unit_selector, false, false, 0); unitbox.pack_end(units_label, false, false, 3); @@ -226,28 +229,28 @@ Export::Export (void) : t->set_col_spacings (4); #endif - x0_adj = createSpinbutton ( "x0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(), + x0_adj = createSpinbutton ( "x0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(), t, 0, 0, _("_x0:"), "", EXPORT_COORD_PRECISION, 1, &Export::onAreaX0Change); - x1_adj = createSpinbutton ( "x1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(), + x1_adj = createSpinbutton ( "x1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(), t, 0, 1, _("x_1:"), "", EXPORT_COORD_PRECISION, 1, &Export::onAreaX1Change); width_adj = createSpinbutton ( "width", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0, - unit_selector->gobj(), t, 0, 2, _("Wid_th:"), "", EXPORT_COORD_PRECISION, 1, + ((Gtk::Widget*) unit_selector)->gobj(), t, 0, 2, _("Wid_th:"), "", EXPORT_COORD_PRECISION, 1, &Export::onAreaWidthChange); - y0_adj = createSpinbutton ( "y0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(), + y0_adj = createSpinbutton ( "y0", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(), t, 2, 0, _("_y0:"), "", EXPORT_COORD_PRECISION, 1, &Export::onAreaY0Change); - y1_adj = createSpinbutton ( "y1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, unit_selector->gobj(), + y1_adj = createSpinbutton ( "y1", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, ((Gtk::Widget*) unit_selector)->gobj(), t, 2, 1, _("y_1:"), "", EXPORT_COORD_PRECISION, 1, &Export::onAreaY1Change); height_adj = createSpinbutton ( "height", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0, - unit_selector->gobj(), t, 2, 2, _("Hei_ght:"), "", EXPORT_COORD_PRECISION, 1, + ((Gtk::Widget*) unit_selector)->gobj(), t, 2, 2, _("Hei_ght:"), "", EXPORT_COORD_PRECISION, 1, &Export::onAreaHeightChange); area_box.pack_start(togglebox, false, false, 3); @@ -496,9 +499,6 @@ Gtk::Adjustment * Export::createSpinbutton( gchar const * /*key*/, float val, fl #else Gtk::Adjustment *adj = new Gtk::Adjustment ( val, min, max, step, page, 0 ); #endif - if (us) { - sp_unit_selector_add_adjustment ( SP_UNIT_SELECTOR (us), GTK_ADJUSTMENT (adj->gobj()) ); - } int pos = 0; Gtk::Label *l = NULL; @@ -979,6 +979,12 @@ Glib::ustring Export::absolutize_path_from_document_location (SPDocument *doc, c return path; } +// Called when unit is changed +void Export::onUnitChanged() +{ + onAreaToggled(); +} + void Export::onHideExceptSelected () { prefs->setBool("/dialogs/export/hideexceptselected/value", hide_export.get_active()); @@ -1507,10 +1513,6 @@ void Export::areaXChange (Gtk::Adjustment *adj) return; } - if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) { - return; - } - update = true; x0 = getValuePx(x0_adj); @@ -1554,10 +1556,6 @@ void Export::areaYChange (Gtk::Adjustment *adj) return; } - if (sp_unit_selector_update_test (SP_UNIT_SELECTOR(unit_selector->gobj()))) { - return; - } - update = true; y0 = getValuePx(y0_adj); @@ -1597,10 +1595,6 @@ void Export::onAreaWidthChange() return; } - if (sp_unit_selector_update_test(reinterpret_cast(unit_selector->gobj()))) { - return; - } - update = true; float x0 = getValuePx(x0_adj); @@ -1630,10 +1624,6 @@ void Export::onAreaHeightChange() return; } - if (sp_unit_selector_update_test(reinterpret_cast(unit_selector->gobj()))) { - return; - } - update = true; float y0 = getValuePx(y0_adj); @@ -1709,10 +1699,6 @@ void Export::onBitmapWidthChange () return; } - if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) { - return; - } - update = true; x0 = getValuePx(x0_adj); @@ -1743,10 +1729,6 @@ void Export::onBitmapHeightChange () return; } - if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) { - return; - } - update = true; y0 = getValuePx(y0_adj); @@ -1803,10 +1785,6 @@ void Export::onExportXdpiChange() return; } - if (sp_unit_selector_update_test(SP_UNIT_SELECTOR(unit_selector->gobj()))) { - return; - } - update = true; x0 = getValuePx(x0_adj); @@ -1905,9 +1883,11 @@ void Export::setValuePx(Glib::RefPtr& adj, double val) void Export::setValuePx( Gtk::Adjustment *adj, double val) #endif { - const SPUnit *unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unit_selector->gobj()) ); + const Unit unit = unit_selector->getUnit(); + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit px = unit_table.getUnit("px"); - setValue(adj, sp_pixels_get_units (val, *unit)); + setValue(adj, Inkscape::Util::Quantity::convert(val, &px, &unit)); return; } @@ -1955,9 +1935,11 @@ float Export::getValuePx( Gtk::Adjustment *adj ) #endif { float value = getValue( adj); - const SPUnit *unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unit_selector->gobj())); + const Unit unit = unit_selector->getUnit(); + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit px = unit_table.getUnit("px"); - return sp_units_get_pixels (value, *unit); + return Inkscape::Util::Quantity::convert(value, &unit, &px); } // end of sp_export_value_get_px() /** diff --git a/src/ui/dialog/export.h b/src/ui/dialog/export.h index b10c98fd2..f324f5dc5 100644 --- a/src/ui/dialog/export.h +++ b/src/ui/dialog/export.h @@ -171,6 +171,11 @@ private: void areaYChange ( Gtk::Adjustment *adj); #endif + /** + * Unit changed callback + */ + void onUnitChanged(); + /** * Hide except selected callback */ @@ -330,7 +335,7 @@ private: /* Unit selector widgets */ Gtk::HBox unitbox; - Gtk::Widget* unit_selector; + Inkscape::UI::Widget::UnitMenu *unit_selector; Gtk::Label units_label; /* Filename widgets */ @@ -365,6 +370,7 @@ private: sigc::connection selectChangedConn; sigc::connection subselChangedConn; sigc::connection selectModifiedConn; + sigc::connection unitChangedConn; }; -- cgit v1.2.3 From ce25410db81c6a22a6b841efdb4790f7f19319ec Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 18 Jul 2013 10:39:48 -0400 Subject: Ported "ui/dialog/clonetiler.*". (bzr r12380.1.23) --- src/ui/dialog/clonetiler.cpp | 86 +++++++++++++++++++++++++++----------------- src/ui/dialog/clonetiler.h | 20 +++++++++-- 2 files changed, 72 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index 00bb6f0e2..d270afc3f 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -34,8 +34,8 @@ #include "document.h" #include "document-undo.h" #include "filter-chemistry.h" -#include "helper/unit-menu.h" -#include "helper/units.h" +#include "ui/widget/unit-menu.h" +#include "util/units.h" #include "helper/window.h" #include "inkscape.h" #include "interface.h" @@ -1092,35 +1092,38 @@ CloneTiler::CloneTiler (void) : g_object_set_data (G_OBJECT(dlg), "widthheight", (gpointer) hb); // unitmenu - GtkWidget *u = sp_unit_selector_new (SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); - //sp_unit_selector_set_unit (SP_UNIT_SELECTOR(u), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units); + unit_menu = new Inkscape::UI::Widget::UnitMenu(); + unit_menu->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR); + unit_menu->setUnit(sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units->abbr); + unitChangedConn = unit_menu->signal_changed().connect(sigc::mem_fun(*this, &CloneTiler::clonetiler_unit_changed)); { // Width spinbutton #if WITH_GTKMM_3_0 - Glib::RefPtr a = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0); + fill_width = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0); #else - Gtk::Adjustment *a = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0); + fill_width = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0); #endif - sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a->gobj())); double value = prefs->getDouble(prefs_path + "fillwidth", 50.0); - SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u)); - gdouble const units = sp_pixels_get_units (value, unit); - a->set_value (units); + Inkscape::Util::Unit const unit = unit_menu->getUnit(); + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit const px = unit_table.getUnit("px"); + gdouble const units = Inkscape::Util::Quantity::convert(value, &px, &unit); + fill_width->set_value (units); #if WITH_GTKMM_3_0 - Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(a, 1.0, 2); + Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(fill_width, 1.0, 2); #else - Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*a, 1.0, 2); + Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*fill_width, 1.0, 2); #endif e->set_tooltip_text (_("Width of the rectangle to be filled")); e->set_width_chars (7); e->set_digits (4); gtk_box_pack_start (GTK_BOX (hb), GTK_WIDGET(e->gobj()), TRUE, TRUE, 0); // TODO: C++ification - g_signal_connect(G_OBJECT(a->gobj()), "value_changed", - G_CALLBACK(clonetiler_fill_width_changed), u); + g_signal_connect(G_OBJECT(fill_width->gobj()), "value_changed", + G_CALLBACK(clonetiler_fill_width_changed), unit_menu); } { GtkWidget *l = gtk_label_new (""); @@ -1132,32 +1135,33 @@ CloneTiler::CloneTiler (void) : { // Height spinbutton #if WITH_GTKMM_3_0 - Glib::RefPtr a = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0); + fill_height = Gtk::Adjustment::create(0.0, -1e6, 1e6, 1.0, 10.0, 0); #else - Gtk::Adjustment *a = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0); + fill_height = new Gtk::Adjustment (0.0, -1e6, 1e6, 1.0, 10.0, 0); #endif - sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (u), GTK_ADJUSTMENT (a->gobj())); double value = prefs->getDouble(prefs_path + "fillheight", 50.0); - SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u)); - gdouble const units = sp_pixels_get_units (value, unit); - a->set_value (units); + Inkscape::Util::Unit const unit = unit_menu->getUnit(); + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit const px = unit_table.getUnit("px"); + gdouble const units = Inkscape::Util::Quantity::convert(value, &px, &unit); + fill_height->set_value (units); #if WITH_GTKMM_3_0 - Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(a, 1.0, 2); + Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton(fill_height, 1.0, 2); #else - Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*a, 1.0, 2); + Inkscape::UI::Widget::SpinButton *e = new Inkscape::UI::Widget::SpinButton (*fill_height, 1.0, 2); #endif e->set_tooltip_text (_("Height of the rectangle to be filled")); e->set_width_chars (7); e->set_digits (4); gtk_box_pack_start (GTK_BOX (hb), GTK_WIDGET(e->gobj()), TRUE, TRUE, 0); // TODO: C++ification - g_signal_connect(G_OBJECT(a->gobj()), "value_changed", - G_CALLBACK(clonetiler_fill_height_changed), u); + g_signal_connect(G_OBJECT(fill_height->gobj()), "value_changed", + G_CALLBACK(clonetiler_fill_height_changed), unit_menu); } - gtk_box_pack_start (GTK_BOX (hb), u, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hb), (GtkWidget*) unit_menu->gobj(), TRUE, TRUE, 0); clonetiler_table_attach (table, hb, 0.0, 2, 2); } @@ -2944,26 +2948,45 @@ void CloneTiler::clonetiler_switch_to_fill(GtkToggleButton * /*tb*/, GtkWidget * -void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, GtkWidget *u) +void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u) { gdouble const raw_dist = gtk_adjustment_get_value (adj); - SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u)); - gdouble const pixels = sp_units_get_pixels (raw_dist, unit); + Inkscape::Util::Unit const unit = u->getUnit(); + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit const px = unit_table.getUnit("px"); + gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, &unit, &px); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble(prefs_path + "fillwidth", pixels); } -void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, GtkWidget *u) +void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u) { gdouble const raw_dist = gtk_adjustment_get_value (adj); - SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(u)); - gdouble const pixels = sp_units_get_pixels (raw_dist, unit); + Inkscape::Util::Unit const unit = u->getUnit(); + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit const px = unit_table.getUnit("px"); + gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, &unit, &px); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble(prefs_path + "fillheight", pixels); } +void CloneTiler::clonetiler_unit_changed() +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gdouble width_pixels = prefs->getDouble(prefs_path + "fillwidth"); + gdouble height_pixels = prefs->getDouble(prefs_path + "fillheight"); + + Inkscape::Util::Unit unit = unit_menu->getUnit(); + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit px = unit_table.getUnit("px"); + + gdouble width_value = Inkscape::Util::Quantity::convert(width_pixels, &px, &unit); + gdouble height_value = Inkscape::Util::Quantity::convert(height_pixels, &px, &unit); + gtk_adjustment_set_value(fill_width->gobj(), width_value); + gtk_adjustment_set_value(fill_height->gobj(), height_value); +} void CloneTiler::clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg) { @@ -2977,7 +3000,6 @@ void CloneTiler::clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg) } } - } } } diff --git a/src/ui/dialog/clonetiler.h b/src/ui/dialog/clonetiler.h index 7ec30cfaa..e2a0240ee 100644 --- a/src/ui/dialog/clonetiler.h +++ b/src/ui/dialog/clonetiler.h @@ -19,6 +19,11 @@ namespace Inkscape { namespace UI { + +namespace Widget { + class UnitMenu; +} + namespace Dialog { class CloneTiler : public Widget::Panel { @@ -45,8 +50,9 @@ protected: static void clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg); static void clonetiler_pick_to(GtkToggleButton *tb, gpointer data); static void clonetiler_xy_changed(GtkAdjustment *adj, gpointer data); - static void clonetiler_fill_width_changed(GtkAdjustment *adj, GtkWidget *u); - static void clonetiler_fill_height_changed(GtkAdjustment *adj, GtkWidget *u); + static void clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u); + static void clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u); + void clonetiler_unit_changed(); static void clonetiler_switch_to_create(GtkToggleButton */*tb*/, GtkWidget *dlg); static void clonetiler_switch_to_fill(GtkToggleButton */*tb*/, GtkWidget *dlg); static void clonetiler_keep_bbox_toggled(GtkToggleButton *tb, gpointer /*data*/); @@ -112,12 +118,22 @@ private: DesktopTracker deskTrack; Inkscape::UI::Widget::ColorPicker *color_picker; GtkSizeGroup* table_row_labels; + Inkscape::UI::Widget::UnitMenu *unit_menu; + +#if WITH_GTKMM_3_0 + Glib::RefPtr fill_width; + Glib::RefPtr fill_height; +#else + Gtk::Adjustment *fill_width; + Gtk::Adjustment *fill_height; +#endif sigc::connection desktopChangeConn; sigc::connection selectChangedConn; sigc::connection subselChangedConn; sigc::connection selectModifiedConn; sigc::connection color_changed_connection; + sigc::connection unitChangedConn; /** * Can be invoked for setting the desktop. Currently not used. -- cgit v1.2.3 From 65e3eb1a68581bede3788501a3052e97df16c91a Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 18 Jul 2013 15:00:03 -0400 Subject: Added quantity string parsing. (bzr r12380.1.24) --- src/util/units.cpp | 22 ++++++++++++++++++++++ src/util/units.h | 27 +++++++++++++++------------ 2 files changed, 37 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/util/units.cpp b/src/util/units.cpp index d485f6aef..705fc850c 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "io/simple-sax.h" #include "util/units.h" @@ -228,6 +229,27 @@ Unit UnitTable::getUnit(Glib::ustring const &unit_abbr) const { } } +Quantity UnitTable::getQuantity(Glib::ustring const& q) const { + Glib::MatchInfo match_info; + + // Extract value + double value = 0; + Glib::RefPtr value_regex = Glib::Regex::create("\\d+\\.?\\d"); + if (value_regex->match(q, match_info)) { + value = atof(match_info.fetch(0).c_str()); + } + + // Extract unit abbreviation + Glib::ustring abbr; + Glib::RefPtr unit_regex = Glib::Regex::create("[A-z]+"); + if (unit_regex->match(q, match_info)) { + abbr = match_info.fetch(0); + } + Unit *u = new Inkscape::Util::Unit(getUnit(abbr)); + + return Quantity(value, u); +} + bool UnitTable::deleteUnit(Unit const &u) { bool deleted = false; // Cannot delete the primary unit type since it's diff --git a/src/util/units.h b/src/util/units.h index c6f124203..5d7bfaeaa 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -82,6 +82,18 @@ class Unit { int metric() const; }; +class Quantity { +public: + const Unit *unit; + double quantity; + + Quantity(double q, const Unit *u); // constructor + bool compatibleWith(const Unit *u) const; + double value(Unit *u) const; + + static double convert(const double from_dist, const Unit *from, const Unit *to); +}; + class UnitTable { public: /** @@ -99,6 +111,9 @@ class UnitTable { /** Retrieve a given unit based on its string identifier */ Unit getUnit(Glib::ustring const& name) const; + + /** Retrieve a quantity based on its string identifier */ + Quantity getQuantity(Glib::ustring const& q) const; /** Remove a unit definition from the given unit type table */ bool deleteUnit(Unit const& u); @@ -142,18 +157,6 @@ class UnitTable { }; -class Quantity { -public: - const Unit *unit; - double quantity; - - Quantity(double q, const Unit *u); // constructor - bool compatibleWith(const Unit *u) const; - double value(Unit *u) const; - - static double convert(const double from_dist, const Unit *from, const Unit *to); -}; - } // namespace Util } // namespace Inkscape -- cgit v1.2.3 From e641b84738df214c63ff67ce1bd2d0b8f6449c2e Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 18 Jul 2013 15:02:24 -0400 Subject: Ported "display/canvas-grid.*" and "display/canvas-axonomgrid.*". (bzr r12380.1.25) --- src/display/canvas-axonomgrid.cpp | 104 ++++++++--------------------- src/display/canvas-grid.cpp | 134 +++++++++++++------------------------- src/display/canvas-grid.h | 6 +- 3 files changed, 78 insertions(+), 166 deletions(-) (limited to 'src') diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 59d2bb36d..5d6efb18e 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -51,7 +51,7 @@ #include "2geom/angle.h" #include "util/mathfns.h" #include "round.h" -#include "helper/units.h" +#include "util/units.h" enum Dim3 { X=0, Y, Z }; @@ -160,15 +160,17 @@ CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_r : CanvasGrid(nv, in_repr, in_doc, GRID_AXONOMETRIC) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gridunit = sp_unit_get_by_abbreviation( prefs->getString("/options/grids/axonom/units").data() ); + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit px = unit_table.getUnit("px"); + gridunit = new Inkscape::Util::Unit(unit_table.getUnit(prefs->getString("/options/grids/axonom/units"))); if (!gridunit) - gridunit = &sp_unit_get_by_id(SP_UNIT_PX); - origin[Geom::X] = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/origin_x", 0.0), *gridunit ); - origin[Geom::Y] = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/origin_y", 0.0), *gridunit ); + gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px")); + origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_x", 0.0), gridunit, &px); + origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_y", 0.0), gridunit, &px); color = prefs->getInt("/options/grids/axonom/color", 0x0000ff20); empcolor = prefs->getInt("/options/grids/axonom/empcolor", 0x0000ff40); empspacing = prefs->getInt("/options/grids/axonom/empspacing", 5); - lengthy = sp_units_get_pixels( prefs->getDouble("/options/grids/axonom/spacing_y", 1.0), *gridunit ); + lengthy = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/spacing_y", 1.0), gridunit, &px); angle_deg[X] = prefs->getDouble("/options/grids/axonom/angle_x", 30.0); angle_deg[Z] = prefs->getDouble("/options/grids/axonom/angle_z", 30.0); angle_deg[Y] = 0; @@ -188,63 +190,6 @@ CanvasAxonomGrid::~CanvasAxonomGrid () if (snapper) delete snapper; } - -/* fixme: Collect all these length parsing methods and think common sane API */ - -static gboolean sp_nv_read_length(gchar const *str, guint base, gdouble *val, SPUnit const **unit) -{ - if (!str) { - return FALSE; - } - - gchar *u; - gdouble v = g_ascii_strtod(str, &u); - if (!u) { - return FALSE; - } - while (isspace(*u)) { - u += 1; - } - - if (!*u) { - /* No unit specified - keep default */ - *val = v; - return TRUE; - } - - if (base & SP_UNIT_DEVICE) { - if (u[0] && u[1] && !isalnum(u[2]) && !strncmp(u, "px", 2)) { - *unit = &sp_unit_get_by_id(SP_UNIT_PX); - *val = v; - return TRUE; - } - } - - if (base & SP_UNIT_ABSOLUTE) { - if (!strncmp(u, "pt", 2)) { - *unit = &sp_unit_get_by_id(SP_UNIT_PT); - } else if (!strncmp(u, "mm", 2)) { - *unit = &sp_unit_get_by_id(SP_UNIT_MM); - } else if (!strncmp(u, "cm", 2)) { - *unit = &sp_unit_get_by_id(SP_UNIT_CM); - } else if (!strncmp(u, "m", 1)) { - *unit = &sp_unit_get_by_id(SP_UNIT_M); - } else if (!strncmp(u, "in", 2)) { - *unit = &sp_unit_get_by_id(SP_UNIT_IN); - } else if (!strncmp(u, "ft", 2)) { - *unit = &sp_unit_get_by_id(SP_UNIT_FT); - } else if (!strncmp(u, "pc", 2)) { - *unit = &sp_unit_get_by_id(SP_UNIT_PC); - } else { - return FALSE; - } - *val = v; - return TRUE; - } - - return FALSE; -} - static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color) { if (!str) { @@ -269,18 +214,23 @@ void CanvasAxonomGrid::readRepr() { gchar const *value; + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit px = unit_table.getUnit("px"); if ( (value = repr->attribute("originx")) ) { - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::X], &gridunit); - origin[Geom::X] = sp_units_get_pixels(origin[Geom::X], *(gridunit)); + Inkscape::Util::Quantity q = unit_table.getQuantity(value); + gridunit = q.unit; + origin[Geom::X] = unit_table.getQuantity(value).value(&px); } if ( (value = repr->attribute("originy")) ) { - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::Y], &gridunit); - origin[Geom::Y] = sp_units_get_pixels(origin[Geom::Y], *(gridunit)); + Inkscape::Util::Quantity q = unit_table.getQuantity(value); + gridunit = q.unit; + origin[Geom::Y] = unit_table.getQuantity(value).value(&px); } if ( (value = repr->attribute("spacingy")) ) { - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &lengthy, &gridunit); - lengthy = sp_units_get_pixels(lengthy, *(gridunit)); + Inkscape::Util::Quantity q = unit_table.getQuantity(value); + gridunit = q.unit; + lengthy = q.value(&px); if (lengthy < 0.0500) lengthy = 0.0500; } @@ -422,14 +372,16 @@ _wr.setUpdating (false); _rumg->setUnit (gridunit->abbr); gdouble val; + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit px = unit_table.getUnit("px"); val = origin[Geom::X]; - val = sp_pixels_get_units (val, *(gridunit)); + val = Inkscape::Util::Quantity::convert(val, &px, gridunit); _rsu_ox->setValue (val); val = origin[Geom::Y]; - val = sp_pixels_get_units (val, *(gridunit)); + val = Inkscape::Util::Quantity::convert(val, &px, gridunit); _rsu_oy->setValue (val); val = lengthy; - double gridy = sp_pixels_get_units (val, *(gridunit)); + double gridy = Inkscape::Util::Quantity::convert(val, &px, gridunit); _rsu_sy->setValue (gridy); _rsu_ax->setValue(angle_deg[X]); @@ -458,17 +410,17 @@ CanvasAxonomGrid::updateWidgets() _rcb_enabled.setActive(snapper->getEnabled()); } - _rumg.setUnit (gridunit); + _rumg.setUnit (gridunit->abbr); gdouble val; val = origin[Geom::X]; - val = sp_pixels_get_units (val, *(gridunit)); + val = Inkscape::Util::Quantity::convert(val, &px, gridunit); _rsu_ox.setValue (val); val = origin[Geom::Y]; - val = sp_pixels_get_units (val, *(gridunit)); + val = Inkscape::Util::Quantity::convert(val, &px, gridunit); _rsu_oy.setValue (val); val = lengthy; - double gridy = sp_pixels_get_units (val, *(gridunit)); + double gridy = Inkscape::Util::Quantity::convert(val, &px, gridunit); _rsu_sy.setValue (gridy); _rsu_ax.setValue(angle_deg[X]); diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 9fbb5f907..fdf156262 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -397,12 +397,15 @@ void CanvasGrid::setOrigin(Geom::Point const &origin_px) Inkscape::SVGOStringStream os_x, os_y; gdouble val; + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit px = unit_table.getUnit("px"); + val = origin_px[Geom::X]; - val = sp_pixels_get_units (val, *gridunit); - os_x << val << sp_unit_get_abbreviation(gridunit); + val = Inkscape::Util::Quantity::convert(val, &px, gridunit); + os_x << val << gridunit->abbr; val = origin_px[Geom::Y]; - val = sp_pixels_get_units (val, *gridunit); - os_y << val << sp_unit_get_abbreviation(gridunit); + val = Inkscape::Util::Quantity::convert(val, &px, gridunit); + os_y << val << gridunit->abbr; repr->setAttribute("originx", os_x.str().c_str()); repr->setAttribute("originy", os_y.str().c_str()); } @@ -488,17 +491,19 @@ CanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPD : CanvasGrid(nv, in_repr, in_doc, GRID_RECTANGULAR) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gridunit = sp_unit_get_by_abbreviation( prefs->getString("/options/grids/xy/units").data() ); + Inkscape::Util::UnitTable unit_table; + gridunit = new Inkscape::Util::Unit(unit_table.getUnit(prefs->getString("/options/grids/xy/units"))); if (!gridunit) { - gridunit = &sp_unit_get_by_id(SP_UNIT_PX); + gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px")); } - origin[Geom::X] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/origin_x", 0.0), *gridunit); - origin[Geom::Y] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/origin_y", 0.0), *gridunit); + Inkscape::Util::Unit px = unit_table.getUnit("px"); + origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_x", 0.0), gridunit, &px); + origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_y", 0.0), gridunit, &px); color = prefs->getInt("/options/grids/xy/color", 0x0000ff20); empcolor = prefs->getInt("/options/grids/xy/empcolor", 0x0000ff40); empspacing = prefs->getInt("/options/grids/xy/empspacing", 5); - spacing[Geom::X] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), *gridunit); - spacing[Geom::Y] = sp_units_get_pixels(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), *gridunit); + spacing[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), gridunit, &px); + spacing[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), gridunit, &px); render_dotted = prefs->getBool("/options/grids/xy/dotted", false); snapper = new CanvasXYGridSnapper(this, &namedview->snap_manager, 0); @@ -511,64 +516,6 @@ CanvasXYGrid::~CanvasXYGrid () if (snapper) delete snapper; } - -/* fixme: Collect all these length parsing methods and think common sane API */ - -static gboolean -sp_nv_read_length(gchar const *str, guint base, gdouble *val, SPUnit const **unit) -{ - if (!str) { - return FALSE; - } - - gchar *u; - gdouble v = g_ascii_strtod(str, &u); - if (!u) { - return FALSE; - } - while (isspace(*u)) { - u += 1; - } - - if (!*u) { - /* No unit specified - keep default */ - *val = v; - return TRUE; - } - - if (base & SP_UNIT_DEVICE) { - if (u[0] && u[1] && !isalnum(u[2]) && !strncmp(u, "px", 2)) { - *unit = &sp_unit_get_by_id(SP_UNIT_PX); - *val = v; - return TRUE; - } - } - - if (base & SP_UNIT_ABSOLUTE) { - if (!strncmp(u, "pt", 2)) { - *unit = &sp_unit_get_by_id(SP_UNIT_PT); - } else if (!strncmp(u, "mm", 2)) { - *unit = &sp_unit_get_by_id(SP_UNIT_MM); - } else if (!strncmp(u, "cm", 2)) { - *unit = &sp_unit_get_by_id(SP_UNIT_CM); - } else if (!strncmp(u, "m", 1)) { - *unit = &sp_unit_get_by_id(SP_UNIT_M); - } else if (!strncmp(u, "in", 2)) { - *unit = &sp_unit_get_by_id(SP_UNIT_IN); - } else if (!strncmp(u, "ft", 2)) { - *unit = &sp_unit_get_by_id(SP_UNIT_FT); - } else if (!strncmp(u, "pc", 2)) { - *unit = &sp_unit_get_by_id(SP_UNIT_PC); - } else { - return FALSE; - } - *val = v; - return TRUE; - } - - return FALSE; -} - static gboolean sp_nv_read_opacity(gchar const *str, guint32 *color) { if (!str) { @@ -643,30 +590,37 @@ static void validateInt(gint oldVal, void CanvasXYGrid::readRepr() { + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit px = unit_table.getUnit("px"); + gchar const *value; if ( (value = repr->attribute("originx")) ) { - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::X], &gridunit); - origin[Geom::X] = sp_units_get_pixels(origin[Geom::X], *(gridunit)); + Inkscape::Util::Quantity q = unit_table.getQuantity(value); + gridunit = q.unit; + origin[Geom::X] = unit_table.getQuantity(value).value(&px); } if ( (value = repr->attribute("originy")) ) { - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &origin[Geom::Y], &gridunit); - origin[Geom::Y] = sp_units_get_pixels(origin[Geom::Y], *(gridunit)); + Inkscape::Util::Quantity q = unit_table.getQuantity(value); + gridunit = q.unit; + origin[Geom::Y] = unit_table.getQuantity(value).value(&px); } if ( (value = repr->attribute("spacingx")) ) { double oldVal = spacing[Geom::X]; - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[Geom::X], &gridunit); - validateScalar( oldVal, &spacing[Geom::X]); - spacing[Geom::X] = sp_units_get_pixels(spacing[Geom::X], *(gridunit)); - + Inkscape::Util::Quantity q = unit_table.getQuantity(value); + gridunit = q.unit; + spacing[Geom::X] = q.quantity; + validateScalar(oldVal, &spacing[Geom::X]); + spacing[Geom::X] = Inkscape::Util::Quantity::convert(spacing[Geom::X], gridunit, &px); } if ( (value = repr->attribute("spacingy")) ) { double oldVal = spacing[Geom::Y]; - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &spacing[Geom::Y], &gridunit); - validateScalar( oldVal, &spacing[Geom::Y]); - spacing[Geom::Y] = sp_units_get_pixels(spacing[Geom::Y], *(gridunit)); - + Inkscape::Util::Quantity q = unit_table.getQuantity(value); + gridunit = q.unit; + spacing[Geom::Y] = q.quantity; + validateScalar(oldVal, &spacing[Geom::Y]); + spacing[Geom::Y] = Inkscape::Util::Quantity::convert(spacing[Geom::Y], gridunit, &px); } if ( (value = repr->attribute("color")) ) { @@ -805,17 +759,19 @@ CanvasXYGrid::newSpecificWidget() _rumg->setUnit (gridunit->abbr); gdouble val; + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::Unit px = unit_table.getUnit("px"); val = origin[Geom::X]; - val = sp_pixels_get_units (val, *(gridunit)); + val = Inkscape::Util::Quantity::convert(val, &px, gridunit); _rsu_ox->setValue (val); val = origin[Geom::Y]; - val = sp_pixels_get_units (val, *(gridunit)); + val = Inkscape::Util::Quantity::convert(val, &px, gridunit); _rsu_oy->setValue (val); val = spacing[Geom::X]; - double gridx = sp_pixels_get_units (val, *(gridunit)); + double gridx = Inkscape::Util::Quantity::convert(val, &px, gridunit); _rsu_sx->setValue (gridx); val = spacing[Geom::Y]; - double gridy = sp_pixels_get_units (val, *(gridunit)); + double gridy = Inkscape::Util::Quantity::convert(val, &px, gridunit); _rsu_sy->setValue (gridy); _rcp_gcol->setRgba32 (color); @@ -851,20 +807,20 @@ CanvasXYGrid::updateWidgets() _rcb_enabled.setActive(snapper->getEnabled()); } - _rumg.setUnit (gridunit); + _rumg.setUnit (gridunit->abbr); gdouble val; val = origin[Geom::X]; - val = sp_pixels_get_units (val, *(gridunit)); + val = Inkscape::Quantity::convert(val, &px, gridunit); _rsu_ox.setValue (val); val = origin[Geom::Y]; - val = sp_pixels_get_units (val, *(gridunit)); + val = Inkscape::Quantity::convert(val, &px, gridunit); _rsu_oy.setValue (val); val = spacing[Geom::X]; - double gridx = sp_pixels_get_units (val, *(gridunit)); + double gridx = Inkscape::Quantity::convert(val, &px, gridunit); _rsu_sx.setValue (gridx); val = spacing[Geom::Y]; - double gridy = sp_pixels_get_units (val, *(gridunit)); + double gridy = Inkscape::Quantity::convert(val, &px, gridunit); _rsu_sy.setValue (gridy); _rcp_gcol.setRgba32 (color); diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h index 7eaef407f..70b4bf744 100644 --- a/src/display/canvas-grid.h +++ b/src/display/canvas-grid.h @@ -28,6 +28,10 @@ namespace XML { class Node; } +namespace Util { +class Unit; +} + enum GridType { GRID_RECTANGULAR = 0, GRID_AXONOMETRIC = 1 @@ -88,7 +92,7 @@ public: guint32 empcolor; /**< Color for emphasis lines */ gint empspacing; /**< Spacing between emphasis lines */ - SPUnit const* gridunit; + Inkscape::Util::Unit const* gridunit; Inkscape::XML::Node * repr; SPDocument *doc; -- cgit v1.2.3 From 286ea5f976f27f7fdfec5859b08bcb31e53e6728 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 18 Jul 2013 16:13:16 -0400 Subject: Added more convienient unit conversion functions. (bzr r12380.1.26) --- src/util/units.cpp | 26 +++++++++++++++++++++++++- src/util/units.h | 6 +++++- 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/util/units.cpp b/src/util/units.cpp index 705fc850c..ed8fbfa34 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -462,9 +462,14 @@ bool Quantity::compatibleWith(const Unit *u) const { } /** Return the quantity's value in the specified unit. */ -double Quantity::value(Unit *u) const { +double Quantity::value(const Unit *u) const { return convert(quantity, unit, u); } +double Quantity::value(const Glib::ustring u) const { + static UnitTable unit_table; + Unit to_unit = unit_table.getUnit(u); + return value(&to_unit); +} /** Convert distances. */ double Quantity::convert(const double from_dist, const Unit *from, const Unit *to) { @@ -476,6 +481,25 @@ double Quantity::convert(const double from_dist, const Unit *from, const Unit *t // Compatible units return from_dist * from->factor / to->factor; } +double Quantity::convert(const double from_dist, const Glib::ustring from, const Unit &to) +{ + static UnitTable unit_table; + Unit from_unit = unit_table.getUnit(from); + return convert(from_dist, &from_unit, &to); +} +double Quantity::convert(const double from_dist, const Unit &from, const Glib::ustring to) +{ + static UnitTable unit_table; + Unit to_unit = unit_table.getUnit(to); + return convert(from_dist, &from, &to_unit); +} +double Quantity::convert(const double from_dist, const Glib::ustring from, const Glib::ustring to) +{ + static UnitTable unit_table; + Unit from_unit = unit_table.getUnit(from); + Unit to_unit = unit_table.getUnit(to); + return convert(from_dist, &from_unit, &to_unit); +} } // namespace Util } // namespace Inkscape diff --git a/src/util/units.h b/src/util/units.h index 5d7bfaeaa..f1a5f1e95 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -89,9 +89,13 @@ public: Quantity(double q, const Unit *u); // constructor bool compatibleWith(const Unit *u) const; - double value(Unit *u) const; + double value(const Unit *u) const; + double value(const Glib::ustring u) const; static double convert(const double from_dist, const Unit *from, const Unit *to); + static double convert(const double from_dist, const Glib::ustring from, const Unit &to); + static double convert(const double from_dist, const Unit &from, const Glib::ustring to); + static double convert(const double from_dist, const Glib::ustring from, const Glib::ustring to); }; class UnitTable { -- cgit v1.2.3 From 51ffb1d56821be424fc50c91e486d6143976ba30 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 18 Jul 2013 16:40:36 -0400 Subject: Added more more convientent unit functions. (bzr r12380.1.27) --- src/util/units.cpp | 17 +++++++++++++++++ src/util/units.h | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/util/units.cpp b/src/util/units.cpp index ed8fbfa34..ffbd74fdd 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -140,6 +140,12 @@ bool Unit::compatibleWith(const Unit *u) const { // Different, incompatible types return false; } +bool Unit::compatibleWith(const Glib::ustring u) const +{ + static UnitTable unit_table; + Unit compatible_unit = unit_table.getUnit(u); + return compatibleWith(&compatible_unit); +} /** Check if units are equal. */ bool operator== (const Unit &u1, const Unit &u2) { @@ -455,11 +461,22 @@ Quantity::Quantity(double q, const Unit *u) { unit = u; quantity = q; } +Quantity::Quantity(double q, const Glib::ustring u) { + UnitTable unit_table; + unit = new Unit(unit_table.getUnit(u)); + quantity = q; +} /** Checks if a quantity is compatible with the specified unit. */ bool Quantity::compatibleWith(const Unit *u) const { return unit->compatibleWith(u); } +bool Quantity::compatibleWith(const Glib::ustring u) const +{ + static UnitTable unit_table; + Unit other_unit = unit_table.getUnit(u); + return compatibleWith(&other_unit); +} /** Return the quantity's value in the specified unit. */ double Quantity::value(const Unit *u) const { diff --git a/src/util/units.h b/src/util/units.h index f1a5f1e95..ec9435647 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -66,6 +66,7 @@ class Unit { int defaultDigits() const; bool compatibleWith(const Unit *u) const; + bool compatibleWith(const Glib::ustring) const; UnitType type; double factor; @@ -87,8 +88,10 @@ public: const Unit *unit; double quantity; - Quantity(double q, const Unit *u); // constructor + Quantity(double q, const Unit *u); // constructor + Quantity(double q, const Glib::ustring u); // constructor bool compatibleWith(const Unit *u) const; + bool compatibleWith(const Glib::ustring u) const; double value(const Unit *u) const; double value(const Glib::ustring u) const; -- 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/display/canvas-axonomgrid.cpp | 21 ++++----- src/display/canvas-grid.cpp | 40 ++++++++--------- src/document.cpp | 20 ++++----- src/measure-context.cpp | 14 +++--- src/sp-namedview.cpp | 3 +- src/ui/dialog/clonetiler.cpp | 17 +++----- src/ui/dialog/export.cpp | 6 +-- src/ui/widget/page-sizer.cpp | 17 +++----- src/ui/widget/unit-tracker.cpp | 7 ++- src/util/units.cpp | 92 ++++++++++++++++++++++----------------- src/util/units.h | 22 +++++----- src/widgets/node-toolbar.cpp | 14 +++--- src/widgets/rect-toolbar.cpp | 14 +++--- src/widgets/select-toolbar.cpp | 24 +++++----- 14 files changed, 144 insertions(+), 167 deletions(-) (limited to 'src') diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 5d6efb18e..d3db94975 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -161,16 +161,15 @@ CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_r { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit px = unit_table.getUnit("px"); gridunit = new Inkscape::Util::Unit(unit_table.getUnit(prefs->getString("/options/grids/axonom/units"))); if (!gridunit) gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px")); - origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_x", 0.0), gridunit, &px); - origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_y", 0.0), gridunit, &px); + origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_x", 0.0), *gridunit, "px"); + origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/origin_y", 0.0), *gridunit, "px"); color = prefs->getInt("/options/grids/axonom/color", 0x0000ff20); empcolor = prefs->getInt("/options/grids/axonom/empcolor", 0x0000ff40); empspacing = prefs->getInt("/options/grids/axonom/empspacing", 5); - lengthy = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/spacing_y", 1.0), gridunit, &px); + lengthy = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/axonom/spacing_y", 1.0), *gridunit, "px"); angle_deg[X] = prefs->getDouble("/options/grids/axonom/angle_x", 30.0); angle_deg[Z] = prefs->getDouble("/options/grids/axonom/angle_z", 30.0); angle_deg[Y] = 0; @@ -215,22 +214,21 @@ CanvasAxonomGrid::readRepr() { gchar const *value; Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit px = unit_table.getUnit("px"); if ( (value = repr->attribute("originx")) ) { Inkscape::Util::Quantity q = unit_table.getQuantity(value); gridunit = q.unit; - origin[Geom::X] = unit_table.getQuantity(value).value(&px); + origin[Geom::X] = unit_table.getQuantity(value).value("px"); } if ( (value = repr->attribute("originy")) ) { Inkscape::Util::Quantity q = unit_table.getQuantity(value); gridunit = q.unit; - origin[Geom::Y] = unit_table.getQuantity(value).value(&px); + origin[Geom::Y] = unit_table.getQuantity(value).value("px"); } if ( (value = repr->attribute("spacingy")) ) { Inkscape::Util::Quantity q = unit_table.getQuantity(value); gridunit = q.unit; - lengthy = q.value(&px); + lengthy = q.value("px"); if (lengthy < 0.0500) lengthy = 0.0500; } @@ -373,15 +371,14 @@ _wr.setUpdating (false); gdouble val; Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit px = unit_table.getUnit("px"); val = origin[Geom::X]; - val = Inkscape::Util::Quantity::convert(val, &px, gridunit); + val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); _rsu_ox->setValue (val); val = origin[Geom::Y]; - val = Inkscape::Util::Quantity::convert(val, &px, gridunit); + val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); _rsu_oy->setValue (val); val = lengthy; - double gridy = Inkscape::Util::Quantity::convert(val, &px, gridunit); + double gridy = Inkscape::Util::Quantity::convert(val, "px", *gridunit); _rsu_sy->setValue (gridy); _rsu_ax->setValue(angle_deg[X]); diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index fdf156262..e72e01dbc 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -398,13 +398,12 @@ void CanvasGrid::setOrigin(Geom::Point const &origin_px) gdouble val; Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit px = unit_table.getUnit("px"); val = origin_px[Geom::X]; - val = Inkscape::Util::Quantity::convert(val, &px, gridunit); + val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); os_x << val << gridunit->abbr; val = origin_px[Geom::Y]; - val = Inkscape::Util::Quantity::convert(val, &px, gridunit); + val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); os_y << val << gridunit->abbr; repr->setAttribute("originx", os_x.str().c_str()); repr->setAttribute("originy", os_y.str().c_str()); @@ -496,14 +495,13 @@ CanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPD if (!gridunit) { gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px")); } - Inkscape::Util::Unit px = unit_table.getUnit("px"); - origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_x", 0.0), gridunit, &px); - origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_y", 0.0), gridunit, &px); + origin[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_x", 0.0), *gridunit, "px"); + origin[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/origin_y", 0.0), *gridunit, "px"); color = prefs->getInt("/options/grids/xy/color", 0x0000ff20); empcolor = prefs->getInt("/options/grids/xy/empcolor", 0x0000ff40); empspacing = prefs->getInt("/options/grids/xy/empspacing", 5); - spacing[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), gridunit, &px); - spacing[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), gridunit, &px); + spacing[Geom::X] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_x", 0.0), *gridunit, "px"); + spacing[Geom::Y] = Inkscape::Util::Quantity::convert(prefs->getDouble("/options/grids/xy/spacing_y", 0.0), *gridunit, "px"); render_dotted = prefs->getBool("/options/grids/xy/dotted", false); snapper = new CanvasXYGridSnapper(this, &namedview->snap_manager, 0); @@ -591,19 +589,18 @@ void CanvasXYGrid::readRepr() { Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit px = unit_table.getUnit("px"); gchar const *value; if ( (value = repr->attribute("originx")) ) { Inkscape::Util::Quantity q = unit_table.getQuantity(value); gridunit = q.unit; - origin[Geom::X] = unit_table.getQuantity(value).value(&px); + origin[Geom::X] = unit_table.getQuantity(value).value("px"); } if ( (value = repr->attribute("originy")) ) { Inkscape::Util::Quantity q = unit_table.getQuantity(value); gridunit = q.unit; - origin[Geom::Y] = unit_table.getQuantity(value).value(&px); + origin[Geom::Y] = unit_table.getQuantity(value).value("px"); } if ( (value = repr->attribute("spacingx")) ) { @@ -612,7 +609,7 @@ CanvasXYGrid::readRepr() gridunit = q.unit; spacing[Geom::X] = q.quantity; validateScalar(oldVal, &spacing[Geom::X]); - spacing[Geom::X] = Inkscape::Util::Quantity::convert(spacing[Geom::X], gridunit, &px); + spacing[Geom::X] = Inkscape::Util::Quantity::convert(spacing[Geom::X], *gridunit, "px"); } if ( (value = repr->attribute("spacingy")) ) { double oldVal = spacing[Geom::Y]; @@ -620,7 +617,7 @@ CanvasXYGrid::readRepr() gridunit = q.unit; spacing[Geom::Y] = q.quantity; validateScalar(oldVal, &spacing[Geom::Y]); - spacing[Geom::Y] = Inkscape::Util::Quantity::convert(spacing[Geom::Y], gridunit, &px); + spacing[Geom::Y] = Inkscape::Util::Quantity::convert(spacing[Geom::Y], *gridunit, "px"); } if ( (value = repr->attribute("color")) ) { @@ -760,18 +757,17 @@ CanvasXYGrid::newSpecificWidget() gdouble val; Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit px = unit_table.getUnit("px"); val = origin[Geom::X]; - val = Inkscape::Util::Quantity::convert(val, &px, gridunit); + val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); _rsu_ox->setValue (val); val = origin[Geom::Y]; - val = Inkscape::Util::Quantity::convert(val, &px, gridunit); + val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); _rsu_oy->setValue (val); val = spacing[Geom::X]; - double gridx = Inkscape::Util::Quantity::convert(val, &px, gridunit); + double gridx = Inkscape::Util::Quantity::convert(val, "px", *gridunit); _rsu_sx->setValue (gridx); val = spacing[Geom::Y]; - double gridy = Inkscape::Util::Quantity::convert(val, &px, gridunit); + double gridy = Inkscape::Util::Quantity::convert(val, "px", *gridunit); _rsu_sy->setValue (gridy); _rcp_gcol->setRgba32 (color); @@ -811,16 +807,16 @@ CanvasXYGrid::updateWidgets() gdouble val; val = origin[Geom::X]; - val = Inkscape::Quantity::convert(val, &px, gridunit); + val = Inkscape::Quantity::convert(val, "px", *gridunit); _rsu_ox.setValue (val); val = origin[Geom::Y]; - val = Inkscape::Quantity::convert(val, &px, gridunit); + val = Inkscape::Quantity::convert(val, "px", *gridunit); _rsu_oy.setValue (val); val = spacing[Geom::X]; - double gridx = Inkscape::Quantity::convert(val, &px, gridunit); + double gridx = Inkscape::Quantity::convert(val, "px", *gridunit); _rsu_sx.setValue (gridx); val = spacing[Geom::Y]; - double gridy = Inkscape::Quantity::convert(val, &px, gridunit); + double gridy = Inkscape::Quantity::convert(val, "px", *gridunit); _rsu_sy.setValue (gridy); _rcp_gcol.setRgba32 (color); 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()) diff --git a/src/measure-context.cpp b/src/measure-context.cpp index 6e7709d56..465b1da80 100644 --- a/src/measure-context.cpp +++ b/src/measure-context.cpp @@ -520,8 +520,6 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv if (!unit_name.compare("")) { unit_name = "px"; } - Inkscape::Util::Unit unit = unit_table.getUnit(unit_name); - Inkscape::Util::Unit px = unit_table.getUnit("px"); double fontsize = prefs->getInt("/tools/measure/fontsize"); @@ -532,7 +530,7 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv for (size_t idx = 1; idx < intersections.size(); ++idx) { LabelPlacement placement; placement.lengthVal = (intersections[idx] - intersections[idx - 1]).length(); - placement.lengthVal = Inkscape::Util::Quantity::convert(placement.lengthVal, &px, &unit); + placement.lengthVal = Inkscape::Util::Quantity::convert(placement.lengthVal, "px", unit_name); placement.offset = DIMENSION_OFFSET; placement.start = desktop->doc2dt( (intersections[idx - 1] + intersections[idx]) / 2 ); placement.end = placement.start - (normal * placement.offset); @@ -548,7 +546,7 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv LabelPlacement &place = *it; // TODO cleanup memory, Glib::ustring, etc.: - gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit.abbr.c_str()); + gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit_name.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, place.end, @@ -589,10 +587,10 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv { double totallengthval = (end_point - start_point).length(); - totallengthval = Inkscape::Util::Quantity::convert(totallengthval, &px, &unit); + totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); // TODO cleanup memory, Glib::ustring, etc.: - gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr.c_str()); + gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), @@ -610,10 +608,10 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv if (intersections.size() > 2) { double totallengthval = (intersections[intersections.size()-1] - intersections[0]).length(); - totallengthval = Inkscape::Util::Quantity::convert(totallengthval, &px, &unit); + totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); // TODO cleanup memory, Glib::ustring, etc.: - gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit.abbr.c_str()); + gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); SPCanvasText *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * 60, diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 0833d93bf..bf3adf816 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -1119,8 +1119,7 @@ double SPNamedView::getMarginLength(gchar const * const key, if (*margin_units == percent) { return (use_width)? width * value : height * value; } -// if (!sp_convert_distance (&value, margin_units, return_units)) { - if (!margin_units->compatibleWith(return_units)) { + if (!margin_units->compatibleWith(*return_units)) { return 0.0; } return value; diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index d270afc3f..abb2512f7 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -1108,8 +1108,7 @@ CloneTiler::CloneTiler (void) : double value = prefs->getDouble(prefs_path + "fillwidth", 50.0); Inkscape::Util::Unit const unit = unit_menu->getUnit(); Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit const px = unit_table.getUnit("px"); - gdouble const units = Inkscape::Util::Quantity::convert(value, &px, &unit); + gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit); fill_width->set_value (units); #if WITH_GTKMM_3_0 @@ -1143,8 +1142,7 @@ CloneTiler::CloneTiler (void) : double value = prefs->getDouble(prefs_path + "fillheight", 50.0); Inkscape::Util::Unit const unit = unit_menu->getUnit(); Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit const px = unit_table.getUnit("px"); - gdouble const units = Inkscape::Util::Quantity::convert(value, &px, &unit); + gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit); fill_height->set_value (units); #if WITH_GTKMM_3_0 @@ -2953,8 +2951,7 @@ void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI: gdouble const raw_dist = gtk_adjustment_get_value (adj); Inkscape::Util::Unit const unit = u->getUnit(); Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit const px = unit_table.getUnit("px"); - gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, &unit, &px); + gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble(prefs_path + "fillwidth", pixels); @@ -2965,8 +2962,7 @@ void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI gdouble const raw_dist = gtk_adjustment_get_value (adj); Inkscape::Util::Unit const unit = u->getUnit(); Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit const px = unit_table.getUnit("px"); - gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, &unit, &px); + gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble(prefs_path + "fillheight", pixels); @@ -2980,10 +2976,9 @@ void CloneTiler::clonetiler_unit_changed() Inkscape::Util::Unit unit = unit_menu->getUnit(); Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit px = unit_table.getUnit("px"); - gdouble width_value = Inkscape::Util::Quantity::convert(width_pixels, &px, &unit); - gdouble height_value = Inkscape::Util::Quantity::convert(height_pixels, &px, &unit); + gdouble width_value = Inkscape::Util::Quantity::convert(width_pixels, "px", unit); + gdouble height_value = Inkscape::Util::Quantity::convert(height_pixels, "px", unit); gtk_adjustment_set_value(fill_width->gobj(), width_value); gtk_adjustment_set_value(fill_height->gobj(), height_value); } diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 61fb6e4ee..5cb9357c3 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -1885,9 +1885,8 @@ void Export::setValuePx( Gtk::Adjustment *adj, double val) { const Unit unit = unit_selector->getUnit(); Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit px = unit_table.getUnit("px"); - setValue(adj, Inkscape::Util::Quantity::convert(val, &px, &unit)); + setValue(adj, Inkscape::Util::Quantity::convert(val, "px", unit)); return; } @@ -1937,9 +1936,8 @@ float Export::getValuePx( Gtk::Adjustment *adj ) float value = getValue( adj); const Unit unit = unit_selector->getUnit(); Inkscape::Util::UnitTable unit_table; - Inkscape::Util::Unit px = unit_table.getUnit("px"); - return Inkscape::Util::Quantity::convert(value, &unit, &px); + return Inkscape::Util::Quantity::convert(value, unit, "px"); } // end of sp_export_value_get_px() /** diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index 73b75090b..f6392cfd8 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -228,10 +228,6 @@ static PaperSizeRec const inkscape_papers[] = { //# P A G E S I Z E R //######################################################################## -//The default unit for this widget and its calculations -static Inkscape::Util::Unit _px_unit = unit_table.getUnit("px"); - - /** * Constructor */ @@ -481,8 +477,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 (Inkscape::Util::Quantity(w, &_px_unit)); - doc->setHeight (Inkscape::Util::Quantity(h, &_px_unit)); + doc->setWidth (Inkscape::Util::Quantity(w, "px")); + doc->setHeight (Inkscape::Util::Quantity(h, "px")); // 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))); @@ -567,8 +563,8 @@ PageSizer::find_paper_size (double w, double h) const iter != _paperSizeTable.end() ; ++iter) { PaperSize paper = iter->second; Inkscape::Util::Unit const &i_unit = paper.unit; - double smallX = Inkscape::Util::Quantity::convert(paper.smaller, &i_unit, &_px_unit); - double largeX = Inkscape::Util::Quantity::convert(paper.larger, &i_unit, &_px_unit); + double smallX = Inkscape::Util::Quantity::convert(paper.smaller, i_unit, "px"); + double largeX = Inkscape::Util::Quantity::convert(paper.larger, i_unit, "px"); g_return_val_if_fail(smallX <= largeX, _paperSizeListStore->children().end()); @@ -659,9 +655,8 @@ PageSizer::on_paper_size_list_changed() _landscape = _landscapeButton.get_active(); } - Inkscape::Util::Unit const &src_unit = paper.unit; - w = Inkscape::Util::Quantity::convert(w, &src_unit, &_px_unit); - h = Inkscape::Util::Quantity::convert(h, &src_unit, &_px_unit); + w = Inkscape::Util::Quantity::convert(w, paper.unit, "px"); + h = Inkscape::Util::Quantity::convert(h, paper.unit, "px"); if (_landscape) setDim (h, w, false); diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp index df78e21dd..372419c3b 100644 --- a/src/ui/widget/unit-tracker.cpp +++ b/src/ui/widget/unit-tracker.cpp @@ -224,7 +224,6 @@ void UnitTracker::_setActive(gint active) void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape::Util::Unit const newUnit) { _isUpdating = true; - Inkscape::Util::Unit px = _unit_table.getUnit("px"); for ( GSList *cur = _adjList ; cur ; cur = g_slist_next(cur) ) { GtkAdjustment *adj = GTK_ADJUSTMENT(cur->data); gdouble oldVal = gtk_adjustment_get_value(adj); @@ -234,15 +233,15 @@ void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape && (newUnit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) ) { val = newUnit.factor; - _priorValues[adj] = Inkscape::Util::Quantity::convert(oldVal, &oldUnit, &px); + _priorValues[adj] = Inkscape::Util::Quantity::convert(oldVal, oldUnit, "px"); } else if ( (oldUnit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) && (newUnit.type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) ) { if (_priorValues.find(adj) != _priorValues.end()) { - val = Inkscape::Util::Quantity::convert(_priorValues[adj], &newUnit, &px); + val = Inkscape::Util::Quantity::convert(_priorValues[adj], newUnit, "px"); } } else { - val = Inkscape::Util::Quantity::convert(oldVal, &oldUnit, &newUnit); + val = Inkscape::Util::Quantity::convert(oldVal, oldUnit, newUnit); } gtk_adjustment_set_value(adj, val); diff --git a/src/util/units.cpp b/src/util/units.cpp index ffbd74fdd..78531bfaf 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -115,7 +115,8 @@ void Unit::clear() *this = Unit(); } -int Unit::defaultDigits() const { +int Unit::defaultDigits() const +{ int factor_digits = int(log10(factor)); if (factor_digits < 0) { g_warning("factor = %f, factor_digits = %d", factor, factor_digits); @@ -126,14 +127,15 @@ int Unit::defaultDigits() const { } /** Checks if a unit is compatible with the specified unit. */ -bool Unit::compatibleWith(const Unit *u) const { +bool Unit::compatibleWith(const Unit &u) const +{ // Percentages - if (type == UNIT_TYPE_DIMENSIONLESS || u->type == UNIT_TYPE_DIMENSIONLESS) { + if (type == UNIT_TYPE_DIMENSIONLESS || u.type == UNIT_TYPE_DIMENSIONLESS) { return true; } // Other units with same type - if (type == u->type) { + if (type == u.type) { return true; } @@ -143,22 +145,24 @@ bool Unit::compatibleWith(const Unit *u) const { bool Unit::compatibleWith(const Glib::ustring u) const { static UnitTable unit_table; - Unit compatible_unit = unit_table.getUnit(u); - return compatibleWith(&compatible_unit); + return compatibleWith(unit_table.getUnit(u)); } /** Check if units are equal. */ -bool operator== (const Unit &u1, const Unit &u2) { +bool operator== (const Unit &u1, const Unit &u2) +{ return (u1.type == u2.type && u1.name.compare(u2.name) == 0); } /** Check if units are not equal. */ -bool operator!= (const Unit &u1, const Unit &u2) { +bool operator!= (const Unit &u1, const Unit &u2) +{ return !(u1 == u2); } /** Temporary - get SVG unit. */ -int Unit::svgUnit() const { +int Unit::svgUnit() const +{ if (!abbr.compare("px")) return 1; if (!abbr.compare("pt")) @@ -183,7 +187,8 @@ int Unit::svgUnit() const { } /** Temporary - get metric. */ -int Unit::metric() const { +int Unit::metric() const +{ if (!abbr.compare("mm")) return 1; if (!abbr.compare("cm")) @@ -212,21 +217,24 @@ UnitTable::UnitTable() g_free(filename); } -UnitTable::~UnitTable() { +UnitTable::~UnitTable() +{ for (UnitMap::iterator iter = _unit_map.begin(); iter != _unit_map.end(); ++iter) { delete (*iter).second; } } -void UnitTable::addUnit(Unit const &u, bool primary) { +void UnitTable::addUnit(Unit const &u, bool primary) +{ _unit_map[u.abbr] = new Unit(u); if (primary) { _primary_unit[u.type] = u.abbr; } } -Unit UnitTable::getUnit(Glib::ustring const &unit_abbr) const { +Unit UnitTable::getUnit(Glib::ustring const &unit_abbr) const +{ UnitMap::const_iterator iter = _unit_map.find(unit_abbr); if (iter != _unit_map.end()) { return *((*iter).second); @@ -235,7 +243,8 @@ Unit UnitTable::getUnit(Glib::ustring const &unit_abbr) const { } } -Quantity UnitTable::getQuantity(Glib::ustring const& q) const { +Quantity UnitTable::getQuantity(Glib::ustring const& q) const +{ Glib::MatchInfo match_info; // Extract value @@ -251,12 +260,12 @@ Quantity UnitTable::getQuantity(Glib::ustring const& q) const { if (unit_regex->match(q, match_info)) { abbr = match_info.fetch(0); } - Unit *u = new Inkscape::Util::Unit(getUnit(abbr)); - return Quantity(value, u); + return Quantity(value, abbr); } -bool UnitTable::deleteUnit(Unit const &u) { +bool UnitTable::deleteUnit(Unit const &u) +{ bool deleted = false; // Cannot delete the primary unit type since it's // used for conversions @@ -365,7 +374,8 @@ bool UnitTable::loadText(Glib::ustring const &filename) return true; } -bool UnitTable::load(Glib::ustring const &filename) { +bool UnitTable::load(Glib::ustring const &filename) +{ UnitsSAXHandler handler(this); int result = handler.parseFile( filename.c_str() ); @@ -378,8 +388,8 @@ bool UnitTable::load(Glib::ustring const &filename) { return true; } -bool UnitTable::save(Glib::ustring const &filename) { - +bool UnitTable::save(Glib::ustring const &filename) +{ // open file for writing FILE *f = fopen(filename.c_str(), "w"); if (f == NULL) { @@ -457,65 +467,65 @@ void UnitsSAXHandler::_endElement(xmlChar const *xname) } /** Initialize a quantity. */ -Quantity::Quantity(double q, const Unit *u) { - unit = u; +Quantity::Quantity(double q, const Unit &u) +{ + unit = new Unit(u); quantity = q; } -Quantity::Quantity(double q, const Glib::ustring u) { +Quantity::Quantity(double q, const Glib::ustring u) +{ UnitTable unit_table; unit = new Unit(unit_table.getUnit(u)); quantity = q; } /** Checks if a quantity is compatible with the specified unit. */ -bool Quantity::compatibleWith(const Unit *u) const { +bool Quantity::compatibleWith(const Unit &u) const +{ return unit->compatibleWith(u); } bool Quantity::compatibleWith(const Glib::ustring u) const { static UnitTable unit_table; - Unit other_unit = unit_table.getUnit(u); - return compatibleWith(&other_unit); + return compatibleWith(unit_table.getUnit(u)); } /** Return the quantity's value in the specified unit. */ -double Quantity::value(const Unit *u) const { - return convert(quantity, unit, u); +double Quantity::value(const Unit &u) const +{ + return convert(quantity, *unit, u); } -double Quantity::value(const Glib::ustring u) const { +double Quantity::value(const Glib::ustring u) const +{ static UnitTable unit_table; - Unit to_unit = unit_table.getUnit(u); - return value(&to_unit); + return value(unit_table.getUnit(u)); } /** Convert distances. */ -double Quantity::convert(const double from_dist, const Unit *from, const Unit *to) { +double Quantity::convert(const double from_dist, const Unit &from, const Unit &to) +{ // Incompatible units - if (from->type != to->type) { + if (from.type != to.type) { return -1; } // Compatible units - return from_dist * from->factor / to->factor; + return from_dist * from.factor / to.factor; } double Quantity::convert(const double from_dist, const Glib::ustring from, const Unit &to) { static UnitTable unit_table; - Unit from_unit = unit_table.getUnit(from); - return convert(from_dist, &from_unit, &to); + return convert(from_dist, unit_table.getUnit(from), to); } double Quantity::convert(const double from_dist, const Unit &from, const Glib::ustring to) { static UnitTable unit_table; - Unit to_unit = unit_table.getUnit(to); - return convert(from_dist, &from, &to_unit); + return convert(from_dist, from, unit_table.getUnit(to)); } double Quantity::convert(const double from_dist, const Glib::ustring from, const Glib::ustring to) { static UnitTable unit_table; - Unit from_unit = unit_table.getUnit(from); - Unit to_unit = unit_table.getUnit(to); - return convert(from_dist, &from_unit, &to_unit); + return convert(from_dist, unit_table.getUnit(from), unit_table.getUnit(to)); } } // namespace Util diff --git a/src/util/units.h b/src/util/units.h index ec9435647..392e51e7a 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -65,7 +65,7 @@ class Unit { */ int defaultDigits() const; - bool compatibleWith(const Unit *u) const; + bool compatibleWith(const Unit &u) const; bool compatibleWith(const Glib::ustring) const; UnitType type; @@ -88,14 +88,14 @@ public: const Unit *unit; double quantity; - Quantity(double q, const Unit *u); // constructor + Quantity(double q, const Unit &u); // constructor Quantity(double q, const Glib::ustring u); // constructor - bool compatibleWith(const Unit *u) const; + bool compatibleWith(const Unit &u) const; bool compatibleWith(const Glib::ustring u) const; - double value(const Unit *u) const; + double value(const Unit &u) const; double value(const Glib::ustring u) const; - static double convert(const double from_dist, const Unit *from, const Unit *to); + static double convert(const double from_dist, const Unit &from, const Unit &to); static double convert(const double from_dist, const Glib::ustring from, const Unit &to); static double convert(const double from_dist, const Unit &from, const Glib::ustring to); static double convert(const double from_dist, const Glib::ustring from, const Glib::ustring to); @@ -114,16 +114,16 @@ class UnitTable { typedef std::map UnitMap; /** Add a new unit to the table */ - void addUnit(Unit const& u, bool primary); + void addUnit(Unit const &u, bool primary); /** Retrieve a given unit based on its string identifier */ - Unit getUnit(Glib::ustring const& name) const; + Unit getUnit(Glib::ustring const &name) const; /** Retrieve a quantity based on its string identifier */ - Quantity getQuantity(Glib::ustring const& q) const; + Quantity getQuantity(Glib::ustring const &q) const; /** Remove a unit definition from the given unit type table */ - bool deleteUnit(Unit const& u); + bool deleteUnit(Unit const &u); /** Returns true if the given string 'name' is a valid unit in the table */ bool hasUnit(Glib::ustring const &name) const; @@ -159,8 +159,8 @@ class UnitTable { double _linear_scale; private: - UnitTable(UnitTable const& t); - UnitTable operator=(UnitTable const& t); + UnitTable(UnitTable const &t); + UnitTable operator=(UnitTable const &t); }; diff --git a/src/widgets/node-toolbar.cpp b/src/widgets/node-toolbar.cpp index 50880f481..d60b58886 100644 --- a/src/widgets/node-toolbar.cpp +++ b/src/widgets/node-toolbar.cpp @@ -250,16 +250,15 @@ static void sp_node_toolbox_coord_changed(gpointer /*shape_editor*/, GObject *tb gtk_action_set_sensitive(xact, TRUE); gtk_action_set_sensitive(yact, TRUE); Inkscape::Util::UnitTable unit_table; - Unit px = unit_table.getUnit("px"); - Geom::Coord oldx = Quantity::convert(gtk_adjustment_get_value(xadj), &unit, &px); - Geom::Coord oldy = Quantity::convert(gtk_adjustment_get_value(yadj), &unit, &px); + Geom::Coord oldx = Quantity::convert(gtk_adjustment_get_value(xadj), unit, "px"); + Geom::Coord oldy = Quantity::convert(gtk_adjustment_get_value(yadj), unit, "px"); Geom::Point mid = nt->_selected_nodes->pointwiseBounds()->midpoint(); if (oldx != mid[Geom::X]) { - gtk_adjustment_set_value(xadj, Quantity::convert(mid[Geom::X], &px, &unit)); + gtk_adjustment_set_value(xadj, Quantity::convert(mid[Geom::X], "px", unit)); } if (oldy != mid[Geom::Y]) { - gtk_adjustment_set_value(yadj, Quantity::convert(mid[Geom::Y], &px, &unit)); + gtk_adjustment_set_value(yadj, Quantity::convert(mid[Geom::Y], "px", unit)); } } @@ -278,11 +277,10 @@ static void sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::D Unit const unit = tracker->getActiveUnit(); Inkscape::Util::UnitTable unit_table; - Unit px = unit_table.getUnit("px"); if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { prefs->setDouble(Glib::ustring("/tools/nodes/") + (d == Geom::X ? "x" : "y"), - Quantity::convert(gtk_adjustment_get_value(adj), &unit, &px)); + Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); } // quit if run by the attr_changed listener @@ -295,7 +293,7 @@ static void sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::D InkNodeTool *nt = get_node_tool(); if (nt && !nt->_selected_nodes->empty()) { - double val = Quantity::convert(gtk_adjustment_get_value(adj), &unit, &px); + double val = Quantity::convert(gtk_adjustment_get_value(adj), unit, "px"); double oldval = nt->_selected_nodes->pointwiseBounds()->midpoint()[d]; Geom::Point delta(0,0); delta[d] = val - oldval; diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 359bc48e0..d91b08273 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -95,12 +95,11 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * UnitTracker* tracker = reinterpret_cast(g_object_get_data( tbl, "tracker" )); Unit const unit = tracker->getActiveUnit(); Inkscape::Util::UnitTable unit_table; - Unit const px = unit_table.getUnit("px"); if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble(Glib::ustring("/tools/shapes/rect/") + value_name, - Quantity::convert(gtk_adjustment_get_value(adj), &unit, &px)); + Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); } // quit if run by the attr_changed listener @@ -117,7 +116,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * if (SP_IS_RECT(items->data)) { if (gtk_adjustment_get_value(adj) != 0) { setter(SP_RECT(items->data), - Quantity::convert(gtk_adjustment_get_value(adj), &unit, &px)); + Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); } else { SP_OBJECT(items->data)->getRepr()->setAttribute(value_name, NULL); } @@ -190,32 +189,31 @@ static void rect_tb_event_attr_changed(Inkscape::XML::Node * /*repr*/, gchar con UnitTracker* tracker = reinterpret_cast( g_object_get_data( tbl, "tracker" ) ); Unit const unit = tracker->getActiveUnit(); Inkscape::Util::UnitTable unit_table; - Unit const px = unit_table.getUnit("px"); gpointer item = g_object_get_data( tbl, "item" ); if (item && SP_IS_RECT(item)) { { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "rx" ) ); gdouble rx = sp_rect_get_visible_rx(SP_RECT(item)); - gtk_adjustment_set_value(adj, Quantity::convert(rx, &px, &unit)); + gtk_adjustment_set_value(adj, Quantity::convert(rx, "px", unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "ry" ) ); gdouble ry = sp_rect_get_visible_ry(SP_RECT(item)); - gtk_adjustment_set_value(adj, Quantity::convert(ry, &px, &unit)); + gtk_adjustment_set_value(adj, Quantity::convert(ry, "px", unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "width" ) ); gdouble width = sp_rect_get_visible_width (SP_RECT(item)); - gtk_adjustment_set_value(adj, Quantity::convert(width, &px, &unit)); + gtk_adjustment_set_value(adj, Quantity::convert(width, "px", unit)); } { GtkAdjustment *adj = GTK_ADJUSTMENT( g_object_get_data( tbl, "height" ) ); gdouble height = sp_rect_get_visible_height (SP_RECT(item)); - gtk_adjustment_set_value(adj, Quantity::convert(height, &px, &unit)); + gtk_adjustment_set_value(adj, Quantity::convert(height, "px", unit)); } } diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index ffab3deab..617757845 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -97,10 +97,9 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel) } } else { Inkscape::Util::UnitTable unit_table; - Unit px = unit_table.getUnit("px"); for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) { GtkAdjustment *a = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(spw), keyval[i].key)); - gtk_adjustment_set_value(a, Quantity::convert(keyval[i].val, &px, &unit)); + gtk_adjustment_set_value(a, Quantity::convert(keyval[i].val, "px", unit)); } } } @@ -194,15 +193,14 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw) GtkAdjustment* a_h = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "height" ) ); Inkscape::Util::UnitTable unit_table; - Unit px = unit_table.getUnit("px"); if (unit.type == Inkscape::Util::UNIT_TYPE_LINEAR) { - x0 = Quantity::convert(gtk_adjustment_get_value(a_x), &unit, &px); - y0 = Quantity::convert(gtk_adjustment_get_value(a_y), &unit, &px); - x1 = x0 + Quantity::convert(gtk_adjustment_get_value(a_w), &unit, &px); - xrel = Quantity::convert(gtk_adjustment_get_value(a_w), &unit, &px) / bbox_user->dimensions()[Geom::X]; - y1 = y0 + Quantity::convert(gtk_adjustment_get_value(a_h), &unit, &px);; - yrel = Quantity::convert(gtk_adjustment_get_value(a_h), &unit, &px) / bbox_user->dimensions()[Geom::Y]; + x0 = Quantity::convert(gtk_adjustment_get_value(a_x), unit, "px"); + y0 = Quantity::convert(gtk_adjustment_get_value(a_y), unit, "px"); + x1 = x0 + Quantity::convert(gtk_adjustment_get_value(a_w), unit, "px"); + xrel = Quantity::convert(gtk_adjustment_get_value(a_w), unit, "px") / bbox_user->dimensions()[Geom::X]; + y1 = y0 + Quantity::convert(gtk_adjustment_get_value(a_h), unit, "px");; + yrel = Quantity::convert(gtk_adjustment_get_value(a_h), unit, "px") / bbox_user->dimensions()[Geom::Y]; } else { double const x0_propn = gtk_adjustment_get_value (a_x) * unit.factor; x0 = bbox_user->min()[Geom::X] * x0_propn; @@ -232,10 +230,10 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw) // unless the unit is %, convert the scales and moves to the unit if (unit.type == Inkscape::Util::UNIT_TYPE_LINEAR) { - mh = Quantity::convert(mh, &px, &unit); - sh = Quantity::convert(sh, &px, &unit); - mv = Quantity::convert(mv, &px, &unit); - sv = Quantity::convert(sv, &px, &unit); + mh = Quantity::convert(mh, "px", unit); + sh = Quantity::convert(sh, "px", unit); + mv = Quantity::convert(mv, "px", unit); + sv = Quantity::convert(sv, "px", unit); } // do the action only if one of the scales/moves is greater than half the last significant -- cgit v1.2.3 From 5ce7ccd3fb416c686f570e86295c5f619bd86973 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 14:02:26 -0400 Subject: Removed "helper/unit-menu.h" from "widgets/rect-toolbar.*" and "widgets/spw-utilities.h". (bzr r12380.1.29) --- src/widgets/rect-toolbar.cpp | 1 - src/widgets/spw-utilities.cpp | 46 ------------------------------------------- src/widgets/spw-utilities.h | 5 ----- 3 files changed, 52 deletions(-) (limited to 'src') diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index d91b08273..e54a2df07 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -53,7 +53,6 @@ #include "../xml/repr.h" #include "ui/uxmanager.h" #include "../ui/icon-names.h" -#include "../helper/unit-menu.h" #include "util/units.h" #include "ui/widget/unit-tracker.h" #include "../pen-context.h" diff --git a/src/widgets/spw-utilities.cpp b/src/widgets/spw-utilities.cpp index 87ca80f2f..d0a3ed1c5 100644 --- a/src/widgets/spw-utilities.cpp +++ b/src/widgets/spw-utilities.cpp @@ -32,7 +32,6 @@ #include "selection.h" -#include "helper/unit-menu.h" #include "spw-utilities.h" #include @@ -231,51 +230,6 @@ spw_dropdown(GtkWidget * dialog, GtkWidget * table, return selector; } -/** - * Creates a unit selector widget, used for selecting whether one wishes - * to measure screen elements in millimeters, points, etc. This is a - * compound unit that includes a label as well as the dropdown selector. - */ -GtkWidget * -spw_unit_selector(GtkWidget * dialog, GtkWidget * table, - const gchar * label_text, gchar * key, int row, - GtkWidget * us, GCallback cb, bool can_be_negative) -{ - g_assert(dialog != NULL); - g_assert(table != NULL); - g_assert(us != NULL); - - spw_label_old(table, label_text, 0, row); - -#if GTK_CHECK_VERSION(3,0,0) - GtkAdjustment * a = gtk_adjustment_new(0.0, can_be_negative?-1e6:0, 1e6, 1.0, 10.0, 10.0); -#else - GtkObject * a = gtk_adjustment_new(0.0, can_be_negative?-1e6:0, 1e6, 1.0, 10.0, 10.0); -#endif - - g_assert(a != NULL); - g_object_set_data (G_OBJECT (a), "key", key); - g_object_set_data (G_OBJECT (a), "unit_selector", us); - g_object_set_data (G_OBJECT (dialog), key, a); - sp_unit_selector_add_adjustment (SP_UNIT_SELECTOR (us), GTK_ADJUSTMENT (a)); - GtkWidget * sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 1.0, 4); - g_assert(sb != NULL); - gtk_widget_show (sb); - -#if GTK_CHECK_VERSION(3,0,0) - gtk_widget_set_halign(sb, GTK_ALIGN_FILL); - gtk_widget_set_hexpand(sb, TRUE); - gtk_widget_set_valign(sb, GTK_ALIGN_CENTER); - gtk_grid_attach(GTK_GRID(table), sb, 1, row, 1, 1); -#else - gtk_table_attach (GTK_TABLE (table), sb, 1, 2, row, row+1, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)0, 0, 0); -#endif - - g_signal_connect (G_OBJECT (a), "value_changed", cb, dialog); - return sb; -} - static void sp_set_font_size_recursive (GtkWidget *w, gpointer font) { diff --git a/src/widgets/spw-utilities.h b/src/widgets/spw-utilities.h index fb8c04ebf..d52cbd888 100644 --- a/src/widgets/spw-utilities.h +++ b/src/widgets/spw-utilities.h @@ -56,11 +56,6 @@ spw_dropdown(GtkWidget *dialog, GtkWidget *table, GtkWidget *selector ); -GtkWidget * -spw_unit_selector(GtkWidget *dialog, GtkWidget *table, - gchar const *label, gchar *key, int row, - GtkWidget *us, GCallback cb, bool can_be_negative = false); - void sp_set_font_size (GtkWidget *w, guint font); void sp_set_font_size_smaller (GtkWidget *w); -- cgit v1.2.3 From ef3bfa7e8bb2996c4042314accc34f6a72f072e1 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 14:19:03 -0400 Subject: Removed "helper/unit-menu.h" from "widgest/toolbar.*" and associated files. (bzr r12380.1.30) --- src/widgets/arc-toolbar.cpp | 4 ++-- src/widgets/box3d-toolbar.cpp | 6 +++--- src/widgets/calligraphy-toolbar.cpp | 16 ++++++++-------- src/widgets/connector-toolbar.cpp | 6 +++--- src/widgets/erasor-toolbar.cpp | 2 +- src/widgets/gradient-toolbar.cpp | 2 +- src/widgets/measure-toolbar.cpp | 2 +- src/widgets/mesh-toolbar.cpp | 4 ++-- src/widgets/node-toolbar.cpp | 4 ++-- src/widgets/paintbucket-toolbar.cpp | 4 ++-- src/widgets/pencil-toolbar.cpp | 2 +- src/widgets/rect-toolbar.cpp | 8 ++++---- src/widgets/spiral-toolbar.cpp | 6 +++--- src/widgets/spray-toolbar.cpp | 12 ++++++------ src/widgets/star-toolbar.cpp | 8 ++++---- src/widgets/text-toolbar.cpp | 6 ------ src/widgets/toolbox.cpp | 5 ----- src/widgets/toolbox.h | 1 - src/widgets/tweak-toolbar.cpp | 6 +++--- 19 files changed, 46 insertions(+), 58 deletions(-) (limited to 'src') diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index e3f3a8c79..42f696bec 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -337,7 +337,7 @@ void sp_arc_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObjec _("Start"), _("Start:"), _("The angle (in degrees) from the horizontal to the arc's start point"), "/tools/shapes/arc/start", 0.0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, "altx-arc", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-arc", -360.0, 360.0, 1.0, 10.0, 0, 0, 0, sp_arctb_start_value_changed); @@ -350,7 +350,7 @@ void sp_arc_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObjec _("End"), _("End:"), _("The angle (in degrees) from the horizontal to the arc's end point"), "/tools/shapes/arc/end", 0.0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -360.0, 360.0, 1.0, 10.0, 0, 0, 0, sp_arctb_end_value_changed); diff --git a/src/widgets/box3d-toolbar.cpp b/src/widgets/box3d-toolbar.cpp index 2d40b996b..91d4ebdec 100644 --- a/src/widgets/box3d-toolbar.cpp +++ b/src/widgets/box3d-toolbar.cpp @@ -316,7 +316,7 @@ void box3d_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject // Translators: PL is short for 'perspective line' _("Angle of PLs in X direction"), "/tools/shapes/3dbox/box3d_angle_x", 30, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-box3d", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-box3d", -360.0, 360.0, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), box3d_angle_x_value_changed ); @@ -356,7 +356,7 @@ void box3d_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject // Translators: PL is short for 'perspective line' _("Angle of PLs in Y direction"), "/tools/shapes/3dbox/box3d_angle_y", 30, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -360.0, 360.0, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), box3d_angle_y_value_changed ); @@ -395,7 +395,7 @@ void box3d_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject // Translators: PL is short for 'perspective line' _("Angle of PLs in Z direction"), "/tools/shapes/3dbox/box3d_angle_z", 30, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -360.0, 360.0, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), box3d_angle_z_value_changed ); diff --git a/src/widgets/calligraphy-toolbar.cpp b/src/widgets/calligraphy-toolbar.cpp index 7c2d6bf19..1f91b9fe2 100644 --- a/src/widgets/calligraphy-toolbar.cpp +++ b/src/widgets/calligraphy-toolbar.cpp @@ -447,7 +447,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Pen Width"), _("Width:"), _("The width of the calligraphic pen (relative to the visible canvas area)"), "/tools/calligraphic/width", 15, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-calligraphy", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-calligraphy", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_ddc_width_value_changed, 1, 0 ); @@ -464,7 +464,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Stroke Thinning"), _("Thinning:"), _("How much velocity thins the stroke (> 0 makes fast strokes thinner, < 0 makes them broader, 0 makes width independent of velocity)"), "/tools/calligraphic/thinning", 10, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -100, 100, 1, 10.0, labels, values, G_N_ELEMENTS(labels), sp_ddc_velthin_value_changed, 1, 0); @@ -480,7 +480,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Pen Angle"), _("Angle:"), _("The angle of the pen's nib (in degrees; 0 = horizontal; has no effect if fixation = 0)"), "/tools/calligraphic/angle", 30, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "calligraphy-angle", + GTK_WIDGET(desktop->canvas), holder, TRUE, "calligraphy-angle", -90.0, 90.0, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_ddc_angle_value_changed, 1, 0 ); @@ -498,7 +498,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Fixation"), _("Fixation:"), _("Angle behavior (0 = nib always perpendicular to stroke direction, 100 = fixed angle)"), "/tools/calligraphic/flatness", 90, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_ddc_flatness_value_changed, 1, 0); @@ -515,7 +515,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Cap rounding"), _("Caps:"), _("Increase to make caps at the ends of strokes protrude more (0 = no caps, 1 = round caps)"), "/tools/calligraphic/cap_rounding", 0.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 5.0, 0.01, 0.1, labels, values, G_N_ELEMENTS(labels), sp_ddc_cap_rounding_value_changed, 0.01, 2 ); @@ -531,7 +531,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Stroke Tremor"), _("Tremor:"), _("Increase to make strokes rugged and trembling"), "/tools/calligraphic/tremor", 0.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 100, 1, 10.0, labels, values, G_N_ELEMENTS(labels), sp_ddc_tremor_value_changed, 1, 0); @@ -549,7 +549,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Pen Wiggle"), _("Wiggle:"), _("Increase to make the pen waver and wiggle"), "/tools/calligraphic/wiggle", 0.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 100, 1, 10.0, labels, values, G_N_ELEMENTS(labels), sp_ddc_wiggle_value_changed, 1, 0); @@ -566,7 +566,7 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions _("Pen Mass"), _("Mass:"), _("Increase to make the pen drag behind, as if slowed by inertia"), "/tools/calligraphic/mass", 2.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 100, 1, 10.0, labels, values, G_N_ELEMENTS(labels), sp_ddc_mass_value_changed, 1, 0); diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index 293f1184d..54344e446 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -361,7 +361,7 @@ void sp_connector_toolbox_prep( SPDesktop *desktop, GtkActionGroup* mainActions, _("Connector Curvature"), _("Curvature:"), _("The amount of connectors curvature"), "/tools/connector/curvature", defaultConnCurvature, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "inkscape:connector-curvature", + GTK_WIDGET(desktop->canvas), holder, TRUE, "inkscape:connector-curvature", 0, 100, 1.0, 10.0, 0, 0, 0, connector_curvature_changed, 1, 0 ); @@ -372,7 +372,7 @@ void sp_connector_toolbox_prep( SPDesktop *desktop, GtkActionGroup* mainActions, _("Connector Spacing"), _("Spacing:"), _("The amount of space left around objects by auto-routing connectors"), "/tools/connector/spacing", defaultConnSpacing, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "inkscape:connector-spacing", + GTK_WIDGET(desktop->canvas), holder, TRUE, "inkscape:connector-spacing", 0, 100, 1.0, 10.0, 0, 0, 0, connector_spacing_changed, 1, 0 ); @@ -394,7 +394,7 @@ void sp_connector_toolbox_prep( SPDesktop *desktop, GtkActionGroup* mainActions, _("Connector Length"), _("Length:"), _("Ideal length for connectors when layout is applied"), "/tools/connector/length", 100, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "inkscape:connector-length", + GTK_WIDGET(desktop->canvas), holder, TRUE, "inkscape:connector-length", 10, 1000, 10.0, 100.0, 0, 0, 0, connector_length_changed, 1, 0 ); diff --git a/src/widgets/erasor-toolbar.cpp b/src/widgets/erasor-toolbar.cpp index 44c79d5f3..8ad376edb 100644 --- a/src/widgets/erasor-toolbar.cpp +++ b/src/widgets/erasor-toolbar.cpp @@ -145,7 +145,7 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb _("Pen Width"), _("Width:"), _("The width of the eraser pen (relative to the visible canvas area)"), "/tools/eraser/width", 15, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-eraser", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-eraser", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_erc_width_value_changed, 1, 0); diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index ea125a380..c1eb13ceb 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -1171,7 +1171,7 @@ void sp_gradient_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, eact = create_adjustment_action( "GradientEditOffsetAction", _("Offset"), _("Offset:"), _("Offset of selected stop"), "/tools/gradient/stopoffset", 0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 1.0, 0.01, 0.1, 0, 0, 0, gr_stop_offset_adjustment_changed diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index c72cb8fa3..d51a81457 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -106,7 +106,7 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G _("Font Size"), _("Font Size:"), _("The font size to be used in the measurement labels"), "/tools/measure/fontsize", 0.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 10, 36, 1.0, 4.0, 0, 0, 0, sp_measure_fontsize_value_changed); diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index 99a34fbda..37763ab34 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -262,7 +262,7 @@ void sp_mesh_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObj eact = create_adjustment_action( "MeshRowAction", _("Rows"), _("Rows:"), _("Number of rows in new mesh"), "/tools/mesh/mesh_rows", 1, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 1, 20, 1, 1, labels, values, G_N_ELEMENTS(labels), ms_row_changed, @@ -278,7 +278,7 @@ void sp_mesh_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObj eact = create_adjustment_action( "MeshColumnAction", _("Columns"), _("Columns:"), _("Number of columns in new mesh"), "/tools/mesh/mesh_cols", 1, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 1, 20, 1, 1, labels, values, G_N_ELEMENTS(labels), ms_col_changed, diff --git a/src/widgets/node-toolbar.cpp b/src/widgets/node-toolbar.cpp index d60b58886..65e42a60b 100644 --- a/src/widgets/node-toolbar.cpp +++ b/src/widgets/node-toolbar.cpp @@ -594,7 +594,7 @@ void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "NodeXAction", _("X coordinate:"), _("X:"), _("X coordinate of selected node(s)"), "/tools/nodes/Xcoord", 0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, "altx-nodes", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-nodes", -1e6, 1e6, SPIN_STEP, SPIN_PAGE_STEP, labels, values, G_N_ELEMENTS(labels), sp_node_path_x_value_changed ); @@ -612,7 +612,7 @@ void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "NodeYAction", _("Y coordinate:"), _("Y:"), _("Y coordinate of selected node(s)"), "/tools/nodes/Ycoord", 0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -1e6, 1e6, SPIN_STEP, SPIN_PAGE_STEP, labels, values, G_N_ELEMENTS(labels), sp_node_path_y_value_changed ); diff --git a/src/widgets/paintbucket-toolbar.cpp b/src/widgets/paintbucket-toolbar.cpp index 2c782da70..3bb1fa24a 100644 --- a/src/widgets/paintbucket-toolbar.cpp +++ b/src/widgets/paintbucket-toolbar.cpp @@ -164,7 +164,7 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions "ThresholdAction", _("Fill Threshold"), _("Threshold:"), _("The maximum allowed difference between the clicked pixel and the neighboring pixels to be counted in the fill"), - "/tools/paintbucket/threshold", 5, GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, + "/tools/paintbucket/threshold", 5, GTK_WIDGET(desktop->canvas), holder, TRUE, "inkscape:paintbucket-threshold", 0, 100.0, 1.0, 10.0, 0, 0, 0, paintbucket_threshold_changed, 1, 0 ); @@ -193,7 +193,7 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions "OffsetAction", _("Grow/shrink by"), _("Grow/shrink by:"), _("The amount to grow (positive) or shrink (negative) the created fill path"), - "/tools/paintbucket/offset", 0, GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, + "/tools/paintbucket/offset", 0, GTK_WIDGET(desktop->canvas), holder, TRUE, "inkscape:paintbucket-offset", -1e4, 1e4, 0.1, 0.5, 0, 0, 0, paintbucket_offset_changed, 1, 2); diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index e38b54b5d..851ad7134 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -302,7 +302,7 @@ void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb _("How much smoothing (simplifying) is applied to the line"), "/tools/freehand/pencil/tolerance", 3.0, - GTK_WIDGET(desktop->canvas), NULL, + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-pencil", 1, 100.0, 0.5, 1.0, labels, values, G_N_ELEMENTS(labels), diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index e54a2df07..29488031f 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -317,7 +317,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "RectWidthAction", _("Width"), _("W:"), _("Width of rectangle"), "/tools/shapes/rect/width", 0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, TRUE, "altx-rect", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-rect", 0, 1e6, SPIN_STEP, SPIN_PAGE_STEP, labels, values, G_N_ELEMENTS(labels), sp_rtb_width_value_changed ); @@ -334,7 +334,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "RectHeightAction", _("Height"), _("H:"), _("Height of rectangle"), "/tools/shapes/rect/height", 0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0, 1e6, SPIN_STEP, SPIN_PAGE_STEP, labels, values, G_N_ELEMENTS(labels), sp_rtb_height_value_changed ); @@ -351,7 +351,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "RadiusXAction", _("Horizontal radius"), _("Rx:"), _("Horizontal radius of rounded corners"), "/tools/shapes/rect/rx", 0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0, 1e6, SPIN_STEP, SPIN_PAGE_STEP, labels, values, G_N_ELEMENTS(labels), sp_rtb_rx_value_changed); @@ -366,7 +366,7 @@ void sp_rect_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "RadiusYAction", _("Vertical radius"), _("Ry:"), _("Vertical radius of rounded corners"), "/tools/shapes/rect/ry", 0, - GTK_WIDGET(desktop->canvas), NULL/*us*/, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0, 1e6, SPIN_STEP, SPIN_PAGE_STEP, labels, values, G_N_ELEMENTS(labels), sp_rtb_ry_value_changed); diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp index 48b509acc..cccaf5154 100644 --- a/src/widgets/spiral-toolbar.cpp +++ b/src/widgets/spiral-toolbar.cpp @@ -259,7 +259,7 @@ void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb eact = create_adjustment_action( "SpiralRevolutionAction", _("Number of turns"), _("Turns:"), _("Number of revolutions"), "/tools/shapes/spiral/revolution", 3.0, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-spiral", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-spiral", 0.01, 1024.0, 0.1, 1.0, labels, values, G_N_ELEMENTS(labels), sp_spl_tb_revolution_value_changed, 1, 2); @@ -273,7 +273,7 @@ void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb eact = create_adjustment_action( "SpiralExpansionAction", _("Divergence"), _("Divergence:"), _("How much denser/sparser are outer revolutions; 1 = uniform"), "/tools/shapes/spiral/expansion", 1.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 1000.0, 0.01, 1.0, labels, values, G_N_ELEMENTS(labels), sp_spl_tb_expansion_value_changed); @@ -287,7 +287,7 @@ void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb eact = create_adjustment_action( "SpiralT0Action", _("Inner radius"), _("Inner radius:"), _("Radius of the innermost revolution (relative to the spiral size)"), "/tools/shapes/spiral/t0", 0.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.0, 0.999, 0.01, 1.0, labels, values, G_N_ELEMENTS(labels), sp_spl_tb_t0_value_changed); diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index bdc700aa8..fe221f695 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -127,7 +127,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj EgeAdjustmentAction *eact = create_adjustment_action( "SprayWidthAction", _("Width"), _("Width:"), _("The width of the spray area (relative to the visible canvas area)"), "/tools/spray/width", 15, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-spray", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-spray", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_spray_width_value_changed, 1, 0 ); @@ -143,7 +143,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj EgeAdjustmentAction *eact = create_adjustment_action( "SprayMeanAction", _("Focus"), _("Focus:"), _("0 to spray a spot; increase to enlarge the ring radius"), "/tools/spray/mean", 0, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-mean", + GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-mean", 0, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_spray_mean_value_changed, 1, 0 ); @@ -159,7 +159,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj EgeAdjustmentAction *eact = create_adjustment_action( "SprayStandard_deviationAction", C_("Spray tool", "Scatter"), C_("Spray tool", "Scatter:"), _("Increase to scatter sprayed objects"), "/tools/spray/standard_deviation", 70, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-standard_deviation", + GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-standard_deviation", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_spray_standard_deviation_value_changed, 1, 0 ); @@ -220,7 +220,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj _("Amount"), _("Amount:"), _("Adjusts the number of items sprayed per click"), "/tools/spray/population", 70, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-population", + GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-population", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_spray_population_value_changed, 1, 0 ); @@ -251,7 +251,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj // xgettext:no-c-format _("Variation of the rotation of the sprayed objects; 0% for the same rotation than the original object"), "/tools/spray/rotation_variation", 0, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-rotation", + GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-rotation", 0, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_spray_rotation_value_changed, 1, 0 ); @@ -269,7 +269,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj // xgettext:no-c-format _("Variation in the scale of the sprayed objects; 0% for the same scale than the original object"), "/tools/spray/scale_variation", 0, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "spray-scale", + GTK_WIDGET(desktop->canvas), holder, TRUE, "spray-scale", 0, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_spray_scale_value_changed, 1, 0 ); diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index 545256061..9f7dd95e0 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -501,7 +501,7 @@ void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "MagnitudeAction", _("Corners"), _("Corners:"), _("Number of corners of a polygon or star"), "/tools/shapes/star/magnitude", 3, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 3, 1024, 1, 5, labels, values, G_N_ELEMENTS(labels), sp_stb_magnitude_value_changed, @@ -520,7 +520,7 @@ void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje // Base radius is the same for the closest handle. _("Base radius to tip radius ratio"), "/tools/shapes/star/proportion", 0.5, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, 0.01, 1.0, 0.01, 0.1, labels, values, G_N_ELEMENTS(labels), sp_stb_proportion_value_changed ); @@ -541,7 +541,7 @@ void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "RoundednessAction", _("Rounded"), _("Rounded:"), _("How much rounded are the corners (0 for sharp)"), "/tools/shapes/star/rounded", 0.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -10.0, 10.0, 0.01, 0.1, labels, values, G_N_ELEMENTS(labels), sp_stb_rounded_value_changed ); @@ -556,7 +556,7 @@ void sp_star_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje eact = create_adjustment_action( "RandomizationAction", _("Randomized"), _("Randomized:"), _("Scatter randomly the corners and angles"), "/tools/shapes/star/randomized", 0.0, - GTK_WIDGET(desktop->canvas), NULL, holder, FALSE, NULL, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, -10.0, 10.0, 0.001, 0.01, labels, values, G_N_ELEMENTS(labels), sp_stb_randomized_value_changed, 0.1, 3 ); diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 4dd44bb8d..a7bd25b2c 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -1459,7 +1459,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje "/tools/text/lineheight", /* preferences path */ 0.0, /* default */ GTK_WIDGET(desktop->canvas), /* focusTarget */ - NULL, /* unit selector */ holder, /* dataKludge */ FALSE, /* set alt-x keyboard shortcut? */ NULL, /* altx_mark */ @@ -1490,7 +1489,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje "/tools/text/wordspacing", /* preferences path */ 0.0, /* default */ GTK_WIDGET(desktop->canvas), /* focusTarget */ - NULL, /* unit selector */ holder, /* dataKludge */ FALSE, /* set alt-x keyboard shortcut? */ NULL, /* altx_mark */ @@ -1521,7 +1519,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje "/tools/text/letterspacing", /* preferences path */ 0.0, /* default */ GTK_WIDGET(desktop->canvas), /* focusTarget */ - NULL, /* unit selector */ holder, /* dataKludge */ FALSE, /* set alt-x keyboard shortcut? */ NULL, /* altx_mark */ @@ -1552,7 +1549,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje "/tools/text/dx", /* preferences path */ 0.0, /* default */ GTK_WIDGET(desktop->canvas), /* focusTarget */ - NULL, /* unit selector */ holder, /* dataKludge */ FALSE, /* set alt-x keyboard shortcut? */ NULL, /* altx_mark */ @@ -1583,7 +1579,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje "/tools/text/dy", /* preferences path */ 0.0, /* default */ GTK_WIDGET(desktop->canvas), /* focusTarget */ - NULL, /* unit selector */ holder, /* dataKludge */ FALSE, /* set alt-x keyboard shortcut? */ NULL, /* altx_mark */ @@ -1614,7 +1609,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje "/tools/text/rotation", /* preferences path */ 0.0, /* default */ GTK_WIDGET(desktop->canvas), /* focusTarget */ - NULL, /* unit selector */ holder, /* dataKludge */ FALSE, /* set alt-x keyboard shortcut? */ NULL, /* altx_mark */ diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 687f62420..dcd4360fd 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -49,7 +49,6 @@ #include "../graphlayout.h" #include "../helper/action.h" #include "../helper/action-context.h" -#include "../helper/unit-menu.h" #include "icon.h" #include "../ink-action.h" #include "../ink-comboboxentry-action.h" @@ -1028,7 +1027,6 @@ EgeAdjustmentAction * create_adjustment_action( gchar const *name, gchar const *label, gchar const *shortLabel, gchar const *tooltip, Glib::ustring const &path, gdouble def, GtkWidget *focusTarget, - GtkWidget *us, GObject *dataKludge, gboolean altx, gchar const *altx_mark, gdouble lower, gdouble upper, gdouble step, gdouble page, @@ -1045,9 +1043,6 @@ EgeAdjustmentAction * create_adjustment_action( gchar const *name, Inkscape::Preferences *prefs = Inkscape::Preferences::get(); GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( prefs->getDouble(path, def) * factor, lower, upper, step, page, 0 ) ); - if (us) { - sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(us), adj ); - } g_signal_connect( G_OBJECT(adj), "value-changed", G_CALLBACK(callback), dataKludge ); diff --git a/src/widgets/toolbox.h b/src/widgets/toolbox.h index 9c839a8fe..197f0fb5e 100644 --- a/src/widgets/toolbox.h +++ b/src/widgets/toolbox.h @@ -118,7 +118,6 @@ void delete_connection(GObject * /*obj*/, sigc::connection *connection); gchar const *label, gchar const *shortLabel, gchar const *tooltip, Glib::ustring const &path, gdouble def, GtkWidget *focusTarget, - GtkWidget *us, GObject *dataKludge, gboolean altx, gchar const *altx_mark, gdouble lower, gdouble upper, gdouble step, gdouble page, diff --git a/src/widgets/tweak-toolbar.cpp b/src/widgets/tweak-toolbar.cpp index e96418957..d5fe67ef7 100644 --- a/src/widgets/tweak-toolbar.cpp +++ b/src/widgets/tweak-toolbar.cpp @@ -141,7 +141,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj EgeAdjustmentAction *eact = create_adjustment_action( "TweakWidthAction", _("Width"), _("Width:"), _("The width of the tweak area (relative to the visible canvas area)"), "/tools/tweak/width", 15, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-tweak", + GTK_WIDGET(desktop->canvas), holder, TRUE, "altx-tweak", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_tweak_width_value_changed, 0.01, 0, 100 ); @@ -158,7 +158,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj EgeAdjustmentAction *eact = create_adjustment_action( "TweakForceAction", _("Force"), _("Force:"), _("The force of the tweak action"), "/tools/tweak/force", 20, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "tweak-force", + GTK_WIDGET(desktop->canvas), holder, TRUE, "tweak-force", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_tweak_force_value_changed, 0.01, 0, 100 ); @@ -367,7 +367,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj _("Fidelity"), _("Fidelity:"), _("Low fidelity simplifies paths; high fidelity preserves path features but may generate a lot of new nodes"), "/tools/tweak/fidelity", 50, - GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "tweak-fidelity", + GTK_WIDGET(desktop->canvas), holder, TRUE, "tweak-fidelity", 1, 100, 1.0, 10.0, labels, values, G_N_ELEMENTS(labels), sp_tweak_fidelity_value_changed, 0.01, 0, 100 ); -- cgit v1.2.3 From 912d3580e5931b73b79fef0c060906676259d9f0 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 14:20:56 -0400 Subject: Removed "helper/unit-menu.h" and "helper/units.h" from "desktop-events.cpp". (bzr r12380.1.31) --- src/desktop-events.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 217187553..473ccfa9f 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -34,8 +34,6 @@ #include "document-undo.h" #include "event-context.h" #include "helper/action.h" -#include "helper/unit-menu.h" -#include "helper/units.h" #include "message-context.h" #include "preferences.h" #include "snap.h" -- cgit v1.2.3 From 180129cb81a37d222ab8fb3bd0446d043324ba2e Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 14:22:11 -0400 Subject: Removed "helper/unit-menu.h" and "helper/units.h" from "flood-context.h". (bzr r12380.1.32) --- src/flood-context.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/flood-context.h b/src/flood-context.h index 3e81cd01e..810a3b48f 100644 --- a/src/flood-context.h +++ b/src/flood-context.h @@ -15,8 +15,6 @@ #include #include #include "event-context.h" -#include "helper/unit-menu.h" -#include "helper/units.h" #define SP_TYPE_FLOOD_CONTEXT (sp_flood_context_get_type ()) #define SP_FLOOD_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_FLOOD_CONTEXT, SPFloodContext)) -- cgit v1.2.3 From 231a793d4d28f83b55fe9104a6593d72bca75219 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 14:32:09 -0400 Subject: Removed "helper/units.h" from "ui/dialog/document-properties.cpp". (bzr r12380.1.33) --- src/ui/dialog/document-properties.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index af462a1df..77fb182e5 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -28,7 +28,6 @@ #include "document.h" #include "desktop-handles.h" #include "desktop.h" -#include "helper/units.h" #include "inkscape.h" #include "io/sys.h" #include "preferences.h" @@ -1431,8 +1430,8 @@ void DocumentProperties::update() _rcp_bord.setRgba32 (nv->bordercolor); _rcb_shad.setActive (nv->showpageshadow); - //if (nv->doc_units) - // _rum_deflt.setUnit (nv->doc_units); + if (nv->doc_units) + _rum_deflt.setUnit (nv->doc_units->abbr); double const doc_w_px = sp_desktop_document(dt)->getWidth(); double const doc_h_px = sp_desktop_document(dt)->getHeight(); -- cgit v1.2.3 From fb1ac7622934007e4358a5797473f78fc1704ee9 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 14:42:21 -0400 Subject: Removed "helper/units.h" from "snap-preferences.h". (bzr r12380.1.34) --- src/snap-preferences.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/snap-preferences.h b/src/snap-preferences.h index c2db0b432..a7a2e2926 100644 --- a/src/snap-preferences.h +++ b/src/snap-preferences.h @@ -10,7 +10,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "helper/units.h" #include "snap-enums.h" namespace Inkscape -- cgit v1.2.3 From 6e9cf2ac415ff74108850236175ed7aeef496059 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 14:59:49 -0400 Subject: Ported "src/lpe-tool-context.*" (bzr r12380.1.35) --- src/lpe-tool-context.cpp | 37 ++++++++++++++++++++++++++++--------- src/lpe-tool-context.h | 1 - 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp index feabfa02d..bf032b7eb 100644 --- a/src/lpe-tool-context.cpp +++ b/src/lpe-tool-context.cpp @@ -37,7 +37,7 @@ #include "display/canvas-text.h" #include "message-stack.h" #include "sp-path.h" -#include "helper/units.h" +#include "util/units.h" #include "lpe-tool-context.h" @@ -444,6 +444,8 @@ lpetool_create_measuring_items(SPLPEToolContext *lc, Inkscape::Selection *select gchar *arc_length; double lengthval; + Inkscape::Util::UnitTable unit_table; + for (GSList const *i = selection->itemList(); i != NULL; i = i->next) { if (SP_IS_PATH(i->data)) { path = SP_PATH(i->data); @@ -453,13 +455,21 @@ lpetool_create_measuring_items(SPLPEToolContext *lc, Inkscape::Selection *select if (!show) sp_canvas_item_hide(SP_CANVAS_ITEM(canvas_text)); - SPUnitId unitid = static_cast(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX)); - SPUnit unit = sp_unit_get_by_id(unitid); + //SPUnitId unitid = static_cast(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX)); + //SPUnit unit = sp_unit_get_by_id(unitid); + Inkscape::Util::Unit unit; + if (prefs->getString("/tools/lpetool/unit").compare("")) { + unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit")); + } else { + unit = unit_table.getUnit("px"); + } lengthval = Geom::length(pwd2); gboolean success; - success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit); - arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px"); + //success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit); + lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit); + //arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px"); + arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str()); sp_canvastext_set_text (canvas_text, arc_length); set_pos_and_anchor(canvas_text, pwd2, 0.5, 10); // TODO: must we free arc_length? @@ -482,6 +492,7 @@ void lpetool_update_measuring_items(SPLPEToolContext *lc) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + Inkscape::Util::UnitTable unit_table; SPPath *path; SPCurve *curve; double lengthval; @@ -491,12 +502,20 @@ lpetool_update_measuring_items(SPLPEToolContext *lc) path = i->first; curve = SP_SHAPE(path)->getCurve(); Geom::Piecewise > pwd2 = Geom::paths_to_pw(curve->get_pathvector()); - SPUnitId unitid = static_cast(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX)); - SPUnit unit = sp_unit_get_by_id(unitid); + //SPUnitId unitid = static_cast(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX)); + //SPUnit unit = sp_unit_get_by_id(unitid); + Inkscape::Util::Unit unit; + if (prefs->getString("/tools/lpetool/unit").compare("")) { + unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit")); + } else { + unit = unit_table.getUnit("px"); + } lengthval = Geom::length(pwd2); gboolean success; - success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit); - arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px"); + //success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit); + lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit); + //arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px"); + arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str()); sp_canvastext_set_text (SP_CANVASTEXT(i->second), arc_length); set_pos_and_anchor(SP_CANVASTEXT(i->second), pwd2, 0.5, 10); // TODO: must we free arc_length? diff --git a/src/lpe-tool-context.h b/src/lpe-tool-context.h index fb3a5d4e2..7b85b09f2 100644 --- a/src/lpe-tool-context.h +++ b/src/lpe-tool-context.h @@ -16,7 +16,6 @@ */ #include "pen-context.h" -#include "helper/units.h" #define SP_TYPE_LPETOOL_CONTEXT (sp_lpetool_context_get_type()) #define SP_LPETOOL_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_LPETOOL_CONTEXT, SPLPEToolContext)) -- cgit v1.2.3 From d955b45ebb37552b33e8d3350be2446bd4692bd9 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 15:01:55 -0400 Subject: Removed "helper/units.h" from "display/canvas-grid.cpp". (bzr r12380.1.36) --- src/display/canvas-grid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index e72e01dbc..1a5e0e52d 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -42,7 +42,7 @@ #include "display/canvas-grid.h" #include "display/sp-canvas-group.h" #include "document.h" -#include "helper/units.h" +#include "util/units.h" #include "inkscape.h" #include "preferences.h" #include "sp-namedview.h" -- cgit v1.2.3 From dbc9ab3286ecb7a885ae9bdb524174c661607d6a Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 15:04:03 -0400 Subject: Removed "helper/units.h" from "selection-chemistry.cpp". (bzr r12380.1.37) --- src/selection-chemistry.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 29cb208d9..dc786f340 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -86,7 +86,6 @@ SPCycleType SP_CYCLING = SP_CYCLE_FOCUS; #include #include #include -#include "helper/units.h" #include "sp-item.h" #include "box3d.h" #include "persp3d.h" -- cgit v1.2.3 From 4d84edcf25468530660a441c55544c7db27c2682 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 15:08:24 -0400 Subject: Removed "helper/units.h" from "pen-context.cpp". (bzr r12380.1.38) --- src/pen-context.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 5972a6ca8..eac2ce5d1 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -39,7 +39,6 @@ #include "display/sp-ctrlline.h" #include "display/sodipodi-ctrl.h" #include -#include "helper/units.h" #include "macros.h" #include "context-fns.h" #include "tools-switch.h" @@ -1188,8 +1187,12 @@ static void spdc_pen_set_angle_distance_status_message(SPPenContext *const pc, G GString *dist = SP_PX_TO_METRIC_STRING(Geom::L2(rel), desktop->namedview->getDefaultMetric()); double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) - angle = angle_to_compass (angle); + if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) { + angle = 90 - angle; + if (angle < 0) { + angle += 360; + } + } pc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str); g_string_free(dist, FALSE); -- cgit v1.2.3 From 4f6415189dc97ccb8b8dfaa5ad515b56dd72de0f Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 15:48:48 -0400 Subject: Ported "ui/widget/selected-style.*". (bzr r12380.1.39) --- src/desktop.cpp | 1 - src/ui/widget/selected-style.cpp | 29 ++++++++++++++++------------- src/ui/widget/selected-style.h | 11 +++++++---- src/widgets/desktop-widget.cpp | 5 +++-- 4 files changed, 26 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/desktop.cpp b/src/desktop.cpp index ce740f76f..13e339abe 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -54,7 +54,6 @@ #include "document.h" #include "event-log.h" #include "helper/action-context.h" -#include "helper/units.h" #include "interface.h" #include "inkscape-private.h" #include "layer-fns.h" diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index 102132158..edf53d25c 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -50,6 +50,7 @@ #include "pixmaps/cursor-adj-a.xpm" #include "sp-cursor.h" #include "gradient-chemistry.h" +#include "util/units.h" static gdouble const _sw_presets[] = { 32 , 16 , 10 , 8 , 6 , 4 , 3 , 2 , 1.5 , 1 , 0.75 , 0.5 , 0.25 , 0.1 }; static gchar const *const _sw_presets_str[] = {"32", "16", "10", "8", "6", "4", "3", "2", "1.5", "1", "0.75", "0.5", "0.25", "0.1"}; @@ -306,15 +307,18 @@ SelectedStyle::SelectedStyle(bool /*layout*/) { int row = 0; - // List of units should match with Fill/Stroke dialog stroke style width list - for (GSList *l = sp_unit_get_list(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); l != NULL; l = l->next) { - SPUnit const *u = static_cast(l->data); + Inkscape::Util::UnitTable unit_table; + Inkscape::Util::UnitTable::UnitMap m = unit_table.units(Inkscape::Util::UNIT_TYPE_LINEAR); + Inkscape::Util::UnitTable::UnitMap::iterator iter = m.begin(); + while(iter != m.end()) { Gtk::RadioMenuItem *mi = Gtk::manage(new Gtk::RadioMenuItem(_sw_group)); - mi->add(*(new Gtk::Label(u->abbr, 0.0, 0.5))); + mi->add(*(new Gtk::Label((*iter).first, 0.0, 0.5))); _unit_mis = g_slist_append(_unit_mis, mi); - mi->signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), u->unit_id)); + Inkscape::Util::Unit const *u = new Inkscape::Util::Unit(unit_table.getUnit(iter->first)); + mi->signal_activate().connect(sigc::bind(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), *u)); _popup_sw.attach(*mi, 0,1, row, row+1); row++; + ++iter; } _popup_sw.attach(*(new Gtk::SeparatorMenuItem()), 0,1, row, row+1); @@ -476,14 +480,13 @@ SelectedStyle::setDesktop(SPDesktop *desktop) this ) )); - //_sw_unit = const_cast(sp_desktop_namedview(desktop)->doc_units); - _sw_unit = const_cast(&sp_unit_get_by_id(SP_UNIT_PX)); + _sw_unit = const_cast(sp_desktop_namedview(desktop)->doc_units); // Set the doc default unit active in the units list gint length = g_slist_length(_unit_mis); for (int i = 0; i < length; i++) { Gtk::RadioMenuItem *mi = (Gtk::RadioMenuItem *) g_slist_nth_data(_unit_mis, i); - if (mi && mi->get_label() == Glib::ustring(_sw_unit->abbr)) { + if (mi && mi->get_label() == _sw_unit->abbr) { mi->set_active(); break; } @@ -927,8 +930,8 @@ SelectedStyle::on_opacity_click(GdkEventButton *event) return false; } -void SelectedStyle::on_popup_units(SPUnitId id) { - _sw_unit = (SPUnit *) &(sp_unit_get_by_id(id)); +void SelectedStyle::on_popup_units(Inkscape::Util::Unit &unit) { + _sw_unit = new Inkscape::Util::Unit(unit); update(); } @@ -936,7 +939,7 @@ void SelectedStyle::on_popup_preset(int i) { SPCSSAttr *css = sp_repr_css_attr_new (); gdouble w; if (_sw_unit) { - w = sp_units_get_pixels (_sw_presets[i], *_sw_unit); + w = Inkscape::Util::Quantity::convert(_sw_presets[i], *_sw_unit, "px"); } else { w = _sw_presets[i]; } @@ -1115,7 +1118,7 @@ SelectedStyle::update() { double w; if (_sw_unit) { - w = sp_pixels_get_units(query->stroke_width.computed, *_sw_unit); + w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *_sw_unit); } else { w = query->stroke_width.computed; } @@ -1129,7 +1132,7 @@ SelectedStyle::update() { gchar *str = g_strdup_printf(_("Stroke width: %.5g%s%s"), w, - _sw_unit? sp_unit_get_abbreviation(_sw_unit) : "px", + _sw_unit? _sw_unit->abbr.c_str() : "px", (result_sw == QUERY_STYLE_MULTIPLE_AVERAGED)? _(" (averaged)") : ""); _stroke_width_place.set_tooltip_text(str); diff --git a/src/ui/widget/selected-style.h b/src/ui/widget/selected-style.h index e5bc4f883..0a907f1fd 100644 --- a/src/ui/widget/selected-style.h +++ b/src/ui/widget/selected-style.h @@ -41,12 +41,15 @@ #include #include "rotateable.h" -#include "helper/units.h" class SPDesktop; -struct SPUnit; namespace Inkscape { + +namespace Util { + class Unit; +} + namespace UI { namespace Widget { @@ -273,11 +276,11 @@ protected: Gtk::Menu _popup_sw; Gtk::RadioButtonGroup _sw_group; GSList *_unit_mis; - void on_popup_units(SPUnitId id); + void on_popup_units(Inkscape::Util::Unit &u); void on_popup_preset(int i); Gtk::MenuItem _popup_sw_remove; - SPUnit *_sw_unit; + Inkscape::Util::Unit *_sw_unit; void *_drop[2]; bool _dropEnabled[2]; diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 1c6852f35..56a5baf5b 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -394,7 +394,8 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) dtw->hruler = sp_ruler_new(GTK_ORIENTATION_HORIZONTAL); dtw->hruler_box = eventbox; sp_ruler_set_unit(SP_RULER(dtw->hruler), SP_PT); - gtk_widget_set_tooltip_text (dtw->hruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT)))); + Inkscape::Util::UnitTable unit_table; + gtk_widget_set_tooltip_text (dtw->hruler_box, gettext(unit_table.getUnit("pt").name_plural.c_str())); gtk_container_add (GTK_CONTAINER (eventbox), dtw->hruler); g_signal_connect (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (sp_dt_hruler_event), dtw); g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_hruler_event), dtw); @@ -423,7 +424,7 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) dtw->vruler = sp_ruler_new(GTK_ORIENTATION_VERTICAL); dtw->vruler_box = eventbox; sp_ruler_set_unit (SP_RULER (dtw->vruler), SP_PT); - gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT)))); + gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(unit_table.getUnit("pt").name_plural.c_str())); gtk_container_add (GTK_CONTAINER (eventbox), GTK_WIDGET (dtw->vruler)); #if GTK_CHECK_VERSION(3,0,0) -- cgit v1.2.3 From 4d00e731811f7c795b80b49b408eb76a9852b9f0 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 15:56:24 -0400 Subject: Ported "ui/widget/style-swatch.*". (bzr r12380.1.40) --- src/ui/widget/style-swatch.cpp | 6 +++--- src/ui/widget/style-swatch.h | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp index aedab3fa5..682457bed 100644 --- a/src/ui/widget/style-swatch.cpp +++ b/src/ui/widget/style-swatch.cpp @@ -26,7 +26,7 @@ #include "xml/repr.h" #include "xml/sp-css-attr.h" #include "widgets/widget-sizes.h" -#include "helper/units.h" +#include "util/units.h" #include "helper/action.h" #include "helper/action-context.h" #include "preferences.h" @@ -333,7 +333,7 @@ void StyleSwatch::setStyle(SPStyle *query) if (has_stroke) { double w; if (_sw_unit) { - w = sp_pixels_get_units(query->stroke_width.computed, *_sw_unit); + w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *_sw_unit); } else { w = query->stroke_width.computed; } @@ -346,7 +346,7 @@ void StyleSwatch::setStyle(SPStyle *query) { gchar *str = g_strdup_printf(_("Stroke width: %.5g%s"), w, - _sw_unit? sp_unit_get_abbreviation(_sw_unit) : "px"); + _sw_unit? _sw_unit->abbr.c_str() : "px"); _stroke_width_place.set_tooltip_text(str); g_free (str); } diff --git a/src/ui/widget/style-swatch.h b/src/ui/widget/style-swatch.h index 6bdb5e248..6da58a2dd 100644 --- a/src/ui/widget/style-swatch.h +++ b/src/ui/widget/style-swatch.h @@ -30,7 +30,6 @@ #include "button.h" #include "preferences.h" -struct SPUnit; struct SPStyle; class SPCSSAttr; @@ -43,6 +42,11 @@ class Table; } namespace Inkscape { + +namespace Util { + class Unit; +} + namespace UI { namespace Widget { @@ -93,7 +97,7 @@ private: Gtk::EventBox _stroke_width_place; Gtk::Label _stroke_width; - SPUnit *_sw_unit; + Inkscape::Util::Unit *_sw_unit; friend class ToolObserver; }; -- cgit v1.2.3 From 5b8a6e510cb69d33bc8834a7586142be800471b5 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 16:31:57 -0400 Subject: Ported "live_effects/parameter/unit.*". (bzr r12380.1.41) --- src/live_effects/lpe-path_length.cpp | 5 +++-- src/live_effects/lpe-ruler.cpp | 8 ++++---- src/live_effects/parameter/unit.cpp | 22 ++++++++++++---------- src/live_effects/parameter/unit.h | 15 +++++++++------ 4 files changed, 28 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp index d3edcda27..504fb53c0 100644 --- a/src/live_effects/lpe-path_length.cpp +++ b/src/live_effects/lpe-path_length.cpp @@ -15,6 +15,7 @@ #include "live_effects/lpe-path_length.h" #include "sp-metrics.h" +#include "util/units.h" #include "2geom/sbasis-geometric.h" @@ -52,11 +53,11 @@ LPEPathLength::doEffect_pwd2 (Geom::Piecewise > const & p /* convert the measured length to the correct unit ... */ double lengthval = Geom::length(pwd2_in) * scale; - gboolean success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), unit); + lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit.get_abbreviation()); /* ... set it as the canvas text ... */ gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, - display_unit ? (success ? unit.get_abbreviation() : "px") : ""); + display_unit ? unit.get_abbreviation() : ""); info_text.param_setValue(arc_length); g_free(arc_length); diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index fefdad95a..788ab593a 100644 --- a/src/live_effects/lpe-ruler.cpp +++ b/src/live_effects/lpe-ruler.cpp @@ -81,9 +81,9 @@ LPERuler::ruler_mark(Geom::Point const &A, Geom::Point const &n, MarkType const using namespace Geom; double real_mark_length = mark_length; - sp_convert_distance(&real_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX)); + real_mark_length = Inkscape::Util::Quantity::convert(real_mark_length, unit.get_abbreviation(), "px"); double real_minor_mark_length = minor_mark_length; - sp_convert_distance(&real_minor_mark_length, unit, &sp_unit_get_by_id(SP_UNIT_PX)); + real_minor_mark_length = Inkscape::Util::Quantity::convert(real_minor_mark_length, unit.get_abbreviation(), "px"); n_major = real_mark_length * n; n_minor = real_minor_mark_length * n; @@ -133,10 +133,10 @@ LPERuler::doEffect_pwd2 (Geom::Piecewise > const & pwd2_i std::vector s_cuts; double real_mark_distance = mark_distance; - sp_convert_distance(&real_mark_distance, unit, &sp_unit_get_by_id(SP_UNIT_PX)); + real_mark_distance = Inkscape::Util::Quantity::convert(real_mark_distance, unit.get_abbreviation(), "px"); double real_offset = offset; - sp_convert_distance(&real_offset, unit, &sp_unit_get_by_id(SP_UNIT_PX)); + real_offset = Inkscape::Util::Quantity::convert(real_offset, unit.get_abbreviation(), "px"); for (double s = real_offset; sabbr.c_str()); } void UnitParam::param_set_default() { - param_set_value(defunit); + param_set_value(*defunit); } void -UnitParam::param_set_value(SPUnit const *val) +UnitParam::param_set_value(Inkscape::Util::Unit const &val) { - unit = val; + unit = new Inkscape::Util::Unit(val); } const gchar * UnitParam::get_abbreviation() const { - return sp_unit_get_abbreviation(unit); + return unit->abbr.c_str(); } Gtk::Widget * diff --git a/src/live_effects/parameter/unit.h b/src/live_effects/parameter/unit.h index ea7a0112a..59a483018 100644 --- a/src/live_effects/parameter/unit.h +++ b/src/live_effects/parameter/unit.h @@ -10,10 +10,13 @@ */ #include "live_effects/parameter/parameter.h" -#include namespace Inkscape { +namespace Util { + class Unit; +} + namespace LivePathEffect { class UnitParam : public Parameter { @@ -23,22 +26,22 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - SPUnitId default_value = SP_UNIT_PX); + Glib::ustring default_unit = "px"); virtual ~UnitParam(); virtual bool param_readSVGValue(const gchar * strvalue); virtual gchar * param_getSVGValue() const; virtual void param_set_default(); - void param_set_value(SPUnit const *val); + void param_set_value(Inkscape::Util::Unit const &val); const gchar *get_abbreviation() const; virtual Gtk::Widget * param_newWidget(); - operator SPUnit const *() const { return unit; } + operator Inkscape::Util::Unit const *() const { return unit; } private: - SPUnit const *unit; - SPUnit const *defunit; + Inkscape::Util::Unit const *unit; + Inkscape::Util::Unit const *defunit; UnitParam(const UnitParam&); UnitParam& operator=(const UnitParam&); -- cgit v1.2.3 From 988e8e11fd11f1598d3ac0a42bdeef605772e6a9 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 16:34:39 -0400 Subject: Cleanup. (bzr r12380.1.42) --- src/lpe-tool-context.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src') diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp index bf032b7eb..32096970f 100644 --- a/src/lpe-tool-context.cpp +++ b/src/lpe-tool-context.cpp @@ -455,8 +455,6 @@ lpetool_create_measuring_items(SPLPEToolContext *lc, Inkscape::Selection *select if (!show) sp_canvas_item_hide(SP_CANVAS_ITEM(canvas_text)); - //SPUnitId unitid = static_cast(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX)); - //SPUnit unit = sp_unit_get_by_id(unitid); Inkscape::Util::Unit unit; if (prefs->getString("/tools/lpetool/unit").compare("")) { unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit")); @@ -466,9 +464,7 @@ lpetool_create_measuring_items(SPLPEToolContext *lc, Inkscape::Selection *select lengthval = Geom::length(pwd2); gboolean success; - //success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit); lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit); - //arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px"); arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str()); sp_canvastext_set_text (canvas_text, arc_length); set_pos_and_anchor(canvas_text, pwd2, 0.5, 10); @@ -502,8 +498,6 @@ lpetool_update_measuring_items(SPLPEToolContext *lc) path = i->first; curve = SP_SHAPE(path)->getCurve(); Geom::Piecewise > pwd2 = Geom::paths_to_pw(curve->get_pathvector()); - //SPUnitId unitid = static_cast(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX)); - //SPUnit unit = sp_unit_get_by_id(unitid); Inkscape::Util::Unit unit; if (prefs->getString("/tools/lpetool/unit").compare("")) { unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit")); @@ -512,9 +506,7 @@ lpetool_update_measuring_items(SPLPEToolContext *lc) } lengthval = Geom::length(pwd2); gboolean success; - //success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit); lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit); - //arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px"); arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str()); sp_canvastext_set_text (SP_CANVASTEXT(i->second), arc_length); set_pos_and_anchor(SP_CANVASTEXT(i->second), pwd2, 0.5, 10); -- cgit v1.2.3 From b4b22e6dba56bc9b0b8c35a9d484f1d86d61f45b Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sat, 20 Jul 2013 12:29:12 -0400 Subject: Added percentage support to "Inkscape::Util::Quantity::convert". (bzr r12380.1.43) --- src/util/units.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/util/units.cpp b/src/util/units.cpp index 78531bfaf..dcb3ae4b1 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -504,6 +504,11 @@ double Quantity::value(const Glib::ustring u) const /** Convert distances. */ double Quantity::convert(const double from_dist, const Unit &from, const Unit &to) { + // Percentage + if (to.type == UNIT_TYPE_DIMENSIONLESS) { + return from_dist * to.factor; + } + // Incompatible units if (from.type != to.type) { return -1; -- cgit v1.2.3 From 08d18ac062f175f893bc7251e39072d0f0d4577c Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sat, 20 Jul 2013 12:30:28 -0400 Subject: Ported "widgets/stroke-style.*". (bzr r12380.1.44) --- src/widgets/stroke-style.cpp | 123 ++++++++++++------------------------------- src/widgets/stroke-style.h | 24 ++++++--- 2 files changed, 50 insertions(+), 97 deletions(-) (limited to 'src') diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 17e3984bb..e35a8b36b 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -22,6 +22,8 @@ #include "sp-gradient.h" #include "sp-stop.h" #include "svg/svg-color.h" +#include "util/units.h" +#include "ui/widget/unit-menu.h" using Inkscape::DocumentUndo; @@ -189,22 +191,23 @@ StrokeStyle::StrokeStyle() : sp_dialog_defocus_on_enter_cpp(widthSpin); hb->pack_start(*widthSpin, false, false, 0); - unitSelector = sp_unit_selector_new(SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE); - Gtk::Widget *us = manage(Glib::wrap(unitSelector)); + unitSelector = new Inkscape::UI::Widget::UnitMenu(); + unitSelector->setUnitType(Inkscape::Util::UNIT_TYPE_LINEAR); + Gtk::Widget *us = manage(unitSelector); SPDesktop *desktop = SP_ACTIVE_DESKTOP; - //if (desktop) - // sp_unit_selector_set_unit (SP_UNIT_SELECTOR(unitSelector), sp_desktop_namedview(desktop)->doc_units); - sp_unit_selector_add_unit(SP_UNIT_SELECTOR(unitSelector), &sp_unit_get_by_id(SP_UNIT_PERCENT), 0); - g_signal_connect ( G_OBJECT (unitSelector), "set_unit", G_CALLBACK (StrokeStyle::setStrokeWidthUnit), this ); + Inkscape::Util::UnitTable unit_table; + unitSelector->addUnit(unit_table.getUnit("%")); + if (desktop) { + unitSelector->setUnit(sp_desktop_namedview(desktop)->doc_units->abbr); + _old_unit = new Inkscape::Util::Unit(*sp_desktop_namedview(desktop)->doc_units); + } + _old_unit = new Inkscape::Util::Unit(unitSelector->getUnit()); + widthSpin->setUnitMenu(unitSelector); + unitChangedConn = unitSelector->signal_changed().connect(sigc::mem_fun(*this, &StrokeStyle::unitChangedCB)); + us->show(); -#if WITH_GTKMM_3_0 - sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(unitSelector), GTK_ADJUSTMENT((*widthAdj)->gobj()) ); -#else - sp_unit_selector_add_adjustment( SP_UNIT_SELECTOR(unitSelector), GTK_ADJUSTMENT(widthAdj->gobj()) ); -#endif - hb->pack_start(*us, FALSE, FALSE, 0); #if WITH_GTKMM_3_0 @@ -519,75 +522,17 @@ void StrokeStyle::updateMarkerHist(SPMarkerLoc const which) } /** - * Sets the stroke width units for all selected items. - * Also handles absolute and dimensionless units. + * Callback for when UnitMenu widget is modified. + * Triggers update action. */ -gboolean StrokeStyle::setStrokeWidthUnit(SPUnitSelector *, - SPUnit const *old, - SPUnit const *new_units, - StrokeStyle *spw) +void StrokeStyle::unitChangedCB() { - if (spw->update) { - return FALSE; - } - - if (!spw->desktop) { - return FALSE; + Inkscape::Util::Unit new_unit = unitSelector->getUnit(); + if (new_unit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) { + widthSpin->set_value(100); } - - Inkscape::Selection *selection = sp_desktop_selection (spw->desktop); - - if (selection->isEmpty()) - return FALSE; - - GSList const *objects = selection->itemList(); - - if ((old->base == SP_UNIT_ABSOLUTE || old->base == SP_UNIT_DEVICE) && - (new_units->base == SP_UNIT_DIMENSIONLESS)) { - - /* Absolute to percentage */ - spw->update = true; - -#if WITH_GTKMM_3_0 - float w = sp_units_get_pixels( (*spw->widthAdj)->get_value(), *old); -#else - float w = sp_units_get_pixels(spw->widthAdj->get_value(), *old); -#endif - - gdouble average = stroke_average_width (objects); - - if ((average == Geom::infinity()) || (average < 1e-8)){ //less than 1e-8: to campare against zero, while taking numeric accuracy into account - return FALSE; - } - -#if WITH_GTKMM_3_0 - (*spw->widthAdj)->set_value(100.0 * w / average); -#else - spw->widthAdj->set_value(100.0 * w / average); -#endif - - spw->update = false; - return TRUE; - - } else if ((old->base == SP_UNIT_DIMENSIONLESS) && - (new_units->base == SP_UNIT_ABSOLUTE || new_units->base == SP_UNIT_DEVICE)) { - - /* Percentage to absolute */ - spw->update = true; - - gdouble average = stroke_average_width (objects); - -#if WITH_GTKMM_3_0 - (*spw->widthAdj)->set_value (sp_pixels_get_units (0.01 * (*spw->widthAdj)->get_value() * average, *new_units)); -#else - spw->widthAdj->set_value (sp_pixels_get_units (0.01 * spw->widthAdj->get_value() * average, *new_units)); -#endif - - spw->update = false; - return TRUE; - } - - return FALSE; + widthSpin->set_value(Inkscape::Util::Quantity::convert(widthSpin->get_value(), *_old_unit, new_unit)); + _old_unit = new Inkscape::Util::Unit(new_unit); } /** @@ -877,21 +822,21 @@ StrokeStyle::updateLine() } else { table->set_sensitive(true); - SPUnit const *unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unitSelector)); + Inkscape::Util::Unit const *unit = new Inkscape::Util::Unit(unitSelector->getUnit()); if (result_sw == QUERY_STYLE_MULTIPLE_AVERAGED) { - sp_unit_selector_set_unit(SP_UNIT_SELECTOR(unitSelector), &sp_unit_get_by_id(SP_UNIT_PERCENT)); + unitSelector->setUnit("%"); } else { // same width, or only one object; no sense to keep percent, switch to absolute - if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) { - //sp_unit_selector_set_unit(SP_UNIT_SELECTOR(unitSelector), sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units); + if (unit->type != Inkscape::Util::UNIT_TYPE_LINEAR) { + unitSelector->setUnit(sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units->abbr); } } - unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unitSelector)); + unit = new Inkscape::Util::Unit(unitSelector->getUnit()); - if (unit->base == SP_UNIT_ABSOLUTE || unit->base == SP_UNIT_DEVICE) { - double avgwidth = sp_pixels_get_units (query->stroke_width.computed, *unit); + if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { + double avgwidth = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *unit); #if WITH_GTKMM_3_0 (*widthAdj)->set_value(avgwidth); #else @@ -1017,7 +962,7 @@ StrokeStyle::scaleLine() double const miterlimit = miterLimitAdj->get_value(); #endif - SPUnit const *const unit = sp_unit_selector_get_unit(SP_UNIT_SELECTOR(unitSelector)); + Inkscape::Util::Unit const *const unit = new Inkscape::Util::Unit(unitSelector->getUnit()); double *dash, offset; int ndash; @@ -1026,8 +971,8 @@ StrokeStyle::scaleLine() for (GSList const *i = items; i != NULL; i = i->next) { /* Set stroke width */ double width; - if (unit->base == SP_UNIT_ABSOLUTE || unit->base == SP_UNIT_DEVICE) { - width = sp_units_get_pixels (width_typed, *unit); + if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { + width = Inkscape::Util::Quantity::convert(width_typed, *unit, "px"); } else { // percentage gdouble old_w = SP_OBJECT(i->data)->style->stroke_width.computed; width = old_w * width_typed / 100; @@ -1053,7 +998,7 @@ StrokeStyle::scaleLine() g_free(dash); - if (unit->base != SP_UNIT_ABSOLUTE && unit->base != SP_UNIT_DEVICE) { + if (unit->type != Inkscape::Util::UNIT_TYPE_LINEAR) { // reset to 100 percent #if WITH_GTKMM_3_0 (*widthAdj)->set_value(100.0); diff --git a/src/widgets/stroke-style.h b/src/widgets/stroke-style.h index fd9940db1..440881c6d 100644 --- a/src/widgets/stroke-style.h +++ b/src/widgets/stroke-style.h @@ -40,8 +40,6 @@ #include "document-undo.h" #include "gradient-chemistry.h" #include "helper/stock-items.h" -#include "helper/unit-menu.h" -#include "helper/units.h" #include "inkscape.h" #include "io/sys.h" #include "marker.h" @@ -77,6 +75,17 @@ class Widget; class Container; } +namespace Inkscape { + namespace Util { + class Unit; + } + namespace UI { + namespace Widget { + class UnitMenu; + } + } +} + struct { gchar const *key; gint value; } const SPMarkerNames[] = { {"marker-all", SP_MARKER_LOC}, {"marker-start", SP_MARKER_LOC_START}, @@ -162,17 +171,13 @@ private: StrokeStyleButtonType button_type, gchar const *stroke_style); - static gboolean setStrokeWidthUnit(SPUnitSelector *, - SPUnit const *old, - SPUnit const *new_units, - StrokeStyle *spw); - // Callback functions void selectionModifiedCB(guint flags); void selectionChangedCB(); void widthChangedCB(); void miterLimitChangedCB(); void lineDashChangedCB(); + void unitChangedCB(); static void markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, SPMarkerLoc const which); static void buttonToggledCB(StrokeStyleButton *tb, StrokeStyle *spw); @@ -191,7 +196,7 @@ private: #endif Inkscape::UI::Widget::SpinButton *miterLimitSpin; Inkscape::UI::Widget::SpinButton *widthSpin; - GtkWidget *unitSelector; + Inkscape::UI::Widget::UnitMenu *unitSelector; StrokeStyleButton *joinMiter; StrokeStyleButton *joinRound; StrokeStyleButton *joinBevel; @@ -207,6 +212,9 @@ private: sigc::connection startMarkerConn; sigc::connection midMarkerConn; sigc::connection endMarkerConn; + sigc::connection unitChangedConn; + + Inkscape::Util::Unit *_old_unit; }; } // namespace Inkscape -- cgit v1.2.3 From 567fbf4a2759ff93533a22a8688b4dcc01f19138 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sat, 20 Jul 2013 14:00:42 -0400 Subject: Removed last traces of "SPUnit" and removed "helper/unit*". (bzr r12380.1.45) --- src/helper/Makefile_insert | 4 - src/helper/unit-menu.cpp | 360 -------------------------------------- src/helper/unit-menu.h | 60 ------- src/helper/units-test.h | 90 ---------- src/helper/units.cpp | 261 --------------------------- src/helper/units.h | 146 ---------------- src/ui/widget/registered-widget.h | 1 - 7 files changed, 922 deletions(-) delete mode 100644 src/helper/unit-menu.cpp delete mode 100644 src/helper/unit-menu.h delete mode 100644 src/helper/units-test.h delete mode 100644 src/helper/units.cpp delete mode 100644 src/helper/units.h (limited to 'src') diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index 0008936dd..5d1703b5c 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -18,10 +18,6 @@ ink_common_sources += \ helper/png-write.h \ helper/sp-marshal.cpp \ helper/sp-marshal.h \ - helper/unit-menu.cpp \ - helper/unit-menu.h \ - helper/units.cpp \ - helper/units.h \ helper/window.cpp \ helper/window.h \ helper/stock-items.cpp \ diff --git a/src/helper/unit-menu.cpp b/src/helper/unit-menu.cpp deleted file mode 100644 index af07c03c1..000000000 --- a/src/helper/unit-menu.cpp +++ /dev/null @@ -1,360 +0,0 @@ -#define __SP_UNIT_MENU_C__ - -/* - * Unit selector with autupdate capability - * - * Authors: - * Lauris Kaplinski - * bulia byak - * - * Copyright (C) 2000-2002 Authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#define noUNIT_SELECTOR_VERBOSE - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#include -#include "helper/sp-marshal.h" -#include "helper/units.h" -#include "helper/unit-menu.h" -#include "widgets/spw-utilities.h" - -struct SPUnitSelector { - GtkHBox box; - - GtkWidget *combo_box; - GtkListStore *store; - - - guint bases; - GSList *units; - SPUnit const *unit; - gdouble ctmscale; - guint plural : 1; - guint abbr : 1; - - guint update : 1; - - GSList *adjustments; -}; - -enum {COMBO_COL_LABEL=0, COMBO_COL_UNIT}; - -struct SPUnitSelectorClass { - GtkHBoxClass parent_class; - - gboolean (* set_unit)(SPUnitSelector *us, SPUnit const *old, SPUnit const *new_unit); -}; - -enum {SET_UNIT, LAST_SIGNAL}; - -static void sp_unit_selector_finalize(GObject *object); - -static guint signals[LAST_SIGNAL] = {0}; - -G_DEFINE_TYPE(SPUnitSelector, sp_unit_selector, GTK_TYPE_HBOX); - -static void -sp_unit_selector_class_init(SPUnitSelectorClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS(klass); - - signals[SET_UNIT] = g_signal_new("set_unit", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(SPUnitSelectorClass, set_unit), - NULL, NULL, - sp_marshal_BOOLEAN__POINTER_POINTER, - G_TYPE_BOOLEAN, 2, - G_TYPE_POINTER, G_TYPE_POINTER); - - object_class->finalize = sp_unit_selector_finalize; -} - -static void -sp_unit_selector_init(SPUnitSelector *us) -{ - us->ctmscale = 1.0; - us->abbr = FALSE; - us->plural = TRUE; - - /** - * Create a combo_box and store with 2 columns, - * a label and a pointer to a SPUnit - */ - us->store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER); - us->combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (us->store)); - - GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); - g_object_set (renderer, "scale", 0.8, "scale-set", TRUE, NULL); - gtk_cell_renderer_set_padding (renderer, 2, 0); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (us->combo_box), renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (us->combo_box), renderer, "text", COMBO_COL_LABEL, NULL); - - gtk_widget_show (us->combo_box); - gtk_box_pack_start (GTK_BOX(us), us->combo_box, TRUE, TRUE, 0); -} - -static void -sp_unit_selector_finalize(GObject *object) -{ - SPUnitSelector *selector = SP_UNIT_SELECTOR(object); - - if (selector->combo_box) { - selector->combo_box = NULL; - } - - while (selector->adjustments) { - g_object_unref(selector->adjustments->data); - selector->adjustments = g_slist_remove(selector->adjustments, selector->adjustments->data); - } - - if (selector->units) { - sp_unit_free_list(selector->units); - } - - selector->unit = NULL; - - G_OBJECT_CLASS(sp_unit_selector_parent_class)->finalize(object); -} - -GtkWidget * -sp_unit_selector_new(guint bases) -{ - SPUnitSelector *us = SP_UNIT_SELECTOR(g_object_new(SP_TYPE_UNIT_SELECTOR, NULL)); - - sp_unit_selector_set_bases(us, bases); - - return GTK_WIDGET(us); -} - -void -sp_unit_selector_setsize(GtkWidget *us, guint w, guint h) -{ - gtk_widget_set_size_request((SP_UNIT_SELECTOR(us))->combo_box, w, h); -} - -SPUnit const * -sp_unit_selector_get_unit(SPUnitSelector const *us) -{ - g_return_val_if_fail(us != NULL, NULL); - g_return_val_if_fail(SP_IS_UNIT_SELECTOR(us), NULL); - - return us->unit; -} - - -static void -on_combo_box_changed (GtkComboBox *widget, SPUnitSelector *us) -{ - GtkTreeIter iter; - if (!gtk_combo_box_get_active_iter (widget, &iter)) { - return; - } - - SPUnit const *unit = NULL; - gtk_tree_model_get (GTK_TREE_MODEL(us->store), &iter, COMBO_COL_UNIT, &unit, -1); - - g_return_if_fail(unit != NULL); - -#ifdef UNIT_SELECTOR_VERBOSE - g_print("Old unit %s new unit %s\n", us->unit->name, unit->name); -#endif - - SPUnit const *old = us->unit; - us->unit = unit; - - us->update = TRUE; - - gboolean consumed = FALSE; - g_signal_emit(G_OBJECT(us), signals[SET_UNIT], 0, old, unit, &consumed); - - if ( !consumed - && ( unit->base == old->base - || ( unit->base == SP_UNIT_ABSOLUTE && old->base == SP_UNIT_DEVICE ) - || ( old->base == SP_UNIT_ABSOLUTE && unit->base == SP_UNIT_DEVICE ) ) ) { - // Either the same base, or absolute<->device: - /* Recalculate adjustments. */ - for (GSList *l = us->adjustments; l != NULL; l = g_slist_next(l)) { - GtkAdjustment *adj = GTK_ADJUSTMENT(l->data); - gdouble val = gtk_adjustment_get_value (adj); -#ifdef UNIT_SELECTOR_VERBOSE - g_print("Old val %g ... ", val); -#endif - val = sp_convert_distance_full(val, *old, *unit); -#ifdef UNIT_SELECTOR_VERBOSE - g_print("new val %g\n", val); -#endif - gtk_adjustment_set_value (adj, val); - } - /* need to separate the value changing from the notification - * or else the unit changes can break the calculations */ - for (GSList *l = us->adjustments; l != NULL; l = g_slist_next(l)) { - gtk_adjustment_value_changed(GTK_ADJUSTMENT(l->data)); - } - } else if (!consumed && unit->base != old->base) { - /* when the base changes, signal all the adjustments to get them - * to recalculate */ - for (GSList *l = us->adjustments; l != NULL; l = g_slist_next(l)) { - g_signal_emit_by_name(G_OBJECT(l->data), "value_changed"); - } - } - - us->update = FALSE; - -} - -static void -spus_rebuild_menu(SPUnitSelector *us) -{ - - gtk_list_store_clear(us->store); - - GtkTreeIter iter; - - gint pos = 0; - gint p = 0; - for (GSList *l = us->units; l != NULL; l = l->next) { - SPUnit const *u = static_cast(l->data); - - // use only abbreviations in the menu - // i = gtk_menu_item_new_with_label((us->abbr) ? (us->plural) ? u->abbr_plural : u->abbr : (us->plural) ? u->plural : u->name); - gtk_list_store_append (us->store, &iter); - gtk_list_store_set (us->store, &iter, COMBO_COL_LABEL, u->abbr, COMBO_COL_UNIT, (gpointer) u, -1); - - if (u == us->unit) { - pos = p; - } - - p += 1; - } - - gtk_combo_box_set_active(GTK_COMBO_BOX(us->combo_box), pos); - g_signal_connect (G_OBJECT (us->combo_box), "changed", G_CALLBACK (on_combo_box_changed), us); -} - -void -sp_unit_selector_set_bases(SPUnitSelector *us, guint bases) -{ - g_return_if_fail(us != NULL); - g_return_if_fail(SP_IS_UNIT_SELECTOR(us)); - - if (bases == us->bases) return; - - GSList *units = sp_unit_get_list(bases); - g_return_if_fail(units != NULL); - sp_unit_free_list(us->units); - us->units = units; - us->unit = static_cast(units->data); - - spus_rebuild_menu(us); -} - -void -sp_unit_selector_add_unit(SPUnitSelector *us, SPUnit const *unit, int position) -{ - if (!g_slist_find(us->units, (gpointer) unit)) { - us->units = g_slist_insert(us->units, (gpointer) unit, position); - - spus_rebuild_menu(us); - } -} - -void -sp_unit_selector_set_unit(SPUnitSelector *us, SPUnit const *unit) -{ - g_return_if_fail(us != NULL); - g_return_if_fail(SP_IS_UNIT_SELECTOR(us)); - - if (unit == NULL) { - return; // silently return, by default a newly created selector uses pt - } - if (unit == us->unit) { - return; - } - - gint const pos = g_slist_index(us->units, (gpointer) unit); - g_return_if_fail(pos >= 0); - - gtk_combo_box_set_active(GTK_COMBO_BOX(us->combo_box), pos); - - SPUnit const *old = us->unit; - us->unit = unit; - - /* Recalculate adjustments */ - for (GSList *l = us->adjustments; l != NULL; l = l->next) { - GtkAdjustment *adj = GTK_ADJUSTMENT(l->data); - gdouble const val = sp_convert_distance_full(gtk_adjustment_get_value (adj), *old, *unit); - gtk_adjustment_set_value(adj, val); - } -} - -void -sp_unit_selector_add_adjustment(SPUnitSelector *us, GtkAdjustment *adj) -{ - g_return_if_fail(us != NULL); - g_return_if_fail(SP_IS_UNIT_SELECTOR(us)); - g_return_if_fail(adj != NULL); - g_return_if_fail(GTK_IS_ADJUSTMENT(adj)); - - g_return_if_fail(!g_slist_find(us->adjustments, adj)); - - g_object_ref(adj); - us->adjustments = g_slist_prepend(us->adjustments, adj); -} - -void -sp_unit_selector_remove_adjustment(SPUnitSelector *us, GtkAdjustment *adj) -{ - g_return_if_fail(us != NULL); - g_return_if_fail(SP_IS_UNIT_SELECTOR(us)); - g_return_if_fail(adj != NULL); - g_return_if_fail(GTK_IS_ADJUSTMENT(adj)); - - g_return_if_fail(g_slist_find(us->adjustments, adj)); - - us->adjustments = g_slist_remove(us->adjustments, adj); - g_object_unref(adj); -} - -gboolean -sp_unit_selector_update_test(SPUnitSelector const *selector) -{ - g_return_val_if_fail(selector != NULL, FALSE); - g_return_val_if_fail(SP_IS_UNIT_SELECTOR(selector), FALSE); - - return selector->update; -} - -double -sp_unit_selector_get_value_in_pixels(SPUnitSelector const *selector, GtkAdjustment *adj) -{ - g_return_val_if_fail(selector != NULL, gtk_adjustment_get_value (adj)); - g_return_val_if_fail(SP_IS_UNIT_SELECTOR(selector), gtk_adjustment_get_value (adj)); - - return sp_units_get_pixels(gtk_adjustment_get_value (adj), *(selector->unit)); -} - -void -sp_unit_selector_set_value_in_pixels(SPUnitSelector *selector, GtkAdjustment *adj, double value) -{ - g_return_if_fail(selector != NULL); - g_return_if_fail(SP_IS_UNIT_SELECTOR(selector)); - - gtk_adjustment_set_value(adj, sp_pixels_get_units(value, *(selector->unit))); -} - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/helper/unit-menu.h b/src/helper/unit-menu.h deleted file mode 100644 index b3ee6bcd1..000000000 --- a/src/helper/unit-menu.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef SP_UNIT_MENU_H -#define SP_UNIT_MENU_H - -/* - * SPUnitMenu - * - * Generic (and quite unintelligent) grid item for gnome canvas - * - * Copyright (C) Lauris Kaplinski 2000 - * - */ - -#include -#include - -struct SPUnit; -struct SPUnitSelector; -struct SPUnitSelectorClass; - -/* Unit selector Widget */ - -#define SP_TYPE_UNIT_SELECTOR (sp_unit_selector_get_type()) -#define SP_UNIT_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_UNIT_SELECTOR, SPUnitSelector)) -#define SP_UNIT_SELECTOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), SP_TYPE_UNIT_SELECTOR, SPUnitSelectorClass)) -#define SP_IS_UNIT_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_UNIT_SELECTOR)) -#define SP_IS_UNIT_SELECTOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), SP_TYPE_UNIT_SELECTOR)) - -GType sp_unit_selector_get_type(void); - -GtkWidget *sp_unit_selector_new(guint bases); -void sp_unit_selector_setsize(GtkWidget *us, guint w, guint h); - -SPUnit const *sp_unit_selector_get_unit(SPUnitSelector const *selector); - -void sp_unit_selector_set_bases(SPUnitSelector *selector, guint bases); -void sp_unit_selector_add_unit(SPUnitSelector *selector, SPUnit const *unit, int position); - -void sp_unit_selector_set_unit(SPUnitSelector *selector, SPUnit const *unit); -void sp_unit_selector_add_adjustment(SPUnitSelector *selector, GtkAdjustment *adjustment); -void sp_unit_selector_remove_adjustment(SPUnitSelector *selector, GtkAdjustment *adjustment); - -gboolean sp_unit_selector_update_test(SPUnitSelector const *selector); - -double sp_unit_selector_get_value_in_pixels(SPUnitSelector const *selector, GtkAdjustment *adj); -void sp_unit_selector_set_value_in_pixels(SPUnitSelector *selector, GtkAdjustment *adj, double value); - - - -#endif // SP_UNIT_MENU_H - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/helper/units-test.h b/src/helper/units-test.h deleted file mode 100644 index 05bc75eff..000000000 --- a/src/helper/units-test.h +++ /dev/null @@ -1,90 +0,0 @@ -#include - -#include -#include -#include - -class UnitsTest : public CxxTest::TestSuite { -public: - - UnitsTest() - { - } - virtual ~UnitsTest() {} - -// createSuite and destroySuite get us per-suite setup and teardown -// without us having to worry about static initialization order, etc. - static UnitsTest *createSuite() { return new UnitsTest(); } - static void destroySuite( UnitsTest *suite ) { delete suite; } - - void testConversions() - { - struct Case { double x; char const *abbr; double pts; } const tests[] = { - { 1.0, "pt", 1.0 }, - { 5.0, "pt", 5.0 }, - { 1.0, "in", 72.0 }, - { 2.0, "in", 144.0 }, - { 254., "mm", 720.0 }, - { 254., "cm", 7200. }, - { 254., "m", 720000. }, - { 1.5, "mm", (15 * 72. / 254) } - }; - for (unsigned i = 0; i < G_N_ELEMENTS(tests); ++i) { - Case const &c = tests[i]; - SPUnit const &unit = *sp_unit_get_by_abbreviation(N_(c.abbr)); - - double const calc_pts = sp_units_get_points(c.x, unit); - TS_ASSERT(approx_equal(calc_pts, c.pts)); - - double const calc_x = sp_points_get_units(c.pts, unit); - TS_ASSERT(approx_equal(calc_x, c.x)); - - double tmp = c.x; - bool const converted_to_pts = sp_convert_distance(&tmp, &unit, SP_PS_UNIT); - TS_ASSERT(converted_to_pts); - TS_ASSERT(approx_equal(tmp, c.pts)); - - tmp = c.pts; - bool const converted_from_pts = sp_convert_distance(&tmp, SP_PS_UNIT, &unit); - TS_ASSERT(converted_from_pts); - TS_ASSERT(approx_equal(tmp, c.x)); - } - } - - void testUnitTable() - { - TS_ASSERT(sp_units_table_sane()); - } - -private: - /* N.B. Wrongly returns false if both near 0. (Not a problem for current users.) */ - bool approx_equal(double const x, double const y) - { - return fabs(x / y - 1) < 1e-15; - } - - double sp_units_get_points(double const x, SPUnit const &unit) - { - SPUnit const &pt_unit = sp_unit_get_by_id(SP_UNIT_PT); - double const px = sp_units_get_pixels(x, unit); - return sp_pixels_get_units(px, pt_unit); - } - - double sp_points_get_units(double const pts, SPUnit const &unit) - { - SPUnit const &pt_unit = sp_unit_get_by_id(SP_UNIT_PT); - double const px = sp_units_get_pixels(pts, pt_unit); - return sp_pixels_get_units(px, unit); - } -}; - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/helper/units.cpp b/src/helper/units.cpp deleted file mode 100644 index 1593fc131..000000000 --- a/src/helper/units.cpp +++ /dev/null @@ -1,261 +0,0 @@ -#define __SP_PAPER_C__ - -/* - * SPUnit - * - * Ported from libgnomeprint - * - * Authors: - * Dirk Luetjens - * Yves Arrouye - * Lauris Kaplinski - * bulia byak - * - * Copyright 1999-2001 Ximian, Inc. and authors - * - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "helper/units.h" -#include // g_assert() -#include -#include "unit-constants.h" -#include "svg/svg-length.h" - -/* todo: use some fancy unit program */ - -/* The order determines the order of the list returned by sp_unit_get_list. - * (It can also affect string lookups if there are any duplicates in the - * current locale... hopefully none.) If you re-order this list, then you must - * also re-order the SPUnitId enum values accordingly. Run `make check' (which - * calls sp_unit_table_sane) to ensure that the two are in sync. - */ -SPUnit const sp_units[] = { - {SP_UNIT_SCALE, SP_UNIT_DIMENSIONLESS, 1.0, SP_NONE, SVGLength::NONE, N_("Unit"), "", N_("Units"), ""}, - {SP_UNIT_PT, SP_UNIT_ABSOLUTE, PX_PER_PT, SP_PT, SVGLength::PT, N_("Point"), N_("pt"), N_("Points"), N_("Pt")}, - {SP_UNIT_PC, SP_UNIT_ABSOLUTE, PX_PER_PC, SP_PC, SVGLength::PC, N_("Pica"), N_("pc"), N_("Picas"), N_("Pc")}, - {SP_UNIT_PX, SP_UNIT_DEVICE, PX_PER_PX, SP_PX, SVGLength::PX, N_("Pixel"), N_("px"), N_("Pixels"), N_("Px")}, - /* You can add new elements from this point forward */ - {SP_UNIT_PERCENT, SP_UNIT_DIMENSIONLESS, 0.01, SP_NONE, SVGLength::PERCENT, N_("Percent"), N_("%"), N_("Percents"), N_("%")}, - {SP_UNIT_MM, SP_UNIT_ABSOLUTE, PX_PER_MM, SP_MM, SVGLength::MM, N_("Millimeter"), N_("mm"), N_("Millimeters"), N_("mm")}, - {SP_UNIT_CM, SP_UNIT_ABSOLUTE, PX_PER_CM, SP_CM, SVGLength::CM, N_("Centimeter"), N_("cm"), N_("Centimeters"), N_("cm")}, - {SP_UNIT_M, SP_UNIT_ABSOLUTE, PX_PER_M, SP_M, SVGLength::NONE, N_("Meter"), N_("m"), N_("Meters"), N_("m")}, // no svg_unit - {SP_UNIT_IN, SP_UNIT_ABSOLUTE, PX_PER_IN, SP_IN, SVGLength::INCH, N_("Inch"), N_("in"), N_("Inches"), N_("in")}, - {SP_UNIT_FT, SP_UNIT_ABSOLUTE, PX_PER_FT, SP_FT, SVGLength::FOOT, N_("Foot"), N_("ft"), N_("Feet"), N_("ft")}, - /* Volatiles do not have default, so there are none here */ - // TRANSLATORS: for info, see http://www.w3.org/TR/REC-CSS2/syndata.html#length-units - {SP_UNIT_EM, SP_UNIT_VOLATILE, 1.0, SP_NONE, SVGLength::EM, N_("Em square"), N_("em"), N_("Em squares"), N_("em")}, - // TRANSLATORS: for info, see http://www.w3.org/TR/REC-CSS2/syndata.html#length-units - {SP_UNIT_EX, SP_UNIT_VOLATILE, 1.0, SP_NONE, SVGLength::EX, N_("Ex square"), N_("ex"), N_("Ex squares"), N_("ex")}, -}; - -#define sp_num_units G_N_ELEMENTS(sp_units) - -SPUnit const * -sp_unit_get_by_abbreviation(gchar const *abbreviation) -{ - g_return_val_if_fail(abbreviation != NULL, NULL); - - for (unsigned i = 0 ; i < sp_num_units ; i++) { - if (!g_ascii_strcasecmp(abbreviation, sp_units[i].abbr)) return &sp_units[i]; - if (!g_ascii_strcasecmp(abbreviation, sp_units[i].abbr_plural)) return &sp_units[i]; - } - - return NULL; -} - -gchar const * -sp_unit_get_abbreviation(SPUnit const *unit) -{ - g_return_val_if_fail(unit != NULL, NULL); - - return unit->abbr; -} - -gchar const * -sp_unit_get_plural (SPUnit const *unit) -{ - g_return_val_if_fail(unit != NULL, NULL); - - return unit->plural; -} - -SPMetric sp_unit_get_metric(SPUnit const *unit) -{ - g_return_val_if_fail(unit != NULL, SP_NONE); - - return unit->metric; -} - -guint sp_unit_get_svg_unit(SPUnit const *unit) -{ - g_return_val_if_fail(unit != NULL, SP_NONE); - - return unit->svg_unit; -} - -GSList * -sp_unit_get_list(guint bases) -{ - g_return_val_if_fail((bases & ~SP_UNITS_ALL) == 0, NULL); - - GSList *units = NULL; - for (unsigned i = sp_num_units ; i--; ) { - if (bases & sp_units[i].base) { - units = g_slist_prepend(units, (gpointer) &sp_units[i]); - } - } - - return units; -} - -void -sp_unit_free_list(GSList *units) -{ - g_slist_free(units); -} - -/* These are pure utility */ -/* Return TRUE if conversion is possible */ -gboolean -sp_convert_distance(gdouble *distance, SPUnit const *from, SPUnit const *to) -{ - g_return_val_if_fail(distance != NULL, FALSE); - g_return_val_if_fail(from != NULL, FALSE); - g_return_val_if_fail(to != NULL, FALSE); - - if (from == to) return TRUE; - if ((from->base == SP_UNIT_DIMENSIONLESS) || (to->base == SP_UNIT_DIMENSIONLESS)) { - *distance = *distance * from->unittobase / to->unittobase; - return TRUE; - } - if ((from->base == SP_UNIT_VOLATILE) || (to->base == SP_UNIT_VOLATILE)) return FALSE; - - if ((from->base == to->base) - || ((from->base == SP_UNIT_DEVICE) && (to->base == SP_UNIT_ABSOLUTE)) - || ((from->base == SP_UNIT_ABSOLUTE) && (to->base == SP_UNIT_DEVICE))) - { - *distance = *distance * from->unittobase / to->unittobase; - return TRUE; - } - - return FALSE; -} - -/** @param devicetransform for device units. */ -/* TODO: Remove the ctmscale parameter given that we no longer have SP_UNIT_USERSPACE. */ -gdouble -sp_convert_distance_full(gdouble const from_dist, SPUnit const &from, SPUnit const &to) -{ - if (&from == &to) { - return from_dist; - } - if (from.base == to.base) { - gdouble ret = from_dist; - bool const succ = sp_convert_distance(&ret, &from, &to); - g_assert(succ); - return ret; - } - if ((from.base == SP_UNIT_DIMENSIONLESS) - || (to.base == SP_UNIT_DIMENSIONLESS)) - { - return from_dist * from.unittobase / to.unittobase; - } - g_return_val_if_fail(((from.base != SP_UNIT_VOLATILE) - && (to.base != SP_UNIT_VOLATILE)), - from_dist); - - gdouble absolute; - switch (from.base) { - case SP_UNIT_ABSOLUTE: - case SP_UNIT_DEVICE: - absolute = from_dist * from.unittobase; - break; - default: - g_warning("file %s: line %d: Illegal unit (base 0x%x)", __FILE__, __LINE__, from.base); - return from_dist; - } - - gdouble ret; - switch (to.base) { - default: - g_warning("file %s: line %d: Illegal unit (base 0x%x)", __FILE__, __LINE__, to.base); - /* FALL-THROUGH */ - case SP_UNIT_ABSOLUTE: - case SP_UNIT_DEVICE: - ret = absolute / to.unittobase; - break; - } - - return ret; -} - -/* Some more convenience */ - -gdouble -sp_units_get_pixels(gdouble const units, SPUnit const &unit) -{ - if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) { - return units * unit.unittobase; - } else { - g_warning("Different unit bases: No exact unit conversion available"); - return units * unit.unittobase; - } -} - -gdouble -sp_pixels_get_units(gdouble const pixels, SPUnit const &unit) -{ - if (unit.base == SP_UNIT_ABSOLUTE || unit.base == SP_UNIT_DEVICE) { - return pixels / unit.unittobase; - } else { - g_warning("Different unit bases: No exact unit conversion available"); - return pixels / unit.unittobase; - } -} - -bool -sp_units_table_sane() -{ - for (unsigned i = 0; i < G_N_ELEMENTS(sp_units); ++i) { - if (unsigned(sp_units[i].unit_id) != i) { - return false; - } - } - return true; -} - -/** Converts angle (in deg) to compass display */ -double -angle_to_compass(double angle) -{ - double ret = 90 - angle; - if (ret < 0) - ret = 360 + ret; - return ret; -} - -/** Converts angle (in deg) to compass display */ -double -angle_from_compass(double angle) -{ - double ret = 90 - angle; - if (ret > 180) - ret = ret - 180; - return ret; -} - - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/helper/units.h b/src/helper/units.h deleted file mode 100644 index 93bd70615..000000000 --- a/src/helper/units.h +++ /dev/null @@ -1,146 +0,0 @@ -#ifndef __SP_UNIT_H__ -#define __SP_UNIT_H__ - -/* - * SPUnit - * - * Ported from libgnomeprint - * - * Authors: - * Dirk Luetjens - * Yves Arrouye - * Lauris Kaplinski - * - * Copyright 1999-2001 Ximian, Inc. and authors - * - */ - -#include -#include "sp-metric.h" - - -/* - * Units and conversion methods used by libgnomeprint. - * - * You need those for certain config keys (like paper size), if you are - * interested in using these (look at gnome-print-config.h for discussion, - * why you may NOT be interested in paper size). - * - * Unit bases define set of mutually unrelated measuring systems (numbers, - * paper, screen and dimesionless user coordinates). Still, you can convert - * between those, specifying scaling factors explicitly. - * - * Paper (i.e. output) coordinates are taken as absolute real world units. - * It has some justification, because screen unit (pixel) size changes, - * if you change screen resolution, while you cannot change output on paper - * as easily (unless you have thermally contracting paper, of course). - * - */ - -struct SPUnit; -struct SPDistance; - -/* - * The base linear ("absolute") unit is 1/72th of an inch, i.e. the base unit of postscript. - */ - -/* - * Unit bases - */ -enum SPUnitBase { - SP_UNIT_DIMENSIONLESS = (1 << 0), /* For percentages and like */ - SP_UNIT_ABSOLUTE = (1 << 1), /* Real world distances - i.e. mm, cm... */ - SP_UNIT_DEVICE = (1 << 2), /* Pixels in the SVG/CSS sense. */ - SP_UNIT_VOLATILE = (1 << 3) /* em and ex */ -}; - -/* - * Units: indexes into sp_units. - */ -enum SPUnitId { - SP_UNIT_SCALE, // 1.0 == 100% - SP_UNIT_PT, // Postscript points: exactly 72 per inch - SP_UNIT_PC, // Pica; there are 12 points per pica - SP_UNIT_PX, // "Pixels" in the CSS sense; though Inkscape assumes a constant 90 per inch. - SP_UNIT_PERCENT, /* Note: In Inkscape this often means "relative to current value" (for - users to edit a value), rather than the SVG/CSS use of percentages. */ - SP_UNIT_MM, // millimetres - SP_UNIT_CM, // centimetres - SP_UNIT_M, // metres - SP_UNIT_IN, // inches - SP_UNIT_FT, // foot - SP_UNIT_EM, // font-size of relevant font - SP_UNIT_EX, // x-height of relevant font - sp_max_unit_id = SP_UNIT_EX // For bounds-checking in sp_unit_get_by_id. -}; - -/* - * Notice, that for correct menus etc. you have to use - * ngettext method family yourself. For that reason we - * do not provide translations in unit names. - * I also do not know, whether to allow user-created units, - * because this would certainly confuse textdomain. - */ - -struct SPUnit { - SPUnitId unit_id; /* used as sanity check */ - SPUnitBase base; - gdouble unittobase; /* how many base units in this unit */ - SPMetric metric; // the corresponding SPMetric from sp-metrics.h - guint svg_unit; // the corresponding SVGLengthUnit - - /* When using, you must call "gettext" on them so they're translated */ - gchar const *name; - gchar const *abbr; - gchar const *plural; - gchar const *abbr_plural; -}; - -const SPUnit *sp_unit_get_by_abbreviation (const gchar *abbreviation); -/* When using, you must call "gettext" on them so they're translated */ -const gchar *sp_unit_get_abbreviation (const SPUnit *unit); -gchar const *sp_unit_get_plural (SPUnit const *unit); - -SPMetric sp_unit_get_metric(SPUnit const *unit); -guint sp_unit_get_svg_unit(SPUnit const *unit); - -extern SPUnit const sp_units[]; - -inline SPUnit const & -sp_unit_get_by_id(SPUnitId const id) -{ - /* inline because the compiler should optimize away the g_return_val_if_fail test in the - usual case that the argument value is known at compile-time, leaving just - "return sp_units[constant]". */ - unsigned const ix = unsigned(id); - g_return_val_if_fail(ix <= sp_max_unit_id, sp_units[SP_UNIT_PX]); - return sp_units[ix]; -} - -#define SP_PS_UNIT (&sp_unit_get_by_id(SP_UNIT_PT)) - - -/** Used solely by units-test.cpp. */ -bool sp_units_table_sane(); - -#define SP_UNITS_ALL (SP_UNIT_DIMENSIONLESS | SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE | SP_UNIT_VOLATILE) - -GSList *sp_unit_get_list (guint bases); -void sp_unit_free_list (GSList *units); - -/* These are pure utility */ -/* Return TRUE if conversion is possible, FALSE if unit bases differ */ -gboolean sp_convert_distance (gdouble *distance, const SPUnit *from, const SPUnit *to); - -/* If either one is NULL, transconverting to/from that base fails */ -/* Generic conversion between volatile units would be useless anyways */ -gdouble sp_convert_distance_full(gdouble const from_dist, SPUnit const &from, SPUnit const &to); - -/* Some more convenience */ -gdouble sp_units_get_pixels(gdouble const units, SPUnit const &unit); -gdouble sp_pixels_get_units(gdouble const pixels, SPUnit const &unit); - -double angle_to_compass(double angle); -double angle_from_compass(double angle); - -#endif diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 491ca6050..53d53345a 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -32,7 +32,6 @@ #include -struct SPUnit; class SPDocument; namespace Gtk { -- cgit v1.2.3 From 86abdc99654356a2047571e907b933505dbfab76 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sat, 20 Jul 2013 14:45:18 -0400 Subject: Add string output functions for units. (bzr r12380.1.46) --- src/util/units.cpp | 13 +++++++++++++ src/util/units.h | 3 +++ 2 files changed, 16 insertions(+) (limited to 'src') diff --git a/src/util/units.cpp b/src/util/units.cpp index dcb3ae4b1..01424520b 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -501,6 +502,18 @@ double Quantity::value(const Glib::ustring u) const return value(unit_table.getUnit(u)); } +/** Return a printable string of the value in the specified unit. */ +Glib::ustring Quantity::string(const Unit &u) const { + return Glib::ustring::format(std::fixed, std::setprecision(2), value(u)) + " " + unit->abbr; +} +Glib::ustring Quantity::string(const Glib::ustring u) const { + static UnitTable unit_table; + return string(unit_table.getUnit(u)); +} +Glib::ustring Quantity::string() const { + return string(*unit); +} + /** Convert distances. */ double Quantity::convert(const double from_dist, const Unit &from, const Unit &to) { diff --git a/src/util/units.h b/src/util/units.h index 392e51e7a..0bbe604ef 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -94,6 +94,9 @@ public: bool compatibleWith(const Glib::ustring u) const; double value(const Unit &u) const; double value(const Glib::ustring u) const; + Glib::ustring string(const Unit &u) const; + Glib::ustring string(const Glib::ustring u) const; + Glib::ustring string() const; static double convert(const double from_dist, const Unit &from, const Unit &to); static double convert(const double from_dist, const Glib::ustring from, const Unit &to); -- cgit v1.2.3 From fdf69629c66f6c1a69d88a00bb6c1311c97b631b Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sat, 20 Jul 2013 15:08:31 -0400 Subject: Ported away from and removed "sp-metrics.*". (bzr r12380.1.47) --- src/CMakeLists.txt | 2 - src/Makefile_insert | 1 - src/arc-context.cpp | 7 +- src/box3d-context.cpp | 1 - src/desktop-events.cpp | 1 - src/doxygen-main.cpp | 2 - src/flood-context.cpp | 1 - src/live_effects/lpe-path_length.cpp | 1 - src/pen-context.cpp | 4 +- src/rect-context.cpp | 7 +- src/seltrans.cpp | 13 ++-- src/sp-guide.cpp | 9 ++- src/sp-metrics.cpp | 120 ----------------------------------- src/sp-metrics.h | 20 ------ src/sp-text.cpp | 4 +- src/spiral-context.cpp | 4 +- src/star-context.cpp | 4 +- src/text-context.cpp | 7 +- src/ui/tool/node.cpp | 18 ++++-- 19 files changed, 44 insertions(+), 182 deletions(-) delete mode 100644 src/sp-metrics.cpp delete mode 100644 src/sp-metrics.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa54940db..f975f16bf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -46,7 +46,6 @@ set(sp_SRC sp-mesh-patch.cpp sp-mesh-row.cpp sp-metadata.cpp - sp-metrics.cpp sp-missing-glyph.cpp sp-namedview.cpp sp-object-group.cpp @@ -137,7 +136,6 @@ set(sp_SRC sp-mesh-row.h sp-metadata.h sp-metric.h - sp-metrics.h sp-missing-glyph.h sp-namedview.h sp-object-group.h diff --git a/src/Makefile_insert b/src/Makefile_insert index 88f809b52..ba14056e5 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -200,7 +200,6 @@ ink_common_sources += \ sp-mesh-row-fns.h \ sp-mesh-row.cpp sp-mesh-row.h \ sp-metric.h \ - sp-metrics.cpp sp-metrics.h \ sp-missing-glyph.cpp sp-missing-glyph.h \ sp-namedview.cpp sp-namedview.h \ sp-object.cpp sp-object.h \ diff --git a/src/arc-context.cpp b/src/arc-context.cpp index 34e4bbeab..115f45493 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -32,7 +32,6 @@ #include "desktop-handles.h" #include "snap.h" #include "pixmaps/cursor-ellipse.xpm" -#include "sp-metrics.h" #include "xml/repr.h" #include "xml/node-event-vector.h" #include "preferences.h" @@ -450,8 +449,10 @@ static void sp_arc_drag(SPArcContext *ac, Geom::Point pt, guint state) double rdimx = r.dimensions()[Geom::X]; double rdimy = r.dimensions()[Geom::Y]; - GString *xs = SP_PX_TO_METRIC_STRING(rdimx, desktop->namedview->getDefaultMetric()); - GString *ys = SP_PX_TO_METRIC_STRING(rdimy, desktop->namedview->getDefaultMetric()); + Inkscape::Util::Quantity rdimx_q = Inkscape::Util::Quantity(rdimx, "px"); + Inkscape::Util::Quantity rdimy_q = Inkscape::Util::Quantity(rdimy, "px"); + GString *xs = g_string_new(rdimx_q.string(*desktop->namedview->doc_units).c_str()); + GString *ys = g_string_new(rdimy_q.string(*desktop->namedview->doc_units).c_str()); if (state & GDK_CONTROL_MASK) { int ratio_x, ratio_y; if (fabs (rdimx) > fabs (rdimy)) { diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index a55aba00d..7491520de 100644 --- a/src/box3d-context.cpp +++ b/src/box3d-context.cpp @@ -35,7 +35,6 @@ #include "pixmaps/cursor-3dbox.xpm" #include "box3d.h" #include "box3d-context.h" -#include "sp-metrics.h" #include #include "xml/repr.h" #include "xml/node-event-vector.h" diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 473ccfa9f..5cb26abc0 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -39,7 +39,6 @@ #include "snap.h" #include "display/sp-canvas.h" #include "sp-guide.h" -#include "sp-metrics.h" #include "sp-namedview.h" #include "tools-switch.h" #include "verbs.h" diff --git a/src/doxygen-main.cpp b/src/doxygen-main.cpp index 04e5ab33e..d254299c8 100644 --- a/src/doxygen-main.cpp +++ b/src/doxygen-main.cpp @@ -334,8 +334,6 @@ namespace XML {} * * Inkscape::GC * - * [\ref sp-metrics.cpp, \ref sp-metrics.h] - * * [\ref prefs-utils.cpp] [\ref print.cpp] * * - Inkscape::GZipBuffer [\ref streams-gzip.h] diff --git a/src/flood-context.cpp b/src/flood-context.cpp index 8fde11f88..a719f1202 100644 --- a/src/flood-context.cpp +++ b/src/flood-context.cpp @@ -54,7 +54,6 @@ #include "sp-defs.h" #include "sp-item.h" #include "splivarot.h" -#include "sp-metrics.h" #include "sp-namedview.h" #include "sp-object.h" #include "sp-path.h" diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp index 504fb53c0..4ca380c15 100644 --- a/src/live_effects/lpe-path_length.cpp +++ b/src/live_effects/lpe-path_length.cpp @@ -14,7 +14,6 @@ #include #include "live_effects/lpe-path_length.h" -#include "sp-metrics.h" #include "util/units.h" #include "2geom/sbasis-geometric.h" diff --git a/src/pen-context.cpp b/src/pen-context.cpp index eac2ce5d1..69abf3513 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -22,7 +22,6 @@ #include "pen-context.h" #include "sp-namedview.h" -#include "sp-metrics.h" #include "desktop.h" #include "desktop-handles.h" #include "selection.h" @@ -1184,7 +1183,8 @@ static void spdc_pen_set_angle_distance_status_message(SPPenContext *const pc, G SPDesktop *desktop = SP_EVENT_CONTEXT(pc)->desktop; Geom::Point rel = p - pc->p[pc_point_to_compare]; - GString *dist = SP_PX_TO_METRIC_STRING(Geom::L2(rel), desktop->namedview->getDefaultMetric()); + Inkscape::Util::Quantity q = Inkscape::Util::Quantity(Geom::L2(rel), "px"); + GString *dist = g_string_new(q.string(*desktop->namedview->doc_units).c_str()); double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) { diff --git a/src/rect-context.cpp b/src/rect-context.cpp index 06745564f..17675745f 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -35,7 +35,6 @@ #include "message-context.h" #include "pixmaps/cursor-rect.xpm" #include "rect-context.h" -#include "sp-metrics.h" #include #include "xml/repr.h" #include "xml/node-event-vector.h" @@ -483,8 +482,10 @@ static void sp_rect_drag(SPRectContext &rc, Geom::Point const pt, guint state) // status text double rdimx = r.dimensions()[Geom::X]; double rdimy = r.dimensions()[Geom::Y]; - GString *xs = SP_PX_TO_METRIC_STRING(rdimx, desktop->namedview->getDefaultMetric()); - GString *ys = SP_PX_TO_METRIC_STRING(rdimy, desktop->namedview->getDefaultMetric()); + Inkscape::Util::Quantity rdimx_q = Inkscape::Util::Quantity(rdimx, "px"); + Inkscape::Util::Quantity rdimy_q = Inkscape::Util::Quantity(rdimy, "px"); + GString *xs = g_string_new(rdimx_q.string(*desktop->namedview->doc_units).c_str()); + GString *ys = g_string_new(rdimy_q.string(*desktop->namedview->doc_units).c_str()); if (state & GDK_CONTROL_MASK) { int ratio_x, ratio_y; bool is_golden_ratio = false; diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 33bfe3e4a..f614853bc 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -37,7 +37,6 @@ #include "seltrans-handles.h" #include "seltrans.h" #include "selection-chemistry.h" -#include "sp-metrics.h" #include "verbs.h" #include #include "display/sp-ctrlline.h" @@ -1273,8 +1272,10 @@ gboolean Inkscape::SelTrans::centerRequest(Geom::Point &pt, guint state) m.unSetup(); // status text - GString *xs = SP_PX_TO_METRIC_STRING(pt[Geom::X], _desktop->namedview->getDefaultMetric()); - GString *ys = SP_PX_TO_METRIC_STRING(pt[Geom::Y], _desktop->namedview->getDefaultMetric()); + Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(pt[Geom::X], "px"); + Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(pt[Geom::Y], "px"); + GString *xs = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str()); + GString *ys = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str()); _message_context.setF(Inkscape::NORMAL_MESSAGE, _("Move center to %s, %s"), xs->str, ys->str); g_string_free(xs, FALSE); g_string_free(ys, FALSE); @@ -1425,8 +1426,10 @@ void Inkscape::SelTrans::moveTo(Geom::Point const &xy, guint state) transform(move, norm); // status text - GString *xs = SP_PX_TO_METRIC_STRING(dxy[Geom::X], _desktop->namedview->getDefaultMetric()); - GString *ys = SP_PX_TO_METRIC_STRING(dxy[Geom::Y], _desktop->namedview->getDefaultMetric()); + Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dxy[Geom::X], "px"); + Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dxy[Geom::Y], "px"); + GString *xs = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str()); + GString *ys = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str()); _message_context.setF(Inkscape::NORMAL_MESSAGE, _("Move by %s, %s; with Ctrl to restrict to horizontal/vertical; with Shift to disable snapping"), xs->str, ys->str); g_string_free(xs, TRUE); g_string_free(ys, TRUE); diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 48596cbc0..961e53e04 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -35,7 +35,6 @@ #include #include #include -#include "sp-metrics.h" #include "inkscape.h" #include "desktop.h" #include "sp-namedview.h" @@ -463,10 +462,10 @@ char *sp_guide_description(SPGuide const *guide, const bool verbose) } else { SPNamedView *namedview = sp_document_namedview(guide->document, NULL); - GString *position_string_x = SP_PX_TO_METRIC_STRING(guide->point_on_line[X], - namedview->getDefaultMetric()); - GString *position_string_y = SP_PX_TO_METRIC_STRING(guide->point_on_line[Y], - namedview->getDefaultMetric()); + Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(guide->point_on_line[X], "px"); + Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(guide->point_on_line[Y], "px"); + GString *position_string_x = g_string_new(x_q.string(*namedview->doc_units).c_str()); + GString *position_string_y = g_string_new(y_q.string(*namedview->doc_units).c_str()); gchar *shortcuts = g_strdup_printf("; %s", _("Shift+drag to rotate, Ctrl+drag to move origin, Del to delete")); diff --git a/src/sp-metrics.cpp b/src/sp-metrics.cpp deleted file mode 100644 index 2b421cf05..000000000 --- a/src/sp-metrics.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include "sp-metrics.h" -#include "unit-constants.h" - -/* - * SPMetric handling and stuff - * I hope this will be usefull :-) - */ - -gdouble -sp_absolute_metric_to_metric (gdouble length_src, const SPMetric metric_src, const SPMetric metric_dst) -{ - gdouble src = 1; - gdouble dst = 1; - - switch (metric_src) { - case SP_M: - src = M_PER_IN; - break; - case SP_MM: - src = MM_PER_IN; - break; - case SP_CM: - src = CM_PER_IN; - break; - case SP_IN: - src = IN_PER_IN; - break; - case SP_FT: - src = FT_PER_IN; - break; - case SP_PT: - src = PT_PER_IN; - break; - case SP_PC: - src = PC_PER_IN; - break; - case SP_PX: - src = PX_PER_IN; - break; - case SP_NONE: - src = 1; - break; - } - - switch (metric_dst) { - case SP_M: - dst = M_PER_IN; - break; - case SP_MM: - dst = MM_PER_IN; - break; - case SP_CM: - dst = CM_PER_IN; - break; - case SP_IN: - dst = IN_PER_IN; - break; - case SP_FT: - dst = FT_PER_IN; - break; - case SP_PT: - dst = PT_PER_IN; - break; - case SP_PC: - dst = PC_PER_IN; - break; - case SP_PX: - dst = PX_PER_IN; - break; - case SP_NONE: - dst = 1; - break; - } - - return length_src * (dst/src); -} - -/** - * Create a human-readable string suitable for status-bar display. - */ -GString * -sp_metric_to_metric_string(gdouble const length, - SPMetric const metric_src, SPMetric const metric_dst, - gboolean const m) -{ - gdouble const len = sp_absolute_metric_to_metric(length, metric_src, metric_dst); - GString *str = g_string_new(""); - g_string_printf(str, "%0.02f", len); - /* We need a fixed number of fractional digits, because otherwise the live statusbar display of - * lengths will be too jerky */ - - if (m) { - char const *unit_str; - switch (metric_dst) { - case SP_M: unit_str = " m"; break; - case SP_MM: unit_str = " mm"; break; - case SP_CM: unit_str = " cm"; break; - case SP_IN: unit_str = "\""; break; - case SP_PT: unit_str = " pt"; break; - case SP_PX: unit_str = " px"; break; - default: unit_str = NULL; break; - } - if (unit_str) { - g_string_append(str, unit_str); - } - } - return str; -} - - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/sp-metrics.h b/src/sp-metrics.h deleted file mode 100644 index c2f968797..000000000 --- a/src/sp-metrics.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef SP_METRICS_H -#define SP_METRICS_H - -#include -#include "sp-metric.h" - -gdouble sp_absolute_metric_to_metric (gdouble length_src, const SPMetric metric_src, const SPMetric metric_dst); -GString * sp_metric_to_metric_string (gdouble length, const SPMetric metric_src, const SPMetric metric_dst, gboolean m); - -// convenience since we mostly deal with points -#define SP_METRIC_TO_PT(l,m) sp_absolute_metric_to_metric(l,m,SP_PT); -#define SP_PT_TO_METRIC(l,m) sp_absolute_metric_to_metric(l,SP_PT,m); - -#define SP_PT_TO_METRIC_STRING(l,m) sp_metric_to_metric_string(l, SP_PT, m, TRUE) -#define SP_PT_TO_STRING(l,m) sp_metric_to_metric_string(l, SP_PT, m, FALSE) - -#define SP_PX_TO_METRIC_STRING(l,m) sp_metric_to_metric_string(l, SP_PX, m, TRUE) -#define SP_PX_TO_STRING(l,m) sp_metric_to_metric_string(l, SP_PX, m, FALSE) - -#endif diff --git a/src/sp-text.cpp b/src/sp-text.cpp index 8d42b7d59..d84bbdc6c 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -43,7 +43,6 @@ #include "sp-namedview.h" #include "style.h" #include "inkscape.h" -#include "sp-metrics.h" #include "xml/quote.h" #include "xml/repr.h" #include "mod360.h" @@ -392,7 +391,8 @@ static char * sp_text_description(SPItem *item) n = g_strdup(_("<no name found>")); } - GString *xs = SP_PX_TO_METRIC_STRING(style->font_size.computed, sp_desktop_namedview(SP_ACTIVE_DESKTOP)->getDefaultMetric()); + Inkscape::Util::Quantity q = Inkscape::Util::Quantity(style->font_size.computed, "px"); + GString *xs = g_string_new(q.string(*sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units).c_str()); char const *trunc = ""; Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) item); diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index b7bf5aead..a6cdc6bc4 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -34,7 +34,6 @@ #include "message-context.h" #include "pixmaps/cursor-spiral.xpm" #include "spiral-context.h" -#include "sp-metrics.h" #include #include "xml/repr.h" #include "xml/node-event-vector.h" @@ -437,7 +436,8 @@ static void sp_spiral_drag(SPSpiralContext *sc, Geom::Point const &p, guint stat /*t0*/ sc->t0); /* status text */ - GString *rads = SP_PX_TO_METRIC_STRING(rad, desktop->namedview->getDefaultMetric()); + Inkscape::Util::Quantity q = Inkscape::Util::Quantity(rad, "px"); + GString *rads = g_string_new(q.string(*desktop->namedview->doc_units).c_str()); sc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Spiral: radius %s, angle %5g°; with Ctrl to snap angle"), rads->str, sp_round((arg + 2.0*M_PI*spiral->revo)*180/M_PI, 0.0001)); diff --git a/src/star-context.cpp b/src/star-context.cpp index 5fb33a180..d4996e189 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -36,7 +36,6 @@ #include "desktop-style.h" #include "message-context.h" #include "pixmaps/cursor-star.xpm" -#include "sp-metrics.h" #include #include "preferences.h" #include "xml/repr.h" @@ -450,7 +449,8 @@ static void sp_star_drag(SPStarContext *sc, Geom::Point p, guint state) arg1, arg1 + M_PI / sides, sc->isflatsided, sc->rounded, sc->randomized); /* status text */ - GString *rads = SP_PX_TO_METRIC_STRING(r1, desktop->namedview->getDefaultMetric()); + Inkscape::Util::Quantity q = Inkscape::Util::Quantity(r1, "px"); + GString *rads = g_string_new(q.string(*desktop->namedview->doc_units).c_str()); sc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, ( sc->isflatsided? _("Polygon: radius %s, angle %5g°; with Ctrl to snap angle") diff --git a/src/text-context.cpp b/src/text-context.cpp index 862c50737..719a82156 100644 --- a/src/text-context.cpp +++ b/src/text-context.cpp @@ -42,7 +42,6 @@ #include "selection.h" #include "shape-editor.h" #include "sp-flowtext.h" -#include "sp-metrics.h" #include "sp-namedview.h" #include "sp-text.h" #include "style.h" @@ -640,8 +639,10 @@ static gint sp_text_context_root_handler(SPEventContext *const event_context, Gd gobble_motion_events(GDK_BUTTON1_MASK); // status text - GString *xs = SP_PX_TO_METRIC_STRING(fabs((p - tc->p0)[Geom::X]), desktop->namedview->getDefaultMetric()); - GString *ys = SP_PX_TO_METRIC_STRING(fabs((p - tc->p0)[Geom::Y]), desktop->namedview->getDefaultMetric()); + Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(fabs((p - tc->p0)[Geom::X]), "px"); + Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(fabs((p - tc->p0)[Geom::Y]), "px"); + GString *xs = g_string_new(x_q.string(*desktop->namedview->doc_units).c_str()); + GString *ys = g_string_new(y_q.string(*desktop->namedview->doc_units).c_str()); event_context->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("Flowed text frame: %s × %s"), xs->str, ys->str); g_string_free(xs, FALSE); g_string_free(ys, FALSE); diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index dc6e0fbae..82eb697bd 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -22,7 +22,6 @@ #include "preferences.h" #include "snap.h" #include "snap-preferences.h" -#include "sp-metrics.h" #include "sp-namedview.h" #include "ui/control-manager.h" #include "ui/tool/control-point-selection.h" @@ -490,9 +489,13 @@ Glib::ustring Handle::_getDragTip(GdkEventMotion */*event*/) const double angle = Geom::angle_between(Geom::Point(-1,0), position() - _parent->position()); angle += M_PI; // angle is (-M_PI...M_PI] - offset by +pi and scale to 0...360 angle *= 360.0 / (2 * M_PI); - GString *x = SP_PX_TO_METRIC_STRING(dist[Geom::X], _desktop->namedview->getDefaultMetric()); - GString *y = SP_PX_TO_METRIC_STRING(dist[Geom::Y], _desktop->namedview->getDefaultMetric()); - GString *len = SP_PX_TO_METRIC_STRING(length(), _desktop->namedview->getDefaultMetric()); + + Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dist[Geom::X], "px"); + Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dist[Geom::Y], "px"); + Inkscape::Util::Quantity len_q = Inkscape::Util::Quantity(length(), "px"); + GString *x = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str()); + GString *y = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str()); + GString *len = g_string_new(len_q.string(*_desktop->namedview->doc_units).c_str()); Glib::ustring ret = format_tip(C_("Path handle tip", "Move handle by %s, %s; angle %.2f°, length %s"), x->str, y->str, angle, len->str); g_string_free(x, TRUE); @@ -1294,8 +1297,11 @@ Glib::ustring Node::_getTip(unsigned state) const Glib::ustring Node::_getDragTip(GdkEventMotion */*event*/) const { Geom::Point dist = position() - _last_drag_origin(); - GString *x = SP_PX_TO_METRIC_STRING(dist[Geom::X], _desktop->namedview->getDefaultMetric()); - GString *y = SP_PX_TO_METRIC_STRING(dist[Geom::Y], _desktop->namedview->getDefaultMetric()); + + Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(dist[Geom::X], "px"); + Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(dist[Geom::Y], "px"); + GString *x = g_string_new(x_q.string(*_desktop->namedview->doc_units).c_str()); + GString *y = g_string_new(y_q.string(*_desktop->namedview->doc_units).c_str()); Glib::ustring ret = format_tip(C_("Path node tip", "Move node by %s, %s"), x->str, y->str); g_string_free(x, TRUE); -- cgit v1.2.3 From 4deb0f64f3bdab48475819a4d236f125594244f4 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sun, 21 Jul 2013 23:38:29 -0400 Subject: Ported "widgets/ruler.*" away from SPMetric. (bzr r12380.1.48) --- src/sp-namedview.cpp | 13 +++++++++++++ src/sp-namedview.h | 1 + src/widgets/desktop-widget.cpp | 17 +++++++++-------- src/widgets/ruler.cpp | 36 +++++++++++++++++++----------------- src/widgets/ruler.h | 11 ++++++++--- 5 files changed, 50 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index bf3adf816..d01185981 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -1138,6 +1138,19 @@ SPMetric SPNamedView::getDefaultMetric() const } } +/** + * Returns namedview's default unit. + */ +Inkscape::Util::Unit const SPNamedView::getDefaultUnit() const +{ + if (doc_units) { + return *doc_units; + } else { + Inkscape::Util::UnitTable unit_table; + return *(new Inkscape::Util::Unit(unit_table.getUnit("pt"))); + } +} + /** * Returns the first grid it could find that isEnabled(). Returns NULL, if none is enabled */ diff --git a/src/sp-namedview.h b/src/sp-namedview.h index f9629f0c6..7f7e81f1f 100644 --- a/src/sp-namedview.h +++ b/src/sp-namedview.h @@ -85,6 +85,7 @@ struct SPNamedView : public SPObjectGroup { guint getViewCount(); GSList const *getViewList() const; SPMetric getDefaultMetric() const; + Inkscape::Util::Unit const getDefaultUnit() const; void translateGuides(Geom::Translate const &translation); void translateGrids(Geom::Translate const &translation); diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 56a5baf5b..863912d03 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -393,9 +393,10 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) GtkWidget *eventbox = gtk_event_box_new (); dtw->hruler = sp_ruler_new(GTK_ORIENTATION_HORIZONTAL); dtw->hruler_box = eventbox; - sp_ruler_set_unit(SP_RULER(dtw->hruler), SP_PT); Inkscape::Util::UnitTable unit_table; - gtk_widget_set_tooltip_text (dtw->hruler_box, gettext(unit_table.getUnit("pt").name_plural.c_str())); + Inkscape::Util::Unit pt = unit_table.getUnit("pt"); + sp_ruler_set_unit(SP_RULER(dtw->hruler), pt); + gtk_widget_set_tooltip_text (dtw->hruler_box, gettext(pt.name_plural.c_str())); gtk_container_add (GTK_CONTAINER (eventbox), dtw->hruler); g_signal_connect (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (sp_dt_hruler_event), dtw); g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_hruler_event), dtw); @@ -423,8 +424,8 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) eventbox = gtk_event_box_new (); dtw->vruler = sp_ruler_new(GTK_ORIENTATION_VERTICAL); dtw->vruler_box = eventbox; - sp_ruler_set_unit (SP_RULER (dtw->vruler), SP_PT); - gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(unit_table.getUnit("pt").name_plural.c_str())); + sp_ruler_set_unit (SP_RULER (dtw->vruler), pt); + gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(pt.name_plural.c_str())); gtk_container_add (GTK_CONTAINER (eventbox), GTK_WIDGET (dtw->vruler)); #if GTK_CHECK_VERSION(3,0,0) @@ -1675,7 +1676,7 @@ SPDesktopWidget* SPDesktopWidget::createInstance(SPNamedView *namedview) { SPDesktopWidget *dtw = static_cast(g_object_new(SP_TYPE_DESKTOP_WIDGET, NULL)); - dtw->dt2r = namedview->doc_units->factor; + dtw->dt2r = 1. / namedview->doc_units->factor; dtw->ruler_origin = Geom::Point(0,0); //namedview->gridorigin; Why was the grid origin used here? @@ -1747,11 +1748,11 @@ void SPDesktopWidget::namedviewModified(SPObject *obj, guint flags) SPNamedView *nv=SP_NAMEDVIEW(obj); if (flags & SP_OBJECT_MODIFIED_FLAG) { - this->dt2r = nv->doc_units->factor; + this->dt2r = 1. / nv->doc_units->factor; this->ruler_origin = Geom::Point(0,0); //nv->gridorigin; Why was the grid origin used here? - sp_ruler_set_unit(SP_RULER (this->vruler), nv->getDefaultMetric()); - sp_ruler_set_unit(SP_RULER (this->hruler), nv->getDefaultMetric()); + sp_ruler_set_unit(SP_RULER (this->vruler), nv->getDefaultUnit()); + sp_ruler_set_unit(SP_RULER (this->hruler), nv->getDefaultUnit()); /* This loops through all the grandchildren of aux toolbox, * and for each that it finds, it performs an sp_search_by_data_recursive(), diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp index c1f9be2a5..274e1df54 100644 --- a/src/widgets/ruler.cpp +++ b/src/widgets/ruler.cpp @@ -33,9 +33,9 @@ #include "widget-sizes.h" #include "ruler.h" -#include "unit-constants.h" #include "round.h" #include +#include "util/units.h" #define ROUND(x) ((int) ((x) + 0.5)) @@ -62,7 +62,7 @@ enum { typedef struct { GtkOrientation orientation; - SPMetric unit; + Inkscape::Util::Unit *unit; gdouble lower; gdouble upper; gdouble position; @@ -196,11 +196,10 @@ sp_ruler_class_init (SPRulerClass *klass) /* FIXME: Should probably use g_param_spec_enum */ g_object_class_install_property (object_class, PROP_UNIT, - g_param_spec_uint ("unit", + g_param_spec_string ("unit", _("Unit"), _("Unit of the ruler"), - 0, 8, - SP_PX, + "px", static_cast(GTK_PARAM_READWRITE))); g_object_class_install_property (object_class, @@ -259,8 +258,10 @@ sp_ruler_init (SPRuler *ruler) gtk_widget_set_has_window (GTK_WIDGET (ruler), FALSE); + Inkscape::Util::UnitTable unit_table; + priv->orientation = GTK_ORIENTATION_HORIZONTAL; - priv->unit = SP_PX; + priv->unit = new Inkscape::Util::Unit(unit_table.getUnit("px")); priv->lower = 0; priv->upper = 0; priv->position = 0; @@ -379,6 +380,8 @@ sp_ruler_set_property (GObject *object, SPRuler *ruler = SP_RULER (object); SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + Inkscape::Util::UnitTable unit_table; + switch (prop_id) { case PROP_ORIENTATION: @@ -387,7 +390,7 @@ sp_ruler_set_property (GObject *object, break; case PROP_UNIT: - sp_ruler_set_unit (ruler, static_cast(g_value_get_int (value))); + sp_ruler_set_unit (ruler, unit_table.getUnit(g_value_get_string (value))); break; case PROP_LOWER: @@ -436,7 +439,7 @@ sp_ruler_get_property (GObject *object, break; case PROP_UNIT: - g_value_set_int (value, priv->unit); + g_value_set_string (value, priv->unit->abbr.c_str()); break; case PROP_LOWER: g_value_set_double (value, priv->lower); @@ -1071,15 +1074,15 @@ sp_ruler_remove_track_widget (SPRuler *ruler, */ void sp_ruler_set_unit (SPRuler *ruler, - SPMetric unit) + const Inkscape::Util::Unit &unit) { SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); g_return_if_fail (SP_IS_RULER (ruler)); - if (priv->unit != unit) + if (*priv->unit != unit) { - priv->unit = unit; + priv->unit = new Inkscape::Util::Unit(unit); g_object_notify(G_OBJECT(ruler), "unit"); gtk_widget_queue_draw (GTK_WIDGET (ruler)); @@ -1092,11 +1095,9 @@ sp_ruler_set_unit (SPRuler *ruler, * * Return value: the unit currently used in the @ruler widget. **/ -SPMetric +Inkscape::Util::Unit* sp_ruler_get_unit (SPRuler *ruler) { - g_return_val_if_fail(SP_IS_RULER(ruler), static_cast(0)); - return SP_RULER_GET_PRIVATE (ruler)->unit; } @@ -1184,10 +1185,11 @@ sp_ruler_draw_ticks (SPRuler *ruler) gint text_size; gint pos; gdouble max_size; - SPMetric unit; + Inkscape::Util::Unit *unit; SPRulerMetric ruler_metric = ruler_metric_general; /* The metric to use for this unit system */ PangoLayout *layout; PangoRectangle logical_rect, ink_rect; + Inkscape::Util::UnitTable unit_table; if (! gtk_widget_is_drawable (widget)) return; @@ -1300,7 +1302,7 @@ sp_ruler_draw_ticks (SPRuler *ruler) /* Inkscape change to ruler: Use a 1,2,4,8... scale for inches * or a 1,2,5,10... scale for everything else */ - if (sp_ruler_get_unit (ruler) == SP_IN) + if (*sp_ruler_get_unit (ruler) == unit_table.getUnit("in")) ruler_metric = ruler_metric_inches; for (scale = 0; scale < G_N_ELEMENTS (ruler_metric.ruler_scale); scale++) @@ -1319,7 +1321,7 @@ sp_ruler_draw_ticks (SPRuler *ruler) gdouble subd_incr; /* hack to get proper subdivisions at full pixels */ - if (unit == SP_PX && scale == 1 && i == 1) + if (*unit == unit_table.getUnit("px") && scale == 1 && i == 1) subd_incr = 1.0; else subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] / diff --git a/src/widgets/ruler.h b/src/widgets/ruler.h index f0d866fff..08760f584 100644 --- a/src/widgets/ruler.h +++ b/src/widgets/ruler.h @@ -14,10 +14,15 @@ */ #include -#include "sp-metric.h" #include #include +namespace Inkscape { + namespace Util { + class Unit; + } +} + G_BEGIN_DECLS #define SP_TYPE_RULER (sp_ruler_get_type ()) @@ -51,8 +56,8 @@ void sp_ruler_remove_track_widget (SPRuler *ruler, GtkWidget *widget); void sp_ruler_set_unit (SPRuler *ruler, - SPMetric unit); -SPMetric sp_ruler_get_unit (SPRuler *ruler); + const Inkscape::Util::Unit &unit); +Inkscape::Util::Unit *sp_ruler_get_unit (SPRuler *ruler); void sp_ruler_set_position (SPRuler *ruler, gdouble set_position); gdouble sp_ruler_get_position (SPRuler *ruler); -- cgit v1.2.3 From 0b2190b4a186f4b1a2265c85b4baa801d49e5534 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sun, 21 Jul 2013 23:50:53 -0400 Subject: Removed SPMetric. (bzr r12380.1.49) --- src/CMakeLists.txt | 1 - src/Makefile_insert | 1 - src/sp-metric.h | 28 ---------------------------- src/sp-namedview.cpp | 13 ------------- src/sp-namedview.h | 2 -- src/util/units.cpp | 22 ---------------------- src/util/units.h | 1 - 7 files changed, 68 deletions(-) delete mode 100644 src/sp-metric.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f975f16bf..b2af3809d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -135,7 +135,6 @@ set(sp_SRC sp-mesh-row-fns.h sp-mesh-row.h sp-metadata.h - sp-metric.h sp-missing-glyph.h sp-namedview.h sp-object-group.h diff --git a/src/Makefile_insert b/src/Makefile_insert index ba14056e5..32771b99f 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -199,7 +199,6 @@ ink_common_sources += \ sp-mesh-patch.cpp sp-mesh-patch.h \ sp-mesh-row-fns.h \ sp-mesh-row.cpp sp-mesh-row.h \ - sp-metric.h \ sp-missing-glyph.cpp sp-missing-glyph.h \ sp-namedview.cpp sp-namedview.h \ sp-object.cpp sp-object.h \ diff --git a/src/sp-metric.h b/src/sp-metric.h deleted file mode 100644 index 31f3330fa..000000000 --- a/src/sp-metric.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef INKSCAPE_SP_METRIC_H -#define INKSCAPE_SP_METRIC_H - -/** Known metrics so far. (I don't know why this doesn't include pica.) */ -enum SPMetric { - SP_NONE, - SP_MM, - SP_CM, - SP_IN, - SP_FT, - SP_PT, - SP_PC, - SP_PX, - SP_M -}; - -#endif /* !INKSCAPE_SP_METRIC_H */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index d01185981..dde205eed 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -1125,19 +1125,6 @@ double SPNamedView::getMarginLength(gchar const * const key, return value; } - -/** - * Returns namedview's default metric. - */ -SPMetric SPNamedView::getDefaultMetric() const -{ - if (doc_units) { - return (SPMetric) doc_units->metric(); - } else { - return SP_PT; - } -} - /** * Returns namedview's default unit. */ diff --git a/src/sp-namedview.h b/src/sp-namedview.h index 7f7e81f1f..26febd7d3 100644 --- a/src/sp-namedview.h +++ b/src/sp-namedview.h @@ -21,7 +21,6 @@ #define SP_IS_NAMEDVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_NAMEDVIEW)) #include "sp-object-group.h" -#include "sp-metric.h" #include "snap.h" #include "document.h" #include "util/units.h" @@ -84,7 +83,6 @@ struct SPNamedView : public SPObjectGroup { gchar const *getName() const; guint getViewCount(); GSList const *getViewList() const; - SPMetric getDefaultMetric() const; Inkscape::Util::Unit const getDefaultUnit() const; void translateGuides(Geom::Translate const &translation); diff --git a/src/util/units.cpp b/src/util/units.cpp index 01424520b..582c52090 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -187,28 +187,6 @@ int Unit::svgUnit() const return 0; } -/** Temporary - get metric. */ -int Unit::metric() const -{ - if (!abbr.compare("mm")) - return 1; - if (!abbr.compare("cm")) - return 2; - if (!abbr.compare("in")) - return 3; - if (!abbr.compare("ft")) - return 4; - if (!abbr.compare("pt")) - return 5; - if (!abbr.compare("pc")) - return 6; - if (!abbr.compare("px")) - return 7; - if (!abbr.compare("m")) - return 8; - return 0; -} - UnitTable::UnitTable() { // if we swich to the xml file, don't forget to force locale to 'C' diff --git a/src/util/units.h b/src/util/units.h index 0bbe604ef..99ba93c6b 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -80,7 +80,6 @@ class Unit { // temporary int svgUnit() const; - int metric() const; }; class Quantity { -- cgit v1.2.3 From 90edb3a743ab4e9fc18ff18844cc3624433cd3fc Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Mon, 29 Jul 2013 21:47:12 -0400 Subject: Update unit extraction regular expressions. (bzr r12380.1.50) --- src/util/units.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/util/units.cpp b/src/util/units.cpp index 582c52090..342c9ff32 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -228,14 +228,14 @@ Quantity UnitTable::getQuantity(Glib::ustring const& q) const // Extract value double value = 0; - Glib::RefPtr value_regex = Glib::Regex::create("\\d+\\.?\\d"); + Glib::RefPtr value_regex = Glib::Regex::create("[-+]*[\\d+]*\\.*[\\d+]*[eE]*[-+]*\\d+"); if (value_regex->match(q, match_info)) { value = atof(match_info.fetch(0).c_str()); } // Extract unit abbreviation Glib::ustring abbr; - Glib::RefPtr unit_regex = Glib::Regex::create("[A-z]+"); + Glib::RefPtr unit_regex = Glib::Regex::create("[A-z%]+"); if (unit_regex->match(q, match_info)) { abbr = match_info.fetch(0); } -- cgit v1.2.3 From 7aab446af9e2eb34ce50c8ef0ec58710fac49396 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Mon, 29 Jul 2013 22:51:28 -0400 Subject: Cleanup. (bzr r12380.1.52) --- src/ui/CMakeLists.txt | 2 ++ src/ui/dialog/guides.cpp | 2 +- src/ui/widget/page-sizer.cpp | 4 ++-- src/util/units.cpp | 9 --------- src/util/units.h | 13 ++++++++++++- src/widgets/measure-toolbar.cpp | 5 ----- src/widgets/text-toolbar.cpp | 6 ------ 7 files changed, 17 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index e831bcf69..b592d2527 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -112,6 +112,7 @@ set(ui_SRC widget/text.cpp widget/tolerance-slider.cpp widget/unit-menu.cpp + widget/unit-tracker.cpp view/view.cpp view/view-widget.cpp @@ -240,6 +241,7 @@ set(ui_SRC widget/text.h widget/tolerance-slider.h widget/unit-menu.h + widget/unit-tracker.h view/edit-widget-interface.h view/view-widget.h diff --git a/src/ui/dialog/guides.cpp b/src/ui/dialog/guides.cpp index 9a7b19c35..2de387364 100644 --- a/src/ui/dialog/guides.cpp +++ b/src/ui/dialog/guides.cpp @@ -230,7 +230,7 @@ void GuidelinePropertiesDialog::_setup() { _unit_menu.setUnitType(UNIT_TYPE_LINEAR); _unit_menu.setUnit("px"); if (_desktop->namedview->doc_units) { - //_unit_menu.setUnit( sp_unit_get_abbreviation(_desktop->namedview->doc_units) ); + _unit_menu.setUnit( _desktop->namedview->doc_units->abbr ); } _spin_angle.setUnit(_angle_unit_status); diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index f6392cfd8..b15ab2823 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -313,9 +313,9 @@ PageSizer::PageSizer(Registry & _wr) SPNamedView *nv = sp_desktop_namedview(dt); _wr.setUpdating (true); if (nv->units) { - //_dimensionUnits.setUnit(nv->units); + _dimensionUnits.setUnit(nv->units->abbr); } else if (nv->doc_units) { - //_dimensionUnits.setUnit(nv->doc_units); + _dimensionUnits.setUnit(nv->doc_units->abbr); } _wr.setUpdating (false); diff --git a/src/util/units.cpp b/src/util/units.cpp index f40e33c67..7f60eb391 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -132,7 +132,6 @@ int Unit::defaultDigits() const return factor_digits; } -/** Checks if a unit is compatible with the specified unit. */ bool Unit::compatibleWith(const Unit &u) const { // Percentages @@ -154,19 +153,16 @@ bool Unit::compatibleWith(const Glib::ustring u) const return compatibleWith(unit_table.getUnit(u)); } -/** Check if units are equal. */ bool operator== (const Unit &u1, const Unit &u2) { return (u1.type == u2.type && u1.name.compare(u2.name) == 0); } -/** Check if units are not equal. */ bool operator!= (const Unit &u1, const Unit &u2) { return !(u1 == u2); } -/** Temporary - get SVG unit. */ int Unit::svgUnit() const { if (!abbr.compare("px")) @@ -355,7 +351,6 @@ void UnitParser::on_end_element(Ctx &ctx, Glib::ustring const &name) } } -/** Initialize a quantity. */ Quantity::Quantity(double q, const Unit &u) { unit = new Unit(u); @@ -368,7 +363,6 @@ Quantity::Quantity(double q, const Glib::ustring u) quantity = q; } -/** Checks if a quantity is compatible with the specified unit. */ bool Quantity::compatibleWith(const Unit &u) const { return unit->compatibleWith(u); @@ -379,7 +373,6 @@ bool Quantity::compatibleWith(const Glib::ustring u) const return compatibleWith(unit_table.getUnit(u)); } -/** Return the quantity's value in the specified unit. */ double Quantity::value(const Unit &u) const { return convert(quantity, *unit, u); @@ -390,7 +383,6 @@ double Quantity::value(const Glib::ustring u) const return value(unit_table.getUnit(u)); } -/** Return a printable string of the value in the specified unit. */ Glib::ustring Quantity::string(const Unit &u) const { return Glib::ustring::format(std::fixed, std::setprecision(2), value(u)) + " " + unit->abbr; } @@ -402,7 +394,6 @@ Glib::ustring Quantity::string() const { return string(*unit); } -/** Convert distances. */ double Quantity::convert(const double from_dist, const Unit &from, const Unit &to) { // Percentage diff --git a/src/util/units.h b/src/util/units.h index 79b62be60..c30fa24b3 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -65,6 +65,7 @@ class Unit { */ int defaultDigits() const; + /** Checks if a unit is compatible with the specified unit. */ bool compatibleWith(const Unit &u) const; bool compatibleWith(const Glib::ustring) const; @@ -75,10 +76,12 @@ class Unit { Glib::ustring abbr; Glib::ustring description; + /** Check if units are equal. */ friend bool operator== (const Unit &u1, const Unit &u2); + /** Check if units are not equal. */ friend bool operator!= (const Unit &u1, const Unit &u2); - // temporary + /** Get SVG unit. */ int svgUnit() const; }; @@ -87,16 +90,24 @@ public: const Unit *unit; double quantity; + /** Initialize a quantity. */ Quantity(double q, const Unit &u); // constructor Quantity(double q, const Glib::ustring u); // constructor + + /** Checks if a quantity is compatible with the specified unit. */ bool compatibleWith(const Unit &u) const; bool compatibleWith(const Glib::ustring u) const; + + /** Return the quantity's value in the specified unit. */ double value(const Unit &u) const; double value(const Glib::ustring u) const; + + /** Return a printable string of the value in the specified unit. */ Glib::ustring string(const Unit &u) const; Glib::ustring string(const Glib::ustring u) const; Glib::ustring string() const; + /** Convert distances. */ static double convert(const double from_dist, const Unit &from, const Unit &to); static double convert(const double from_dist, const Glib::ustring from, const Unit &to); static double convert(const double from_dist, const Unit &from, const Glib::ustring to); diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index d51a81457..53ed2d275 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -93,9 +93,6 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G Inkscape::Preferences *prefs = Inkscape::Preferences::get(); tracker->setActiveUnitByAbbr(prefs->getString("/tools/measure/unit").c_str()); - //tracker->setUnitType(UNIT_TYPE_LINEAR); - //tracker->setUnit("px"); - g_object_set_data( holder, "tracker", tracker ); EgeAdjustmentAction *eact = 0; @@ -125,10 +122,8 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G // units menu { GtkAction* act = tracker->createAction( "MeasureUnitsAction", _("Units:"), _("The units to be used for the measurements") ); - //EgeOutputAction* act = ege_output_action_new( "MeasureUnitsAction", _("Units:"), _("The units to be used for the measurements"), 0 ); g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(measure_unit_changed), holder ); gtk_action_group_add_action( mainActions, act ); - //gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); } } // end of sp_measure_toolbox_prep() diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index a7bd25b2c..7554f4faf 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -1213,12 +1213,6 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); - // Is this used? - /*UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); - //tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); - tracker->setActiveUnit(&sp_unit_get_by_id(SP_UNIT_PX)); - g_object_set_data( holder, "tracker", tracker );*/ - /* Font family */ { // Font list -- cgit v1.2.3 From c135cb8c39a4004e9eb8adb227ba4c54848a8c45 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Wed, 31 Jul 2013 16:45:07 -0400 Subject: Added percent support back to select toolbar. (bzr r12380.1.53) --- src/ui/widget/unit-tracker.cpp | 9 ++++++++- src/ui/widget/unit-tracker.h | 1 + src/widgets/select-toolbar.cpp | 13 +++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp index 372419c3b..c0d3eec9b 100644 --- a/src/ui/widget/unit-tracker.cpp +++ b/src/ui/widget/unit-tracker.cpp @@ -111,6 +111,13 @@ void UnitTracker::addAdjustment(GtkAdjustment *adj) } } +void UnitTracker::addUnit(Inkscape::Util::Unit const &u) +{ + GtkTreeIter iter; + gtk_list_store_append(_store, &iter); + gtk_list_store_set(_store, &iter, COLUMN_STRING, u.abbr.c_str(), -1); +} + void UnitTracker::setFullVal(GtkAdjustment *adj, gdouble val) { _priorValues[adj] = val; @@ -232,7 +239,7 @@ void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape if ( (oldUnit.type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) && (newUnit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) ) { - val = newUnit.factor; + val = newUnit.factor * 100; _priorValues[adj] = Inkscape::Util::Quantity::convert(oldVal, oldUnit, "px"); } else if ( (oldUnit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) && (newUnit.type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) ) diff --git a/src/ui/widget/unit-tracker.h b/src/ui/widget/unit-tracker.h index 521fe50c8..cdcb07c57 100644 --- a/src/ui/widget/unit-tracker.h +++ b/src/ui/widget/unit-tracker.h @@ -39,6 +39,7 @@ public: void setActiveUnitByAbbr(gchar const *abbr); Inkscape::Util::Unit getActiveUnit() const; + void addUnit(Inkscape::Util::Unit const &u); void addAdjustment(GtkAdjustment *adj); void setFullVal(GtkAdjustment *adj, gdouble val); diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index 617757845..ab6d6ca3b 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -89,7 +89,7 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel) }; if (unit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) { - double const val = unit.factor; + double const val = unit.factor * 100; for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) { GtkAdjustment *a = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(spw), keyval[i].key)); gtk_adjustment_set_value(a, val); @@ -202,13 +202,13 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw) y1 = y0 + Quantity::convert(gtk_adjustment_get_value(a_h), unit, "px");; yrel = Quantity::convert(gtk_adjustment_get_value(a_h), unit, "px") / bbox_user->dimensions()[Geom::Y]; } else { - double const x0_propn = gtk_adjustment_get_value (a_x) * unit.factor; + double const x0_propn = gtk_adjustment_get_value (a_x) / 100 / unit.factor; x0 = bbox_user->min()[Geom::X] * x0_propn; - double const y0_propn = gtk_adjustment_get_value (a_y) * unit.factor; + double const y0_propn = gtk_adjustment_get_value (a_y) / 100 / unit.factor; y0 = y0_propn * bbox_user->min()[Geom::Y]; - xrel = gtk_adjustment_get_value (a_w) * unit.factor; + xrel = gtk_adjustment_get_value (a_w) / 100 / unit.factor; x1 = x0 + xrel * bbox_user->dimensions()[Geom::X]; - yrel = gtk_adjustment_get_value (a_h) * unit.factor; + yrel = gtk_adjustment_get_value (a_h) / 100 / unit.factor; y1 = y0 + yrel * bbox_user->dimensions()[Geom::Y]; } @@ -493,7 +493,8 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb // Create the units menu. UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); - //tracker->addUnit( SP_UNIT_PERCENT, 0 ); + Inkscape::Util::UnitTable unit_table; + tracker->addUnit(unit_table.getUnit("%")); tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); g_object_set_data( G_OBJECT(spw), "tracker", tracker ); -- 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/CMakeLists.txt | 1 - src/Makefile_insert | 1 - src/document.cpp | 4 +- src/doxygen-main.cpp | 2 +- src/extension/internal/cairo-render-context.cpp | 5 +-- src/extension/internal/cairo-renderer-pdf-out.cpp | 4 +- src/extension/internal/cairo-renderer.cpp | 18 ++++----- src/extension/internal/emf-win32-inout.cpp | 1 - src/extension/internal/emf-win32-print.cpp | 2 - src/extension/internal/gdkpixbuf-input.cpp | 4 +- src/extension/internal/latex-pstricks.cpp | 6 +-- src/extension/internal/latex-text-renderer.cpp | 4 +- src/extension/internal/pdfinput/pdf-parser.cpp | 8 ++-- src/extension/internal/pdfinput/svg-builder.cpp | 4 +- src/helper/pixbuf-ops.cpp | 4 +- src/main.cpp | 12 +++--- src/selection-chemistry.cpp | 14 +++---- src/sp-text.cpp | 1 - src/style.cpp | 32 +++++++-------- src/svg/svg-length.cpp | 14 +++---- src/text-editing.cpp | 12 +++--- src/ui/clipboard.cpp | 8 ++-- src/ui/dialog/export.cpp | 7 ++-- src/ui/dialog/inkscape-preferences.cpp | 8 ++-- src/ui/dialog/print.cpp | 12 +++--- src/ui/dialog/text-edit.cpp | 4 +- src/ui/widget/rendering-options.cpp | 6 +-- src/unit-constants.h | 47 ----------------------- src/widgets/font-selector.cpp | 1 - 29 files changed, 95 insertions(+), 151 deletions(-) delete mode 100644 src/unit-constants.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 537e13200..4f7592119 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -481,7 +481,6 @@ set(inkscape_SRC unclump.h undo-stack-observer.h unicoderange.h - unit-constants.h uri-references.h uri.h vanishing-point.h diff --git a/src/Makefile_insert b/src/Makefile_insert index ff64dc183..429c725cd 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -250,7 +250,6 @@ ink_common_sources += \ unclump.cpp unclump.h \ undo-stack-observer.h \ unicoderange.cpp unicoderange.h \ - unit-constants.h \ uri.cpp uri.h \ uri-references.cpp uri-references.h \ vanishing-point.cpp vanishing-point.h \ 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(); } diff --git a/src/doxygen-main.cpp b/src/doxygen-main.cpp index 42eb5dd13..a1d3f3604 100644 --- a/src/doxygen-main.cpp +++ b/src/doxygen-main.cpp @@ -348,7 +348,7 @@ namespace XML {} * Inkscape::Whiteboard::UndoStackObserver [\ref undo-stack-observer.cpp, \ref composite-undo-stack-observer.cpp] * [\ref document-undo.cpp] * - * {\ref dialogs/} [\ref decimal-round.h] [\ref enums.h] [\ref unit-constants.h] + * {\ref dialogs/} [\ref decimal-round.h] [\ref enums.h] */ diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index d7a560f04..09b769229 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -44,12 +44,11 @@ #include "sp-pattern.h" #include "sp-mask.h" #include "sp-clippath.h" +#include "util/units.h" #ifdef WIN32 #include "libnrtype/FontFactory.h" // USE_PANGO_WIN32 #endif -#include - #include "cairo-render-context.h" #include "cairo-renderer.h" #include "extension/system.h" @@ -855,7 +854,7 @@ CairoRenderContext::_finishSurfaceSetup(cairo_surface_t *surface, cairo_matrix_t _surface = surface; if (_vector_based_target) { - cairo_scale(_cr, PT_PER_PX, PT_PER_PX); + cairo_scale(_cr, Inkscape::Util::Quantity::convert(1, "px", "pt"), Inkscape::Util::Quantity::convert(1, "px", "pt")); } else if (cairo_surface_get_content(_surface) != CAIRO_CONTENT_ALPHA) { // set background color on non-alpha surfaces // TODO: bgcolor should be derived from SPDocument diff --git a/src/extension/internal/cairo-renderer-pdf-out.cpp b/src/extension/internal/cairo-renderer-pdf-out.cpp index 6f641fd36..da4cf1bc1 100644 --- a/src/extension/internal/cairo-renderer-pdf-out.cpp +++ b/src/extension/internal/cairo-renderer-pdf-out.cpp @@ -39,7 +39,7 @@ #include <2geom/affine.h> #include "document.h" -#include "unit-constants.h" +#include "util/units.h" namespace Inkscape { namespace Extension { @@ -197,7 +197,7 @@ CairoRendererPdfOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, float new_bleedmargin_px = 0.; try { - new_bleedmargin_px = mod->get_param_float("bleed") * PX_PER_MM; + new_bleedmargin_px = mod->get_param_float("bleed") * Inkscape::Util::Quantity::convert(1, "mm", "px"); } catch(...) { g_warning("Parameter might not exist"); diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index 0a3cff26a..f7ab63c98 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -55,7 +55,7 @@ #include "sp-mask.h" #include "sp-clippath.h" -#include +#include "util/units.h" #include "helper/png-write.h" #include "helper/pixbuf-ops.h" @@ -442,7 +442,7 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx) */ res = ctx->getBitmapResolution(); if(res == 0) { - res = PX_PER_IN; + res = Inkscape::Util::Quantity::convert(1, "in", "px"); } TRACE(("sp_asbitmap_render: resolution: %f\n", res )); @@ -463,8 +463,8 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx) } // The width and height of the bitmap in pixels - unsigned width = ceil(bbox->width() * (res / PX_PER_IN)); - unsigned height = ceil(bbox->height() * (res / PX_PER_IN)); + unsigned width = ceil(bbox->width() * (res / Inkscape::Util::Quantity::convert(1, "in", "px"))); + unsigned height = ceil(bbox->height() * (res / Inkscape::Util::Quantity::convert(1, "in", "px"))); if (width == 0 || height == 0) return; @@ -477,7 +477,7 @@ static void sp_asbitmap_render(SPItem *item, CairoRenderContext *ctx) double shift_y = bbox->max()[Geom::Y]; // For default 90 dpi, snap bitmap to pixel grid - if (res == PX_PER_IN) { + if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) { shift_x = round (shift_x); shift_y = -round (-shift_y); // Correct rounding despite coordinate inversion. // Remove the negations when the inversion is gone. @@ -629,7 +629,7 @@ CairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool page if (ctx->_vector_based_target) { // convert from px to pt - d *= Geom::Scale(PT_PER_PX); + d *= Geom::Scale(Inkscape::Util::Quantity::convert(1, "px", "pt")); } ctx->_width = d.width(); @@ -647,11 +647,11 @@ CairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool page } else { double high = doc->getHeight(); if (ctx->_vector_based_target) - high *= PT_PER_PX; + high *= Inkscape::Util::Quantity::convert(1, "px", "pt"); // this transform translates the export drawing to a virtual page (0,0)-(width,height) - Geom::Affine tp(Geom::Translate(-d.left() * (ctx->_vector_based_target ? PX_PER_PT : 1.0), - (d.bottom() - high) * (ctx->_vector_based_target ? PX_PER_PT : 1.0))); + Geom::Affine tp(Geom::Translate(-d.left() * (ctx->_vector_based_target ? Inkscape::Util::Quantity::convert(1, "pt", "px") : 1.0), + (d.bottom() - high) * (ctx->_vector_based_target ? Inkscape::Util::Quantity::convert(1, "pt", "px") : 1.0))); ctx->transform(tp); } } diff --git a/src/extension/internal/emf-win32-inout.cpp b/src/extension/internal/emf-win32-inout.cpp index e9360a0ea..62cb53413 100644 --- a/src/extension/internal/emf-win32-inout.cpp +++ b/src/extension/internal/emf-win32-inout.cpp @@ -37,7 +37,6 @@ #include "extension/output.h" #include "display/drawing.h" #include "display/drawing-item.h" -#include "unit-constants.h" #include "clear-n_.h" #include "document.h" diff --git a/src/extension/internal/emf-win32-print.cpp b/src/extension/internal/emf-win32-print.cpp index 2b79fd5a4..99f101bb8 100644 --- a/src/extension/internal/emf-win32-print.cpp +++ b/src/extension/internal/emf-win32-print.cpp @@ -43,8 +43,6 @@ #include "emf-win32-print.h" -#include "unit-constants.h" - #include "extension/system.h" #include "extension/print.h" #include "document.h" diff --git a/src/extension/internal/gdkpixbuf-input.cpp b/src/extension/internal/gdkpixbuf-input.cpp index abfad518f..994258ccc 100644 --- a/src/extension/internal/gdkpixbuf-input.cpp +++ b/src/extension/internal/gdkpixbuf-input.cpp @@ -12,7 +12,7 @@ #include "selection-chemistry.h" #include "sp-image.h" #include "document-undo.h" -#include "unit-constants.h" +#include "util/units.h" #include "image-resolution.h" #include @@ -79,7 +79,7 @@ GdkpixbufInput::open(Inkscape::Extension::Input *mod, char const *uri) double width = gdk_pixbuf_get_width(pb); double height = gdk_pixbuf_get_height(pb); - double defaultxdpi = prefs->getDouble("/dialogs/import/defaultxdpi/value", PX_PER_IN); + double defaultxdpi = prefs->getDouble("/dialogs/import/defaultxdpi/value", Inkscape::Util::Quantity::convert(1, "in", "px")); bool forcexdpi = prefs->getBool("/dialogs/import/forcexdpi"); ImageResolution *ir = 0; double xscale = 1; diff --git a/src/extension/internal/latex-pstricks.cpp b/src/extension/internal/latex-pstricks.cpp index c1eddf539..2ece1ba87 100644 --- a/src/extension/internal/latex-pstricks.cpp +++ b/src/extension/internal/latex-pstricks.cpp @@ -21,7 +21,7 @@ #include <2geom/hvlinesegment.h> #include #include -#include +#include "util/units.h" #include "helper/geom-curves.h" #include "extension/print.h" @@ -117,8 +117,8 @@ unsigned int PrintLatex::begin (Inkscape::Extension::Print *mod, SPDocument *doc } // width and height in pt - _width = doc->getWidth() * PT_PER_PX; - _height = doc->getHeight() * PT_PER_PX; + _width = doc->getWidth() * Inkscape::Util::Quantity::convert(1, "px", "pt"); + _height = doc->getHeight() * Inkscape::Util::Quantity::convert(1, "px", "pt"); if (res >= 0) { diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp index ecc201733..57a71b467 100644 --- a/src/extension/internal/latex-text-renderer.cpp +++ b/src/extension/internal/latex-text-renderer.cpp @@ -39,7 +39,7 @@ #include "sp-rect.h" #include "text-editing.h" -#include +#include "util/units.h" #include "extension/system.h" @@ -611,7 +611,7 @@ LaTeXTextRenderer::setupDocument(SPDocument *doc, bool pageBoundingBox, float bl // scaling of the image when including it in LaTeX os << " \\ifx\\svgwidth\\undefined%\n"; - os << " \\setlength{\\unitlength}{" << d.width() * PT_PER_PX << "bp}%\n"; // note: 'bp' is the Postscript pt unit in LaTeX, see LP bug #792384 + os << " \\setlength{\\unitlength}{" << d.width() * Inkscape::Util::Quantity::convert(1, "px", "pt") << "bp}%\n"; // note: 'bp' is the Postscript pt unit in LaTeX, see LP bug #792384 os << " \\ifx\\svgscale\\undefined%\n"; os << " \\relax%\n"; os << " \\else%\n"; diff --git a/src/extension/internal/pdfinput/pdf-parser.cpp b/src/extension/internal/pdfinput/pdf-parser.cpp index 3be7af34f..3b63e9cbe 100644 --- a/src/extension/internal/pdfinput/pdf-parser.cpp +++ b/src/extension/internal/pdfinput/pdf-parser.cpp @@ -34,7 +34,7 @@ extern "C" { #include "svg-builder.h" #include "Gfx.h" #include "pdf-parser.h" -#include "unit-constants.h" +#include "util/units.h" #include "goo/gmem.h" #include "goo/GooTimer.h" @@ -279,14 +279,14 @@ PdfParser::PdfParser(XRef *xrefA, Inkscape::Extension::Internal::SvgBuilder *bui ignoreUndef = 0; operatorHistory = NULL; builder = builderA; - builder->setDocumentSize(state->getPageWidth()*PX_PER_PT, - state->getPageHeight()*PX_PER_PT); + builder->setDocumentSize(state->getPageWidth()*Inkscape::Util::Quantity::convert(1, "pt", "px"), + state->getPageHeight()*Inkscape::Util::Quantity::convert(1, "pt", "px")); double *ctm = state->getCTM(); double scaledCTM[6]; for (int i = 0; i < 6; ++i) { baseMatrix[i] = ctm[i]; - scaledCTM[i] = PX_PER_PT * ctm[i]; + scaledCTM[i] = Inkscape::Util::Quantity::convert(1, "pt", "px") * ctm[i]; } saveState(); builder->setTransform((double*)&scaledCTM); diff --git a/src/extension/internal/pdfinput/svg-builder.cpp b/src/extension/internal/pdfinput/svg-builder.cpp index 75849f6cc..6d9ac1b1a 100644 --- a/src/extension/internal/pdfinput/svg-builder.cpp +++ b/src/extension/internal/pdfinput/svg-builder.cpp @@ -33,7 +33,7 @@ #include "svg/css-ostringstream.h" #include "svg/svg-color.h" #include "color.h" -#include "unit-constants.h" +#include "util/units.h" #include "io/stringstream.h" #include "io/base64stream.h" #include "display/nr-filter-utils.h" @@ -777,7 +777,7 @@ gchar *SvgBuilder::_createGradient(GfxShading *shading, double *matrix, bool for Geom::Affine pat_matrix(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); if ( !for_shading && _is_top_level ) { - Geom::Affine flip(1.0, 0.0, 0.0, -1.0, 0.0, _height * PT_PER_PX); + Geom::Affine flip(1.0, 0.0, 0.0, -1.0, 0.0, _height * Inkscape::Util::Quantity::convert(1, "px", "pt")); pat_matrix *= flip; } gchar *transform_text = sp_svg_transform_write(pat_matrix); diff --git a/src/helper/pixbuf-ops.cpp b/src/helper/pixbuf-ops.cpp index 9cd1967d8..75c002c57 100644 --- a/src/helper/pixbuf-ops.cpp +++ b/src/helper/pixbuf-ops.cpp @@ -29,7 +29,7 @@ #include "sp-root.h" #include "sp-use.h" #include "sp-defs.h" -#include "unit-constants.h" +#include "util/units.h" #include "helper/pixbuf-ops.h" @@ -121,7 +121,7 @@ GdkPixbuf *sp_generate_internal_bitmap(SPDocument *doc, gchar const */*filename* origin[Geom::X] = origin[Geom::X] + (screen[Geom::X].extent() * ((1 - padding) / 2)); origin[Geom::Y] = origin[Geom::Y] + (screen[Geom::Y].extent() * ((1 - padding) / 2)); - Geom::Scale scale( (xdpi / PX_PER_IN), (ydpi / PX_PER_IN)); + Geom::Scale scale( (xdpi / Inkscape::Util::Quantity::convert(1, "in", "px")), (ydpi / Inkscape::Util::Quantity::convert(1, "in", "px"))); Geom::Affine affine = scale * Geom::Translate(-origin * scale); /* Create ArenaItems and set transform */ diff --git a/src/main.cpp b/src/main.cpp index d425b88bb..577cc3d79 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,7 +68,7 @@ #include "color.h" #include "sp-item.h" #include "sp-root.h" -#include "unit-constants.h" +#include "util/units.h" #include "svg/svg.h" #include "svg/svg-color.h" @@ -1524,7 +1524,7 @@ static int sp_do_export_png(SPDocument *doc) // default dpi if (dpi == 0.0) { - dpi = PX_PER_IN; + dpi = Inkscape::Util::Quantity::convert(1, "in", "px"); } unsigned long int width = 0; @@ -1537,7 +1537,7 @@ static int sp_do_export_png(SPDocument *doc) g_warning("Export width %lu out of range (1 - %lu). Nothing exported.", width, (unsigned long int)PNG_UINT_31_MAX); return 1; } - dpi = (gdouble) width * PX_PER_IN / area.width(); + dpi = (gdouble) width * Inkscape::Util::Quantity::convert(1, "in", "px") / area.width(); } if (sp_export_height) { @@ -1547,15 +1547,15 @@ static int sp_do_export_png(SPDocument *doc) g_warning("Export height %lu out of range (1 - %lu). Nothing exported.", height, (unsigned long int)PNG_UINT_31_MAX); return 1; } - dpi = (gdouble) height * PX_PER_IN / area.height(); + dpi = (gdouble) height * Inkscape::Util::Quantity::convert(1, "in", "px") / area.height(); } if (!sp_export_width) { - width = (unsigned long int) (area.width() * dpi / PX_PER_IN + 0.5); + width = (unsigned long int) (area.width() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5); } if (!sp_export_height) { - height = (unsigned long int) (area.height() * dpi / PX_PER_IN + 0.5); + height = (unsigned long int) (area.height() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5); } guint32 bgcolor = 0x00000000; diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index dc786f340..5976555f4 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -89,7 +89,7 @@ SPCycleType SP_CYCLING = SP_CYCLE_FOCUS; #include "sp-item.h" #include "box3d.h" #include "persp3d.h" -#include "unit-constants.h" +#include "util/units.h" #include "xml/simple-document.h" #include "sp-filter-reference.h" #include "gradient-drag.h" @@ -3397,7 +3397,7 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) res = prefs_res; } else if (0 < prefs_min) { // If minsize is given, look up minimum bitmap size (default 250 pixels) and calculate resolution from it - res = PX_PER_IN * prefs_min / MIN(bbox->width(), bbox->height()); + res = Inkscape::Util::Quantity::convert(1, "in", "px") * prefs_min / MIN(bbox->width(), bbox->height()); } else { float hint_xdpi = 0, hint_ydpi = 0; Glib::ustring hint_filename; @@ -3412,14 +3412,14 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) res = hint_xdpi; } else { // if all else fails, take the default 90 dpi - res = PX_PER_IN; + res = Inkscape::Util::Quantity::convert(1, "in", "px"); } } } // The width and height of the bitmap in pixels - unsigned width = (unsigned) floor(bbox->width() * res / PX_PER_IN); - unsigned height =(unsigned) floor(bbox->height() * res / PX_PER_IN); + unsigned width = (unsigned) floor(bbox->width() * res / Inkscape::Util::Quantity::convert(1, "in", "px")); + unsigned height =(unsigned) floor(bbox->height() * res / Inkscape::Util::Quantity::convert(1, "in", "px")); // Find out if we have to run an external filter gchar const *run = NULL; @@ -3451,7 +3451,7 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) double shift_x = bbox->min()[Geom::X]; double shift_y = bbox->max()[Geom::Y]; - if (res == PX_PER_IN) { // for default 90 dpi, snap it to pixel grid + if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) { // for default 90 dpi, snap it to pixel grid shift_x = round(shift_x); shift_y = -round(-shift_y); // this gets correct rounding despite coordinate inversion, remove the negations when the inversion is gone } @@ -3484,7 +3484,7 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) // Create the repr for the image Inkscape::XML::Node * repr = xml_doc->createElement("svg:image"); sp_embed_image(repr, pb, "image/png"); - if (res == PX_PER_IN) { // for default 90 dpi, snap it to pixel grid + if (res == Inkscape::Util::Quantity::convert(1, "in", "px")) { // for default 90 dpi, snap it to pixel grid sp_repr_set_svg_double(repr, "width", width); sp_repr_set_svg_double(repr, "height", height); } else { diff --git a/src/sp-text.cpp b/src/sp-text.cpp index d84bbdc6c..9e0befcca 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -55,7 +55,6 @@ #include "sp-tspan.h" #include "text-editing.h" -#include "unit-constants.h" /*##################################################### # SPTEXT diff --git a/src/style.cpp b/src/style.cpp index 479f30597..f617973ca 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -45,7 +45,7 @@ #include "svg/css-ostringstream.h" #include "xml/repr.h" #include "xml/simple-document.h" -#include "unit-constants.h" +#include "util/units.h" #include "macros.h" #include "preferences.h" @@ -2483,11 +2483,11 @@ sp_style_css_size_px_to_units(double size, int unit) case SP_CSS_UNIT_NONE: unit_size = size; break; case SP_CSS_UNIT_PX: unit_size = size; break; - case SP_CSS_UNIT_PT: unit_size = size * PT_PER_PX; break; - case SP_CSS_UNIT_PC: unit_size = size * (PT_PER_PX / PT_PER_PC); break; - case SP_CSS_UNIT_MM: unit_size = size * MM_PER_PX; break; - case SP_CSS_UNIT_CM: unit_size = size * CM_PER_PX; break; - case SP_CSS_UNIT_IN: unit_size = size * IN_PER_PX; break; + case SP_CSS_UNIT_PT: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "pt"); break; + case SP_CSS_UNIT_PC: unit_size = size * (Inkscape::Util::Quantity::convert(1, "px", "pt") / Inkscape::Util::Quantity::convert(1, "pc", "pt")); break; + case SP_CSS_UNIT_MM: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "mm"); break; + case SP_CSS_UNIT_CM: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "cm"); break; + case SP_CSS_UNIT_IN: unit_size = size * Inkscape::Util::Quantity::convert(1, "px", "in"); break; case SP_CSS_UNIT_EM: unit_size = size / SP_CSS_FONT_SIZE_DEFAULT; break; case SP_CSS_UNIT_EX: unit_size = size * 2.0 / SP_CSS_FONT_SIZE_DEFAULT ; break; case SP_CSS_UNIT_PERCENT: unit_size = size * 100.0 / SP_CSS_FONT_SIZE_DEFAULT; break; @@ -3400,19 +3400,19 @@ sp_style_read_ilength(SPILength *val, gchar const *str) } else if (!strcmp(e, "pt")) { /* Userspace / DEVICESCALE */ val->unit = SP_CSS_UNIT_PT; - val->computed = value * PX_PER_PT; + val->computed = value * Inkscape::Util::Quantity::convert(1, "pt", "px"); } else if (!strcmp(e, "pc")) { val->unit = SP_CSS_UNIT_PC; - val->computed = value * PX_PER_PC; + val->computed = value * Inkscape::Util::Quantity::convert(1, "pc", "px"); } else if (!strcmp(e, "mm")) { val->unit = SP_CSS_UNIT_MM; - val->computed = value * PX_PER_MM; + val->computed = value * Inkscape::Util::Quantity::convert(1, "mm", "px"); } else if (!strcmp(e, "cm")) { val->unit = SP_CSS_UNIT_CM; - val->computed = value * PX_PER_CM; + val->computed = value * Inkscape::Util::Quantity::convert(1, "cm", "px"); } else if (!strcmp(e, "in")) { val->unit = SP_CSS_UNIT_IN; - val->computed = value * PX_PER_IN; + val->computed = value * Inkscape::Util::Quantity::convert(1, "in", "px"); } else if (!strcmp(e, "em")) { /* EM square */ val->unit = SP_CSS_UNIT_EM; @@ -3971,23 +3971,23 @@ sp_style_write_ilength(gchar *p, gint const len, gchar const *const key, return g_strlcpy(p, os.str().c_str(), len); break; case SP_CSS_UNIT_PT: - os << key << ":" << val->computed * PT_PER_PX << "pt;"; + os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "pt") << "pt;"; return g_strlcpy(p, os.str().c_str(), len); break; case SP_CSS_UNIT_PC: - os << key << ":" << val->computed * PT_PER_PX / 12.0 << "pc;"; + os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "pt") / 12.0 << "pc;"; return g_strlcpy(p, os.str().c_str(), len); break; case SP_CSS_UNIT_MM: - os << key << ":" << val->computed * MM_PER_PX << "mm;"; + os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "mm") << "mm;"; return g_strlcpy(p, os.str().c_str(), len); break; case SP_CSS_UNIT_CM: - os << key << ":" << val->computed * CM_PER_PX << "cm;"; + os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "cm") << "cm;"; return g_strlcpy(p, os.str().c_str(), len); break; case SP_CSS_UNIT_IN: - os << key << ":" << val->computed * IN_PER_PX << "in;"; + os << key << ":" << val->computed * Inkscape::Util::Quantity::convert(1, "px", "in") << "in;"; return g_strlcpy(p, os.str().c_str(), len); break; case SP_CSS_UNIT_EM: diff --git a/src/svg/svg-length.cpp b/src/svg/svg-length.cpp index d2f4332d8..7f93f9f0f 100644 --- a/src/svg/svg-length.cpp +++ b/src/svg/svg-length.cpp @@ -23,7 +23,7 @@ #include "svg.h" #include "stringstream.h" -#include "../unit-constants.h" +#include "util/units.h" static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit, float *val, float *computed, char **next); @@ -365,7 +365,7 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit, *unit = SVGLength::PT; } if (computed) { - *computed = v * PX_PER_PT; + *computed = v * Inkscape::Util::Quantity::convert(1, "pt", "px"); } break; case UVAL('p','c'): @@ -373,7 +373,7 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit, *unit = SVGLength::PC; } if (computed) { - *computed = v * PX_PER_PC; + *computed = v * Inkscape::Util::Quantity::convert(1, "pc", "px"); } break; case UVAL('m','m'): @@ -381,7 +381,7 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit, *unit = SVGLength::MM; } if (computed) { - *computed = v * PX_PER_MM; + *computed = v * Inkscape::Util::Quantity::convert(1, "mm", "px"); } break; case UVAL('c','m'): @@ -389,7 +389,7 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit, *unit = SVGLength::CM; } if (computed) { - *computed = v * PX_PER_CM; + *computed = v * Inkscape::Util::Quantity::convert(1, "cm", "px"); } break; case UVAL('i','n'): @@ -397,7 +397,7 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit, *unit = SVGLength::INCH; } if (computed) { - *computed = v * PX_PER_IN; + *computed = v * Inkscape::Util::Quantity::convert(1, "in", "px"); } break; case UVAL('f','t'): @@ -405,7 +405,7 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit, *unit = SVGLength::FOOT; } if (computed) { - *computed = v * PX_PER_FT; + *computed = v * Inkscape::Util::Quantity::convert(1, "ft", "px"); } break; case UVAL('e','m'): diff --git a/src/text-editing.cpp b/src/text-editing.cpp index 401f56bb2..0d30863d9 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -24,7 +24,7 @@ #include "inkscape.h" #include "message-stack.h" #include "style.h" -#include "unit-constants.h" +#include "util/units.h" #include "document.h" #include "xml/repr.h" @@ -1278,23 +1278,23 @@ sp_te_adjust_linespacing_screen (SPItem *text, Inkscape::Text::Layout::iterator style->line_height.value = style->line_height.computed; break; case SP_CSS_UNIT_PT: - style->line_height.computed += zby * PT_PER_PX; + style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "pt"); style->line_height.value = style->line_height.computed; break; case SP_CSS_UNIT_PC: - style->line_height.computed += zby * (PT_PER_PX / 12); + style->line_height.computed += zby * (Inkscape::Util::Quantity::convert(1, "px", "pt") / 12); style->line_height.value = style->line_height.computed; break; case SP_CSS_UNIT_MM: - style->line_height.computed += zby * MM_PER_PX; + style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "mm"); style->line_height.value = style->line_height.computed; break; case SP_CSS_UNIT_CM: - style->line_height.computed += zby * CM_PER_PX; + style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "cm"); style->line_height.value = style->line_height.computed; break; case SP_CSS_UNIT_IN: - style->line_height.computed += zby * IN_PER_PX; + style->line_height.computed += zby * Inkscape::Util::Quantity::convert(1, "px", "in"); style->line_height.value = style->line_height.computed; break; } diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 72ddd90a9..629960613 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -79,7 +79,7 @@ #include "text-editing.h" #include "tools-switch.h" #include "path-chemistry.h" -#include "unit-constants.h" +#include "util/units.h" #include "helper/png-write.h" #include "svg/svg-color.h" #include "sp-namedview.h" @@ -1078,14 +1078,14 @@ void ClipboardManagerImpl::_onGet(Gtk::SelectionData &sel, guint /*info*/) try { if (out == outlist.end() && target == "image/png") { - gdouble dpi = PX_PER_IN; + gdouble dpi = Inkscape::Util::Quantity::convert(1, "in", "px"); guint32 bgcolor = 0x00000000; Geom::Point origin (_clipboardSPDoc->getRoot()->x.computed, _clipboardSPDoc->getRoot()->y.computed); Geom::Rect area = Geom::Rect(origin, origin + _clipboardSPDoc->getDimensions()); - unsigned long int width = (unsigned long int) (area.width() * dpi / PX_PER_IN + 0.5); - unsigned long int height = (unsigned long int) (area.height() * dpi / PX_PER_IN + 0.5); + unsigned long int width = (unsigned long int) (area.width() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5); + unsigned long int height = (unsigned long int) (area.height() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5); // read from namedview Inkscape::XML::Node *nv = sp_repr_lookup_name (_clipboardSPDoc->rroot, "sodipodi:namedview"); diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 5cb9357c3..063902aa7 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -50,7 +50,6 @@ #include "ui/widget/unit-menu.h" #include "util/units.h" -#include "unit-constants.h" #include "helper/window.h" #include "inkscape-private.h" #include "document.h" @@ -98,7 +97,7 @@ #define SP_EXPORT_MIN_SIZE 1.0 -#define DPI_BASE PX_PER_IN +#define DPI_BASE Inkscape::Util::Quantity::convert(1, "in", "px") #define EXPORT_COORD_PRECISION 3 @@ -1048,8 +1047,8 @@ void Export::onExport () Geom::OptRect area = item->desktopVisualBounds(); if (area) { - gint width = (gint) (area->width() * dpi / PX_PER_IN + 0.5); - gint height = (gint) (area->height() * dpi / PX_PER_IN + 0.5); + gint width = (gint) (area->width() * dpi / DPI_BASE + 0.5); + gint height = (gint) (area->height() * dpi / DPI_BASE + 0.5); if (width > 1 && height > 1) { // Do export diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index bc648002d..7890b0b4c 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -28,7 +28,7 @@ #include "preferences.h" #include "verbs.h" #include "selcue.h" -#include "unit-constants.h" +#include "util/units.h" #include #include "enums.h" #include "desktop-handles.h" @@ -1428,10 +1428,10 @@ void InkscapePreferences::initPageBitmaps() _("Automatically reload linked images when file is changed on disk")); _misc_bitmap_editor.init("/options/bitmapeditor/value", true); _page_bitmaps.add_line( false, _("_Bitmap editor:"), _misc_bitmap_editor, "", "", true); - _importexport_export_res.init("/dialogs/export/defaultxdpi/value", 0.0, 6000.0, 1.0, 1.0, PX_PER_IN, true, false); + _importexport_export_res.init("/dialogs/export/defaultxdpi/value", 0.0, 6000.0, 1.0, 1.0, Inkscape::Util::Quantity::convert(1, "in", "px"), true, false); _page_bitmaps.add_line( false, _("Default export _resolution:"), _importexport_export_res, _("dpi"), _("Default bitmap resolution (in dots per inch) in the Export dialog"), false); - _bitmap_copy_res.init("/options/createbitmap/resolution", 1.0, 6000.0, 1.0, 1.0, PX_PER_IN, true, false); + _bitmap_copy_res.init("/options/createbitmap/resolution", 1.0, 6000.0, 1.0, 1.0, Inkscape::Util::Quantity::convert(1, "in", "px"), true, false); _page_bitmaps.add_line( false, _("Resolution for Create Bitmap _Copy:"), _bitmap_copy_res, _("dpi"), _("Resolution used by the Create Bitmap Copy command"), false); { @@ -1443,7 +1443,7 @@ void InkscapePreferences::initPageBitmaps() _bitmap_import_quality.init("/dialogs/import/quality", 1, 100, 1, 1, 100, true, false); _page_bitmaps.add_line( false, _("Bitmap import quality:"), _bitmap_import_quality, "%", "Bitmap import quality (jpeg only). 100 is best quality", false); } - _importexport_import_res.init("/dialogs/import/defaultxdpi/value", 0.0, 6000.0, 1.0, 1.0, PX_PER_IN, true, false); + _importexport_import_res.init("/dialogs/import/defaultxdpi/value", 0.0, 6000.0, 1.0, 1.0, Inkscape::Util::Quantity::convert(1, "in", "px"), true, false); _page_bitmaps.add_line( false, _("Default _import resolution:"), _importexport_import_res, _("dpi"), _("Default bitmap resolution (in dots per inch) for bitmap import"), false); _importexport_import_res_override.init(_("Override file resolution"), "/dialogs/import/forcexdpi", false); diff --git a/src/ui/dialog/print.cpp b/src/ui/dialog/print.cpp index 2ab8cf121..4c8c77f96 100644 --- a/src/ui/dialog/print.cpp +++ b/src/ui/dialog/print.cpp @@ -26,7 +26,7 @@ #include "ui/widget/rendering-options.h" #include "document.h" -#include "unit-constants.h" +#include "util/units.h" #include "helper/png-write.h" #include "svg/svg-color.h" #include "io/sys.h" @@ -72,8 +72,8 @@ static void draw_page( sp_export_png_file(junk->_doc, tmp_png.c_str(), 0.0, 0.0, width, height, - (unsigned long)(width * dpi / PX_PER_IN), - (unsigned long)(height * dpi / PX_PER_IN), + (unsigned long)(width * dpi / Inkscape::Util::Quantity::convert(1, "in", "px")), + (unsigned long)(height * dpi / Inkscape::Util::Quantity::convert(1, "in", "px")), dpi, dpi, bgcolor, NULL, NULL, true, NULL); // This doesn't seem to work: @@ -90,7 +90,7 @@ static void draw_page( cairo_t *cr = gtk_print_context_get_cairo_context (context); cairo_matrix_t m; cairo_get_matrix(cr, &m); - cairo_scale(cr, PT_PER_IN / dpi, PT_PER_IN / dpi); + cairo_scale(cr, Inkscape::Util::Quantity::convert(1, "in", "pt") / dpi, Inkscape::Util::Quantity::convert(1, "in", "pt") / dpi); // FIXME: why is the origin offset?? cairo_set_source_surface(cr, png->cobj(), -16.0, -16.0); cairo_paint(cr); @@ -195,8 +195,8 @@ Print::Print(SPDocument *doc, SPItem *base) : // set up paper size to match the document size gtk_print_operation_set_unit (_printop, GTK_UNIT_POINTS); GtkPageSetup *page_setup = gtk_page_setup_new(); - gdouble doc_width = _doc->getWidth() * PT_PER_PX; - gdouble doc_height = _doc->getHeight() * PT_PER_PX; + gdouble doc_width = _doc->getWidth() * Inkscape::Util::Quantity::convert(1, "px", "pt"); + gdouble doc_height = _doc->getHeight() * Inkscape::Util::Quantity::convert(1, "px", "pt"); GtkPaperSize *paper_size; if (doc_width > doc_height) { gtk_page_setup_set_orientation (page_setup, GTK_PAGE_ORIENTATION_LANDSCAPE); diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index a662495a0..4a25f723b 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -58,7 +58,7 @@ extern "C" { #include "widgets/font-selector.h" #include #include -#include "unit-constants.h" +#include "util/units.h" #include "sp-textpath.h" namespace Inkscape { @@ -401,7 +401,7 @@ void TextEdit::setPreviewText (Glib::ustring font_spec, Glib::ustring phrase) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int unit = prefs->getInt("/options/font/unitType", SP_CSS_UNIT_PT); - double pt_size = sp_style_css_size_units_to_px(sp_font_selector_get_size(fsel), unit) * PT_PER_PX; + double pt_size = sp_style_css_size_units_to_px(sp_font_selector_get_size(fsel), unit) * Inkscape::Util::Quantity::convert(1, "px", "pt"); // Pango font size is in 1024ths of a point // C++11: Glib::ustring size = std::to_string( pt_size * PANGO_SCALE ); diff --git a/src/ui/widget/rendering-options.cpp b/src/ui/widget/rendering-options.cpp index f26e71553..d6248df69 100644 --- a/src/ui/widget/rendering-options.cpp +++ b/src/ui/widget/rendering-options.cpp @@ -13,7 +13,7 @@ #endif #include "rendering-options.h" -#include "unit-constants.h" +#include "util/units.h" #include namespace Inkscape { @@ -59,8 +59,8 @@ RenderingOptions::RenderingOptions () : _radio_bitmap.signal_toggled().connect(sigc::mem_fun(*this, &RenderingOptions::_toggled)); // configure default DPI - _dpi.setRange(PT_PER_IN,2400.0); - _dpi.setValue(PT_PER_IN); + _dpi.setRange(Inkscape::Util::Quantity::convert(1, "in", "pt"),2400.0); + _dpi.setValue(Inkscape::Util::Quantity::convert(1, "in", "pt")); _dpi.setIncrements(1.0,10.0); _dpi.setDigits(0); _dpi.update(); diff --git a/src/unit-constants.h b/src/unit-constants.h deleted file mode 100644 index c56c0a6e8..000000000 --- a/src/unit-constants.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef INKSCAPE_UNIT_CONSTANTS_H -#define INKSCAPE_UNIT_CONSTANTS_H - -// 72 points per inch divided by the SVG-recommended value of 90 pixels per inch for computer screen -// For now it is constant throughout Inkscape, later we may make it changeable. -// Ideally this should be the only place to change it, but this is not guaranteed (be careful!) -#define DEVICESCALE 0.8 - -#define PT_PER_IN 72.0 -#define PT_PER_PX DEVICESCALE -#define PT_PER_PC 12.0 -#define PX_PER_PT (1/DEVICESCALE) -#define PX_PER_PC (PX_PER_PT * PT_PER_PC) -#define PX_PER_IN (PT_PER_IN / PT_PER_PX) -#define PC_PER_IN (PT_PER_IN / PT_PER_PC) -#define M_PER_IN 0.0254 -#define M_PER_PX (M_PER_IN / PX_PER_IN) -#define CM_PER_IN 2.54 -#define MM_PER_IN 25.4 -#define MM_PER_MM 1.0 -#define MM_PER_CM 10.0 -#define MM_PER_M 1000.0 -#define IN_PER_PT (1 / PT_PER_IN) -#define IN_PER_PX (1 / PX_PER_IN) -#define IN_PER_CM (1 / CM_PER_IN) -#define IN_PER_MM (1 / MM_PER_IN) -#define IN_PER_FT 12.0 -#define FT_PER_IN (1 / IN_PER_FT) -#define PT_PER_CM (PT_PER_IN / CM_PER_IN) -#define PX_PER_CM (PX_PER_IN / CM_PER_IN) -#define M_PER_PT (M_PER_IN / PT_PER_IN) -#define PT_PER_M (PT_PER_IN / M_PER_IN) -#define PX_PER_M (PX_PER_IN / M_PER_IN) -#define CM_PER_PT (CM_PER_IN / PT_PER_IN) -#define CM_PER_PX (CM_PER_IN / PX_PER_IN) -#define MM_PER_PT (MM_PER_IN / PT_PER_IN) -#define PT_PER_MM (PT_PER_IN / MM_PER_IN) -#define PX_PER_MM (PX_PER_IN / MM_PER_IN) -#define MM_PER_PX (MM_PER_IN / PX_PER_IN) -#define PX_PER_FT (PX_PER_IN / FT_PER_IN) -#define PT_PER_PT 1.0 -#define PC_PER_PC 1.0 -#define IN_PER_IN 1.0 -#define PX_PER_PX 1.0 -#define FT_PER_FT 1.0 - -#endif /* !INKSCAPE_UNIT_CONSTANTS_H */ diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index 7fa848f1e..5f9098d44 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -33,7 +33,6 @@ #include "desktop.h" #include "widgets/font-selector.h" #include "preferences.h" -#include "unit-constants.h" /* SPFontSelector */ -- cgit v1.2.3 From cd953884af566fce30421a9beee6cb71811ca792 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 1 Aug 2013 12:41:35 -0400 Subject: Improved math formatting. (bzr r12380.1.55) --- src/widgets/select-toolbar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index ab6d6ca3b..b39423635 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -206,9 +206,9 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw) x0 = bbox_user->min()[Geom::X] * x0_propn; double const y0_propn = gtk_adjustment_get_value (a_y) / 100 / unit.factor; y0 = y0_propn * bbox_user->min()[Geom::Y]; - xrel = gtk_adjustment_get_value (a_w) / 100 / unit.factor; + xrel = gtk_adjustment_get_value (a_w) / (100 / unit.factor); x1 = x0 + xrel * bbox_user->dimensions()[Geom::X]; - yrel = gtk_adjustment_get_value (a_h) / 100 / unit.factor; + yrel = gtk_adjustment_get_value (a_h) / (100 / unit.factor); y1 = y0 + yrel * bbox_user->dimensions()[Geom::Y]; } -- cgit v1.2.3 From aaa29715c3e2e854d6c25b6a3c3216f18824d669 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 1 Aug 2013 12:44:34 -0400 Subject: Fixed Windows compile bug. (bzr r12380.1.56) --- src/extension/internal/emf-win32-inout.cpp | 13 +++--- src/extension/internal/emf-win32-print.cpp | 70 +++++++++++++++--------------- 2 files changed, 42 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/extension/internal/emf-win32-inout.cpp b/src/extension/internal/emf-win32-inout.cpp index 62cb53413..627d78b16 100644 --- a/src/extension/internal/emf-win32-inout.cpp +++ b/src/extension/internal/emf-win32-inout.cpp @@ -39,6 +39,7 @@ #include "display/drawing-item.h" #include "clear-n_.h" #include "document.h" +#include "util/units.h" #define WIN32_LEAN_AND_MEAN #include @@ -59,7 +60,7 @@ namespace Inkscape { namespace Extension { namespace Internal { -static float device_scale = DEVICESCALE; +static float device_scale = Inkscape::Util::Quantity::convert(1, "px", "pt"); static float device_x; static float device_y; static RECTL rc_old; @@ -776,18 +777,18 @@ myEnhMetaFileProc(HDC /*hDC*/, HANDLETABLE * /*lpHTable*/, ENHMETARECORD const * d->dc[d->level].PixelsInX = pEmr->rclFrame.right - pEmr->rclFrame.left; d->dc[d->level].PixelsInY = pEmr->rclFrame.bottom - pEmr->rclFrame.top; - device_x = pEmr->rclFrame.left/100.0*PX_PER_MM; - device_y = pEmr->rclFrame.top/100.0*PX_PER_MM; + device_x = pEmr->rclFrame.left/100.0*Inkscape::Util::Quantity::Convert(1, "mm", "px"); + device_y = pEmr->rclFrame.top/100.0*Inkscape::Util::Quantity::Convert(1, "mm", "px"); d->MMX = d->dc[d->level].PixelsInX / 100.0; d->MMY = d->dc[d->level].PixelsInY / 100.0; - d->dc[d->level].PixelsOutX = d->MMX * PX_PER_MM; - d->dc[d->level].PixelsOutY = d->MMY * PX_PER_MM; + d->dc[d->level].PixelsOutX = d->MMX * Inkscape::Util::Quantity::Convert(1, "mm", "px"); + d->dc[d->level].PixelsOutY = d->MMY * Inkscape::Util::Quantity::Convert(1, "mm", "px"); // calculate ratio of Inkscape dpi/device dpi if (pEmr->szlMillimeters.cx && pEmr->szlDevice.cx) - device_scale = PX_PER_MM*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx; + device_scale = Inkscape::Util::Quantity::Convert(1, "mm", "px")*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx; tmp_outdef << " width=\"" << d->MMX << "mm\"\n" << diff --git a/src/extension/internal/emf-win32-print.cpp b/src/extension/internal/emf-win32-print.cpp index 99f101bb8..8784f4ace 100644 --- a/src/extension/internal/emf-win32-print.cpp +++ b/src/extension/internal/emf-win32-print.cpp @@ -127,7 +127,7 @@ unsigned int PrintEmfWin32::begin (Inkscape::Extension::Print *mod, SPDocument * if (bbox) d = *bbox; } - d *= Geom::Scale(IN_PER_PX); + d *= Geom::Scale(Inkscape::Util::Quantity::Convert(1, "px", "in")); float dwInchesX = d.width(); float dwInchesY = d.height(); @@ -194,7 +194,7 @@ unsigned int PrintEmfWin32::begin (Inkscape::Extension::Print *mod, SPDocument * snprintf(buff, sizeof(buff)-1, "Screen=%dx%dpx, %dx%dmm", PixelsX, PixelsY, MMX, MMY); GdiComment(hdc, strlen(buff), (BYTE*) buff); - snprintf(buff, sizeof(buff)-1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, dwInchesX * MM_PER_IN, dwInchesY * MM_PER_IN); + snprintf(buff, sizeof(buff)-1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, dwInchesX * Inkscape::Util::Quantity::Convert(1, "in", "mm"), dwInchesY * Inkscape::Util::Quantity::Convert(1, "in", "mm")); GdiComment(hdc, strlen(buff), (BYTE*) buff); } @@ -303,7 +303,7 @@ void PrintEmfWin32::create_pen(SPStyle const *style, const Geom::Affine &transfo double scale = sqrt( (p[X]*p[X]) + (p[Y]*p[Y]) ) / sqrt(2); - DWORD linewidth = MAX( 1, (DWORD) (scale * style->stroke_width.computed * IN_PER_PX * dwDPI) ); + DWORD linewidth = MAX( 1, (DWORD) (scale * style->stroke_width.computed * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI) ); if (style->stroke_linecap.computed == 0) { linecap = PS_ENDCAP_FLAT; @@ -340,7 +340,7 @@ void PrintEmfWin32::create_pen(SPStyle const *style, const Geom::Affine &transfo n_dash = style->stroke_dash.n_dash; dash = new DWORD[n_dash]; for (i = 0; i < style->stroke_dash.n_dash; i++) { - dash[i] = (DWORD) (style->stroke_dash.dash[i] * IN_PER_PX * dwDPI); + dash[i] = (DWORD) (style->stroke_dash.dash[i] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); } } } @@ -543,8 +543,8 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom Geom::Point p0 = pit->initialPoint(); - p0[X] = (p0[X] * IN_PER_PX * dwDPI); - p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); + p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); LONG const x0 = (LONG) round(p0[X]); LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -563,10 +563,10 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom //Geom::Point p0 = cit->initialPoint(); Geom::Point p1 = cit->finalPoint(); - //p0[X] = (p0[X] * IN_PER_PX * dwDPI); - p1[X] = (p1[X] * IN_PER_PX * dwDPI); - //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); - p1[Y] = (p1[Y] * IN_PER_PX * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -585,14 +585,14 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom Geom::Point p2 = points[2]; Geom::Point p3 = points[3]; - //p0[X] = (p0[X] * IN_PER_PX * dwDPI); - p1[X] = (p1[X] * IN_PER_PX * dwDPI); - p2[X] = (p2[X] * IN_PER_PX * dwDPI); - p3[X] = (p3[X] * IN_PER_PX * dwDPI); - //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); - p1[Y] = (p1[Y] * IN_PER_PX * dwDPI); - p2[Y] = (p2[Y] * IN_PER_PX * dwDPI); - p3[Y] = (p3[Y] * IN_PER_PX * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p2[X] = (p2[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p3[X] = (p3[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p2[Y] = (p2[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p3[Y] = (p3[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -715,8 +715,8 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo Geom::Point p0 = pit->initialPoint(); - p0[X] = (p0[X] * IN_PER_PX * dwDPI); - p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); + p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); LONG const x0 = (LONG) round(p0[X]); LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -733,10 +733,10 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo //Geom::Point p0 = cit->initialPoint(); Geom::Point p1 = cit->finalPoint(); - //p0[X] = (p0[X] * IN_PER_PX * dwDPI); - p1[X] = (p1[X] * IN_PER_PX * dwDPI); - //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); - p1[Y] = (p1[Y] * IN_PER_PX * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -753,14 +753,14 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo Geom::Point p2 = points[2]; Geom::Point p3 = points[3]; - //p0[X] = (p0[X] * IN_PER_PX * dwDPI); - p1[X] = (p1[X] * IN_PER_PX * dwDPI); - p2[X] = (p2[X] * IN_PER_PX * dwDPI); - p3[X] = (p3[X] * IN_PER_PX * dwDPI); - //p0[Y] = (p0[Y] * IN_PER_PX * dwDPI); - p1[Y] = (p1[Y] * IN_PER_PX * dwDPI); - p2[Y] = (p2[Y] * IN_PER_PX * dwDPI); - p3[Y] = (p3[Y] * IN_PER_PX * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p2[X] = (p2[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p3[X] = (p3[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p2[Y] = (p2[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p3[Y] = (p3[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -828,7 +828,7 @@ unsigned int PrintEmfWin32::text(Inkscape::Extension::Print * /*mod*/, char cons LOGFONTW *lf = (LOGFONTW*)g_malloc(sizeof(LOGFONTW)); g_assert(lf != NULL); - lf->lfHeight = -style->font_size.computed * IN_PER_PX * dwDPI; + lf->lfHeight = -style->font_size.computed * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI; lf->lfWidth = 0; lf->lfEscapement = rot; lf->lfOrientation = rot; @@ -877,8 +877,8 @@ unsigned int PrintEmfWin32::text(Inkscape::Extension::Print * /*mod*/, char cons SetBkMode(hdc, TRANSPARENT); Geom::Point p2 = p * tf; - p2[Geom::X] = (p2[Geom::X] * IN_PER_PX * dwDPI); - p2[Geom::Y] = (p2[Geom::Y] * IN_PER_PX * dwDPI); + p2[Geom::X] = (p2[Geom::X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p2[Geom::Y] = (p2[Geom::Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); LONG const xpos = (LONG) round(p2[Geom::X]); LONG const ypos = (LONG) round(rc.bottom - p2[Geom::Y]); -- cgit v1.2.3 From 5a15ea1a002fa4638198d50182e6fd5847ee9cf9 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 1 Aug 2013 16:28:56 -0400 Subject: Fixed Windows compile bug. (bzr r12380.1.58) --- src/extension/internal/emf-win32-inout.cpp | 10 ++--- src/extension/internal/emf-win32-print.cpp | 71 +++++++++++++++--------------- 2 files changed, 41 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/extension/internal/emf-win32-inout.cpp b/src/extension/internal/emf-win32-inout.cpp index 627d78b16..2530af0cc 100644 --- a/src/extension/internal/emf-win32-inout.cpp +++ b/src/extension/internal/emf-win32-inout.cpp @@ -777,18 +777,18 @@ myEnhMetaFileProc(HDC /*hDC*/, HANDLETABLE * /*lpHTable*/, ENHMETARECORD const * d->dc[d->level].PixelsInX = pEmr->rclFrame.right - pEmr->rclFrame.left; d->dc[d->level].PixelsInY = pEmr->rclFrame.bottom - pEmr->rclFrame.top; - device_x = pEmr->rclFrame.left/100.0*Inkscape::Util::Quantity::Convert(1, "mm", "px"); - device_y = pEmr->rclFrame.top/100.0*Inkscape::Util::Quantity::Convert(1, "mm", "px"); + device_x = pEmr->rclFrame.left/100.0*Inkscape::Util::Quantity::convert(1, "mm", "px"); + device_y = pEmr->rclFrame.top/100.0*Inkscape::Util::Quantity::convert(1, "mm", "px"); d->MMX = d->dc[d->level].PixelsInX / 100.0; d->MMY = d->dc[d->level].PixelsInY / 100.0; - d->dc[d->level].PixelsOutX = d->MMX * Inkscape::Util::Quantity::Convert(1, "mm", "px"); - d->dc[d->level].PixelsOutY = d->MMY * Inkscape::Util::Quantity::Convert(1, "mm", "px"); + d->dc[d->level].PixelsOutX = d->MMX * Inkscape::Util::Quantity::convert(1, "mm", "px"); + d->dc[d->level].PixelsOutY = d->MMY * Inkscape::Util::Quantity::convert(1, "mm", "px"); // calculate ratio of Inkscape dpi/device dpi if (pEmr->szlMillimeters.cx && pEmr->szlDevice.cx) - device_scale = Inkscape::Util::Quantity::Convert(1, "mm", "px")*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx; + device_scale = Inkscape::Util::Quantity::convert(1, "mm", "px")*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx; tmp_outdef << " width=\"" << d->MMX << "mm\"\n" << diff --git a/src/extension/internal/emf-win32-print.cpp b/src/extension/internal/emf-win32-print.cpp index 8784f4ace..dae97fecf 100644 --- a/src/extension/internal/emf-win32-print.cpp +++ b/src/extension/internal/emf-win32-print.cpp @@ -36,6 +36,7 @@ #include "helper/geom.h" #include "helper/geom-curves.h" #include "sp-item.h" +#include "util/units.h" #include "style.h" #include "inkscape-version.h" @@ -127,7 +128,7 @@ unsigned int PrintEmfWin32::begin (Inkscape::Extension::Print *mod, SPDocument * if (bbox) d = *bbox; } - d *= Geom::Scale(Inkscape::Util::Quantity::Convert(1, "px", "in")); + d *= Geom::Scale(Inkscape::Util::Quantity::convert(1, "px", "in")); float dwInchesX = d.width(); float dwInchesY = d.height(); @@ -194,7 +195,7 @@ unsigned int PrintEmfWin32::begin (Inkscape::Extension::Print *mod, SPDocument * snprintf(buff, sizeof(buff)-1, "Screen=%dx%dpx, %dx%dmm", PixelsX, PixelsY, MMX, MMY); GdiComment(hdc, strlen(buff), (BYTE*) buff); - snprintf(buff, sizeof(buff)-1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, dwInchesX * Inkscape::Util::Quantity::Convert(1, "in", "mm"), dwInchesY * Inkscape::Util::Quantity::Convert(1, "in", "mm")); + snprintf(buff, sizeof(buff)-1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, dwInchesX * Inkscape::Util::Quantity::convert(1, "in", "mm"), dwInchesY * Inkscape::Util::Quantity::convert(1, "in", "mm")); GdiComment(hdc, strlen(buff), (BYTE*) buff); } @@ -303,7 +304,7 @@ void PrintEmfWin32::create_pen(SPStyle const *style, const Geom::Affine &transfo double scale = sqrt( (p[X]*p[X]) + (p[Y]*p[Y]) ) / sqrt(2); - DWORD linewidth = MAX( 1, (DWORD) (scale * style->stroke_width.computed * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI) ); + DWORD linewidth = MAX( 1, (DWORD) (scale * style->stroke_width.computed * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI) ); if (style->stroke_linecap.computed == 0) { linecap = PS_ENDCAP_FLAT; @@ -340,7 +341,7 @@ void PrintEmfWin32::create_pen(SPStyle const *style, const Geom::Affine &transfo n_dash = style->stroke_dash.n_dash; dash = new DWORD[n_dash]; for (i = 0; i < style->stroke_dash.n_dash; i++) { - dash[i] = (DWORD) (style->stroke_dash.dash[i] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + dash[i] = (DWORD) (style->stroke_dash.dash[i] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); } } } @@ -543,8 +544,8 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom Geom::Point p0 = pit->initialPoint(); - p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); LONG const x0 = (LONG) round(p0[X]); LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -563,10 +564,10 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom //Geom::Point p0 = cit->initialPoint(); Geom::Point p1 = cit->finalPoint(); - //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -585,14 +586,14 @@ bool PrintEmfWin32::print_simple_shape(Geom::PathVector const &pathv, const Geom Geom::Point p2 = points[2]; Geom::Point p3 = points[3]; - //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p2[X] = (p2[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p3[X] = (p3[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p2[Y] = (p2[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p3[Y] = (p3[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p2[X] = (p2[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p3[X] = (p3[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p2[Y] = (p2[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p3[Y] = (p3[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -715,8 +716,8 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo Geom::Point p0 = pit->initialPoint(); - p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); LONG const x0 = (LONG) round(p0[X]); LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -733,10 +734,10 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo //Geom::Point p0 = cit->initialPoint(); Geom::Point p1 = cit->finalPoint(); - //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -753,14 +754,14 @@ unsigned int PrintEmfWin32::print_pathv(Geom::PathVector const &pathv, const Geo Geom::Point p2 = points[2]; Geom::Point p3 = points[3]; - //p0[X] = (p0[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[X] = (p1[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p2[X] = (p2[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p3[X] = (p3[X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p1[Y] = (p1[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p2[Y] = (p2[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p3[Y] = (p3[Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + //p0[X] = (p0[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[X] = (p1[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p2[X] = (p2[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p3[X] = (p3[X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + //p0[Y] = (p0[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p1[Y] = (p1[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p2[Y] = (p2[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p3[Y] = (p3[Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); //LONG const x0 = (LONG) round(p0[X]); //LONG const y0 = (LONG) round(rc.bottom-p0[Y]); @@ -828,7 +829,7 @@ unsigned int PrintEmfWin32::text(Inkscape::Extension::Print * /*mod*/, char cons LOGFONTW *lf = (LOGFONTW*)g_malloc(sizeof(LOGFONTW)); g_assert(lf != NULL); - lf->lfHeight = -style->font_size.computed * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI; + lf->lfHeight = -style->font_size.computed * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI; lf->lfWidth = 0; lf->lfEscapement = rot; lf->lfOrientation = rot; @@ -877,8 +878,8 @@ unsigned int PrintEmfWin32::text(Inkscape::Extension::Print * /*mod*/, char cons SetBkMode(hdc, TRANSPARENT); Geom::Point p2 = p * tf; - p2[Geom::X] = (p2[Geom::X] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); - p2[Geom::Y] = (p2[Geom::Y] * Inkscape::Util::Quantity::Convert(1, "px", "in") * dwDPI); + p2[Geom::X] = (p2[Geom::X] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); + p2[Geom::Y] = (p2[Geom::Y] * Inkscape::Util::Quantity::convert(1, "px", "in") * dwDPI); LONG const xpos = (LONG) round(p2[Geom::X]); LONG const ypos = (LONG) round(rc.bottom - p2[Geom::Y]); -- cgit v1.2.3 From f69ba9fbb46f827a2cb76f2d1f87acbf53edc416 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Thu, 1 Aug 2013 19:42:12 -0400 Subject: Fix UnitTracker percentage bug. (bzr r12380.1.59) --- src/ui/widget/unit-tracker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp index c0d3eec9b..99074be40 100644 --- a/src/ui/widget/unit-tracker.cpp +++ b/src/ui/widget/unit-tracker.cpp @@ -245,7 +245,7 @@ void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape && (newUnit.type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) ) { if (_priorValues.find(adj) != _priorValues.end()) { - val = Inkscape::Util::Quantity::convert(_priorValues[adj], newUnit, "px"); + val = Inkscape::Util::Quantity::convert(_priorValues[adj], "px", newUnit); } } else { val = Inkscape::Util::Quantity::convert(oldVal, oldUnit, newUnit); -- cgit v1.2.3 From 6c7ac8dd7e8403645de3090777ed6b50c95420e3 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sat, 3 Aug 2013 12:21:14 -0400 Subject: Fixed building of tests. (bzr r12380.1.60) --- src/helper/Makefile_insert | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src') diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index 5d1703b5c..4c6437f13 100644 --- a/src/helper/Makefile_insert +++ b/src/helper/Makefile_insert @@ -40,9 +40,3 @@ helper/sp-marshal.cpp: helper/sp-marshal.list helper/sp-marshal.h else mv helper/tmp.sp-marshal.cpp helper/sp-marshal.cpp; fi helper/sp-marshal.cpp helper/sp-marshal.h: helper/sp-marshal.list - -# ###################### -# ### CxxTest stuff #### -# ###################### -CXXTEST_TESTSUITES += \ - $(srcdir)/helper/units-test.h -- cgit v1.2.3 From c935444b90a29e270371f1afee773104dc314e88 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sat, 3 Aug 2013 12:55:11 -0400 Subject: Fix handling of SVG lengths with spaces [Bug #1208002]. (bzr r12380.1.61) --- src/svg/svg-length.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/svg/svg-length.cpp b/src/svg/svg-length.cpp index 7f93f9f0f..ea438e91a 100644 --- a/src/svg/svg-length.cpp +++ b/src/svg/svg-length.cpp @@ -330,6 +330,8 @@ static unsigned sp_svg_length_read_lff(gchar const *str, SVGLength::Unit *unit, *next = (char *) e + 1; } return 1; + } else if (g_ascii_isspace(e[0])) { + return 0; // spaces are not allowed } else { /* Unitless */ if (unit) { -- 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/display/canvas-axonomgrid.cpp | 4 +--- src/display/canvas-grid.cpp | 7 +------ src/document.cpp | 3 +-- src/live_effects/parameter/unit.cpp | 4 ++-- src/lpe-tool-context.cpp | 5 ++--- src/main.cpp | 1 - src/measure-context.cpp | 2 +- src/preferences.cpp | 4 ++-- src/sp-namedview.cpp | 5 +---- src/ui/dialog/clonetiler.cpp | 6 +----- src/ui/dialog/export.cpp | 4 ++-- src/ui/widget/page-sizer.cpp | 3 +-- src/ui/widget/page-sizer.h | 1 - src/ui/widget/scalar-unit.cpp | 7 ++++--- src/ui/widget/selected-style.cpp | 3 ++- src/ui/widget/unit-menu.cpp | 16 +++++++++------- src/ui/widget/unit-menu.h | 3 --- src/ui/widget/unit-tracker.cpp | 12 +++++++----- src/ui/widget/unit-tracker.h | 2 -- src/util/expression-evaluator.cpp | 4 ++-- src/util/units.cpp | 9 ++------- src/util/units.h | 2 ++ src/widgets/desktop-widget.cpp | 2 +- src/widgets/node-toolbar.cpp | 4 +--- src/widgets/paintbucket-toolbar.cpp | 2 +- src/widgets/rect-toolbar.cpp | 3 +-- src/widgets/ruler.cpp | 6 +----- src/widgets/select-toolbar.cpp | 5 +---- src/widgets/stroke-style.cpp | 2 +- 29 files changed, 50 insertions(+), 81 deletions(-) (limited to 'src') diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index d3db94975..f7a7cb39a 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -53,6 +53,7 @@ #include "round.h" #include "util/units.h" +using Inkscape::Util::unit_table; enum Dim3 { X=0, Y, Z }; @@ -160,7 +161,6 @@ CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_r : CanvasGrid(nv, in_repr, in_doc, GRID_AXONOMETRIC) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Inkscape::Util::UnitTable unit_table; gridunit = new Inkscape::Util::Unit(unit_table.getUnit(prefs->getString("/options/grids/axonom/units"))); if (!gridunit) gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px")); @@ -213,7 +213,6 @@ void CanvasAxonomGrid::readRepr() { gchar const *value; - Inkscape::Util::UnitTable unit_table; if ( (value = repr->attribute("originx")) ) { Inkscape::Util::Quantity q = unit_table.getQuantity(value); gridunit = q.unit; @@ -370,7 +369,6 @@ _wr.setUpdating (false); _rumg->setUnit (gridunit->abbr); gdouble val; - Inkscape::Util::UnitTable unit_table; val = origin[Geom::X]; val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); _rsu_ox->setValue (val); diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 1a5e0e52d..ef32c113b 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -55,6 +55,7 @@ #include "display/sp-canvas.h" using Inkscape::DocumentUndo; +using Inkscape::Util::unit_table; namespace Inkscape { @@ -397,8 +398,6 @@ void CanvasGrid::setOrigin(Geom::Point const &origin_px) Inkscape::SVGOStringStream os_x, os_y; gdouble val; - Inkscape::Util::UnitTable unit_table; - val = origin_px[Geom::X]; val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); os_x << val << gridunit->abbr; @@ -490,7 +489,6 @@ CanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPD : CanvasGrid(nv, in_repr, in_doc, GRID_RECTANGULAR) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Inkscape::Util::UnitTable unit_table; gridunit = new Inkscape::Util::Unit(unit_table.getUnit(prefs->getString("/options/grids/xy/units"))); if (!gridunit) { gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px")); @@ -588,8 +586,6 @@ static void validateInt(gint oldVal, void CanvasXYGrid::readRepr() { - Inkscape::Util::UnitTable unit_table; - gchar const *value; if ( (value = repr->attribute("originx")) ) { Inkscape::Util::Quantity q = unit_table.getQuantity(value); @@ -756,7 +752,6 @@ CanvasXYGrid::newSpecificWidget() _rumg->setUnit (gridunit->abbr); gdouble val; - Inkscape::Util::UnitTable unit_table; val = origin[Geom::X]; val = Inkscape::Util::Quantity::convert(val, "px", *gridunit); _rsu_ox->setValue (val); 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), diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp index 264b4b9ee..561766920 100644 --- a/src/live_effects/parameter/unit.cpp +++ b/src/live_effects/parameter/unit.cpp @@ -12,6 +12,8 @@ #include "verbs.h" #include "util/units.h" +using Inkscape::Util::unit_table; + namespace Inkscape { namespace LivePathEffect { @@ -22,7 +24,6 @@ UnitParam::UnitParam( const Glib::ustring& label, const Glib::ustring& tip, Effect* effect, Glib::ustring default_unit) : Parameter(label, tip, key, wr, effect) { - Inkscape::Util::UnitTable unit_table; defunit = new Inkscape::Util::Unit(unit_table.getUnit(default_unit)); unit = defunit; } @@ -34,7 +35,6 @@ UnitParam::~UnitParam() bool UnitParam::param_readSVGValue(const gchar * strvalue) { - Inkscape::Util::UnitTable unit_table; if (strvalue) { param_set_value(unit_table.getUnit(strvalue)); return true; diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp index 32096970f..4e50a12e1 100644 --- a/src/lpe-tool-context.cpp +++ b/src/lpe-tool-context.cpp @@ -41,6 +41,8 @@ #include "lpe-tool-context.h" +using Inkscape::Util::unit_table; + static void sp_lpetool_context_dispose(GObject *object); static void sp_lpetool_context_setup(SPEventContext *ec); @@ -444,8 +446,6 @@ lpetool_create_measuring_items(SPLPEToolContext *lc, Inkscape::Selection *select gchar *arc_length; double lengthval; - Inkscape::Util::UnitTable unit_table; - for (GSList const *i = selection->itemList(); i != NULL; i = i->next) { if (SP_IS_PATH(i->data)) { path = SP_PATH(i->data); @@ -488,7 +488,6 @@ void lpetool_update_measuring_items(SPLPEToolContext *lc) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - Inkscape::Util::UnitTable unit_table; SPPath *path; SPCurve *curve; double lengthval; diff --git a/src/main.cpp b/src/main.cpp index 577cc3d79..29f431aa8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,7 +68,6 @@ #include "color.h" #include "sp-item.h" #include "sp-root.h" -#include "util/units.h" #include "svg/svg.h" #include "svg/svg-color.h" diff --git a/src/measure-context.cpp b/src/measure-context.cpp index 465b1da80..3c02c6f15 100644 --- a/src/measure-context.cpp +++ b/src/measure-context.cpp @@ -46,6 +46,7 @@ using Inkscape::ControlManager; using Inkscape::CTLINE_SECONDARY; +using Inkscape::Util::unit_table; static void sp_measure_context_setup(SPEventContext *ec); static void sp_measure_context_finish(SPEventContext *ec); @@ -515,7 +516,6 @@ static gint sp_measure_context_root_handler(SPEventContext *event_context, GdkEv std::sort(intersections.begin(), intersections.end(), GeomPointSortPredicate); } - Inkscape::Util::UnitTable unit_table; Glib::ustring unit_name = prefs->getString("/tools/measure/unit"); if (!unit_name.compare("")) { unit_name = "px"; diff --git a/src/preferences.cpp b/src/preferences.cpp index 1d7009a99..0dc6f1ec4 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -28,6 +28,8 @@ #define PREFERENCES_FILE_NAME "preferences.xml" +using Inkscape::Util::unit_table; + namespace Inkscape { static Inkscape::XML::Document *loadImpl( std::string const& prefsFilename, Glib::ustring & errMsg ); @@ -777,8 +779,6 @@ double Preferences::_extractDouble(Entry const &v) double Preferences::_extractDouble(Entry const &v, Glib::ustring const &requested_unit) { - static Inkscape::Util::UnitTable unit_table; // load the unit_table once by making it static - double val = _extractDouble(v); Glib::ustring unit = _extractUnit(v); diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index dde205eed..48f8eba2a 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -40,6 +40,7 @@ #include using Inkscape::DocumentUndo; +using Inkscape::Util::unit_table; #define DEFAULTGRIDCOLOR 0x3f3fff25 #define DEFAULTGRIDEMPCOLOR 0x3f3fff60 @@ -287,8 +288,6 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va { SPNamedView *nv = SP_NAMEDVIEW(object); - static Inkscape::Util::UnitTable unit_table; - switch (key) { case SP_ATTR_VIEWONLY: nv->editable = (!value); @@ -1111,7 +1110,6 @@ double SPNamedView::getMarginLength(gchar const * const key, bool const use_width) { double value; - static Inkscape::Util::UnitTable unit_table; Inkscape::Util::Unit percent = unit_table.getUnit("%"); if(!this->storeAsDouble(key,&value)) { return 0.0; @@ -1133,7 +1131,6 @@ Inkscape::Util::Unit const SPNamedView::getDefaultUnit() const if (doc_units) { return *doc_units; } else { - Inkscape::Util::UnitTable unit_table; return *(new Inkscape::Util::Unit(unit_table.getUnit("pt"))); } } diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index abb2512f7..b3675440b 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -58,6 +58,7 @@ #include "sp-root.h" using Inkscape::DocumentUndo; +using Inkscape::Util::unit_table; namespace Inkscape { namespace UI { @@ -1107,7 +1108,6 @@ CloneTiler::CloneTiler (void) : double value = prefs->getDouble(prefs_path + "fillwidth", 50.0); Inkscape::Util::Unit const unit = unit_menu->getUnit(); - Inkscape::Util::UnitTable unit_table; gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit); fill_width->set_value (units); @@ -1141,7 +1141,6 @@ CloneTiler::CloneTiler (void) : double value = prefs->getDouble(prefs_path + "fillheight", 50.0); Inkscape::Util::Unit const unit = unit_menu->getUnit(); - Inkscape::Util::UnitTable unit_table; gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit); fill_height->set_value (units); @@ -2950,7 +2949,6 @@ void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI: { gdouble const raw_dist = gtk_adjustment_get_value (adj); Inkscape::Util::Unit const unit = u->getUnit(); - Inkscape::Util::UnitTable unit_table; gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -2961,7 +2959,6 @@ void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI { gdouble const raw_dist = gtk_adjustment_get_value (adj); Inkscape::Util::Unit const unit = u->getUnit(); - Inkscape::Util::UnitTable unit_table; gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -2975,7 +2972,6 @@ void CloneTiler::clonetiler_unit_changed() gdouble height_pixels = prefs->getDouble(prefs_path + "fillheight"); Inkscape::Util::Unit unit = unit_menu->getUnit(); - Inkscape::Util::UnitTable unit_table; gdouble width_value = Inkscape::Util::Quantity::convert(width_pixels, "px", unit); gdouble height_value = Inkscape::Util::Quantity::convert(height_pixels, "px", unit); diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 063902aa7..2c92608d7 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -107,6 +107,8 @@ #include "verbs.h" #include "export.h" +using Inkscape::Util::unit_table; + namespace { class MessageCleaner @@ -1883,7 +1885,6 @@ void Export::setValuePx( Gtk::Adjustment *adj, double val) #endif { const Unit unit = unit_selector->getUnit(); - Inkscape::Util::UnitTable unit_table; setValue(adj, Inkscape::Util::Quantity::convert(val, "px", unit)); @@ -1934,7 +1935,6 @@ float Export::getValuePx( Gtk::Adjustment *adj ) { float value = getValue( adj); const Unit unit = unit_selector->getUnit(); - Inkscape::Util::UnitTable unit_table; return Inkscape::Util::Quantity::convert(value, unit, "px"); } // end of sp_export_value_get_px() diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index b15ab2823..d912fd9d3 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -47,9 +47,8 @@ #include "xml/node.h" #include "xml/repr.h" -static Inkscape::Util::UnitTable unit_table; - using std::pair; +using Inkscape::Util::unit_table; namespace Inkscape { namespace UI { diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h index fc8edeeac..34ed7592d 100644 --- a/src/ui/widget/page-sizer.h +++ b/src/ui/widget/page-sizer.h @@ -117,7 +117,6 @@ private: name = ""; smaller = 0.0; larger = 0.0; - static Inkscape::Util::UnitTable unit_table; unit = unit_table.getUnit("px"); } diff --git a/src/ui/widget/scalar-unit.cpp b/src/ui/widget/scalar-unit.cpp index 99ff70846..2f4c1f341 100644 --- a/src/ui/widget/scalar-unit.cpp +++ b/src/ui/widget/scalar-unit.cpp @@ -16,6 +16,8 @@ #include "scalar-unit.h" #include "spinbutton.h" +using Inkscape::Util::unit_table; + namespace Inkscape { namespace UI { namespace Widget { @@ -226,9 +228,8 @@ void ScalarUnit::on_unit_changed() Glib::ustring abbr = _unit_menu->getUnitAbbr(); _suffix->set_label(abbr); - Inkscape::Util::UnitTable &table = _unit_menu->getUnitTable(); - Inkscape::Util::Unit new_unit = (table.getUnit(abbr)); - Inkscape::Util::Unit old_unit = (table.getUnit(lastUnits)); + Inkscape::Util::Unit new_unit = (unit_table.getUnit(abbr)); + Inkscape::Util::Unit old_unit = (unit_table.getUnit(lastUnits)); double convertedVal = 0; if (old_unit.type == UNIT_TYPE_DIMENSIONLESS && new_unit.type == UNIT_TYPE_LINEAR) { diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index edf53d25c..388a0bcea 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -52,6 +52,8 @@ #include "gradient-chemistry.h" #include "util/units.h" +using Inkscape::Util::unit_table; + static gdouble const _sw_presets[] = { 32 , 16 , 10 , 8 , 6 , 4 , 3 , 2 , 1.5 , 1 , 0.75 , 0.5 , 0.25 , 0.1 }; static gchar const *const _sw_presets_str[] = {"32", "16", "10", "8", "6", "4", "3", "2", "1.5", "1", "0.75", "0.5", "0.25", "0.1"}; @@ -307,7 +309,6 @@ SelectedStyle::SelectedStyle(bool /*layout*/) { int row = 0; - Inkscape::Util::UnitTable unit_table; Inkscape::Util::UnitTable::UnitMap m = unit_table.units(Inkscape::Util::UNIT_TYPE_LINEAR); Inkscape::Util::UnitTable::UnitMap::iterator iter = m.begin(); while(iter != m.end()) { diff --git a/src/ui/widget/unit-menu.cpp b/src/ui/widget/unit-menu.cpp index 18b7bcab9..111226774 100644 --- a/src/ui/widget/unit-menu.cpp +++ b/src/ui/widget/unit-menu.cpp @@ -15,6 +15,8 @@ #include "unit-menu.h" +using Inkscape::Util::unit_table; + namespace Inkscape { namespace UI { namespace Widget { @@ -30,7 +32,7 @@ UnitMenu::~UnitMenu() { bool UnitMenu::setUnitType(UnitType unit_type) { // Expand the unit widget with unit entries from the unit table - UnitTable::UnitMap m = _unit_table.units(unit_type); + UnitTable::UnitMap m = unit_table.units(unit_type); UnitTable::UnitMap::iterator iter = m.begin(); while(iter != m.end()) { Glib::ustring text = (*iter).first; @@ -38,7 +40,7 @@ bool UnitMenu::setUnitType(UnitType unit_type) ++iter; } _type = unit_type; - set_active_text(_unit_table.primary(unit_type)); + set_active_text(unit_table.primary(unit_type)); return true; } @@ -52,7 +54,7 @@ bool UnitMenu::resetUnitType(UnitType unit_type) void UnitMenu::addUnit(Unit const& u) { - _unit_table.addUnit(u, false); + unit_table.addUnit(u, false); append(u.abbr); } @@ -60,9 +62,9 @@ Unit UnitMenu::getUnit() const { if (get_active_text() == "") { g_assert(_type != UNIT_TYPE_NONE); - return _unit_table.getUnit(_unit_table.primary(_type)); + return unit_table.getUnit(unit_table.primary(_type)); } - return _unit_table.getUnit(get_active_text()); + return unit_table.getUnit(get_active_text()); } bool UnitMenu::setUnit(Glib::ustring const & unit) @@ -112,8 +114,8 @@ double UnitMenu::getConversion(Glib::ustring const &new_unit_abbr, Glib::ustring { double old_factor = getUnit().factor; if (old_unit_abbr != "no_unit") - old_factor = _unit_table.getUnit(old_unit_abbr).factor; - Unit new_unit = _unit_table.getUnit(new_unit_abbr); + old_factor = unit_table.getUnit(old_unit_abbr).factor; + Unit new_unit = unit_table.getUnit(new_unit_abbr); // Catch the case of zero or negative unit factors (error!) if (old_factor < 0.0000001 || diff --git a/src/ui/widget/unit-menu.h b/src/ui/widget/unit-menu.h index 3104d5aef..3f4df6bf9 100644 --- a/src/ui/widget/unit-menu.h +++ b/src/ui/widget/unit-menu.h @@ -127,10 +127,7 @@ public: */ bool isRadial() const; - UnitTable &getUnitTable() {return _unit_table;} - protected: - UnitTable _unit_table; UnitType _type; }; diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp index 99074be40..5b2dc031b 100644 --- a/src/ui/widget/unit-tracker.cpp +++ b/src/ui/widget/unit-tracker.cpp @@ -17,6 +17,9 @@ #define COLUMN_STRING 0 +using Inkscape::Util::UnitTable; +using Inkscape::Util::unit_table; + namespace Inkscape { namespace UI { namespace Widget { @@ -32,10 +35,9 @@ UnitTracker::UnitTracker(UnitType unit_type) : _priorValues() { _store = gtk_list_store_new(1, G_TYPE_STRING); - static Inkscape::Util::UnitTable unit_table; GtkTreeIter iter; - UnitTable::UnitMap m = _unit_table.units(unit_type); + UnitTable::UnitMap m = unit_table.units(unit_type); UnitTable::UnitMap::iterator m_iter = m.begin(); while(m_iter != m.end()) { Glib::ustring text = (*m_iter).first; @@ -99,7 +101,7 @@ void UnitTracker::setActiveUnit(Inkscape::Util::Unit const *unit) void UnitTracker::setActiveUnitByAbbr(gchar const *abbr) { - Inkscape::Util::Unit u = _unit_table.getUnit(abbr); + Inkscape::Util::Unit u = unit_table.getUnit(abbr); setActiveUnit(&u); } @@ -195,13 +197,13 @@ void UnitTracker::_setActive(gint active) if (found) { gchar *abbr; gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &abbr, -1); - Inkscape::Util::Unit unit = _unit_table.getUnit(abbr); + Inkscape::Util::Unit unit = unit_table.getUnit(abbr); found = gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(_store), &iter, NULL, active); if (found) { gchar *newAbbr; gtk_tree_model_get(GTK_TREE_MODEL(_store), &iter, COLUMN_STRING, &newAbbr, -1); - Inkscape::Util::Unit newUnit = _unit_table.getUnit(newAbbr); + Inkscape::Util::Unit newUnit = unit_table.getUnit(newAbbr); _activeUnit = newUnit; if (_adjList) { diff --git a/src/ui/widget/unit-tracker.h b/src/ui/widget/unit-tracker.h index cdcb07c57..19559ae1c 100644 --- a/src/ui/widget/unit-tracker.h +++ b/src/ui/widget/unit-tracker.h @@ -21,7 +21,6 @@ #include "util/units.h" using Inkscape::Util::Unit; -using Inkscape::Util::UnitTable; using Inkscape::Util::UnitType; namespace Inkscape { @@ -46,7 +45,6 @@ public: GtkAction *createAction(gchar const *name, gchar const *label, gchar const *tooltip); protected: - UnitTable _unit_table; UnitType _type; private: diff --git a/src/util/expression-evaluator.cpp b/src/util/expression-evaluator.cpp index 3e1bab6bc..dc59c67f4 100644 --- a/src/util/expression-evaluator.cpp +++ b/src/util/expression-evaluator.cpp @@ -29,6 +29,8 @@ #include +using Inkscape::Util::unit_table; + namespace Inkscape { namespace Util { @@ -77,8 +79,6 @@ typedef struct */ static bool unitresolverproc (const gchar* identifier, GimpEevlQuantity *result, Unit* unit) { - static UnitTable unit_table; - if (!unit) { result->value = 1; result->dimension = 1; diff --git a/src/util/units.cpp b/src/util/units.cpp index 7f60eb391..7bc910fcc 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -303,6 +303,8 @@ bool UnitTable::save(std::string const &filename) { return true; } +Inkscape::Util::UnitTable unit_table; + void UnitParser::on_start_element(Ctx &ctx, Glib::ustring const &name, AttrMap const &attrs) { if (name == "unit") { @@ -358,7 +360,6 @@ Quantity::Quantity(double q, const Unit &u) } Quantity::Quantity(double q, const Glib::ustring u) { - UnitTable unit_table; unit = new Unit(unit_table.getUnit(u)); quantity = q; } @@ -369,7 +370,6 @@ bool Quantity::compatibleWith(const Unit &u) const } bool Quantity::compatibleWith(const Glib::ustring u) const { - static UnitTable unit_table; return compatibleWith(unit_table.getUnit(u)); } @@ -379,7 +379,6 @@ double Quantity::value(const Unit &u) const } double Quantity::value(const Glib::ustring u) const { - static UnitTable unit_table; return value(unit_table.getUnit(u)); } @@ -387,7 +386,6 @@ Glib::ustring Quantity::string(const Unit &u) const { return Glib::ustring::format(std::fixed, std::setprecision(2), value(u)) + " " + unit->abbr; } Glib::ustring Quantity::string(const Glib::ustring u) const { - static UnitTable unit_table; return string(unit_table.getUnit(u)); } Glib::ustring Quantity::string() const { @@ -411,17 +409,14 @@ double Quantity::convert(const double from_dist, const Unit &from, const Unit &t } double Quantity::convert(const double from_dist, const Glib::ustring from, const Unit &to) { - static UnitTable unit_table; return convert(from_dist, unit_table.getUnit(from), to); } double Quantity::convert(const double from_dist, const Unit &from, const Glib::ustring to) { - static UnitTable unit_table; return convert(from_dist, from, unit_table.getUnit(to)); } double Quantity::convert(const double from_dist, const Glib::ustring from, const Glib::ustring to) { - static UnitTable unit_table; return convert(from_dist, unit_table.getUnit(from), unit_table.getUnit(to)); } diff --git a/src/util/units.h b/src/util/units.h index c30fa24b3..bb202b96a 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -175,6 +175,8 @@ class UnitTable { }; +extern UnitTable unit_table; + } // namespace Util } // namespace Inkscape diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 863912d03..6493da84d 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -83,6 +83,7 @@ using Inkscape::UI::Widget::UnitTracker; using Inkscape::UI::UXManager; using Inkscape::UI::ToolboxFactory; using ege::AppearTimeTracker; +using Inkscape::Util::unit_table; enum { ACTIVATE, @@ -393,7 +394,6 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) GtkWidget *eventbox = gtk_event_box_new (); dtw->hruler = sp_ruler_new(GTK_ORIENTATION_HORIZONTAL); dtw->hruler_box = eventbox; - Inkscape::Util::UnitTable unit_table; Inkscape::Util::Unit pt = unit_table.getUnit("pt"); sp_ruler_set_unit(SP_RULER(dtw->hruler), pt); gtk_widget_set_tooltip_text (dtw->hruler_box, gettext(pt.name_plural.c_str())); diff --git a/src/widgets/node-toolbar.cpp b/src/widgets/node-toolbar.cpp index 65e42a60b..a9e298f1d 100644 --- a/src/widgets/node-toolbar.cpp +++ b/src/widgets/node-toolbar.cpp @@ -70,6 +70,7 @@ using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; using Inkscape::UI::PrefPusher; +using Inkscape::Util::unit_table; //#################################### //# node editing callbacks @@ -249,7 +250,6 @@ static void sp_node_toolbox_coord_changed(gpointer /*shape_editor*/, GObject *tb } else { gtk_action_set_sensitive(xact, TRUE); gtk_action_set_sensitive(yact, TRUE); - Inkscape::Util::UnitTable unit_table; Geom::Coord oldx = Quantity::convert(gtk_adjustment_get_value(xadj), unit, "px"); Geom::Coord oldy = Quantity::convert(gtk_adjustment_get_value(yadj), unit, "px"); Geom::Point mid = nt->_selected_nodes->pointwiseBounds()->midpoint(); @@ -276,8 +276,6 @@ static void sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::D } Unit const unit = tracker->getActiveUnit(); - Inkscape::Util::UnitTable unit_table; - if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { prefs->setDouble(Glib::ustring("/tools/nodes/") + (d == Geom::X ? "x" : "y"), Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); diff --git a/src/widgets/paintbucket-toolbar.cpp b/src/widgets/paintbucket-toolbar.cpp index 3bb1fa24a..7c23379cd 100644 --- a/src/widgets/paintbucket-toolbar.cpp +++ b/src/widgets/paintbucket-toolbar.cpp @@ -68,6 +68,7 @@ using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; using Inkscape::UI::PrefPusher; +using Inkscape::Util::unit_table; @@ -175,7 +176,6 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions // Create the units menu. UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); - Inkscape::Util::UnitTable unit_table; Glib::ustring stored_unit = prefs->getString("/tools/paintbucket/offsetunits"); if (!stored_unit.empty()) { Unit u = unit_table.getUnit(stored_unit); diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 29488031f..6dfd9cfcb 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -66,6 +66,7 @@ using Inkscape::UI::ToolboxFactory; using Inkscape::UI::PrefPusher; using Inkscape::Util::Unit; using Inkscape::Util::Quantity; +using Inkscape::Util::unit_table; //######################## @@ -93,7 +94,6 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * UnitTracker* tracker = reinterpret_cast(g_object_get_data( tbl, "tracker" )); Unit const unit = tracker->getActiveUnit(); - Inkscape::Util::UnitTable unit_table; if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -187,7 +187,6 @@ static void rect_tb_event_attr_changed(Inkscape::XML::Node * /*repr*/, gchar con UnitTracker* tracker = reinterpret_cast( g_object_get_data( tbl, "tracker" ) ); Unit const unit = tracker->getActiveUnit(); - Inkscape::Util::UnitTable unit_table; gpointer item = g_object_get_data( tbl, "item" ); if (item && SP_IS_RECT(item)) { diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp index 274e1df54..e4e72d86e 100644 --- a/src/widgets/ruler.cpp +++ b/src/widgets/ruler.cpp @@ -44,6 +44,7 @@ #define DEFAULT_RULER_FONT_SCALE PANGO_SCALE_X_SMALL #define MINIMUM_INCR 5 +using Inkscape::Util::unit_table; enum { PROP_0, @@ -258,8 +259,6 @@ sp_ruler_init (SPRuler *ruler) gtk_widget_set_has_window (GTK_WIDGET (ruler), FALSE); - Inkscape::Util::UnitTable unit_table; - priv->orientation = GTK_ORIENTATION_HORIZONTAL; priv->unit = new Inkscape::Util::Unit(unit_table.getUnit("px")); priv->lower = 0; @@ -380,8 +379,6 @@ sp_ruler_set_property (GObject *object, SPRuler *ruler = SP_RULER (object); SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - Inkscape::Util::UnitTable unit_table; - switch (prop_id) { case PROP_ORIENTATION: @@ -1189,7 +1186,6 @@ sp_ruler_draw_ticks (SPRuler *ruler) SPRulerMetric ruler_metric = ruler_metric_general; /* The metric to use for this unit system */ PangoLayout *layout; PangoRectangle logical_rect, ink_rect; - Inkscape::Util::UnitTable unit_table; if (! gtk_widget_is_drawable (widget)) return; diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index b39423635..e4a5a2905 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -59,6 +59,7 @@ using Inkscape::UI::Widget::UnitTracker; using Inkscape::Util::Unit; using Inkscape::Util::Quantity; using Inkscape::DocumentUndo; +using Inkscape::Util::unit_table; static void sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel) @@ -96,7 +97,6 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel) tracker->setFullVal( a, keyval[i].val ); } } else { - Inkscape::Util::UnitTable unit_table; for (unsigned i = 0; i < G_N_ELEMENTS(keyval); ++i) { GtkAdjustment *a = GTK_ADJUSTMENT(g_object_get_data(G_OBJECT(spw), keyval[i].key)); gtk_adjustment_set_value(a, Quantity::convert(keyval[i].val, "px", unit)); @@ -192,8 +192,6 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw) GtkAdjustment* a_w = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "width" ) ); GtkAdjustment* a_h = GTK_ADJUSTMENT( g_object_get_data( G_OBJECT(spw), "height" ) ); - Inkscape::Util::UnitTable unit_table; - if (unit.type == Inkscape::Util::UNIT_TYPE_LINEAR) { x0 = Quantity::convert(gtk_adjustment_get_value(a_x), unit, "px"); y0 = Quantity::convert(gtk_adjustment_get_value(a_y), unit, "px"); @@ -493,7 +491,6 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb // Create the units menu. UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); - Inkscape::Util::UnitTable unit_table; tracker->addUnit(unit_table.getUnit("%")); tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index e35a8b36b..12d4002b8 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -26,6 +26,7 @@ #include "ui/widget/unit-menu.h" using Inkscape::DocumentUndo; +using Inkscape::Util::unit_table; /** * Creates a new widget for the line stroke paint. @@ -196,7 +197,6 @@ StrokeStyle::StrokeStyle() : Gtk::Widget *us = manage(unitSelector); SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Inkscape::Util::UnitTable unit_table; unitSelector->addUnit(unit_table.getUnit("%")); if (desktop) { unitSelector->setUnit(sp_desktop_namedview(desktop)->doc_units->abbr); -- cgit v1.2.3 From 0ec2d349388ad6a4e0c35039b2f5c09cccadc6b0 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Tue, 6 Aug 2013 14:44:23 -0400 Subject: Fixed bug in page sizer. (bzr r12380.1.63) --- src/ui/widget/page-sizer.cpp | 138 +++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 69 deletions(-) (limited to 'src') diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index d912fd9d3..8287452d7 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -97,7 +97,7 @@ struct PaperSizeRec { char const * const name; //name double const smaller; //lesser dimension double const larger; //greater dimension - Inkscape::Util::Unit const unit; //units + Glib::ustring const unit; //units }; // list of page formats that should be in landscape automatically @@ -115,31 +115,31 @@ fill_landscape_papers() { } static PaperSizeRec const inkscape_papers[] = { - { "A4", 210, 297, unit_table.getUnit("mm") }, - { "US Letter", 8.5, 11, unit_table.getUnit("in") }, - { "US Legal", 8.5, 14, unit_table.getUnit("in") }, - { "US Executive", 7.25, 10.5, unit_table.getUnit("in") }, - { "A0", 841, 1189, unit_table.getUnit("mm") }, - { "A1", 594, 841, unit_table.getUnit("mm") }, - { "A2", 420, 594, unit_table.getUnit("mm") }, - { "A3", 297, 420, unit_table.getUnit("mm") }, - { "A5", 148, 210, unit_table.getUnit("mm") }, - { "A6", 105, 148, unit_table.getUnit("mm") }, - { "A7", 74, 105, unit_table.getUnit("mm") }, - { "A8", 52, 74, unit_table.getUnit("mm") }, - { "A9", 37, 52, unit_table.getUnit("mm") }, - { "A10", 26, 37, unit_table.getUnit("mm") }, - { "B0", 1000, 1414, unit_table.getUnit("mm") }, - { "B1", 707, 1000, unit_table.getUnit("mm") }, - { "B2", 500, 707, unit_table.getUnit("mm") }, - { "B3", 353, 500, unit_table.getUnit("mm") }, - { "B4", 250, 353, unit_table.getUnit("mm") }, - { "B5", 176, 250, unit_table.getUnit("mm") }, - { "B6", 125, 176, unit_table.getUnit("mm") }, - { "B7", 88, 125, unit_table.getUnit("mm") }, - { "B8", 62, 88, unit_table.getUnit("mm") }, - { "B9", 44, 62, unit_table.getUnit("mm") }, - { "B10", 31, 44, unit_table.getUnit("mm") }, + { "A4", 210, 297, "mm" }, + { "US Letter", 8.5, 11, "in" }, + { "US Legal", 8.5, 14, "in" }, + { "US Executive", 7.25, 10.5, "in" }, + { "A0", 841, 1189, "mm" }, + { "A1", 594, 841, "mm" }, + { "A2", 420, 594, "mm" }, + { "A3", 297, 420, "mm" }, + { "A5", 148, 210, "mm" }, + { "A6", 105, 148, "mm" }, + { "A7", 74, 105, "mm" }, + { "A8", 52, 74, "mm" }, + { "A9", 37, 52, "mm" }, + { "A10", 26, 37, "mm" }, + { "B0", 1000, 1414, "mm" }, + { "B1", 707, 1000, "mm" }, + { "B2", 500, 707, "mm" }, + { "B3", 353, 500, "mm" }, + { "B4", 250, 353, "mm" }, + { "B5", 176, 250, "mm" }, + { "B6", 125, 176, "mm" }, + { "B7", 88, 125, "mm" }, + { "B8", 62, 88, "mm" }, + { "B9", 44, 62, "mm" }, + { "B10", 31, 44, "mm" }, @@ -151,63 +151,63 @@ static PaperSizeRec const inkscape_papers[] = { don't know what D and E series are used for. */ - { "C0", 917, 1297, unit_table.getUnit("mm") }, - { "C1", 648, 917, unit_table.getUnit("mm") }, - { "C2", 458, 648, unit_table.getUnit("mm") }, - { "C3", 324, 458, unit_table.getUnit("mm") }, - { "C4", 229, 324, unit_table.getUnit("mm") }, - { "C5", 162, 229, unit_table.getUnit("mm") }, - { "C6", 114, 162, unit_table.getUnit("mm") }, - { "C7", 81, 114, unit_table.getUnit("mm") }, - { "C8", 57, 81, unit_table.getUnit("mm") }, - { "C9", 40, 57, unit_table.getUnit("mm") }, - { "C10", 28, 40, unit_table.getUnit("mm") }, - { "D1", 545, 771, unit_table.getUnit("mm") }, - { "D2", 385, 545, unit_table.getUnit("mm") }, - { "D3", 272, 385, unit_table.getUnit("mm") }, - { "D4", 192, 272, unit_table.getUnit("mm") }, - { "D5", 136, 192, unit_table.getUnit("mm") }, - { "D6", 96, 136, unit_table.getUnit("mm") }, - { "D7", 68, 96, unit_table.getUnit("mm") }, - { "E3", 400, 560, unit_table.getUnit("mm") }, - { "E4", 280, 400, unit_table.getUnit("mm") }, - { "E5", 200, 280, unit_table.getUnit("mm") }, - { "E6", 140, 200, unit_table.getUnit("mm") }, + { "C0", 917, 1297, "mm" }, + { "C1", 648, 917, "mm" }, + { "C2", 458, 648, "mm" }, + { "C3", 324, 458, "mm" }, + { "C4", 229, 324, "mm" }, + { "C5", 162, 229, "mm" }, + { "C6", 114, 162, "mm" }, + { "C7", 81, 114, "mm" }, + { "C8", 57, 81, "mm" }, + { "C9", 40, 57, "mm" }, + { "C10", 28, 40, "mm" }, + { "D1", 545, 771, "mm" }, + { "D2", 385, 545, "mm" }, + { "D3", 272, 385, "mm" }, + { "D4", 192, 272, "mm" }, + { "D5", 136, 192, "mm" }, + { "D6", 96, 136, "mm" }, + { "D7", 68, 96, "mm" }, + { "E3", 400, 560, "mm" }, + { "E4", 280, 400, "mm" }, + { "E5", 200, 280, "mm" }, + { "E6", 140, 200, "mm" }, //#endif - { "CSE", 462, 649, unit_table.getUnit("pt") }, - { "US #10 Envelope", 4.125, 9.5, unit_table.getUnit("in") }, + { "CSE", 462, 649, "pt" }, + { "US #10 Envelope", 4.125, 9.5, "in" }, /* See http://www.hbp.com/content/PCR_envelopes.cfm for a much larger list of US envelope sizes. */ - { "DL Envelope", 110, 220, unit_table.getUnit("mm") }, - { "Ledger/Tabloid", 11, 17, unit_table.getUnit("in") }, + { "DL Envelope", 110, 220, "mm" }, + { "Ledger/Tabloid", 11, 17, "in" }, /* Note that `Folio' (used in QPrinter/KPrinter) is deliberately absent from this list, as it means different sizes to different people: different people may expect the width to be either 8, 8.25 or 8.5 inches, and the height to be either 13 or 13.5 inches, even restricting our interpretation to foolscap folio. If you wish to introduce a folio-like page size to the list, then please consider using a name more specific than just `Folio' or `Foolscap Folio'. */ - { "Banner 468x60", 60, 468, unit_table.getUnit("px") }, - { "Icon 16x16", 16, 16, unit_table.getUnit("px") }, - { "Icon 32x32", 32, 32, unit_table.getUnit("px") }, - { "Icon 48x48", 48, 48, unit_table.getUnit("px") }, + { "Banner 468x60", 60, 468, "px" }, + { "Icon 16x16", 16, 16, "px" }, + { "Icon 32x32", 32, 32, "px" }, + { "Icon 48x48", 48, 48, "px" }, /* business cards */ - { "Business Card (ISO 7810)", 53.98, 85.60, unit_table.getUnit("mm") }, - { "Business Card (US)", 2, 3.5, unit_table.getUnit("in") }, - { "Business Card (Europe)", 55, 85, unit_table.getUnit("mm") }, - { "Business Card (Aus/NZ)", 55, 90, unit_table.getUnit("mm") }, + { "Business Card (ISO 7810)", 53.98, 85.60, "mm" }, + { "Business Card (US)", 2, 3.5, "in" }, + { "Business Card (Europe)", 55, 85, "mm" }, + { "Business Card (Aus/NZ)", 55, 90, "mm" }, // Start Arch Series List - { "Arch A", 9, 12, unit_table.getUnit("in") }, // 229 x 305 mm - { "Arch B", 12, 18, unit_table.getUnit("in") }, // 305 x 457 mm - { "Arch C", 18, 24, unit_table.getUnit("in") }, // 457 x 610 mm - { "Arch D", 24, 36, unit_table.getUnit("in") }, // 610 x 914 mm - { "Arch E", 36, 48, unit_table.getUnit("in") }, // 914 x 1219 mm - { "Arch E1", 30, 42, unit_table.getUnit("in") }, // 762 x 1067 mm + { "Arch A", 9, 12, "in" }, // 229 x 305 mm + { "Arch B", 12, 18, "in" }, // 305 x 457 mm + { "Arch C", 18, 24, "in" }, // 457 x 610 mm + { "Arch D", 24, 36, "in" }, // 610 x 914 mm + { "Arch E", 36, 48, "in" }, // 914 x 1219 mm + { "Arch E1", 30, 42, "in" }, // 762 x 1067 mm /* * The above list of Arch sizes were taken from the following site: @@ -218,7 +218,7 @@ static PaperSizeRec const inkscape_papers[] = { * September 2009 - DAK */ - { NULL, 0, 0, unit_table.getUnit("px") }, + { NULL, 0, 0, "px" }, }; @@ -277,8 +277,8 @@ PageSizer::PageSizer(Registry & _wr) char formatBuf[80]; snprintf(formatBuf, 79, "%0.1f x %0.1f", p->smaller, p->larger); Glib::ustring desc = formatBuf; - desc.append(" " + p->unit.abbr); - PaperSize paper(name, p->smaller, p->larger, p->unit); + desc.append(" " + p->unit); + PaperSize paper(name, p->smaller, p->larger, unit_table.getUnit(p->unit)); _paperSizeTable[name] = paper; Gtk::TreeModel::Row row = *(_paperSizeListStore->append()); row[_paperSizeListColumns.nameColumn] = name; -- cgit v1.2.3