diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2013-10-13 19:40:31 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2013-10-13 19:40:31 +0000 |
| commit | 34789891fcdbd099bd390ce3d0465dee24a788db (patch) | |
| tree | 1b16d78374f9d56c0f03a6b20c9e2e6048f4fb5e /src | |
| parent | update to trunk (diff) | |
| parent | UI message generalisation (diff) | |
| download | inkscape-34789891fcdbd099bd390ce3d0465dee24a788db.tar.gz inkscape-34789891fcdbd099bd390ce3d0465dee24a788db.zip | |
Update to trunk
(bzr r12588.1.12)
Diffstat (limited to 'src')
113 files changed, 1491 insertions, 1279 deletions
diff --git a/src/2geom/convex-cover.h b/src/2geom/convex-cover.h index a0443e9dc..a5f95a5fb 100644 --- a/src/2geom/convex-cover.h +++ b/src/2geom/convex-cover.h @@ -163,7 +163,7 @@ unsigned find_bottom_right(ConvexHull const &a); /*** Arbitrary transform operator. * Take a convex hull and apply an arbitrary convexity preserving transform. - * we should be concerned about singular tranforms here. + * we should be concerned about singular transforms here. */ template <class T> ConvexHull operator*(ConvexHull const &p, T const &m) { ConvexHull pr; diff --git a/src/Makefile.am b/src/Makefile.am index a45a33932..411e3cf86 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -266,7 +266,7 @@ TESTS = $(check_PROGRAMS) ../share/extensions/test/run-all-extension-tests XFAIL_TESTS = $(check_PROGRAMS) -# including the the testsuites here ensures that they get distributed +# including the testsuites here ensures that they get distributed cxxtests_SOURCES = cxxtests.cpp $(CXXTEST_TESTSUITES) $(ink_common_sources) $(win32_sources) cxxtests_LDADD = $(all_libs) diff --git a/src/arc-context.cpp b/src/arc-context.cpp index 046541b9b..a14562a32 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -363,7 +363,7 @@ void SPArcContext::drag(Geom::Point pt, guint state) { // Set style sp_desktop_apply_style_tool(desktop, repr, "/tools/shapes/arc", false); - this->arc = SP_ARC(desktop->currentLayer()->appendChildRepr(repr)); + this->arc = SP_GENERICELLIPSE(desktop->currentLayer()->appendChildRepr(repr)); Inkscape::GC::release(repr); this->arc->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); this->arc->updateRepr(); @@ -409,17 +409,17 @@ void SPArcContext::drag(Geom::Point pt, guint state) { } } - this->arc->sp_arc_position_set( - r.midpoint()[Geom::X], r.midpoint()[Geom::Y], - r.dimensions()[Geom::X] / 2, r.dimensions()[Geom::Y] / 2); + this->arc->position_set( + r.midpoint()[Geom::X], r.midpoint()[Geom::Y], + r.dimensions()[Geom::X] / 2, r.dimensions()[Geom::Y] / 2); double rdimx = r.dimensions()[Geom::X]; double rdimy = r.dimensions()[Geom::Y]; 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()); + 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; diff --git a/src/arc-context.h b/src/arc-context.h index 56eb02943..6a0a6c071 100644 --- a/src/arc-context.h +++ b/src/arc-context.h @@ -41,7 +41,7 @@ public: virtual const std::string& getPrefsPath(); private: - SPArc *arc; + SPGenericEllipse *arc; Geom::Point center; diff --git a/src/box3d.cpp b/src/box3d.cpp index 193051ee5..ff99fccba 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -1325,6 +1325,15 @@ SPGroup *box3d_convert_to_group(SPBox3D *box) return SP_GROUP(doc->getObjectByRepr(grepr)); } +const char *SPBox3D::displayName() { + return _("3D Box"); +} + +gchar *SPBox3D::description() { + // We could put more details about the 3d box here + return g_strdup(""); +} + static inline void box3d_push_back_corner_pair(SPBox3D *box, std::list<std::pair<Geom::Point, Geom::Point> > &pts, int c1, int c2) { pts.push_back(std::make_pair(box3d_get_corner_screen(box, c1, false), diff --git a/src/box3d.h b/src/box3d.h index be5f1926c..1dec1e792 100644 --- a/src/box3d.h +++ b/src/box3d.h @@ -61,6 +61,8 @@ public: virtual const char* display_name(); virtual Geom::Affine set_transform(Geom::Affine const &transform); virtual void convert_to_guides(); + virtual const char* displayName(); + virtual gchar *description(); }; void box3d_position_set (SPBox3D *box); diff --git a/src/common-context.cpp b/src/common-context.cpp index fb984cbf1..2155f9739 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -19,50 +19,41 @@ #define DRAG_DEFAULT 1.0 #define DRAG_MAX 1.0 -SPCommonContext::SPCommonContext() : SPEventContext() { - this->tremor = 0; - this->usetilt = 0; - this->is_drawing = false; - this->xtilt = 0; - this->ytilt = 0; - this->usepressure = 0; - -// ctx->cursor_shape = cursor_eraser_xpm; -// ctx->hot_x = 4; -// ctx->hot_y = 4; - - this->accumulated = 0; - this->segments = 0; - this->currentcurve = 0; - this->currentshape = 0; - this->npoints = 0; - this->cal1 = 0; - this->cal2 = 0; - this->repr = 0; - - /* Common values */ - this->cur = Geom::Point(0,0); - this->last = Geom::Point(0,0); - this->vel = Geom::Point(0,0); - this->vel_max = 0; - this->acc = Geom::Point(0,0); - this->ang = Geom::Point(0,0); - this->del = Geom::Point(0,0); - - /* attributes */ - this->dragging = FALSE; - - this->mass = 0.3; - this->drag = DRAG_DEFAULT; - this->angle = 30.0; - this->width = 0.2; - this->pressure = DEFAULT_PRESSURE; - - this->vel_thin = 0.1; - this->flatness = 0.9; - this->cap_rounding = 0.0; - - this->abs_width = false; +SPCommonContext::SPCommonContext() : + SPEventContext(), + accumulated(NULL), + segments(NULL), + currentshape(NULL), + currentcurve(NULL), + cal1(NULL), + cal2(NULL), + point1(), + point2(), + repr(NULL), + cur(0,0), + vel(0,0), + vel_max(0), + acc(0,0), + ang(0,0), + last(0,0), + del(0,0), + pressure(DEFAULT_PRESSURE), + xtilt(0), + ytilt(0), + dragging(FALSE), + usepressure(FALSE), + usetilt(FALSE), + mass(0.3), + drag(DRAG_DEFAULT), + angle(30.0), + width(0.2), + vel_thin(0.1), + flatness(0.9), + tremor(0), + cap_rounding(0), + is_drawing(false), + abs_width(false) +{ } SPCommonContext::~SPCommonContext() { diff --git a/src/connector-context.cpp b/src/connector-context.cpp index 3d6a4f28e..99239533d 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -50,7 +50,7 @@ * changed so that it no longer defines special attributes to record * the points. Instead it uses single node paths to define points * who are then seperate objects that can be fixed on the canvas, - * grouped into objects and take full advantage of all tranform, snap + * grouped into objects and take full advantage of all transform, snap * and align functionality of all other objects. * * I think that the style change between polyline and orthogonal diff --git a/src/desktop.cpp b/src/desktop.cpp index d19a99da6..dbad37b92 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -1896,55 +1896,45 @@ SPDesktop::show_dialogs() /* - * Get each dialogs previous state from preferences and reopen on startup if needed. - * Map dialog 'open' verb ids to dialog last visible state preference. - * Would prefer to use the Dialog Manager to open, but currently it doesn't support non-dockable dialogs + * Get each dialogs previous state from preferences and reopen on startup if needed, without grabbing focus (canvas retains focus). + * Map dialog manager's dialog IDs to dialog last visible state preference. FIXME: store this correspondence in dialogs themselves! */ - std::map<int, Glib::ustring> mapVerbPreference; - std::map<int, Glib::ustring>::const_iterator iter; - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_LAYERS, "/dialogs/layers") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_FILL_STROKE, "/dialogs/fillstroke") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_EXTENSIONEDITOR, "/dialogs/extensioneditor") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_ALIGN_DISTRIBUTE, "/dialogs/align") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_METADATA, "/dialogs/documentmetadata") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_NAMEDVIEW, "/dialogs/documentoptions") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_FILTER_EFFECTS, "/dialogs/filtereffects") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_FIND, "/dialogs/find") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_GLYPHS, "/dialogs/glyphs") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_DEBUG, "/dialogs/messages") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_HELP_MEMORY, "/dialogs/memory") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_LIVE_PATH_EFFECT, "/dialogs/livepatheffect") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_UNDO_HISTORY, "/dialogs/undo-history") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_TRANSFORM, "/dialogs/transformation") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_SWATCHES, "/dialogs/swatches") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_VIEW_ICON_PREVIEW, "/dialogs/iconpreview") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_SVG_FONTS, "/dialogs/svgfonts") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_INPUT, "/dialogs/inputdevices") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_DISPLAY, "/dialogs/preferences") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_SELECTION_GRIDTILE, "/dialogs/gridtiler") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_SELECTION_TRACE, "/dialogs/trace") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_SELECTION_PIXEL_ART, "/dialogs/pixelart") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_TEXT, "/dialogs/textandfont") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_EXPORT, "/dialogs/export") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_XML_EDITOR, "/dialogs/xml") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_FIND, "/dialogs/find") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_CLONETILER, "/dialogs/clonetiler") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_ITEM, "/dialogs/object") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_SPELLCHECK, "/dialogs/spellcheck") ); - mapVerbPreference.insert(std::make_pair ((int)SP_VERB_DIALOG_SYMBOLS, "/dialogs/symbols") ); - - for (iter = mapVerbPreference.begin(); iter != mapVerbPreference.end(); iter++) { - int verbId = iter->first; + std::map<Glib::ustring, Glib::ustring> mapVerbPreference; + mapVerbPreference.insert(std::make_pair ("LayersPanel", "/dialogs/layers") ); + mapVerbPreference.insert(std::make_pair ("FillAndStroke", "/dialogs/fillstroke") ); + mapVerbPreference.insert(std::make_pair ("ExtensionEditor", "/dialogs/extensioneditor") ); + mapVerbPreference.insert(std::make_pair ("AlignAndDistribute", "/dialogs/align") ); + mapVerbPreference.insert(std::make_pair ("DocumentMetadata", "/dialogs/documentmetadata") ); + mapVerbPreference.insert(std::make_pair ("DocumentProperties", "/dialogs/documentoptions") ); + mapVerbPreference.insert(std::make_pair ("FilterEffectsDialog", "/dialogs/filtereffects") ); + mapVerbPreference.insert(std::make_pair ("Find", "/dialogs/find") ); + mapVerbPreference.insert(std::make_pair ("Glyphs", "/dialogs/glyphs") ); + mapVerbPreference.insert(std::make_pair ("Messages", "/dialogs/messages") ); + mapVerbPreference.insert(std::make_pair ("Memory", "/dialogs/memory") ); + mapVerbPreference.insert(std::make_pair ("LivePathEffect", "/dialogs/livepatheffect") ); + mapVerbPreference.insert(std::make_pair ("UndoHistory", "/dialogs/undo-history") ); + mapVerbPreference.insert(std::make_pair ("Transformation", "/dialogs/transformation") ); + mapVerbPreference.insert(std::make_pair ("Swatches", "/dialogs/swatches") ); + mapVerbPreference.insert(std::make_pair ("IconPreviewPanel", "/dialogs/iconpreview") ); + mapVerbPreference.insert(std::make_pair ("SvgFontsDialog", "/dialogs/svgfonts") ); + mapVerbPreference.insert(std::make_pair ("InputDevices", "/dialogs/inputdevices") ); + mapVerbPreference.insert(std::make_pair ("InkscapePreferences", "/dialogs/preferences") ); + mapVerbPreference.insert(std::make_pair ("TileDialog", "/dialogs/gridtiler") ); + mapVerbPreference.insert(std::make_pair ("Trace", "/dialogs/trace") ); + mapVerbPreference.insert(std::make_pair ("PixelArt", "/dialogs/pixelart") ); + mapVerbPreference.insert(std::make_pair ("TextFont", "/dialogs/textandfont") ); + mapVerbPreference.insert(std::make_pair ("Export", "/dialogs/export") ); + mapVerbPreference.insert(std::make_pair ("XmlTree", "/dialogs/xml") ); + mapVerbPreference.insert(std::make_pair ("CloneTiler", "/dialogs/clonetiler") ); + mapVerbPreference.insert(std::make_pair ("ObjectProperties", "/dialogs/object") ); + mapVerbPreference.insert(std::make_pair ("SpellCheck", "/dialogs/spellcheck") ); + mapVerbPreference.insert(std::make_pair ("Symbols", "/dialogs/symbols") ); + + for (std::map<Glib::ustring, Glib::ustring>::const_iterator iter = mapVerbPreference.begin(); iter != mapVerbPreference.end(); iter++) { Glib::ustring pref = iter->second; int visible = prefs->getInt(pref + "/visible", 0); if (visible) { - Inkscape::Verb *verb = Inkscape::Verb::get(verbId); - if (verb) { - SPAction *action = verb->get_action(Inkscape::ActionContext(this)); - if (action) { - sp_action_perform(action, NULL); - } - } + _dlg_mgr->showDialog(iter->first.c_str(), false); // without grabbing focus, we need focus to remain on the canvas } } } diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 451f0b509..5b358ade7 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -254,7 +254,6 @@ Pixbuf *Pixbuf::create_from_data_uri(gchar const *uri_data) } if ((*data) && data_is_image && data_is_base64) { - GdkPixbuf *buf = NULL; GdkPixbufLoader *loader = gdk_pixbuf_loader_new(); if (!loader) return NULL; @@ -264,7 +263,7 @@ Pixbuf *Pixbuf::create_from_data_uri(gchar const *uri_data) if (gdk_pixbuf_loader_write(loader, decoded, decoded_len, NULL)) { gdk_pixbuf_loader_close(loader, NULL); - buf = gdk_pixbuf_loader_get_pixbuf(loader); + GdkPixbuf *buf = gdk_pixbuf_loader_get_pixbuf(loader); if (buf) { g_object_ref(buf); pixbuf = new Pixbuf(buf); diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index f7a7cb39a..d66b97bbc 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -161,15 +161,16 @@ CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_r : CanvasGrid(nv, in_repr, in_doc, GRID_AXONOMETRIC) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - 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"); + gridunit = unit_table.getUnit(prefs->getString("/options/grids/axonom/units")); + if (!gridunit) { + gridunit = 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 = 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; @@ -214,18 +215,18 @@ CanvasAxonomGrid::readRepr() { gchar const *value; if ( (value = repr->attribute("originx")) ) { - Inkscape::Util::Quantity q = unit_table.getQuantity(value); + Inkscape::Util::Quantity q = unit_table.parseQuantity(value); gridunit = q.unit; - origin[Geom::X] = unit_table.getQuantity(value).value("px"); + origin[Geom::X] = q.value("px"); } if ( (value = repr->attribute("originy")) ) { - Inkscape::Util::Quantity q = unit_table.getQuantity(value); + Inkscape::Util::Quantity q = unit_table.parseQuantity(value); gridunit = q.unit; - origin[Geom::Y] = unit_table.getQuantity(value).value("px"); + origin[Geom::Y] = q.value("px"); } if ( (value = repr->attribute("spacingy")) ) { - Inkscape::Util::Quantity q = unit_table.getQuantity(value); + Inkscape::Util::Quantity q = unit_table.parseQuantity(value); gridunit = q.unit; lengthy = q.value("px"); if (lengthy < 0.0500) lengthy = 0.0500; @@ -370,13 +371,13 @@ _wr.setUpdating (false); gdouble val; 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 ef32c113b..192cc4cba 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -399,10 +399,10 @@ void CanvasGrid::setOrigin(Geom::Point const &origin_px) gdouble val; 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()); @@ -489,17 +489,17 @@ 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 = new Inkscape::Util::Unit(unit_table.getUnit(prefs->getString("/options/grids/xy/units"))); + gridunit = unit_table.getUnit(prefs->getString("/options/grids/xy/units")); if (!gridunit) { - gridunit = new Inkscape::Util::Unit(unit_table.getUnit("px")); + gridunit = 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); @@ -588,32 +588,32 @@ CanvasXYGrid::readRepr() { gchar const *value; if ( (value = repr->attribute("originx")) ) { - Inkscape::Util::Quantity q = unit_table.getQuantity(value); + Inkscape::Util::Quantity q = unit_table.parseQuantity(value); gridunit = q.unit; - origin[Geom::X] = unit_table.getQuantity(value).value("px"); + origin[Geom::X] = q.value("px"); } if ( (value = repr->attribute("originy")) ) { - Inkscape::Util::Quantity q = unit_table.getQuantity(value); + Inkscape::Util::Quantity q = unit_table.parseQuantity(value); gridunit = q.unit; - origin[Geom::Y] = unit_table.getQuantity(value).value("px"); + origin[Geom::Y] = q.value("px"); } if ( (value = repr->attribute("spacingx")) ) { double oldVal = spacing[Geom::X]; - Inkscape::Util::Quantity q = unit_table.getQuantity(value); + Inkscape::Util::Quantity q = unit_table.parseQuantity(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"); + spacing[Geom::X] = Inkscape::Util::Quantity::convert(spacing[Geom::X], gridunit, "px"); } if ( (value = repr->attribute("spacingy")) ) { double oldVal = spacing[Geom::Y]; - Inkscape::Util::Quantity q = unit_table.getQuantity(value); + Inkscape::Util::Quantity q = unit_table.parseQuantity(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"); + spacing[Geom::Y] = Inkscape::Util::Quantity::convert(spacing[Geom::Y], gridunit, "px"); } if ( (value = repr->attribute("color")) ) { @@ -753,16 +753,16 @@ CanvasXYGrid::newSpecificWidget() gdouble val; 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); diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h index 56ed86e94..078670da7 100644 --- a/src/display/canvas-grid.h +++ b/src/display/canvas-grid.h @@ -92,7 +92,7 @@ public: guint32 empcolor; /**< Color for emphasis lines */ gint empspacing; /**< Spacing between emphasis lines */ - Inkscape::Util::Unit const* gridunit; + Inkscape::Util::Unit const* gridunit; /**< points to Unit object in UnitTable (so don't delete it) */ Inkscape::XML::Node * repr; SPDocument *doc; diff --git a/src/display/drawing-item.cpp b/src/display/drawing-item.cpp index 69adcb441..a8257e6e5 100644 --- a/src/display/drawing-item.cpp +++ b/src/display/drawing-item.cpp @@ -459,7 +459,7 @@ struct MaskLuminanceToAlpha { /** * Rasterize items. * This method submits the drawing opeartions required to draw this item - * to the supplied DrawingContext, restricting drawing the the specified area. + * to the supplied DrawingContext, restricting drawing the specified area. * * This method does some common tasks and calls the item-specific rendering * function, _renderItem(), to render e.g. paths or bitmaps. diff --git a/src/document.cpp b/src/document.cpp index b94b72bda..4f57cf080 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -556,8 +556,8 @@ SPDocument *SPDocument::doUnref() Inkscape::Util::Quantity SPDocument::getWidth() const { - g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit())); - g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit())); + g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit(""))); + g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit(""))); gdouble result = root->width.value; SVGLength::Unit u = root->width.unit; @@ -577,7 +577,7 @@ void SPDocument::setWidth(const Inkscape::Util::Quantity &width) 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")) { + if (*width.unit == *unit_table.getUnit("m")) { root->width.value = width.value("cm"); root->width.unit = SVGLength::CM; } else { @@ -593,8 +593,8 @@ void SPDocument::setWidth(const Inkscape::Util::Quantity &width) Inkscape::Util::Quantity SPDocument::getHeight() const { - g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit())); - g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, Inkscape::Util::Unit())); + g_return_val_if_fail(this->priv != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit(""))); + g_return_val_if_fail(this->root != NULL, Inkscape::Util::Quantity(0.0, unit_table.getUnit(""))); gdouble result = root->height.value; SVGLength::Unit u = root->height.unit; @@ -614,7 +614,7 @@ void SPDocument::setHeight(const Inkscape::Util::Quantity &height) 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")) { + if (*height.unit == *unit_table.getUnit("m")) { root->height.value = height.value("cm"); root->height.unit = SVGLength::CM; } else { @@ -660,7 +660,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) double const h = rect.height(); double const old_height = getHeight().value("px"); - Inkscape::Util::Unit const px = unit_table.getUnit("px"); + Inkscape::Util::Unit const *px = unit_table.getUnit("px"); /* in px */ double margin_top = 0.0; @@ -674,17 +674,16 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) if (nv != NULL) { gchar const * const units_abbr = nv->getAttribute("units"); Inkscape::Util::Unit const *margin_units = NULL; - if (units_abbr != NULL) { - Inkscape::Util::Unit mu = unit_table.getUnit(units_abbr); - margin_units = μ + if (units_abbr) { + margin_units = unit_table.getUnit(units_abbr); } - if (margin_units == NULL) { - margin_units = &px; + if (!margin_units) { + margin_units = px; } - margin_top = nv->getMarginLength("fit-margin-top",margin_units, &px, w, h, false); - margin_left = nv->getMarginLength("fit-margin-left",margin_units, &px, w, h, true); - margin_right = nv->getMarginLength("fit-margin-right",margin_units, &px, w, h, true); - margin_bottom = nv->getMarginLength("fit-margin-bottom",margin_units, &px, w, h, false); + margin_top = nv->getMarginLength("fit-margin-top",margin_units, px, w, h, false); + margin_left = nv->getMarginLength("fit-margin-left",margin_units, px, w, h, true); + margin_right = nv->getMarginLength("fit-margin-right",margin_units, px, w, h, true); + margin_bottom = nv->getMarginLength("fit-margin-bottom",margin_units, px, w, h, false); } } @@ -693,8 +692,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/extension/extension.h b/src/extension/extension.h index 079276936..1fb8bdfec 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -144,12 +144,12 @@ private: extension */ public: - /** \brief A function to get the the number of parameters that + /** \brief A function to get the number of parameters that the extension has. \return The number of parameters. */ unsigned int param_count ( ) { return parameters == NULL ? 0 : g_slist_length(parameters); }; - /** \brief A function to get the the number of parameters that + /** \brief A function to get the number of parameters that are visible to the user that the extension has. \return The number of visible parameters. diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index d9489af31..f1876c687 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -46,6 +46,10 @@ #include "clear-n_.h" #include "document.h" #include "util/units.h" +#include "shape-editor.h" +#include "sp-namedview.h" +#include "document-undo.h" +#include "inkscape.h" #include "emf-print.h" #include "emf-inout.h" @@ -317,7 +321,7 @@ Emf::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filena } -/* given the transformation matrix from worldTranform return the scale in the matrix part. Assumes that the +/* given the transformation matrix from worldTransform return the scale in the matrix part. Assumes that the matrix is not used to skew, invert, or make another distorting transformation. */ double Emf::current_scale(PEMF_CALLBACK_DATA d){ double scale = @@ -328,7 +332,7 @@ double Emf::current_scale(PEMF_CALLBACK_DATA d){ return(scale); } -/* given the transformation matrix from worldTranform and the current x,y position in inkscape coordinates, +/* given the transformation matrix from worldTransform and the current x,y position in inkscape coordinates, generate an SVG transform that gives the same amount of rotation, no scaling, and maps x,y back onto x,y. This is used for rotating objects when the location of at least one point in that object is known. Returns: "matrix(a,b,c,d,e,f)" (WITH the double quotes) @@ -355,7 +359,7 @@ std::string Emf::current_matrix(PEMF_CALLBACK_DATA d, double x, double y, int us return(cxform.str()); } -/* given the transformation matrix from worldTranform return the rotation angle in radians. +/* given the transformation matrix from worldTransform return the rotation angle in radians. counter clocwise from the x axis. */ double Emf::current_rotation(PEMF_CALLBACK_DATA d){ return -std::atan2(d->dc[d->level].worldTransform.eM12, d->dc[d->level].worldTransform.eM11); @@ -3485,7 +3489,29 @@ Emf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) // Set viewBox if it doesn't exist if (!doc->getRoot()->viewBox_set) { + bool saved = Inkscape::DocumentUndo::getUndoSensitive(doc); + Inkscape::DocumentUndo::setUndoSensitive(doc, false); + + doc->ensureUpToDate(); + + // Set document unit + Inkscape::XML::Node *repr = sp_document_namedview(doc, 0)->getRepr(); + Inkscape::SVGOStringStream os; + os << doc->getWidth().unit->abbr; + repr->setAttribute("inkscape:document-units", os.str().c_str()); + + // Set viewBox doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity)); + + // Scale and translate objects + double scale = Inkscape::Util::Quantity::convert(1, "px", doc->getWidth().unit); + ShapeEditor::blockSetItem(true); + doc->getRoot()->scaleChildItemsRec(Geom::Scale(scale), Geom::Point(0, SP_ACTIVE_DOCUMENT->getHeight().value("px"))); + ShapeEditor::blockSetItem(false); + + doc->ensureUpToDate(); + + Inkscape::DocumentUndo::setUndoSensitive(doc, saved); } return doc; diff --git a/src/extension/internal/text_reassemble.c b/src/extension/internal/text_reassemble.c index 9ed6c9c3a..cd84910fc 100644 --- a/src/extension/internal/text_reassemble.c +++ b/src/extension/internal/text_reassemble.c @@ -1015,7 +1015,7 @@ int cxinfo_make_insertable(CX_INFO *cxi){ \brief Insert a complex into the CX_INFO structure. (Insert may be either TR_TEXT or TR_LINE.) \returns 0 on success, !0 on error. \param cxi pointer to the CX_INFO structure (complexes). - \param src index of the the complex to insert. + \param src index of the complex to insert. \param src_rt_tidx index of the bounding rectangle \param type TR_TEXT (index is for tpi->chunks[]) or TR_LINE (index is for cxi->kids[]) */ diff --git a/src/extension/internal/wmf-inout.cpp b/src/extension/internal/wmf-inout.cpp index e7dfa46d7..d69d46f20 100644 --- a/src/extension/internal/wmf-inout.cpp +++ b/src/extension/internal/wmf-inout.cpp @@ -46,6 +46,10 @@ #include "util/units.h" #include "clear-n_.h" #include "document.h" +#include "shape-editor.h" +#include "sp-namedview.h" +#include "document-undo.h" +#include "inkscape.h" #include "wmf-inout.h" @@ -316,12 +320,12 @@ Wmf::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filena } -/* WMF has no worldTranform, so this always returns 1.0. Retain it to keep WMF and WMF in sync as much as possible.*/ +/* WMF has no worldTransform, so this always returns 1.0. Retain it to keep WMF and WMF in sync as much as possible.*/ double Wmf::current_scale(PWMF_CALLBACK_DATA d){ return 1.0; } -/* WMF has no worldTranform, so this always returns an Identity rotation matrix, but the offsets may have values.*/ +/* WMF has no worldTransform, so this always returns an Identity rotation matrix, but the offsets may have values.*/ std::string Wmf::current_matrix(PWMF_CALLBACK_DATA d, double x, double y, int useoffset){ std::stringstream cxform; double scale = current_scale(d); @@ -336,7 +340,7 @@ std::string Wmf::current_matrix(PWMF_CALLBACK_DATA d, double x, double y, int us return(cxform.str()); } -/* WMF has no worldTranform, so this always returns 0. Retain it to keep WMF and WMF in sync as much as possible.*/ +/* WMF has no worldTransform, so this always returns 0. Retain it to keep WMF and WMF in sync as much as possible.*/ double Wmf::current_rotation(PWMF_CALLBACK_DATA d){ return 0.0; } @@ -3173,7 +3177,29 @@ Wmf::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) // Set viewBox if it doesn't exist if (!doc->getRoot()->viewBox_set) { + bool saved = Inkscape::DocumentUndo::getUndoSensitive(doc); + Inkscape::DocumentUndo::setUndoSensitive(doc, false); + + doc->ensureUpToDate(); + + // Set document unit + Inkscape::XML::Node *repr = sp_document_namedview(doc, 0)->getRepr(); + Inkscape::SVGOStringStream os; + os << doc->getWidth().unit->abbr; + repr->setAttribute("inkscape:document-units", os.str().c_str()); + + // Set viewBox doc->setViewBox(Geom::Rect::from_xywh(0, 0, doc->getWidth().quantity, doc->getHeight().quantity)); + + // Scale and translate objects + double scale = Inkscape::Util::Quantity::convert(1, "px", doc->getWidth().unit); + ShapeEditor::blockSetItem(true); + doc->getRoot()->scaleChildItemsRec(Geom::Scale(scale), Geom::Point(0, SP_ACTIVE_DOCUMENT->getHeight().value("px"))); + ShapeEditor::blockSetItem(false); + + doc->ensureUpToDate(); + + Inkscape::DocumentUndo::setUndoSensitive(doc, saved); } return doc; diff --git a/src/knotholder.cpp b/src/knotholder.cpp index 9abba83d7..7129348c2 100644 --- a/src/knotholder.cpp +++ b/src/knotholder.cpp @@ -242,7 +242,7 @@ KnotHolder::knot_ungrabbed_handler(SPKnot */*knot*/) void KnotHolder::add(KnotHolderEntity *e) { - g_message("Adding a knot at %p", e); + // g_message("Adding a knot at %p", e); entity.push_back(e); updateControlSizes(); } diff --git a/src/libavoid/connector.cpp b/src/libavoid/connector.cpp index 3dbd941a4..cf8cfa11a 100644 --- a/src/libavoid/connector.cpp +++ b/src/libavoid/connector.cpp @@ -286,7 +286,7 @@ void ConnRef::common_updateEndPoint(const unsigned int type, const ConnEnd& conn } VertInf *altered = NULL; - VertInf *partner = NULL; + // VertInf *partner = NULL; bool isShape = false; if (type == (unsigned int) VertID::src) @@ -302,7 +302,7 @@ void ConnRef::common_updateEndPoint(const unsigned int type, const ConnEnd& conn _srcVert->visDirections = connEnd.directions(); altered = _srcVert; - partner = _dstVert; + // partner = _dstVert; } else // if (type == (unsigned int) VertID::tar) { @@ -317,7 +317,7 @@ void ConnRef::common_updateEndPoint(const unsigned int type, const ConnEnd& conn _dstVert->visDirections = connEnd.directions(); altered = _dstVert; - partner = _srcVert; + // partner = _srcVert; } // XXX: Seems to be faster to just remove the edges and recreate diff --git a/src/libavoid/orthogonal.cpp b/src/libavoid/orthogonal.cpp index d0a899252..b5ef8d7e8 100644 --- a/src/libavoid/orthogonal.cpp +++ b/src/libavoid/orthogonal.cpp @@ -1510,7 +1510,7 @@ extern void generateStaticOrthogonalVisGraph(Router *router) const int pass = 1; processEventVert(router, scanline, segments, events[i], pass); } - COLA_ASSERT(scanline.size() == 0); + COLA_ASSERT(scanline.empty()); for (unsigned i = 0; i < totalEvents; ++i) { delete events[i]; @@ -1589,7 +1589,7 @@ extern void generateStaticOrthogonalVisGraph(Router *router) const int pass = 1; processEventHori(router, scanline, vertSegments, events[i], pass); } - COLA_ASSERT(scanline.size() == 0); + COLA_ASSERT(scanline.empty()); for (unsigned i = 0; i < totalEvents; ++i) { delete events[i]; @@ -1879,7 +1879,7 @@ static void buildOrthogonalChannelInfo(Router *router, processShiftEvent(router, scanline, segmentList, events[i], dim, pass); } - COLA_ASSERT(scanline.size() == 0); + COLA_ASSERT(scanline.empty()); for (unsigned i = 0; i < totalEvents; ++i) { delete events[i]; diff --git a/src/libavoid/router.cpp b/src/libavoid/router.cpp index ab13a981b..35f921bb4 100644 --- a/src/libavoid/router.cpp +++ b/src/libavoid/router.cpp @@ -58,13 +58,17 @@ class ActionInfo { } ActionInfo(ActionType t, ShapeRef *s) : type(t), - objPtr(s) + objPtr(s), + newPoly(), + firstMove(0) { COLA_ASSERT(type != ConnChange); } ActionInfo(ActionType t, ConnRef *c) : type(t), - objPtr(c) + objPtr(c), + newPoly(), + firstMove(0) { COLA_ASSERT(type == ConnChange); } diff --git a/src/libavoid/vpsc.cpp b/src/libavoid/vpsc.cpp index 1646ddaaa..bdf01d51c 100644 --- a/src/libavoid/vpsc.cpp +++ b/src/libavoid/vpsc.cpp @@ -104,7 +104,7 @@ void IncSolver::copyResult() { for(Variables::const_iterator i=vs.begin();i!=vs.end();++i) { Variable* v=*i; v->finalPosition=v->position(); - COLA_ASSERT(v->finalPosition==v->finalPosition); + COLA_ASSERT(v->finalPosition==v->finalPosition);/// TODO: check! Possibly some error in this line... } } @@ -132,16 +132,16 @@ bool IncSolver::constraintGraphIsCyclic(const unsigned n, Variable* const vs[]) varmap[vs[i]]->out.insert(varmap[r]); } } - while(graph.size()>0) { + while(!graph.empty()) { node *u=NULL; vector<node*>::iterator i=graph.begin(); for(;i!=graph.end();++i) { u=*i; - if(u->in.size()==0) { + if(u->in.empty()) { break; } } - if(i==graph.end() && graph.size()>0) { + if(i==graph.end() && !graph.empty()) { //cycle found! return true; } else { @@ -189,16 +189,16 @@ bool IncSolver::blockGraphIsCyclic() { c=b->findMinOutConstraint(); } } - while(graph.size()>0) { + while(!graph.empty()) { node *u=NULL; vector<node*>::iterator i=graph.begin(); for(;i!=graph.end();++i) { u=*i; - if(u->in.size()==0) { + if(u->in.empty()) { break; } } - if(i==graph.end() && graph.size()>0) { + if(i==graph.end() && !graph.empty()) { //cycle found! return true; } else { @@ -287,7 +287,7 @@ bool IncSolver::satisfy() { v->unsatisfiable=true; continue; } - } catch(UnsatisfiableException e) { + } catch(UnsatisfiableException& e) { e.path.push_back(v); std::cerr << "Unsatisfiable:" << std::endl; for(std::vector<Constraint*>::iterator r=e.path.begin(); @@ -1162,10 +1162,10 @@ Constraint* Block::splitBetween(Variable* const vl, Variable* const vr, f<<" need to split between: "<<*vl<<" and "<<*vr<<endl; #endif Constraint *c=findMinLMBetween(vl, vr); + if(c!=NULL) { #ifdef LIBVPSC_LOGGING f<<" going to split on: "<<*c<<endl; #endif - if(c!=NULL) { split(lb,rb,c); deleted = true; } diff --git a/src/libcola/gradient_projection.h b/src/libcola/gradient_projection.h index 66fc37aba..8cf45586c 100644 --- a/src/libcola/gradient_projection.h +++ b/src/libcola/gradient_projection.h @@ -225,7 +225,7 @@ public: delete [] g; delete [] d; delete [] old_place; - for(Constraints::iterator i(gcs.begin()); i!=gcs.end(); i++) { + for(Constraints::iterator i(gcs.begin()); i!=gcs.end(); ++i) { delete *i; } gcs.clear(); diff --git a/src/libcroco/cr-num.c b/src/libcroco/cr-num.c index c714894d6..062784c84 100644 --- a/src/libcroco/cr-num.c +++ b/src/libcroco/cr-num.c @@ -91,15 +91,13 @@ cr_num_new_with_val (gdouble a_val, enum CRNumType a_type) guchar * cr_num_to_string (CRNum * a_this) { - gdouble test_val = 0.0; - guchar *tmp_char1 = NULL, *tmp_char2 = NULL, *result = NULL; g_return_val_if_fail (a_this, NULL); - test_val = a_this->val - (glong) a_this->val; + gdouble test_val = a_this->val - (glong) a_this->val; if (!test_val) { tmp_char1 = (guchar *)g_strdup_printf ("%ld", (glong) a_this->val); diff --git a/src/libcroco/cr-parser.c b/src/libcroco/cr-parser.c index 917c5cb60..410f8f80f 100644 --- a/src/libcroco/cr-parser.c +++ b/src/libcroco/cr-parser.c @@ -3235,7 +3235,7 @@ cr_parser_parse_statement_core (CRParser * a_this) *ruleset ::= selector [ ',' S* selector ]* *'{' S* declaration? [ ';' S* declaration? ]* '}' S*; * - *This methods calls the the SAC handler on the relevant SAC handler + *This methods calls the SAC handler on the relevant SAC handler *callbacks whenever it encounters some specific constructions. *See the documentation of #CRDocHandler (the SAC handler) to know *when which SAC handler is called. diff --git a/src/libcroco/cr-rgb.c b/src/libcroco/cr-rgb.c index 893c2080b..e0c28701a 100644 --- a/src/libcroco/cr-rgb.c +++ b/src/libcroco/cr-rgb.c @@ -365,7 +365,7 @@ cr_rgb_is_set_to_inherit (CRRgb *a_this) } /** - *Tests if the the rgb is set to the + *Tests if the rgb is set to the *value "transparent" or not. *@param a_this the current instance of *#CRRgb diff --git a/src/libcroco/cr-sel-eng.c b/src/libcroco/cr-sel-eng.c index f010efea0..266191e82 100644 --- a/src/libcroco/cr-sel-eng.c +++ b/src/libcroco/cr-sel-eng.c @@ -839,7 +839,7 @@ cr_sel_eng_get_matched_rulesets_real (CRSelEng * a_this, sel_list = NULL; /* - *get the the damn selector list in + *get the damn selector list in *which we have to look */ switch (cur_stmt->type) { diff --git a/src/libcroco/cr-statement.c b/src/libcroco/cr-statement.c index 2b2c1836c..147cc8347 100644 --- a/src/libcroco/cr-statement.c +++ b/src/libcroco/cr-statement.c @@ -1907,7 +1907,7 @@ cr_statement_ruleset_set_sel_list (CRStatement * a_this, *Gets a pointer to the list of declaration contained *in the ruleset statement. *@param a_this the current instance of #CRStatement. - *@a_decl_list out parameter. A pointer to the the returned + *@a_decl_list out parameter. A pointer to the returned *list of declaration. Must not be NULL. *@return CR_OK upon successfull completion, an error code if something *bad happened. diff --git a/src/libcroco/cr-style.c b/src/libcroco/cr-style.c index e0abba83a..a9c5a5cec 100644 --- a/src/libcroco/cr-style.c +++ b/src/libcroco/cr-style.c @@ -36,7 +36,7 @@ *Each supported css property has an ID which is *an entry into a property "population" jump table. *each entry of the property population jump table - *contains code to tranform the literal form of + *contains code to transform the literal form of *a property value into a strongly typed value. */ enum CRPropertyID { @@ -148,7 +148,7 @@ static CRPropertyDesc gv_prop_table[] = { /** *A the key/value pair of this hash table *are: - *key => name of the the css propertie found in gv_prop_table + *key => name of the css property found in gv_prop_table *value => matching property id found in gv_prop_table. *So this hash table is here just to retrieval of a property id *from a property name. diff --git a/src/libcroco/cr-term.c b/src/libcroco/cr-term.c index 635577334..ccdff2522 100644 --- a/src/libcroco/cr-term.c +++ b/src/libcroco/cr-term.c @@ -766,7 +766,7 @@ cr_term_unref (CRTerm * a_this) } /** - *The destructor of the the #CRTerm class. + *The destructor of the #CRTerm class. *@param a_this the "this pointer" of the current instance *of #CRTerm. */ diff --git a/src/libdepixelize/!PLEASE DON'T MAKE CHANGES IN THESE FILES.README b/src/libdepixelize/!PLEASE DON'T MAKE CHANGES IN THESE FILES.README new file mode 100644 index 000000000..df63435d6 --- /dev/null +++ b/src/libdepixelize/!PLEASE DON'T MAKE CHANGES IN THESE FILES.README @@ -0,0 +1,9 @@ +All code files in this directory are *direct* copies of the files in +libdepixelize's BZR repo. +If you want to change the code, please change it in libdepixelize, then copy the +files here. +Otherwise, I will probably miss that you changed something in Inkscape's copy, +and destroy your changes by copying libdepixelize's files over it during the +next time I update Inkscape's copy of libdepixelize. + +libdepixelize's BZR repo = lp:libdepixelize diff --git a/src/libdepixelize/kopftracer2011.cpp b/src/libdepixelize/kopftracer2011.cpp index 5e6e26048..ab31d05c3 100644 --- a/src/libdepixelize/kopftracer2011.cpp +++ b/src/libdepixelize/kopftracer2011.cpp @@ -86,7 +86,7 @@ Splines Kopf2011::to_voronoi(const std::string &filename, Splines Kopf2011::to_voronoi(const Glib::RefPtr<Gdk::Pixbuf const> &buf, const Options &options) { - return Splines(_voronoi<Precision>(buf, options)); + return Splines(_voronoi<Precision, false>(buf, options)); } Splines Kopf2011::to_splines(const std::string &filename, @@ -98,13 +98,15 @@ Splines Kopf2011::to_splines(const std::string &filename, Splines Kopf2011::to_splines(const Glib::RefPtr<Gdk::Pixbuf const> &buf, const Options &options) { - HomogeneousSplines<Precision> splines(_voronoi<Precision>(buf, options)); + HomogeneousSplines<Precision> splines(_voronoi<Precision, true> + (buf, options)); return Splines(splines, options.optimize, options.nthreads); } -template<class T> -SimplifiedVoronoi<T> Kopf2011::_voronoi(const Glib::RefPtr<Gdk::Pixbuf const> &buf, - const Options &options) +template<class T, bool adjust_splines> +SimplifiedVoronoi<T, adjust_splines> +Kopf2011::_voronoi(const Glib::RefPtr<Gdk::Pixbuf const> &buf, + const Options &options) { PixelGraph graph(buf); @@ -146,13 +148,7 @@ SimplifiedVoronoi<T> Kopf2011::_voronoi(const Glib::RefPtr<Gdk::Pixbuf const> &b graph.checkConsistency(); #endif - _remove_puzzle_pattern(graph); - -#ifndef NDEBUG - graph.checkConsistency(); -#endif - - return SimplifiedVoronoi<T>(graph); + return SimplifiedVoronoi<T, adjust_splines>(graph); } // TODO: move this function (plus connectAllNeighbors) to PixelGraph constructor @@ -315,40 +311,6 @@ void Kopf2011::_remove_crossing_edges_unsafe(PixelGraph &graph, } } -inline -void Kopf2011::_remove_puzzle_pattern(PixelGraph &graph) -{ - if ( graph.width() < 2 || graph.height() < 2 ) - return; - - PixelGraph::iterator it = graph.begin(); - for ( int i = 0 ; i + 1 != graph.height() ; ++i ) { - PixelGraph::iterator it2 = it; - for ( int j = 0 ; j + 1 != graph.width() ; ++j ) { - // Evil pattern currently not handled correctly in SimplifiedVoronoi - if ( it2->adj.right + it2->adj.bottom - + graph.nodeBottomRight(it2)->adj.left - + graph.nodeBottomRight(it2)->adj.top == 3 ) { - // We fake a new connection =) - it2->adj.right = true; - graph.nodeRight(it2)->adj.left = true; - - it2->adj.bottom = true; - graph.nodeBottom(it2)->adj.top = true; - - graph.nodeBottomRight(it2)->adj.left = true; - graph.nodeBottom(it2)->adj.right = true; - - graph.nodeBottomRight(it2)->adj.top = true; - graph.nodeRight(it2)->adj.bottom = true; - } - - it2 = graph.nodeRight(it2); - } - it = graph.nodeBottom(it); - } -} - inline int Heuristics::curves(const PixelGraph &graph, PixelGraph::const_iterator a, PixelGraph::const_iterator b) @@ -374,8 +336,7 @@ inline int Heuristics::curves(const PixelGraph &graph, { // There are only two values that won't be zero'ed // and one of them has the same value of prev - guintptr aux = guintptr(to_ptr(it)); - aux = (it->adj.top + guintptr aux = (it->adj.top * guintptr(to_ptr(graph.nodeTop(it)))) + (it->adj.topright * guintptr(to_ptr(graph.nodeTopRight(it)))) diff --git a/src/libdepixelize/kopftracer2011.h b/src/libdepixelize/kopftracer2011.h index aff39d3d8..c224abe9a 100644 --- a/src/libdepixelize/kopftracer2011.h +++ b/src/libdepixelize/kopftracer2011.h @@ -35,8 +35,6 @@ namespace Tracer { class PixelGraph; -template<typename T> class SimplifiedVoronoi; -template<typename T> class HomogeneousSplines; class Kopf2011 { @@ -102,15 +100,15 @@ public: private: typedef Geom::Coord Precision; - template<class T> - static SimplifiedVoronoi<T> _voronoi(const Glib::RefPtr<Gdk::Pixbuf const> &buf, - const Options &options); + template<class T, bool adjust_splines> + static SimplifiedVoronoi<T, adjust_splines> + _voronoi(const Glib::RefPtr<Gdk::Pixbuf const> &buf, + const Options &options); static void _disconnect_neighbors_with_dissimilar_colors(PixelGraph &graph); static void _remove_crossing_edges_safe(PixelGraph &graph); static void _remove_crossing_edges_unsafe(PixelGraph &graph, const Options &options); - static void _remove_puzzle_pattern(PixelGraph &graph); }; } // namespace Tracer diff --git a/src/libdepixelize/priv/simplifiedvoronoi.h b/src/libdepixelize/priv/simplifiedvoronoi.h index d5ebc36e5..8a25bc626 100644 --- a/src/libdepixelize/priv/simplifiedvoronoi.h +++ b/src/libdepixelize/priv/simplifiedvoronoi.h @@ -32,7 +32,7 @@ namespace Tracer { -template<typename T> +template<typename T, bool adjust_splines> class SimplifiedVoronoi { public: @@ -121,8 +121,10 @@ public: } private: +#ifdef LIBDEPIXELIZE_VERY_TYPE_SAFE typedef void (*PointTransform)(Point<T> &p, T dx, T dy); typedef bool (*NodeTransform)(PixelGraph::const_iterator); +#endif // LIBDEPIXELIZE_VERY_TYPE_SAFE /** * Output is translated by -.5 in each axis. This function fixes this error. @@ -221,6 +223,9 @@ private: * indirection, except for the problem of too many layers of indirection." * -- David J. Wheeler */ +#ifndef LIBDEPIXELIZE_VERY_TYPE_SAFE + template<class PointTransform, class NodeTransform> +#endif // LIBDEPIXELIZE_VERY_TYPE_SAFE void _genericComplexBottomRight(PixelGraph::const_iterator a_it, PixelGraph::const_iterator b_it, PixelGraph::const_iterator c_it, @@ -241,8 +246,9 @@ private: std::vector<Cell> _cells; }; -template<class T> -SimplifiedVoronoi<T>::SimplifiedVoronoi(const PixelGraph &graph) : +template<class T, bool adjust_splines> +SimplifiedVoronoi<T, adjust_splines> +::SimplifiedVoronoi(const PixelGraph &graph) : _width(graph.width()), _height(graph.height()), _cells(graph.size()) @@ -481,10 +487,11 @@ SimplifiedVoronoi<T>::SimplifiedVoronoi(const PixelGraph &graph) : } } -template<class T> void -SimplifiedVoronoi<T>::_complexTopLeft(const PixelGraph &graph, - PixelGraph::const_iterator graph_it, - Cell *const cells_it, int x, int y) +template<class T, bool adjust_splines> void +SimplifiedVoronoi<T, adjust_splines> +::_complexTopLeft(const PixelGraph &graph, + PixelGraph::const_iterator graph_it, Cell *const cells_it, + int x, int y) { _genericComplexBottomRight(graph_it, graph.nodeLeft(graph_it), @@ -502,10 +509,11 @@ SimplifiedVoronoi<T>::_complexTopLeft(const PixelGraph &graph, &SimplifiedVoronoi::_complexTopLeftTransformTopLeft); } -template<class T> void -SimplifiedVoronoi<T>::_complexTopRight(const PixelGraph &graph, - PixelGraph::const_iterator graph_it, - Cell *const cells_it, int x, int y) +template<class T, bool adjust_splines> void +SimplifiedVoronoi<T, adjust_splines> +::_complexTopRight(const PixelGraph &graph, + PixelGraph::const_iterator graph_it, Cell *const cells_it, + int x, int y) { _genericComplexBottomRight(graph_it, graph.nodeTop(graph_it), @@ -523,10 +531,11 @@ SimplifiedVoronoi<T>::_complexTopRight(const PixelGraph &graph, &SimplifiedVoronoi::_complexTopRightTransformTopLeft); } -template<class T> void -SimplifiedVoronoi<T>::_complexBottomRight(const PixelGraph &graph, - PixelGraph::const_iterator graph_it, - Cell *const cells_it, int x, int y) +template<class T, bool adjust_splines> void +SimplifiedVoronoi<T, adjust_splines> +::_complexBottomRight(const PixelGraph &graph, + PixelGraph::const_iterator graph_it, Cell *const cells_it, + int x, int y) { _genericComplexBottomRight(graph_it, graph.nodeRight(graph_it), @@ -544,10 +553,11 @@ SimplifiedVoronoi<T>::_complexBottomRight(const PixelGraph &graph, &SimplifiedVoronoi::_complexBottomRightTransformTopLeft); } -template<class T> void -SimplifiedVoronoi<T>::_complexBottomLeft(const PixelGraph &graph, - PixelGraph::const_iterator graph_it, - Cell *const cells_it, int x, int y) +template<class T, bool adjust_splines> void +SimplifiedVoronoi<T, adjust_splines> +::_complexBottomLeft(const PixelGraph &graph, + PixelGraph::const_iterator graph_it, Cell *const cells_it, + int x, int y) { _genericComplexBottomRight(graph_it, graph.nodeBottom(graph_it), @@ -565,229 +575,268 @@ SimplifiedVoronoi<T>::_complexBottomLeft(const PixelGraph &graph, &SimplifiedVoronoi::_complexBottomLeftTransformTopLeft); } -template<class T> void -SimplifiedVoronoi<T>::_complexTopLeftTransform(Point<T> &p, T dx, T dy) +template<class T, bool adjust_splines> void +SimplifiedVoronoi<T, adjust_splines> +::_complexTopLeftTransform(Point<T> &p, T dx, T dy) { p.x -= dx; p.y -= dy; } -template<class T> void -SimplifiedVoronoi<T>::_complexTopRightTransform(Point<T> &p, T dx, T dy) +template<class T, bool adjust_splines> void +SimplifiedVoronoi<T, adjust_splines> +::_complexTopRightTransform(Point<T> &p, T dx, T dy) { p.x += dy; p.y -= dx; } -template<class T> void -SimplifiedVoronoi<T>::_complexBottomRightTransform(Point<T> &p, T dx, T dy) +template<class T, bool adjust_splines> void +SimplifiedVoronoi<T, adjust_splines> +::_complexBottomRightTransform(Point<T> &p, T dx, T dy) { p.x += dx; p.y += dy; } -template<class T> void -SimplifiedVoronoi<T>::_complexBottomLeftTransform(Point<T> &p, T dx, T dy) +template<class T, bool adjust_splines> void +SimplifiedVoronoi<T, adjust_splines> +::_complexBottomLeftTransform(Point<T> &p, T dx, T dy) { p.x -= dy; p.y += dx; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopLeftTransformTop(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopLeftTransformTop(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottom; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopLeftTransformTopRight(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopLeftTransformTopRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomleft; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopLeftTransformRight(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopLeftTransformRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.left; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopLeftTransformBottomRight(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopLeftTransformBottomRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.topleft; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopLeftTransformBottom(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopLeftTransformBottom(PixelGraph::const_iterator graph_it) { return graph_it->adj.top; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopLeftTransformBottomLeft(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopLeftTransformBottomLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.topright; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopLeftTransformLeft(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopLeftTransformLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.right; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopLeftTransformTopLeft(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopLeftTransformTopLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomright; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopRightTransformTop(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopRightTransformTop(PixelGraph::const_iterator graph_it) { return graph_it->adj.left; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopRightTransformTopRight(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopRightTransformTopRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.topleft; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopRightTransformRight(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopRightTransformRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.top; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopRightTransformBottomRight(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopRightTransformBottomRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.topright; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopRightTransformBottom(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopRightTransformBottom(PixelGraph::const_iterator graph_it) { return graph_it->adj.right; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopRightTransformBottomLeft(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopRightTransformBottomLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomright; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopRightTransformLeft(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopRightTransformLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottom; } -template<class T> -bool SimplifiedVoronoi<T>::_complexTopRightTransformTopLeft(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexTopRightTransformTopLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomleft; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomRightTransformTop(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomRightTransformTop(PixelGraph::const_iterator graph_it) { return graph_it->adj.top; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomRightTransformTopRight(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomRightTransformTopRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.topright; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomRightTransformRight(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomRightTransformRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.right; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomRightTransformBottomRight(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomRightTransformBottomRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomright; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomRightTransformBottom(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomRightTransformBottom(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottom; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomRightTransformBottomLeft(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomRightTransformBottomLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomleft; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomRightTransformLeft(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomRightTransformLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.left; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomRightTransformTopLeft(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomRightTransformTopLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.topleft; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomLeftTransformTop(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomLeftTransformTop(PixelGraph::const_iterator graph_it) { return graph_it->adj.right; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomLeftTransformTopRight(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomLeftTransformTopRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomright; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomLeftTransformRight(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomLeftTransformRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottom; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomLeftTransformBottomRight(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomLeftTransformBottomRight(PixelGraph::const_iterator graph_it) { return graph_it->adj.bottomleft; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomLeftTransformBottom(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomLeftTransformBottom(PixelGraph::const_iterator graph_it) { return graph_it->adj.left; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomLeftTransformBottomLeft(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomLeftTransformBottomLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.topleft; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomLeftTransformLeft(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomLeftTransformLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.top; } -template<class T> -bool SimplifiedVoronoi<T>::_complexBottomLeftTransformTopLeft(PixelGraph::const_iterator graph_it) +template<class T, bool adjust_splines> +bool SimplifiedVoronoi<T, adjust_splines> +::_complexBottomLeftTransformTopLeft(PixelGraph::const_iterator graph_it) { return graph_it->adj.topright; } -template<class T> +template<class T, bool adjust_splines> +#ifndef LIBDEPIXELIZE_VERY_TYPE_SAFE +template<class PointTransform, class NodeTransform> +#endif // LIBDEPIXELIZE_VERY_TYPE_SAFE void -SimplifiedVoronoi<T> +SimplifiedVoronoi<T, adjust_splines> ::_genericComplexBottomRight(PixelGraph::const_iterator a_it, PixelGraph::const_iterator b_it, PixelGraph::const_iterator c_it, @@ -817,8 +866,12 @@ SimplifiedVoronoi<T> // this and bottom-right are connected bool smooth[2] = { - same_color(a_it->rgba, d_it->rgba) || right(a_it), - same_color(a_it->rgba, d_it->rgba) || bottom(a_it) + ( same_color(a_it->rgba, d_it->rgba) + || same_color(a_it->rgba, b_it->rgba) + || same_color(b_it->rgba, d_it->rgba) ), + ( same_color(a_it->rgba, d_it->rgba) + || same_color(a_it->rgba, c_it->rgba) + || same_color(c_it->rgba, d_it->rgba) ) }; Point<T> borderMid = initial; @@ -836,7 +889,7 @@ SimplifiedVoronoi<T> vertices[1] = _adjust(midpoint(borderMid, vertices[1]), smooth[1]); } - if ( !smooth[0] ) { + if ( !smooth[0] && adjust_splines ) { cells_it->vertices.push_back(vertices[0].invisible()); { Point<T> another = vertices[0]; @@ -885,7 +938,7 @@ SimplifiedVoronoi<T> cells_it->vertices.push_back(vertices[0]); - if ( !smooth[1] ) { + if ( !smooth[1] && adjust_splines ) { { Point<T> another = vertices[1]; transform(another, @@ -954,7 +1007,7 @@ SimplifiedVoronoi<T> vertex = _adjust(midpoint(initial, vertex)); // compute smoothness - if ( right(a_it) ) { + if ( right(a_it) && adjust_splines ) { // this and right are connected if ( !right(c_it) && !( bottom(a_it) && bottom(b_it) ) ) { @@ -1006,11 +1059,65 @@ SimplifiedVoronoi<T> * 0.03125 ); transform(vertex, amount, amount); } + } else if ( !same_color(a_it->rgba, b_it->rgba) ) { + vertex.smooth = false; + // This is the same code of the if ( special ) + // I REALLY NEED lambdas to improve this code without + // creating yet another interface that takes a million + // of function parameters and keep code locality + { + Point<T> another = vertex; + T amount = 0.03125; + transform(another, + amount + * ( topleft(c_it) - topright(d_it) + + bottomleft(a_it) - bottomright(b_it) ), + // y + - amount + * ( topleft(c_it) + topright(d_it) + - bottomleft(a_it) - bottomright(b_it) )); + cells_it->vertices.push_back(another.invisible()); + } + { + Point<T> another = vertex; + T amount = 0.0625; + transform(another, + 0.25 - amount + * ( topright(d_it) + bottomright(b_it) ), + // y + - amount + * ( topright(d_it) - bottomright(b_it) )); + cells_it->vertices.push_back(another.invisible()); + } + { + Point<T> another = vertex; + T amount = 0.0625; + transform(another, + - ( 0.25 - amount + * ( topleft(c_it) + bottomleft(a_it) ) ), + // y + - amount + * ( topleft(c_it) - bottomleft(a_it) )); + another.smooth = true; + cells_it->vertices.push_back(another); + } + { + Point<T> another = vertex; + T amount = 0.1875; + transform(another, + - ( 0.75 - amount + * ( topleft(c_it) + bottomleft(a_it) ) ), + // y + - amount + * ( topleft(c_it) - bottomleft(a_it) )); + cells_it->vertices.push_back(another.invisible()); + } + vertex.visible = false; } } else { // {this, right} is the pair with the angle // closest to 180 degrees - vertex.smooth = true; + vertex.smooth = same_color(a_it->rgba, b_it->rgba); } } else { // there might be 2-color, then vertex.smooth = true @@ -1018,17 +1125,12 @@ SimplifiedVoronoi<T> // or it might be 1-color and doesn't matter, // because the current node will disappear vertex.smooth - = !( bottom(a_it) ^ bottom(b_it) ); - - if ( vertex.smooth ) { - vertex.smooth - = same_color(a_it->rgba, b_it->rgba) - + same_color(a_it->rgba, c_it->rgba) - + same_color(d_it->rgba, b_it->rgba) - + same_color(d_it->rgba, c_it->rgba) == 2; - } + = same_color(a_it->rgba, b_it->rgba) + + same_color(a_it->rgba, c_it->rgba) + + same_color(d_it->rgba, b_it->rgba) + + same_color(d_it->rgba, c_it->rgba) == 2; } - } else if ( bottom(a_it) ) { + } else if ( bottom(a_it) && adjust_splines ) { // this and bottom are connected if ( !bottom(b_it) && !( right(a_it) && right(c_it) ) ) { @@ -1079,28 +1181,75 @@ SimplifiedVoronoi<T> * 0.03125 ); transform(vertex, amount, amount); } + } else if ( !same_color(a_it->rgba, c_it->rgba) ) { + vertex.smooth = false; + // This is the same code of the if ( special ) + // I REALLY NEED lambdas to improve this code without + // creating yet another interface that takes a million + // of function parameters and keep code locality + cells_it->vertices.push_back(vertex.invisible()); + { + Point<T> another = vertex; + T amount = 0.1875; + transform(another, + - ( topleft(b_it) - topright(a_it) ) * amount, + // y + - ( 0.75 + - ( topleft(b_it) + topright(a_it) ) + * amount )); + cells_it->vertices.push_back(another.invisible()); + } + { + Point<T> another = vertex; + T amount = 0.0625; + transform(another, + - ( topleft(b_it) - topright(a_it) ) * amount, + // y + - ( 0.25 + - ( topleft(b_it) + topright(a_it) ) + * amount )); + another.smooth = true; + cells_it->vertices.push_back(another); + } + { + Point<T> another = vertex; + T amount = 0.0625; + transform(another, - amount + * ( bottomleft(d_it) - bottomright(c_it) ), + // y + 0.25 - amount + * ( bottomleft(d_it) + bottomright(c_it) )); + cells_it->vertices.push_back(another.invisible()); + } + { + transform(vertex, + - ( topleft(b_it) + bottomleft(d_it) + - topright(a_it) - bottomright(c_it) ) + * 0.03125, + // y + ( topleft(b_it) - bottomleft(d_it) + + topright(a_it) - bottomright(c_it) ) + * 0.03125); + vertex.visible = false; + } } } else { // {this, bottom} is the pair with the angle // closest to 180 degrees - vertex.smooth = true; + vertex.smooth = same_color(a_it->rgba, c_it->rgba); } } else { // there might be 2-color, then vertex.smooth = true // or it might be 1-color and doesn't matter, // because the current node will disappear - vertex.smooth = !( right(a_it) ^ right(c_it) ); - - if ( vertex.smooth ) { - vertex.smooth - = same_color(a_it->rgba, c_it->rgba) - + same_color(a_it->rgba, b_it->rgba) - + same_color(d_it->rgba, b_it->rgba) - + same_color(d_it->rgba, c_it->rgba) == 2; - } + vertex.smooth + = same_color(a_it->rgba, c_it->rgba) + + same_color(a_it->rgba, b_it->rgba) + + same_color(d_it->rgba, b_it->rgba) + + same_color(d_it->rgba, c_it->rgba) == 2; } - } else if ( bottom(b_it) ) { + } else if ( bottom(b_it) && adjust_splines ) { // right and bottom-right are connected bool special = false; @@ -1205,7 +1354,7 @@ SimplifiedVoronoi<T> vertex.visible = false; } } - } else if ( right(c_it) ) { + } else if ( right(c_it) && adjust_splines ) { // bottom and bottom-right are connected bool special = false; diff --git a/src/libdepixelize/priv/splines-kopf2011.h b/src/libdepixelize/priv/splines-kopf2011.h index eb84c3bfb..fb4f8ba1e 100644 --- a/src/libdepixelize/priv/splines-kopf2011.h +++ b/src/libdepixelize/priv/splines-kopf2011.h @@ -107,22 +107,22 @@ void worker(const typename HomogeneousSplines<T>::Polygon &source, } } -template<typename T> -Splines::Splines(const SimplifiedVoronoi<T> &diagram) : +template<typename T, bool adjust_splines> +Splines::Splines(const SimplifiedVoronoi<T, adjust_splines> &diagram) : _width(diagram.width()), _height(diagram.height()) { _paths.reserve(diagram.size()); - for ( typename SimplifiedVoronoi<T>::const_iterator it = diagram.begin() - , end = diagram.end() ; it != end ; ++it ) { + for ( typename SimplifiedVoronoi<T, adjust_splines>::const_iterator + it = diagram.begin() , end = diagram.end() ; it != end ; ++it ) { Path path; path.pathVector .push_back(Geom::Path(to_geom_point(it->vertices.front()))); for ( typename std::vector< Point<T> >::const_iterator - it2 = it->vertices.begin(), end2 = it->vertices.end() + it2 = ++it->vertices.begin(), end2 = it->vertices.end() ; it2 != end2 ; ++it2 ) { path.pathVector.back() .appendNew<Geom::LineSegment>(Geom::Point(it2->x, it2->y)); diff --git a/src/libdepixelize/splines.h b/src/libdepixelize/splines.h index c4b455aae..b06ba8ba9 100644 --- a/src/libdepixelize/splines.h +++ b/src/libdepixelize/splines.h @@ -30,7 +30,7 @@ namespace Tracer { -template<typename T> +template<typename T, bool adjust_splines = true> class SimplifiedVoronoi; template<typename T> @@ -54,8 +54,8 @@ public: Splines() /* = default */ {} - template<typename T> - Splines(const SimplifiedVoronoi<T> &simplifiedVoronoi); + template<typename T, bool adjust_splines> + Splines(const SimplifiedVoronoi<T, adjust_splines> &simplifiedVoronoi); /** * There are two levels of optimization. The first level only removes diff --git a/src/libnrtype/Layout-TNG-Output.cpp b/src/libnrtype/Layout-TNG-Output.cpp index bdc786749..149f600b7 100644 --- a/src/libnrtype/Layout-TNG-Output.cpp +++ b/src/libnrtype/Layout-TNG-Output.cpp @@ -221,13 +221,9 @@ void Layout::print(SPPrintContext *ctx, Geom::Affine const &ctm) const { bool text_to_path = ctx->module->textToPath(); -int oldtarget = 0; -int newtarget = 0; #define MAX_DX 2048 float hold_dx[MAX_DX]; // For smuggling dx values (character widths) into print functions, unlikely any simple text output will be longer than this. -float ky; // For smuggling y kern value for span -int ndx = 0; -double rtl = 1.0; // 1 L->R, -1 R->L, constant across a span. 1.0 for t->b b->t??? + Geom::Affine glyph_matrix; if (_input_stream.empty()) return; @@ -253,7 +249,10 @@ Geom::Affine glyph_matrix; double char_x; int doUTN = CanUTN(); // Unicode to Nonunicode translation enabled if true Direction block_progression = _blockProgression(); - + int oldtarget = 0; + int ndx = 0; + double rtl = 1.0; // 1 L->R, -1 R->L, constant across a span. 1.0 for t->b b->t??? + for (unsigned char_index = 0 ; char_index < _characters.size() ; ) { Glib::ustring text_string; // accumulate text for record in this Geom::Point g_pos(0,0); // all strings are output at (0,0) because we do the translation using the matrix @@ -262,7 +261,7 @@ Geom::Affine glyph_matrix; char_index++; continue; } - ky = _glyphs[glyph_index].y; // same value for all positions in a span + float ky = _glyphs[glyph_index].y; // For smuggling y kern value for span // same value for all positions in a span unsigned span_index = _characters[char_index].in_span; Span const &span = _spans[span_index]; char_x = 0.0; @@ -283,12 +282,15 @@ Geom::Affine glyph_matrix; case Layout::LEFT_TO_RIGHT: rtl = 1.0; break; case Layout::RIGHT_TO_LEFT: rtl = -1.0; break; } - if(doUTN)oldtarget=SingleUnicodeToNon(*text_iter); // this should only ever be with a 1:1 glyph:character situation + if(doUTN){ + oldtarget=SingleUnicodeToNon(*text_iter); // this should only ever be with a 1:1 glyph:character situation + } // accumulate a record to write unsigned lc_index = char_index; unsigned hold_iisi = _spans[span_index].in_input_stream_item; + int newtarget = 0; while(1){ glyph_index = _characters[lc_index].in_glyph; if(glyph_index == -1){ // end of a line within a paragraph, for instance @@ -377,7 +379,7 @@ std:: cout << "DEBUG Layout::print in while --- " sp_print_text(ctx, smuggle_string, g_pos, text_source->style); free(smuggle_string); sp_print_release(ctx); - ndx=0; + ndx = 0; char_index = lc_index; } } @@ -546,28 +548,29 @@ Glib::ustring Layout::dumpAsText() const result += line; snprintf(line, sizeof(line), "glyphs %zu\n", _glyphs.size()); result += line; - unsigned lastspan=5000; + if(_characters.size() > 1){ + unsigned lastspan=5000; for(unsigned j = 0; j < _characters.size() ; j++){ if(lastspan != _characters[j].in_span){ lastspan = _characters[j].in_span; icc = _spans[lastspan].input_stream_first_character; } - snprintf(line, sizeof(line), "char %4d: '%c' 0x%4.4x x=%8.4f glyph=%3d span=%3d\n", j, *icc, *icc, _characters[j].x, _characters[j].in_glyph, _characters[j].in_span); + snprintf(line, sizeof(line), "char %4u: '%c' 0x%4.4x x=%8.4f glyph=%3d span=%3d\n", j, *icc, *icc, _characters[j].x, _characters[j].in_glyph, _characters[j].in_span); result += line; ++icc; } } if(_glyphs.size()){ for(unsigned j = 0; j < _glyphs.size() ; j++){ - snprintf(line, sizeof(line), "glyph %4d: %4d (%8.4f,%8.4f) rot=%8.4f cx=%8.4f char=%4d\n", + snprintf(line, sizeof(line), "glyph %4u: %4d (%8.4f,%8.4f) rot=%8.4f cx=%8.4f char=%4d\n", j, _glyphs[j].glyph, _glyphs[j].x, _glyphs[j].y, _glyphs[j].rotation, _glyphs[j].width, _glyphs[j].in_character); result += line; } } for (unsigned span_index = 0 ; span_index < _spans.size() ; span_index++) { - snprintf(line, sizeof(line), "==== span %d \n", span_index); + snprintf(line, sizeof(line), "==== span %u \n", span_index); result += line; snprintf(line, sizeof(line), " in para %d (direction=%s)\n", _lines[_chunks[_spans[span_index].in_chunk].in_line].in_paragraph, direction_to_text(_paragraphs[_lines[_chunks[_spans[span_index].in_chunk].in_line].in_paragraph].base_direction)); @@ -600,9 +603,9 @@ Glib::ustring Layout::dumpAsText() const u.pattr = &_characters[char_index].char_attributes; if (_characters[char_index].in_span != span_index) continue; if (_input_stream[_spans[span_index].in_input_stream_item]->Type() != TEXT_SOURCE) { - snprintf(line, sizeof(line), " %d: control x=%f flags=%03x glyph=%d\n", char_index, _characters[char_index].x, *u.uattr, _characters[char_index].in_glyph); + snprintf(line, sizeof(line), " %u: control x=%f flags=%03x glyph=%d\n", char_index, _characters[char_index].x, *u.uattr, _characters[char_index].in_glyph); } else { // some text has empty tspans, iter_char cannot be dereferenced - snprintf(line, sizeof(line), " %d: '%c' 0x%4.4x x=%f flags=%03x glyph=%d\n", char_index, *iter_char, *iter_char, _characters[char_index].x, *u.uattr, _characters[char_index].in_glyph); + snprintf(line, sizeof(line), " %u: '%c' 0x%4.4x x=%f flags=%03x glyph=%d\n", char_index, *iter_char, *iter_char, _characters[char_index].x, *u.uattr, _characters[char_index].in_glyph); ++iter_char; } result += line; @@ -610,7 +613,7 @@ Glib::ustring Layout::dumpAsText() const result += " ** glyphs:\n"; for (unsigned glyph_index = 0 ; glyph_index < _glyphs.size() ; glyph_index++) { if (_characters[_glyphs[glyph_index].in_character].in_span != span_index) continue; - snprintf(line, sizeof(line), " %d: %d (%f,%f) rot=%f cx=%f char=%d\n", glyph_index, _glyphs[glyph_index].glyph, _glyphs[glyph_index].x, _glyphs[glyph_index].y, _glyphs[glyph_index].rotation, _glyphs[glyph_index].width, _glyphs[glyph_index].in_character); + snprintf(line, sizeof(line), " %u: %d (%f,%f) rot=%f cx=%f char=%d\n", glyph_index, _glyphs[glyph_index].glyph, _glyphs[glyph_index].x, _glyphs[glyph_index].y, _glyphs[glyph_index].rotation, _glyphs[glyph_index].width, _glyphs[glyph_index].in_character); result += line; } result += "\n"; diff --git a/src/libnrtype/Layout-TNG.cpp b/src/libnrtype/Layout-TNG.cpp index bda0d1697..dd9c90949 100644 --- a/src/libnrtype/Layout-TNG.cpp +++ b/src/libnrtype/Layout-TNG.cpp @@ -16,9 +16,10 @@ namespace Text { const gunichar Layout::UNICODE_SOFT_HYPHEN = 0x00AD; const double Layout::LINE_HEIGHT_NORMAL = 1.25; -Layout::Layout() +Layout::Layout() : + _input_truncated(0), + _path_fitted(NULL) { - _path_fitted = NULL; } Layout::~Layout() diff --git a/src/libnrtype/Layout-TNG.h b/src/libnrtype/Layout-TNG.h index 573301c69..d16c2843d 100644 --- a/src/libnrtype/Layout-TNG.h +++ b/src/libnrtype/Layout-TNG.h @@ -817,7 +817,12 @@ class Layout::iterator { public: friend class Layout; // this is just so you can create uninitialised iterators - don't actually try to use one - iterator() : _parent_layout(NULL) {} + iterator() : + _parent_layout(NULL), + _glyph_index(-1), + _char_index(0), + _cursor_moving_vertically(false), + _x_coordinate(0.0){} // no copy constructor required, the default does what we want bool operator== (iterator const &other) const {return _glyph_index == other._glyph_index && _char_index == other._char_index;} diff --git a/src/live_effects/lpe-rough-hatches.cpp b/src/live_effects/lpe-rough-hatches.cpp index 0579b1016..6ffb913bd 100644 --- a/src/live_effects/lpe-rough-hatches.cpp +++ b/src/live_effects/lpe-rough-hatches.cpp @@ -239,10 +239,10 @@ LPERoughHatches::LPERoughHatches(LivePathEffectObject *lpeobject) : fat_output(_("Generate thick/thin path"), _("Simulate a stroke of varying width"), "fat_output", &wr, this, true), do_bend(_("Bend hatches"), _("Add a global bend to the hatches (slower)"), "do_bend", &wr, this, true), stroke_width_top(_("Thickness: at 1st side:"), _("Width at 'bottom' half-turns"), "stroke_width_top", &wr, this, 1.), - stroke_width_bot(_("at 2nd side:"), _("Width at 'top' half-turns"), "stroke_width_bottom", &wr, this, 1.), + stroke_width_bot(_("At 2nd side:"), _("Width at 'top' half-turns"), "stroke_width_bottom", &wr, this, 1.), // - front_thickness(_("from 2nd to 1st side:"), _("Width from 'top' to 'bottom'"), "front_thickness", &wr, this, 1.), - back_thickness(_("from 1st to 2nd side:"), _("Width from 'bottom' to 'top'"), "back_thickness", &wr, this, .25), + front_thickness(_("From 2nd to 1st side:"), _("Width from 'top' to 'bottom'"), "front_thickness", &wr, this, 1.), + back_thickness(_("From 1st to 2nd side:"), _("Width from 'bottom' to 'top'"), "back_thickness", &wr, this, .25), direction(_("Hatches width and dir"), _("Defines hatches frequency and direction"), "direction", &wr, this, Geom::Point(50,0)), // diff --git a/src/live_effects/parameter/unit.cpp b/src/live_effects/parameter/unit.cpp index 561766920..0ee553e2c 100644 --- a/src/live_effects/parameter/unit.cpp +++ b/src/live_effects/parameter/unit.cpp @@ -24,7 +24,7 @@ UnitParam::UnitParam( const Glib::ustring& label, const Glib::ustring& tip, Effect* effect, Glib::ustring default_unit) : Parameter(label, tip, key, wr, effect) { - defunit = new Inkscape::Util::Unit(unit_table.getUnit(default_unit)); + defunit = unit_table.getUnit(default_unit); unit = defunit; } @@ -36,7 +36,7 @@ bool UnitParam::param_readSVGValue(const gchar * strvalue) { if (strvalue) { - param_set_value(unit_table.getUnit(strvalue)); + param_set_value(*unit_table.getUnit(strvalue)); return true; } return false; diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp index edc9a6930..bf912746e 100644 --- a/src/lpe-tool-context.cpp +++ b/src/lpe-tool-context.cpp @@ -191,8 +191,7 @@ bool SPLPEToolContext::root_handler(GdkEvent* event) { if (sp_pen_context_has_waiting_LPE(this)) { // quit when we are waiting for a LPE to be applied //ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler(event_context, event); - ret = this->root_handler(event); - return ret; + return SPPenContext::root_handler(event); } switch (event->type) { @@ -224,7 +223,7 @@ bool SPLPEToolContext::root_handler(GdkEvent* event) { // we pass the mouse click on to pen tool as the first click which it should collect //ret = ((SPEventContextClass *) sp_lpetool_context_parent_class)->root_handler(event_context, event); - ret = this->root_handler(event); + ret = SPPenContext::root_handler(event); } break; @@ -416,7 +415,7 @@ lpetool_create_measuring_items(SPLPEToolContext *lc, Inkscape::Selection *select if (!show) sp_canvas_item_hide(SP_CANVAS_ITEM(canvas_text)); - Inkscape::Util::Unit unit; + Inkscape::Util::Unit const * unit = NULL; if (prefs->getString("/tools/lpetool/unit").compare("")) { unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit")); } else { @@ -425,7 +424,7 @@ lpetool_create_measuring_items(SPLPEToolContext *lc, Inkscape::Selection *select lengthval = Geom::length(pwd2); lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit); - arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str()); + 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? @@ -455,7 +454,7 @@ lpetool_update_measuring_items(SPLPEToolContext *lc) SPPath *path = i->first; SPCurve *curve = path->getCurve(); Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = Geom::paths_to_pw(curve->get_pathvector()); - Inkscape::Util::Unit unit; + Inkscape::Util::Unit const * unit = NULL; if (prefs->getString("/tools/lpetool/unit").compare("")) { unit = unit_table.getUnit(prefs->getString("/tools/lpetool/unit")); } else { @@ -463,7 +462,7 @@ lpetool_update_measuring_items(SPLPEToolContext *lc) } double lengthval = Geom::length(pwd2); lengthval = Inkscape::Util::Quantity::convert(lengthval, "px", unit); - gchar *arc_length = g_strdup_printf("%.2f %s", lengthval, unit.abbr.c_str()); + gchar *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/marker.cpp b/src/marker.cpp index 45188b4a4..50e7c970f 100644 --- a/src/marker.cpp +++ b/src/marker.cpp @@ -319,7 +319,7 @@ void SPMarker::update(SPCtx *ctx, guint flags) { // Copy parent context rctx.flags = ctx->flags; - // Initialize tranformations + // Initialize transformations rctx.i2doc = Geom::identity(); rctx.i2vp = Geom::identity(); diff --git a/src/object-edit.cpp b/src/object-edit.cpp index 2021b91f5..e9b183eca 100644 --- a/src/object-edit.cpp +++ b/src/object-edit.cpp @@ -69,7 +69,7 @@ KnotHolder *createKnotHolder(SPItem *item, SPDesktop *desktop) knotholder = new RectKnotHolder(desktop, item, NULL); } else if (SP_IS_BOX3D(item)) { knotholder = new Box3DKnotHolder(desktop, item, NULL); - } else if (SP_IS_ARC(item)) { + } else if (SP_IS_GENERICELLIPSE(item)) { knotholder = new ArcKnotHolder(desktop, item, NULL); } else if (SP_IS_STAR(item)) { knotholder = new StarKnotHolder(desktop, item, NULL); @@ -787,7 +787,7 @@ ArcKnotHolderEntityStart::knot_set(Geom::Point const &p, Geom::Point const &/*or { int snaps = Inkscape::Preferences::get()->getInt("/options/rotationsnapsperpi/value", 12); - SPArc *arc = SP_ARC(item); + SPGenericEllipse *arc = SP_GENERICELLIPSE(item); arc->setClosed(sp_genericellipse_side(arc, p) == -1); @@ -808,9 +808,8 @@ Geom::Point ArcKnotHolderEntityStart::knot_get() const { SPGenericEllipse const *ge = SP_GENERICELLIPSE(item); - SPArc *arc = SP_ARC(item); - return arc->getPointAtAngle(ge->start); + return ge->getPointAtAngle(ge->start); } void @@ -829,7 +828,7 @@ ArcKnotHolderEntityEnd::knot_set(Geom::Point const &p, Geom::Point const &/*orig { int snaps = Inkscape::Preferences::get()->getInt("/options/rotationsnapsperpi/value", 12); - SPArc *arc = SP_ARC(item); + SPGenericEllipse *arc = SP_GENERICELLIPSE(item); arc->setClosed(sp_genericellipse_side(arc, p) == -1); @@ -850,9 +849,8 @@ Geom::Point ArcKnotHolderEntityEnd::knot_get() const { SPGenericEllipse const *ge = SP_GENERICELLIPSE(item); - SPArc *arc = SP_ARC(item); - return arc->getPointAtAngle(ge->end); + return ge->getPointAtAngle(ge->end); } diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 3f3f0c1bf..de50f0dd8 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -538,7 +538,7 @@ void Inkscape::ObjectSnapper::_snapPaths(IntermSnapResults &isr, * - Linking the individual nodes of the SPPath we have here, to the nodes of the NodePath::SubPath class as being * used in sp_nodepath_selected_nodes_move. This class has a member variable called "selected". For this the nodes * should be in the exact same order for both classes, so we can index them - * - Replacing the SPPath being used here by the the NodePath::SubPath class; but how? + * - Replacing the SPPath being used here by the NodePath::SubPath class; but how? */ } diff --git a/src/pen-context.cpp b/src/pen-context.cpp index d67bc5e57..428ebd6d9 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -1137,7 +1137,7 @@ 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]; Inkscape::Util::Quantity q = Inkscape::Util::Quantity(Geom::L2(rel), "px"); - GString *dist = g_string_new(q.string(*desktop->namedview->doc_units).c_str()); + 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/pencil-context.cpp b/src/pencil-context.cpp index 94310ea31..abd9af1d3 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -80,19 +80,19 @@ const std::string& SPPencilContext::getPrefsPath() { const std::string SPPencilContext::prefsPath = "/tools/freehand/pencil"; -SPPencilContext::SPPencilContext() : SPDrawContext() { - this->is_drawing = false; - +SPPencilContext::SPPencilContext() : + SPDrawContext(), + p(), + npoints(0), + state(SP_PENCIL_CONTEXT_IDLE), + req_tangent(0,0), + is_drawing(false), + ps(), + sketch_interpolation(Geom::Piecewise<Geom::D2<Geom::SBasis> >())// since SPPencilContext is not properly constructed... +{ this->cursor_shape = cursor_pencil_xpm; this->hot_x = 4; this->hot_y = 4; - - this->npoints = 0; - this->state = SP_PENCIL_CONTEXT_IDLE; - this->req_tangent = Geom::Point(0, 0); - - // since SPPencilContext is not properly constructed... - this->sketch_interpolation = Geom::Piecewise<Geom::D2<Geom::SBasis> >(); this->sketch_n = 0; } diff --git a/src/pixmaps/cursor-node-d.xpm b/src/pixmaps/cursor-node-d.xpm index 264da58c3..7e177bff4 100644 --- a/src/pixmaps/cursor-node-d.xpm +++ b/src/pixmaps/cursor-node-d.xpm @@ -1,9 +1,9 @@ /* XPM */ static char const *cursor_node_d_xpm[] = { "32 32 3 1", -" g None", -". g #ffffff", -"+ g #000000", +" c None", +". c #FFFFFF", +"+ c #000000", " . ", ".+. ", " .+. ", diff --git a/src/preferences.cpp b/src/preferences.cpp index 0dc6f1ec4..0dcebbb90 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -785,9 +785,8 @@ double Preferences::_extractDouble(Entry const &v, Glib::ustring const &requeste if (unit.length() == 0) { // no unit specified, don't do conversion return val; - } else { - return val * (unit_table.getUnit(unit).factor / unit_table.getUnit(requested_unit).factor); } + return val * (unit_table.getUnit(unit)->factor / unit_table.getUnit(requested_unit)->factor); /// \todo rewrite using Quantity class, so the standard code handles unit conversion } Glib::ustring Preferences::_extractString(Entry const &v) diff --git a/src/rect-context.cpp b/src/rect-context.cpp index f60b3d465..a0e751359 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -426,8 +426,8 @@ void SPRectContext::drag(Geom::Point const pt, guint state) { 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()); + 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; diff --git a/src/registrytool.cpp b/src/registrytool.cpp index 01a83a7e0..51c1063ef 100644 --- a/src/registrytool.cpp +++ b/src/registrytool.cpp @@ -142,7 +142,7 @@ bool RegistryTool::setPathInfo() // fullPath.c_str(), path.c_str(), exeName.c_str()); Glib::ustring keyName = - "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\"; + "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\"; keyName.append(exeName); Glib::ustring valueName = ""; diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 49a731b15..5463c3f94 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1032,7 +1032,8 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) } DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_LOWER, - _("Lower")); + //TRANSLATORS: "Lower" means "to lower an object" in the undo history + C_("Undo action", "Lower")); } void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *desktop) @@ -1915,8 +1916,8 @@ static bool item_type_match (SPItem *i, SPItem *j) if ( SP_IS_RECT(i)) { return ( SP_IS_RECT(j) ); - } else if (SP_IS_GENERICELLIPSE(i) || SP_IS_ELLIPSE(i) || SP_IS_ARC(i) || SP_IS_CIRCLE(i)) { - return (SP_IS_GENERICELLIPSE(j) || SP_IS_ELLIPSE(j) || SP_IS_ARC(j) || SP_IS_CIRCLE(j)); + } else if (SP_IS_GENERICELLIPSE(i)) { + return (SP_IS_GENERICELLIPSE(j)); } else if (SP_IS_STAR(i) || SP_IS_POLYGON(i)) { return (SP_IS_STAR(j) || SP_IS_POLYGON(j)) ; diff --git a/src/seltrans.cpp b/src/seltrans.cpp index f614853bc..7a8f5ec17 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -1274,8 +1274,8 @@ gboolean Inkscape::SelTrans::centerRequest(Geom::Point &pt, guint state) // status text 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()); + 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 <b>center</b> to %s, %s"), xs->str, ys->str); g_string_free(xs, FALSE); g_string_free(ys, FALSE); @@ -1428,8 +1428,8 @@ void Inkscape::SelTrans::moveTo(Geom::Point const &xy, guint state) // status text 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()); + 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, _("<b>Move</b> by %s, %s; with <b>Ctrl</b> to restrict to horizontal/vertical; with <b>Shift</b> to disable snapping"), xs->str, ys->str); g_string_free(xs, TRUE); g_string_free(ys, TRUE); diff --git a/src/sp-ellipse.cpp b/src/sp-ellipse.cpp index 06201859f..8a0a8f233 100644 --- a/src/sp-ellipse.cpp +++ b/src/sp-ellipse.cpp @@ -9,6 +9,7 @@ * * Copyright (C) 1999-2002 Lauris Kaplinski * Copyright (C) 2000-2001 Ximian, Inc. + * Copyright (C) 2013 Tavmjong Bah * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -39,17 +40,23 @@ namespace { SPObject *create_ellipse() { - return new SPEllipse(); + SPGenericEllipse *ellipse = new SPGenericEllipse(); + ellipse->type = SP_GENERIC_ELLIPSE_ELLIPSE; + return (SPObject*)ellipse; } SPObject *create_circle() { - return new SPCircle(); + SPGenericEllipse *circle = new SPGenericEllipse(); + circle->type = SP_GENERIC_ELLIPSE_CIRCLE; + return (SPObject*)circle; } SPObject *create_arc() { - return new SPArc(); + SPGenericEllipse *arc = new SPGenericEllipse(); + arc->type = SP_GENERIC_ELLIPSE_ARC; + return (SPObject*)arc; } bool ellipse_registered = SPFactory::instance().registerObject("svg:ellipse", create_ellipse); @@ -68,6 +75,7 @@ SPGenericEllipse::SPGenericEllipse() : SPShape() , start(0) , end(SP_2PI) + , type(SP_GENERIC_ELLIPSE_UNDEFINED) , _closed(true) { } @@ -76,16 +84,120 @@ SPGenericEllipse::~SPGenericEllipse() { } +void SPGenericEllipse::setClosed(bool value) { + _closed = value; +} + bool SPGenericEllipse::closed() { return _closed; } -void SPGenericEllipse::setClosed(bool value) { - _closed = value; +void SPGenericEllipse::build(SPDocument *document, Inkscape::XML::Node *repr) +{ + // std::cout << "SPGenericEllipse::build: Entrance: " << this->type + // << " (" << g_quark_to_string(repr->code()) << ")" << std::endl; + + switch ( type ) { + case SP_GENERIC_ELLIPSE_ARC: + this->readAttr("sodipodi:cx"); + this->readAttr("sodipodi:cy"); + this->readAttr("sodipodi:rx"); + this->readAttr("sodipodi:ry"); + this->readAttr("sodipodi:start"); + this->readAttr("sodipodi:end"); + this->readAttr("sodipodi:open"); + break; + + case SP_GENERIC_ELLIPSE_CIRCLE: + this->readAttr("cx"); + this->readAttr("cy"); + this->readAttr("r"); + break; + + case SP_GENERIC_ELLIPSE_ELLIPSE: + this->readAttr("cx"); + this->readAttr("cy"); + this->readAttr("rx"); + this->readAttr("ry"); + break; + + default: + std::cerr << "SPGenericEllipse::build() unknown defined type." << std::endl; + } + + SPShape::build(document, repr); +} + +void SPGenericEllipse::set(unsigned int key, gchar const *value) +{ + // There are multiple ways to set internal cx, cy, rx, and ry (via SVG attributes or Sodipodi + // attributes) thus we don't want to unset them if a read fails (e.g., when we explicitly clear + // an attribute by setting it to NULL). + SVGLength t; + switch (key) { + case SP_ATTR_CX: + case SP_ATTR_SODIPODI_CX: + if( t.read(value) ) cx = t; + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + break; + + case SP_ATTR_CY: + case SP_ATTR_SODIPODI_CY: + if( t.read(value) ) cy = t; + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + break; + + case SP_ATTR_RX: + case SP_ATTR_SODIPODI_RX: + if( t.read(value) && t.value > 0.0 ) this->rx = t; + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + break; + + case SP_ATTR_RY: + case SP_ATTR_SODIPODI_RY: + if( t.read(value) && t.value > 0.0 ) this->ry = t; + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + break; + + case SP_ATTR_R: + if( t.read(value) && t.value > 0.0 ) { + this->ry = this->rx = t; + } + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + break; + + case SP_ATTR_SODIPODI_START: + if (value) { + sp_svg_number_read_d(value, &this->start); + } else { + this->start = 0; + } + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + break; + + case SP_ATTR_SODIPODI_END: + if (value) { + sp_svg_number_read_d(value, &this->end); + } else { + this->end = 2 * M_PI; + } + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + break; + + case SP_ATTR_SODIPODI_OPEN: + this->_closed = (!value); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + break; + + default: + SPShape::set(key, value); + break; + } } void SPGenericEllipse::update(SPCtx *ctx, guint flags) { + // std::cout << "\nSPGenericEllipse::update: Entrance" << std::endl; if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { Geom::Rect const &viewbox = ((SPItemCtx const *) ctx)->viewport; @@ -104,36 +216,185 @@ void SPGenericEllipse::update(SPCtx *ctx, guint flags) } SPShape::update(ctx, flags); + // std::cout << "SPGenericEllipse::update: Exit\n" << std::endl; } -void SPGenericEllipse::update_patheffect(bool write) +Inkscape::XML::Node *SPGenericEllipse::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - this->set_shape(); + // std::cout << "\nSPGenericEllipse::write: Entrance (" + // << (repr == NULL ? " NULL" : g_quark_to_string(repr->code())) + // << ")" << std::endl; - if (write) { - Inkscape::XML::Node *repr = this->getRepr(); + GenericEllipseType new_type = SP_GENERIC_ELLIPSE_UNDEFINED; + if (this->_isSlice() || hasPathEffect() ) { + new_type = SP_GENERIC_ELLIPSE_ARC; + } else if ( rx.computed == ry.computed ) { + new_type = SP_GENERIC_ELLIPSE_CIRCLE; + } else { + new_type = SP_GENERIC_ELLIPSE_ELLIPSE; + } + // std::cout << " new_type: " << new_type << std::endl; - if (this->_curve != NULL) { - gchar *str = sp_svg_write_path(this->_curve->get_pathvector()); - repr->setAttribute("d", str); - g_free(str); - } else { - repr->setAttribute("d", NULL); + if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { + + switch ( new_type ) { + + case SP_GENERIC_ELLIPSE_ARC: + repr = xml_doc->createElement("svg:path"); + break; + case SP_GENERIC_ELLIPSE_CIRCLE: + repr = xml_doc->createElement("svg:circle"); + break; + case SP_GENERIC_ELLIPSE_ELLIPSE: + repr = xml_doc->createElement("svg:ellipse"); + break; + case SP_GENERIC_ELLIPSE_UNDEFINED: + default: + std::cerr << "SPGenericEllipse::write(): unknown type." << std::endl; } } - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + if( type != new_type ) { + switch( new_type ) { + case SP_GENERIC_ELLIPSE_ARC: + repr->setCodeUnsafe(g_quark_from_string("svg:path")); + break; + case SP_GENERIC_ELLIPSE_CIRCLE: + repr->setCodeUnsafe(g_quark_from_string("svg:circle")); + break; + case SP_GENERIC_ELLIPSE_ELLIPSE: + repr->setCodeUnsafe(g_quark_from_string("svg:ellipse")); + break; + default: + std::cerr << "SPGenericEllipse::write(): unknown type." << std::endl; + } + type = new_type; + + // FIXME: The XML dialog won't update the element name. We need + // a notifyElementNameChanged callback added to the XML observers + // to trigger a refresh. + } + + // std::cout << " type: " << g_quark_to_string( repr->code() ) << std::endl; + // std::cout << " cx: " << cx.computed + // << " cy: " << cy.computed + // << " rx: " << rx.computed + // << " ry: " << ry.computed << std::endl; + + switch ( type ) { + case SP_GENERIC_ELLIPSE_UNDEFINED: + case SP_GENERIC_ELLIPSE_ARC: + + repr->setAttribute("cx", NULL ); + repr->setAttribute("cy", NULL ); + repr->setAttribute("rx", NULL ); + repr->setAttribute("ry", NULL ); + repr->setAttribute("r", NULL ); + + if (flags & SP_OBJECT_WRITE_EXT) { + + repr->setAttribute("sodipodi:type", "arc"); + sp_repr_set_svg_double(repr, "sodipodi:cx", this->cx.computed); + sp_repr_set_svg_double(repr, "sodipodi:cy", this->cy.computed); + sp_repr_set_svg_double(repr, "sodipodi:rx", this->rx.computed); + sp_repr_set_svg_double(repr, "sodipodi:ry", this->ry.computed); + + // write start and end only if they are non-trivial; otherwise remove + if (this->_isSlice()) { + sp_repr_set_svg_double(repr, "sodipodi:start", this->start); + sp_repr_set_svg_double(repr, "sodipodi:end", this->end); + + repr->setAttribute("sodipodi:open", (!this->_closed) ? "true" : NULL); + } else { + repr->setAttribute("sodipodi:end", NULL); + repr->setAttribute("sodipodi:start", NULL); + repr->setAttribute("sodipodi:open", NULL); + } + } + + // write d= + this->set_elliptical_path_attribute(repr); + break; + + case SP_GENERIC_ELLIPSE_CIRCLE: + sp_repr_set_svg_double(repr, "cx", this->cx.computed); + sp_repr_set_svg_double(repr, "cy", this->cy.computed); + sp_repr_set_svg_double(repr, "r", this->rx.computed); + repr->setAttribute("rx", NULL ); + repr->setAttribute("ry", NULL ); + repr->setAttribute("sodipodi:cx", NULL ); + repr->setAttribute("sodipodi:cy", NULL ); + repr->setAttribute("sodipodi:rx", NULL ); + repr->setAttribute("sodipodi:ry", NULL ); + repr->setAttribute("sodipodi:end", NULL ); + repr->setAttribute("sodipodi:start", NULL ); + repr->setAttribute("sodipodi:open", NULL ); + repr->setAttribute("sodipodi:type", NULL ); + repr->setAttribute("d", NULL ); + break; + + case SP_GENERIC_ELLIPSE_ELLIPSE: + sp_repr_set_svg_double(repr, "cx", this->cx.computed); + sp_repr_set_svg_double(repr, "cy", this->cy.computed); + sp_repr_set_svg_double(repr, "rx", this->rx.computed); + sp_repr_set_svg_double(repr, "ry", this->ry.computed); + repr->setAttribute("r", NULL ); + repr->setAttribute("sodipodi:cx", NULL ); + repr->setAttribute("sodipodi:cy", NULL ); + repr->setAttribute("sodipodi:rx", NULL ); + repr->setAttribute("sodipodi:ry", NULL ); + repr->setAttribute("sodipodi:end", NULL ); + repr->setAttribute("sodipodi:start", NULL ); + repr->setAttribute("sodipodi:open", NULL ); + repr->setAttribute("sodipodi:type", NULL ); + repr->setAttribute("d", NULL ); + break; + + default: + std::cerr << "SPGenericEllipse::write: unknown type." << std::endl; + } + + this->set_shape(); // evaluate SPCurve + + SPShape::write(xml_doc, repr, flags); + + // std::cout << "SPGenericEllipse::write: Exit: " << g_quark_to_string(repr->code()) << "\n" << std::endl; + return repr; } -bool SPGenericEllipse::_isSlice() const +const char *SPGenericEllipse::displayName() { - Geom::AngleInterval a(this->start, this->end, true); - return !(Geom::are_near(a.extent(), 0) || Geom::are_near(a.extent(), SP_2PI)); + switch ( type ) { + case SP_GENERIC_ELLIPSE_UNDEFINED: + case SP_GENERIC_ELLIPSE_ARC: + + if (this->_isSlice()) { + if (this->_closed) { + return _("Segment"); + } else { + return _("Arc"); + } + } else { + return _("Ellipse"); + } + + case SP_GENERIC_ELLIPSE_CIRCLE: + return _("Circle"); + + case SP_GENERIC_ELLIPSE_ELLIPSE: + return _("Ellipse"); + + default: + return "Unknown ellipse: ERROR"; + } + return ("Shouldn't be here"); } +// Create path for rendering shape on screen void SPGenericEllipse::set_shape() { + // std::cout << "SPGenericEllipse::set_shape: Entrance" << std::endl; if (hasBrokenPathEffect()) { g_warning("The ellipse shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as ellipse will remove the bad LPE"); @@ -147,7 +408,6 @@ void SPGenericEllipse::set_shape() return; } - if (Geom::are_near(this->rx.computed, 0) || Geom::are_near(this->ry.computed, 0)) { return; } @@ -157,6 +417,7 @@ void SPGenericEllipse::set_shape() SPCurve *curve = NULL; // For simplicity, we use a circle with center (0, 0) and radius 1 for our calculations. + Geom::Circle circle(0, 0, 1); if (this->_isSlice()) { Geom::Point center(0, 0); @@ -164,8 +425,7 @@ void SPGenericEllipse::set_shape() Geom::Point end_point = Geom::Point::polar(end); Geom::Point middle_point = make_angle_bisector_ray(Geom::Ray(center, start), Geom::Ray(center, end)).versor(); - Geom::Ellipse ellipse(0, 0, 1, 1, 0); - Geom::EllipticalArc *arc = ellipse.arc(start_point, middle_point, end_point); + Geom::EllipticalArc *arc = circle.arc(start_point, middle_point, end_point); Geom::Path path(start_point); path.append(*arc); @@ -187,15 +447,39 @@ void SPGenericEllipse::set_shape() curve = new SPCurve(pb.peek()); } else { // Full ellipse - Geom::Circle circle(0, 0, 1); - Geom::PathVector path; + // This code converts the circle to four elliptical arcs explicitly. + // Circle::getPath currently creates cubic bezier curves, these are not suitable here + // as a circle should have four mid markers at 0, 90, 180, 270 degrees. + Geom::Path path; + Geom::EllipticalArc* arc; - circle.getPath(path); + arc = circle.arc(Geom::Point::polar(0), Geom::Point::polar(M_PI / 4.0), Geom::Point::polar(M_PI / 2.0)); + path.append(*arc); + delete arc; + + arc = circle.arc(Geom::Point::polar(M_PI / 2.0), Geom::Point::polar(3.0 * M_PI / 4.0), Geom::Point::polar(M_PI)); + path.append(*arc); + delete arc; + + arc = circle.arc(Geom::Point::polar(M_PI), Geom::Point::polar(5.0 * M_PI / 4.0), Geom::Point::polar(3.0 * M_PI / 2.0)); + path.append(*arc); + delete arc; + + arc = circle.arc(Geom::Point::polar(3.0 * M_PI / 2.0), Geom::Point::polar(7.0 * M_PI / 4.0), Geom::Point::polar(2.0 * M_PI)); + path.append(*arc); + delete arc; + + Geom::PathBuilder pb; + pb.append(path); + pb.closePath(); - curve = new SPCurve(path); - curve->closepath(); + curve = new SPCurve(pb.peek()); } + // gchar *str = sp_svg_write_path(curve->get_pathvector()); + // std::cout << " path: " << str << std::endl; + // g_free(str); + // Stretching / moving the calculated shape to fit the actual dimensions. Geom::Affine aff = Geom::Scale(rx.computed, ry.computed) * Geom::Translate(cx.computed, cy.computed); curve->transform(aff); @@ -217,54 +501,7 @@ void SPGenericEllipse::set_shape() } curve->unref(); -} - -void SPGenericEllipse::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) -{ - this->normalize(); - Geom::Affine const i2dt = this->i2dt_affine(); - - // Snap to the 4 quadrant points of the ellipse, but only if the arc - // spans far enough to include them - if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_ELLIPSE_QUADRANT_POINT)) { - for (double angle = 0; angle < SP_2PI; angle += M_PI_2) { - if (Geom::AngleInterval(this->start, this->end, true).contains(angle)) { - Geom::Point pt = this->getPointAtAngle(angle) * i2dt; - p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_ELLIPSE_QUADRANT_POINT, Inkscape::SNAPTARGET_ELLIPSE_QUADRANT_POINT)); - } - } - } - - double cx = this->cx.computed; - double cy = this->cy.computed; - - bool slice = this->_isSlice(); - - // Add the centre, if we have a closed slice or when explicitly asked for - if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_NODE_CUSP) && slice && this->_closed) { - Geom::Point pt = Geom::Point(cx, cy) * i2dt; - p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_NODE_CUSP, Inkscape::SNAPTARGET_NODE_CUSP)); - } - - if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) { - Geom::Point pt = Geom::Point(cx, cy) * i2dt; - p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT)); - } - - // And if we have a slice, also snap to the endpoints - if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_NODE_CUSP) && slice) { - // Add the start point, if it's not coincident with a quadrant point - if (!Geom::are_near(std::fmod(this->start, M_PI_2), 0)) { - Geom::Point pt = this->getPointAtAngle(this->start) * i2dt; - p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_NODE_CUSP, Inkscape::SNAPTARGET_NODE_CUSP)); - } - - // Add the end point, if it's not coincident with a quadrant point - if (!Geom::are_near(std::fmod(this->end, M_PI_2), 0)) { - Geom::Point pt = this->getPointAtAngle(this->end) * i2dt; - p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_NODE_CUSP, Inkscape::SNAPTARGET_NODE_CUSP)); - } - } + // std::cout << "SPGenericEllipse::set_shape: Exit" << std::endl; } Geom::Affine SPGenericEllipse::set_transform(Geom::Affine const &xform) @@ -323,367 +560,123 @@ Geom::Affine SPGenericEllipse::set_transform(Geom::Affine const &xform) return ret; } -void SPGenericEllipse::normalize() -{ - Geom::AngleInterval a(this->start, this->end, true); - - this->start = a.initialAngle().radians0(); - this->end = a.finalAngle().radians0(); -} - -Inkscape::XML::Node *SPGenericEllipse::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +void SPGenericEllipse::snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs) { - if (flags & SP_OBJECT_WRITE_EXT) { - if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - repr = xml_doc->createElement("svg:path"); - } - - sp_repr_set_svg_double(repr, "sodipodi:cx", this->cx.computed); - sp_repr_set_svg_double(repr, "sodipodi:cy", this->cy.computed); - sp_repr_set_svg_double(repr, "sodipodi:rx", this->rx.computed); - sp_repr_set_svg_double(repr, "sodipodi:ry", this->ry.computed); + this->normalize(); + Geom::Affine const i2dt = this->i2dt_affine(); - if (SP_IS_ARC(this)) { - SP_ARC(this)->sp_arc_set_elliptical_path_attribute(this->getRepr()); + // Snap to the 4 quadrant points of the ellipse, but only if the arc + // spans far enough to include them + if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_ELLIPSE_QUADRANT_POINT)) { + for (double angle = 0; angle < SP_2PI; angle += M_PI_2) { + if (Geom::AngleInterval(this->start, this->end, true).contains(angle)) { + Geom::Point pt = this->getPointAtAngle(angle) * i2dt; + p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_ELLIPSE_QUADRANT_POINT, Inkscape::SNAPTARGET_ELLIPSE_QUADRANT_POINT)); + } } } - this->set_shape(); // evaluate SPCurve - - SPShape::write(xml_doc, repr, flags); - - return repr; -} - -/* SVG <ellipse> element */ -SPEllipse::SPEllipse() : SPGenericEllipse() -{ -} - -SPEllipse::~SPEllipse() -{ -} - -void SPEllipse::build(SPDocument *document, Inkscape::XML::Node *repr) -{ - SPGenericEllipse::build(document, repr); - - this->readAttr("cx"); - this->readAttr("cy"); - this->readAttr("rx"); - this->readAttr("ry"); -} + double cx = this->cx.computed; + double cy = this->cy.computed; + + bool slice = this->_isSlice(); -Inkscape::XML::Node *SPEllipse::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) -{ - if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - repr = xml_doc->createElement("svg:ellipse"); + // Add the centre, if we have a closed slice or when explicitly asked for + if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_NODE_CUSP) && slice && this->_closed) { + Geom::Point pt = Geom::Point(cx, cy) * i2dt; + p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_NODE_CUSP, Inkscape::SNAPTARGET_NODE_CUSP)); } - sp_repr_set_svg_double(repr, "cx", this->cx.computed); - sp_repr_set_svg_double(repr, "cy", this->cy.computed); - sp_repr_set_svg_double(repr, "rx", this->rx.computed); - sp_repr_set_svg_double(repr, "ry", this->ry.computed); - - SPGenericEllipse::write(xml_doc, repr, flags); - - return repr; -} - - -void SPEllipse::set(unsigned int key, gchar const *value) -{ - switch (key) { - case SP_ATTR_CX: - this->cx.readOrUnset(value); - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - - case SP_ATTR_CY: - this->cy.readOrUnset(value); - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; + if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) { + Geom::Point pt = Geom::Point(cx, cy) * i2dt; + p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT)); + } - case SP_ATTR_RX: - if (!this->rx.read(value) || (this->rx.value <= 0.0)) { - this->rx.unset(); + // And if we have a slice, also snap to the endpoints + if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_NODE_CUSP) && slice) { + // Add the start point, if it's not coincident with a quadrant point + if (!Geom::are_near(std::fmod(this->start, M_PI_2), 0)) { + Geom::Point pt = this->getPointAtAngle(this->start) * i2dt; + p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_NODE_CUSP, Inkscape::SNAPTARGET_NODE_CUSP)); } - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - - case SP_ATTR_RY: - if (!this->ry.read(value) || (this->ry.value <= 0.0)) { - this->ry.unset(); + // Add the end point, if it's not coincident with a quadrant point + if (!Geom::are_near(std::fmod(this->end, M_PI_2), 0)) { + Geom::Point pt = this->getPointAtAngle(this->end) * i2dt; + p.push_back(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_NODE_CUSP, Inkscape::SNAPTARGET_NODE_CUSP)); } - - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - - default: - SPGenericEllipse::set(key, value); - break; } } -const char *SPEllipse::displayName() -{ - return _("Ellipse"); -} - - -/* SVG <circle> element */ -SPCircle::SPCircle() : SPGenericEllipse() -{ -} - -SPCircle::~SPCircle() -{ -} - -void SPCircle::build(SPDocument *document, Inkscape::XML::Node *repr) -{ - SPGenericEllipse::build(document, repr); - - this->readAttr("cx"); - this->readAttr("cy"); - this->readAttr("r"); -} - - -Inkscape::XML::Node *SPCircle::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +void SPGenericEllipse::modified(guint flags) { - if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - repr = xml_doc->createElement("svg:circle"); + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + this->set_shape(); } - sp_repr_set_svg_double(repr, "cx", this->cx.computed); - sp_repr_set_svg_double(repr, "cy", this->cy.computed); - sp_repr_set_svg_double(repr, "r", this->rx.computed); - - SPGenericEllipse::write(xml_doc, repr, flags); - - return repr; + SPShape::modified(flags); } -void SPCircle::set(unsigned int key, gchar const *value) +void SPGenericEllipse::update_patheffect(bool write) { - switch (key) { - case SP_ATTR_CX: - this->cx.readOrUnset(value); - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; + this->set_shape(); - case SP_ATTR_CY: - this->cy.readOrUnset(value); - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; + if (write) { + Inkscape::XML::Node *repr = this->getRepr(); - case SP_ATTR_R: - if (!this->rx.read(value) || this->rx.value <= 0.0) { - this->rx.unset(); + if (this->_curve != NULL) { + gchar *str = sp_svg_write_path(this->_curve->get_pathvector()); + repr->setAttribute("d", str); + g_free(str); + } else { + repr->setAttribute("d", NULL); } - - this->ry = this->rx; - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - - default: - SPGenericEllipse::set(key, value); - break; } -} -const char *SPCircle::displayName() -{ - return _("Circle"); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -/* <path sodipodi:type="arc"> element */ -SPArc::SPArc() : SPGenericEllipse() +void SPGenericEllipse::normalize() { -} + Geom::AngleInterval a(this->start, this->end, true); -SPArc::~SPArc() -{ + this->start = a.initialAngle().radians0(); + this->end = a.finalAngle().radians0(); } -void SPArc::build(SPDocument *document, Inkscape::XML::Node *repr) +Geom::Point SPGenericEllipse::getPointAtAngle(double arg) const { - SPGenericEllipse::build(document, repr); - - this->readAttr("sodipodi:cx"); - this->readAttr("sodipodi:cy"); - this->readAttr("sodipodi:rx"); - this->readAttr("sodipodi:ry"); - - this->readAttr("sodipodi:start"); - this->readAttr("sodipodi:end"); - this->readAttr("sodipodi:open"); + return Geom::Point::polar(arg) * Geom::Scale(rx.computed, ry.computed) * Geom::Translate(cx.computed, cy.computed); } /* - * sp_arc_set_elliptical_path_attribute: + * set_elliptical_path_attribute: * * Convert center to endpoint parameterization and set it to repr. * * See SVG 1.0 Specification W3C Recommendation * ``F.6 Ellptical arc implementation notes'' for more detail. */ -bool SPArc::sp_arc_set_elliptical_path_attribute(Inkscape::XML::Node *repr) +bool SPGenericEllipse::set_elliptical_path_attribute(Inkscape::XML::Node *repr) { - Inkscape::SVG::PathString str; - - Geom::Point p1 = this->getPointAtAngle(this->start); - Geom::Point p2 = this->getPointAtAngle(this->end); - double rx = this->rx.computed; - double ry = this->ry.computed; - - str.moveTo(p1); + // Make sure our pathvector is up to date. + this->set_shape(); - double dt = fmod(this->end - this->start, SP_2PI); + if (this->getCurve() != NULL) { + gchar* d = sp_svg_write_path(this->getCurve()->get_pathvector()); - if (fabs(dt) < 1e-6) { - Geom::Point ph = getPointAtAngle((this->start + this->end) / 2.0); + repr->setAttribute("d", d); - str.arcTo(rx, ry, 0, true, true, ph) - .arcTo(rx, ry, 0, true, true, p2) - .closePath(); + g_free(d); } else { - bool fa = (fabs(dt) > M_PI); - bool fs = (dt > 0); - - str.arcTo(rx, ry, 0, fa, fs, p2); - - if (this->_closed) { - Geom::Point center = Geom::Point(this->cx.computed, this->cy.computed); - str.lineTo(center).closePath(); - } + repr->setAttribute("d", NULL); } - repr->setAttribute("d", str.c_str()); return true; } -Inkscape::XML::Node *SPArc::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) -{ - if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - repr = xml_doc->createElement("svg:path"); - } - - if (flags & SP_OBJECT_WRITE_EXT) { - repr->setAttribute("sodipodi:type", "arc"); - - sp_repr_set_svg_double(repr, "sodipodi:cx", this->cx.computed); - sp_repr_set_svg_double(repr, "sodipodi:cy", this->cy.computed); - sp_repr_set_svg_double(repr, "sodipodi:rx", this->rx.computed); - sp_repr_set_svg_double(repr, "sodipodi:ry", this->ry.computed); - - // write start and end only if they are non-trivial; otherwise remove - if (this->_isSlice()) { - sp_repr_set_svg_double(repr, "sodipodi:start", this->start); - sp_repr_set_svg_double(repr, "sodipodi:end", this->end); - - repr->setAttribute("sodipodi:open", (!this->_closed) ? "true" : NULL); - } else { - repr->setAttribute("sodipodi:end", NULL); - repr->setAttribute("sodipodi:start", NULL); - repr->setAttribute("sodipodi:open", NULL); - } - } - - // write d= - this->sp_arc_set_elliptical_path_attribute(repr); - - SPGenericEllipse::write(xml_doc, repr, flags); - - return repr; -} - -void SPArc::set(unsigned int key, gchar const *value) -{ - switch (key) { - case SP_ATTR_SODIPODI_CX: - this->cx.readOrUnset(value); - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - - case SP_ATTR_SODIPODI_CY: - this->cy.readOrUnset(value); - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - - case SP_ATTR_SODIPODI_RX: - if (!this->rx.read(value) || this->rx.computed <= 0.0) { - this->rx.unset(); - } - - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - - case SP_ATTR_SODIPODI_RY: - if (!this->ry.read(value) || this->ry.computed <= 0.0) { - this->ry.unset(); - } - - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - - case SP_ATTR_SODIPODI_START: - if (value) { - sp_svg_number_read_d(value, &this->start); - } else { - this->start = 0; - } - - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - - case SP_ATTR_SODIPODI_END: - if (value) { - sp_svg_number_read_d(value, &this->end); - } else { - this->end = 2 * M_PI; - } - - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - - case SP_ATTR_SODIPODI_OPEN: - this->_closed = (!value); - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - break; - - default: - SPGenericEllipse::set(key, value); - break; - } -} - -void SPArc::modified(guint flags) -{ - if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - this->set_shape(); - } - - SPGenericEllipse::modified(flags); -} - -const char *SPArc::displayName() -{ - if (this->_isSlice()) { - if (this->_closed) { - return _("Segment"); - } else { - return _("Arc"); - } - } else { - return _("Ellipse"); - } -} - -void SPArc::sp_arc_position_set(gdouble x, gdouble y, gdouble rx, gdouble ry) +void SPGenericEllipse::position_set(gdouble x, gdouble y, gdouble rx, gdouble ry) { this->cx.computed = x; this->cy.computed = y; @@ -706,9 +699,11 @@ void SPArc::sp_arc_position_set(gdouble x, gdouble y, gdouble rx, gdouble ry) this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -Geom::Point SPGenericEllipse::getPointAtAngle(double arg) const +bool SPGenericEllipse::_isSlice() const { - return Geom::Point::polar(arg) * Geom::Scale(rx.computed, ry.computed) * Geom::Translate(cx.computed, cy.computed); + Geom::AngleInterval a(this->start, this->end, true); + + return !(Geom::are_near(a.extent(), 0) || Geom::are_near(a.extent(), SP_2PI)); } /* diff --git a/src/sp-ellipse.h b/src/sp-ellipse.h index eab0b4907..94bddde98 100644 --- a/src/sp-ellipse.h +++ b/src/sp-ellipse.h @@ -7,9 +7,11 @@ * Authors: * Lauris Kaplinski <lauris@kaplinski.com> * Mitsuru Oka + * Tavmjong Bah * * Copyright (C) 1999-2002 Lauris Kaplinski * Copyright (C) 2000-2001 Ximian, Inc. + * Copyright (C) 2013 Tavmjong Bah * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -21,11 +23,20 @@ #define SP_GENERICELLIPSE(obj) (dynamic_cast<SPGenericEllipse*>((SPObject*)obj)) #define SP_IS_GENERICELLIPSE(obj) (dynamic_cast<const SPGenericEllipse*>((SPObject*)obj) != NULL) +enum GenericEllipseType { + SP_GENERIC_ELLIPSE_UNDEFINED, + SP_GENERIC_ELLIPSE_ARC, + SP_GENERIC_ELLIPSE_CIRCLE, + SP_GENERIC_ELLIPSE_ELLIPSE +}; + class SPGenericEllipse : public SPShape { public: SPGenericEllipse(); virtual ~SPGenericEllipse(); + // Regardless of type, the ellipse/circle/arc is stored + // internally with these variables. (Circle radius is rx). SVGLength cx; SVGLength cy; SVGLength rx; @@ -38,14 +49,23 @@ public: void setClosed(bool value); double start, end; + GenericEllipseType type; + + virtual void build(SPDocument *document, Inkscape::XML::Node *repr); + virtual void set(unsigned int key, gchar const *value); virtual void update(SPCtx *ctx, unsigned int flags); + virtual Inkscape::XML::Node *write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual const char *displayName(); - virtual void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs); virtual void set_shape(); virtual Geom::Affine set_transform(Geom::Affine const &xform); + virtual void snappoints(std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs); + + virtual void modified(unsigned int flags); + virtual void update_patheffect(bool write); /** @@ -55,6 +75,9 @@ public: Geom::Point getPointAtAngle(double arg) const; + bool set_elliptical_path_attribute(Inkscape::XML::Node *repr); + void position_set(gdouble x, gdouble y, gdouble rx, gdouble ry); + protected: /** * @brief Determines whether the shape is a part of an ellipse. @@ -64,62 +87,6 @@ protected: bool _closed; }; - -/* SVG <ellipse> element */ -#define SP_ELLIPSE(obj) (dynamic_cast<SPEllipse*>((SPObject*)obj)) -#define SP_IS_ELLIPSE(obj) (dynamic_cast<const SPEllipse*>((SPObject*)obj) != NULL) - -class SPEllipse : public SPGenericEllipse { -public: - SPEllipse(); - virtual ~SPEllipse(); - - virtual void build(SPDocument *document, Inkscape::XML::Node *repr); - virtual Inkscape::XML::Node *write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); - virtual void set(unsigned int key, gchar const *value); - virtual const char *displayName(); -}; - - -/* SVG <circle> element */ -#define SP_CIRCLE(obj) (dynamic_cast<SPCircle*>((SPObject*)obj)) -#define SP_IS_CIRCLE(obj) (dynamic_cast<const SPCircle*>((SPObject*)obj) != NULL) - -class SPCircle : public SPGenericEllipse { -public: - SPCircle(); - virtual ~SPCircle(); - - virtual void build(SPDocument *document, Inkscape::XML::Node *repr); - virtual Inkscape::XML::Node *write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); - virtual void set(unsigned int key, gchar const *value); - virtual const char *displayName(); -}; - - -/* <path sodipodi:type="arc"> element */ -#define SP_ARC(obj) (dynamic_cast<SPArc*>((SPObject*)obj)) -#define SP_IS_ARC(obj) (dynamic_cast<const SPArc*>((SPObject*)obj) != NULL) - -class SPArc : public SPGenericEllipse { -public: - SPArc(); - virtual ~SPArc(); - - virtual void build(SPDocument *document, Inkscape::XML::Node *repr); - virtual Inkscape::XML::Node *write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); - virtual void set(unsigned int key, gchar const *value); - virtual const char *displayName(); - virtual void modified(unsigned int flags); - - void sp_arc_position_set(gdouble x, gdouble y, gdouble rx, gdouble ry); - -private: - bool sp_arc_set_elliptical_path_attribute(Inkscape::XML::Node *repr); - - friend class SPGenericEllipse; -}; - #endif /* diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index 1a5c65be9..9d45c92fc 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -114,7 +114,7 @@ void SPFilter::release() { this->href = NULL; } - for (map<gchar *, int, ltstr>::const_iterator i = this->_image_name->begin() ; i != this->_image_name->end() ; i++) { + for (map<gchar *, int, ltstr>::const_iterator i = this->_image_name->begin() ; i != this->_image_name->end() ; ++i) { g_free(i->first); } diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 83d2d8e78..a0aa9692e 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -476,8 +476,8 @@ char *sp_guide_description(SPGuide const *guide, const bool verbose) 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()); + 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", _("<b>Shift+drag</b> to rotate, <b>Ctrl+drag</b> to move origin, <b>Del</b> to delete")); diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index b7e4ee4a9..61ba2ae0d 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -35,6 +35,7 @@ #include "inkscape.h" #include "desktop.h" #include "shape-editor.h" +#include "sp-ellipse.h" #include <algorithm> @@ -387,6 +388,10 @@ void SPLPEItem::addPathEffect(gchar *value, bool reset) this->getRepr()->setAttribute("inkscape:path-effect", hrefs.c_str()); + // Make sure that ellipse is stored as <svg:path> + if( SP_IS_GENERICELLIPSE(this)) { + SP_GENERICELLIPSE(this)->write( this->getRepr()->document(), this->getRepr(), SP_OBJECT_WRITE_EXT ); + } // make sure there is an original-d for paths!!! sp_lpe_item_create_original_path_recursive(this); @@ -436,6 +441,10 @@ void SPLPEItem::removeCurrentPathEffect(bool keep_paths) this->getRepr()->setAttribute("inkscape:path-effect", r.c_str()); } else { this->getRepr()->setAttribute("inkscape:path-effect", NULL); + // Make sure that ellipse is stored as <svg:circle> or <svg:ellipse> if possible. + if( SP_IS_GENERICELLIPSE(this)) { + SP_GENERICELLIPSE(this)->write( this->getRepr()->document(), this->getRepr(), SP_OBJECT_WRITE_EXT ); + } } if (!keep_paths) { @@ -447,6 +456,11 @@ void SPLPEItem::removeAllPathEffects(bool keep_paths) { this->getRepr()->setAttribute("inkscape:path-effect", NULL); + // Make sure that ellipse is stored as <svg:circle> or <svg:ellipse> if possible. + if( SP_IS_GENERICELLIPSE(this)) { + SP_GENERICELLIPSE(this)->write( this->getRepr()->document(), this->getRepr(), SP_OBJECT_WRITE_EXT ); + } + if (!keep_paths) { sp_lpe_item_cleanup_original_path_recursive(this); } diff --git a/src/sp-mesh-array.cpp b/src/sp-mesh-array.cpp index 2c3c7fa65..5a204e8b0 100644 --- a/src/sp-mesh-array.cpp +++ b/src/sp-mesh-array.cpp @@ -1058,9 +1058,9 @@ void SPMeshNodeArray::create( SPMeshGradient *mg, SPItem *item, Geom::OptRect bb end = start + 2.0 * M_PI; } - if ( SP_IS_ARC( item ) ) { + if ( SP_IS_GENERICELLIPSE( item ) ) { // For arcs use set start/stop - SPArc* arc = SP_ARC( item ); + SPGenericEllipse* arc = SP_GENERICELLIPSE( item ); center[Geom::X] = arc->cx.computed; center[Geom::Y] = arc->cy.computed; rx = arc->rx.computed; @@ -1130,11 +1130,11 @@ void SPMeshNodeArray::create( SPMeshGradient *mg, SPItem *item, Geom::OptRect bb // Normal grid meshes - if( SP_IS_ARC( item ) ) { + if( SP_IS_GENERICELLIPSE( item ) ) { // std::cout << "We've got ourselves an arc!" << std::endl; - SPArc* arc = SP_ARC( item ); + SPGenericEllipse* arc = SP_GENERICELLIPSE( item ); center[Geom::X] = arc->cx.computed; center[Geom::Y] = arc->cy.computed; gdouble rx = arc->rx.computed; diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 4464a0be2..ad497ff2f 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -557,12 +557,11 @@ void SPNamedView::set(unsigned int key, const gchar* value) { * in that they aren't in general absolute units as currently required by * doc_units. */ - static Inkscape::Util::Unit px = unit_table.getUnit("px"); - Inkscape::Util::Unit const *new_unit = new Inkscape::Util::Unit(px); + static Inkscape::Util::Unit const *px = unit_table.getUnit("px"); + Inkscape::Util::Unit const *new_unit = px; if (value) { - Inkscape::Util::Unit u = unit_table.getUnit(value); - Inkscape::Util::Unit const *const req_unit = new Inkscape::Util::Unit(u); + Inkscape::Util::Unit const *const req_unit = unit_table.getUnit(value); if ( !unit_table.hasUnit(value) ) { g_warning("Unrecognized unit `%s'", value); /* fixme: Document errors should be reported in the status bar or @@ -585,8 +584,7 @@ void SPNamedView::set(unsigned int key, const gchar* value) { Inkscape::Util::Unit const *new_unit = NULL; if (value) { - Inkscape::Util::Unit u = unit_table.getUnit(value); - Inkscape::Util::Unit const *const req_unit = new Inkscape::Util::Unit(u); + Inkscape::Util::Unit const *const req_unit = unit_table.getUnit(value); if ( !unit_table.hasUnit(value) ) { g_warning("Unrecognized unit `%s'", value); /* fixme: Document errors should be reported in the status bar or @@ -1114,14 +1112,14 @@ double SPNamedView::getMarginLength(gchar const * const key, bool const use_width) { double value; - Inkscape::Util::Unit percent = unit_table.getUnit("%"); + static Inkscape::Util::Unit const *percent = unit_table.getUnit("%"); if(!this->storeAsDouble(key,&value)) { return 0.0; } - if (*margin_units == percent) { + if (*margin_units == *percent) { return (use_width)? width * value : height * value; } - if (!margin_units->compatibleWith(*return_units)) { + if (!margin_units->compatibleWith(return_units)) { return 0.0; } return value; @@ -1129,14 +1127,11 @@ double SPNamedView::getMarginLength(gchar const * const key, /** * Returns namedview's default unit. + * If no default unit is set, "pt" is returned */ -Inkscape::Util::Unit const SPNamedView::getDefaultUnit() const +Inkscape::Util::Unit const * SPNamedView::getDefaultUnit() const { - if (doc_units) { - return *doc_units; - } else { - return *(new Inkscape::Util::Unit(unit_table.getUnit("pt"))); - } + return doc_units ? doc_units : unit_table.getUnit("pt"); } /** diff --git a/src/sp-namedview.h b/src/sp-namedview.h index 30f962d9f..00302e9a1 100644 --- a/src/sp-namedview.h +++ b/src/sp-namedview.h @@ -82,7 +82,7 @@ public: gchar const *getName() const; guint getViewCount(); GSList const *getViewList() const; - Inkscape::Util::Unit const getDefaultUnit() const; + Inkscape::Util::Unit const * getDefaultUnit() const; void translateGuides(Geom::Translate const &translation); void translateGrids(Geom::Translate const &translation); diff --git a/src/sp-object.h b/src/sp-object.h index bcaa1dac7..3faadb404 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -514,7 +514,7 @@ public: /** * Updates the object's repr based on the object's state. * - * This method updates the the repr attached to the object to reflect the object's current + * This method updates the repr attached to the object to reflect the object's current * state; see the three-argument version for details. * * @param flags object write flags that apply to this update diff --git a/src/sp-text.cpp b/src/sp-text.cpp index c431f52da..de5e63fe6 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -348,7 +348,7 @@ gchar* SPText::description() { } 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()); + 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 *) this); diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index 24a3ea6de..9d44b5adb 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -399,7 +399,7 @@ void SPSpiralContext::drag(Geom::Point const &p, guint state) { /* status text */ Inkscape::Util::Quantity q = Inkscape::Util::Quantity(rad, "px"); - GString *rads = g_string_new(q.string(*desktop->namedview->doc_units).c_str()); + GString *rads = g_string_new(q.string(desktop->namedview->doc_units).c_str()); this->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Spiral</b>: radius %s, angle %5g°; with <b>Ctrl</b> to snap angle"), rads->str, sp_round((arg + 2.0*M_PI*this->spiral->revo)*180/M_PI, 0.0001)); diff --git a/src/star-context.cpp b/src/star-context.cpp index 30112cbe9..d801ad0a0 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -417,7 +417,7 @@ void SPStarContext::drag(Geom::Point p, guint state) /* status text */ Inkscape::Util::Quantity q = Inkscape::Util::Quantity(r1, "px"); - GString *rads = g_string_new(q.string(*desktop->namedview->doc_units).c_str()); + GString *rads = g_string_new(q.string(desktop->namedview->doc_units).c_str()); this->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, ( this->isflatsided? _("<b>Polygon</b>: radius %s, angle %5g°; with <b>Ctrl</b> to snap angle") diff --git a/src/svg/svg-length.cpp b/src/svg/svg-length.cpp index 8d26a95d2..6f1a88a58 100644 --- a/src/svg/svg-length.cpp +++ b/src/svg/svg-length.cpp @@ -541,6 +541,8 @@ std::string sp_svg_length_write_with_units(SVGLength const &length) Inkscape::SVGOStringStream os; if (length.unit == SVGLength::PERCENT) { os << 100*length.value << sp_svg_length_get_css_units(length.unit); + } else if (length.unit == SVGLength::FOOT) { + os << 12*length.value << sp_svg_length_get_css_units(SVGLength::INCH); } else { os << length.value << sp_svg_length_get_css_units(length.unit); } diff --git a/src/text-context.cpp b/src/text-context.cpp index f12ce6aa6..7d9b9848f 100644 --- a/src/text-context.cpp +++ b/src/text-context.cpp @@ -601,8 +601,8 @@ bool SPTextContext::root_handler(GdkEvent* event) { // status text Inkscape::Util::Quantity x_q = Inkscape::Util::Quantity(fabs((p - this->p0)[Geom::X]), "px"); Inkscape::Util::Quantity y_q = Inkscape::Util::Quantity(fabs((p - this->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()); + 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()); this->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Flowed text frame</b>: %s × %s"), xs->str, ys->str); g_string_free(xs, FALSE); diff --git a/src/tools-switch.cpp b/src/tools-switch.cpp index a3c0f2daa..5f54ad15a 100644 --- a/src/tools-switch.cpp +++ b/src/tools-switch.cpp @@ -88,7 +88,7 @@ static char const *const tool_names[] = { }; static char const *const tool_msg[] = { NULL, - N_("<b>Click</b> to Select and Tranform objects, <b>Drag</b> to select many objects."), + N_("<b>Click</b> to Select and Transform objects, <b>Drag</b> to select many objects."), N_("Modify selected path points (nodes) directly."), N_("To tweak a path by pushing, select it and drag over it."), N_("<b>Drag</b>, <b>click</b> or <b>click and scroll</b> to spray the selected objects."), @@ -143,7 +143,9 @@ tools_active(SPDesktop *dt) void tools_switch(SPDesktop *dt, int num) { + dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, gettext( tool_msg[num] ) ); if (dt) { + // This event may change the above message dt->_tool_changed.emit(num); } @@ -152,7 +154,6 @@ tools_switch(SPDesktop *dt, int num) /* First 4 tools use guides, first is undefined but we don't care */ dt->activate_guides(num < 5); inkscape_eventcontext_set(dt->getEventContext()); - dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, gettext( tool_msg[num] ) ); } void tools_switch_by_item(SPDesktop *dt, SPItem *item, Geom::Point const p) diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index b3675440b..87c399339 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -1107,7 +1107,7 @@ CloneTiler::CloneTiler (void) : #endif double value = prefs->getDouble(prefs_path + "fillwidth", 50.0); - Inkscape::Util::Unit const unit = unit_menu->getUnit(); + Inkscape::Util::Unit const *unit = unit_menu->getUnit(); gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit); fill_width->set_value (units); @@ -1140,7 +1140,7 @@ CloneTiler::CloneTiler (void) : #endif double value = prefs->getDouble(prefs_path + "fillheight", 50.0); - Inkscape::Util::Unit const unit = unit_menu->getUnit(); + Inkscape::Util::Unit const *unit = unit_menu->getUnit(); gdouble const units = Inkscape::Util::Quantity::convert(value, "px", unit); fill_height->set_value (units); @@ -2948,7 +2948,7 @@ void CloneTiler::clonetiler_switch_to_fill(GtkToggleButton * /*tb*/, GtkWidget * void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u) { gdouble const raw_dist = gtk_adjustment_get_value (adj); - Inkscape::Util::Unit const unit = u->getUnit(); + Inkscape::Util::Unit const *unit = u->getUnit(); gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -2958,7 +2958,7 @@ void CloneTiler::clonetiler_fill_width_changed(GtkAdjustment *adj, Inkscape::UI: void CloneTiler::clonetiler_fill_height_changed(GtkAdjustment *adj, Inkscape::UI::Widget::UnitMenu *u) { gdouble const raw_dist = gtk_adjustment_get_value (adj); - Inkscape::Util::Unit const unit = u->getUnit(); + Inkscape::Util::Unit const *unit = u->getUnit(); gdouble const pixels = Inkscape::Util::Quantity::convert(raw_dist, unit, "px"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -2971,7 +2971,7 @@ void CloneTiler::clonetiler_unit_changed() 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::Unit const *unit = unit_menu->getUnit(); 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/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp index 17f6ae74d..6d32e3aa8 100644 --- a/src/ui/dialog/dialog-manager.cpp +++ b/src/ui/dialog/dialog-manager.cpp @@ -243,14 +243,14 @@ Dialog *DialogManager::getDialog(GQuark name) { /** * Shows the named dialog, creating it if necessary. */ -void DialogManager::showDialog(gchar const *name) { - showDialog(g_quark_from_string(name)); +void DialogManager::showDialog(gchar const *name, bool grabfocus) { + showDialog(g_quark_from_string(name), grabfocus); } /** * Shows the named dialog, creating it if necessary. */ -void DialogManager::showDialog(GQuark name) { +void DialogManager::showDialog(GQuark name, bool grabfocus) { bool wantTiming = Inkscape::Preferences::get()->getBool("/dialogs/debug/trackAppear", false); GTimer *timer = (wantTiming) ? g_timer_new() : 0; // if needed, must be created/started before getDialog() Dialog *dialog = getDialog(name); @@ -261,7 +261,8 @@ void DialogManager::showDialog(GQuark name) { tracker->setAutodelete(true); timer = 0; } - dialog->present(); + if (grabfocus) + dialog->present(); } if ( timer ) { diff --git a/src/ui/dialog/dialog-manager.h b/src/ui/dialog/dialog-manager.h index 33b166aa1..15573f760 100644 --- a/src/ui/dialog/dialog-manager.h +++ b/src/ui/dialog/dialog-manager.h @@ -44,8 +44,8 @@ public: void registerFactory(GQuark name, DialogFactory factory); Dialog *getDialog(gchar const* dlgName); Dialog *getDialog(GQuark dlgName); - void showDialog(gchar const *name); - void showDialog(GQuark name); + void showDialog(gchar const *name, bool grabfocus=true); + void showDialog(GQuark name, bool grabfocus=true); protected: DialogManager(DialogManager const &d); // no copy diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 37d0ce213..a6019c55c 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -1441,7 +1441,7 @@ void DocumentProperties::update() _rum_deflt.setUnit (nv->doc_units->abbr); double doc_w = sp_desktop_document(dt)->getRoot()->width.value; - Glib::ustring doc_w_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->width.unit).abbr; + Glib::ustring doc_w_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->width.unit)->abbr; if (doc_w_unit == "") { doc_w_unit = "px"; } else if (doc_w_unit == "%" && sp_desktop_document(dt)->getRoot()->viewBox_set) { @@ -1449,7 +1449,7 @@ void DocumentProperties::update() doc_w = sp_desktop_document(dt)->getRoot()->viewBox.width(); } double doc_h = sp_desktop_document(dt)->getRoot()->height.value; - Glib::ustring doc_h_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->height.unit).abbr; + Glib::ustring doc_h_unit = unit_table.getUnit(sp_desktop_document(dt)->getRoot()->height.unit)->abbr; if (doc_h_unit == "") { doc_h_unit = "px"; } else if (doc_h_unit == "%" && sp_desktop_document(dt)->getRoot()->viewBox_set) { @@ -1644,11 +1644,11 @@ void DocumentProperties::onDocUnitChange() { SPDocument *doc = SP_ACTIVE_DOCUMENT; Inkscape::XML::Node *repr = sp_desktop_namedview(getDesktop())->getRepr(); - Inkscape::Util::Unit old_doc_unit = unit_table.getUnit("px"); + Inkscape::Util::Unit const *old_doc_unit = unit_table.getUnit("px"); if(repr->attribute("inkscape:document-units")) { old_doc_unit = unit_table.getUnit(repr->attribute("inkscape:document-units")); } - Inkscape::Util::Unit doc_unit = _rum_deflt.getUnit(); + Inkscape::Util::Unit const *doc_unit = _rum_deflt.getUnit(); // Don't execute when change is being undone if (!DocumentUndo::getUndoSensitive(doc)) { @@ -1657,7 +1657,7 @@ void DocumentProperties::onDocUnitChange() // Set document unit Inkscape::SVGOStringStream os; - os << doc_unit.abbr; + os << doc_unit->abbr; repr->setAttribute("inkscape:document-units", os.str().c_str()); // Set viewBox diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 577793496..f1f7cf6c1 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -1884,7 +1884,7 @@ void Export::setValuePx(Glib::RefPtr<Gtk::Adjustment>& adj, double val) void Export::setValuePx( Gtk::Adjustment *adj, double val) #endif { - const Unit unit = unit_selector->getUnit(); + Unit const *unit = unit_selector->getUnit(); setValue(adj, Inkscape::Util::Quantity::convert(val, "px", unit)); @@ -1934,7 +1934,7 @@ float Export::getValuePx( Gtk::Adjustment *adj ) #endif { float value = getValue( adj); - const Unit unit = unit_selector->getUnit(); + Unit const *unit = unit_selector->getUnit(); return Inkscape::Util::Quantity::convert(value, unit, "px"); } // end of sp_export_value_get_px() diff --git a/src/ui/dialog/filedialogimpl-win32.h b/src/ui/dialog/filedialogimpl-win32.h index 2e6bb4bb8..29bcb9a45 100644 --- a/src/ui/dialog/filedialogimpl-win32.h +++ b/src/ui/dialog/filedialogimpl-win32.h @@ -140,7 +140,7 @@ public: /// Shows the file dialog, and blocks until a file /// has been selected. - /// @return Returns true if the the user selected a + /// @return Returns true if the user selected a /// file, or false if the user pressed cancel. bool show(); @@ -341,7 +341,7 @@ public: /// Shows the file dialog, and blocks until a file /// has been selected. - /// @return Returns true if the the user selected a + /// @return Returns true if the user selected a /// file, or false if the user pressed cancel. bool show(); diff --git a/src/ui/dialog/find.cpp b/src/ui/dialog/find.cpp index def7b5bdb..37f2761df 100644 --- a/src/ui/dialog/find.cpp +++ b/src/ui/dialog/find.cpp @@ -664,7 +664,7 @@ bool Find::item_type_match (SPItem *item) if ( SP_IS_RECT(item)) { return ( all ||check_rects.get_active()); - } else if (SP_IS_GENERICELLIPSE(item) || SP_IS_ELLIPSE(item) || SP_IS_ARC(item) || SP_IS_CIRCLE(item)) { + } else if (SP_IS_GENERICELLIPSE(item)) { return ( all || check_ellipses.get_active()); } else if (SP_IS_STAR(item) || SP_IS_POLYGON(item)) { diff --git a/src/ui/dialog/guides.cpp b/src/ui/dialog/guides.cpp index 2de387364..5dfafa78d 100644 --- a/src/ui/dialog/guides.cpp +++ b/src/ui/dialog/guides.cpp @@ -59,7 +59,7 @@ Glib::ustring GuidelinePropertiesDialog::_angle_unit_status = DEG; // initialize GuidelinePropertiesDialog::~GuidelinePropertiesDialog() { // save current status _relative_toggle_status = _relative_toggle.get_active(); - _angle_unit_status = _spin_angle.getUnit().abbr; + _angle_unit_status = _spin_angle.getUnit()->abbr; } void GuidelinePropertiesDialog::showDialog(SPGuide *guide, SPDesktop *desktop) { diff --git a/src/ui/tool/node-tool.cpp b/src/ui/tool/node-tool.cpp index 4b236e94c..76e33e506 100644 --- a/src/ui/tool/node-tool.cpp +++ b/src/ui/tool/node-tool.cpp @@ -534,11 +534,7 @@ bool InkNodeTool::root_handler(GdkEvent* event) { break; } -// if (SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->root_handler) -// return SP_EVENT_CONTEXT_CLASS(ink_node_tool_parent_class)->root_handler(event_context, event); - SPEventContext::root_handler(event); - - return FALSE; + return SPEventContext::root_handler(event); } void InkNodeTool::update_tip(GdkEvent *event) { @@ -607,12 +603,6 @@ void InkNodeTool::update_tip(GdkEvent *event) { } } -bool InkNodeTool::item_handler(SPItem* item, GdkEvent* event) { - SPEventContext::item_handler(item, event); - - return FALSE; -} - void InkNodeTool::select_area(Geom::Rect const &sel, GdkEventButton *event) { using namespace Inkscape::UI; diff --git a/src/ui/tool/node-tool.h b/src/ui/tool/node-tool.h index ce022cec6..c41f50650 100644 --- a/src/ui/tool/node-tool.h +++ b/src/ui/tool/node-tool.h @@ -49,7 +49,6 @@ public: virtual void setup(); virtual void set(const Inkscape::Preferences::Entry& val); virtual bool root_handler(GdkEvent* event); - virtual bool item_handler(SPItem* item, GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index 82eb697bd..76ec68c3e 100644 --- a/src/ui/tool/node.cpp +++ b/src/ui/tool/node.cpp @@ -493,9 +493,9 @@ Glib::ustring Handle::_getDragTip(GdkEventMotion */*event*/) const 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()); + 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); @@ -1300,10 +1300,9 @@ Glib::ustring Node::_getDragTip(GdkEventMotion */*event*/) const 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); + 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); g_string_free(y, TRUE); return ret; diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index 2379dc181..b13567adb 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -565,9 +565,8 @@ PageSizer::find_paper_size (Inkscape::Util::Quantity w, Inkscape::Util::Quantity for (iter = _paperSizeTable.begin() ; 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, *w.unit); - double largeX = Inkscape::Util::Quantity::convert(paper.larger, i_unit, *w.unit); + double smallX = Inkscape::Util::Quantity::convert(paper.smaller, paper.unit, w.unit); + double largeX = Inkscape::Util::Quantity::convert(paper.larger, paper.unit, w.unit); g_return_val_if_fail(smallX <= largeX, _paperSizeListStore->children().end()); @@ -704,7 +703,7 @@ void PageSizer::on_value_changed() { if (_widgetRegistry->isUpdating()) return; - if (_unit != _dimensionUnits.getUnit().abbr) return; + if (_unit != _dimensionUnits.getUnit()->abbr) return; setDim (Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionUnits.getUnit()), Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionUnits.getUnit())); } @@ -712,7 +711,7 @@ void PageSizer::on_units_changed() { if (_widgetRegistry->isUpdating()) return; - _unit = _dimensionUnits.getUnit().abbr; + _unit = _dimensionUnits.getUnit()->abbr; setDim (Inkscape::Util::Quantity(_dimensionWidth.getValue(""), _dimensionUnits.getUnit()), Inkscape::Util::Quantity(_dimensionHeight.getValue(""), _dimensionUnits.getUnit())); } diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h index 95836a005..dc8e34d82 100644 --- a/src/ui/widget/page-sizer.h +++ b/src/ui/widget/page-sizer.h @@ -64,7 +64,7 @@ public: PaperSize(const Glib::ustring &nameArg, double smallerArg, double largerArg, - Inkscape::Util::Unit unitArg) + Inkscape::Util::Unit const *unitArg) { name = nameArg; smaller = smallerArg; @@ -108,7 +108,7 @@ public: /** * The units (px, pt, mm, etc) of this specification */ - Inkscape::Util::Unit unit; + Inkscape::Util::Unit const *unit; /// pointer to object in UnitTable, do not delete private: diff --git a/src/ui/widget/preferences-widget.cpp b/src/ui/widget/preferences-widget.cpp index 567f29f91..3ba00c083 100644 --- a/src/ui/widget/preferences-widget.cpp +++ b/src/ui/widget/preferences-widget.cpp @@ -354,7 +354,7 @@ void PrefSpinUnit::on_my_value_changed() Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (getWidget()->get_visible()) //only take action if user changed value { - prefs->setDoubleUnit(_prefs_path, getValue(getUnit().abbr), getUnit().abbr); + prefs->setDoubleUnit(_prefs_path, getValue(getUnit()->abbr), getUnit()->abbr); } } diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 93b0cef4e..883a9e1a2 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -167,7 +167,7 @@ public: SPDocument *doc_in = NULL ); void setUnit (const Glib::ustring); - Unit getUnit() const { return static_cast<UnitMenu*>(_widget)->getUnit(); }; + Unit const * getUnit() const { return static_cast<UnitMenu*>(_widget)->getUnit(); }; UnitMenu* getUnitMenu() const { return static_cast<UnitMenu*>(_widget); }; sigc::connection _changed_connection; diff --git a/src/ui/widget/scalar-unit.cpp b/src/ui/widget/scalar-unit.cpp index 2f4c1f341..4fa1a7584 100644 --- a/src/ui/widget/scalar-unit.cpp +++ b/src/ui/widget/scalar-unit.cpp @@ -102,7 +102,7 @@ void ScalarUnit::resetUnitType(UnitType unit_type) lastUnits = _unit_menu->getUnitAbbr(); } -Unit ScalarUnit::getUnit() const +Unit const * ScalarUnit::getUnit() const { g_assert(_unit_menu != NULL); return _unit_menu->getUnit(); @@ -228,13 +228,13 @@ void ScalarUnit::on_unit_changed() Glib::ustring abbr = _unit_menu->getUnitAbbr(); _suffix->set_label(abbr); - Inkscape::Util::Unit new_unit = (unit_table.getUnit(abbr)); - Inkscape::Util::Unit old_unit = (unit_table.getUnit(lastUnits)); + Inkscape::Util::Unit const *new_unit = unit_table.getUnit(abbr); + Inkscape::Util::Unit const *old_unit = unit_table.getUnit(lastUnits); double convertedVal = 0; - if (old_unit.type == UNIT_TYPE_DIMENSIONLESS && new_unit.type == UNIT_TYPE_LINEAR) { + if (old_unit->type == UNIT_TYPE_DIMENSIONLESS && new_unit->type == UNIT_TYPE_LINEAR) { convertedVal = PercentageToAbsolute(Scalar::getValue()); - } else if (old_unit.type == UNIT_TYPE_LINEAR && new_unit.type == UNIT_TYPE_DIMENSIONLESS) { + } else if (old_unit->type == UNIT_TYPE_LINEAR && new_unit->type == UNIT_TYPE_DIMENSIONLESS) { convertedVal = AbsoluteToPercentage(Scalar::getValue()); } else { double conversion = _unit_menu->getConversion(lastUnits); diff --git a/src/ui/widget/scalar-unit.h b/src/ui/widget/scalar-unit.h index 4f22f438c..9e310d3bd 100644 --- a/src/ui/widget/scalar-unit.h +++ b/src/ui/widget/scalar-unit.h @@ -82,7 +82,7 @@ public: /** * Gets the object for the currently selected unit. */ - Unit getUnit() const; + Unit const * getUnit() const; /** * Gets the UnitType ID for the unit. diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp index 894700046..3a6b0c7df 100644 --- a/src/ui/widget/selected-style.cpp +++ b/src/ui/widget/selected-style.cpp @@ -313,10 +313,10 @@ SelectedStyle::SelectedStyle(bool /*layout*/) 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((*iter).first, 0.0, 0.5))); + mi->add(*(new Gtk::Label(iter->first, 0.0, 0.5))); _unit_mis = g_slist_append(_unit_mis, mi); - Inkscape::Util::Unit const *u = new Inkscape::Util::Unit(unit_table.getUnit(iter->first)); - mi->signal_activate().connect(sigc::bind<Inkscape::Util::Unit>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), *u)); + Inkscape::Util::Unit const *u = unit_table.getUnit(iter->first); + mi->signal_activate().connect(sigc::bind<Inkscape::Util::Unit const *>(sigc::mem_fun(*this, &SelectedStyle::on_popup_units), u)); _popup_sw.attach(*mi, 0,1, row, row+1); row++; ++iter; @@ -481,7 +481,7 @@ SelectedStyle::setDesktop(SPDesktop *desktop) this ) )); - _sw_unit = const_cast<Inkscape::Util::Unit*>(sp_desktop_namedview(desktop)->doc_units); + _sw_unit = sp_desktop_namedview(desktop)->doc_units; // Set the doc default unit active in the units list gint length = g_slist_length(_unit_mis); @@ -931,8 +931,8 @@ SelectedStyle::on_opacity_click(GdkEventButton *event) return false; } -void SelectedStyle::on_popup_units(Inkscape::Util::Unit &unit) { - _sw_unit = new Inkscape::Util::Unit(unit); +void SelectedStyle::on_popup_units(Inkscape::Util::Unit const *unit) { + _sw_unit = unit; update(); } @@ -940,7 +940,7 @@ void SelectedStyle::on_popup_preset(int i) { SPCSSAttr *css = sp_repr_css_attr_new (); gdouble w; if (_sw_unit) { - w = Inkscape::Util::Quantity::convert(_sw_presets[i], *_sw_unit, "px"); + w = Inkscape::Util::Quantity::convert(_sw_presets[i], _sw_unit, "px"); } else { w = _sw_presets[i]; } @@ -1119,7 +1119,7 @@ SelectedStyle::update() { double w; if (_sw_unit) { - w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *_sw_unit); + w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", _sw_unit); } else { w = query->stroke_width.computed; } diff --git a/src/ui/widget/selected-style.h b/src/ui/widget/selected-style.h index 0a907f1fd..21e5575ed 100644 --- a/src/ui/widget/selected-style.h +++ b/src/ui/widget/selected-style.h @@ -276,11 +276,11 @@ protected: Gtk::Menu _popup_sw; Gtk::RadioButtonGroup _sw_group; GSList *_unit_mis; - void on_popup_units(Inkscape::Util::Unit &u); + void on_popup_units(Inkscape::Util::Unit const *u); void on_popup_preset(int i); Gtk::MenuItem _popup_sw_remove; - Inkscape::Util::Unit *_sw_unit; + Inkscape::Util::Unit const *_sw_unit; /// points to object in UnitTable, do not delete void *_drop[2]; bool _dropEnabled[2]; diff --git a/src/ui/widget/spinbutton.cpp b/src/ui/widget/spinbutton.cpp index 1114ff32b..6cbc15c1b 100644 --- a/src/ui/widget/spinbutton.cpp +++ b/src/ui/widget/spinbutton.cpp @@ -35,16 +35,16 @@ int SpinButton::on_input(double* newvalue) try { Inkscape::Util::EvaluatorQuantity result; if (_unit_menu || _unit_tracker) { - Unit unit; + Unit const *unit = NULL; if (_unit_menu) { unit = _unit_menu->getUnit(); } else { unit = _unit_tracker->getActiveUnit(); } - Inkscape::Util::ExpressionEvaluator eval = Inkscape::Util::ExpressionEvaluator(get_text().c_str(), &unit); + Inkscape::Util::ExpressionEvaluator eval = Inkscape::Util::ExpressionEvaluator(get_text().c_str(), unit); result = eval.evaluate(); // check if output dimension corresponds to input unit - if (result.dimension != (unit.isAbsolute() ? 1 : 0) ) { + if (result.dimension != (unit->isAbsolute() ? 1 : 0) ) { throw Inkscape::Util::EvaluatorException("Input dimensions do not match with parameter dimensions.",""); } } else { diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp index 49466ce54..a33c1d09f 100644 --- a/src/ui/widget/style-swatch.cpp +++ b/src/ui/widget/style-swatch.cpp @@ -333,7 +333,7 @@ void StyleSwatch::setStyle(SPStyle *query) if (has_stroke) { double w; if (_sw_unit) { - w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *_sw_unit); + w = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", _sw_unit); } else { w = query->stroke_width.computed; } diff --git a/src/ui/widget/unit-menu.cpp b/src/ui/widget/unit-menu.cpp index 111226774..7416a2f02 100644 --- a/src/ui/widget/unit-menu.cpp +++ b/src/ui/widget/unit-menu.cpp @@ -33,11 +33,9 @@ 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::iterator iter = m.begin(); - while(iter != m.end()) { - Glib::ustring text = (*iter).first; - append(text); - ++iter; + + for (UnitTable::UnitMap::iterator i = m.begin(); i != m.end(); ++i) { + append(i->first); } _type = unit_type; set_active_text(unit_table.primary(unit_type)); @@ -58,7 +56,7 @@ void UnitMenu::addUnit(Unit const& u) append(u.abbr); } -Unit UnitMenu::getUnit() const +Unit const * UnitMenu::getUnit() const { if (get_active_text() == "") { g_assert(_type != UNIT_TYPE_NONE); @@ -81,27 +79,27 @@ Glib::ustring UnitMenu::getUnitAbbr() const if (get_active_text() == "") { return ""; } - return getUnit().abbr; + return getUnit()->abbr; } UnitType UnitMenu::getUnitType() const { - return getUnit().type; + return getUnit()->type; } double UnitMenu::getUnitFactor() const { - return getUnit().factor; + return getUnit()->factor; } int UnitMenu::getDefaultDigits() const { - return getUnit().defaultDigits(); + return getUnit()->defaultDigits(); } double UnitMenu::getDefaultStep() const { - int factor_digits = -1*int(log10(getUnit().factor)); + int factor_digits = -1*int(log10(getUnit()->factor)); return pow(10.0, factor_digits); } @@ -112,19 +110,20 @@ double UnitMenu::getDefaultPage() const double UnitMenu::getConversion(Glib::ustring const &new_unit_abbr, Glib::ustring const &old_unit_abbr) const { - 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); + double old_factor = getUnit()->factor; + if (old_unit_abbr != "no_unit") { + old_factor = unit_table.getUnit(old_unit_abbr)->factor; + } + Unit const * new_unit = unit_table.getUnit(new_unit_abbr); // Catch the case of zero or negative unit factors (error!) if (old_factor < 0.0000001 || - new_unit.factor < 0.0000001) { + new_unit->factor < 0.0000001) { // TODO: Should we assert here? return 0.00; } - return old_factor / new_unit.factor; + return old_factor / new_unit->factor; } bool UnitMenu::isAbsolute() const diff --git a/src/ui/widget/unit-menu.h b/src/ui/widget/unit-menu.h index 3f4df6bf9..114c536c9 100644 --- a/src/ui/widget/unit-menu.h +++ b/src/ui/widget/unit-menu.h @@ -74,7 +74,7 @@ public: * Returns the Unit object corresponding to the current selection * in the dropdown widget. */ - Unit getUnit() const; + Unit const * getUnit() const; /** * Returns the abbreviated unit name of the selected unit. diff --git a/src/ui/widget/unit-tracker.cpp b/src/ui/widget/unit-tracker.cpp index f9b0c3a44..67eb1f48d 100644 --- a/src/ui/widget/unit-tracker.cpp +++ b/src/ui/widget/unit-tracker.cpp @@ -27,6 +27,7 @@ namespace Widget { UnitTracker::UnitTracker(UnitType unit_type) : _active(0), _isUpdating(false), + _activeUnit(NULL), _activeUnitInitialized(false), _store(0), _unitList(0), @@ -38,10 +39,10 @@ UnitTracker::UnitTracker(UnitType unit_type) : 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; + + + for (UnitTable::UnitMap::iterator m_iter = m.begin(); m_iter != m.end(); ++m_iter) { + Glib::ustring text = m_iter->first; gtk_list_store_append(_store, &iter); gtk_list_store_set(_store, &iter, COLUMN_STRING, text.c_str(), -1); } @@ -74,7 +75,7 @@ bool UnitTracker::isUpdating() const return _isUpdating; } -Inkscape::Util::Unit UnitTracker::getActiveUnit() const +Inkscape::Util::Unit const * UnitTracker::getActiveUnit() const { return _activeUnit; } @@ -101,8 +102,8 @@ void UnitTracker::setActiveUnit(Inkscape::Util::Unit const *unit) void UnitTracker::setActiveUnitByAbbr(gchar const *abbr) { - Inkscape::Util::Unit u = unit_table.getUnit(abbr); - setActiveUnit(&u); + Inkscape::Util::Unit const *u = unit_table.getUnit(abbr); + setActiveUnit(u); } void UnitTracker::addAdjustment(GtkAdjustment *adj) @@ -113,11 +114,11 @@ void UnitTracker::addAdjustment(GtkAdjustment *adj) } } -void UnitTracker::addUnit(Inkscape::Util::Unit const &u) +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); + gtk_list_store_set(_store, &iter, COLUMN_STRING, u ? u->abbr.c_str() : "NULL", -1); } void UnitTracker::setFullVal(GtkAdjustment *adj, gdouble val) @@ -197,13 +198,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 const *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 const *newUnit = unit_table.getUnit(newAbbr); _activeUnit = newUnit; if (_adjList) { @@ -230,7 +231,7 @@ void UnitTracker::_setActive(gint active) } } -void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape::Util::Unit const newUnit) +void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const *oldUnit, Inkscape::Util::Unit const *newUnit) { _isUpdating = true; for ( GSList *cur = _adjList ; cur ; cur = g_slist_next(cur) ) { @@ -238,13 +239,13 @@ void UnitTracker::_fixupAdjustments(Inkscape::Util::Unit const oldUnit, Inkscape 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) ) + if ( (oldUnit->type != Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) + && (newUnit->type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) ) { - val = newUnit.factor * 100; + 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) ) + } 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], "px", newUnit); diff --git a/src/ui/widget/unit-tracker.h b/src/ui/widget/unit-tracker.h index 19559ae1c..61bb556ef 100644 --- a/src/ui/widget/unit-tracker.h +++ b/src/ui/widget/unit-tracker.h @@ -36,9 +36,9 @@ public: void setActiveUnit(Inkscape::Util::Unit const *unit); void setActiveUnitByAbbr(gchar const *abbr); - Inkscape::Util::Unit getActiveUnit() const; + Inkscape::Util::Unit const * getActiveUnit() const; - void addUnit(Inkscape::Util::Unit const &u); + void addUnit(Inkscape::Util::Unit const *u); void addAdjustment(GtkAdjustment *adj); void setFullVal(GtkAdjustment *adj, gdouble val); @@ -52,13 +52,13 @@ private: 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 _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; + Inkscape::Util::Unit const *_activeUnit; bool _activeUnitInitialized; GtkListStore *_store; GSList *_unitList; diff --git a/src/util/expression-evaluator.cpp b/src/util/expression-evaluator.cpp index 3b7e77c6c..48064e647 100644 --- a/src/util/expression-evaluator.cpp +++ b/src/util/expression-evaluator.cpp @@ -48,7 +48,7 @@ EvaluatorToken::EvaluatorToken() value.fl = 0; } -ExpressionEvaluator::ExpressionEvaluator(const char *string, Unit *unit) : +ExpressionEvaluator::ExpressionEvaluator(const char *string, Unit const *unit) : string(string), unit(unit) { @@ -360,7 +360,7 @@ int ExpressionEvaluator::getIdentifierSize(const char *string, int start_offset) bool ExpressionEvaluator::resolveUnit (const char* identifier, EvaluatorQuantity *result, - Unit* unit) + Unit const* unit) { if (!unit) { result->value = 1; @@ -371,9 +371,9 @@ bool ExpressionEvaluator::resolveUnit (const char* identifier, result->dimension = unit->isAbsolute() ? 1 : 0; return true; } else if (unit_table.hasUnit(identifier)) { - Unit identifier_unit = unit_table.getUnit(identifier); - result->value = Quantity::convert(1, *unit, identifier_unit); - result->dimension = identifier_unit.isAbsolute() ? 1 : 0; + Unit const *identifier_unit = unit_table.getUnit(identifier); + result->value = Quantity::convert(1, unit, identifier_unit); + result->dimension = identifier_unit->isAbsolute() ? 1 : 0; return true; } else { return false; diff --git a/src/util/expression-evaluator.h b/src/util/expression-evaluator.h index 6412dfea7..50ff3fb70 100644 --- a/src/util/expression-evaluator.h +++ b/src/util/expression-evaluator.h @@ -133,13 +133,13 @@ public: class ExpressionEvaluator { public: - ExpressionEvaluator(const char *string, Unit *unit = NULL); + ExpressionEvaluator(const char *string, Unit const *unit = NULL); EvaluatorQuantity evaluate(); private: const char *string; - Unit *unit; + Unit const *unit; EvaluatorToken current_token; const char *start_of_current_token; @@ -160,7 +160,7 @@ private: static bool isUnitIdentifierStart(gunichar c); static int getIdentifierSize(const char *s, int start); - static bool resolveUnit(const char *identifier, EvaluatorQuantity *result, Unit *unit); + static bool resolveUnit(const char *identifier, EvaluatorQuantity *result, Unit const *unit); void throwError(const char *msg); }; diff --git a/src/util/units.cpp b/src/util/units.cpp index 59717d0b5..1023cfb6e 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -33,29 +33,85 @@ using Inkscape::Util::UNIT_TYPE_FONT_HEIGHT; namespace { -/** - * A std::map that gives the data type value for the string version. - * - * Note that we'd normally not return a reference to an internal version, but - * for this constant case it allows us to check against getTypeMappings().end(). - */ -/** @todo consider hiding map behind hasFoo() and getFoo() type functions.*/ -std::map<Glib::ustring, Inkscape::Util::UnitType> &getTypeMappings() +#define MAKE_UNIT_CODE(a, b) \ + ((((unsigned)(a) & 0xdf) << 8) | ((unsigned)(b) & 0xdf)) + +enum UnitCode { + UNIT_CODE_PX = MAKE_UNIT_CODE('p','x'), + UNIT_CODE_PT = MAKE_UNIT_CODE('p','t'), + UNIT_CODE_PC = MAKE_UNIT_CODE('p','c'), + UNIT_CODE_MM = MAKE_UNIT_CODE('m','m'), + UNIT_CODE_CM = MAKE_UNIT_CODE('c','m'), + UNIT_CODE_IN = MAKE_UNIT_CODE('i','n'), + UNIT_CODE_FT = MAKE_UNIT_CODE('f','t'), + UNIT_CODE_EM = MAKE_UNIT_CODE('e','m'), + UNIT_CODE_EX = MAKE_UNIT_CODE('e','x'), + UNIT_CODE_PERCENT = MAKE_UNIT_CODE('%',0) +}; + +// TODO: convert to constexpr in C++11, so that the above constants can be eliminated +inline unsigned make_unit_code(char a, char b) { + // this should work without the casts, but let's be 100% sure + // also ensure that the codes are in lowercase + return MAKE_UNIT_CODE(a,b); +} +inline unsigned make_unit_code(char const *str) { + if (!str || str[0] == 0) return 0; + return MAKE_UNIT_CODE(str[0], str[1]); +} + + + +unsigned const svg_length_lookup[] = { + 0, + UNIT_CODE_PX, + UNIT_CODE_PT, + UNIT_CODE_PC, + UNIT_CODE_MM, + UNIT_CODE_CM, + UNIT_CODE_IN, + UNIT_CODE_FT, + UNIT_CODE_EM, + UNIT_CODE_EX, + UNIT_CODE_PERCENT +}; + + + +// maps unit codes obtained from their abbreviations to their SVGLength unit indexes +typedef INK_UNORDERED_MAP<unsigned, SVGLength::Unit> UnitCodeLookup; + +UnitCodeLookup make_unit_code_lookup() { - static bool init = false; - static std::map<Glib::ustring, Inkscape::Util::UnitType> typeMap; - if (!init) - { - init = true; - typeMap["DIMENSIONLESS"] = UNIT_TYPE_DIMENSIONLESS; - typeMap["LINEAR"] = UNIT_TYPE_LINEAR; - typeMap["RADIAL"] = UNIT_TYPE_RADIAL; - typeMap["FONT_HEIGHT"] = UNIT_TYPE_FONT_HEIGHT; - // Note that code was not yet handling LINEAR_SCALED, TIME, QTY and NONE + UnitCodeLookup umap; + for (unsigned i = 1; i < G_N_ELEMENTS(svg_length_lookup); ++i) { + umap[svg_length_lookup[i]] = static_cast<SVGLength::Unit>(i); } - return typeMap; + return umap; +} + +UnitCodeLookup const unit_code_lookup = make_unit_code_lookup(); + + + +typedef INK_UNORDERED_MAP<Glib::ustring, Inkscape::Util::UnitType> TypeMap; + +/** A std::map that gives the data type value for the string version. + * @todo consider hiding map behind hasFoo() and getFoo() type functions. */ +TypeMap make_type_map() +{ + TypeMap tmap; + tmap["DIMENSIONLESS"] = UNIT_TYPE_DIMENSIONLESS; + tmap["LINEAR"] = UNIT_TYPE_LINEAR; + tmap["RADIAL"] = UNIT_TYPE_RADIAL; + tmap["FONT_HEIGHT"] = UNIT_TYPE_FONT_HEIGHT; + // Note that code was not yet handling LINEAR_SCALED, TIME, QTY and NONE + + return tmap; } +TypeMap const type_map = make_type_map(); + } // namespace namespace Inkscape { @@ -106,13 +162,13 @@ Unit::Unit(UnitType type, Glib::ustring const &name, Glib::ustring const &name_plural, Glib::ustring const &abbr, - Glib::ustring const &description) : - type(type), - factor(factor), - name(name), - name_plural(name_plural), - abbr(abbr), - description(description) + Glib::ustring const &description) + : type(type) + , factor(factor) + , name(name) + , name_plural(name_plural) + , abbr(abbr) + , description(description) { g_return_if_fail(factor <= 0); } @@ -133,62 +189,48 @@ int Unit::defaultDigits() const return factor_digits; } -bool Unit::compatibleWith(const Unit &u) const +bool Unit::compatibleWith(Unit const *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; } - + // Different, incompatible types return false; } -bool Unit::compatibleWith(const Glib::ustring u) const +bool Unit::compatibleWith(Glib::ustring const &u) const { static UnitTable unit_table; return compatibleWith(unit_table.getUnit(u)); } -bool operator== (const Unit &u1, const Unit &u2) +bool Unit::operator==(Unit const &other) const { - return (u1.type == u2.type && u1.name.compare(u2.name) == 0); -} - -bool operator!= (const Unit &u1, const Unit &u2) -{ - return !(u1 == u2); + return (type == other.type && name.compare(other.name) == 0); } int Unit::svgUnit() const { - if (!abbr.compare("px")) - return SVGLength::PX; - if (!abbr.compare("pt")) - return SVGLength::PT; - if (!abbr.compare("pc")) - return SVGLength::PC; - if (!abbr.compare("mm")) - return SVGLength::MM; - if (!abbr.compare("cm")) - return SVGLength::CM; - if (!abbr.compare("in")) - return SVGLength::INCH; - if (!abbr.compare("ft")) - return SVGLength::FOOT; - if (!abbr.compare("em")) - return SVGLength::EM; - if (!abbr.compare("ex")) - return SVGLength::EX; - if (!abbr.compare("%")) - return SVGLength::PERCENT; + char const *astr = abbr.c_str(); + unsigned code = make_unit_code(astr); + + UnitCodeLookup::const_iterator u = unit_code_lookup.find(code); + if (u != unit_code_lookup.end()) { + return u->second; + } return 0; } + + +Unit UnitTable::_empty_unit; + UnitTable::UnitTable() { gchar *filename = g_build_filename(INKSCAPE_UIDIR, "units.xml", NULL); @@ -198,64 +240,50 @@ UnitTable::UnitTable() UnitTable::~UnitTable() { - for (UnitMap::iterator iter = _unit_map.begin(); iter != _unit_map.end(); ++iter) + for (UnitCodeMap::iterator iter = _unit_map.begin(); iter != _unit_map.end(); ++iter) { - delete (*iter).second; + delete iter->second; } } void UnitTable::addUnit(Unit const &u, bool primary) { - _unit_map[u.abbr] = new Unit(u); + _unit_map[make_unit_code(u.abbr.c_str())] = new Unit(u); if (primary) { _primary_unit[u.type] = u.abbr; } } -Unit UnitTable::getUnit(Glib::ustring const &unit_abbr) const +Unit const *UnitTable::getUnit(char const *abbr) const { - UnitMap::const_iterator iter = _unit_map.find(unit_abbr); - if (iter != _unit_map.end()) { - return *((*iter).second); - } else { - return Unit(); + UnitCodeMap::const_iterator f = _unit_map.find(make_unit_code(abbr)); + if (f != _unit_map.end()) { + return &(*f->second); } + return &_empty_unit; } -Unit UnitTable::getUnit(SVGLength::Unit const u) const -{ - Glib::ustring u_str; - switch(u) { - case SVGLength::PX: - u_str = "px"; break; - case SVGLength::PT: - u_str = "pt"; break; - case SVGLength::PC: - u_str = "pc"; break; - case SVGLength::MM: - u_str = "mm"; break; - case SVGLength::CM: - u_str = "cm"; break; - case SVGLength::INCH: - u_str = "in"; break; - case SVGLength::FOOT: - u_str = "ft"; break; - case SVGLength::EM: - u_str = "em"; break; - case SVGLength::EX: - u_str = "ex"; break; - case SVGLength::PERCENT: - u_str = "%"; break; - default: - u_str = ""; + +Unit const *UnitTable::getUnit(Glib::ustring const &unit_abbr) const +{ + return getUnit(unit_abbr.c_str()); +} +Unit const *UnitTable::getUnit(SVGLength::Unit u) const +{ + if (u == 0 || u > SVGLength::LAST_UNIT) { + return &_empty_unit; } - - return getUnit(u_str); + + UnitCodeMap::const_iterator f = _unit_map.find(svg_length_lookup[u]); + if (f != _unit_map.end()) { + return &(*f->second); + } + return &_empty_unit; } -Quantity UnitTable::getQuantity(Glib::ustring const& q) const +Quantity UnitTable::parseQuantity(Glib::ustring const &q) const { Glib::MatchInfo match_info; - + // Extract value double value = 0; Glib::RefPtr<Glib::Regex> value_regex = Glib::Regex::create("[-+]*[\\d+]*[\\.,]*[\\d+]*[eE]*[-+]*\\d+"); @@ -263,24 +291,26 @@ Quantity UnitTable::getQuantity(Glib::ustring const& q) const std::istringstream tmp_v(match_info.fetch(0)); tmp_v >> value; } - + // Extract unit abbreviation Glib::ustring abbr; Glib::RefPtr<Glib::Regex> unit_regex = Glib::Regex::create("[A-z%]+"); if (unit_regex->match(q, match_info)) { abbr = match_info.fetch(0); } - - return Quantity(value, abbr); + + Quantity qty(value, abbr); + return qty; } +/* UNSAFE while passing around pointers to the Unit objects in this table bool UnitTable::deleteUnit(Unit const &u) { bool deleted = false; // Cannot delete the primary unit type since it's // used for conversions if (u.abbr != _primary_unit[u.type]) { - UnitMap::iterator iter = _unit_map.find(u.abbr); + UnitCodeMap::iterator iter = _unit_map.find(make_unit_code(u.abbr.c_str())); if (iter != _unit_map.end()) { delete (*iter).second; _unit_map.erase(iter); @@ -289,19 +319,20 @@ bool UnitTable::deleteUnit(Unit const &u) } return deleted; } +*/ bool UnitTable::hasUnit(Glib::ustring const &unit) const { - UnitMap::const_iterator iter = _unit_map.find(unit); + UnitCodeMap::const_iterator iter = _unit_map.find(make_unit_code(unit.c_str())); return (iter != _unit_map.end()); } UnitTable::UnitMap UnitTable::units(UnitType type) const { UnitMap submap; - for (UnitMap::const_iterator iter = _unit_map.begin(); iter != _unit_map.end(); ++iter) { - if (((*iter).second)->type == type) { - submap.insert(UnitMap::value_type((*iter).first, new Unit(*((*iter).second)))); + for (UnitCodeMap::const_iterator iter = _unit_map.begin(); iter != _unit_map.end(); ++iter) { + if (iter->second->type == type) { + submap.insert(UnitMap::value_type(iter->second->abbr, *iter->second)); } } @@ -351,8 +382,9 @@ void UnitParser::on_start_element(Ctx &ctx, Glib::ustring const &name, AttrMap c AttrMap::const_iterator f; if ((f = attrs.find("type")) != attrs.end()) { Glib::ustring type = f->second; - if (getTypeMappings().find(type) != getTypeMappings().end()) { - unit.type = getTypeMappings()[type]; + TypeMap::const_iterator tf = type_map.find(type); + if (tf != type_map.end()) { + unit.type = tf->second; } else { g_warning("Skipping unknown unit type '%s'.\n", type.c_str()); skip = true; @@ -388,92 +420,101 @@ void UnitParser::on_end_element(Ctx &ctx, Glib::ustring const &name) } } -Quantity::Quantity(double q, const Unit &u) +Quantity::Quantity(double q, Unit const *u) + : unit(u) + , quantity(q) +{ +} +Quantity::Quantity(double q, Glib::ustring const &u) + : unit(unit_table.getUnit(u.c_str())) + , quantity(q) { - unit = new Unit(u); - quantity = q; } -Quantity::Quantity(double q, const Glib::ustring u) +Quantity::Quantity(double q, char const *u) + : unit(unit_table.getUnit(u)) + , quantity(q) { - unit = new Unit(unit_table.getUnit(u)); - quantity = q; } -bool Quantity::compatibleWith(const Unit &u) const +bool Quantity::compatibleWith(Unit const *u) const { return unit->compatibleWith(u); } -bool Quantity::compatibleWith(const Glib::ustring u) const +bool Quantity::compatibleWith(Glib::ustring const &u) const +{ + return compatibleWith(u.c_str()); +} +bool Quantity::compatibleWith(char const *u) const { return compatibleWith(unit_table.getUnit(u)); } -double Quantity::value(const Unit &u) const +double Quantity::value(Unit const *u) const +{ + return convert(quantity, unit, u); +} +double Quantity::value(Glib::ustring const &u) const { - return convert(quantity, *unit, u); + return value(u.c_str()); } -double Quantity::value(const Glib::ustring u) const +double Quantity::value(char const *u) const { return value(unit_table.getUnit(u)); } -Glib::ustring Quantity::string(const Unit &u) const { +Glib::ustring Quantity::string(Unit const *u) const { return Glib::ustring::format(std::fixed, std::setprecision(2), value(u)) + " " + unit->abbr; } -Glib::ustring Quantity::string(const Glib::ustring u) const { - return string(unit_table.getUnit(u)); +Glib::ustring Quantity::string(Glib::ustring const &u) const { + return string(unit_table.getUnit(u.c_str())); } Glib::ustring Quantity::string() const { - return string(*unit); + return string(unit); } -double Quantity::convert(const double from_dist, const Unit &from, const Unit &to) +double Quantity::convert(double from_dist, Unit const *from, Unit const *to) { // Percentage - if (to.type == UNIT_TYPE_DIMENSIONLESS) { - return from_dist * to.factor; + if (to->type == UNIT_TYPE_DIMENSIONLESS) { + return from_dist * to->factor; } // 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) +double Quantity::convert(double from_dist, Glib::ustring const &from, Unit const *to) { - return convert(from_dist, unit_table.getUnit(from), to); + return convert(from_dist, unit_table.getUnit(from.c_str()), to); } -double Quantity::convert(const double from_dist, const Unit &from, const Glib::ustring to) +double Quantity::convert(double from_dist, Unit const *from, Glib::ustring const &to) { - return convert(from_dist, from, unit_table.getUnit(to)); + return convert(from_dist, from, unit_table.getUnit(to.c_str())); } -double Quantity::convert(const double from_dist, const Glib::ustring from, const Glib::ustring to) +double Quantity::convert(double from_dist, Glib::ustring const &from, Glib::ustring const &to) { - return convert(from_dist, unit_table.getUnit(from), unit_table.getUnit(to)); + return convert(from_dist, unit_table.getUnit(from.c_str()), unit_table.getUnit(to.c_str())); } - -bool operator< (const Quantity &ql, const Quantity &qr) +double Quantity::convert(double from_dist, char const *from, char const *to) { - if (ql.unit->type != qr.unit->type) { - g_warning("Incompatible units"); - return false; - } - return ql.quantity < qr.value(*ql.unit); + return convert(from_dist, unit_table.getUnit(from), unit_table.getUnit(to)); } -bool operator> (const Quantity &ql, const Quantity &qr) + +bool Quantity::operator<(Quantity const &other) const { - if (ql.unit->type != qr.unit->type) { + if (unit->type != other.unit->type) { g_warning("Incompatible units"); return false; } - return ql.quantity > qr.value(*ql.unit); + return quantity < other.value(unit); } -bool operator!= (const Quantity &q1, const Quantity &q2) +bool Quantity::operator==(Quantity const &other) const { - return (*q1.unit != *q2.unit) || (q1.quantity != q2.quantity); + return (*unit == *other.unit) && (quantity == other.quantity); } } // namespace Util diff --git a/src/util/units.h b/src/util/units.h index 7ba6e1e86..e1addaa24 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -14,8 +14,10 @@ #define INKSCAPE_UTIL_UNITS_H #include <map> +#include <boost/operators.hpp> #include <glibmm/ustring.h> #include "svg/svg-length.h" +#include "unordered-containers.h" namespace Inkscape { namespace Util { @@ -33,8 +35,10 @@ enum UnitType { const char DEG[] = "°"; -class Unit { - public: +class Unit + : boost::equality_comparable<Unit> +{ +public: Unit(); Unit(UnitType type, double factor, @@ -54,8 +58,9 @@ 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; + bool compatibleWith(Unit const *u) const; + bool compatibleWith(Glib::ustring const &) const; + bool compatibleWith(char const *) const; UnitType type; double factor; @@ -65,50 +70,54 @@ class Unit { 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); + bool operator==(Unit const &other) const; - /** Get SVG unit. */ + /** Get SVG unit code. */ int svgUnit() const; }; -class Quantity { +class Quantity + : boost::totally_ordered<Quantity> +{ public: - const Unit *unit; + Unit const *unit; double quantity; /** Initialize a quantity. */ - Quantity(double q, const Unit &u); // constructor - Quantity(double q, const Glib::ustring u); // constructor + Quantity(double q, Unit const *u); + Quantity(double q, Glib::ustring const &u); + Quantity(double q, char const *u); /** Checks if a quantity is compatible with the specified unit. */ - bool compatibleWith(const Unit &u) const; - bool compatibleWith(const Glib::ustring u) const; + bool compatibleWith(Unit const *u) const; + bool compatibleWith(Glib::ustring const &u) const; + bool compatibleWith(char const *u) const; /** Return the quantity's value in the specified unit. */ - double value(const Unit &u) const; - double value(const Glib::ustring u) const; + double value(Unit const *u) const; + double value(Glib::ustring const &u) const; + double value(char const *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(Unit const *u) const; + Glib::ustring string(Glib::ustring const &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); - static double convert(const double from_dist, const Glib::ustring from, const Glib::ustring to); - + /** Convert distances. + no NULL check is performed on the passed pointers to Unit objects! */ + static double convert(double from_dist, Unit const *from, Unit const *to); + static double convert(double from_dist, Glib::ustring const &from, Unit const *to); + static double convert(double from_dist, Unit const *from, Glib::ustring const &to); + static double convert(double from_dist, Glib::ustring const &from, Glib::ustring const &to); + static double convert(double from_dist, char const *from, char const *to); + /** Comparison operators. */ - friend bool operator< (const Quantity &ql, const Quantity &qr); - friend bool operator> (const Quantity &ql, const Quantity &qr); - friend bool operator!= (const Quantity &q1, const Quantity &q2); + bool operator<(Quantity const &other) const; + bool operator==(Quantity const &other) const; }; class UnitTable { - public: +public: /** * Initializes the unit tables and identifies the primary unit types. * @@ -117,28 +126,31 @@ class UnitTable { UnitTable(); virtual ~UnitTable(); - typedef std::map<Glib::ustring, Unit*> UnitMap; + typedef INK_UNORDERED_MAP<Glib::ustring, Unit> UnitMap; + typedef INK_UNORDERED_MAP<unsigned, Unit*> UnitCodeMap; /** Add a new unit to the table */ void addUnit(Unit const &u, bool primary); /** Retrieve a given unit based on its string identifier */ - Unit getUnit(Glib::ustring const &name) const; + Unit const *getUnit(Glib::ustring const &name) const; + Unit const *getUnit(char const *name) const; /** Retrieve a given unit based on its SVGLength unit */ - Unit getUnit(SVGLength::Unit const u) const; + Unit const *getUnit(SVGLength::Unit u) const; /** Retrieve a quantity based on its string identifier */ - Quantity getQuantity(Glib::ustring const &q) const; + Quantity parseQuantity(Glib::ustring const &q) const; - /** Remove a unit definition from the given unit type table */ - bool deleteUnit(Unit const &u); + /** Remove a unit definition from the given unit type table * / + * DISABLED, unsafe with the current passing around pointers to Unit objects in this table */ + //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; /** Provides an iteratable list of items in the given unit table */ - UnitTable::UnitMap units(UnitType type) const; + UnitMap units(UnitType type) const; /** Returns the default unit abbr for the given type */ Glib::ustring primary(UnitType type) const; @@ -159,13 +171,14 @@ class UnitTable { /** Saves the current UnitTable to the given file. */ bool save(std::string const &filename); - protected: - UnitTable::UnitMap _unit_map; +protected: + UnitCodeMap _unit_map; Glib::ustring _primary_unit[UNIT_TYPE_QTY]; double _linear_scale; + static Unit _empty_unit; - private: +private: UnitTable(UnitTable const &t); UnitTable operator=(UnitTable const &t); diff --git a/src/util/unordered-containers.h b/src/util/unordered-containers.h index 6f738f0ce..70d36c4dc 100644 --- a/src/util/unordered-containers.h +++ b/src/util/unordered-containers.h @@ -16,6 +16,8 @@ # include "config.h" #endif +#include <glibmm/ustring.h> + #ifndef DOXYGEN_SHOULD_SKIP_THIS #if defined(HAVE_TR1_UNORDERED_SET) @@ -25,6 +27,17 @@ # define INK_UNORDERED_MAP std::tr1::unordered_map # define INK_HASH std::tr1::hash +namespace std { +namespace tr1 { +template <> +struct hash<Glib::ustring> : public std::unary_function<Glib::ustring, std::size_t> { + std::size_t operator()(Glib::ustring const &s) const { + return hash<std::string>()(s.raw()); + } +}; +} // namespace tr1 +} // namespace std + #elif defined(HAVE_BOOST_UNORDERED_SET) # include <boost/unordered_set.hpp> # include <boost/unordered_map.hpp> @@ -32,6 +45,15 @@ # define INK_UNORDERED_MAP boost::unordered_map # define INK_HASH boost::hash +namespace boost { +template <> +struct hash<Glib::ustring> : public std::unary_function<Glib::ustring, std::size_t> { + std::size_t operator()(Glib::ustring const &s) const { + return hash<std::string>()(s.raw()); + } +}; +} // namespace boost + #elif defined(HAVE_EXT_HASH_SET) # include <functional> @@ -54,6 +76,13 @@ struct hash<T *> : public std::unary_function<T *, std::size_t> { return x + (x >> 3); } }; + +template <> +struct hash<Glib::ustring> : public std::unary_function<Glib::ustring, std::size_t> { + std::size_t operator()(Glib::ustring const &s) const { + return hash<std::string>()(s.raw()); + } +}; } // namespace __gnu_cxx #endif diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index c31c61e32..5569780e7 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -112,10 +112,9 @@ sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *v { SPItem *item = SP_ITEM(items->data); - if (SP_IS_ARC(item) && SP_IS_GENERICELLIPSE(item)) { + if (SP_IS_GENERICELLIPSE(item)) { SPGenericEllipse *ge = SP_GENERICELLIPSE(item); - SPArc *arc = SP_ARC(item); if (!strcmp(value_name, "start")) { ge->start = (gtk_adjustment_get_value(adj) * M_PI)/ 180; @@ -124,8 +123,8 @@ sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *v } ge->normalize(); - (SP_OBJECT(arc))->updateRepr(); - (SP_OBJECT(arc))->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + (SP_OBJECT(ge))->updateRepr(); + (SP_OBJECT(ge))->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); modmade = true; } @@ -181,7 +180,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) items = items->next) { SPItem *item = reinterpret_cast<SPItem*>(items->data); - if (SP_IS_ARC(item)) { + if (SP_IS_GENERICELLIPSE(item)) { Inkscape::XML::Node *repr = item->getRepr(); repr->setAttribute("sodipodi:open", "true"); item->updateRepr(); @@ -194,7 +193,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) items = items->next) { SPItem *item = reinterpret_cast<SPItem *>(items->data); - if (SP_IS_ARC(item)) { + if (SP_IS_GENERICELLIPSE(item)) { Inkscape::XML::Node *repr = item->getRepr(); repr->setAttribute("sodipodi:open", NULL); item->updateRepr(); @@ -286,7 +285,7 @@ static void sp_arc_toolbox_selection_changed(Inkscape::Selection *selection, GOb items = items->next) { SPItem *item = reinterpret_cast<SPItem *>(items->data); - if (SP_IS_ARC(item)) { + if (SP_IS_GENERICELLIPSE(item)) { n_selected++; repr = item->getRepr(); } diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index e9a834db7..3ca433586 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -394,9 +394,9 @@ 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::Unit pt = unit_table.getUnit("pt"); + Inkscape::Util::Unit const *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_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); @@ -425,7 +425,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), pt); - gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(pt.name_plural.c_str())); + 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) diff --git a/src/widgets/lpe-toolbar.cpp b/src/widgets/lpe-toolbar.cpp index 922526a9f..045d7aa78 100644 --- a/src/widgets/lpe-toolbar.cpp +++ b/src/widgets/lpe-toolbar.cpp @@ -198,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<UnitTracker*>(g_object_get_data(tbl, "tracker")); - Unit const unit = tracker->getActiveUnit(); + Unit const *unit = tracker->getActiveUnit(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString("/tools/lpetool/unit", unit.abbr); + prefs->setString("/tools/lpetool/unit", unit->abbr); SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); if (SP_IS_LPETOOL_CONTEXT(desktop->event_context)) { @@ -299,10 +299,10 @@ void sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GO UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); tracker->setActiveUnit(sp_desktop_namedview(desktop)->doc_units); g_object_set_data(holder, "tracker", tracker); - Unit const unit = tracker->getActiveUnit(); + Unit const *unit = tracker->getActiveUnit(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString("/tools/lpetool/unit", unit.abbr); + prefs->setString("/tools/lpetool/unit", unit->abbr); /** Automatically create a list of LPEs that get added to the toolbar **/ { diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 53ed2d275..58244566d 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -82,7 +82,7 @@ sp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl) static void measure_unit_changed(GtkAction* /*act*/, GObject* tbl) { UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data(tbl, "tracker")); - Glib::ustring const unit = tracker->getActiveUnit().abbr; + Glib::ustring const unit = tracker->getActiveUnit()->abbr; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setString("/tools/measure/unit", unit); } diff --git a/src/widgets/node-toolbar.cpp b/src/widgets/node-toolbar.cpp index 2348acc46..0d4868642 100644 --- a/src/widgets/node-toolbar.cpp +++ b/src/widgets/node-toolbar.cpp @@ -240,7 +240,7 @@ static void sp_node_toolbox_coord_changed(gpointer /*shape_editor*/, GObject *tb if (!tracker) { return; } - Unit const unit = tracker->getActiveUnit(); + Unit const *unit = tracker->getActiveUnit(); InkNodeTool *nt = get_node_tool(); if (!nt || nt->_selected_nodes->empty()) { @@ -274,7 +274,7 @@ static void sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::D if (!tracker) { return; } - Unit const unit = tracker->getActiveUnit(); + Unit const *unit = tracker->getActiveUnit(); if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { prefs->setDouble(Glib::ustring("/tools/nodes/") + (d == Geom::X ? "x" : "y"), diff --git a/src/widgets/paintbucket-toolbar.cpp b/src/widgets/paintbucket-toolbar.cpp index 028753b59..363fadd3d 100644 --- a/src/widgets/paintbucket-toolbar.cpp +++ b/src/widgets/paintbucket-toolbar.cpp @@ -98,13 +98,13 @@ static void paintbucket_autogap_changed(EgeSelectOneAction* act, GObject * /*tbl static void paintbucket_offset_changed(GtkAdjustment *adj, GObject *tbl) { UnitTracker* tracker = static_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" )); - Unit 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", unit.abbr); + prefs->setString("/tools/paintbucket/offsetunits", unit->abbr); } static void paintbucket_defaults(GtkWidget *, GObject *tbl) @@ -179,8 +179,8 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions UnitTracker* tracker = new UnitTracker(Inkscape::Util::UNIT_TYPE_LINEAR); Glib::ustring stored_unit = prefs->getString("/tools/paintbucket/offsetunits"); if (!stored_unit.empty()) { - Unit u = unit_table.getUnit(stored_unit); - tracker->setActiveUnit(&u); + Unit const *u = unit_table.getUnit(stored_unit); + tracker->setActiveUnit(u); } g_object_set_data( holder, "tracker", tracker ); { diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 0d5d3a688..0287a9aeb 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -93,7 +93,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); UnitTracker* tracker = reinterpret_cast<UnitTracker*>(g_object_get_data( tbl, "tracker" )); - Unit const unit = tracker->getActiveUnit(); + Unit const *unit = tracker->getActiveUnit(); if (DocumentUndo::getUndoSensitive(sp_desktop_document(desktop))) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -114,7 +114,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * for (GSList const *items = selection->itemList(); items != NULL; items = items->next) { if (SP_IS_RECT(items->data)) { if (gtk_adjustment_get_value(adj) != 0) { - (SP_RECT(items->data)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, *sp_desktop_namedview(desktop)->doc_units)); + (SP_RECT(items->data)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, sp_desktop_namedview(desktop)->doc_units)); } else { SP_OBJECT(items->data)->getRepr()->setAttribute(value_name, NULL); } @@ -185,8 +185,8 @@ 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<UnitTracker*>( g_object_get_data( tbl, "tracker" ) ); - Unit const unit = tracker->getActiveUnit(); - Unit const doc_unit = *sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units; + Unit const *unit = tracker->getActiveUnit(); + Unit const *doc_unit = sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units; 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 e4e72d86e..2604ebf22 100644 --- a/src/widgets/ruler.cpp +++ b/src/widgets/ruler.cpp @@ -63,7 +63,7 @@ enum { typedef struct { GtkOrientation orientation; - Inkscape::Util::Unit *unit; + Inkscape::Util::Unit const *unit; gdouble lower; gdouble upper; gdouble position; @@ -260,7 +260,7 @@ sp_ruler_init (SPRuler *ruler) gtk_widget_set_has_window (GTK_WIDGET (ruler), FALSE); priv->orientation = GTK_ORIENTATION_HORIZONTAL; - priv->unit = new Inkscape::Util::Unit(unit_table.getUnit("px")); + priv->unit = unit_table.getUnit("px"); priv->lower = 0; priv->upper = 0; priv->position = 0; @@ -1071,15 +1071,15 @@ sp_ruler_remove_track_widget (SPRuler *ruler, */ void sp_ruler_set_unit (SPRuler *ruler, - const Inkscape::Util::Unit &unit) + Inkscape::Util::Unit const *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 = new Inkscape::Util::Unit(unit); + priv->unit = unit; g_object_notify(G_OBJECT(ruler), "unit"); gtk_widget_queue_draw (GTK_WIDGET (ruler)); @@ -1092,7 +1092,7 @@ sp_ruler_set_unit (SPRuler *ruler, * * Return value: the unit currently used in the @ruler widget. **/ -Inkscape::Util::Unit* +Inkscape::Util::Unit const* sp_ruler_get_unit (SPRuler *ruler) { return SP_RULER_GET_PRIVATE (ruler)->unit; @@ -1182,7 +1182,7 @@ sp_ruler_draw_ticks (SPRuler *ruler) gint text_size; gint pos; gdouble max_size; - Inkscape::Util::Unit *unit; + Inkscape::Util::Unit const *unit = NULL; SPRulerMetric ruler_metric = ruler_metric_general; /* The metric to use for this unit system */ PangoLayout *layout; PangoRectangle logical_rect, ink_rect; @@ -1298,7 +1298,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) == unit_table.getUnit("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++) @@ -1317,7 +1317,7 @@ sp_ruler_draw_ticks (SPRuler *ruler) gdouble subd_incr; /* hack to get proper subdivisions at full pixels */ - if (*unit == unit_table.getUnit("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 08760f584..ed529d082 100644 --- a/src/widgets/ruler.h +++ b/src/widgets/ruler.h @@ -56,8 +56,8 @@ void sp_ruler_remove_track_widget (SPRuler *ruler, GtkWidget *widget); void sp_ruler_set_unit (SPRuler *ruler, - const Inkscape::Util::Unit &unit); -Inkscape::Util::Unit *sp_ruler_get_unit (SPRuler *ruler); + const Inkscape::Util::Unit *unit); +Inkscape::Util::Unit const * sp_ruler_get_unit (SPRuler *ruler); void sp_ruler_set_position (SPRuler *ruler, gdouble set_position); gdouble sp_ruler_get_position (SPRuler *ruler); diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index 590b0867f..58d7134b3 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -80,7 +80,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<UnitTracker*>(g_object_get_data(G_OBJECT(spw), "tracker")); - Unit const unit = tracker->getActiveUnit(); + Unit const *unit = tracker->getActiveUnit(); struct { char const *key; double val; } const keyval[] = { { "X", bbox->min()[X] }, @@ -89,8 +89,8 @@ sp_selection_layout_widget_update(SPWidget *spw, Inkscape::Selection *sel) { "height", bbox->dimensions()[Y] } }; - if (unit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) { - double const val = unit.factor * 100; + if (unit->type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) { + 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); @@ -185,14 +185,14 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, SPWidget *spw) gdouble y1 = 0; gdouble xrel = 0; gdouble yrel = 0; - Unit 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.type == Inkscape::Util::UNIT_TYPE_LINEAR) { + 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"); @@ -200,13 +200,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) / 100 / 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) / 100 / 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) / (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]; } @@ -227,7 +227,7 @@ 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.type == Inkscape::Util::UNIT_TYPE_LINEAR) { + 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); diff --git a/src/widgets/sp-widget.cpp b/src/widgets/sp-widget.cpp index 7876f0454..0e2295e36 100644 --- a/src/widgets/sp-widget.cpp +++ b/src/widgets/sp-widget.cpp @@ -183,7 +183,7 @@ void SPWidgetImpl::dispose(GObject *object) if (spw->inkscape) { // Disconnect signals - // the checks are necessary because when destroy is caused by the the program shutting down, + // the checks are necessary because when destroy is caused by the program shutting down, // the inkscape object may already be (partly?) invalid --bb if (G_IS_OBJECT(spw->inkscape) && G_OBJECT_GET_CLASS(spw->inkscape)) { sp_signal_disconnect_by_data(spw->inkscape, spw); diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index a0b638031..d140cfb21 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -147,7 +147,8 @@ StrokeStyle::StrokeStyle() : selectModifiedConn(), startMarkerConn(), midMarkerConn(), - endMarkerConn() + endMarkerConn(), + _old_unit(NULL) { Gtk::HBox *hb; Gtk::HBox *f = new Gtk::HBox(false, 0); @@ -199,12 +200,12 @@ StrokeStyle::StrokeStyle() : Gtk::Widget *us = manage(unitSelector); SPDesktop *desktop = SP_ACTIVE_DESKTOP; - unitSelector->addUnit(unit_table.getUnit("%")); + unitSelector->addUnit(*unit_table.getUnit("%")); + _old_unit = unitSelector->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 = 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)); @@ -529,12 +530,12 @@ void StrokeStyle::updateMarkerHist(SPMarkerLoc const which) */ void StrokeStyle::unitChangedCB() { - Inkscape::Util::Unit new_unit = unitSelector->getUnit(); - if (new_unit.type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) { + Inkscape::Util::Unit const *new_unit = unitSelector->getUnit(); + if (new_unit->type == Inkscape::Util::UNIT_TYPE_DIMENSIONLESS) { widthSpin->set_value(100); } - widthSpin->set_value(Inkscape::Util::Quantity::convert(widthSpin->get_value(), *_old_unit, new_unit)); - _old_unit = new Inkscape::Util::Unit(new_unit); + widthSpin->set_value(Inkscape::Util::Quantity::convert(widthSpin->get_value(), _old_unit, new_unit)); + _old_unit = new_unit; } /** @@ -824,21 +825,20 @@ StrokeStyle::updateLine() } else { table->set_sensitive(true); - Inkscape::Util::Unit const *unit = new Inkscape::Util::Unit(unitSelector->getUnit()); - if (result_sw == QUERY_STYLE_MULTIPLE_AVERAGED) { unitSelector->setUnit("%"); } else { // same width, or only one object; no sense to keep percent, switch to absolute - if (unit->type != Inkscape::Util::UNIT_TYPE_LINEAR) { + Inkscape::Util::Unit const *tempunit = unitSelector->getUnit(); + if (tempunit->type != Inkscape::Util::UNIT_TYPE_LINEAR) { unitSelector->setUnit(sp_desktop_namedview(SP_ACTIVE_DESKTOP)->doc_units->abbr); } } - unit = new Inkscape::Util::Unit(unitSelector->getUnit()); + Inkscape::Util::Unit const *unit = unitSelector->getUnit(); if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { - double avgwidth = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", *unit); + double avgwidth = Inkscape::Util::Quantity::convert(query->stroke_width.computed, "px", unit); #if WITH_GTKMM_3_0 (*widthAdj)->set_value(avgwidth); #else @@ -964,7 +964,7 @@ StrokeStyle::scaleLine() double const miterlimit = miterLimitAdj->get_value(); #endif - Inkscape::Util::Unit const *const unit = new Inkscape::Util::Unit(unitSelector->getUnit()); + Inkscape::Util::Unit const *const unit = unitSelector->getUnit(); double *dash, offset; int ndash; @@ -974,7 +974,7 @@ StrokeStyle::scaleLine() /* Set stroke width */ double width; if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { - width = Inkscape::Util::Quantity::convert(width_typed, *unit, "px"); + 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; diff --git a/src/widgets/stroke-style.h b/src/widgets/stroke-style.h index 440881c6d..6f0fe583b 100644 --- a/src/widgets/stroke-style.h +++ b/src/widgets/stroke-style.h @@ -214,7 +214,7 @@ private: sigc::connection endMarkerConn; sigc::connection unitChangedConn; - Inkscape::Util::Unit *_old_unit; + Inkscape::Util::Unit const *_old_unit; }; } // namespace Inkscape |
