From 4d9dc443915f588d2e3de8dbc9b61ba1cf2e6dee Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Sat, 6 Jul 2013 02:09:21 -0400 Subject: Fix verbs that were out by 5 because of missing script verbs (broken between r7137-r11611) (bzr r12406) --- src/verbs.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/verbs.cpp b/src/verbs.cpp index 1dae8bcf0..d0396155c 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -2903,7 +2903,17 @@ Verb *Verb::_base_verbs[] = { N_("Link an ICC color profile"), NULL), new EditVerb(SP_VERB_EDIT_REMOVE_COLOR_PROFILE, "RemoveColorProfile", N_("Remove Color Profile"), N_("Remove a linked ICC color profile"), NULL), - + // Scripting + new ContextVerb(SP_VERB_EDIT_ADD_EXTERNAL_SCRIPT, "AddExternalScript", + N_("Add External Script"), N_("Add an external script"), NULL), + new ContextVerb(SP_VERB_EDIT_ADD_EMBEDDED_SCRIPT, "AddEmbeddedScript", + N_("Add Embedded Script"), N_("Add an embedded script"), NULL), + new ContextVerb(SP_VERB_EDIT_EMBEDDED_SCRIPT, "EditEmbeddedScript", + N_("Edit Embedded Script"), N_("Edit an embedded script"), NULL), + new ContextVerb(SP_VERB_EDIT_REMOVE_EXTERNAL_SCRIPT, "RemoveExternalScript", + N_("Remove External Script"), N_("Remove an external script"), NULL), + new ContextVerb(SP_VERB_EDIT_REMOVE_EMBEDDED_SCRIPT, "RemoveEmbeddedScript", + N_("Remove Embedded Script"), N_("Remove an embedded script"), NULL), // Align new ContextVerb(SP_VERB_ALIGN_HORIZONTAL_RIGHT_TO_ANCHOR, "AlignHorizontalRightToAnchor", N_("Align right edges of objects to the left edge of the anchor"), N_("Align right edges of objects to the left edge of the anchor"), INKSCAPE_ICON("align-horizontal-right-to-anchor")), -- cgit v1.2.3 From 2a5484afeb64207849e1dcdd9336fd4b0aaab06b Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sat, 6 Jul 2013 11:19:17 +0100 Subject: Fix build failure with GDL >= 3.6 Fixed bugs: - https://launchpad.net/bugs/1196070 (bzr r12407) --- src/ui/widget/dock.cpp | 20 ++++++++++++++++---- src/ui/widget/dock.h | 10 +++++----- 2 files changed, 21 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/ui/widget/dock.cpp b/src/ui/widget/dock.cpp index 2bfc7e0df..52e9ea605 100644 --- a/src/ui/widget/dock.cpp +++ b/src/ui/widget/dock.cpp @@ -48,11 +48,21 @@ const int Dock::_default_dock_bar_width = 36; Dock::Dock(Gtk::Orientation orientation) - : _gdl_dock (GDL_DOCK (gdl_dock_new())), - _gdl_dock_bar (GDL_DOCK_BAR (gdl_dock_bar_new(GDL_DOCK(_gdl_dock)))), + : _gdl_dock(gdl_dock_new()), +#if WITH_GDL_3_6 + _gdl_dock_bar(GDL_DOCK_BAR(gdl_dock_bar_new(G_OBJECT(_gdl_dock)))), +#else + _gdl_dock_bar(GDL_DOCK_BAR(gdl_dock_bar_new(GDL_DOCK(_gdl_dock)))), +#endif _scrolled_window (Gtk::manage(new Gtk::ScrolledWindow)) { - gdl_dock_bar_set_orientation(_gdl_dock_bar, static_cast(orientation)); +#if WITH_GDL_3_6 + gtk_orientable_set_orientation(GTK_ORIENTABLE(_gdl_dock_bar), + static_cast(orientation)); +#else + gdl_dock_bar_set_orientation(_gdl_dock_bar, + static_cast(orientation)); +#endif #if WITH_GTKMM_3_0 switch(orientation) { @@ -127,7 +137,9 @@ Dock::~Dock() void Dock::addItem(DockItem& item, DockItem::Placement placement) { _dock_items.push_back(&item); - gdl_dock_add_item(_gdl_dock, GDL_DOCK_ITEM(item.gobj()), (GdlDockPlacement)placement); + gdl_dock_add_item(GDL_DOCK(_gdl_dock), + GDL_DOCK_ITEM(item.gobj()), + (GdlDockPlacement)placement); // FIXME: This is a hack to prevent the dock from expanding the main window, this can't be done // initially as the paned doesn't exist. diff --git a/src/ui/widget/dock.h b/src/ui/widget/dock.h index 611c10f46..33e60b836 100644 --- a/src/ui/widget/dock.h +++ b/src/ui/widget/dock.h @@ -74,11 +74,11 @@ protected: /** Interface widgets, will be packed like * _scrolled_window -> (_dock_box -> (_paned -> (_dock -> _filler) | _dock_bar)) */ - Gtk::Box *_dock_box; - Gtk::Paned* _paned; - GdlDock *_gdl_dock; - GdlDockBar *_gdl_dock_bar; - Gtk::VBox _filler; + Gtk::Box *_dock_box; + Gtk::Paned *_paned; + GtkWidget *_gdl_dock; + GdlDockBar *_gdl_dock_bar; + Gtk::VBox _filler; Gtk::ScrolledWindow *_scrolled_window; /** Internal signal handlers */ -- cgit v1.2.3 From c2476065a96485c282da32a8859ef8c5617b5b7d Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Sun, 7 Jul 2013 10:12:44 -0400 Subject: Make colour a guint instead of a uint. bug 1198501 Fixed bugs: - https://launchpad.net/bugs/1198501 (bzr r12408) --- src/seltrans.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/seltrans.h b/src/seltrans.h index 880f30c94..67d581471 100644 --- a/src/seltrans.h +++ b/src/seltrans.h @@ -71,6 +71,7 @@ public: gboolean skewRequest(SPSelTransHandle const &handle, Geom::Point &pt, guint state); gboolean rotateRequest(Geom::Point &pt, guint state); gboolean centerRequest(Geom::Point &pt, guint state); + void alignClick(SPSelTransHandle const &handle); gboolean handleRequest(SPKnot *knot, Geom::Point *position, guint state, SPSelTransHandle const &handle); void handleGrab(SPKnot *knot, guint state, SPSelTransHandle const &handle); @@ -130,6 +131,7 @@ private: }; SPDesktop *_desktop; + SPCanvasItem *aguide; std::vector _items; std::vector _items_const; @@ -180,7 +182,7 @@ private: bool _center_is_set; ///< we've already set _center, no need to reread it from items int _center_handle; - SPKnot *knots[17]; + SPKnot *knots[NUMHANDS]; SPCanvasItem *_norm; SPCanvasItem *_grip; SPCtrlLine *_l[4]; -- cgit v1.2.3 From a48ec17933088b745b16a0903ef00bd5a9366a71 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Mon, 8 Jul 2013 07:40:48 -0400 Subject: Revert wrong changes and apply right fixes from prev-commit (bzr r12409) --- src/seltrans-handles.h | 2 +- src/seltrans.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/seltrans-handles.h b/src/seltrans-handles.h index 5c3fdd269..740729a6e 100644 --- a/src/seltrans-handles.h +++ b/src/seltrans-handles.h @@ -33,7 +33,7 @@ enum SPSelTransType { }; struct SPSelTransTypeInfo { - uint const *color; + guint32 const *color; gchar const *tip; }; // One per handle type in order diff --git a/src/seltrans.h b/src/seltrans.h index 67d581471..d97375520 100644 --- a/src/seltrans.h +++ b/src/seltrans.h @@ -71,7 +71,6 @@ public: gboolean skewRequest(SPSelTransHandle const &handle, Geom::Point &pt, guint state); gboolean rotateRequest(Geom::Point &pt, guint state); gboolean centerRequest(Geom::Point &pt, guint state); - void alignClick(SPSelTransHandle const &handle); gboolean handleRequest(SPKnot *knot, Geom::Point *position, guint state, SPSelTransHandle const &handle); void handleGrab(SPKnot *knot, guint state, SPSelTransHandle const &handle); @@ -131,7 +130,6 @@ private: }; SPDesktop *_desktop; - SPCanvasItem *aguide; std::vector _items; std::vector _items_const; -- cgit v1.2.3 From c56584bdf7c95b528d1b8016a0b4009f8b829dab Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Tue, 9 Jul 2013 21:34:33 +0200 Subject: Fix for Bug #1185132 (colorspace.h not included in the tarball when doing a make dist) by Ryan Lerch. Fixed bugs: - https://launchpad.net/bugs/1185132 (bzr r12410) --- src/Makefile_insert | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/Makefile_insert b/src/Makefile_insert index 023d640ca..88f809b52 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -21,6 +21,7 @@ ink_common_sources += \ color-profile.cpp color-profile.h \ color-profile-cms-fns.h \ color-rgba.h \ + colorspace.h \ common-context.cpp common-context.h \ composite-undo-stack-observer.cpp \ composite-undo-stack-observer.h \ -- cgit v1.2.3 From 4d232a223d1dcb7b2381615de1a64b20b2fb6165 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Tue, 9 Jul 2013 20:46:51 -0400 Subject: Small refactor of align and distribute to reduce complexity. (bzr r12411) --- src/document.cpp | 5 +++ src/document.h | 1 + src/ui/dialog/align-and-distribute.cpp | 59 ++++++++++------------------------ 3 files changed, 23 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/document.cpp b/src/document.cpp index 706710cfc..0e9c43fe4 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -611,6 +611,11 @@ Geom::Point SPDocument::getDimensions() const return Geom::Point(getWidth(), getHeight()); } +Geom::OptRect SPDocument::preferredBounds() const +{ + return Geom::OptRect( Geom::Point(0, 0), getDimensions() ); +} + /** * Given a Geom::Rect that may, for example, correspond to the bbox of an object, * this function fits the canvas to that rect by resizing the canvas diff --git a/src/document.h b/src/document.h index 606a83be8..d49067250 100644 --- a/src/document.h +++ b/src/document.h @@ -228,6 +228,7 @@ public: gdouble getWidth() const; gdouble getHeight() const; Geom::Point getDimensions() const; + Geom::OptRect preferredBounds() const; void setWidth(gdouble width, const SPUnit *unit); void setHeight(gdouble height, const SPUnit *unit); void requestModified(); diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index 7f88824f7..6a1cfc0ba 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -88,23 +88,23 @@ Action::Action(const Glib::ustring &id, } -void ActionAlign::do_action(SPDesktop *desktop, int index) { - +void ActionAlign::do_action(SPDesktop *desktop, int index) +{ Inkscape::Selection *selection = sp_desktop_selection(desktop); if (!selection) return; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool sel_as_group = prefs->getBool("/dialogs/align/sel-as-groups"); - int prefs_bbox = prefs->getBool("/tools/bounding_box"); using Inkscape::Util::GSListConstIterator; std::list selected; selected.insert >(selected.end(), selection->itemList(), NULL); if (selected.empty()) return; - Geom::Point mp; //Anchor point + const Coeffs &a = _allCoeffs[index]; + Geom::OptRect b = Geom::OptRect(); AlignAndDistribute::AlignTarget target = AlignAndDistribute::getAlignTarget(); - const Coeffs &a= _allCoeffs[index]; + switch (target) { case AlignAndDistribute::LAST: @@ -132,51 +132,27 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) { /*if (!sel_as_group) { */ selected.erase(master); /*}*/ - //Compute the anchor point - Geom::OptRect b = !prefs_bbox ? thing->desktopVisualBounds() : thing->desktopGeometricBounds(); - if (b) { - mp = Geom::Point(a.mx0 * b->min()[Geom::X] + a.mx1 * b->max()[Geom::X], - a.my0 * b->min()[Geom::Y] + a.my1 * b->max()[Geom::Y]); - } else { - return; - } + b = thing->desktopPreferredBounds(); break; } - case AlignAndDistribute::PAGE: - mp = Geom::Point(a.mx1 * sp_desktop_document(desktop)->getWidth(), - a.my1 * sp_desktop_document(desktop)->getHeight()); + b = sp_desktop_document(desktop)->preferredBounds(); break; - case AlignAndDistribute::DRAWING: - { - Geom::OptRect b = !prefs_bbox ? sp_desktop_document(desktop)->getRoot()->desktopVisualBounds() - : sp_desktop_document(desktop)->getRoot()->desktopGeometricBounds(); - if (b) { - mp = Geom::Point(a.mx0 * b->min()[Geom::X] + a.mx1 * b->max()[Geom::X], - a.my0 * b->min()[Geom::Y] + a.my1 * b->max()[Geom::Y]); - } else { - return; - } + b = sp_desktop_document(desktop)->getRoot()->desktopPreferredBounds(); break; - } - case AlignAndDistribute::SELECTION: - { - Geom::OptRect b = !prefs_bbox ? selection->visualBounds() : selection->geometricBounds(); - if (b) { - mp = Geom::Point(a.mx0 * b->min()[Geom::X] + a.mx1 * b->max()[Geom::X], - a.my0 * b->min()[Geom::Y] + a.my1 * b->max()[Geom::Y]); - } else { - return; - } + b = selection->preferredBounds(); break; - } - default: g_assert_not_reached (); break; - }; // end of switch + }; + + g_return_if_fail(b); + + Geom::Point mp = Geom::Point(a.mx0 * b->min()[Geom::X] + a.mx1 * b->max()[Geom::X], + a.my0 * b->min()[Geom::Y] + a.my1 * b->max()[Geom::Y]); // Top hack: temporarily set clone compensation to unmoved, so that we can align/distribute // clones with their original (and the move of the original does not disturb the @@ -188,9 +164,8 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) { prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); bool changed = false; - Geom::OptRect b; if (sel_as_group) - b = !prefs_bbox ? selection->visualBounds() : selection->geometricBounds(); + b = selection->preferredBounds(); //Move each item in the selected list separately for (std::list::iterator it(selected.begin()); @@ -199,7 +174,7 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) { { sp_desktop_document (desktop)->ensureUpToDate(); if (!sel_as_group) - b = !prefs_bbox ? (*it)->desktopVisualBounds() : (*it)->desktopGeometricBounds(); + b = (*it)->desktopPreferredBounds(); if (b) { Geom::Point const sp(a.sx0 * b->min()[Geom::X] + a.sx1 * b->max()[Geom::X], a.sy0 * b->min()[Geom::Y] + a.sy1 * b->max()[Geom::Y]); -- cgit v1.2.3 From bea3d29ac007d6c8faca786538fafb0d7d789ffc Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Wed, 10 Jul 2013 11:50:45 +0100 Subject: Added "dbus-name" command line option to allow a D-Bus bus name other than "org.inkscape" to be specified. This allows multiple Inkscape instances to be controlled over D-Bus in a single user session. (bzr r12402.1.1) --- src/extension/dbus/dbus-init.cpp | 29 ++++++++++++++++++++-- src/extension/dbus/dbus-init.h | 10 ++++++++ src/extension/dbus/document-interface.h | 3 --- src/extension/dbus/wrapper/inkscape-dbus-wrapper.h | 2 -- src/main.cpp | 20 +++++++++++++++ 5 files changed, 57 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index eb62f4b3a..19b48e10d 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -36,7 +36,14 @@ #include - +namespace +{ + // This stores the bus name to use for this app instance. By default, it + // will be set to org.inkscape. However, users may provide other names by + // setting command-line parameters when starting Inkscape, so that more + // than one instance of Inkscape may be used by external scripts. + gchar *instance_bus_name = NULL; +} namespace Inkscape { namespace Extension { @@ -120,6 +127,11 @@ dbus_register_document(Inkscape::ActionContext const & target) void init (void) { + if (instance_bus_name == NULL) { + // Set the bus name to the default + instance_bus_name = strdup("org.inkscape"); + } + guint result; GError *error = NULL; DBusGConnection *connection; @@ -127,7 +139,7 @@ init (void) connection = dbus_get_connection(); proxy = dbus_get_proxy(connection); org_freedesktop_DBus_request_name (proxy, - "org.inkscape", + instance_bus_name, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); //create interface for application dbus_register_object (connection, @@ -198,6 +210,19 @@ init_desktop (void) { return strdup(name.c_str()); } +void +dbus_set_bus_name(gchar * bus_name) +{ + g_assert(bus_name != NULL); + g_assert(instance_bus_name == NULL); + instance_bus_name = strdup(bus_name); +} +gchar * +dbus_get_bus_name() +{ + g_assert(instance_bus_name != NULL); + return instance_bus_name; +} } } } /* namespace Inkscape::Extension::Dbus */ diff --git a/src/extension/dbus/dbus-init.h b/src/extension/dbus/dbus-init.h index 486e55b86..7862ad3c3 100644 --- a/src/extension/dbus/dbus-init.h +++ b/src/extension/dbus/dbus-init.h @@ -28,6 +28,16 @@ gchar * init_desktop (void); gchar * dbus_init_desktop_interface (SPDesktop * dt); +/** Set the bus name to use. Default is "org.inkscape". + This function should only be called once, before init(), if a non-default + bus name is required. */ +void dbus_set_bus_name(gchar * bus_name); + +/** Get the bus name for this instance. Default is "org.inkscape". + This function should only be called after init(). + The returned gchar * is owned by this module and should not be freed. */ +gchar * dbus_get_bus_name(); + } } } /* namespace Dbus, Extension, Inkscape */ #endif /* INKSCAPE_EXTENSION_DBUS_INIT_H__ */ diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index 00d964f36..27460de52 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -34,9 +34,6 @@ class SPDesktop; class SPItem; - -// TODO: this define doesn't seem to be used... although the path itself is also hardcoded in dbus-init.cpp -#define DBUS_DOCUMENT_INTERFACE_PATH "/org/inkscape/document" #define TYPE_DOCUMENT_INTERFACE (document_interface_get_type ()) #define DOCUMENT_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TYPE_DOCUMENT_INTERFACE, DocumentInterface)) diff --git a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h index 79f8188d4..20830bd65 100644 --- a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h +++ b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h @@ -8,8 +8,6 @@ //#include //#include - -#define DBUS_DOCUMENT_INTERFACE_PATH "/org/inkscape/document" #define TYPE_DOCUMENT_INTERFACE (document_interface_get_type ()) #define DOCUMENT_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TYPE_DOCUMENT_INTERFACE, DocumentInterface)) diff --git a/src/main.cpp b/src/main.cpp index ba51951da..4e2f2fd2b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -103,6 +103,11 @@ #endif // WIN32 #include "extension/init.h" +// Not ideal, but there doesn't appear to be a nicer system in place for +// passing command-line parameters to extensions before initialization... +#ifdef WITH_DBUS +#include "extension/dbus/dbus-init.h" +#endif // WITH_DBUS #include #include @@ -171,6 +176,7 @@ enum { SP_ARG_VACUUM_DEFS, #ifdef WITH_DBUS SP_ARG_DBUS_LISTEN, + SP_ARG_DBUS_NAME, #endif // WITH_DBUS SP_ARG_VERB_LIST, SP_ARG_VERB, @@ -227,6 +233,7 @@ static gboolean sp_shell = FALSE; static gboolean sp_vacuum_defs = FALSE; #ifdef WITH_DBUS static gboolean sp_dbus_listen = FALSE; +static gchar *sp_dbus_name = NULL; #endif // WITH_DBUS static gchar *sp_export_png_utf8 = NULL; static gchar *sp_export_svg_utf8 = NULL; @@ -274,6 +281,7 @@ static void resetCommandlineGlobals() { sp_vacuum_defs = FALSE; #ifdef WITH_DBUS sp_dbus_listen = FALSE; + sp_dbus_name = NULL; #endif // WITH_DBUS sp_export_png_utf8 = NULL; @@ -487,6 +495,11 @@ struct poptOption options[] = { POPT_ARG_NONE, &sp_dbus_listen, SP_ARG_DBUS_LISTEN, N_("Enter a listening loop for D-Bus messages in console mode"), NULL}, + + {"dbus-name", 0, + POPT_ARG_STRING, &sp_dbus_name, SP_ARG_DBUS_NAME, + N_("Specify the D-Bus bus name to listen for messages on (default is org.inkscape)"), + N_("BUS-NAME")}, #endif // WITH_DBUS {"verb-list", 0, @@ -885,6 +898,13 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest ) if ( sp_global_printer ) sp_global_printer_utf8 = g_strdup( sp_global_printer ); } + +#ifdef WITH_DBUS + // Before initializing extensions, we must set the DBus bus name if required + if (sp_dbus_name != NULL) { + Inkscape::Extension::Dbus::dbus_set_bus_name(sp_dbus_name); + } +#endif // Return the list if wanted, else free it up. if ( flDest ) { -- cgit v1.2.3 From 80a911db81b651f38205c1eb926af4986bc033e8 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 10 Jul 2013 22:24:38 -0400 Subject: Step 2 refactoring the align functions, added some functionality to selection. (bzr r12413) --- src/selection.cpp | 30 ++++++++ src/selection.h | 18 +++++ src/ui/dialog/align-and-distribute.cpp | 127 +++++---------------------------- src/ui/dialog/align-and-distribute.h | 10 +-- 4 files changed, 68 insertions(+), 117 deletions(-) (limited to 'src') diff --git a/src/selection.cpp b/src/selection.cpp index d018aba0c..83caaf459 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -42,6 +42,7 @@ namespace Inkscape { Selection::Selection(LayerModel *layers, SPDesktop *desktop) : + align_point(NULL), _objs(NULL), _reprs(NULL), _items(NULL), @@ -358,6 +359,35 @@ SPItem *Selection::singleItem() { } } +SPItem *Selection::smallestItem(Selection::CompareSize compare) { + return _sizeistItem(true, compare); +} + +SPItem *Selection::largestItem(Selection::CompareSize compare) { + return _sizeistItem(false, compare); +} + +SPItem *Selection::_sizeistItem(bool small, Selection::CompareSize compare) { + GSList const *items = const_cast(this)->itemList(); + gdouble max = small ? 1e18 : 0; + SPItem *ist = NULL; + + for ( GSList const *i = items; i != NULL ; i = i->next ) { + Geom::OptRect bbox = SP_ITEM(i->data)->desktopPreferredBounds(); + if (!bbox) continue; + + gdouble size = compare == 2 ? + (*bbox)[Geom::X].extent() * (*bbox)[Geom::Y].extent() : + (*bbox)[compare == 1 ? Geom::X : Geom::Y].extent(); + size = small ? size : size * -1; + if (size < max) { + max = size; + ist = SP_ITEM(i->data); + } + } + return ist; +} + Inkscape::XML::Node *Selection::singleRepr() { SPObject *obj=single(); return obj ? obj->getRepr() : NULL; diff --git a/src/selection.h b/src/selection.h index f076cf7aa..25c018f7b 100644 --- a/src/selection.h +++ b/src/selection.h @@ -27,6 +27,7 @@ #include "sp-item.h" #include "snapped-point.h" + class SPDesktop; class SPItem; class SPBox3D; @@ -63,6 +64,7 @@ class Selection : public Inkscape::GC::Managed<>, public Inkscape::GC::Anchored { public: + enum CompareSize { HORIZONTAL, VERTICAL, AREA }; /** * Constructs an selection object, bound to a particular * layer model @@ -219,6 +221,16 @@ public: */ SPItem *singleItem(); + /** + * Returns the smallest item from this selection. + */ + SPItem *smallestItem(CompareSize compare); + + /** + * Returns the largest item from this selection. + */ + SPItem *largestItem(CompareSize compare); + /** * Returns a single selected object's xml node. * @@ -308,6 +320,11 @@ public: return _modified_signal.connect(slot); } + /** + * Selection wants to be aligned to this point, not bbox + */ + Geom::Point *align_point; + private: /** no copy. */ Selection(Selection const &); @@ -349,6 +366,7 @@ private: void add_3D_boxes_recursively(SPObject *obj); void remove_box_perspective(SPBox3D *box); void remove_3D_boxes_recursively(SPObject *obj); + SPItem *_sizeistItem(bool small, CompareSize compare); std::list _3dboxes; diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index 6a1cfc0ba..ed3f3adce 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -103,45 +103,30 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) const Coeffs &a = _allCoeffs[index]; Geom::OptRect b = Geom::OptRect(); - AlignAndDistribute::AlignTarget target = AlignAndDistribute::getAlignTarget(); + Selection::CompareSize horiz = (a.mx0 != 0.0) || (a.mx1 != 0.0) + ? Selection::HORIZONTAL : Selection::VERTICAL; - switch (target) + switch (AlignTarget(prefs->getInt("/dialogs/align/align-to", 6))) { - case AlignAndDistribute::LAST: - case AlignAndDistribute::FIRST: - case AlignAndDistribute::BIGGEST: - case AlignAndDistribute::SMALLEST: - { - //Check 2 or more selected objects - std::list::iterator second(selected.begin()); - ++second; - if (second == selected.end()) - return; - //Find the master (anchor on which the other objects are aligned) - std::list::iterator master( - AlignAndDistribute::find_master ( - selected, - (a.mx0 != 0.0) || - (a.mx1 != 0.0) ) - ); - //remove the master from the selection - SPItem * thing = *master; - // TODO: either uncomment or remove the following commented lines, depending on which - // behaviour of moving objects makes most sense; also cf. discussion at - // https://bugs.launchpad.net/inkscape/+bug/255933 - /*if (!sel_as_group) { */ - selected.erase(master); - /*}*/ - b = thing->desktopPreferredBounds(); + case LAST: + b = SP_ITEM(*selected.begin())->desktopPreferredBounds(); break; - } - case AlignAndDistribute::PAGE: + case FIRST: + b = SP_ITEM(*--(selected.end()))->desktopPreferredBounds(); + break; + case BIGGEST: + b = selection->largestItem(horiz)->desktopPreferredBounds(); + break; + case SMALLEST: + b = selection->smallestItem(horiz)->desktopPreferredBounds(); + break; + case PAGE: b = sp_desktop_document(desktop)->preferredBounds(); break; - case AlignAndDistribute::DRAWING: + case DRAWING: b = sp_desktop_document(desktop)->getRoot()->desktopPreferredBounds(); break; - case AlignAndDistribute::SELECTION: + case SELECTION: b = selection->preferredBounds(); break; default: @@ -151,18 +136,10 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) g_return_if_fail(b); + // Generate the move point from the selected bounding box Geom::Point mp = Geom::Point(a.mx0 * b->min()[Geom::X] + a.mx1 * b->max()[Geom::X], a.my0 * b->min()[Geom::Y] + a.my1 * b->max()[Geom::Y]); - // Top hack: temporarily set clone compensation to unmoved, so that we can align/distribute - // clones with their original (and the move of the original does not disturb the - // clones). The only problem with this is that if there are outside-of-selection clones of - // a selected original, they will be unmoved too, possibly contrary to user's - // expecation. However this is a minor point compared to making align/distribute always - // work as expected, and "unmoved" is the default option anyway. - int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - bool changed = false; if (sel_as_group) b = selection->preferredBounds(); @@ -186,15 +163,10 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) } } - // restore compensation setting - prefs->setInt("/options/clonecompensation/value", saved_compensation); - if (changed) { DocumentUndo::done( sp_desktop_document(desktop) , SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Align")); } - - } @@ -1240,69 +1212,6 @@ void AlignAndDistribute::addBaselineButton(const Glib::ustring &id, const Glib:: *this, table, orientation, distribute)); } - - - -std::list::iterator AlignAndDistribute::find_master( std::list &list, bool horizontal){ - std::list::iterator master = list.end(); - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - int prefs_bbox = prefs->getBool("/tools/bounding_box"); - switch (getAlignTarget()) { - case LAST: - return list.begin(); - break; - - case FIRST: - return --(list.end()); - break; - - case BIGGEST: - { - gdouble max = -1e18; - for (std::list::iterator it = list.begin(); it != list.end(); ++it) { - Geom::OptRect b = !prefs_bbox ? (*it)->desktopVisualBounds() : (*it)->desktopGeometricBounds(); - if (b) { - gdouble dim = (*b)[horizontal ? Geom::X : Geom::Y].extent(); - if (dim > max) { - max = dim; - master = it; - } - } - } - return master; - } - - case SMALLEST: - { - gdouble max = 1e18; - for (std::list::iterator it = list.begin(); it != list.end(); ++it) { - Geom::OptRect b = !prefs_bbox ? (*it)->desktopVisualBounds() : (*it)->desktopGeometricBounds(); - if (b) { - gdouble dim = (*b)[horizontal ? Geom::X : Geom::Y].extent(); - if (dim < max) { - max = dim; - master = it; - } - } - } - return master; - } - - default: - g_assert_not_reached (); - break; - - } // end of switch statement - return master; -} - -AlignAndDistribute::AlignTarget AlignAndDistribute::getAlignTarget() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - return AlignTarget(prefs->getInt("/dialogs/align/align-to", 6)); -} - - - } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/dialog/align-and-distribute.h b/src/ui/dialog/align-and-distribute.h index c9165a83e..dfd84535b 100644 --- a/src/ui/dialog/align-and-distribute.h +++ b/src/ui/dialog/align-and-distribute.h @@ -47,12 +47,6 @@ public: static AlignAndDistribute &getInstance() { return *new AlignAndDistribute(); } - enum AlignTarget { LAST=0, FIRST, BIGGEST, SMALLEST, PAGE, DRAWING, SELECTION }; - - - - static AlignTarget getAlignTarget(); - #if WITH_GTKMM_3_0 Gtk::Grid &align_table(){return _alignTable;} Gtk::Grid &distribute_table(){return _distributeTable;} @@ -67,7 +61,6 @@ public: Gtk::Table &nodes_table(){return _nodesTable;} #endif - static std::list::iterator find_master(std::list &list, bool horizontal); void setMode(bool nodeEdit); Geom::OptRect randomize_bbox; @@ -189,6 +182,7 @@ public : double sx0, sx1, sy0, sy1; int verb_id; }; + enum AlignTarget { LAST=0, FIRST, BIGGEST, SMALLEST, PAGE, DRAWING, SELECTION }; ActionAlign(const Glib::ustring &id, const Glib::ustring &tiptext, guint row, guint column, @@ -204,6 +198,7 @@ public : * Static function called to align from a keyboard shortcut */ static void do_verb_action(SPDesktop *desktop, int verb); + static int verb_to_coeff(int verb); private : @@ -217,7 +212,6 @@ private : } static void do_action(SPDesktop *desktop, int index); - static int verb_to_coeff(int verb); guint _index; AlignAndDistribute &_dialog; -- cgit v1.2.3 From c3074d380bbdbd8ec8f17b9cfb3059119005a30b Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 10 Jul 2013 23:08:15 -0400 Subject: Remove align point, not required any more (bzr r12414) --- src/selection.cpp | 1 - src/selection.h | 5 ----- 2 files changed, 6 deletions(-) (limited to 'src') diff --git a/src/selection.cpp b/src/selection.cpp index 83caaf459..e66137f65 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -42,7 +42,6 @@ namespace Inkscape { Selection::Selection(LayerModel *layers, SPDesktop *desktop) : - align_point(NULL), _objs(NULL), _reprs(NULL), _items(NULL), diff --git a/src/selection.h b/src/selection.h index 25c018f7b..75351a4ff 100644 --- a/src/selection.h +++ b/src/selection.h @@ -320,11 +320,6 @@ public: return _modified_signal.connect(slot); } - /** - * Selection wants to be aligned to this point, not bbox - */ - Geom::Point *align_point; - private: /** no copy. */ Selection(Selection const &); -- cgit v1.2.3 From df87c3c1c14f2483a9dbfc8bf2ac69e9834a42bf Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Thu, 11 Jul 2013 06:41:25 -0400 Subject: Change small to sml to fix windows compile problem (bzr r12415) --- src/selection.cpp | 6 +++--- src/selection.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/selection.cpp b/src/selection.cpp index e66137f65..8f43d8e70 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -366,9 +366,9 @@ SPItem *Selection::largestItem(Selection::CompareSize compare) { return _sizeistItem(false, compare); } -SPItem *Selection::_sizeistItem(bool small, Selection::CompareSize compare) { +SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) { GSList const *items = const_cast(this)->itemList(); - gdouble max = small ? 1e18 : 0; + gdouble max = sml ? 1e18 : 0; SPItem *ist = NULL; for ( GSList const *i = items; i != NULL ; i = i->next ) { @@ -378,7 +378,7 @@ SPItem *Selection::_sizeistItem(bool small, Selection::CompareSize compare) { gdouble size = compare == 2 ? (*bbox)[Geom::X].extent() * (*bbox)[Geom::Y].extent() : (*bbox)[compare == 1 ? Geom::X : Geom::Y].extent(); - size = small ? size : size * -1; + size = sml ? size : size * -1; if (size < max) { max = size; ist = SP_ITEM(i->data); diff --git a/src/selection.h b/src/selection.h index 75351a4ff..32eade21f 100644 --- a/src/selection.h +++ b/src/selection.h @@ -361,7 +361,7 @@ private: void add_3D_boxes_recursively(SPObject *obj); void remove_box_perspective(SPBox3D *box); void remove_3D_boxes_recursively(SPObject *obj); - SPItem *_sizeistItem(bool small, CompareSize compare); + SPItem *_sizeistItem(bool sml, CompareSize compare); std::list _3dboxes; -- cgit v1.2.3 From f5692180123a550cfd6d1b8780ee23096418dd79 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Fri, 12 Jul 2013 12:08:13 -0400 Subject: Do not effect the focus in align computation Fixed bugs: - https://launchpad.net/bugs/1200649 (bzr r12416) --- src/ui/dialog/align-and-distribute.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index ed3f3adce..8845b60e5 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -102,6 +102,7 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) if (selected.empty()) return; const Coeffs &a = _allCoeffs[index]; + SPItem *focus = NULL; Geom::OptRect b = Geom::OptRect(); Selection::CompareSize horiz = (a.mx0 != 0.0) || (a.mx1 != 0.0) ? Selection::HORIZONTAL : Selection::VERTICAL; @@ -109,16 +110,16 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) switch (AlignTarget(prefs->getInt("/dialogs/align/align-to", 6))) { case LAST: - b = SP_ITEM(*selected.begin())->desktopPreferredBounds(); + focus = SP_ITEM(*selected.begin()); break; case FIRST: - b = SP_ITEM(*--(selected.end()))->desktopPreferredBounds(); + focus = SP_ITEM(*--(selected.end())); break; case BIGGEST: - b = selection->largestItem(horiz)->desktopPreferredBounds(); + focus = selection->largestItem(horiz); break; case SMALLEST: - b = selection->smallestItem(horiz)->desktopPreferredBounds(); + focus = selection->smallestItem(horiz); break; case PAGE: b = sp_desktop_document(desktop)->preferredBounds(); @@ -134,6 +135,8 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) break; }; + if(focus) + b = focus->desktopPreferredBounds(); g_return_if_fail(b); // Generate the move point from the selected bounding box @@ -146,13 +149,12 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) //Move each item in the selected list separately for (std::list::iterator it(selected.begin()); - it != selected.end(); - ++it) + it != selected.end(); ++it) { sp_desktop_document (desktop)->ensureUpToDate(); if (!sel_as_group) b = (*it)->desktopPreferredBounds(); - if (b) { + if (b && (!focus || (*it) != focus)) { Geom::Point const sp(a.sx0 * b->min()[Geom::X] + a.sx1 * b->max()[Geom::X], a.sy0 * b->min()[Geom::Y] + a.sy1 * b->max()[Geom::Y]); Geom::Point const mp_rel( mp - sp ); -- cgit v1.2.3 From ed6229c5b41b72df6c59878aaae328cb2b6e3559 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Fri, 12 Jul 2013 13:06:09 -0400 Subject: Use Jon Cruz info about OptRect to correctly get area height and width (bzr r12417) --- src/selection.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/selection.cpp b/src/selection.cpp index 8f43d8e70..784219c88 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -372,12 +372,12 @@ SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) { SPItem *ist = NULL; for ( GSList const *i = items; i != NULL ; i = i->next ) { - Geom::OptRect bbox = SP_ITEM(i->data)->desktopPreferredBounds(); - if (!bbox) continue; + Geom::OptRect obox = SP_ITEM(i->data)->desktopPreferredBounds(); + if (!obox || obox.isEmpty()) continue; + Geom::Rect bbox = *obox; - gdouble size = compare == 2 ? - (*bbox)[Geom::X].extent() * (*bbox)[Geom::Y].extent() : - (*bbox)[compare == 1 ? Geom::X : Geom::Y].extent(); + gdouble size = compare == 2 ? bbox.area() : + (compare == 1 ? bbox.width() : bbox.height()); size = sml ? size : size * -1; if (size < max) { max = size; -- cgit v1.2.3 From 44431062712056a395e0708b89f600a1ffb78343 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 13 Jul 2013 14:10:01 -0700 Subject: Whitespace cleanup. (bzr r12418) --- src/util/units.cpp | 158 ++++++++++++++++++++++++++--------------------------- 1 file changed, 79 insertions(+), 79 deletions(-) (limited to 'src') diff --git a/src/util/units.cpp b/src/util/units.cpp index f822d01de..002bf3b07 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -60,10 +60,10 @@ int Unit::defaultDigits() const { * * The primary unit's conversion factor is required to be 1.00 */ -UnitTable::UnitTable() +UnitTable::UnitTable() { // if we swich to the xml file, don't forget to force locale to 'C' - // load("share/ui/units.xml"); // <-- Buggy + // load("share/ui/units.xml"); // <-- Buggy gchar *filename = g_build_filename(INKSCAPE_UIDIR, "units.txt", NULL); loadText(filename); g_free(filename); @@ -72,8 +72,8 @@ UnitTable::UnitTable() UnitTable::~UnitTable() { UnitMap::iterator iter = _unit_map.begin(); while (iter != _unit_map.end()) { - delete (*iter).second; - ++iter; + delete (*iter).second; + ++iter; } } @@ -81,7 +81,7 @@ UnitTable::~UnitTable() { void UnitTable::addUnit(Unit const &u, bool primary) { _unit_map[u.abbr] = new Unit(u); if (primary) { - _primary_unit[u.type] = u.abbr; + _primary_unit[u.type] = u.abbr; } } @@ -89,26 +89,26 @@ void UnitTable::addUnit(Unit const &u, bool primary) { Unit UnitTable::getUnit(Glib::ustring const &unit_abbr) const { UnitMap::const_iterator iter = _unit_map.find(unit_abbr); if (iter != _unit_map.end()) { - return *((*iter).second); + return *((*iter).second); } else { - return Unit(); + return Unit(); } } /** Remove a unit definition from the given unit type table */ bool UnitTable::deleteUnit(Unit const &u) { if (u.abbr == _primary_unit[u.type]) { - // Cannot delete the primary unit type since it's - // used for conversions - return false; + // Cannot delete the primary unit type since it's + // used for conversions + return false; } UnitMap::iterator iter = _unit_map.find(u.abbr); if (iter != _unit_map.end()) { - delete (*iter).second; - _unit_map.erase(iter); - return true; + delete (*iter).second; + _unit_map.erase(iter); + return true; } else { - return false; + return false; } } @@ -125,9 +125,9 @@ 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)))); - } + if (((*iter).second)->type == type) { + submap.insert(UnitMap::value_type((*iter).first, new Unit(*((*iter).second)))); + } } return submap; @@ -140,10 +140,10 @@ Glib::ustring UnitTable::primary(UnitType type) const } /** Loads units from a text file. - + loadText loads and merges the contents of the given file into the UnitTable, possibly overwriting existing unit definitions. - + @param filename: file to be loaded*/ bool UnitTable::loadText(Glib::ustring const &filename) { @@ -152,11 +152,11 @@ bool UnitTable::loadText(Glib::ustring const &filename) // Open file for reading FILE * f = fopen(filename.c_str(), "r"); if (f == NULL) { - g_warning("Could not open units file '%s': %s\n", - filename.c_str(), strerror(errno)); + g_warning("Could not open units file '%s': %s\n", + filename.c_str(), strerror(errno)); g_warning("* INKSCAPE_DATADIR is: '%s'\n", INKSCAPE_DATADIR); g_warning("* INKSCAPE_UIDIR is: '%s'\n", INKSCAPE_UIDIR); - return false; + return false; } // bypass current locale in order to make @@ -167,51 +167,51 @@ bool UnitTable::loadText(Glib::ustring const &filename) setlocale (LC_NUMERIC, "C"); while (fgets(buf, BUFSIZE, f) != NULL) { - char name[BUFSIZE]; - char plural[BUFSIZE]; - char abbr[BUFSIZE]; - char type[BUFSIZE]; - double factor; - char primary[BUFSIZE]; - - int nchars = 0; - // locale is set to C, scanning %lf should work _everywhere_ - if (sscanf(buf, "%15s %15s %15s %15s %8lf %1s %15n", - name, plural, abbr, type, &factor, primary, &nchars) != 6) - { - // Skip the line - doesn't appear to be valid - continue; - } - - g_assert(nchars < BUFSIZE); - - char *desc = buf; - desc += nchars; // buf is now only the description - - // insert into _unit_map - Unit u; - u.name = name; - u.name_plural = plural; - u.abbr = abbr; - u.description = desc; - u.factor = factor; - - if (streq(type, "DIMENSIONLESS")) { - u.type = UNIT_TYPE_DIMENSIONLESS; - } else if (streq(type, "LINEAR")) { - u.type = UNIT_TYPE_LINEAR; - } else if (streq(type, "RADIAL")) { - u.type = UNIT_TYPE_RADIAL; - } else if (streq(type, "FONT_HEIGHT")) { - u.type = UNIT_TYPE_FONT_HEIGHT; - } else { - g_warning("Skipping unknown unit type '%s' for %s.\n", - type, name); - continue; - } - - // if primary is 'Y', list this unit as a primary - addUnit(u, (primary[0]=='Y' || primary[0]=='y')); + char name[BUFSIZE]; + char plural[BUFSIZE]; + char abbr[BUFSIZE]; + char type[BUFSIZE]; + double factor; + char primary[BUFSIZE]; + + int nchars = 0; + // locale is set to C, scanning %lf should work _everywhere_ + if (sscanf(buf, "%15s %15s %15s %15s %8lf %1s %15n", + name, plural, abbr, type, &factor, primary, &nchars) != 6) + { + // Skip the line - doesn't appear to be valid + continue; + } + + g_assert(nchars < BUFSIZE); + + char *desc = buf; + desc += nchars; // buf is now only the description + + // insert into _unit_map + Unit u; + u.name = name; + u.name_plural = plural; + u.abbr = abbr; + u.description = desc; + u.factor = factor; + + if (streq(type, "DIMENSIONLESS")) { + u.type = UNIT_TYPE_DIMENSIONLESS; + } else if (streq(type, "LINEAR")) { + u.type = UNIT_TYPE_LINEAR; + } else if (streq(type, "RADIAL")) { + u.type = UNIT_TYPE_RADIAL; + } else if (streq(type, "FONT_HEIGHT")) { + u.type = UNIT_TYPE_FONT_HEIGHT; + } else { + g_warning("Skipping unknown unit type '%s' for %s.\n", + type, name); + continue; + } + + // if primary is 'Y', list this unit as a primary + addUnit(u, (primary[0]=='Y' || primary[0]=='y')); } @@ -221,9 +221,9 @@ bool UnitTable::loadText(Glib::ustring const &filename) // close file if (fclose(f) != 0) { - g_warning("Error closing units file '%s': %s\n", - filename.c_str(), strerror(errno)); - return false; + g_warning("Error closing units file '%s': %s\n", + filename.c_str(), strerror(errno)); + return false; } return true; @@ -235,9 +235,9 @@ bool UnitTable::load(Glib::ustring const &filename) { int result = handler.parseFile( filename.c_str() ); if ( result != 0 ) { // perhaps - g_warning("Problem loading units file '%s': %d\n", - filename.c_str(), result); - return false; + g_warning("Problem loading units file '%s': %d\n", + filename.c_str(), result); + return false; } return true; @@ -249,9 +249,9 @@ bool UnitTable::save(Glib::ustring const &filename) { // open file for writing FILE *f = fopen(filename.c_str(), "w"); if (f == NULL) { - g_warning("Could not open units file '%s': %s\n", - filename.c_str(), strerror(errno)); - return false; + g_warning("Could not open units file '%s': %s\n", + filename.c_str(), strerror(errno)); + return false; } // write out header @@ -268,9 +268,9 @@ bool UnitTable::save(Glib::ustring const &filename) { // close file if (fclose(f) != 0) { - g_warning("Error closing units file '%s': %s\n", - filename.c_str(), strerror(errno)); - return false; + g_warning("Error closing units file '%s': %s\n", + filename.c_str(), strerror(errno)); + return false; } return true; -- cgit v1.2.3 From 8f989e27529c399b7bc23eed49c88df42f42ff1c Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 13 Jul 2013 15:06:55 -0700 Subject: Minor C++ish refactoring pass. (bzr r12419) --- src/util/units.cpp | 195 ++++++++++++++++++++++++++++------------------------- src/util/units.h | 62 +++++++++++++++-- 2 files changed, 158 insertions(+), 99 deletions(-) (limited to 'src') diff --git a/src/util/units.cpp b/src/util/units.cpp index 002bf3b07..d1275b082 100644 --- a/src/util/units.cpp +++ b/src/util/units.cpp @@ -11,6 +11,39 @@ #include "path-prefix.h" #include "streq.h" +using Inkscape::Util::UNIT_TYPE_DIMENSIONLESS; +using Inkscape::Util::UNIT_TYPE_LINEAR; +using Inkscape::Util::UNIT_TYPE_RADIAL; +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 &getTypeMappings() +{ + static bool init = false; + static std::map 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 + } + return typeMap; +} + +} // namespace + namespace Inkscape { namespace Util { @@ -40,26 +73,46 @@ UnitsSAXHandler::UnitsSAXHandler(UnitTable *table) : #define BUFSIZE (255) -/** - * Returns the suggested precision to use for displaying numbers - * of this unit. - */ +Unit::Unit() : + type(UNIT_TYPE_DIMENSIONLESS), // should this or NONE be the default? + factor(1.0), + name(), + name_plural(), + abbr(), + description() +{ +} + +Unit::Unit(UnitType type, + double factor, + 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) +{ +} + +void Unit::clear() +{ + *this = Unit(); +} + int Unit::defaultDigits() const { int factor_digits = int(log10(factor)); if (factor_digits < 0) { g_warning("factor = %f, factor_digits = %d", factor, factor_digits); g_warning("factor_digits < 0 - returning 0"); - return 0; - } else { - return factor_digits; + factor_digits = 0; } + return factor_digits; } -/** - * Initializes the unit tables and identifies the primary unit types. - * - * The primary unit's conversion factor is required to be 1.00 - */ UnitTable::UnitTable() { // if we swich to the xml file, don't forget to force locale to 'C' @@ -70,14 +123,12 @@ UnitTable::UnitTable() } UnitTable::~UnitTable() { - UnitMap::iterator iter = _unit_map.begin(); - while (iter != _unit_map.end()) { + for (UnitMap::iterator iter = _unit_map.begin(); iter != _unit_map.end(); ++iter) + { delete (*iter).second; - ++iter; } } -/** Add a new unit to the table */ void UnitTable::addUnit(Unit const &u, bool primary) { _unit_map[u.abbr] = new Unit(u); if (primary) { @@ -85,7 +136,6 @@ void UnitTable::addUnit(Unit const &u, bool primary) { } } -/** Retrieve a given unit based on its string identifier */ Unit UnitTable::getUnit(Glib::ustring const &unit_abbr) const { UnitMap::const_iterator iter = _unit_map.find(unit_abbr); if (iter != _unit_map.end()) { @@ -95,36 +145,31 @@ Unit UnitTable::getUnit(Glib::ustring const &unit_abbr) const { } } -/** Remove a unit definition from the given unit type table */ bool UnitTable::deleteUnit(Unit const &u) { - if (u.abbr == _primary_unit[u.type]) { - // Cannot delete the primary unit type since it's - // used for conversions - return false; - } - UnitMap::iterator iter = _unit_map.find(u.abbr); - if (iter != _unit_map.end()) { - delete (*iter).second; - _unit_map.erase(iter); - return true; - } else { - return false; + 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); + if (iter != _unit_map.end()) { + delete (*iter).second; + _unit_map.erase(iter); + deleted = true; + } } + return deleted; } -/** Returns true if the given string 'name' is a valid unit in the table */ bool UnitTable::hasUnit(Glib::ustring const &unit) const { UnitMap::const_iterator iter = _unit_map.find(unit); return (iter != _unit_map.end()); } -/** Provides an iteratable list of items in the given unit table */ UnitTable::UnitMap UnitTable::units(UnitType type) const { UnitMap submap; - for (UnitMap::const_iterator iter = _unit_map.begin(); - iter != _unit_map.end(); ++iter) { + 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)))); } @@ -133,21 +178,14 @@ UnitTable::UnitMap UnitTable::units(UnitType type) const return submap; } -/** Returns the default unit abbr for the given type */ Glib::ustring UnitTable::primary(UnitType type) const { return _primary_unit[type]; } -/** Loads units from a text file. - - loadText loads and merges the contents of the given file into the UnitTable, - possibly overwriting existing unit definitions. - - @param filename: file to be loaded*/ bool UnitTable::loadText(Glib::ustring const &filename) { - char buf[BUFSIZE]; + char buf[BUFSIZE] = {0}; // Open file for reading FILE * f = fopen(filename.c_str(), "r"); @@ -159,23 +197,24 @@ bool UnitTable::loadText(Glib::ustring const &filename) return false; } + /** @todo fix this to use C++ means and explicit locale to avoid need to change. */ // bypass current locale in order to make // sscanf read floats with '.' as a separator // set locale to 'C' and keep old locale - char *old_locale; - old_locale = g_strdup (setlocale (LC_NUMERIC, NULL)); + char *old_locale = g_strdup(setlocale(LC_NUMERIC, NULL)); setlocale (LC_NUMERIC, "C"); while (fgets(buf, BUFSIZE, f) != NULL) { - char name[BUFSIZE]; - char plural[BUFSIZE]; - char abbr[BUFSIZE]; - char type[BUFSIZE]; - double factor; - char primary[BUFSIZE]; + char name[BUFSIZE] = {0}; + char plural[BUFSIZE] = {0}; + char abbr[BUFSIZE] = {0}; + char type[BUFSIZE] = {0}; + double factor = 0.0; + char primary[BUFSIZE] = {0}; int nchars = 0; // locale is set to C, scanning %lf should work _everywhere_ + /** @todo address %15n, which causes a warning: */ if (sscanf(buf, "%15s %15s %15s %15s %8lf %1s %15n", name, plural, abbr, type, &factor, primary, &nchars) != 6) { @@ -189,30 +228,17 @@ bool UnitTable::loadText(Glib::ustring const &filename) desc += nchars; // buf is now only the description // insert into _unit_map - Unit u; - u.name = name; - u.name_plural = plural; - u.abbr = abbr; - u.description = desc; - u.factor = factor; - - if (streq(type, "DIMENSIONLESS")) { - u.type = UNIT_TYPE_DIMENSIONLESS; - } else if (streq(type, "LINEAR")) { - u.type = UNIT_TYPE_LINEAR; - } else if (streq(type, "RADIAL")) { - u.type = UNIT_TYPE_RADIAL; - } else if (streq(type, "FONT_HEIGHT")) { - u.type = UNIT_TYPE_FONT_HEIGHT; - } else { - g_warning("Skipping unknown unit type '%s' for %s.\n", - type, name); + if (getTypeMappings().find(type) == getTypeMappings().end()) + { + g_warning("Skipping unknown unit type '%s' for %s.\n", type, name); continue; } + UnitType utype = getTypeMappings()[type]; + + Unit u(utype, factor, name, plural, abbr, desc); // if primary is 'Y', list this unit as a primary addUnit(u, (primary[0]=='Y' || primary[0]=='y')); - } // set back the saved locale @@ -221,8 +247,7 @@ bool UnitTable::loadText(Glib::ustring const &filename) // close file if (fclose(f) != 0) { - g_warning("Error closing units file '%s': %s\n", - filename.c_str(), strerror(errno)); + g_warning("Error closing units file '%s': %s\n", filename.c_str(), strerror(errno)); return false; } @@ -235,22 +260,19 @@ bool UnitTable::load(Glib::ustring const &filename) { int result = handler.parseFile( filename.c_str() ); if ( result != 0 ) { // perhaps - g_warning("Problem loading units file '%s': %d\n", - filename.c_str(), result); + g_warning("Problem loading units file '%s': %d\n", filename.c_str(), result); return false; } return true; } -/** Saves the current UnitTable to the given file. */ bool UnitTable::save(Glib::ustring const &filename) { // open file for writing FILE *f = fopen(filename.c_str(), "w"); if (f == NULL) { - g_warning("Could not open units file '%s': %s\n", - filename.c_str(), strerror(errno)); + g_warning("Could not open units file '%s': %s\n", filename.c_str(), strerror(errno)); return false; } @@ -268,8 +290,7 @@ bool UnitTable::save(Glib::ustring const &filename) { // close file if (fclose(f) != 0) { - g_warning("Error closing units file '%s': %s\n", - filename.c_str(), strerror(errno)); + g_warning("Error closing units file '%s': %s\n", filename.c_str(), strerror(errno)); return false; } @@ -281,12 +302,7 @@ void UnitsSAXHandler::_startElement(xmlChar const *name, xmlChar const **attrs) { if (streq("unit", (char const *)name)) { // reset for next use - unit.name.clear(); - unit.name_plural.clear(); - unit.abbr.clear(); - unit.description.clear(); - unit.type = UNIT_TYPE_DIMENSIONLESS; - unit.factor = 1.0; + unit.clear(); primary = false; skip = false; @@ -294,14 +310,9 @@ void UnitsSAXHandler::_startElement(xmlChar const *name, xmlChar const **attrs) char const *const key = (char const *)attrs[i]; if (streq("type", key)) { char const *type = (char const*)attrs[i+1]; - if (streq(type, "DIMENSIONLESS")) { - unit.type = UNIT_TYPE_DIMENSIONLESS; - } else if (streq(type, "LINEAR")) { - unit.type = UNIT_TYPE_LINEAR; - } else if (streq(type, "RADIAL")) { - unit.type = UNIT_TYPE_RADIAL; - } else if (streq(type, "FONT_HEIGHT")) { - unit.type = UNIT_TYPE_FONT_HEIGHT; + if (getTypeMappings().find(type) != getTypeMappings().end()) + { + unit.type = getTypeMappings()[type]; } else { g_warning("Skipping unknown unit type '%s' for %s.\n", type, name); skip = true; diff --git a/src/util/units.h b/src/util/units.h index b22bdb1f2..40c89a4a0 100644 --- a/src/util/units.h +++ b/src/util/units.h @@ -36,40 +36,78 @@ const char DEG[] = "°"; class Unit { public: - Glib::ustring name; - Glib::ustring name_plural; - Glib::ustring abbr; - Glib::ustring description; - - UnitType type; + Unit(); + Unit(UnitType type, + double factor, + Glib::ustring const &name, + Glib::ustring const &name_plural, + Glib::ustring const &abbr, + Glib::ustring const &description); - double factor; + void clear(); bool isAbsolute() const { return type != UNIT_TYPE_DIMENSIONLESS; } + + /** + * Returns the suggested precision to use for displaying numbers + * of this unit. + */ int defaultDigits() const; + + UnitType type; + double factor; + Glib::ustring name; + Glib::ustring name_plural; + Glib::ustring abbr; + Glib::ustring description; }; class UnitTable { public: + /** + * Initializes the unit tables and identifies the primary unit types. + * + * The primary unit's conversion factor is required to be 1.00 + */ UnitTable(); virtual ~UnitTable(); typedef std::map UnitMap; + /** 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; + + /** Remove a unit definition from the given unit type 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; + /** Returns the default unit abbr for the given type */ Glib::ustring primary(UnitType type) const; double getScale() const; + void setScale(); bool load(Glib::ustring const &filename); + + /** Loads units from a text file. + * + * loadText loads and merges the contents of the given file into the UnitTable, + * possibly overwriting existing unit definitions. + * + * @param filename file to be loaded + */ bool loadText(Glib::ustring const &filename); + + /** Saves the current UnitTable to the given file. */ bool save(Glib::ustring const &filename); protected: @@ -88,3 +126,13 @@ class UnitTable { } // namespace Inkscape #endif // define INKSCAPE_UTIL_UNITS_H +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3 From 4e088d33c04329fe57ef987d577f5aa57f83b644 Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Tue, 16 Jul 2013 15:46:56 -0400 Subject: Shape calculations. re-introduce grid of a smaller size. (http://article.gmane.org/gmane.comp.graphics.inkscape.devel/40786) (bzr r12420) --- src/livarot/Shape.cpp | 8 ++++---- src/livarot/Shape.h | 12 ++++++------ src/livarot/ShapeMisc.cpp | 12 ++++++------ src/livarot/ShapeSweep.cpp | 8 ++++---- 4 files changed, 20 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/livarot/Shape.cpp b/src/livarot/Shape.cpp index 130b1b03a..c29444a33 100644 --- a/src/livarot/Shape.cpp +++ b/src/livarot/Shape.cpp @@ -334,8 +334,8 @@ Shape::AddPoint (const Geom::Point x) pData[n].nextLinkedPoint = -1; pData[n].askForWindingS = NULL; pData[n].askForWindingB = -1; - pData[n].rx[0] = /*Round*/ (p.x[0]); - pData[n].rx[1] = /*Round*/ (p.x[1]); + pData[n].rx[0] = Round(p.x[0]); + pData[n].rx[1] = Round(p.x[1]); } if (_has_voronoi_data) { @@ -2116,8 +2116,8 @@ void Shape::initialisePointData() pData[i].pending = 0; pData[i].edgeOnLeft = -1; pData[i].nextLinkedPoint = -1; - pData[i].rx[0] = /*Round*/ (getPoint(i).x[0]); - pData[i].rx[1] = /*Round*/ (getPoint(i).x[1]); + pData[i].rx[0] = Round(getPoint(i).x[0]); + pData[i].rx[1] = Round(getPoint(i).x[1]); } _point_data_initialised = true; diff --git a/src/livarot/Shape.h b/src/livarot/Shape.h index b999b9dca..98fc2d7bf 100644 --- a/src/livarot/Shape.h +++ b/src/livarot/Shape.h @@ -266,20 +266,20 @@ public: // be careful when using this function // the coordinate rounding function -// inline static double Round(double x) -// { -// return ldexp(rint(ldexp(x, 5)), -5); -// } + inline static double Round(double x) + { + return ldexp(rint(ldexp(x, 9)), -9); + } // 2 miscannellous variations on it, to scale to and back the rounding grid inline static double HalfRound(double x) { - return ldexp(x, -5); + return ldexp(x, -9); } inline static double IHalfRound(double x) { - return ldexp(x, 5); + return ldexp(x, 9); } // boolean operations on polygons (requests intersection-free poylygons) diff --git a/src/livarot/ShapeMisc.cpp b/src/livarot/ShapeMisc.cpp index 5bb8a25ef..6fd40790f 100644 --- a/src/livarot/ShapeMisc.cpp +++ b/src/livarot/ShapeMisc.cpp @@ -49,8 +49,8 @@ Shape::ConvertToForme (Path * dest) for (int i = 0; i < numberOfPoints(); i++) { - pData[i].rx[0] = /*Round*/ (getPoint(i).x[0]); - pData[i].rx[1] = /*Round*/ (getPoint(i).x[1]); + pData[i].rx[0] = Round (getPoint(i).x[0]); + pData[i].rx[1] = Round (getPoint(i).x[1]); } for (int i = 0; i < numberOfEdges(); i++) { @@ -199,8 +199,8 @@ Shape::ConvertToForme (Path * dest, int nbP, Path * *orig, bool splitWhenForced) for (int i = 0; i < numberOfPoints(); i++) { - pData[i].rx[0] = /*Round*/ (getPoint(i).x[0]); - pData[i].rx[1] = /*Round*/ (getPoint(i).x[1]); + pData[i].rx[0] = Round (getPoint(i).x[0]); + pData[i].rx[1] = Round (getPoint(i).x[1]); } for (int i = 0; i < numberOfEdges(); i++) { @@ -352,8 +352,8 @@ Shape::ConvertToFormeNested (Path * dest, int nbP, Path * *orig, int wildPath,in for (int i = 0; i < numberOfPoints(); i++) { - pData[i].rx[0] = /*Round*/ (getPoint(i).x[0]); - pData[i].rx[1] = /*Round*/ (getPoint(i).x[1]); + pData[i].rx[0] = Round (getPoint(i).x[0]); + pData[i].rx[1] = Round (getPoint(i).x[1]); } for (int i = 0; i < numberOfEdges(); i++) { diff --git a/src/livarot/ShapeSweep.cpp b/src/livarot/ShapeSweep.cpp index ffe5a9d73..c2fd83e31 100644 --- a/src/livarot/ShapeSweep.cpp +++ b/src/livarot/ShapeSweep.cpp @@ -250,8 +250,8 @@ Shape::ConvertToShape (Shape * a, FillRule directed, bool invert) } Geom::Point rPtX; - rPtX[0]= /*Round*/ (ptX[0]); - rPtX[1]= /*Round*/ (ptX[1]); + rPtX[0]= Round (ptX[0]); + rPtX[1]= Round (ptX[1]); int lastPointNo = -1; lastPointNo = AddPoint (rPtX); pData[lastPointNo].rx = rPtX; @@ -1051,8 +1051,8 @@ Shape::Booleen (Shape * a, Shape * b, BooleanOp mod,int cutPathID) } Geom::Point rPtX; - rPtX[0]= /*Round*/ (ptX[0]); - rPtX[1]= /*Round*/ (ptX[1]); + rPtX[0]= Round (ptX[0]); + rPtX[1]= Round (ptX[1]); int lastPointNo = -1; lastPointNo = AddPoint (rPtX); pData[lastPointNo].rx = rPtX; -- cgit v1.2.3