diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/display/canvas-axonomgrid.cpp | 21 | ||||
| -rw-r--r-- | src/display/canvas-grid.cpp | 40 | ||||
| -rw-r--r-- | src/document.cpp | 20 | ||||
| -rw-r--r-- | src/measure-context.cpp | 14 | ||||
| -rw-r--r-- | src/sp-namedview.cpp | 3 | ||||
| -rw-r--r-- | src/ui/dialog/clonetiler.cpp | 17 | ||||
| -rw-r--r-- | src/ui/dialog/export.cpp | 6 | ||||
| -rw-r--r-- | src/ui/widget/page-sizer.cpp | 17 | ||||
| -rw-r--r-- | src/ui/widget/unit-tracker.cpp | 7 | ||||
| -rw-r--r-- | src/util/units.cpp | 92 | ||||
| -rw-r--r-- | src/util/units.h | 22 | ||||
| -rw-r--r-- | src/widgets/node-toolbar.cpp | 14 | ||||
| -rw-r--r-- | src/widgets/rect-toolbar.cpp | 14 | ||||
| -rw-r--r-- | src/widgets/select-toolbar.cpp | 24 |
14 files changed, 144 insertions, 167 deletions
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<Glib::ustring, Unit*> 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<UnitTracker*>(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<UnitTracker*>( 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 |
