From 7239afff554c14388dd6e930d903beb7bbd8b2ca Mon Sep 17 00:00:00 2001 From: Felipe Corr??a da Silva Sanches Date: Wed, 18 May 2011 17:04:33 -0300 Subject: Adding inkscape:label parameter to guidelines so that our guidelanes can display labels (we still dont have a user interface, but files with that parameter will render correctly) (bzr r10209) --- src/sp-guide.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 7d36df4a3..1e51ee4d5 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -160,6 +160,7 @@ static void sp_guide_build(SPObject *object, SPDocument *document, Inkscape::XML (* ((SPObjectClass *) (parent_class))->build)(object, document, repr); } + object->readAttr( "inkscape:label" ); object->readAttr( "orientation" ); object->readAttr( "position" ); } @@ -183,6 +184,15 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value) SPGuide *guide = SP_GUIDE(object); switch (key) { + case SP_ATTR_INKSCAPE_LABEL: + if (value) { + guide->label = g_strdup(value); + } else { + guide->label = NULL; + } + + sp_guide_set_label(*guide, guide->label, false); + break; case SP_ATTR_ORIENTATION: { if (value && !strcmp(value, "horizontal")) { @@ -291,7 +301,7 @@ sp_guide_create_guides_around_page(SPDesktop *dt) { void SPGuide::showSPGuide(SPCanvasGroup *group, GCallback handler) { - SPCanvasItem *item = sp_guideline_new(group, point_on_line, normal_to_line); + SPCanvasItem *item = sp_guideline_new(group, label, point_on_line, normal_to_line); sp_guideline_set_color(SP_GUIDELINE(item), color); g_signal_connect(G_OBJECT(item), "event", G_CALLBACK(handler), this); @@ -402,6 +412,19 @@ void sp_guide_set_normal(SPGuide &guide, Geom::Point const normal_to_line, bool */ } +void sp_guide_set_label(SPGuide &guide, char* label, bool const commit) +{ + g_assert(SP_IS_GUIDE(&guide)); + if (guide.views){ + sp_guideline_set_label(SP_GUIDELINE(guide.views->data), label); + } + + if (commit){ + //XML Tree being used directly while it shouldn't be + guide.getRepr()->setAttribute("label", label); + } +} + /** * Returns a human-readable description of the guideline for use in dialog boxes and status bar. * If verbose is false, only positioning information is included (useful for dialogs). -- cgit v1.2.3 From d08f8e9ed468767cc64766eb80ea134bb5edb197 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Thu, 26 May 2011 23:17:37 +0200 Subject: add entry widget to guideline dialog to change guide's label (and fix some label xml writing and rendering bugs) (bzr r10234) --- src/sp-guide.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 1e51ee4d5..584a6a366 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -412,7 +412,7 @@ void sp_guide_set_normal(SPGuide &guide, Geom::Point const normal_to_line, bool */ } -void sp_guide_set_label(SPGuide &guide, char* label, bool const commit) +void sp_guide_set_label(SPGuide &guide, const char* label, bool const commit) { g_assert(SP_IS_GUIDE(&guide)); if (guide.views){ @@ -421,7 +421,7 @@ void sp_guide_set_label(SPGuide &guide, char* label, bool const commit) if (commit){ //XML Tree being used directly while it shouldn't be - guide.getRepr()->setAttribute("label", label); + guide.getRepr()->setAttribute("inkscape:label", label); } } -- cgit v1.2.3 From 637e36780dacfed78c322064e322f247bd764fd1 Mon Sep 17 00:00:00 2001 From: Felipe Corr??a da Silva Sanches Date: Sat, 18 Jun 2011 05:51:28 -0300 Subject: user interface for selecting colors of guidelines (bzr r10315) --- src/sp-guide.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 584a6a366..19b64eb1a 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -412,6 +412,23 @@ void sp_guide_set_normal(SPGuide &guide, Geom::Point const normal_to_line, bool */ } +void sp_guide_set_color(SPGuide &guide, const unsigned char r, const unsigned char g, const unsigned char b, bool const commit) +{ + g_assert(SP_IS_GUIDE(&guide)); + guide.color = (r << 24) | (g << 16) | (b << 8) | 0x7f; + + if (guide.views){ + sp_guideline_set_color(SP_GUIDELINE(guide.views->data), guide.color); + } + + if (commit){ + std::ostringstream os; + os << "rgb(" << r << "," << g << "," << b << ")"; + //XML Tree being used directly while it shouldn't be + guide.getRepr()->setAttribute("inkscape:color", os.str().c_str()); + } +} + void sp_guide_set_label(SPGuide &guide, const char* label, bool const commit) { g_assert(SP_IS_GUIDE(&guide)); -- cgit v1.2.3 From eff2aa4cbf77f5fec1ba2fd98f482737635db342 Mon Sep 17 00:00:00 2001 From: Felipe Corr??a da Silva Sanches Date: Wed, 22 Jun 2011 09:56:30 -0300 Subject: =?UTF-8?q?The=20label=20=E2=80=98Guides=20Around=20Page=E2=80=99?= =?UTF-8?q?=20does=20not=20include=20a=20verb.=20=E2=80=98Guides=20Around?= =?UTF-8?q?=20Page=E2=80=99=20what=3F=20'Create=20Guides=20Around=20the=20?= =?UTF-8?q?Page'=20:-D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http://cuts.thinking-garment.com/144 (bzr r10340) --- src/sp-guide.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 19b64eb1a..aa365eb99 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -296,7 +296,7 @@ sp_guide_create_guides_around_page(SPDesktop *dt) { sp_guide_pt_pairs_to_guides(dt, pts); - DocumentUndo::done(doc, SP_VERB_NONE, _("Guides Around Page")); + DocumentUndo::done(doc, SP_VERB_NONE, _("Create Guides Around the Page")); } void SPGuide::showSPGuide(SPCanvasGroup *group, GCallback handler) -- cgit v1.2.3 From 1f189ac0c28ee85408431815dceefd0607b6465b Mon Sep 17 00:00:00 2001 From: Felipe Corr??a da Silva Sanches Date: Wed, 22 Jun 2011 18:40:59 -0300 Subject: Adding a "Remove All Guides" option to the Edit menu. (bzr r10343) --- src/sp-guide.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index aa365eb99..f71bc1762 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -163,6 +163,9 @@ static void sp_guide_build(SPObject *object, SPDocument *document, Inkscape::XML object->readAttr( "inkscape:label" ); object->readAttr( "orientation" ); object->readAttr( "position" ); + + /* Register */ + document->addResource("guide", object); } static void sp_guide_release(SPObject *object) @@ -174,6 +177,11 @@ static void sp_guide_release(SPObject *object) guide->views = g_slist_remove(guide->views, guide->views->data); } + if (object->document) { + // Unregister ourselves + object->document->removeResource("guide", object); + } + if (((SPObjectClass *) parent_class)->release) { ((SPObjectClass *) parent_class)->release(object); } @@ -299,6 +307,18 @@ sp_guide_create_guides_around_page(SPDesktop *dt) { DocumentUndo::done(doc, SP_VERB_NONE, _("Create Guides Around the Page")); } +void +sp_guide_delete_all_guides(SPDesktop *dt) { + SPDocument *doc=sp_desktop_document(dt); + const GSList *current; + while ( (current = doc->getResourceList("guide")) ) { + SPGuide* guide = SP_GUIDE(current->data); + sp_guide_remove(guide); + } + + DocumentUndo::done(doc, SP_VERB_NONE, _("Delete All Guides")); +} + void SPGuide::showSPGuide(SPCanvasGroup *group, GCallback handler) { SPCanvasItem *item = sp_guideline_new(group, label, point_on_line, normal_to_line); -- cgit v1.2.3 From 61ec015d8734244ecd6223e941ecc09eccdfcdaa Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 18 Jul 2011 22:44:25 +0200 Subject: refactor the guideline drawing. now it obeys desktop transforms a lot better. (bzr r10471) --- src/sp-guide.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index f71bc1762..71312b698 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -40,6 +40,7 @@ #include "desktop.h" #include "sp-namedview.h" #include <2geom/angle.h> +#include <2geom/transforms.h> #include "document.h" using Inkscape::DocumentUndo; @@ -321,7 +322,14 @@ sp_guide_delete_all_guides(SPDesktop *dt) { void SPGuide::showSPGuide(SPCanvasGroup *group, GCallback handler) { - SPCanvasItem *item = sp_guideline_new(group, label, point_on_line, normal_to_line); + // historically, normal_to_line and point_on_line are stored in desktop coordinates (without desktop rotation) + // therefore, we have to correct for this first... + SPDesktop const *desktop = inkscape_active_desktop(); /// @fixme Obtain SPDesktop in better way... + Geom::Affine correction = Geom::Translate(0, -desktop->namedview->document->getHeight()) * Geom::Scale(1, -1); + Geom::Point normal_dt = normal_to_line * correction.withoutTranslation() * desktop->doc2dt().withoutTranslation(); + Geom::Point point_on_line_dt = point_on_line * correction * desktop->doc2dt(); + + SPCanvasItem *item = sp_guideline_new(group, label, point_on_line_dt, normal_dt); sp_guideline_set_color(SP_GUIDELINE(item), color); g_signal_connect(G_OBJECT(item), "event", G_CALLBACK(handler), this); @@ -379,8 +387,14 @@ void sp_guide_moveto(SPGuide &guide, Geom::Point const point_on_line, bool const { g_assert(SP_IS_GUIDE(&guide)); + // historically, normal_to_line and point_on_line are stored in desktop coordinates (without desktop rotation) + // therefore, we have to correct for this first... + SPDesktop const *desktop = inkscape_active_desktop(); /// @fixme Obtain SPDesktop in better way... + Geom::Affine correction = Geom::Translate(0, -desktop->namedview->document->getHeight()) * Geom::Scale(1, -1); + Geom::Point point_on_line_dt = point_on_line * correction * desktop->doc2dt(); + for (GSList *l = guide.views; l != NULL; l = l->next) { - sp_guideline_set_position(SP_GUIDELINE(l->data), point_on_line); + sp_guideline_set_position(SP_GUIDELINE(l->data), point_on_line_dt); } /* Calling sp_repr_set_point must precede calling sp_item_notify_moveto in the commit @@ -410,8 +424,14 @@ void sp_guide_set_normal(SPGuide &guide, Geom::Point const normal_to_line, bool { g_assert(SP_IS_GUIDE(&guide)); + // historically, normal_to_line and point_on_line are stored in desktop coordinates (without desktop rotation) + // therefore, we have to correct for this first... + SPDesktop const *desktop = inkscape_active_desktop(); /// @fixme Obtain SPDesktop in better way... + Geom::Affine correction = Geom::Translate(0, -desktop->namedview->document->getHeight()) * Geom::Scale(1, -1); + Geom::Point normal_dt = normal_to_line * correction.withoutTranslation() * desktop->doc2dt().withoutTranslation(); + for (GSList *l = guide.views; l != NULL; l = l->next) { - sp_guideline_set_normal(SP_GUIDELINE(l->data), normal_to_line); + sp_guideline_set_normal(SP_GUIDELINE(l->data), normal_dt); } /* Calling sp_repr_set_svg_point must precede calling sp_item_notify_moveto in the commit -- cgit v1.2.3 From 8c1d98b10004841b97520b6be6eaca72764cdd08 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 18 Jul 2011 22:55:55 +0200 Subject: revert unnecessary complicated change (bzr r10472) --- src/sp-guide.cpp | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 71312b698..f71bc1762 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -40,7 +40,6 @@ #include "desktop.h" #include "sp-namedview.h" #include <2geom/angle.h> -#include <2geom/transforms.h> #include "document.h" using Inkscape::DocumentUndo; @@ -322,14 +321,7 @@ sp_guide_delete_all_guides(SPDesktop *dt) { void SPGuide::showSPGuide(SPCanvasGroup *group, GCallback handler) { - // historically, normal_to_line and point_on_line are stored in desktop coordinates (without desktop rotation) - // therefore, we have to correct for this first... - SPDesktop const *desktop = inkscape_active_desktop(); /// @fixme Obtain SPDesktop in better way... - Geom::Affine correction = Geom::Translate(0, -desktop->namedview->document->getHeight()) * Geom::Scale(1, -1); - Geom::Point normal_dt = normal_to_line * correction.withoutTranslation() * desktop->doc2dt().withoutTranslation(); - Geom::Point point_on_line_dt = point_on_line * correction * desktop->doc2dt(); - - SPCanvasItem *item = sp_guideline_new(group, label, point_on_line_dt, normal_dt); + SPCanvasItem *item = sp_guideline_new(group, label, point_on_line, normal_to_line); sp_guideline_set_color(SP_GUIDELINE(item), color); g_signal_connect(G_OBJECT(item), "event", G_CALLBACK(handler), this); @@ -387,14 +379,8 @@ void sp_guide_moveto(SPGuide &guide, Geom::Point const point_on_line, bool const { g_assert(SP_IS_GUIDE(&guide)); - // historically, normal_to_line and point_on_line are stored in desktop coordinates (without desktop rotation) - // therefore, we have to correct for this first... - SPDesktop const *desktop = inkscape_active_desktop(); /// @fixme Obtain SPDesktop in better way... - Geom::Affine correction = Geom::Translate(0, -desktop->namedview->document->getHeight()) * Geom::Scale(1, -1); - Geom::Point point_on_line_dt = point_on_line * correction * desktop->doc2dt(); - for (GSList *l = guide.views; l != NULL; l = l->next) { - sp_guideline_set_position(SP_GUIDELINE(l->data), point_on_line_dt); + sp_guideline_set_position(SP_GUIDELINE(l->data), point_on_line); } /* Calling sp_repr_set_point must precede calling sp_item_notify_moveto in the commit @@ -424,14 +410,8 @@ void sp_guide_set_normal(SPGuide &guide, Geom::Point const normal_to_line, bool { g_assert(SP_IS_GUIDE(&guide)); - // historically, normal_to_line and point_on_line are stored in desktop coordinates (without desktop rotation) - // therefore, we have to correct for this first... - SPDesktop const *desktop = inkscape_active_desktop(); /// @fixme Obtain SPDesktop in better way... - Geom::Affine correction = Geom::Translate(0, -desktop->namedview->document->getHeight()) * Geom::Scale(1, -1); - Geom::Point normal_dt = normal_to_line * correction.withoutTranslation() * desktop->doc2dt().withoutTranslation(); - for (GSList *l = guide.views; l != NULL; l = l->next) { - sp_guideline_set_normal(SP_GUIDELINE(l->data), normal_dt); + sp_guideline_set_normal(SP_GUIDELINE(l->data), normal_to_line); } /* Calling sp_repr_set_svg_point must precede calling sp_item_notify_moveto in the commit -- cgit v1.2.3 From 97b1c4d688a979eb8e327c13c6bcc6fad20902f2 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Tue, 19 Jul 2011 20:24:59 +0200 Subject: remove some unnecessary inkscape_active_desktop() calls (bzr r10477) --- src/sp-guide.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index f71bc1762..45491e5e5 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -261,9 +261,8 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value) } } -SPGuide *SPGuide::createSPGuide(SPDesktop *desktop, Geom::Point const &pt1, Geom::Point const &pt2) +SPGuide *SPGuide::createSPGuide(SPDocument *doc, Geom::Point const &pt1, Geom::Point const &pt2) { - SPDocument *doc = sp_desktop_document(desktop); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::XML::Node *repr = xml_doc->createElement("sodipodi:guide"); @@ -273,7 +272,10 @@ SPGuide *SPGuide::createSPGuide(SPDesktop *desktop, Geom::Point const &pt1, Geom sp_repr_set_point(repr, "position", pt1); sp_repr_set_point(repr, "orientation", n); - desktop->namedview->appendChild(repr); + SPNamedView *namedview = sp_document_namedview(doc, NULL); + if (namedview) { + namedview->appendChild(repr); + } Inkscape::GC::release(repr); SPGuide *guide= SP_GUIDE(doc->getObjectByRepr(repr)); @@ -281,9 +283,9 @@ SPGuide *SPGuide::createSPGuide(SPDesktop *desktop, Geom::Point const &pt1, Geom } void -sp_guide_pt_pairs_to_guides(SPDesktop *dt, std::list > &pts) { +sp_guide_pt_pairs_to_guides(SPDocument *doc, std::list > &pts) { for (std::list >::iterator i = pts.begin(); i != pts.end(); ++i) { - SPGuide::createSPGuide(dt, (*i).first, (*i).second); + SPGuide::createSPGuide(doc, (*i).first, (*i).second); } } @@ -302,7 +304,7 @@ sp_guide_create_guides_around_page(SPDesktop *dt) { pts.push_back(std::make_pair(C, D)); pts.push_back(std::make_pair(D, A)); - sp_guide_pt_pairs_to_guides(dt, pts); + sp_guide_pt_pairs_to_guides(doc, pts); DocumentUndo::done(doc, SP_VERB_NONE, _("Create Guides Around the Page")); } -- cgit v1.2.3 From afa84f849bf79bce9ef7c2179982e62df8ca520b Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Tue, 19 Jul 2011 20:49:49 +0200 Subject: another case of SP_ACTIVE_DESKTOP removed (bzr r10478) --- src/sp-guide.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 45491e5e5..8d9d7b87d 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -474,11 +474,12 @@ char *sp_guide_description(SPGuide const *guide, const bool verbose) { using Geom::X; using Geom::Y; - + + SPNamedView *namedview = sp_document_namedview(guide->document, NULL); GString *position_string_x = SP_PX_TO_METRIC_STRING(guide->point_on_line[X], - SP_ACTIVE_DESKTOP->namedview->getDefaultMetric()); + namedview->getDefaultMetric()); GString *position_string_y = SP_PX_TO_METRIC_STRING(guide->point_on_line[Y], - SP_ACTIVE_DESKTOP->namedview->getDefaultMetric()); + namedview->getDefaultMetric()); gchar *shortcuts = g_strdup_printf("; %s", _("Shift+drag to rotate, Ctrl+drag to move origin, Del to delete")); gchar *descr; -- cgit v1.2.3 From 9c0b8ae87db4fc8f471924a14b9420709a607b7d Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Fri, 22 Jul 2011 12:02:36 +0200 Subject: fix crash when guideline is deleted by dragging it off-canvas (bzr r10488) --- src/sp-guide.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 8d9d7b87d..033e1db1f 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -476,6 +476,10 @@ char *sp_guide_description(SPGuide const *guide, const bool verbose) using Geom::Y; SPNamedView *namedview = sp_document_namedview(guide->document, NULL); + if (!namedview) { + // Guide has probably been deleted and no longer has an attached namedview. + return g_strdup_printf(_("Deleted")); + } GString *position_string_x = SP_PX_TO_METRIC_STRING(guide->point_on_line[X], namedview->getDefaultMetric()); GString *position_string_y = SP_PX_TO_METRIC_STRING(guide->point_on_line[Y], -- cgit v1.2.3 From 07fed71027585bb07a0952ca2c5e6ab2f90f8e68 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 23 Jul 2011 14:58:50 -0700 Subject: Fix issue with deleted guides and gtk warnings. (bzr r10496) --- src/sp-guide.cpp | 61 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 033e1db1f..0b1888340 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -475,40 +475,43 @@ char *sp_guide_description(SPGuide const *guide, const bool verbose) using Geom::X; using Geom::Y; - SPNamedView *namedview = sp_document_namedview(guide->document, NULL); - if (!namedview) { + char *descr = 0; + if ( !guide->document ) { // Guide has probably been deleted and no longer has an attached namedview. - return g_strdup_printf(_("Deleted")); - } - GString *position_string_x = SP_PX_TO_METRIC_STRING(guide->point_on_line[X], - namedview->getDefaultMetric()); - GString *position_string_y = SP_PX_TO_METRIC_STRING(guide->point_on_line[Y], - namedview->getDefaultMetric()); - - gchar *shortcuts = g_strdup_printf("; %s", _("Shift+drag to rotate, Ctrl+drag to move origin, Del to delete")); - gchar *descr; - - if ( are_near(guide->normal_to_line, component_vectors[X]) || - are_near(guide->normal_to_line, -component_vectors[X]) ) { - descr = g_strdup_printf(_("vertical, at %s"), position_string_x->str); - } else if ( are_near(guide->normal_to_line, component_vectors[Y]) || - are_near(guide->normal_to_line, -component_vectors[Y]) ) { - descr = g_strdup_printf(_("horizontal, at %s"), position_string_y->str); + descr = g_strdup_printf(_("Deleted")); } else { - double const radians = guide->angle(); - double const degrees = Geom::rad_to_deg(radians); - int const degrees_int = (int) round(degrees); - descr = g_strdup_printf(_("at %d degrees, through (%s,%s)"), - degrees_int, position_string_x->str, position_string_y->str); - } + SPNamedView *namedview = sp_document_namedview(guide->document, NULL); + + GString *position_string_x = SP_PX_TO_METRIC_STRING(guide->point_on_line[X], + namedview->getDefaultMetric()); + GString *position_string_y = SP_PX_TO_METRIC_STRING(guide->point_on_line[Y], + namedview->getDefaultMetric()); - g_string_free(position_string_x, TRUE); - g_string_free(position_string_y, TRUE); + gchar *shortcuts = g_strdup_printf("; %s", _("Shift+drag to rotate, Ctrl+drag to move origin, Del to delete")); - if (verbose) { - descr = g_strconcat(descr, shortcuts, NULL); + if ( are_near(guide->normal_to_line, component_vectors[X]) || + are_near(guide->normal_to_line, -component_vectors[X]) ) { + descr = g_strdup_printf(_("vertical, at %s"), position_string_x->str); + } else if ( are_near(guide->normal_to_line, component_vectors[Y]) || + are_near(guide->normal_to_line, -component_vectors[Y]) ) { + descr = g_strdup_printf(_("horizontal, at %s"), position_string_y->str); + } else { + double const radians = guide->angle(); + double const degrees = Geom::rad_to_deg(radians); + int const degrees_int = (int) round(degrees); + descr = g_strdup_printf(_("at %d degrees, through (%s,%s)"), + degrees_int, position_string_x->str, position_string_y->str); + } + + g_string_free(position_string_x, TRUE); + g_string_free(position_string_y, TRUE); + + if (verbose) { + descr = g_strconcat(descr, shortcuts, NULL); + } + g_free(shortcuts); } - g_free(shortcuts); + return descr; } -- cgit v1.2.3 From 894102c82e86480a4701ef92464d4f895bcd0d91 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 23 Jul 2011 15:33:32 -0700 Subject: Fix memory leak. (bzr r10497) --- src/sp-guide.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 0b1888340..b55084609 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -507,7 +507,9 @@ char *sp_guide_description(SPGuide const *guide, const bool verbose) g_string_free(position_string_y, TRUE); if (verbose) { - descr = g_strconcat(descr, shortcuts, NULL); + gchar *oldDescr = descr; + descr = g_strconcat(oldDescr, shortcuts, NULL); + g_free(oldDescr); } g_free(shortcuts); } -- cgit v1.2.3 From 9b4b20104eba525bdfff7c40ca1a985cda5d7791 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 21 Aug 2011 12:29:02 +0200 Subject: fix for bad argument crash for guides Fixed bugs: - https://launchpad.net/bugs/829947 (bzr r10562) --- src/sp-guide.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index b55084609..a06d098d0 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -231,23 +231,27 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value) break; case SP_ATTR_POSITION: { - gchar ** strarray = g_strsplit(value, ",", 2); - double newx, newy; - unsigned int success = sp_svg_number_read_d(strarray[0], &newx); - success += sp_svg_number_read_d(strarray[1], &newy); - g_strfreev (strarray); - if (success == 2) { - guide->point_on_line = Geom::Point(newx, newy); - } else if (success == 1) { - // before 0.46 style guideline definition. - const gchar *attr = object->getRepr()->attribute("orientation"); - if (attr && !strcmp(attr, "horizontal")) { - guide->point_on_line = Geom::Point(0, newx); - } else { - guide->point_on_line = Geom::Point(newx, 0); + if (value) { + gchar ** strarray = g_strsplit(value, ",", 2); + double newx, newy; + unsigned int success = sp_svg_number_read_d(strarray[0], &newx); + success += sp_svg_number_read_d(strarray[1], &newy); + g_strfreev (strarray); + if (success == 2) { + guide->point_on_line = Geom::Point(newx, newy); + } else if (success == 1) { + // before 0.46 style guideline definition. + const gchar *attr = object->getRepr()->attribute("orientation"); + if (attr && !strcmp(attr, "horizontal")) { + guide->point_on_line = Geom::Point(0, newx); + } else { + guide->point_on_line = Geom::Point(newx, 0); + } } + } else { + // default to (0,0) for bad arguments + guide->point_on_line = Geom::Point(0,0); } - // update position in non-committing way // fixme: perhaps we need to add an update method instead, and request_update here sp_guide_moveto(*guide, guide->point_on_line, false); -- cgit v1.2.3 From d6af1140ee108cc7d7fb6e0ba89ff7e30bb7ad3a Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 27 Aug 2011 18:05:32 +0200 Subject: Completely remove NRRect, NRRectL, in-svg-plane.h (bzr r10582.1.6) --- src/sp-guide.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/sp-guide.cpp') diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index a06d098d0..5d30800d6 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -116,7 +116,7 @@ static void sp_guide_class_init(SPGuideClass *gc) static void sp_guide_init(SPGuide *guide) { - guide->normal_to_line = component_vectors[Geom::Y]; + guide->normal_to_line = Geom::Point(0.,1.); guide->point_on_line = Geom::Point(0.,0.); guide->color = 0x0000ff7f; guide->hicolor = 0xff00007f; @@ -205,9 +205,9 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value) { if (value && !strcmp(value, "horizontal")) { /* Visual representation of a horizontal line, constrain vertically (y coordinate). */ - guide->normal_to_line = component_vectors[Geom::Y]; + guide->normal_to_line = Geom::Point(0., 1.); } else if (value && !strcmp(value, "vertical")) { - guide->normal_to_line = component_vectors[Geom::X]; + guide->normal_to_line = Geom::Point(1., 0.); } else if (value) { gchar ** strarray = g_strsplit(value, ",", 2); double newx, newy; @@ -220,11 +220,11 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value) guide->normal_to_line = direction; } else { // default to vertical line for bad arguments - guide->normal_to_line = component_vectors[Geom::X]; + guide->normal_to_line = Geom::Point(1., 0.); } } else { // default to vertical line for bad arguments - guide->normal_to_line = component_vectors[Geom::X]; + guide->normal_to_line = Geom::Point(1., 0.); } sp_guide_set_normal(*guide, guide->normal_to_line, false); } @@ -493,11 +493,11 @@ char *sp_guide_description(SPGuide const *guide, const bool verbose) gchar *shortcuts = g_strdup_printf("; %s", _("Shift+drag to rotate, Ctrl+drag to move origin, Del to delete")); - if ( are_near(guide->normal_to_line, component_vectors[X]) || - are_near(guide->normal_to_line, -component_vectors[X]) ) { + if ( are_near(guide->normal_to_line, Geom::Point(1., 0.)) || + are_near(guide->normal_to_line, -Geom::Point(1., 0.)) ) { descr = g_strdup_printf(_("vertical, at %s"), position_string_x->str); - } else if ( are_near(guide->normal_to_line, component_vectors[Y]) || - are_near(guide->normal_to_line, -component_vectors[Y]) ) { + } else if ( are_near(guide->normal_to_line, Geom::Point(0., 1.)) || + are_near(guide->normal_to_line, -Geom::Point(0., 1.)) ) { descr = g_strdup_printf(_("horizontal, at %s"), position_string_y->str); } else { double const radians = guide->angle(); -- cgit v1.2.3