diff options
| author | su_v <suv-sf@users.sourceforge.net> | 2015-11-15 08:31:53 +0000 |
|---|---|---|
| committer | ~suv <suv-sf@users.sourceforge.net> | 2015-11-15 08:31:53 +0000 |
| commit | ac8b388ada4e781b29570276ed9f95fd6f4dafff (patch) | |
| tree | 268308a8a304debb7cf2f84e1255d5633dee5eef /src | |
| parent | Extensions. Fix view center for Render extensions applied in transformed laye... (diff) | |
| parent | Translations. Italian translation update. (diff) | |
| download | inkscape-ac8b388ada4e781b29570276ed9f95fd6f4dafff.tar.gz inkscape-ac8b388ada4e781b29570276ed9f95fd6f4dafff.zip | |
merge from trunk (r14473)
(bzr r14425.1.3)
Diffstat (limited to 'src')
113 files changed, 3483 insertions, 1342 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ec7713464..30af55925 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -531,6 +531,10 @@ endif() add_dependencies(inkscape inkscape_version) +if (NOT "${WITH_EXT_GDL}") + list (APPEND INKSCAPE_LIBS "gdl_LIB") +endif() + set(INKSCAPE_TARGET_LIBS # order from automake #sp_LIB @@ -542,7 +546,6 @@ set(INKSCAPE_TARGET_LIBS croco_LIB avoid_LIB - gdl_LIB cola_LIB vpsc_LIB livarot_LIB diff --git a/src/box3d.cpp b/src/box3d.cpp index dc04a2eb6..c4c2728e4 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -50,6 +50,11 @@ SPBox3D::SPBox3D() : SPGroup() { this->persp_href = NULL; this->persp_ref = new Persp3DReference(this); + + /* we initialize the z-orders to zero so that they are updated during dragging */ + for (int i = 0; i < 6; ++i) { + z_orders[i] = 0; + } } SPBox3D::~SPBox3D() { @@ -902,7 +907,7 @@ box3d_swap_sides(int z_orders[6], Box3D::Axis axis) { } } - if (pos1 != -1){ + if ((pos1 != -1) && (pos2 != -1)){ int tmp = z_orders[pos1]; z_orders[pos1] = z_orders[pos2]; z_orders[pos2] = tmp; diff --git a/src/conn-avoid-ref.cpp b/src/conn-avoid-ref.cpp index ec9aba793..4c9665fa0 100644 --- a/src/conn-avoid-ref.cpp +++ b/src/conn-avoid-ref.cpp @@ -253,7 +253,7 @@ static std::vector<Geom::Point> approxItemWithPoints(SPItem const *item, const G SPGroup* group = SP_GROUP(item); // consider all first-order children std::vector<SPItem*> itemlist = sp_item_group_item_list(group); - for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i != itemlist.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i != itemlist.end(); ++i) { SPItem* child_item = *i; std::vector<Geom::Point> child_points = approxItemWithPoints(child_item, item_transform * child_item->transform); poly_points.insert(poly_points.end(), child_points.begin(), child_points.end()); diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index 02c18339b..e66da90fb 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -195,7 +195,7 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write sp_css_attr_unset_uris(css_write); prefs->mergeStyle("/desktop/style", css_write); std::vector<SPItem*> const itemlist = desktop->selection->itemList(); - for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i!= itemlist.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i!= itemlist.end(); ++i) { /* last used styles for 3D box faces are stored separately */ SPObject *obj = *i; Box3DSide *side = dynamic_cast<Box3DSide *>(obj); @@ -235,7 +235,7 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write css_no_text = sp_css_attr_unset_text(css_no_text); std::vector<SPItem*> const itemlist = desktop->selection->itemList(); - for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i!= itemlist.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i!= itemlist.end(); ++i) { SPItem *item = *i; // If not text, don't apply text attributes (can a group have text attributes? Yes! FIXME) @@ -447,7 +447,7 @@ stroke_average_width (const std::vector<SPItem*> &objects) gdouble avgwidth = 0.0; bool notstroked = true; int n_notstroked = 0; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPItem *item = *i; if (!item) { continue; @@ -513,7 +513,7 @@ objects_query_fillstroke (const std::vector<SPItem*> &objects, SPStyle *style_re prev[0] = prev[1] = prev[2] = 0.0; bool same_color = true; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i!= objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i!= objects.end(); ++i) { SPObject *obj = *i; if (!obj) { continue; @@ -697,7 +697,7 @@ objects_query_opacity (const std::vector<SPItem*> &objects, SPStyle *style_res) guint opacity_items = 0; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!obj) { continue; @@ -753,7 +753,7 @@ objects_query_strokewidth (const std::vector<SPItem*> &objects, SPStyle *style_r int n_stroked = 0; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!obj) { continue; @@ -827,7 +827,7 @@ objects_query_miterlimit (const std::vector<SPItem*> &objects, SPStyle *style_re gdouble prev_ml = -1; bool same_ml = true; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!dynamic_cast<SPItem *>(obj)) { continue; @@ -886,7 +886,7 @@ objects_query_strokecap (const std::vector<SPItem*> &objects, SPStyle *style_res bool same_cap = true; int n_stroked = 0; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!dynamic_cast<SPItem *>(obj)) { continue; @@ -940,7 +940,7 @@ objects_query_strokejoin (const std::vector<SPItem*> &objects, SPStyle *style_re bool same_join = true; int n_stroked = 0; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!dynamic_cast<SPItem *>(obj)) { continue; @@ -1003,7 +1003,7 @@ objects_query_fontnumbers (const std::vector<SPItem*> &objects, SPStyle *style_r int texts = 0; int no_size = 0; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!isTextualItem(obj)) { @@ -1122,7 +1122,7 @@ objects_query_fontstyle (const std::vector<SPItem*> &objects, SPStyle *style_res int texts = 0; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!isTextualItem(obj)) { @@ -1192,7 +1192,7 @@ objects_query_fontvariants (const std::vector<SPItem*> &objects, SPStyle *style_ caps_res->value = 0; numeric_res->value = 0; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!isTextualItem(obj)) { @@ -1268,7 +1268,7 @@ objects_query_fontfeaturesettings (const std::vector<SPItem*> &objects, SPStyle } style_res->font_feature_settings.set = FALSE; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; // std::cout << " " << reinterpret_cast<SPObject*>(i->data)->getId() << std::endl; @@ -1336,7 +1336,7 @@ objects_query_baselines (const std::vector<SPItem*> &objects, SPStyle *style_res int texts = 0; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!isTextualItem(obj)) { @@ -1424,7 +1424,7 @@ objects_query_fontfamily (const std::vector<SPItem*> &objects, SPStyle *style_re } style_res->font_family.set = FALSE; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; // std::cout << " " << reinterpret_cast<SPObject*>(i->data)->getId() << std::endl; @@ -1480,7 +1480,7 @@ objects_query_fontspecification (const std::vector<SPItem*> &objects, SPStyle *s } style_res->font_specification.set = FALSE; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; // std::cout << " " << reinterpret_cast<SPObject*>(i->data)->getId() << std::endl; @@ -1538,7 +1538,7 @@ objects_query_blend (const std::vector<SPItem*> &objects, SPStyle *style_res) bool same_blend = true; guint items = 0; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!obj) { continue; @@ -1628,7 +1628,7 @@ objects_query_blur (const std::vector<SPItem*> &objects, SPStyle *style_res) guint blur_items = 0; guint items = 0; - for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = objects.begin(); i != objects.end(); ++i) { SPObject *obj = *i; if (!obj) { continue; diff --git a/src/display/canvas-text.cpp b/src/display/canvas-text.cpp index 5ad87b4ef..7c019caf5 100644 --- a/src/display/canvas-text.cpp +++ b/src/display/canvas-text.cpp @@ -266,10 +266,10 @@ sp_canvastext_set_coords (SPCanvasText *ct, gdouble x0, gdouble y0) void sp_canvastext_set_coords (SPCanvasText *ct, const Geom::Point start) { - Geom::Point pos = ct->desktop->doc2dt(start); - - g_return_if_fail (ct != NULL); + g_return_if_fail (ct && ct->desktop); g_return_if_fail (SP_IS_CANVASTEXT (ct)); + + Geom::Point pos = ct->desktop->doc2dt(start); if (DIFFER (pos[0], ct->s[Geom::X]) || DIFFER (pos[1], ct->s[Geom::Y])) { ct->s[Geom::X] = pos[0]; diff --git a/src/display/curve.cpp b/src/display/curve.cpp index 3024d1276..b6c387034 100644 --- a/src/display/curve.cpp +++ b/src/display/curve.cpp @@ -496,7 +496,7 @@ SPCurve::append(SPCurve const *curve2, _pathv.push_back( (*it) ); } - for (it++; it != curve2->_pathv.end(); ++it) { + for (++it; it != curve2->_pathv.end(); ++it) { _pathv.push_back( (*it) ); } } else { diff --git a/src/document.cpp b/src/document.cpp index c64bf3ed5..0e49f23e2 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1450,7 +1450,7 @@ std::vector<SPItem*> SPDocument::getItemsPartiallyInBox(unsigned int dkey, Geom: return find_items_in_area(x, SP_GROUP(this->root), dkey, box, overlaps); } -std::vector<SPItem*> SPDocument::getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points) const +std::vector<SPItem*> SPDocument::getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points, bool all_layers, size_t limit) const { std::vector<SPItem*> items; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -1464,11 +1464,25 @@ std::vector<SPItem*> SPDocument::getItemsAtPoints(unsigned const key, std::vecto // Cache a flattened SVG DOM to speed up selection. std::deque<SPItem*> nodes; build_flat_item_list(&nodes, key, SP_GROUP(this->root), true, false, NULL); - + SPObject *current_layer = SP_ACTIVE_DESKTOP->currentLayer(); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + Inkscape::LayerModel *layer_model = NULL; + if(desktop){ + layer_model = desktop->layers; + } + size_t item_counter = 0; for(int i = points.size()-1;i>=0; i--) { SPItem *item = find_item_at_point(&nodes, key, points[i]); if (item && items.end()==find(items.begin(),items.end(), item)) - items.push_back(item); + if(all_layers || (layer_model && layer_model->layerForObject(item) == current_layer)){ + items.push_back(item); + item_counter++; + //limit 0 = no limit + if(item_counter == limit){ + prefs->setDouble("/options/cursortolerance/value", saved_delta); + return items; + } + } } // and now we restore it back diff --git a/src/document.h b/src/document.h index dd1e295a2..be3f106d8 100644 --- a/src/document.h +++ b/src/document.h @@ -262,7 +262,7 @@ public: std::vector<SPItem*> getItemsInBox(unsigned int dkey, Geom::Rect const &box) const; std::vector<SPItem*> getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const; SPItem *getItemAtPoint(unsigned int key, Geom::Point const &p, bool into_groups, SPItem *upto = NULL) const; - std::vector<SPItem*> getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points) const; + std::vector<SPItem*> getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points, bool all_layers = true, size_t limit = 0) const; SPItem *getGroupAtPoint(unsigned int key, Geom::Point const &p) const; void changeUriAndHrefs(char const *uri); diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp index 29c2b5537..27d19fdff 100644 --- a/src/extension/execution-env.cpp +++ b/src/extension/execution-env.cpp @@ -61,7 +61,7 @@ ExecutionEnv::ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Imp if (desktop != NULL) { std::vector<SPItem*> selected = desktop->getSelection()->itemList(); - for(std::vector<SPItem*>::const_iterator x = selected.begin(); x != selected.end(); x++){ + for(std::vector<SPItem*>::const_iterator x = selected.begin(); x != selected.end(); ++x){ Glib::ustring selected_id; selected_id = (*x)->getId(); _selected.insert(_selected.end(), selected_id); diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index 5a5553e97..a4561fd11 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -295,7 +295,7 @@ static void sp_group_render(SPGroup *group, CairoRenderContext *ctx) TRACE(("sp_group_render opacity: %f\n", SP_SCALE24_TO_FLOAT(item->style->opacity.value))); std::vector<SPObject*> l(group->childList(false)); - for(std::vector<SPObject*>::const_iterator x = l.begin(); x!= l.end(); x++){ + for(std::vector<SPObject*>::const_iterator x = l.begin(); x!= l.end(); ++x){ SPItem *item = dynamic_cast<SPItem*>(*x); if (item) { renderer->renderItem(ctx, item); diff --git a/src/extension/internal/emf-inout.cpp b/src/extension/internal/emf-inout.cpp index e88cf3d42..68b38f5ee 100644 --- a/src/extension/internal/emf-inout.cpp +++ b/src/extension/internal/emf-inout.cpp @@ -1174,10 +1174,7 @@ Emf::select_extpen(PEMF_CALLBACK_DATA d, int index) if (!d->dc[d->level].style.stroke_dasharray.values.empty() && (d->level==0 || (d->level>0 && d->dc[d->level].style.stroke_dasharray.values!=d->dc[d->level-1].style.stroke_dasharray.values))) d->dc[d->level].style.stroke_dasharray.values.clear(); for (unsigned int i=0; i<pEmr->elp.elpNumEntries; i++) { -// Doing it this way typically results in a pattern that is tiny, better to assume the array -// is the same scale as for dot/dash below, that is, no scaling should be applied -// double dash_length = pix_to_abs_size( d, pEmr->elp.elpStyleEntry[i] ); - double dash_length = pEmr->elp.elpStyleEntry[i]; + double dash_length = pix_to_abs_size( d, pEmr->elp.elpStyleEntry[i] ); d->dc[d->level].style.stroke_dasharray.values.push_back(dash_length); } d->dc[d->level].style.stroke_dasharray.set = 1; diff --git a/src/extension/internal/emf-print.cpp b/src/extension/internal/emf-print.cpp index 5b8aae655..cc798cc5f 100644 --- a/src/extension/internal/emf-print.cpp +++ b/src/extension/internal/emf-print.cpp @@ -708,7 +708,7 @@ int PrintEmf::create_pen(SPStyle const *style, const Geom::Affine &transform) n_dash = style->stroke_dasharray.values.size(); dash = new uint32_t[n_dash]; for (i = 0; i < n_dash; i++) { - dash[i] = style->stroke_dasharray.values[i]; + dash[i] = MAX(1, (uint32_t) round(scale * style->stroke_dasharray.values[i] * PX2WORLD)); } } } diff --git a/src/extension/internal/latex-text-renderer.cpp b/src/extension/internal/latex-text-renderer.cpp index 5933dd526..dec75aeb6 100644 --- a/src/extension/internal/latex-text-renderer.cpp +++ b/src/extension/internal/latex-text-renderer.cpp @@ -229,7 +229,7 @@ LaTeXTextRenderer::writePostamble() void LaTeXTextRenderer::sp_group_render(SPGroup *group) { std::vector<SPObject*> l = (group->childList(false)); - for(std::vector<SPObject*>::const_iterator x = l.begin(); x != l.end(); x++){ + for(std::vector<SPObject*>::const_iterator x = l.begin(); x != l.end(); ++x){ SPItem *item = dynamic_cast<SPItem*>(*x); if (item) { renderItem(item); diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index 409e9f0e6..886bf484d 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -1571,7 +1571,7 @@ void sp_gradient_invert_selected_gradients(SPDesktop *desktop, Inkscape::PaintTa Inkscape::Selection *selection = desktop->getSelection(); const std::vector<SPItem*> list=selection->itemList(); - for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); ++i) { sp_item_gradient_invert_vector_color(*i, fill_or_stroke); } @@ -1596,7 +1596,7 @@ void sp_gradient_reverse_selected_gradients(SPDesktop *desktop) drag->selected_reverse_vector(); } else { // If no drag or no dragger selected, act on selection (both fill and stroke gradients) const std::vector<SPItem*> list=selection->itemList(); - for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); ++i) { sp_item_gradient_reverse_vector(*i, Inkscape::FOR_FILL); sp_item_gradient_reverse_vector(*i, Inkscape::FOR_STROKE); } diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index b5a988729..f94ffb838 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -2083,7 +2083,7 @@ void GrDrag::updateDraggers() g_return_if_fail(this->selection != NULL); std::vector<SPItem*> list = this->selection->itemList(); - for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); ++i) { SPItem *item = *i; SPStyle *style = item->style; @@ -2152,7 +2152,7 @@ void GrDrag::updateLines() g_return_if_fail(this->selection != NULL); std::vector<SPItem*> list = this->selection->itemList(); - for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); ++i) { SPItem *item = *i; SPStyle *style = item->style; @@ -2296,7 +2296,7 @@ void GrDrag::updateLevels() g_return_if_fail (this->selection != NULL); std::vector<SPItem*> list = this->selection->itemList(); - for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = list.begin(); i != list.end(); ++i) { SPItem *item = *i; Geom::OptRect rect = item->desktopVisualBounds(); if (rect) { diff --git a/src/graphlayout.cpp b/src/graphlayout.cpp index 40994347c..9b67ba0b5 100644 --- a/src/graphlayout.cpp +++ b/src/graphlayout.cpp @@ -89,7 +89,7 @@ struct CheckProgress : TestConvergence { * not connectors in filtered */ void filterConnectors(std::vector<SPItem*> const &items, list<SPItem *> &filtered) { - for(std::vector<SPItem*>::const_iterator i = items.begin();i !=items.end(); i++){ + for(std::vector<SPItem*>::const_iterator i = items.begin();i !=items.end(); ++i){ SPItem *item = *i; if(!isConnector(item)) { filtered.push_back(item); diff --git a/src/libcroco/cr-additional-sel.c b/src/libcroco/cr-additional-sel.c index 5a37eba6c..c34b8d243 100644 --- a/src/libcroco/cr-additional-sel.c +++ b/src/libcroco/cr-additional-sel.c @@ -247,7 +247,7 @@ cr_additional_sel_to_string (CRAdditionalSel const * a_this) guchar *name = NULL; if (cur->content.class_name) { - name = g_strndup + name = (guchar *) g_strndup (cur->content.class_name->stryng->str, cur->content.class_name->stryng->len); @@ -266,8 +266,8 @@ cr_additional_sel_to_string (CRAdditionalSel const * a_this) { guchar *name = NULL; - if (cur->content.class_name) { - name = g_strndup + if (cur->content.id_name) { + name = (guchar *) g_strndup (cur->content.id_name->stryng->str, cur->content.id_name->stryng->len); @@ -323,7 +323,7 @@ cr_additional_sel_to_string (CRAdditionalSel const * a_this) } if (str_buf) { - result = str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } @@ -347,7 +347,7 @@ cr_additional_sel_one_to_string (CRAdditionalSel const *a_this) guchar *name = NULL; if (a_this->content.class_name) { - name = g_strndup + name = (guchar *) g_strndup (a_this->content.class_name->stryng->str, a_this->content.class_name->stryng->len); @@ -366,8 +366,8 @@ cr_additional_sel_one_to_string (CRAdditionalSel const *a_this) { guchar *name = NULL; - if (a_this->content.class_name) { - name = g_strndup + if (a_this->content.id_name) { + name = (guchar *) g_strndup (a_this->content.id_name->stryng->str, a_this->content.id_name->stryng->len); @@ -422,7 +422,7 @@ cr_additional_sel_one_to_string (CRAdditionalSel const *a_this) } if (str_buf) { - result = str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } diff --git a/src/libcroco/cr-attr-sel.c b/src/libcroco/cr-attr-sel.c index 7976ff1f8..31d9da579 100644 --- a/src/libcroco/cr-attr-sel.c +++ b/src/libcroco/cr-attr-sel.c @@ -123,10 +123,10 @@ cr_attr_sel_to_string (CRAttrSel const * a_this) if (cur->name) { guchar *name = NULL; - name = g_strndup (cur->name->stryng->str, + name = (guchar *) g_strndup (cur->name->stryng->str, cur->name->stryng->len); if (name) { - g_string_append (str_buf, name); + g_string_append (str_buf, (const gchar *) name); g_free (name); name = NULL; } @@ -135,7 +135,7 @@ cr_attr_sel_to_string (CRAttrSel const * a_this) if (cur->value) { guchar *value = NULL; - value = g_strndup (cur->value->stryng->str, + value = (guchar *) g_strndup (cur->value->stryng->str, cur->value->stryng->len); if (value) { switch (cur->match_way) { @@ -168,7 +168,7 @@ cr_attr_sel_to_string (CRAttrSel const * a_this) } if (str_buf) { - result = str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); } diff --git a/src/libcroco/cr-cascade.c b/src/libcroco/cr-cascade.c index 31e938bb7..9f8dbdf8d 100644 --- a/src/libcroco/cr-cascade.c +++ b/src/libcroco/cr-cascade.c @@ -75,8 +75,8 @@ cr_cascade_new (CRStyleSheet * a_author_sheet, PRIVATE (result) = g_try_malloc (sizeof (CRCascadePriv)); if (!PRIVATE (result)) { - g_free(result); cr_utils_trace_info ("Out of memory"); + g_free (result); return NULL; } memset (PRIVATE (result), 0, sizeof (CRCascadePriv)); diff --git a/src/libcroco/cr-declaration.c b/src/libcroco/cr-declaration.c index ab150a9e4..69c24b376 100644 --- a/src/libcroco/cr-declaration.c +++ b/src/libcroco/cr-declaration.c @@ -48,7 +48,7 @@ dump (CRDeclaration const * a_this, FILE * a_fp, glong a_indent) g_return_if_fail (a_this); - str = cr_declaration_to_string (a_this, a_indent); + str = (guchar *) cr_declaration_to_string (a_this, a_indent); if (str) { fprintf (a_fp, "%s", str); g_free (str); @@ -130,7 +130,7 @@ cr_declaration_parse_from_buf (CRStatement * a_statement, g_return_val_if_fail (a_statement->type == RULESET_STMT, NULL); - parser = cr_parser_new_from_buf ((guchar*)a_str, strlen (a_str), a_enc, FALSE); + parser = cr_parser_new_from_buf ((guchar*)a_str, strlen ((const char *) a_str), a_enc, FALSE); g_return_val_if_fail (parser, NULL); status = cr_parser_try_to_skip_spaces_and_comments (parser); @@ -194,7 +194,7 @@ cr_declaration_parse_list_from_buf (const guchar * a_str, g_return_val_if_fail (a_str, NULL); - parser = cr_parser_new_from_buf ((guchar*)a_str, strlen (a_str), a_enc, FALSE); + parser = cr_parser_new_from_buf ((guchar*)a_str, strlen ((const char *) a_str), a_enc, FALSE); g_return_val_if_fail (parser, NULL); status = cr_parser_get_tknzr (parser, &tokenizer); if (status != CR_OK || !tokenizer) { @@ -243,10 +243,10 @@ cr_declaration_parse_list_from_buf (const guchar * a_str, if (status != CR_OK || !property) { if (status == CR_END_OF_INPUT_ERROR) { status = CR_OK; // simply the end of input, do not delete what we got so far, just finish - break; + break; } else { continue; // even if one declaration is broken, it's no reason to discard others (see http://www.w3.org/TR/CSS21/syndata.html#declaration) - } + } } cur_decl = cr_declaration_new (NULL, property, value); if (cur_decl) { @@ -504,7 +504,7 @@ cr_declaration_to_string (CRDeclaration const * a_this, gulong a_indent) { GString *stringue = NULL; - guchar *str = NULL, + gchar *str = NULL, *result = NULL; g_return_val_if_fail (a_this, NULL); @@ -581,7 +581,7 @@ cr_declaration_list_to_string (CRDeclaration const * a_this, gulong a_indent) stringue = g_string_new (NULL); for (cur = a_this; cur; cur = cur->next) { - str = cr_declaration_to_string (cur, a_indent); + str = (guchar *) cr_declaration_to_string (cur, a_indent); if (str) { g_string_append_printf (stringue, "%s;", str); g_free (str); @@ -589,7 +589,7 @@ cr_declaration_list_to_string (CRDeclaration const * a_this, gulong a_indent) break; } if (stringue && stringue->str) { - result = stringue->str; + result = (guchar *) stringue->str; g_string_free (stringue, FALSE); } @@ -620,7 +620,7 @@ cr_declaration_list_to_string2 (CRDeclaration const * a_this, stringue = g_string_new (NULL); for (cur = a_this; cur; cur = cur->next) { - str = cr_declaration_to_string (cur, a_indent); + str = (guchar *) cr_declaration_to_string (cur, a_indent); if (str) { if (a_one_decl_per_line == TRUE) { if (cur->next) @@ -628,21 +628,21 @@ cr_declaration_list_to_string2 (CRDeclaration const * a_this, "%s;\n", str); else g_string_append (stringue, - str); + (const gchar *) str); } else { if (cur->next) g_string_append_printf (stringue, "%s;", str); else g_string_append (stringue, - str); + (const gchar *) str); } g_free (str); } else break; } if (stringue && stringue->str) { - result = stringue->str; + result = (guchar *) stringue->str; g_string_free (stringue, FALSE); } @@ -714,7 +714,7 @@ cr_declaration_get_by_prop_name (CRDeclaration * a_this, && cur->property->stryng && cur->property->stryng->str) { if (!strcmp (cur->property->stryng->str, - a_prop)) { + (const char *) a_prop)) { return cur; } } diff --git a/src/libcroco/cr-enc-handler.c b/src/libcroco/cr-enc-handler.c index b3e5b7eba..646bf1fe2 100644 --- a/src/libcroco/cr-enc-handler.c +++ b/src/libcroco/cr-enc-handler.c @@ -122,7 +122,7 @@ cr_enc_handler_resolve_enc_alias (const guchar * a_alias_name, g_ascii_strup (alias_name_up, -1); for (i = 0; gv_default_aliases[i].name; i++) { - if (!strcmp (gv_default_aliases[i].name, alias_name_up)) { + if (!strcmp (gv_default_aliases[i].name, (const gchar *) alias_name_up)) { *a_enc = gv_default_aliases[i].encoding; status = CR_OK; break; diff --git a/src/libcroco/cr-fonts.c b/src/libcroco/cr-fonts.c index 10f26c99c..78e261149 100644 --- a/src/libcroco/cr-fonts.c +++ b/src/libcroco/cr-fonts.c @@ -78,7 +78,7 @@ cr_font_family_to_string_real (CRFontFamily const * a_this, if (a_this->prev) { g_string_append_printf (*a_string, ", %s", name); } else { - g_string_append (*a_string, name); + g_string_append (*a_string, (const gchar *) name); } } if (a_walk_list == TRUE && a_this->next) { @@ -187,7 +187,7 @@ cr_font_family_to_string (CRFontFamily const * a_this, GString *stringue = NULL; if (!a_this) { - result = g_strdup ("NULL"); + result = (guchar *) g_strdup ("NULL"); g_return_val_if_fail (result, NULL); return result; } @@ -196,7 +196,7 @@ cr_font_family_to_string (CRFontFamily const * a_this, &stringue); if (status == CR_OK && stringue) { - result = stringue->str; + result = (guchar *) stringue->str; g_string_free (stringue, FALSE); stringue = NULL; @@ -420,7 +420,7 @@ cr_font_size_set_predefined_absolute_font_size (CRFontSize *a_this, enum CRPredefinedAbsoluteFontSize a_predefined) { g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - g_return_val_if_fail ((unsigned)a_predefined < NB_FONT_SIZE_TYPE, + g_return_val_if_fail ((unsigned)a_predefined < NB_PREDEFINED_ABSOLUTE_FONT_SIZES, CR_BAD_PARAM_ERROR) ; a_this->type = PREDEFINED_ABSOLUTE_FONT_SIZE ; @@ -526,7 +526,7 @@ cr_font_size_to_string (CRFontSize const * a_this) (a_this->value.predefined)); break; case ABSOLUTE_FONT_SIZE: - str = cr_num_to_string (&a_this->value.absolute); + str = (gchar *) cr_num_to_string (&a_this->value.absolute); break; case RELATIVE_FONT_SIZE: str = g_strdup (cr_relative_font_size_to_string @@ -683,7 +683,7 @@ cr_font_size_adjust_to_string (CRFontSizeAdjust const * a_this) break; case FONT_SIZE_ADJUST_NUMBER: if (a_this->num) - str = cr_num_to_string (a_this->num); + str = (gchar *) cr_num_to_string (a_this->num); else str = g_strdup ("unknow font-size-adjust property value"); /* Should raise an error no?*/ break; diff --git a/src/libcroco/cr-input.c b/src/libcroco/cr-input.c index 3cc283e01..5395ae214 100644 --- a/src/libcroco/cr-input.c +++ b/src/libcroco/cr-input.c @@ -746,7 +746,7 @@ enum CRStatus cr_input_peek_char (CRInput const * a_this, guint32 * a_char) { enum CRStatus status = CR_OK; - glong consumed = 0, + gulong consumed = 0, nb_bytes_left = 0; g_return_val_if_fail (a_this && PRIVATE (a_this) diff --git a/src/libcroco/cr-num.c b/src/libcroco/cr-num.c index a5c320bf2..6cc5150a1 100644 --- a/src/libcroco/cr-num.c +++ b/src/libcroco/cr-num.c @@ -105,7 +105,7 @@ cr_num_to_string (CRNum const * a_this) test_val = a_this->val - (glong) a_this->val; if (!test_val) { - tmp_char1 = g_strdup_printf ("%ld", (glong) a_this->val); + tmp_char1 = (guchar *) g_strdup_printf ("%ld", (glong) a_this->val); } else { /* We can't use g_ascii_dtostr, because that sometimes uses e notation (which wouldn't be a valid number in CSS). */ @@ -195,7 +195,7 @@ cr_num_to_string (CRNum const * a_this) } if (tmp_char2) { - result = g_strconcat (tmp_char1, tmp_char2, NULL); + result = (guchar *) g_strconcat ((gchar *) tmp_char1, tmp_char2, NULL); g_free (tmp_char1); } else { result = tmp_char1; diff --git a/src/libcroco/cr-om-parser.c b/src/libcroco/cr-om-parser.c index c1acb855c..596cd6e6b 100644 --- a/src/libcroco/cr-om-parser.c +++ b/src/libcroco/cr-om-parser.c @@ -39,9 +39,6 @@ struct _CROMParserPriv { #define PRIVATE(a_this) ((a_this)->priv) -// Unfortunately, C does not allow unnamed function arguments, so use this macro instead... -#define UNUSED(x) (void)(x) - /* *Forward declaration of a type defined later *in this file. @@ -210,12 +207,12 @@ static void start_font_face (CRDocHandler * a_this, CRParsingLocation *a_location) { - UNUSED(a_location); - enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; + (void) a_location; + g_return_if_fail (a_this); g_return_if_fail (a_this); @@ -307,8 +304,6 @@ static void charset (CRDocHandler * a_this, CRString * a_charset, CRParsingLocation *a_location) { - UNUSED(a_location); - enum CRStatus status = CR_OK; CRStatement *stmt = NULL, *stmt2 = NULL; @@ -317,6 +312,8 @@ charset (CRDocHandler * a_this, CRString * a_charset, ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; + (void) a_location; + g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); @@ -347,12 +344,12 @@ start_page (CRDocHandler * a_this, CRString * a_pseudo, CRParsingLocation *a_location) { - UNUSED(a_location); - enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; + (void) a_location; + g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); @@ -390,18 +387,21 @@ end_page (CRDocHandler * a_this, CRString * a_page, CRString * a_pseudo_page) { - UNUSED(a_page); - UNUSED(a_pseudo_page); - enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; CRStatement *stmt = NULL; + (void) a_page; + (void) a_pseudo_page; + g_return_if_fail (a_this); + ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt->cur_stmt && ctxt->cur_stmt->type == AT_PAGE_RULE_STMT && ctxt->stylesheet); @@ -419,6 +419,8 @@ end_page (CRDocHandler * a_this, cr_statement_destroy (ctxt->cur_stmt); ctxt->cur_stmt = NULL; } + a_page = NULL; /*keep compiler happy */ + a_pseudo_page = NULL; /*keep compiler happy */ } static void @@ -426,13 +428,13 @@ start_media (CRDocHandler * a_this, GList * a_media_list, CRParsingLocation *a_location) { - UNUSED(a_location); - enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; GList *media_list = NULL; + (void) a_location; + g_return_if_fail (a_this); ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); @@ -456,17 +458,20 @@ start_media (CRDocHandler * a_this, static void end_media (CRDocHandler * a_this, GList * a_media_list) { - UNUSED(a_media_list); - enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; CRStatement *stmts = NULL; + (void) a_media_list; + g_return_if_fail (a_this); + ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt && ctxt->cur_media_stmt && ctxt->cur_media_stmt->type == AT_MEDIA_RULE_STMT @@ -474,6 +479,7 @@ end_media (CRDocHandler * a_this, GList * a_media_list) stmts = cr_statement_append (ctxt->stylesheet->statements, ctxt->cur_media_stmt); + if (!stmts) { cr_statement_destroy (ctxt->cur_media_stmt); ctxt->cur_media_stmt = NULL; @@ -484,6 +490,7 @@ end_media (CRDocHandler * a_this, GList * a_media_list) ctxt->cur_stmt = NULL ; ctxt->cur_media_stmt = NULL ; + a_media_list = NULL; } static void @@ -493,9 +500,6 @@ import_style (CRDocHandler * a_this, CRString * a_uri_default_ns, CRParsingLocation *a_location) { - UNUSED(a_uri_default_ns); - UNUSED(a_location); - enum CRStatus status = CR_OK; CRString *uri = NULL; CRStatement *stmt = NULL, @@ -504,17 +508,26 @@ import_style (CRDocHandler * a_this, ParsingContext **ctxtptr = NULL; GList *media_list = NULL ; + (void) a_uri_default_ns; + (void) a_location; + g_return_if_fail (a_this); + ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt->stylesheet); uri = cr_string_dup (a_uri) ; + if (a_media_list) media_list = cr_utils_dup_glist_of_cr_string (a_media_list) ; + stmt = cr_statement_new_at_import_rule (ctxt->stylesheet, uri, media_list, NULL); + if (!stmt) goto error; @@ -546,6 +559,7 @@ import_style (CRDocHandler * a_this, cr_statement_destroy (stmt); stmt = NULL; } + a_uri_default_ns = NULL; /*keep compiler happy */ } static void @@ -572,16 +586,19 @@ start_selector (CRDocHandler * a_this, CRSelector * a_selector_list) static void end_selector (CRDocHandler * a_this, CRSelector * a_selector_list) { - UNUSED(a_selector_list); - enum CRStatus status = CR_OK; ParsingContext *ctxt = NULL; ParsingContext **ctxtptr = NULL; + (void) a_selector_list; + g_return_if_fail (a_this); + ctxtptr = &ctxt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) ctxtptr); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt->cur_stmt && ctxt->stylesheet); if (ctxt->cur_stmt) { @@ -621,6 +638,8 @@ end_selector (CRDocHandler * a_this, CRSelector * a_selector_list) } } + + a_selector_list = NULL; /*keep compiler happy */ } static void diff --git a/src/libcroco/cr-parser.c b/src/libcroco/cr-parser.c index 69b521496..544b35ab0 100644 --- a/src/libcroco/cr-parser.c +++ b/src/libcroco/cr-parser.c @@ -78,7 +78,7 @@ typedef struct _CRParserError CRParserError; *parsing routines. */ struct _CRParserError { - gchar *msg; + guchar *msg; enum CRStatus status; glong line; glong column; @@ -197,9 +197,9 @@ if ((a_status) != CR_OK) \ */ #define PEEK_NEXT_CHAR(a_this, a_to_char) \ {\ -enum CRStatus status ; \ -status = cr_tknzr_peek_char (PRIVATE (a_this)->tknzr, a_to_char) ; \ -CHECK_PARSING_STATUS (status, TRUE) \ +enum CRStatus pnc_status ; \ +pnc_status = cr_tknzr_peek_char (PRIVATE (a_this)->tknzr, a_to_char) ; \ +CHECK_PARSING_STATUS (pnc_status, TRUE) \ } /** @@ -374,11 +374,11 @@ static enum CRStatus cr_parser_parse_simple_selector (CRParser * a_this, static enum CRStatus cr_parser_parse_simple_sels (CRParser * a_this, CRSimpleSel ** a_sel); -static CRParserError *cr_parser_error_new (const gchar * a_msg, +static CRParserError *cr_parser_error_new (const guchar * a_msg, enum CRStatus); static void cr_parser_error_set_msg (CRParserError * a_this, - const gchar * a_msg); + const guchar * a_msg); static void cr_parser_error_dump (CRParserError * a_this); @@ -392,7 +392,7 @@ static void cr_parser_error_destroy (CRParserError * a_this); static enum CRStatus cr_parser_push_error (CRParser * a_this, - const gchar * a_msg, + const guchar * a_msg, enum CRStatus a_status); static enum CRStatus cr_parser_dump_err_stack (CRParser * a_this, @@ -411,7 +411,7 @@ static enum CRStatus *@return the newly built instance of #CRParserError. */ static CRParserError * -cr_parser_error_new (const gchar * a_msg, enum CRStatus a_status) +cr_parser_error_new (const guchar * a_msg, enum CRStatus a_status) { CRParserError *result = NULL; @@ -436,7 +436,7 @@ cr_parser_error_new (const gchar * a_msg, enum CRStatus a_status) *@param a_msg the new message. */ static void -cr_parser_error_set_msg (CRParserError * a_this, const gchar * a_msg) +cr_parser_error_set_msg (CRParserError * a_this, const guchar * a_msg) { g_return_if_fail (a_this); @@ -444,7 +444,7 @@ cr_parser_error_set_msg (CRParserError * a_this, const gchar * a_msg) g_free (a_this->msg); } - a_this->msg = g_strdup (a_msg); + a_this->msg = (guchar *) g_strdup ((const gchar *) a_msg); } /** @@ -515,7 +515,7 @@ cr_parser_error_destroy (CRParserError * a_this) */ static enum CRStatus cr_parser_push_error (CRParser * a_this, - const gchar * a_msg, enum CRStatus a_status) + const guchar * a_msg, enum CRStatus a_status) { enum CRStatus status = CR_OK; @@ -733,7 +733,7 @@ cr_parser_parse_stylesheet_core (CRParser * a_this) error: cr_parser_push_error - (a_this, "could not recognize next production", CR_ERROR); + (a_this, (const guchar *) "could not recognize next production", CR_ERROR); cr_parser_dump_err_stack (a_this, TRUE); @@ -1688,14 +1688,12 @@ cr_parser_parse_simple_selector (CRParser * a_this, CRSimpleSel ** a_sel) && token->u.unichar == '*') { int comb = (int)sel->type_mask | (int) UNIVERSAL_SELECTOR; sel->type_mask = (enum SimpleSelectorType)comb; - //sel->type_mask |= UNIVERSAL_SELECTOR; sel->name = cr_string_new_from_string ("*"); found_sel = TRUE; } else if (token && token->type == IDENT_TK) { sel->name = token->u.str; int comb = (int)sel->type_mask | (int) TYPE_SELECTOR; sel->type_mask = (enum SimpleSelectorType)comb; - //sel->type_mask |= TYPE_SELECTOR; token->u.str = NULL; found_sel = TRUE; } else { @@ -2707,7 +2705,7 @@ cr_parser_parse_stylesheet (CRParser * a_this) } cr_parser_push_error - (a_this, "could not recognize next production", CR_ERROR); + (a_this, (const guchar *) "could not recognize next production", CR_ERROR); if (PRIVATE (a_this)->sac_handler && PRIVATE (a_this)->sac_handler->unrecoverable_error) { @@ -3193,7 +3191,7 @@ cr_parser_parse_declaration (CRParser * a_this, CHECK_PARSING_STATUS_ERR (a_this, status, FALSE, - "while parsing declaration: next property is malformed", + (const guchar *) "while parsing declaration: next property is malformed", CR_SYNTAX_ERROR); READ_NEXT_CHAR (a_this, &cur_char); @@ -3202,7 +3200,7 @@ cr_parser_parse_declaration (CRParser * a_this, status = CR_PARSING_ERROR; cr_parser_push_error (a_this, - "while parsing declaration: this char must be ':'", + (const guchar *) "while parsing declaration: this char must be ':'", CR_SYNTAX_ERROR); goto error; } @@ -3213,7 +3211,7 @@ cr_parser_parse_declaration (CRParser * a_this, CHECK_PARSING_STATUS_ERR (a_this, status, FALSE, - "while parsing declaration: next expression is malformed", + (const guchar *) "while parsing declaration: next expression is malformed", CR_SYNTAX_ERROR); cr_parser_try_to_skip_spaces_and_comments (a_this); @@ -3353,7 +3351,7 @@ cr_parser_parse_ruleset (CRParser * a_this) ENSURE_PARSING_COND_ERR (a_this, cur_char == '{', - "while parsing rulset: current char should be '{'", + (const guchar *) "while parsing rulset: current char should be '{'", CR_SYNTAX_ERROR); if (PRIVATE (a_this)->sac_handler @@ -3417,7 +3415,7 @@ cr_parser_parse_ruleset (CRParser * a_this) } CHECK_PARSING_STATUS_ERR (a_this, status, FALSE, - "while parsing ruleset: next construction should be a declaration", + (const guchar *) "while parsing ruleset: next construction should be a declaration", CR_SYNTAX_ERROR); for (;;) { @@ -3459,7 +3457,7 @@ cr_parser_parse_ruleset (CRParser * a_this) READ_NEXT_CHAR (a_this, &cur_char); ENSURE_PARSING_COND_ERR (a_this, cur_char == '}', - "while parsing rulset: current char must be a '}'", + (const guchar *) "while parsing rulset: current char must be a '}'", CR_SYNTAX_ERROR); selector->location = end_parsing_location; diff --git a/src/libcroco/cr-pseudo.c b/src/libcroco/cr-pseudo.c index a46e69ed0..cee3fc869 100644 --- a/src/libcroco/cr-pseudo.c +++ b/src/libcroco/cr-pseudo.c @@ -68,11 +68,11 @@ cr_pseudo_to_string (CRPseudo const * a_this) goto error; } - name = g_strndup (a_this->name->stryng->str, + name = (guchar *) g_strndup (a_this->name->stryng->str, a_this->name->stryng->len); if (name) { - g_string_append (str_buf, name); + g_string_append (str_buf, (const gchar *) name); g_free (name); name = NULL; } @@ -83,11 +83,11 @@ cr_pseudo_to_string (CRPseudo const * a_this) if (a_this->name == NULL) goto error; - name = g_strndup (a_this->name->stryng->str, + name = (guchar *) g_strndup (a_this->name->stryng->str, a_this->name->stryng->len); if (a_this->extra) { - arg = g_strndup (a_this->extra->stryng->str, + arg = (guchar *) g_strndup (a_this->extra->stryng->str, a_this->extra->stryng->len); } @@ -97,7 +97,7 @@ cr_pseudo_to_string (CRPseudo const * a_this) name = NULL; if (arg) { - g_string_append (str_buf, arg); + g_string_append (str_buf, (const gchar *) arg); g_free (arg); arg = NULL; } @@ -107,7 +107,7 @@ cr_pseudo_to_string (CRPseudo const * a_this) } if (str_buf) { - result = str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } diff --git a/src/libcroco/cr-rgb.c b/src/libcroco/cr-rgb.c index 537343579..889f248b6 100644 --- a/src/libcroco/cr-rgb.c +++ b/src/libcroco/cr-rgb.c @@ -275,7 +275,7 @@ cr_rgb_to_string (CRRgb const * a_this) } if (str_buf) { - result = str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); } @@ -507,7 +507,7 @@ cr_rgb_set_from_hex_str (CRRgb * a_this, const guchar * a_hex) g_return_val_if_fail (a_this && a_hex, CR_BAD_PARAM_ERROR); - if (strlen (a_hex) == 3) { + if (strlen ((const char *) a_hex) == 3) { for (i = 0; i < 3; i++) { if (a_hex[i] >= '0' && a_hex[i] <= '9') { colors[i] = a_hex[i] - '0'; @@ -522,7 +522,7 @@ cr_rgb_set_from_hex_str (CRRgb * a_this, const guchar * a_hex) status = CR_UNKNOWN_TYPE_ERROR; } } - } else if (strlen (a_hex) == 6) { + } else if (strlen ((const char *) a_hex) == 6) { for (i = 0; i < 6; i++) { if (a_hex[i] >= '0' && a_hex[i] <= '9') { colors[i / 2] <<= 4; @@ -587,7 +587,7 @@ cr_rgb_set_from_term (CRRgb *a_this, const struct _CRTerm *a_value) } else { status = cr_rgb_set_from_name (a_this, - a_value->content.str->stryng->str) ; + (const guchar *) a_value->content.str->stryng->str) ; } } else { cr_utils_trace_info @@ -600,7 +600,7 @@ cr_rgb_set_from_term (CRRgb *a_this, const struct _CRTerm *a_value) && a_value->content.str->stryng->str) { status = cr_rgb_set_from_hex_str (a_this, - a_value->content.str->stryng->str) ; + (const guchar *) a_value->content.str->stryng->str) ; } else { cr_utils_trace_info ("a_value has NULL string value") ; @@ -656,8 +656,7 @@ cr_rgb_parse_from_buf (const guchar *a_str, g_return_val_if_fail (a_str, NULL); - parser = cr_parser_new_from_buf ((guchar*)a_str, strlen (a_str), - a_enc, FALSE) ; + parser = cr_parser_new_from_buf ((guchar *) a_str, strlen ((const char *) a_str), a_enc, FALSE); g_return_val_if_fail (parser, NULL); diff --git a/src/libcroco/cr-sel-eng.c b/src/libcroco/cr-sel-eng.c index 4f501ee05..ed40de393 100644 --- a/src/libcroco/cr-sel-eng.c +++ b/src/libcroco/cr-sel-eng.c @@ -37,7 +37,7 @@ #define PRIVATE(a_this) (a_this)->priv struct CRPseudoClassSelHandlerEntry { - char *name; + guchar *name; enum CRPseudoType type; CRPseudoClassSelectorHandler handler; }; @@ -149,8 +149,8 @@ lang_pseudo_class_handler (CRSelEng *const a_this, || a_sel->content.pseudo->extra->stryng->len < 2) return FALSE; for (; node; node = get_next_parent_element_node (node_iface, node)) { - char *val = node_iface->getProp (node, "lang"); - if (!val) val = node_iface->getProp (node, "xml:lang"); + char *val = node_iface->getProp (node, (const xmlChar *) "lang"); + if (!val) val = node_iface->getProp (node, (const xmlChar *) "xml:lang"); if (val) { if (!strcasecmp(val, a_sel->content.pseudo->extra->stryng->str)) { result = TRUE; @@ -209,7 +209,7 @@ pseudo_class_add_sel_matches_node (CRSelEng * a_this, && a_node, FALSE); status = cr_sel_eng_get_pseudo_class_selector_handler - (a_this, a_add_sel->content.pseudo->name->stryng->str, + (a_this, (guchar *) a_add_sel->content.pseudo->name->stryng->str, a_add_sel->content.pseudo->type, &handler); if (status != CR_OK || !handler) return FALSE; @@ -237,7 +237,7 @@ class_add_sel_matches_node (CRAdditionalSel * a_add_sel, && a_add_sel->content.class_name->stryng->str && a_node, FALSE); - klass = a_node_iface->getProp (a_node, "class"); + klass = a_node_iface->getProp (a_node, (const xmlChar *) "class"); if (klass) { char const *cur; for (cur = klass; cur && *cur; cur++) { @@ -246,7 +246,7 @@ class_add_sel_matches_node (CRAdditionalSel * a_add_sel, == TRUE) cur++; - if (!strncmp (cur, + if (!strncmp ((const char *) cur, a_add_sel->content.class_name->stryng->str, a_add_sel->content.class_name->stryng->len)) { cur += a_add_sel->content.class_name->stryng->len; @@ -291,9 +291,9 @@ id_add_sel_matches_node (CRAdditionalSel * a_add_sel, && a_add_sel->type == ID_ADD_SELECTOR && a_node, FALSE); - id = a_node_iface->getProp (a_node, "id"); + id = a_node_iface->getProp (a_node, (const xmlChar *) "id"); if (id) { - if (!strqcmp (id, a_add_sel->content.id_name->stryng->str, + if (!strqcmp ((const char *) id, a_add_sel->content.id_name->stryng->str, a_add_sel->content.id_name->stryng->len)) { result = TRUE; } @@ -324,7 +324,7 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, for (cur_sel = a_add_sel->content.attr_sel; cur_sel; cur_sel = cur_sel->next) { - if (!cur_sel->name + if (!cur_sel->name || !cur_sel->name->stryng || !cur_sel->name->stryng->str) return FALSE; @@ -384,7 +384,7 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, ptr2 = cur; if (!strncmp - (ptr1, + ((const char *) ptr1, cur_sel->value->stryng->str, ptr2 - ptr1 + 1)) { found = TRUE; @@ -422,7 +422,7 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, ptr2 = cur; if (g_strstr_len - (ptr1, ptr2 - ptr1 + 1, + ((const gchar *) ptr1, ptr2 - ptr1 + 1, cur_sel->value->stryng->str) == ptr1) { found = TRUE; @@ -635,7 +635,7 @@ sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel, && cur_sel->name->stryng && cur_sel->name->stryng->str) && (!strcmp (cur_sel->name->stryng->str, - node_iface->getLocalName(cur_node)))) + (const char *) node_iface->getLocalName(cur_node)))) || (cur_sel->type_mask & UNIVERSAL_SELECTOR)) { /* *this simple selector @@ -1121,11 +1121,11 @@ cr_sel_eng_new (void) } memset (PRIVATE (result), 0, sizeof (CRSelEngPriv)); cr_sel_eng_register_pseudo_class_sel_handler - (result, "first-child", + (result, (guchar *) "first-child", IDENT_PSEUDO, /*(CRPseudoClassSelectorHandler)*/ first_child_pseudo_class_handler); cr_sel_eng_register_pseudo_class_sel_handler - (result, "lang", + (result, (guchar *) "lang", FUNCTION_PSEUDO, /*(CRPseudoClassSelectorHandler)*/ lang_pseudo_class_handler); @@ -1146,7 +1146,7 @@ cr_sel_eng_new (void) */ enum CRStatus cr_sel_eng_register_pseudo_class_sel_handler (CRSelEng * a_this, - char * a_name, + guchar * a_name, enum CRPseudoType a_type, CRPseudoClassSelectorHandler a_handler) @@ -1164,7 +1164,7 @@ cr_sel_eng_register_pseudo_class_sel_handler (CRSelEng * a_this, } memset (handler_entry, 0, sizeof (struct CRPseudoClassSelHandlerEntry)); - handler_entry->name = g_strdup (a_name); + handler_entry->name = (guchar *) g_strdup ((const gchar *) a_name); handler_entry->type = a_type; handler_entry->handler = a_handler; list = g_list_append (PRIVATE (a_this)->pcs_handlers, handler_entry); @@ -1177,7 +1177,7 @@ cr_sel_eng_register_pseudo_class_sel_handler (CRSelEng * a_this, enum CRStatus cr_sel_eng_unregister_pseudo_class_sel_handler (CRSelEng * a_this, - char * a_name, + guchar * a_name, enum CRPseudoType a_type) { GList *elem = NULL, @@ -1190,7 +1190,7 @@ cr_sel_eng_unregister_pseudo_class_sel_handler (CRSelEng * a_this, for (elem = PRIVATE (a_this)->pcs_handlers; elem; elem = g_list_next (elem)) { entry = (struct CRPseudoClassSelHandlerEntry *) elem->data; - if (!strcmp (entry->name, a_name) + if (!strcmp ((const char *) entry->name, (const char *) a_name) && entry->type == a_type) { found = TRUE; break; @@ -1250,7 +1250,7 @@ cr_sel_eng_unregister_all_pseudo_class_sel_handlers (CRSelEng * a_this) enum CRStatus cr_sel_eng_get_pseudo_class_selector_handler (CRSelEng * a_this, - char * a_name, + guchar * a_name, enum CRPseudoType a_type, CRPseudoClassSelectorHandler * a_handler) @@ -1265,7 +1265,7 @@ cr_sel_eng_get_pseudo_class_selector_handler (CRSelEng * a_this, for (elem = PRIVATE (a_this)->pcs_handlers; elem; elem = g_list_next (elem)) { entry = (struct CRPseudoClassSelHandlerEntry *) elem->data; - if (!strcmp (a_name, entry->name) + if (!strcmp ((const char *) a_name, (const char *) entry->name) && entry->type == a_type) { found = TRUE; break; diff --git a/src/libcroco/cr-sel-eng.h b/src/libcroco/cr-sel-eng.h index 4d09f9c95..564debc8d 100644 --- a/src/libcroco/cr-sel-eng.h +++ b/src/libcroco/cr-sel-eng.h @@ -65,18 +65,18 @@ typedef gboolean (*CRPseudoClassSelectorHandler) (CRSelEng* a_this, CRSelEng * cr_sel_eng_new (void) ; enum CRStatus cr_sel_eng_register_pseudo_class_sel_handler (CRSelEng *a_this, - char *a_pseudo_class_sel_name, + guchar *a_pseudo_class_sel_name, enum CRPseudoType a_pseudo_class_type, CRPseudoClassSelectorHandler a_handler) ; enum CRStatus cr_sel_eng_unregister_pseudo_class_sel_handler (CRSelEng *a_this, - char *a_pseudo_class_sel_name, + guchar *a_pseudo_class_sel_name, enum CRPseudoType a_pseudo_class_type) ; enum CRStatus cr_sel_eng_unregister_all_pseudo_class_sel_handlers (CRSelEng *a_this) ; enum CRStatus cr_sel_eng_get_pseudo_class_selector_handler (CRSelEng *a_this, - char *a_pseudo_class_sel_name, + guchar *a_pseudo_class_sel_name, enum CRPseudoType a_pseudo_class_type, CRPseudoClassSelectorHandler *a_handler) ; diff --git a/src/libcroco/cr-selector.c b/src/libcroco/cr-selector.c index 43a3bd914..c56c43fda 100644 --- a/src/libcroco/cr-selector.c +++ b/src/libcroco/cr-selector.c @@ -38,7 +38,10 @@ CRSelector * cr_selector_new (CRSimpleSel * a_simple_sel) { - CRSelector *result = (CRSelector *)g_try_malloc (sizeof (CRSelector)); + CRSelector *result = NULL; + + result = (CRSelector *) g_try_malloc (sizeof (CRSelector)); + if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; @@ -55,8 +58,7 @@ cr_selector_parse_from_buf (const guchar * a_char_buf, enum CREncoding a_enc) g_return_val_if_fail (a_char_buf, NULL); - parser = cr_parser_new_from_buf ((guchar*)a_char_buf, - strlen ((char *)a_char_buf), + parser = cr_parser_new_from_buf ((guchar*)a_char_buf, strlen ((const char *) a_char_buf), a_enc, FALSE); g_return_val_if_fail (parser, NULL); @@ -140,8 +142,9 @@ guchar * cr_selector_to_string (CRSelector const * a_this) { guchar *result = NULL; + GString *str_buf = NULL; - GString *str_buf = (GString *)g_string_new (NULL); + str_buf = (GString *) g_string_new (NULL); g_return_val_if_fail (str_buf, NULL); if (a_this) { @@ -159,7 +162,7 @@ cr_selector_to_string (CRSelector const * a_this) g_string_append (str_buf, ", "); - g_string_append (str_buf, (gchar *)tmp_str); + g_string_append (str_buf, (const gchar *) tmp_str); g_free (tmp_str); tmp_str = NULL; @@ -169,7 +172,7 @@ cr_selector_to_string (CRSelector const * a_this) } if (str_buf) { - result = (guchar *)str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } diff --git a/src/libcroco/cr-simple-sel.c b/src/libcroco/cr-simple-sel.c index 4f5ac965a..a4670fe88 100644 --- a/src/libcroco/cr-simple-sel.c +++ b/src/libcroco/cr-simple-sel.c @@ -35,7 +35,9 @@ CRSimpleSel * cr_simple_sel_new (void) { - CRSimpleSel *result = (CRSimpleSel *)g_try_malloc (sizeof (CRSimpleSel)); + CRSimpleSel *result = NULL; + + result = (CRSimpleSel *) g_try_malloc (sizeof (CRSimpleSel)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; @@ -110,7 +112,7 @@ cr_simple_sel_to_string (CRSimpleSel const * a_this) str_buf = g_string_new (NULL); for (cur = a_this; cur; cur = cur->next) { if (cur->name) { - gchar *str = g_strndup (cur->name->stryng->str, + guchar *str = (guchar *) g_strndup (cur->name->stryng->str, cur->name->stryng->len); if (str) { @@ -131,17 +133,18 @@ cr_simple_sel_to_string (CRSimpleSel const * a_this) break; } - g_string_append (str_buf, str); + g_string_append (str_buf, (const gchar *) str); g_free (str); str = NULL; } } if (cur->add_sel) { + guchar *tmp_str = NULL; - gchar *tmp_str = (gchar *)cr_additional_sel_to_string (cur->add_sel); + tmp_str = cr_additional_sel_to_string (cur->add_sel); if (tmp_str) { - g_string_append (str_buf, tmp_str); + g_string_append (str_buf, (const gchar *) tmp_str); g_free (tmp_str); tmp_str = NULL; } @@ -149,7 +152,7 @@ cr_simple_sel_to_string (CRSimpleSel const * a_this) } if (str_buf) { - result = (guchar *)str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } @@ -168,7 +171,7 @@ cr_simple_sel_one_to_string (CRSimpleSel const * a_this) str_buf = g_string_new (NULL); if (a_this->name) { - gchar *str = g_strndup (a_this->name->stryng->str, + guchar *str = (guchar *) g_strndup (a_this->name->stryng->str, a_this->name->stryng->len); if (str) { @@ -179,8 +182,9 @@ cr_simple_sel_one_to_string (CRSimpleSel const * a_this) } if (a_this->add_sel) { + guchar *tmp_str = NULL; - gchar *tmp_str = (gchar *)cr_additional_sel_to_string (a_this->add_sel); + tmp_str = cr_additional_sel_to_string (a_this->add_sel); if (tmp_str) { g_string_append_printf (str_buf, "%s", tmp_str); @@ -190,7 +194,7 @@ cr_simple_sel_one_to_string (CRSimpleSel const * a_this) } if (str_buf) { - result = (guchar *)str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } diff --git a/src/libcroco/cr-statement.c b/src/libcroco/cr-statement.c index 4666f26ec..e31123aec 100644 --- a/src/libcroco/cr-statement.c +++ b/src/libcroco/cr-statement.c @@ -25,8 +25,6 @@ #include "cr-statement.h" #include "cr-parser.h" -#define UNUSED(_param) ((void)(_param)) - /** *@file *Definition of the #CRStatement class. @@ -38,12 +36,12 @@ static void cr_statement_clear (CRStatement * a_this); static void parse_font_face_start_font_face_cb (CRDocHandler * a_this, - CRParsingLocation * a_location) + CRParsingLocation *a_location) { CRStatement *stmt = NULL; enum CRStatus status = CR_OK; - UNUSED(a_location); + (void) a_location; stmt = cr_statement_new_at_font_face_rule (NULL, NULL); g_return_if_fail (stmt); @@ -86,7 +84,7 @@ parse_font_face_property_cb (CRDocHandler * a_this, CRStatement *stmt = NULL; CRStatement **stmtptr = NULL; - UNUSED(a_important); + (void) a_important; g_return_if_fail (a_this && a_name); @@ -144,13 +142,13 @@ static void parse_page_start_page_cb (CRDocHandler * a_this, CRString * a_name, CRString * a_pseudo_page, - CRParsingLocation * a_location) + CRParsingLocation *a_location) { CRStatement *stmt = NULL; enum CRStatus status = CR_OK; CRString *page_name = NULL, *pseudo_name = NULL ; - UNUSED(a_location); + (void) a_location; if (a_name) page_name = cr_string_dup (a_name) ; @@ -225,8 +223,8 @@ parse_page_end_page_cb (CRDocHandler * a_this, CRStatement *stmt = NULL; CRStatement **stmtptr = NULL; - UNUSED(a_name); - UNUSED(a_pseudo_page); + (void) a_name; + (void) a_pseudo_page; stmtptr = &stmt; status = cr_doc_handler_get_ctxt (a_this, (gpointer *) stmtptr); @@ -240,13 +238,13 @@ parse_page_end_page_cb (CRDocHandler * a_this, static void parse_at_media_start_media_cb (CRDocHandler * a_this, GList * a_media_list, - CRParsingLocation * a_location) + CRParsingLocation *a_location) { enum CRStatus status = CR_OK; CRStatement *at_media = NULL; GList *media_list = NULL; - UNUSED(a_location); + (void) a_location; g_return_if_fail (a_this && a_this->priv); @@ -380,7 +378,7 @@ parse_at_media_end_media_cb (CRDocHandler * a_this, CRStatement *at_media = NULL; CRStatement **at_media_ptr = NULL; - UNUSED(a_media_list); + (void) a_media_list; g_return_if_fail (a_this && a_this->priv); @@ -603,12 +601,13 @@ cr_statement_clear (CRStatement * a_this) static gchar * cr_statement_ruleset_to_string (CRStatement const * a_this, glong a_indent) { + GString *stringue = NULL; gchar *tmp_str = NULL, *result = NULL; g_return_val_if_fail (a_this && a_this->type == RULESET_STMT, NULL); - GString * stringue = (GString *)g_string_new (NULL); + stringue = (GString *) g_string_new (NULL); if (!stringue) { return result; } @@ -617,8 +616,8 @@ cr_statement_ruleset_to_string (CRStatement const * a_this, glong a_indent) if (a_indent) cr_utils_dump_n_chars2 (' ', stringue, a_indent); - tmp_str = (gchar *) - cr_selector_to_string (a_this->kind.ruleset-> + tmp_str = + (gchar *) cr_selector_to_string (a_this->kind.ruleset-> sel_list); if (tmp_str) { g_string_append (stringue, tmp_str); @@ -628,7 +627,7 @@ cr_statement_ruleset_to_string (CRStatement const * a_this, glong a_indent) } g_string_append (stringue, " {\n"); if (a_this->kind.ruleset->decl_list) { - tmp_str = (gchar *)cr_declaration_list_to_string2 + tmp_str = (gchar *) cr_declaration_list_to_string2 (a_this->kind.ruleset->decl_list, a_indent + DECLARATION_INDENT_NB, TRUE); if (tmp_str) { @@ -677,13 +676,13 @@ cr_statement_font_face_rule_to_string (CRStatement const * a_this, NULL); if (a_this->kind.font_face_rule->decl_list) { - stringue = (GString *)g_string_new (NULL) ; + stringue = (GString *) g_string_new (NULL) ; g_return_val_if_fail (stringue, NULL) ; if (a_indent) cr_utils_dump_n_chars2 (' ', stringue, a_indent); g_string_append (stringue, "@font-face {\n"); - tmp_str = (gchar *)cr_declaration_list_to_string2 + tmp_str = (gchar *) cr_declaration_list_to_string2 (a_this->kind.font_face_rule->decl_list, a_indent + DECLARATION_INDENT_NB, TRUE) ; if (tmp_str) { @@ -762,9 +761,10 @@ static gchar * cr_statement_at_page_rule_to_string (CRStatement const *a_this, gulong a_indent) { + GString *stringue = NULL; gchar *result = NULL ; - GString *stringue = (GString *)g_string_new (NULL) ; + stringue = (GString *) g_string_new (NULL) ; cr_utils_dump_n_chars2 (' ', stringue, a_indent) ; g_string_append (stringue, "@page"); @@ -785,7 +785,7 @@ cr_statement_at_page_rule_to_string (CRStatement const *a_this, if (a_this->kind.page_rule->decl_list) { gchar *str = NULL ; g_string_append (stringue, " {\n"); - str = (gchar *)cr_declaration_list_to_string2 + str = (gchar *) cr_declaration_list_to_string2 (a_this->kind.page_rule->decl_list, a_indent + DECLARATION_INDENT_NB, TRUE) ; if (str) { @@ -821,17 +821,17 @@ cr_statement_media_rule_to_string (CRStatement const *a_this, NULL); if (a_this->kind.media_rule) { - stringue = (GString *)g_string_new (NULL) ; + stringue = (GString *) g_string_new (NULL) ; cr_utils_dump_n_chars2 (' ', stringue, a_indent); g_string_append (stringue, "@media"); for (cur = a_this->kind.media_rule->media_list; cur; cur = cur->next) { if (cur->data) { - gchar *str = cr_string_dup2 + gchar *str2 = cr_string_dup2 ((CRString const *) cur->data); - if (str) { + if (str2) { if (cur->prev) { g_string_append (stringue, @@ -839,9 +839,9 @@ cr_statement_media_rule_to_string (CRStatement const *a_this, } g_string_append_printf (stringue, - " %s", str); - g_free (str); - str = NULL; + " %s", str2); + g_free (str2); + str2 = NULL; } } } @@ -878,7 +878,7 @@ cr_statement_import_rule_to_string (CRStatement const *a_this, if (a_this->kind.import_rule->url && a_this->kind.import_rule->url->stryng) { - stringue = (GString *)g_string_new (NULL) ; + stringue = (GString *) g_string_new (NULL) ; g_return_val_if_fail (stringue, NULL) ; str = g_strndup (a_this->kind.import_rule->url->stryng->str, a_this->kind.import_rule->url->stryng->len); @@ -950,8 +950,7 @@ cr_statement_does_buf_parses_against_core (const guchar * a_buf, enum CRStatus status = CR_OK; gboolean result = FALSE; - parser = cr_parser_new_from_buf ((guchar*)a_buf, - strlen ((char *)a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_encoding, FALSE); g_return_val_if_fail (parser, FALSE); @@ -1071,8 +1070,7 @@ cr_statement_ruleset_parse_from_buf (const guchar * a_buf, g_return_val_if_fail (a_buf, NULL); - parser = cr_parser_new_from_buf ((guchar*)a_buf, - strlen ((char *)a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_enc, FALSE); g_return_val_if_fail (parser, NULL); @@ -1138,6 +1136,8 @@ cr_statement_new_ruleset (CRStyleSheet * a_sheet, CRDeclaration * a_decl_list, CRStatement * a_parent_media_rule) { + CRStatement *result = NULL; + g_return_val_if_fail (a_sel_list, NULL); if (a_parent_media_rule) { @@ -1148,7 +1148,7 @@ cr_statement_new_ruleset (CRStyleSheet * a_sheet, NULL); } - CRStatement *result = (CRStatement *)g_try_malloc (sizeof (CRStatement)); + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1157,7 +1157,7 @@ cr_statement_new_ruleset (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = RULESET_STMT; - result->kind.ruleset = (CRRuleSet *)g_try_malloc (sizeof (CRRuleSet)); + result->kind.ruleset = (CRRuleSet *) g_try_malloc (sizeof (CRRuleSet)); if (!result->kind.ruleset) { cr_utils_trace_info ("Out of memory"); @@ -1207,8 +1207,7 @@ cr_statement_at_media_rule_parse_from_buf (const guchar * a_buf, CRDocHandler *sac_handler = NULL; enum CRStatus status = CR_OK; - parser = cr_parser_new_from_buf ((guchar*)a_buf, - strlen ((char *)a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_enc, FALSE); if (!parser) { cr_utils_trace_info ("Instanciation of the parser failed"); @@ -1278,12 +1277,13 @@ CRStatement * cr_statement_new_at_media_rule (CRStyleSheet * a_sheet, CRStatement * a_rulesets, GList * a_media) { - CRStatement *cur = NULL; + CRStatement *result = NULL, + *cur = NULL; if (a_rulesets) g_return_val_if_fail (a_rulesets->type == RULESET_STMT, NULL); - CRStatement *result = (CRStatement *)g_try_malloc (sizeof (CRStatement)); + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1293,7 +1293,7 @@ cr_statement_new_at_media_rule (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_MEDIA_RULE_STMT; - result->kind.media_rule = (CRAtMediaRule *)g_try_malloc (sizeof (CRAtMediaRule)); + result->kind.media_rule = (CRAtMediaRule *) g_try_malloc (sizeof (CRAtMediaRule)); if (!result->kind.media_rule) { cr_utils_trace_info ("Out of memory"); g_free (result); @@ -1340,7 +1340,9 @@ cr_statement_new_at_import_rule (CRStyleSheet * a_container_sheet, GList * a_media_list, CRStyleSheet * a_imported_sheet) { - CRStatement *result = (CRStatement *)g_try_malloc (sizeof (CRStatement)); + CRStatement *result = NULL; + + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1350,7 +1352,7 @@ cr_statement_new_at_import_rule (CRStyleSheet * a_container_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_IMPORT_RULE_STMT; - result->kind.import_rule = (CRAtImportRule *)g_try_malloc (sizeof (CRAtImportRule)); + result->kind.import_rule = (CRAtImportRule *) g_try_malloc (sizeof (CRAtImportRule)); if (!result->kind.import_rule) { cr_utils_trace_info ("Out of memory"); @@ -1391,8 +1393,7 @@ cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf, CRString *import_string = NULL; CRParsingLocation location = {0,0,0} ; - parser = cr_parser_new_from_buf ((guchar*)a_buf, - strlen ((char *)a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_encoding, FALSE); if (!parser) { cr_utils_trace_info ("Instanciation of parser failed."); @@ -1425,8 +1426,7 @@ cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf, parser = NULL; } if (media_list) { - GList *cur = NULL; - for (cur = media_list; media_list; + for (; media_list; media_list = g_list_next (media_list)) { if (media_list->data) { cr_string_destroy ((CRString*)media_list->data); @@ -1463,7 +1463,9 @@ cr_statement_new_at_page_rule (CRStyleSheet * a_sheet, CRDeclaration * a_decl_list, CRString * a_name, CRString * a_pseudo) { - CRStatement *result = (CRStatement *)g_try_malloc (sizeof (CRStatement)); + CRStatement *result = NULL; + + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1473,7 +1475,7 @@ cr_statement_new_at_page_rule (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_PAGE_RULE_STMT; - result->kind.page_rule = (CRAtPageRule *)g_try_malloc (sizeof (CRAtPageRule)); + result->kind.page_rule = (CRAtPageRule *) g_try_malloc (sizeof (CRAtPageRule)); if (!result->kind.page_rule) { cr_utils_trace_info ("Out of memory"); @@ -1511,14 +1513,14 @@ cr_statement_at_page_rule_parse_from_buf (const guchar * a_buf, enum CREncoding a_encoding) { enum CRStatus status = CR_OK; + CRParser *parser = NULL; CRDocHandler *sac_handler = NULL; CRStatement *result = NULL; CRStatement **resultptr = NULL; g_return_val_if_fail (a_buf, NULL); - CRParser *parser = cr_parser_new_from_buf ((guchar*)a_buf, - strlen ((char *)a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_encoding, FALSE); if (!parser) { cr_utils_trace_info ("Instanciation of the parser failed."); @@ -1584,9 +1586,11 @@ CRStatement * cr_statement_new_at_charset_rule (CRStyleSheet * a_sheet, CRString * a_charset) { + CRStatement *result = NULL; + g_return_val_if_fail (a_charset, NULL); - CRStatement *result = (CRStatement *)g_try_malloc (sizeof (CRStatement)); + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1596,7 +1600,7 @@ cr_statement_new_at_charset_rule (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_CHARSET_RULE_STMT; - result->kind.charset_rule = (CRAtCharsetRule *)g_try_malloc (sizeof (CRAtCharsetRule)); + result->kind.charset_rule = (CRAtCharsetRule *) g_try_malloc (sizeof (CRAtCharsetRule)); if (!result->kind.charset_rule) { cr_utils_trace_info ("Out of memory"); @@ -1626,13 +1630,13 @@ cr_statement_at_charset_rule_parse_from_buf (const guchar * a_buf, enum CREncoding a_encoding) { enum CRStatus status = CR_OK; + CRParser *parser = NULL; CRStatement *result = NULL; CRString *charset = NULL; g_return_val_if_fail (a_buf, NULL); - CRParser *parser = cr_parser_new_from_buf ((guchar*)a_buf, - strlen ((char *)a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_encoding, FALSE); if (!parser) { cr_utils_trace_info ("Instanciation of the parser failed."); @@ -1678,7 +1682,9 @@ CRStatement * cr_statement_new_at_font_face_rule (CRStyleSheet * a_sheet, CRDeclaration * a_font_decls) { - CRStatement *result = (CRStatement *)g_try_malloc (sizeof (CRStatement)); + CRStatement *result = NULL; + + result = (CRStatement *) g_try_malloc (sizeof (CRStatement)); if (!result) { cr_utils_trace_info ("Out of memory"); @@ -1687,7 +1693,7 @@ cr_statement_new_at_font_face_rule (CRStyleSheet * a_sheet, memset (result, 0, sizeof (CRStatement)); result->type = AT_FONT_FACE_RULE_STMT; - result->kind.font_face_rule = (CRAtFontFaceRule *)g_try_malloc + result->kind.font_face_rule = (CRAtFontFaceRule *) g_try_malloc (sizeof (CRAtFontFaceRule)); if (!result->kind.font_face_rule) { @@ -1723,12 +1729,11 @@ cr_statement_font_face_rule_parse_from_buf (const guchar * a_buf, { CRStatement *result = NULL; CRStatement **resultptr = NULL; + CRParser *parser = NULL; CRDocHandler *sac_handler = NULL; enum CRStatus status = CR_OK; - CRParser *parser = (CRParser *)cr_parser_new_from_buf ( - (guchar*)a_buf, - strlen ((char *)a_buf), + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), a_encoding, FALSE); if (!parser) goto cleanup; @@ -2614,8 +2619,10 @@ cr_statement_dump (CRStatement const * a_this, FILE * a_fp, gulong a_indent) void cr_statement_dump_ruleset (CRStatement const * a_this, FILE * a_fp, glong a_indent) { + gchar *str = NULL; + g_return_if_fail (a_fp && a_this); - gchar *str = cr_statement_ruleset_to_string (a_this, a_indent); + str = cr_statement_ruleset_to_string (a_this, a_indent); if (str) { fprintf (a_fp, "%s", str); g_free (str); @@ -2661,9 +2668,11 @@ cr_statement_dump_font_face_rule (CRStatement const * a_this, FILE * a_fp, void cr_statement_dump_charset (CRStatement const * a_this, FILE * a_fp, gulong a_indent) { + gchar *str = NULL; + g_return_if_fail (a_this && a_this->type == AT_CHARSET_RULE_STMT); - gchar *str = cr_statement_charset_to_string (a_this, + str = cr_statement_charset_to_string (a_this, a_indent) ; if (str) { fprintf (a_fp, "%s", str) ; @@ -2685,11 +2694,13 @@ cr_statement_dump_charset (CRStatement const * a_this, FILE * a_fp, gulong a_ind void cr_statement_dump_page (CRStatement const * a_this, FILE * a_fp, gulong a_indent) { + gchar *str = NULL; + g_return_if_fail (a_this && a_this->type == AT_PAGE_RULE_STMT && a_this->kind.page_rule); - gchar *str = cr_statement_at_page_rule_to_string (a_this, a_indent) ; + str = cr_statement_at_page_rule_to_string (a_this, a_indent) ; if (str) { fprintf (a_fp, "%s", str); g_free (str) ; diff --git a/src/libcroco/cr-string.c b/src/libcroco/cr-string.c index 47d557d5b..86ad3432c 100644 --- a/src/libcroco/cr-string.c +++ b/src/libcroco/cr-string.c @@ -32,7 +32,9 @@ CRString * cr_string_new (void) { - CRString *result = (CRString *)g_try_malloc (sizeof (CRString)) ; + CRString *result = NULL ; + + result = (CRString *) g_try_malloc (sizeof (CRString)) ; if (!result) { cr_utils_trace_info ("Out of memory") ; return NULL ; @@ -51,7 +53,9 @@ cr_string_new (void) CRString * cr_string_new_from_string (const gchar * a_string) { - CRString *result = cr_string_new () ; + CRString *result = NULL ; + + result = cr_string_new () ; if (!result) { cr_utils_trace_info ("Out of memory") ; return NULL ; @@ -70,7 +74,9 @@ cr_string_new_from_string (const gchar * a_string) CRString * cr_string_new_from_gstring (GString const *a_string) { - CRString *result = cr_string_new () ; + CRString *result = NULL ; + + result = cr_string_new () ; if (!result) { cr_utils_trace_info ("Out of memory") ; return NULL ; @@ -87,9 +93,10 @@ cr_string_new_from_gstring (GString const *a_string) CRString * cr_string_dup (CRString const *a_this) { + CRString *result = NULL ; g_return_val_if_fail (a_this, NULL) ; - CRString *result = cr_string_new_from_gstring (a_this->stryng) ; + result = cr_string_new_from_gstring (a_this->stryng) ; if (!result) { cr_utils_trace_info ("Out of memory") ; return NULL ; diff --git a/src/libcroco/cr-style.c b/src/libcroco/cr-style.c index a9c5a5cec..2b865c248 100644 --- a/src/libcroco/cr-style.c +++ b/src/libcroco/cr-style.c @@ -140,9 +140,9 @@ static CRPropertyDesc gv_prop_table[] = { {"font-size", PROP_ID_FONT_SIZE}, {"font-style", PROP_ID_FONT_STYLE}, {"font-weight", PROP_ID_FONT_WEIGHT}, - {"white-space", PROP_ID_WHITE_SPACE}, + {"white-space", PROP_ID_WHITE_SPACE}, /*must be the last one */ - {NULL, (enum CRPropertyID)0} + {NULL, (enum CRPropertyID) 0} }; /** @@ -185,7 +185,7 @@ static struct CRNumPropEnumDumpInfo gv_num_props_dump_infos[] = { {NUM_PROP_MARGIN_BOTTOM, "margin-bottom"}, {NUM_PROP_MARGIN_LEFT, "margin-left"}, {NUM_PROP_WIDTH, "width"}, - {(enum CRNumProp)0, NULL} + {(enum CRNumProp) 0, NULL} }; struct CRRgbPropEnumDumpInfo { @@ -200,7 +200,7 @@ static struct CRRgbPropEnumDumpInfo gv_rgb_props_dump_infos[] = { {RGB_PROP_BORDER_LEFT_COLOR, "left-color"}, {RGB_PROP_COLOR, "color"}, {RGB_PROP_BACKGROUND_COLOR, "background-color"}, - {(enum CRRgbProp)0, NULL} + {(enum CRRgbProp) 0, NULL} }; struct CRBorderStylePropEnumDumpInfo { @@ -215,7 +215,7 @@ static struct CRBorderStylePropEnumDumpInfo gv_border_style_props_dump_infos[] {BORDER_STYLE_PROP_RIGHT, "border-style-right"}, {BORDER_STYLE_PROP_BOTTOM, "boder-style-bottom"}, {BORDER_STYLE_PROP_LEFT, "border-style-left"}, - {(enum CRBorderStyleProp)0, NULL} + {(enum CRBorderStyleProp) 0, NULL} }; static enum CRStatus @@ -319,9 +319,9 @@ set_prop_font_weight_from_value (CRStyle * a_style, CRTerm * a_value); static const gchar * num_prop_code_to_string (enum CRNumProp a_code) { - int len = sizeof (gv_num_props_dump_infos) / + guint len = sizeof (gv_num_props_dump_infos) / sizeof (struct CRNumPropEnumDumpInfo); - if ((int)a_code >= len) { + if (a_code >= len) { cr_utils_trace_info ("A field has been added " "to 'enum CRNumProp' and no matching" " entry has been " @@ -342,10 +342,10 @@ num_prop_code_to_string (enum CRNumProp a_code) static const gchar * rgb_prop_code_to_string (enum CRRgbProp a_code) { - int len = sizeof (gv_rgb_props_dump_infos) / + guint len = sizeof (gv_rgb_props_dump_infos) / sizeof (struct CRRgbPropEnumDumpInfo); - if ((int)a_code >= len) { + if (a_code >= len) { cr_utils_trace_info ("A field has been added " "to 'enum CRRgbProp' and no matching" " entry has been " @@ -366,10 +366,10 @@ rgb_prop_code_to_string (enum CRRgbProp a_code) static const gchar * border_style_prop_code_to_string (enum CRBorderStyleProp a_code) { - int len = sizeof (gv_border_style_props_dump_infos) / + guint len = sizeof (gv_border_style_props_dump_infos) / sizeof (struct CRBorderStylePropEnumDumpInfo); - if ((int)a_code >= len) { + if (a_code >= len) { cr_utils_trace_info ("A field has been added " "to 'enum CRBorderStyleProp' and no matching" " entry has been " @@ -421,7 +421,7 @@ cr_style_get_prop_id (const guchar * a_prop) cr_style_init_properties (); } - raw_id = (gpointer *)g_hash_table_lookup (gv_prop_hash, a_prop); + raw_id = (gpointer *) g_hash_table_lookup (gv_prop_hash, a_prop); if (!raw_id) { return PROP_ID_NOT_KNOWN; } @@ -465,7 +465,7 @@ set_prop_padding_x_from_value (CRStyle * a_style, if (a_value->content.str && a_value->content.str->stryng && a_value->content.str->stryng->str - && !strncmp ("inherit", + && !strncmp ((const char *) "inherit", a_value->content.str->stryng->str, sizeof ("inherit")-1)) { status = cr_num_set (num_val, 0.0, NUM_INHERIT); @@ -569,9 +569,10 @@ static enum CRStatus set_prop_border_width_from_value (CRStyle *a_style, CRTerm *a_value) { + CRTerm *cur_term = NULL ; g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; - CRTerm *cur_term = a_value ; + cur_term = a_value ; if (!cur_term) return CR_ERROR ; @@ -579,7 +580,7 @@ set_prop_border_width_from_value (CRStyle *a_style, int dir; for (dir = (int) DIR_TOP ; dir < (int)NB_DIRS ; dir++) { enum CRDirection direction = (enum CRDirection)dir; - set_prop_border_x_width_from_value (a_style, + set_prop_border_x_width_from_value (a_style, cur_term, direction) ; } @@ -696,16 +697,18 @@ static enum CRStatus set_prop_border_style_from_value (CRStyle *a_style, CRTerm *a_value) { + CRTerm *cur_term = NULL ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; - CRTerm *cur_term = a_value ; + cur_term = a_value ; if (!cur_term || cur_term->type != TERM_IDENT) { return CR_ERROR ; } int dir; - for (dir = (int)DIR_TOP ; dir < (int)NB_DIRS ; dir++) { + for (dir = (int)DIR_TOP ; dir < (int)NB_DIRS ; dir++) { enum CRDirection direction = (enum CRDirection)dir; set_prop_border_x_style_from_value (a_style, cur_term, @@ -908,7 +911,7 @@ set_prop_position_from_value (CRStyle * a_style, CRTerm * a_value) break; } - return CR_OK; + return status; } static enum CRStatus @@ -1115,11 +1118,11 @@ set_prop_border_x_color_from_value (CRStyle * a_style, CRTerm * a_value, && a_value->content.str->stryng->str) { status = cr_rgb_set_from_name (rgb_color, - (guchar *)a_value->content.str->stryng->str); + (const guchar *) a_value->content.str->stryng->str); } if (status != CR_OK) { - cr_rgb_set_from_name (rgb_color, (guchar *)"black"); + cr_rgb_set_from_name (rgb_color, (const guchar *) "black"); } } else if (a_value->type == TERM_RGB) { if (a_value->content.rgb) { @@ -1354,7 +1357,7 @@ set_prop_font_family_from_value (CRStyle * a_style, CRTerm * a_value) && cur_term->content.str->stryng->str) { cur_ff = cr_font_family_new (FONT_FAMILY_NON_GENERIC, - (guchar *)cur_term->content.str->stryng->str); + (guchar *) cur_term->content.str->stryng->str); } } break; @@ -1707,7 +1710,9 @@ set_prop_white_space_from_value (CRStyle * a_style, CRTerm * a_value) CRStyle * cr_style_new (gboolean a_set_props_to_initial_values) { - CRStyle *result = (CRStyle *)g_try_malloc (sizeof (CRStyle)); + CRStyle *result = NULL; + + result = (CRStyle *) g_try_malloc (sizeof (CRStyle)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; @@ -2018,7 +2023,7 @@ cr_style_set_style_from_decl (CRStyle * a_this, CRDeclaration * a_decl) CR_BAD_PARAM_ERROR); prop_id = cr_style_get_prop_id - ((guchar *)a_decl->property->stryng->str); + ((const guchar *) a_decl->property->stryng->str); value = a_decl->value; switch (prop_id) { @@ -2676,7 +2681,7 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent) *before outputing it value */ cr_utils_dump_n_chars2 (' ', str, indent); - tmp_str = (gchar *) num_prop_code_to_string ((enum CRNumProp)i); + tmp_str = (gchar *) num_prop_code_to_string ((enum CRNumProp) i); if (tmp_str) { g_string_append_printf (str, "%s: ", tmp_str); } else { @@ -2690,7 +2695,7 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent) } /*loop over the rgb_props and to_string() them all */ for (i = RGB_PROP_BORDER_TOP_COLOR; i < NB_RGB_PROPS; i++) { - tmp_str = (gchar *) rgb_prop_code_to_string ((enum CRRgbProp)i); + tmp_str = (gchar *) rgb_prop_code_to_string ((enum CRRgbProp) i); cr_utils_dump_n_chars2 (' ', str, indent); if (tmp_str) { g_string_append_printf (str, "%s: ", tmp_str); @@ -2705,8 +2710,7 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent) } /*loop over the border_style_props and to_string() them */ for (i = BORDER_STYLE_PROP_TOP; i < NB_BORDER_STYLE_PROPS; i++) { - tmp_str = (gchar *) - border_style_prop_code_to_string ((enum CRBorderStyleProp)i); + tmp_str = (gchar *) border_style_prop_code_to_string ((enum CRBorderStyleProp) i); cr_utils_dump_n_chars2 (' ', str, indent); if (tmp_str) { g_string_append_printf (str, "%s: ", tmp_str); @@ -2741,7 +2745,7 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent) cr_utils_dump_n_chars2 (' ', str, indent); g_string_append (str, "font-family: "); - tmp_str = (gchar *)cr_font_family_to_string (a_this->font_family, TRUE); + tmp_str = (gchar *) cr_font_family_to_string (a_this->font_family, TRUE); if (tmp_str) { g_string_append (str, tmp_str); g_free (tmp_str); diff --git a/src/libcroco/cr-stylesheet.c b/src/libcroco/cr-stylesheet.c index 1b26c64bf..cb5de6958 100644 --- a/src/libcroco/cr-stylesheet.c +++ b/src/libcroco/cr-stylesheet.c @@ -36,7 +36,9 @@ CRStyleSheet * cr_stylesheet_new (CRStatement * a_stmts) { - CRStyleSheet *result = (CRStyleSheet *)g_try_malloc (sizeof (CRStyleSheet)); + CRStyleSheet *result; + + result = (CRStyleSheet *) g_try_malloc (sizeof (CRStyleSheet)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; diff --git a/src/libcroco/cr-term.c b/src/libcroco/cr-term.c index 09b6354db..1c50aed2a 100644 --- a/src/libcroco/cr-term.c +++ b/src/libcroco/cr-term.c @@ -84,7 +84,9 @@ cr_term_clear (CRTerm * a_this) CRTerm * cr_term_new (void) { - CRTerm *result = (CRTerm *)g_try_malloc (sizeof (CRTerm)); + CRTerm *result = NULL; + + result = (CRTerm *) g_try_malloc (sizeof (CRTerm)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; @@ -104,15 +106,14 @@ CRTerm * cr_term_parse_expression_from_buf (const guchar * a_buf, enum CREncoding a_encoding) { + CRParser *parser = NULL; CRTerm *result = NULL; enum CRStatus status = CR_OK; g_return_val_if_fail (a_buf, NULL); - CRParser *parser = cr_parser_new_from_buf ( - (guchar*)a_buf, - strlen ((char *)a_buf), - a_encoding, FALSE); + parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen ((const char *) a_buf), + a_encoding, FALSE); g_return_val_if_fail (parser, NULL); status = cr_parser_try_to_skip_spaces_and_comments (parser); @@ -279,8 +280,8 @@ cr_term_to_string (CRTerm const * a_this) { GString *str_buf = NULL; CRTerm const *cur = NULL; - guchar *result = NULL; - gchar *content = NULL; + guchar *result = NULL, + *content = NULL; g_return_val_if_fail (a_this, NULL); @@ -329,11 +330,11 @@ cr_term_to_string (CRTerm const * a_this) switch (cur->type) { case TERM_NUMBER: if (cur->content.num) { - content = (gchar *)cr_num_to_string (cur->content.num); + content = cr_num_to_string (cur->content.num); } if (content) { - g_string_append (str_buf, content); + g_string_append (str_buf, (const gchar *) content); g_free (content); content = NULL; } @@ -342,7 +343,7 @@ cr_term_to_string (CRTerm const * a_this) case TERM_FUNCTION: if (cur->content.str) { - content = g_strndup + content = (guchar *) g_strndup (cur->content.str->stryng->str, cur->content.str->stryng->len); } @@ -360,22 +361,21 @@ cr_term_to_string (CRTerm const * a_this) if (tmp_str) { g_string_append (str_buf, - (gchar *)tmp_str); + (const gchar *) tmp_str); g_free (tmp_str); tmp_str = NULL; } - } + g_string_append (str_buf, ")"); g_free (content); content = NULL; - g_string_append (str_buf, ")"); } break; case TERM_STRING: if (cur->content.str) { - content = g_strndup + content = (guchar *) g_strndup (cur->content.str->stryng->str, cur->content.str->stryng->len); } @@ -390,13 +390,13 @@ cr_term_to_string (CRTerm const * a_this) case TERM_IDENT: if (cur->content.str) { - content = g_strndup + content = (guchar *) g_strndup (cur->content.str->stryng->str, cur->content.str->stryng->len); } if (content) { - g_string_append (str_buf, content); + g_string_append (str_buf, (const gchar *) content); g_free (content); content = NULL; } @@ -404,9 +404,9 @@ cr_term_to_string (CRTerm const * a_this) case TERM_URI: if (cur->content.str) { - content = g_strndup - (cur->content.str->stryng->str, - cur->content.str->stryng->len); + content = (guchar *) g_strndup + (cur->content.str->stryng->str, + cur->content.str->stryng->len); } if (content) { @@ -425,7 +425,7 @@ cr_term_to_string (CRTerm const * a_this) tmp_str = cr_rgb_to_string (cur->content.rgb); if (tmp_str) { - g_string_append (str_buf, (gchar *)tmp_str); + g_string_append (str_buf, (const gchar *) tmp_str); g_free (tmp_str); tmp_str = NULL; } @@ -442,7 +442,7 @@ cr_term_to_string (CRTerm const * a_this) case TERM_HASH: if (cur->content.str) { - content = g_strndup + content = (guchar *) g_strndup (cur->content.str->stryng->str, cur->content.str->stryng->len); } @@ -463,7 +463,7 @@ cr_term_to_string (CRTerm const * a_this) } if (str_buf) { - result = (guchar *)str_buf->str; + result =(guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } @@ -475,8 +475,8 @@ guchar * cr_term_one_to_string (CRTerm const * a_this) { GString *str_buf = NULL; - guchar *result = NULL; - gchar *content = NULL; + guchar *result = NULL, + *content = NULL; g_return_val_if_fail (a_this, NULL); @@ -524,11 +524,11 @@ cr_term_one_to_string (CRTerm const * a_this) switch (a_this->type) { case TERM_NUMBER: if (a_this->content.num) { - content = (gchar *)cr_num_to_string (a_this->content.num); + content = cr_num_to_string (a_this->content.num); } if (content) { - g_string_append (str_buf, content); + g_string_append (str_buf, (const gchar *) content); g_free (content); content = NULL; } @@ -537,7 +537,7 @@ cr_term_one_to_string (CRTerm const * a_this) case TERM_FUNCTION: if (a_this->content.str) { - content = g_strndup + content = (guchar *) g_strndup (a_this->content.str->stryng->str, a_this->content.str->stryng->len); } @@ -571,7 +571,7 @@ cr_term_one_to_string (CRTerm const * a_this) case TERM_STRING: if (a_this->content.str) { - content = g_strndup + content = (guchar *) g_strndup (a_this->content.str->stryng->str, a_this->content.str->stryng->len); } @@ -586,13 +586,13 @@ cr_term_one_to_string (CRTerm const * a_this) case TERM_IDENT: if (a_this->content.str) { - content = g_strndup + content = (guchar *) g_strndup (a_this->content.str->stryng->str, a_this->content.str->stryng->len); } if (content) { - g_string_append (str_buf, content); + g_string_append (str_buf, (const gchar *) content); g_free (content); content = NULL; } @@ -600,7 +600,7 @@ cr_term_one_to_string (CRTerm const * a_this) case TERM_URI: if (a_this->content.str) { - content = g_strndup + content = (guchar *) g_strndup (a_this->content.str->stryng->str, a_this->content.str->stryng->len); } @@ -615,12 +615,13 @@ cr_term_one_to_string (CRTerm const * a_this) case TERM_RGB: if (a_this->content.rgb) { + guchar *tmp_str = NULL; g_string_append_printf (str_buf, "rgb("); - gchar *tmp_str = (gchar *)cr_rgb_to_string (a_this->content.rgb); + tmp_str = cr_rgb_to_string (a_this->content.rgb); if (tmp_str) { - g_string_append (str_buf, tmp_str); + g_string_append (str_buf, (const gchar *) tmp_str); g_free (tmp_str); tmp_str = NULL; } @@ -637,7 +638,7 @@ cr_term_one_to_string (CRTerm const * a_this) case TERM_HASH: if (a_this->content.str) { - content = g_strndup + content = (guchar *) g_strndup (a_this->content.str->stryng->str, a_this->content.str->stryng->len); } @@ -658,7 +659,7 @@ cr_term_one_to_string (CRTerm const * a_this) } if (str_buf) { - result = (guchar *)str_buf->str; + result = (guchar *) str_buf->str; g_string_free (str_buf, FALSE); str_buf = NULL; } diff --git a/src/libcroco/cr-tknzr.c b/src/libcroco/cr-tknzr.c index 1f762b5c5..228471bf9 100644 --- a/src/libcroco/cr-tknzr.c +++ b/src/libcroco/cr-tknzr.c @@ -1586,7 +1586,9 @@ cr_tknzr_parse_num (CRTknzr * a_this, CRTknzr * cr_tknzr_new (CRInput * a_input) { - CRTknzr *result = (CRTknzr *)g_try_malloc (sizeof (CRTknzr)); + CRTknzr *result = NULL; + + result = (CRTknzr *) g_try_malloc (sizeof (CRTknzr)); if (result == NULL) { cr_utils_trace_info ("Out of memory"); @@ -1636,7 +1638,9 @@ cr_tknzr_new_from_uri (const guchar * a_file_uri, enum CREncoding a_enc) { CRTknzr *result = NULL; - CRInput *input = cr_input_new_from_uri ((gchar *)a_file_uri, a_enc); + CRInput *input = NULL; + + input = cr_input_new_from_uri ((const gchar *) a_file_uri, a_enc); g_return_val_if_fail (input != NULL, NULL); result = cr_tknzr_new (input); @@ -1909,7 +1913,7 @@ cr_tknzr_consume_chars (CRTknzr * a_this, guint32 a_char, glong * a_nb_char) } return cr_input_consume_chars (PRIVATE (a_this)->input, - a_char, (gulong *)a_nb_char); + a_char, a_nb_char); } enum CRStatus @@ -2097,15 +2101,15 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk) if (BYTE (input, 2, NULL) == 'r' && BYTE (input, 3, NULL) == 'l' && BYTE (input, 4, NULL) == '(') { - CRString *str = NULL; + CRString *str2 = NULL; - status = cr_tknzr_parse_uri (a_this, &str); + status = cr_tknzr_parse_uri (a_this, &str2); if (status == CR_OK) { - status = cr_token_set_uri (token, str); + status = cr_token_set_uri (token, str2); CHECK_PARSING_STATUS (status, TRUE); - if (str) { + if (str2) { cr_parsing_location_copy (&token->location, - &str->location) ; + &str2->location) ; } goto done; } diff --git a/src/libcroco/cr-token.c b/src/libcroco/cr-token.c index 3dd73ac3e..dfe83e221 100644 --- a/src/libcroco/cr-token.c +++ b/src/libcroco/cr-token.c @@ -133,7 +133,9 @@ cr_token_clear (CRToken * a_this) CRToken * cr_token_new (void) { - CRToken *result = (CRToken *)g_try_malloc (sizeof (CRToken)); + CRToken *result = NULL; + + result = (CRToken *) g_try_malloc (sizeof (CRToken)); if (result == NULL) { cr_utils_trace_info ("Out of memory"); diff --git a/src/libcroco/cr-utils.c b/src/libcroco/cr-utils.c index a51c76920..bfb587017 100644 --- a/src/libcroco/cr-utils.c +++ b/src/libcroco/cr-utils.c @@ -429,9 +429,8 @@ cr_utils_read_char_from_utf8_buf (const guchar * a_in, gulong a_in_len, guint32 * a_out, gulong * a_consumed) { - gulong in_len = 0, - in_index = 0, - nb_bytes_2_decode = 0; + gulong in_index = 0, + nb_bytes_2_decode = 0; enum CRStatus status = CR_OK; /* @@ -448,8 +447,6 @@ cr_utils_read_char_from_utf8_buf (const guchar * a_in, goto end; } - in_len = a_in_len; - if (*a_in <= 0x7F) { /* *7 bits long char @@ -901,15 +898,10 @@ cr_utils_ucs1_to_utf8 (const guchar * a_in, if (*a_in_len == 0) { *a_out_len = 0 ; - return CR_OK ; + return status; } g_return_val_if_fail (a_out, CR_BAD_PARAM_ERROR) ; - if (*a_in_len < 1) { - status = CR_OK; - goto end; - } - in_len = *a_in_len; out_len = *a_out_len; @@ -930,11 +922,10 @@ cr_utils_ucs1_to_utf8 (const guchar * a_in, } } /*end for */ - end: *a_in_len = in_index; *a_out_len = out_index; - return CR_OK; + return status; } /** @@ -951,8 +942,7 @@ cr_utils_ucs1_str_to_utf8 (const guchar * a_in, gulong * a_in_len, guchar ** a_out, gulong * a_out_len) { - gulong in_len = 0, - out_len = 0; + gulong out_len = 0; enum CRStatus status = CR_OK; g_return_val_if_fail (a_in && a_in_len && a_out @@ -969,8 +959,6 @@ cr_utils_ucs1_str_to_utf8 (const guchar * a_in, g_return_val_if_fail (status == CR_OK, status); - in_len = *a_in_len; - *a_out = (guchar *) g_malloc0 (out_len); status = cr_utils_ucs1_to_utf8 (a_in, a_in_len, *a_out, &out_len); @@ -1023,7 +1011,6 @@ cr_utils_utf8_to_ucs1 (const guchar * a_in, && a_out && a_out_len, CR_BAD_PARAM_ERROR); if (*a_in_len < 1) { - status = CR_OK; goto end; } @@ -1102,7 +1089,6 @@ cr_utils_utf8_to_ucs1 (const guchar * a_in, *(if any) to get the current character. */ if (in_index + nb_bytes_2_decode - 1 >= in_len) { - status = CR_OK; goto end; } @@ -1136,7 +1122,7 @@ cr_utils_utf8_to_ucs1 (const guchar * a_in, *a_out_len = out_index; *a_in_len = in_index; - return CR_OK; + return status; } /** diff --git a/src/libgdl/CMakeLists.txt b/src/libgdl/CMakeLists.txt index d59d017f0..a452320f7 100644 --- a/src/libgdl/CMakeLists.txt +++ b/src/libgdl/CMakeLists.txt @@ -1,47 +1,50 @@ +if (NOT "${WITH_EXT_GDL}") -set(libgdl_SRC - gdl-dock-bar.c - gdl-dock-item-button-image.c - gdl-dock-item-grip.c - gdl-dock-item.c - gdl-dock-master.c - gdl-dock-notebook.c - gdl-dock-object.c - gdl-dock-paned.c - gdl-dock-placeholder.c - gdl-dock-tablabel.c - gdl-dock.c - gdl-i18n.c - gdl-switcher.c - libgdlmarshal.c - libgdltypebuiltins.c + set(libgdl_SRC + gdl-dock-bar.c + gdl-dock-item-button-image.c + gdl-dock-item-grip.c + gdl-dock-item.c + gdl-dock-master.c + gdl-dock-notebook.c + gdl-dock-object.c + gdl-dock-paned.c + gdl-dock-placeholder.c + gdl-dock-tablabel.c + gdl-dock.c + gdl-i18n.c + gdl-switcher.c + libgdlmarshal.c + libgdltypebuiltins.c - # ------- - # Headers - gdl-dock-bar.h - gdl-dock-item-button-image.h - gdl-dock-item-grip.h - gdl-dock-item.h - gdl-dock-master.h - gdl-dock-notebook.h - gdl-dock-object.h - gdl-dock-paned.h - gdl-dock-placeholder.h - gdl-dock-tablabel.h - gdl-dock.h - gdl-i18n.h - gdl-switcher.h - gdl.h - libgdlmarshal.h - libgdltypebuiltins.h -) + # ------- + # Headers + gdl-dock-bar.h + gdl-dock-item-button-image.h + gdl-dock-item-grip.h + gdl-dock-item.h + gdl-dock-master.h + gdl-dock-notebook.h + gdl-dock-object.h + gdl-dock-paned.h + gdl-dock-placeholder.h + gdl-dock-tablabel.h + gdl-dock.h + gdl-i18n.h + gdl-switcher.h + gdl.h + libgdlmarshal.h + libgdltypebuiltins.h + ) -if(WIN32) - list(APPEND libgdl_SRC - gdl-win32.c - gdl-win32.h - ) -endif() + if(WIN32) + list(APPEND libgdl_SRC + gdl-win32.c + gdl-win32.h + ) + endif() + + add_inkscape_lib(gdl_LIB "${libgdl_SRC}") -add_inkscape_lib(gdl_LIB "${libgdl_SRC}") +endif() diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index 731b5d645..7e92e767d 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -206,6 +206,18 @@ void sp_bspline_do_effect(SPCurve *curve, double helper_size) Geom::D2<Geom::SBasis> sbasis_helper; Geom::CubicBezier const *cubic = NULL; curve_n->moveto(curve_it1->initialPoint()); + if (path_it->closed()) { + const Geom::Curve &closingline = path_it->back_closed(); + // the closing line segment is always of type + // Geom::LineSegment. + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + // closingline.isDegenerate() did not work, because it only checks for + // *exact* zero length, which goes wrong for relative coordinates and + // rounding errors... + // the closing line segment has zero-length. So stop before that one! + curve_endit = path_it->end_open(); + } + } while (curve_it1 != curve_endit) { SPCurve *in = new SPCurve(); in->moveto(curve_it1->initialPoint()); @@ -361,6 +373,18 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weight_ammount) Geom::D2<Geom::SBasis> sbasis_out; Geom::CubicBezier const *cubic = NULL; curve_n->moveto(curve_it1->initialPoint()); + if (path_it->closed()) { + const Geom::Curve &closingline = path_it->back_closed(); + // the closing line segment is always of type + // Geom::LineSegment. + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + // closingline.isDegenerate() did not work, because it only checks for + // *exact* zero length, which goes wrong for relative coordinates and + // rounding errors... + // the closing line segment has zero-length. So stop before that one! + curve_endit = path_it->end_open(); + } + } while (curve_it1 != curve_endit) { SPCurve *in = new SPCurve(); in->moveto(curve_it1->initialPoint()); diff --git a/src/live_effects/lpe-fill-between-many.cpp b/src/live_effects/lpe-fill-between-many.cpp index 3e0810cfc..574ec3580 100644 --- a/src/live_effects/lpe-fill-between-many.cpp +++ b/src/live_effects/lpe-fill-between-many.cpp @@ -37,7 +37,7 @@ void LPEFillBetweenMany::doEffect (SPCurve * curve) { Geom::PathVector res_pathv; SPItem * firstObj = NULL; - for (std::vector<PathAndDirection*>::iterator iter = linked_paths._vector.begin(); iter != linked_paths._vector.end(); iter++) { + for (std::vector<PathAndDirection*>::iterator iter = linked_paths._vector.begin(); iter != linked_paths._vector.end(); ++iter) { SPObject *obj; if ((*iter)->ref.isAttached() && (obj = (*iter)->ref.getObject()) && SP_IS_ITEM(obj) && !(*iter)->_pathvector.empty()) { Geom::Path linked_path; diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index cea91509e..310f791a1 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -20,6 +20,7 @@ #include "live_effects/parameter/parameter.h" #include <boost/functional/hash.hpp> #include "helper/geom.h" +#include "sp-item-group.h" #include <glibmm/i18n.h> #include <cmath> @@ -59,13 +60,11 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) "global_randomize", &wr, this, 1.), handles(_("Handles"), _("Handles options"), "handles", HMConverter, &wr, this, HM_ALONG_NODES), - max_smooth_angle(_("Max. smooth handle angle"), _("Max. smooth handle angle"), - "max_smooth_angle", &wr, this, 20), shift_nodes(_("Shift nodes"), _("Shift nodes"), "shift_nodes", &wr, this, true), - fixed_displacement(_("Fixed displacement"), _("Fixed displacement, 1/3 of segment lenght"), + fixed_displacement(_("Fixed displacement"), _("Fixed displacement, 1/3 of segment length"), "fixed_displacement", &wr, this, false), - spray_tool_friendly(_("Spray Tool friendly"), _("For use with spray tool"), + spray_tool_friendly(_("Spray Tool friendly"), _("For use with spray tool in copy mode"), "spray_tool_friendly", &wr, this, false) { registerParameter(&method); @@ -75,7 +74,6 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) registerParameter(&displace_y); registerParameter(&global_randomize); registerParameter(&handles); - registerParameter(&max_smooth_angle); registerParameter(&shift_nodes); registerParameter(&fixed_displacement); registerParameter(&spray_tool_friendly); @@ -88,17 +86,52 @@ LPERoughen::LPERoughen(LivePathEffectObject *lpeobject) segments.param_set_range(1, Geom::infinity()); segments.param_set_increments(1, 1); segments.param_set_digits(0); - max_smooth_angle.param_set_range(0, 359); - max_smooth_angle.param_set_increments(1, 1); - max_smooth_angle.param_set_digits(0); seed = 0; } LPERoughen::~LPERoughen() {} +static void +sp_get_better_default_size(SPItem *item, double &value) +{ + if (SP_IS_GROUP(item)) { + std::vector<SPItem*> const item_list = sp_item_group_item_list(SP_GROUP(item)); + for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();iter++) { + SPItem *subitem = *iter; + sp_get_better_default_size(subitem, value); + } + if(item_list.size() > 0){ + value /= item_list.size(); + } + } else { + SPShape *shape = dynamic_cast<SPShape *>(item); + if (shape) { + SPCurve * c = NULL; + SPPath *path = dynamic_cast<SPPath *>(shape); + if (path) { + c = path->get_original_curve(); + } else { + c = shape->getCurve(); + } + if (c) { + value += Geom::length(paths_to_pw(c->get_pathvector()))/(c->get_segment_count () * 6); + } + } + } +} + +void LPERoughen::doOnApply(SPLPEItem const* lpeitem) +{ + SPLPEItem * splpeitem = const_cast<SPLPEItem *>(lpeitem); + double initial = 0; + sp_get_better_default_size(SP_ITEM(splpeitem), initial); + displace_x.param_set_value(initial, 0); + displace_y.param_set_value(initial, 0); +} + void LPERoughen::doBeforeEffect(SPLPEItem const *lpeitem) { - if(spray_tool_friendly && seed == 0){ + if(spray_tool_friendly && seed == 0 && SP_OBJECT(lpeitem)->getId()){ std::string id_item(SP_OBJECT(lpeitem)->getId()); long seed = static_cast<long>(boost::hash_value(id_item)); global_randomize.param_set_value(global_randomize.get_value(), seed); @@ -183,19 +216,15 @@ double LPERoughen::sign(double random_number) return random_number; } -Geom::Point LPERoughen::randomize(double max_lenght, double direction) +Geom::Point LPERoughen::randomize(double max_lenght, bool is_node) { - double displace_x_parsed = displace_x * global_randomize; - double displace_y_parsed = displace_y * global_randomize; - Geom::Point output = Geom::Point(sign(displace_x_parsed), sign(displace_y_parsed)); - if( direction != 0){ - int angle = (int)max_smooth_angle; - if (angle == 0){ - angle = 1; - } - double dist = Geom::distance(Geom::Point(0,0),output); - output = Geom::Point::polar(direction + sign(Geom::deg_to_rad(rand() % angle)), dist); + double factor = 1.0/3.0; + if(is_node){ + factor = 1.0; } + double displace_x_parsed = displace_x * global_randomize * factor; + double displace_y_parsed = displace_y * global_randomize * factor; + Geom::Point output = Geom::Point(sign(displace_x_parsed), sign(displace_y_parsed)); if( fixed_displacement ){ Geom::Ray ray(Geom::Point(0,0),output); output = Geom::Point::polar(ray.angle(), max_lenght); @@ -219,14 +248,27 @@ void LPERoughen::doEffect(SPCurve *curve) Geom::Point prev(0, 0); Geom::Point last_move(0, 0); nCurve->moveto(curve_it1->initialPoint()); + if (path_it->closed()) { + const Geom::Curve &closingline = path_it->back_closed(); + // the closing line segment is always of type + // Geom::LineSegment. + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + // closingline.isDegenerate() did not work, because it only checks for + // *exact* zero length, which goes wrong for relative coordinates and + // rounding errors... + // the closing line segment has zero-length. So stop before that one! + curve_endit = path_it->end_open(); + } + } while (curve_it1 != curve_endit) { Geom::CubicBezier const *cubic = NULL; cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1); if (cubic) { - nCurve->curveto((*cubic)[1], (*cubic)[2], curve_it1->finalPoint()); + nCurve->curveto((*cubic)[1] + last_move, (*cubic)[2], curve_it1->finalPoint()); } else { nCurve->lineto(curve_it1->finalPoint()); } + last_move = Geom::Point(0, 0); double length = curve_it1->length(0.001); std::size_t splits = 0; if (method == DM_SEGMENTS) { @@ -317,9 +359,9 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point Geom::Point point_b2(0, 0); Geom::Point point_b3(0, 0); if (shift_nodes) { - point_a3 = randomize(max_lenght); + point_a3 = randomize(max_lenght, true); if(last){ - point_b3 = randomize(max_lenght); + point_b3 = randomize(max_lenght, true); } } if (handles == HM_RAND || handles == HM_SMOOTH) { @@ -336,7 +378,82 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point point_b2 = point_b3; } } - if(handles == HM_RETRACT){ + if(handles == HM_SMOOTH){ + if(cubic) { + std::pair<Geom::CubicBezier, Geom::CubicBezier> div = cubic->subdivide(t); + std::vector<Geom::Point> seg1 = div.first.controlPoints(), + seg2 = div.second.controlPoints(); + Geom::Ray ray(seg1[3] + point_a3, seg2[1] + point_a3); + double lenght = max_lenght; + if(!fixed_displacement ){ + lenght = Geom::distance(seg1[3] + point_a3, seg2[1] + point_a3); + } + point_b1 = seg1[3] + point_a3 + Geom::Point::polar(ray.angle() , lenght); + point_b2 = seg2[2]; + point_b3 = seg2[3] + point_b3; + point_a3 = seg1[3] + point_a3; + ray.setPoints(prev,A->initialPoint()); + point_a1 = A->initialPoint() + Geom::Point::polar(ray.angle(), max_lenght); + if(prev == Geom::Point(0,0)){ + point_a1 = randomize(max_lenght); + } + if(last){ + Geom::Path b2(point_b3); + b2.appendNew<Geom::LineSegment>(point_a3); + lenght = max_lenght; + ray.setPoints(point_b3, point_b2); + if(!fixed_displacement ){ + lenght = Geom::distance(b2.pointAt(1.0/3.0), point_b3); + } + point_b2 = point_b3 + Geom::Point::polar(ray.angle() , lenght); + } + ray.setPoints(point_b1, point_a3); + point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); + if(last){ + prev = point_b2; + } else { + prev = point_a2; + } + out->moveto(seg1[0]); + out->curveto(point_a1,point_a2,point_a3); + out->curveto(point_b1, point_b2, point_b3); + } else { + Geom::Ray ray(A->pointAt(t) + point_a3, A->pointAt(t + (t / 3))); + double lenght = max_lenght; + if(!fixed_displacement ){ + lenght = Geom::distance(A->pointAt(t) + point_a3, A->pointAt(t + (t / 3))); + } + point_b1 = A->pointAt(t) + point_a3 + Geom::Point::polar(ray.angle() , lenght); + point_b2 = A->pointAt(t +((t / 3) * 2)); + point_b3 = A->finalPoint() + point_b3; + point_a3 = A->pointAt(t) + point_a3; + ray.setPoints(prev,A->initialPoint()); + point_a1 = A->initialPoint() + Geom::Point::polar(ray.angle(), max_lenght); + if(prev == Geom::Point(0,0)){ + point_a1 = randomize(max_lenght); + } + if(last){ + Geom::Path b2(point_b3); + b2.appendNew<Geom::LineSegment>(point_a3); + lenght = max_lenght; + ray.setPoints(point_b3, point_b2); + if(!fixed_displacement ){ + lenght = Geom::distance(b2.pointAt(1.0/3.0), point_b3); + } + point_b2 = point_b3 + Geom::Point::polar(ray.angle() , lenght); + } + ray.setPoints(point_b1, point_a3); + point_a2 = point_a3 + Geom::Point::polar(ray.angle(), max_lenght); + if(last){ + prev = point_b2; + } else { + prev = point_a2; + } + out->moveto(A->initialPoint()); + out->curveto(point_a1,point_a2,point_a3); + out->curveto(point_b1, point_b2, point_b3); + } + } else if(handles == HM_RETRACT){ out->moveto(A->initialPoint()); out->lineto(A->pointAt(t) + point_a3); if(cubic && !last){ @@ -346,63 +463,12 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point } else { out->lineto(A->finalPoint() + point_b3); } - } else if(handles == HM_SMOOTH && cubic) { - std::pair<Geom::CubicBezier, Geom::CubicBezier> div = cubic->subdivide(t); - std::vector<Geom::Point> seg1 = div.first.controlPoints(), - seg2 = div.second.controlPoints(); - Geom::Ray ray(prev,A->initialPoint()); - point_a1 = Geom::Point::polar(ray.angle(), max_lenght); - if(prev == Geom::Point(0,0)){ - point_a1 = randomize(max_lenght); - } - ray.setPoints(seg1[3] + point_a3, seg2[1] + point_a3); - point_b1 = randomize(max_lenght, ray.angle()); - if(last){ - ray.setPoints(seg2[3] + point_b3, A->pointAt(1 - (t / 3)) + point_b3); - point_b2 = randomize(max_lenght, ray.angle()); - } - ray.setPoints(seg2[1] + point_a3 + point_b1, seg2[0] + point_a3); - point_a2 = Geom::Point::polar(ray.angle(), max_lenght); - if(last){ - prev = A->pointAt(1 - (t / 3)) + point_b2 + point_b3; - } else { - prev = seg1[3] + point_a2 + point_a3; - } - out->moveto(seg1[0]); - out->curveto(seg1[0] + point_a1, seg1[3] + point_a2 + point_a3, seg1[3] + point_a3); - if(last){ - out->curveto(seg2[1] + point_a3 + point_b1, A->pointAt(1 - (t / 3)) + point_b2 + point_b3, seg2[3] + point_b3); - } else { - out->curveto(seg2[1] + point_a3 + point_b1, seg2[2] + point_b2 + point_b3, seg2[3] + point_b3); - } - } else if(handles == HM_SMOOTH && !cubic) { - Geom::Ray ray(prev,A->initialPoint()); - point_a1 = Geom::Point::polar(ray.angle(), max_lenght); - if(prev==Geom::Point(0,0)){ - point_a1 = randomize(max_lenght); - } - ray.setPoints(A->pointAt(t) + point_a3, A->pointAt(t + (t / 3)) + point_a3); - point_b1 = randomize(max_lenght, ray.angle()); - if(last){ - ray.setPoints(A->finalPoint() + point_b3, A->pointAt(t +((t / 3) * 2)) + point_b3); - point_b2 = randomize(max_lenght, ray.angle()); - } - ray.setPoints(A->pointAt(t + (t / 3)) + point_a3 + point_b1, A->pointAt(t) + point_a3); - point_a2 = Geom::Point::polar(ray.angle(), max_lenght); - if(last){ - prev = A->pointAt(t +((t / 3) * 2)) + point_b2 + point_b3; - } else { - prev = A->pointAt(t) + point_a3 + point_a2; - } - out->moveto(A->initialPoint()); - out->curveto(A->initialPoint() + point_a1, A->pointAt(t) + point_a3 + point_a2, A->pointAt(t) + point_a3); - out->curveto(A->pointAt(t + (t / 3)) + point_a3 + point_b1, A->pointAt(t +((t / 3) * 2)) + point_b2 + point_b3, A->finalPoint() + point_b3); - } else if (cubic) { - std::pair<Geom::CubicBezier, Geom::CubicBezier> div = cubic->subdivide(t); - std::vector<Geom::Point> seg1 = div.first.controlPoints(), - seg2 = div.second.controlPoints(); - out->moveto(seg1[0]); - if(handles == HM_ALONG_NODES){ + } else if(handles == HM_ALONG_NODES){ + if (cubic) { + std::pair<Geom::CubicBezier, Geom::CubicBezier> div = cubic->subdivide(t); + std::vector<Geom::Point> seg1 = div.first.controlPoints(), + seg2 = div.second.controlPoints(); + out->moveto(seg1[0]); out->curveto(seg1[1] + last_move, seg1[2] + point_a3, seg1[3] + point_a3); last_move = point_a3; if(last){ @@ -410,17 +476,23 @@ SPCurve const * LPERoughen::addNodesAndJitter(Geom::Curve const * A, Geom::Point } out->curveto(seg2[1] + point_a3, seg2[2] + point_b3, seg2[3] + point_b3); } else { + out->moveto(A->initialPoint()); + out->lineto(A->pointAt(t) + point_a3); + out->lineto(A->finalPoint() + point_b3); + } + } else if(handles == HM_RAND) { + if (cubic) { + std::pair<Geom::CubicBezier, Geom::CubicBezier> div = cubic->subdivide(t); + std::vector<Geom::Point> seg1 = div.first.controlPoints(), + seg2 = div.second.controlPoints(); + out->moveto(seg1[0]); out->curveto(seg1[1] + point_a1, seg1[2] + point_a2 + point_a3, seg1[3] + point_a3); out->curveto(seg2[1] + point_a3 + point_b1, seg2[2] + point_b2 + point_b3, seg2[3] + point_b3); + } else { + out->moveto(A->initialPoint()); + out->lineto(A->pointAt(t) + point_a3); + out->lineto(A->finalPoint() + point_b3); } - } else if (handles == HM_RAND) { - out->moveto(A->initialPoint()); - out->curveto(A->pointAt(t / 3) + point_a1, A->pointAt((t / 3) * 2) + point_a2 + point_a3, A->pointAt(t) + point_a3); - out->curveto(A->pointAt(t + (t / 3)) + point_a3 + point_b1, A->pointAt(t +((t / 3) * 2)) + point_b2 + point_b3, A->finalPoint() + point_b3); - } else { - out->moveto(A->initialPoint()); - out->lineto(A->pointAt(t) + point_a3); - out->lineto(A->finalPoint() + point_b3); } return out; } @@ -434,52 +506,52 @@ SPCurve *LPERoughen::jitter(Geom::Curve const * A, Geom::Point &prev, Geom::Poin Geom::Point point_a2(0, 0); Geom::Point point_a3(0, 0); if (shift_nodes) { - point_a3 = randomize(max_lenght); + point_a3 = randomize(max_lenght, true); } if (handles == HM_RAND || handles == HM_SMOOTH) { point_a1 = randomize(max_lenght); point_a2 = randomize(max_lenght); } - if(handles == HM_RETRACT){ - out->moveto(A->initialPoint()); - out->lineto(A->finalPoint() + point_a3); - } else if(handles == HM_SMOOTH && cubic) { - Geom::Ray ray(prev,A->initialPoint()); - point_a1 = Geom::Point::polar(ray.angle(), max_lenght); - if(prev == Geom::Point(0,0)){ - point_a1 = A->pointAt(1.0/3.0) + randomize(max_lenght); - } - ray.setPoints((*cubic)[3] + point_a3, (*cubic)[2] + point_a3); - point_a2 = randomize(max_lenght, ray.angle()); - prev = (*cubic)[2] + point_a2; - out->moveto((*cubic)[0]); - out->curveto((*cubic)[0] + point_a1, (*cubic)[2] + point_a2 + point_a3, (*cubic)[3] + point_a3); - } else if(handles == HM_SMOOTH && !cubic) { - Geom::Ray ray(prev,A->initialPoint()); - point_a1 = Geom::Point::polar(ray.angle(), max_lenght); - if(prev==Geom::Point(0,0)){ - point_a1 = A->pointAt(1.0/3.0) + randomize(max_lenght); + if(handles == HM_SMOOTH) { + if (cubic) { + Geom::Ray ray(prev,A->initialPoint()); + point_a1 = Geom::Point::polar(ray.angle(), max_lenght); + if(prev == Geom::Point(0,0)){ + point_a1 = A->pointAt(1.0/3.0) + randomize(max_lenght); + } + ray.setPoints((*cubic)[3] + point_a3, (*cubic)[2] + point_a3); + point_a2 = randomize(max_lenght, ray.angle()); + prev = (*cubic)[2] + point_a2; + out->moveto((*cubic)[0]); + out->curveto((*cubic)[0] + point_a1, (*cubic)[2] + point_a2 + point_a3, (*cubic)[3] + point_a3); + } else { + Geom::Ray ray(prev,A->initialPoint()); + point_a1 = Geom::Point::polar(ray.angle(), max_lenght); + if(prev==Geom::Point(0,0)){ + point_a1 = A->pointAt(1.0/3.0) + randomize(max_lenght); + } + ray.setPoints(A->finalPoint() + point_a3, A->pointAt((1.0/3.0) * 2) + point_a3); + point_a2 = randomize(max_lenght, ray.angle()); + prev = A->pointAt((1.0/3.0) * 2) + point_a2 + point_a3; + out->moveto(A->initialPoint()); + out->curveto(A->initialPoint() + point_a1, A->pointAt((1.0/3.0) * 2) + point_a2 + point_a3, A->finalPoint() + point_a3); } - ray.setPoints(A->finalPoint() + point_a3, A->pointAt((1.0/3.0) * 2) + point_a3); - point_a2 = randomize(max_lenght, ray.angle()); - prev = A->pointAt((1.0/3.0) * 2) + point_a2 + point_a3; + } else if(handles == HM_RETRACT){ out->moveto(A->initialPoint()); - out->curveto(A->initialPoint() + point_a1, A->pointAt((1.0/3.0) * 2) + point_a2 + point_a3, A->finalPoint() + point_a3); - } else if (cubic) { - out->moveto((*cubic)[0]); - if(handles == HM_ALONG_NODES){ + out->lineto(A->finalPoint() + point_a3); + } else if (handles == HM_ALONG_NODES) { + if(cubic){ + out->moveto((*cubic)[0]); out->curveto((*cubic)[1] + last_move, (*cubic)[2] + point_a3, (*cubic)[3] + point_a3); last_move = point_a3; } else { - out->curveto((*cubic)[1] + point_a1, (*cubic)[2] + point_a2 + point_a3, (*cubic)[3] + point_a3); + out->moveto(A->initialPoint()); + out->lineto(A->finalPoint() + point_a3); } } else if (handles == HM_RAND) { out->moveto(A->initialPoint()); out->curveto(A->pointAt(0.3333) + point_a1, A->pointAt(0.6666) + point_a2 + point_a3, A->finalPoint() + point_a3); - } else { - out->moveto(A->initialPoint()); - out->lineto(A->finalPoint() + point_a3); } return out; } diff --git a/src/live_effects/lpe-roughen.h b/src/live_effects/lpe-roughen.h index e3ede2c2d..7e6a19d5a 100644 --- a/src/live_effects/lpe-roughen.h +++ b/src/live_effects/lpe-roughen.h @@ -45,7 +45,8 @@ public: virtual void doEffect(SPCurve *curve); virtual double sign(double randNumber); - virtual Geom::Point randomize(double max_lenght, double direction = 0); + virtual void doOnApply(SPLPEItem const* lpeitem); + virtual Geom::Point randomize(double max_lenght, bool is_node = false); virtual void doBeforeEffect(SPLPEItem const * lpeitem); virtual SPCurve const * addNodesAndJitter(Geom::Curve const * A, Geom::Point &prev, Geom::Point &last_move, double t, bool last); virtual SPCurve *jitter(Geom::Curve const * A, Geom::Point &prev, Geom::Point &last_move); @@ -60,7 +61,6 @@ private: RandomParam displace_y; RandomParam global_randomize; EnumParam<HandlesMethod> handles; - ScalarParam max_smooth_angle; BoolParam shift_nodes; BoolParam fixed_displacement; BoolParam spray_tool_friendly; diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index f6842a030..2d79d5b34 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -29,7 +29,7 @@ LPESimplify::LPESimplify(LivePathEffectObject *lpeobject) : Effect(lpeobject), steps(_("Steps:"),_("Change number of simplify steps "), "steps", &wr, this,1), threshold(_("Roughly threshold:"), _("Roughly threshold:"), "threshold", &wr, this, 0.003), - smooth_angles(_("Smooth angles:"), _("Max degree difference on handles to preform a smooth"), "smooth_angles", &wr, this, 20.), + smooth_angles(_("Smooth angles:"), _("Max degree difference on handles to perform a smooth"), "smooth_angles", &wr, this, 20.), helper_size(_("Helper size:"), _("Helper size"), "helper_size", &wr, this, 5), simplify_individual_paths(_("Paths separately"), _("Simplifying paths (separately)"), "simplify_individual_paths", &wr, this, false, "", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index ef616f802..f2ddd4929 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -408,9 +408,8 @@ Piecewise<D2<SBasis> > stretch_along(Piecewise<D2<SBasis> > pwd2_in, Geom::Path n = force_continuity(remove_short_cuts(n,.1)); int nbCopies = 0; - double scaling = 1; + double scaling = (uskeleton.domain().extent() - toffset)/pattBndsX->extent(); nbCopies = 1; - scaling = (uskeleton.domain().extent() - toffset)/pattBndsX->extent(); double pattWidth = pattBndsX->extent() * scaling; diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 8326bd6f1..f2b756567 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -30,13 +30,13 @@ LPETransform2Pts::LPETransform2Pts(LivePathEffectObject *lpeobject) : Effect(lpeobject), elastic(_("Elastic"), _("Elastic transform mode"), "elastic", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), from_original_width(_("From original width"), _("From original width"), "from_original_width", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), - lock_lenght(_("Lock lenght"), _("Lock lenght to current distance"), "lock_lenght", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), + lock_lenght(_("Lock length"), _("Lock length to current distance"), "lock_lenght", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), lock_angle(_("Lock angle"), _("Lock angle"), "lock_angle", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), flip_horizontal(_("Flip horizontal"), _("Flip horizontal"), "flip_horizontal", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), flip_vertical(_("Flip vertical"), _("Flip vertical"), "flip_vertical", &wr, this, false,"", INKSCAPE_ICON("on"), INKSCAPE_ICON("off")), start(_("Start"), _("Start point"), "start", &wr, this, "Start point"), end(_("End"), _("End point"), "end", &wr, this, "End point"), - strech(_("Strech"), _("Strech the result"), "strech", &wr, this, 1), + strech(_("Stretch"), _("Stretch the result"), "strech", &wr, this, 1), offset(_("Offset"), _("Offset from knots"), "offset", &wr, this, 0), first_knot(_("First Knot"), _("First Knot"), "first_knot", &wr, this, 1), last_knot(_("Last Knot"), _("Last Knot"), "last_knot", &wr, this, 1), diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp index b089213fd..399307502 100644 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ b/src/live_effects/parameter/filletchamferpointarray.cpp @@ -159,9 +159,8 @@ void FilletChamferPointArrayParam::recalculate_controlpoints_for_new_pwd2( //todo: if the path remove some nodes whith the result of a straight //line but with handles, the node inserted into dont fire the knot // because is not handle as cusp node by get_nodetype function - bool this_is_line = true; bool next_is_line = is_straight_curve(*curve_it1); - this_is_line = is_straight_curve((*path_it)[counterCurves - 1]); + bool this_is_line = is_straight_curve((*path_it)[counterCurves - 1]); nodetype = get_nodetype((*path_it)[counterCurves - 1], *curve_it1); if (this_is_line || next_is_line) { nodetype = NODE_CUSP; @@ -307,9 +306,8 @@ void FilletChamferPointArrayParam::recalculate_knots( nodetype = NODE_NONE; } } else { - bool this_is_line = true; bool next_is_line = is_straight_curve(*curve_it1); - this_is_line = is_straight_curve((*path_it)[counterCurves - 1]); + bool this_is_line = is_straight_curve((*path_it)[counterCurves - 1]); nodetype = get_nodetype((*path_it)[counterCurves - 1], *curve_it1); if (this_is_line || next_is_line) { nodetype = NODE_CUSP; @@ -467,12 +465,12 @@ double FilletChamferPointArrayParam::len_to_rad(int index, double len) Geom::Point endArcPoint = B->toSBasis().valueAt(times[2]); Curve *knotCurve1 = A->portion(times[0], times[1]); Curve *knotCurve2 = B->portion(times[2], 1); - Geom::CubicBezier const *cubic1 = dynamic_cast<Geom::CubicBezier const *>(&*knotCurve1); + Geom::CubicBezier const *cubic1 = dynamic_cast<Geom::CubicBezier const *>(knotCurve1); Ray ray1(startArcPoint, A->finalPoint()); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } - Geom::CubicBezier const *cubic2 = dynamic_cast<Geom::CubicBezier const *>(&*knotCurve2); + Geom::CubicBezier const *cubic2 = dynamic_cast<Geom::CubicBezier const *>(knotCurve2); Ray ray2(B->initialPoint(), endArcPoint); if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); diff --git a/src/live_effects/parameter/originalpatharray.cpp b/src/live_effects/parameter/originalpatharray.cpp index 78e061e66..9e03e2c02 100644 --- a/src/live_effects/parameter/originalpatharray.cpp +++ b/src/live_effects/parameter/originalpatharray.cpp @@ -215,7 +215,7 @@ void OriginalPathArrayParam::on_up_button_click() int i = -1; std::vector<PathAndDirection*>::iterator piter = _vector.begin(); - for (std::vector<PathAndDirection*>::iterator iter = _vector.begin(); iter != _vector.end(); piter = iter, i++, iter++) { + for (std::vector<PathAndDirection*>::iterator iter = _vector.begin(); iter != _vector.end(); piter = iter, i++, ++iter) { if (*iter == row[_model->_colObject]) { _vector.erase(iter); _vector.insert(piter, row[_model->_colObject]); @@ -241,7 +241,7 @@ void OriginalPathArrayParam::on_down_button_click() Gtk::TreeModel::Row row = *iter; int i = 0; - for (std::vector<PathAndDirection*>::iterator iter = _vector.begin(); iter != _vector.end(); i++, iter++) { + for (std::vector<PathAndDirection*>::iterator iter = _vector.begin(); iter != _vector.end(); i++, ++iter) { if (*iter == row[_model->_colObject]) { std::vector<PathAndDirection*>::iterator niter = _vector.erase(iter); if (niter != _vector.end()) { @@ -295,7 +295,7 @@ OriginalPathArrayParam::on_link_button_click() Inkscape::SVGOStringStream os; bool foundOne = false; - for (std::vector<PathAndDirection*>::const_iterator iter = _vector.begin(); iter != _vector.end(); iter++) { + for (std::vector<PathAndDirection*>::const_iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { if (foundOne) { os << "|"; } else { @@ -330,7 +330,7 @@ void OriginalPathArrayParam::unlink(PathAndDirection* to) void OriginalPathArrayParam::remove_link(PathAndDirection* to) { unlink(to); - for (std::vector<PathAndDirection*>::iterator iter = _vector.begin(); iter != _vector.end(); iter++) { + for (std::vector<PathAndDirection*>::iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { if (*iter == to) { PathAndDirection *w = *iter; _vector.erase(iter); @@ -455,7 +455,7 @@ gchar * OriginalPathArrayParam::param_getSVGValue() const { Inkscape::SVGOStringStream os; bool foundOne = false; - for (std::vector<PathAndDirection*>::const_iterator iter = _vector.begin(); iter != _vector.end(); iter++) { + for (std::vector<PathAndDirection*>::const_iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { if (foundOne) { os << "|"; } else { diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 7302f9de6..5b7874c61 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -239,7 +239,7 @@ void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t, bool old_pref2 = _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_ROTATION_CENTER); if (old_pref2) { std::vector<SPItem*> rotationSource=_snapmanager->getRotationCenterSource(); - for ( std::vector<SPItem*>::const_iterator itemlist = rotationSource.begin(); itemlist != rotationSource.end(); itemlist++) { + for ( std::vector<SPItem*>::const_iterator itemlist = rotationSource.begin(); itemlist != rotationSource.end(); ++itemlist) { if ((*i).item == *itemlist) { // don't snap to this item's rotation center _snapmanager->snapprefs.setTargetSnappable(SNAPTARGET_ROTATION_CENTER, false); diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index c71465782..7b52ac2e1 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -71,14 +71,14 @@ sp_selected_path_combine(SPDesktop *desktop) items = sp_degroup_list (items); // descend into any groups in selection std::vector<SPItem*> to_paths; - for (std::vector<SPItem*>::const_reverse_iterator i = items.rbegin(); i != items.rend(); i++) { + for (std::vector<SPItem*>::const_reverse_iterator i = items.rbegin(); i != items.rend(); ++i) { if (!dynamic_cast<SPPath *>(*i) && !dynamic_cast<SPGroup *>(*i)) { to_paths.push_back(*i); } } std::vector<Inkscape::XML::Node*> converted; bool did = sp_item_list_to_curves(to_paths, items, converted); - for (std::vector<Inkscape::XML::Node*>::const_iterator i = converted.begin(); i != converted.end(); i++) + for (std::vector<Inkscape::XML::Node*>::const_iterator i = converted.begin(); i != converted.end(); ++i) items.push_back((SPItem*)doc->getObjectByRepr(*i)); items = sp_degroup_list (items); // converting to path may have added more groups, descend again @@ -101,7 +101,7 @@ sp_selected_path_combine(SPDesktop *desktop) selection->clear(); } - for (std::vector<SPItem*>::const_reverse_iterator i = items.rbegin(); i != items.rend(); i++){ + for (std::vector<SPItem*>::const_reverse_iterator i = items.rbegin(); i != items.rend(); ++i){ SPItem *item = *i; SPPath *path = dynamic_cast<SPPath *>(item); @@ -204,7 +204,7 @@ sp_selected_path_break_apart(SPDesktop *desktop) bool did = false; std::vector<SPItem*> itemlist(selection->itemList()); - for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i != itemlist.end(); i++){ + for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i != itemlist.end(); ++i){ SPItem *item = *i; @@ -354,7 +354,7 @@ bool sp_item_list_to_curves(const std::vector<SPItem*> &items, std::vector<SPItem*>& selected, std::vector<Inkscape::XML::Node*> &to_select, bool skip_all_lpeitems) { bool did = false; - for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++){ + for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); ++i){ SPItem *item = *i; g_assert(item != NULL); SPDocument *document = item->document; @@ -621,7 +621,7 @@ sp_selected_path_reverse(SPDesktop *desktop) bool did = false; desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths...")); - for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++){ + for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); ++i){ SPPath *path = dynamic_cast<SPPath *>(*i); if (!path) { diff --git a/src/persp3d.cpp b/src/persp3d.cpp index dc0975d12..a48481145 100644 --- a/src/persp3d.cpp +++ b/src/persp3d.cpp @@ -36,10 +36,10 @@ static int global_counter = 0; /* Constructor/destructor for the internal class */ -Persp3DImpl::Persp3DImpl() { - tmat = Proj::TransfMat3x4 (); - document = NULL; - +Persp3DImpl::Persp3DImpl() : + tmat (Proj::TransfMat3x4 ()), + document (NULL) +{ my_counter = global_counter++; } diff --git a/src/pure-transform.h b/src/pure-transform.h index 8ea74ce76..f973a95b1 100644 --- a/src/pure-transform.h +++ b/src/pure-transform.h @@ -54,10 +54,7 @@ public: // PureTranslate(); // Default constructor // PureTranslate(PureTranslate const &); // Copy constructor virtual ~PureTranslate() {}; - PureTranslate(Geom::Point vector = Geom::Point()) { - _vector = vector; - _vector_snapped = vector; - } + PureTranslate(Geom::Point vector = Geom::Point()) : _vector(vector), _vector_snapped(vector) {} Geom::Point getTranslationSnapped() {return _vector_snapped;} // PureTranslate * clone () const {return new PureTranslate(*this);} @@ -100,12 +97,12 @@ public: // PureScale(PureScale const &); // Copy constructor virtual ~PureScale() {}; - PureScale(Geom::Scale scale, Geom::Point origin, bool uniform) { - _scale = scale; - _scale_snapped = scale; - _origin = origin; - _uniform = uniform; - } + PureScale(Geom::Scale scale, Geom::Point origin, bool uniform) : + _scale (scale), + _scale_snapped (scale), + _origin (origin), + _uniform (uniform) + {} Geom::Scale getScaleSnapped() {return _scale_snapped;} // PureScale * clone () const {return new PureScale (*this);} @@ -142,12 +139,13 @@ protected: public: virtual ~PureStretchConstrained() {}; - PureStretchConstrained(Geom::Coord magnitude, Geom::Point origin, Geom::Dim2 direction, bool uniform) { - _magnitude = magnitude; - _origin = origin; - _direction = direction; - _uniform = uniform; - _stretch_snapped = Geom::Scale(magnitude, magnitude); + PureStretchConstrained(Geom::Coord magnitude, Geom::Point origin, Geom::Dim2 direction, bool uniform) : + _magnitude (magnitude), + _stretch_snapped (Geom::Scale(magnitude, magnitude)), + _origin (origin), + _direction (direction), + _uniform (uniform) + { if (not uniform) { _stretch_snapped[1-direction] = 1.0; } @@ -178,13 +176,13 @@ protected: public: virtual ~PureSkewConstrained() {}; - PureSkewConstrained(Geom::Coord skew, Geom::Coord scale, Geom::Point origin, Geom::Dim2 direction) { - _skew = skew; - _skew_snapped = skew; - _scale = scale; - _origin = origin; - _direction = direction; - }; + PureSkewConstrained(Geom::Coord skew, Geom::Coord scale, Geom::Point origin, Geom::Dim2 direction) : + _skew (skew), + _skew_snapped (skew), + _scale (scale), + _origin (origin), + _direction (direction) + {}; Geom::Coord getSkewSnapped() {return _skew_snapped;} @@ -212,12 +210,12 @@ public: // PureRotate(PureRotate const &); // Copy constructor virtual ~PureRotateConstrained() {}; - PureRotateConstrained(double angle, Geom::Point origin) { - _origin = origin; - _angle = angle; // in radians! - _angle_snapped = angle; - _uniform = true; // We do not yet allow for simultaneous rotation and scaling - } + PureRotateConstrained(double angle, Geom::Point origin) : + _angle (angle), // in radians! + _angle_snapped (angle), + _origin (origin), + _uniform (true) // We do not yet allow for simultaneous rotation and scaling + {} double getAngleSnapped() {return _angle_snapped;} diff --git a/src/selcue.cpp b/src/selcue.cpp index c73219b7d..297b9fffc 100644 --- a/src/selcue.cpp +++ b/src/selcue.cpp @@ -104,7 +104,7 @@ void Inkscape::SelCue::_updateItemBboxes(gint mode, int prefs_bbox) int bcount = 0; std::vector<SPItem*> ll=_selection->itemList(); - for (std::vector<SPItem*>::const_iterator l = ll.begin(); l != ll.end(); l++) { + for (std::vector<SPItem*>::const_iterator l = ll.begin(); l != ll.end(); ++l) { SPItem *item = *l; SPCanvasItem* box = _item_bboxes[bcount ++]; @@ -147,7 +147,7 @@ void Inkscape::SelCue::_newItemBboxes() int prefs_bbox = prefs->getBool("/tools/bounding_box"); std::vector<SPItem*> ll=_selection->itemList(); - for (std::vector<SPItem*>::const_iterator l = ll.begin(); l != ll.end(); l++) { + for (std::vector<SPItem*>::const_iterator l = ll.begin(); l != ll.end(); ++l) { SPItem *item = *l; Geom::OptRect const b = (prefs_bbox == 0) ? @@ -202,7 +202,7 @@ void Inkscape::SelCue::_newTextBaselines() _text_baselines.clear(); std::vector<SPItem*> ll = _selection->itemList(); - for (std::vector<SPItem*>::const_iterator l=ll.begin();l!=ll.end();l++) { + for (std::vector<SPItem*>::const_iterator l=ll.begin();l!=ll.end();++l) { SPItem *item = *l; SPCanvasItem* baseline_point = NULL; diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 85b62957c..cdbc6a937 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -284,7 +284,7 @@ void SelectionHelper::fixSelection(SPDesktop *dt) std::vector<SPItem*> const selList = selection->itemList(); - for( std::vector<SPItem*>::const_reverse_iterator i = selList.rbegin(); i != selList.rend(); i++ ) { + for( std::vector<SPItem*>::const_reverse_iterator i = selList.rbegin(); i != selList.rend(); ++i ) { SPItem *item = *i; if( item && !dt->isLayer(item) && @@ -330,7 +330,7 @@ static void sp_selection_copy_impl(std::vector<SPItem*> const &items, std::vecto sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position_bool); // Copy item reprs: - for (std::vector<SPItem*>::const_iterator i = sorted_items.begin(); i != sorted_items.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = sorted_items.begin(); i != sorted_items.end(); ++i) { SPItem *item = *i; if (item) { sp_selection_copy_one(item->getRepr(), item->i2doc_affine(), clip, xml_doc); @@ -351,7 +351,7 @@ static std::vector<Inkscape::XML::Node*> sp_selection_paste_impl(SPDocument *doc std::vector<Inkscape::XML::Node*> copied; // add objects to document - for (std::vector<Inkscape::XML::Node*>::const_iterator l = clip.begin(); l != clip.end(); l++) { + for (std::vector<Inkscape::XML::Node*>::const_iterator l = clip.begin(); l != clip.end(); ++l) { Inkscape::XML::Node *repr = *l; Inkscape::XML::Node *copy = repr->duplicate(xml_doc); @@ -378,10 +378,10 @@ static std::vector<Inkscape::XML::Node*> sp_selection_paste_impl(SPDocument *doc static void sp_selection_delete_impl(std::vector<SPItem*> const &items, bool propagate = true, bool propagate_descendants = true) { - for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); ++i) { sp_object_ref(*i, NULL); } - for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); ++i) { SPItem *item = *i; item->deleteObject(propagate, propagate_descendants); sp_object_unref(item, NULL); @@ -475,7 +475,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone, bool duplicat bool relink_clones = prefs->getBool("/options/relinkclonesonduplicate/value"); const bool fork_livepatheffects = prefs->getBool("/options/forklpeonduplicate/value", true); - for(std::vector<Inkscape::XML::Node*>::const_iterator i=reprs.begin();i!=reprs.end();i++){ + for(std::vector<Inkscape::XML::Node*>::const_iterator i=reprs.begin();i!=reprs.end();++i){ Inkscape::XML::Node *old_repr = *i; Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); @@ -483,7 +483,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone, bool duplicat if(! duplicateLayer) parent->appendChild(copy); else - parent->addChild(copy, old_repr); + parent->addChild(copy, old_repr); if (relink_clones) { SPObject *old_obj = doc->getObjectByRepr(old_repr); @@ -547,7 +547,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone, bool duplicat if(!duplicateLayer) selection->setReprList(newsel); else{ - SPObject* new_layer = doc->getObjectByRepr(newsel[0]); + SPObject* new_layer = doc->getObjectByRepr(newsel[0]); gchar* name = g_strdup_printf(_("%s copy"), new_layer->label()); desktop->layer_manager->renameLayer( new_layer, name, TRUE ); g_free(name); @@ -638,7 +638,7 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i std::vector<SPItem*> all_items = sp_item_group_item_list(dynamic_cast<SPGroup *>(dt->currentLayer())); - for (std::vector<SPItem*>::const_reverse_iterator i=all_items.rbegin();i!=all_items.rend();i++) { + for (std::vector<SPItem*>::const_reverse_iterator i=all_items.rbegin();i!=all_items.rend();++i) { SPItem *item = *i; if (item && (!onlysensitive || !item->isLocked())) { @@ -655,7 +655,7 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i break; } case PREFS_SELECTION_LAYER_RECURSIVE: { - std::vector<SPItem*> x; + std::vector<SPItem*> x; items = get_all_items(x, dt->currentLayer(), dt, onlyvisible, onlysensitive, FALSE, exclude); break; } @@ -698,7 +698,7 @@ static void sp_selection_group_impl(std::vector<Inkscape::XML::Node*> p, Inkscap gint topmost = p.back()->position(); Inkscape::XML::Node *topmost_parent = p.back()->parent(); - for(std::vector<Inkscape::XML::Node*>::const_iterator i = p.begin(); i != p.end(); i++){ + for(std::vector<Inkscape::XML::Node*>::const_iterator i = p.begin(); i != p.end(); ++i){ Inkscape::XML::Node *current = *i; if (current->parent() == topmost_parent) { @@ -802,7 +802,7 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) std::vector<SPItem*> old_select = selection->itemList(); std::vector<SPItem*> new_select; GSList *groups = NULL; - for (std::vector<SPItem*>::const_iterator item = old_select.begin(); item!=old_select.end(); item++) { + for (std::vector<SPItem*>::const_iterator item = old_select.begin(); item!=old_select.end(); ++item) { SPItem *obj = *item; if (dynamic_cast<SPGroup *>(obj)) { groups = g_slist_prepend(groups, obj); @@ -821,7 +821,7 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) // If any of the clones refer to the groups, unlink them and replace them with successors // in the items list. GSList *clones_to_unlink = NULL; - for (std::vector<SPItem*>::const_iterator item = items.begin(); item != items.end(); item++) { + for (std::vector<SPItem*>::const_iterator item = items.begin(); item != items.end(); ++item) { SPUse *use = dynamic_cast<SPUse *>(*item); SPItem *original = use; @@ -847,12 +847,12 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) g_slist_free(clones_to_unlink); // do the actual work - for (std::vector<SPItem*>::iterator item = items.begin(); item != items.end(); item++) { + for (std::vector<SPItem*>::iterator item = items.begin(); item != items.end(); ++item) { SPItem *obj = *item; // ungroup only the groups marked earlier if (g_slist_find(groups, *item) != NULL) { - std::vector<SPItem*> children; + std::vector<SPItem*> children; sp_item_group_ungroup(dynamic_cast<SPGroup *>(obj), children, false); // add the items resulting from ungrouping to the selection new_select.insert(new_select.end(),children.begin(),children.end()); @@ -873,16 +873,16 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) std::vector<SPItem*> sp_degroup_list(std::vector<SPItem*> &items) { - std::vector<SPItem*> out; + std::vector<SPItem*> out; bool has_groups = false; - for (std::vector<SPItem*>::const_iterator item=items.begin();item!=items.end();item++) { + for (std::vector<SPItem*>::const_iterator item=items.begin();item!=items.end();++item) { SPGroup *group = dynamic_cast<SPGroup *>(*item); if (!group) { out.push_back(*item); } else { has_groups = true; std::vector<SPItem*> members = sp_item_group_item_list(group); - for (std::vector<SPItem*>::const_iterator member=members.begin();member!=members.end();member++) { + for (std::vector<SPItem*>::const_iterator member=members.begin();member!=members.end();++member) { out.push_back(*member); } members.clear(); @@ -899,7 +899,7 @@ sp_degroup_list(std::vector<SPItem*> &items) /** If items in the list have a common parent, return it, otherwise return NULL */ static SPGroup * -sp_item_list_common_parent_group(std::vector<SPItem*> const items) +sp_item_list_common_parent_group(std::vector<SPItem*> const &items) { if (items.empty()) { return NULL; @@ -909,8 +909,8 @@ sp_item_list_common_parent_group(std::vector<SPItem*> const items) if (!dynamic_cast<SPGroup *>(parent)) { return NULL; } - for (std::vector<SPItem*>::const_iterator item=items.begin();item!=items.end();item++) { - if((*item)==items[0])continue; + for (std::vector<SPItem*>::const_iterator item=items.begin();item!=items.end();++item) { + if((*item)==items[0])continue; if ((*item)->parent != parent) { return NULL; } @@ -926,7 +926,7 @@ enclose_items(std::vector<SPItem*> const &items) g_assert(!items.empty()); Geom::OptRect r; - for (std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++) { + for (std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();++i) { r.unionWith((*i)->desktopVisualBounds()); } return r; @@ -945,7 +945,7 @@ static SPObject *prev_sibling(SPObject *child) bool sp_item_repr_compare_position_bool(SPObject const *first, SPObject const *second) { return sp_repr_compare_position(((SPItem*)first)->getRepr(), - ((SPItem*)second)->getRepr())<0; + ((SPItem*)second)->getRepr())<0; } void @@ -974,7 +974,7 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) // Iterate over all objects in the selection (starting from top). if (selected) { - for (std::vector<SPItem*>::const_iterator item=rev.begin();item!=rev.end();item++) { + for (std::vector<SPItem*>::const_iterator item=rev.begin();item!=rev.end();++item) { SPObject *child = *item; // for each selected object, find the next sibling for (SPObject *newref = child->next; newref; newref = newref->next) { @@ -1019,7 +1019,7 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto std::vector<Inkscape::XML::Node*> rl(selection->reprList()); sort(rl.begin(),rl.end(),sp_repr_compare_position_bool); - for (std::vector<Inkscape::XML::Node*>::const_iterator l=rl.begin(); l!=rl.end();l++) { + for (std::vector<Inkscape::XML::Node*>::const_iterator l=rl.begin(); l!=rl.end();++l) { Inkscape::XML::Node *repr =(*l); repr->setPosition(-1); } @@ -1053,7 +1053,7 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) // Iterate over all objects in the selection (starting from top). if (selected) { - for (std::vector<SPItem*>::const_reverse_iterator item=rev.rbegin();item!=rev.rend();item++) { + for (std::vector<SPItem*>::const_reverse_iterator item=rev.rbegin();item!=rev.rend();++item) { SPObject *child = *item; // for each selected object, find the prev sibling for (SPObject *newref = prev_sibling(child); newref; newref = prev_sibling(newref)) { @@ -1103,7 +1103,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des std::vector<Inkscape::XML::Node*> rl(selection->reprList()); sort(rl.begin(),rl.end(),sp_repr_compare_position_bool); - for (std::vector<Inkscape::XML::Node*>::const_reverse_iterator l=rl.rbegin();l!=rl.rend();l++) { + for (std::vector<Inkscape::XML::Node*>::const_reverse_iterator l=rl.rbegin();l!=rl.rend();++l) { gint minpos; SPObject *pp, *pc; Inkscape::XML::Node *repr = (*l); @@ -1256,7 +1256,7 @@ void sp_selection_remove_livepatheffect(SPDesktop *desktop) return; } std::vector<SPItem*> list=selection->itemList(); - for ( std::vector<SPItem*>::const_iterator itemlist=list.begin();itemlist!=list.end();itemlist++) { + for ( std::vector<SPItem*>::const_iterator itemlist=list.begin();itemlist!=list.end();++itemlist) { SPItem *item = *itemlist; sp_selection_remove_livepatheffect_impl(item); @@ -1313,7 +1313,7 @@ void sp_selection_paste_size_separately(SPDesktop *desktop, bool apply_x, bool a */ void sp_selection_change_layer_maintain_clones(std::vector<SPItem*> const &items,SPObject *where) { - for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); ++i) { SPItem *item = *i; if (item) { SPItem *oldparent = dynamic_cast<SPItem *>(item->parent); @@ -1472,7 +1472,7 @@ selection_contains_both_clone_and_original(Inkscape::Selection *selection) { bool clone_with_original = false; std::vector<SPItem*> items = selection->itemList(); - for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;l++) { + for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;++l) { SPItem *item = *l; if (item) { clone_with_original |= selection_contains_original(item, selection); @@ -1517,7 +1517,7 @@ void sp_selection_apply_affine(Inkscape::Selection *selection, Geom::Affine cons persp3d_apply_affine_transformation(transf_persp, affine); } std::vector<SPItem*> items = selection->itemList(); - for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;l++) { + for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;++l) { SPItem *item = *l; if( dynamic_cast<SPRoot *>(item) ) { @@ -1688,7 +1688,7 @@ void sp_selection_remove_transform(SPDesktop *desktop) Inkscape::Selection *selection = desktop->getSelection(); std::vector<Inkscape::XML::Node*> items = selection->reprList(); - for (std::vector<Inkscape::XML::Node*>::const_iterator l=items.begin();l!=items.end() ;l++) { + for (std::vector<Inkscape::XML::Node*>::const_iterator l=items.begin();l!=items.end() ;++l) { (*l)->setAttribute("transform", NULL, false); } @@ -1789,7 +1789,7 @@ void sp_selection_rotate_90(SPDesktop *desktop, bool ccw) std::vector<SPItem*> items = selection->itemList(); Geom::Rotate const rot_90(Geom::Point(0, ccw ? 1 : -1)); // pos. or neg. rotation, depending on the value of ccw - for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;l++) { + for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;++l) { SPItem *item = *l; if (item) { sp_item_rotate_rel(item, rot_90); @@ -1854,14 +1854,14 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea std::vector<SPItem*> items = selection->itemList(); std::vector<SPItem*> tmp; - for (std::vector<SPItem*>::const_iterator iter=all_list.begin();iter!=all_list.end();iter++) { + for (std::vector<SPItem*>::const_iterator iter=all_list.begin();iter!=all_list.end();++iter) { if(!SP_IS_GROUP(*iter)){ tmp.push_back(*iter); } } all_list=tmp; - for (std::vector<SPItem*>::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + for (std::vector<SPItem*>::const_iterator sel_iter=items.begin();sel_iter!=items.end();++sel_iter) { SPItem *sel = *sel_iter; std::vector<SPItem*> matches = all_list; if (fill && stroke && style) { @@ -1909,7 +1909,7 @@ void sp_select_same_object_type(SPDesktop *desktop) Inkscape::Selection *selection = desktop->getSelection(); std::vector<SPItem*> items=selection->itemList(); - for (std::vector<SPItem*>::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) { + for (std::vector<SPItem*>::const_iterator sel_iter=items.begin();sel_iter!=items.end();++sel_iter) { SPItem *sel = *sel_iter; if (sel) { matches = sp_get_same_object_type(sel, matches); @@ -1936,7 +1936,7 @@ std::vector<SPItem*> sp_get_same_fill_or_stroke_color(SPItem *sel, std::vector<S SPIPaint *sel_paint = (type == SP_FILL_COLOR) ? &(sel->style->fill) : &(sel->style->stroke); - for (std::vector<SPItem*>::const_reverse_iterator i=src.rbegin();i!=src.rend();i++) { + for (std::vector<SPItem*>::const_reverse_iterator i=src.rbegin();i!=src.rend();++i) { SPItem *iter = *i; if (iter) { SPIPaint *iter_paint = (type == SP_FILL_COLOR) ? &(iter->style->fill) : &(iter->style->stroke); @@ -2031,7 +2031,7 @@ std::vector<SPItem*> sp_get_same_object_type(SPItem *sel, std::vector<SPItem*> & { std::vector<SPItem*> matches; - for (std::vector<SPItem*>::const_reverse_iterator i=src.rbegin();i!=src.rend();i++) { + for (std::vector<SPItem*>::const_reverse_iterator i=src.rbegin();i!=src.rend();++i) { SPItem *item = *i; if (item && item_type_match(sel, item) && !item->cloned) { matches.push_back(item); @@ -2072,7 +2072,7 @@ std::vector<SPItem*> sp_get_same_style(SPItem *sel, std::vector<SPItem*> &src, S objects_query_strokewidth (objects, sel_style_for_width); } bool match_g; - for (std::vector<SPItem*>::const_iterator i=src.begin();i!=src.end();i++) { + for (std::vector<SPItem*>::const_iterator i=src.begin();i!=src.end();++i) { SPItem *iter = *i; if (iter) { match_g=true; @@ -2112,7 +2112,7 @@ std::vector<SPItem*> sp_get_same_style(SPItem *sel, std::vector<SPItem*> &src, S } } } - match_g = match_g && match; + match_g = match_g && match; if (match_g) { while (iter->cloned) iter=dynamic_cast<SPItem *>(iter->parent); matches.insert(matches.begin(),iter); @@ -2371,11 +2371,11 @@ SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root, template <typename D> -SPItem *next_item_from_list(SPDesktop *desktop, std::vector<SPItem*> const items, +SPItem *next_item_from_list(SPDesktop *desktop, std::vector<SPItem*> const &items, SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive) { SPObject *current=root; - for(std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++) { + for(std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();++i) { SPItem *item = *i; if ( root->isAncestorOf(item) && ( !only_in_viewport || desktop->isWithinViewport(item) ) ) @@ -2577,8 +2577,8 @@ void sp_selection_clone(SPDesktop *desktop) std::vector<Inkscape::XML::Node*> newsel; - for(std::vector<Inkscape::XML::Node*>::const_iterator i=reprs.begin();i!=reprs.end();i++){ - Inkscape::XML::Node *sel_repr = *i; + for(std::vector<Inkscape::XML::Node*>::const_iterator i=reprs.begin();i!=reprs.end();++i){ + Inkscape::XML::Node *sel_repr = *i; Inkscape::XML::Node *parent = sel_repr->parent(); Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); @@ -2628,7 +2628,7 @@ sp_selection_relink(SPDesktop *desktop) // Get a copy of current selection. bool relinked = false; std::vector<SPItem*> items=selection->itemList(); - for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){ SPItem *item = *i; if (dynamic_cast<SPUse *>(item)) { @@ -2666,7 +2666,7 @@ sp_selection_unlink(SPDesktop *desktop) std::vector<SPItem*> new_select; bool unlinked = false; std::vector<SPItem*> items=selection->itemList(); - for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ + for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();++i){ SPItem *item = *i; if (dynamic_cast<SPText *>(item)) { @@ -2831,7 +2831,7 @@ void sp_selection_clone_original_path_lpe(SPDesktop *desktop) Inkscape::SVGOStringStream os; SPObject * firstItem = NULL; std::vector<SPItem*> items=selection->itemList(); - for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){ if (SP_IS_SHAPE(*i) || SP_IS_TEXT(*i)) { if (firstItem) { os << "|"; @@ -2934,7 +2934,7 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) // Create a list of duplicates, to be pasted inside marker element. std::vector<Inkscape::XML::Node*> repr_copies; - for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ + for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();++i){ Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc); repr_copies.push_back(dup); } @@ -2944,7 +2944,7 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) if (apply) { // Delete objects so that their clones don't get alerted; // the objects will be restored inside the marker element. - for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){ SPObject *item = *i; item->deleteObject(false); } @@ -2973,7 +2973,7 @@ static void sp_selection_to_guides_recursive(SPItem *item, bool wholegroups) { SPGroup *group = dynamic_cast<SPGroup *>(item); if (group && !dynamic_cast<SPBox3D *>(item) && !wholegroups) { std::vector<SPItem*> items=sp_item_group_item_list(group); - for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){ sp_selection_to_guides_recursive(*i, wholegroups); } } else { @@ -3004,7 +3004,7 @@ void sp_selection_to_guides(SPDesktop *desktop) // and its entry in the selection list is invalid (crash). // Therefore: first convert all, then delete all. - for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){ sp_selection_to_guides_recursive(*i, wholegroups); } @@ -3122,7 +3122,7 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) } // Move selected items to new <symbol> - for (std::vector<SPObject*>::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ + for (std::vector<SPObject*>::const_reverse_iterator i=items.rbegin();i!=items.rend();++i){ Inkscape::XML::Node *repr = (*i)->getRepr(); repr->parent()->removeChild(repr); symbol_repr->addChild(repr,NULL); @@ -3206,7 +3206,7 @@ void sp_selection_unsymbol(SPDesktop *desktop) } } - for (std::vector<SPObject*>::const_reverse_iterator i=children.rbegin();i!=children.rend();i++){ + for (std::vector<SPObject*>::const_reverse_iterator i=children.rbegin();i!=children.rend();++i){ Inkscape::XML::Node *repr = (*i)->getRepr(); repr->parent()->removeChild(repr); group->addChild(repr,NULL); @@ -3290,7 +3290,7 @@ sp_selection_tile(SPDesktop *desktop, bool apply) // create a list of duplicates std::vector<Inkscape::XML::Node*> repr_copies; - for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){ Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc); repr_copies.push_back(dup); } @@ -3299,7 +3299,7 @@ sp_selection_tile(SPDesktop *desktop, bool apply) if (apply) { // delete objects so that their clones don't get alerted; this object will be restored shortly - for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){ SPObject *item = *i; item->deleteObject(false); } @@ -3373,7 +3373,7 @@ void sp_selection_untile(SPDesktop *desktop) bool did = false; std::vector<SPItem*> items(selection->itemList()); - for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){ + for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();++i){ SPItem *item = *i; SPStyle *style = item->style; @@ -3442,7 +3442,7 @@ void sp_selection_get_export_hints(Inkscape::Selection *selection, Glib::ustring bool xdpi_search = TRUE; bool ydpi_search = TRUE; - for (std::vector<Inkscape::XML::Node*>::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();i++){ + for (std::vector<Inkscape::XML::Node*>::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();++i){ gchar const *dpi_string; Inkscape::XML::Node *repr = *i; @@ -3493,7 +3493,6 @@ void sp_document_get_export_hints(SPDocument *doc, Glib::ustring &filename, floa *xdpi = atof(dpi_string); } - dpi_string = NULL; dpi_string = repr->attribute("inkscape:export-ydpi"); if (dpi_string != NULL) { *ydpi = atof(dpi_string); @@ -3743,8 +3742,8 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) Inkscape::XML::Node *inner = xml_doc->createElement("svg:g"); inner->setAttribute("inkscape:label", "Clip"); - for(std::vector<Inkscape::XML::Node*>::const_iterator i=p.begin();i!=p.end();i++){ - Inkscape::XML::Node *current = *i; + for(std::vector<Inkscape::XML::Node*>::const_iterator i=p.begin();i!=p.end();++i){ + Inkscape::XML::Node *current = *i; if (current->parent() == topmost_parent) { Inkscape::XML::Node *spnew = current->duplicate(xml_doc); @@ -3879,12 +3878,12 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ apply_to_items.push_back(SP_ITEM(desktop->currentLayer())); } - for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++) { + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i) { if((!topmost && !apply_to_layer && *i == items.front()) || (topmost && !apply_to_layer && *i == items.back()) - || apply_to_layer){ + || apply_to_layer){ - Geom::Affine oldtr=(*i)->transform; + Geom::Affine oldtr=(*i)->transform; (*i)->doWriteTransform((*i)->getRepr(), (*i)->i2doc_affine()); Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc); (*i)->doWriteTransform((*i)->getRepr(), oldtr); @@ -3896,7 +3895,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ else { items_to_select.push_back(*i); } - continue; + continue; }else{ apply_to_items.push_back(*i); items_to_select.push_back(*i); @@ -3914,7 +3913,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ group->setAttribute("inkscape:groupmode", "maskhelper"); std::vector<Inkscape::XML::Node*> reprs_to_group; - for (std::vector<SPItem*>::const_iterator i = apply_to_items.begin(); i != apply_to_items.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = apply_to_items.begin(); i != apply_to_items.end(); ++i) { reprs_to_group.push_back(static_cast<SPObject*>(*i)->getRepr()); } items_to_select.clear(); @@ -3935,13 +3934,13 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ gchar const *attributeName = apply_clip_path ? "clip-path" : "mask"; - for (std::vector<SPItem*>::const_reverse_iterator i = apply_to_items.rbegin(); i != apply_to_items.rend(); i++) { + for (std::vector<SPItem*>::const_reverse_iterator i = apply_to_items.rbegin(); i != apply_to_items.rend(); ++i) { SPItem *item = reinterpret_cast<SPItem *>(*i); // inverted object transform should be applied to a mask object, // as mask is calculated in user space (after applying transform) std::vector<Inkscape::XML::Node*> mask_items_dup; - for(std::vector<Inkscape::XML::Node*>::const_iterator it=mask_items.begin();it!=mask_items.end();it++) - mask_items_dup.push_back((*it)->duplicate(xml_doc)); + for(std::vector<Inkscape::XML::Node*>::const_iterator it=mask_items.begin();it!=mask_items.end();++it) + mask_items_dup.push_back((*it)->duplicate(xml_doc)); Inkscape::XML::Node *current = SP_OBJECT(*i)->getRepr(); // Node to apply mask to Inkscape::XML::Node *apply_mask_to = current; @@ -3980,7 +3979,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ } - for (std::vector<SPItem*>::const_iterator i = items_to_delete.begin(); i != items_to_delete.end(); i++) { + for (std::vector<SPItem*>::const_iterator i = items_to_delete.begin(); i != items_to_delete.end(); ++i) { SPObject *item = reinterpret_cast<SPObject*>(*i); item->deleteObject(false); items_to_select.erase(remove(items_to_select.begin(), items_to_select.end(), item), items_to_select.end()); @@ -4027,7 +4026,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { // SPObject* refers to a group containing the clipped path or mask itself, // whereas SPItem* refers to the item being clipped or masked - for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){ if (remove_original) { // remember referenced mask/clippath, so orphaned masks can be moved back to document SPItem *item = *i; diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp index 8304db684..ddc7a0d10 100644 --- a/src/selection-describer.cpp +++ b/src/selection-describer.cpp @@ -46,7 +46,7 @@ char* collect_terms (const std::vector<SPItem*> &items) std::stringstream ss; bool first = true; - for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();++iter ) { SPItem *item = *iter; if (item) { const char *term = item->displayName(); @@ -65,7 +65,7 @@ static int count_terms (const std::vector<SPItem*> &items) { GSList *check = NULL; int count=0; - for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();++iter ) { SPItem *item = *iter; if (item) { const char *term = item->displayName(); @@ -82,7 +82,7 @@ static int count_terms (const std::vector<SPItem*> &items) static int count_filtered (const std::vector<SPItem*> &items) { int count=0; - for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();++iter ) { SPItem *item = *iter; if (item) { count += item->isFiltered(); diff --git a/src/selection.cpp b/src/selection.cpp index 77a507eec..020912381 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -255,7 +255,7 @@ void Selection::addList(std::vector<SPItem*> const &list) { _invalidateCachedLists(); - for ( std::vector<SPItem*>::const_iterator iter=list.begin();iter!=list.end();iter++ ) { + for ( std::vector<SPItem*>::const_iterator iter=list.begin();iter!=list.end(); ++iter) { SPObject *obj = *iter; if (includes(obj)) continue; _add (obj); @@ -267,7 +267,7 @@ void Selection::addList(std::vector<SPItem*> const &list) { void Selection::setReprList(std::vector<XML::Node*> const &list) { _clear(); - for ( std::vector<XML::Node*>::const_reverse_iterator iter=list.rbegin();iter!=list.rend();iter++ ) { + for ( std::vector<XML::Node*>::const_reverse_iterator iter=list.rbegin();iter!=list.rend(); ++iter) { SPObject *obj=_objectForXMLNode(*iter); if (obj) { _add(obj); @@ -286,7 +286,7 @@ std::vector<SPObject*> const &Selection::list() { if(!_objs_vector.empty()) return _objs_vector; - for ( std::list<SPObject*>::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + for ( std::list<SPObject*>::const_iterator iter=_objs.begin();iter!=_objs.end(); ++iter) { _objs_vector.push_back(*iter); } return _objs_vector; @@ -298,7 +298,7 @@ std::vector<SPItem*> const &Selection::itemList() { return _items; } - for ( std::list<SPObject*>::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + for ( std::list<SPObject*>::const_iterator iter=_objs.begin();iter!=_objs.end(); ++iter) { SPObject *obj=*iter; if (SP_IS_ITEM(obj)) { _items.push_back(SP_ITEM(obj)); @@ -310,7 +310,7 @@ std::vector<SPItem*> const &Selection::itemList() { std::vector<XML::Node*> const &Selection::reprList() { if (!_reprs.empty()) { return _reprs; } std::vector<SPItem*> list = itemList(); - for ( std::vector<SPItem*>::const_iterator iter=list.begin();iter!=list.end();iter++ ) { + for ( std::vector<SPItem*>::const_iterator iter=list.begin();iter!=list.end(); ++iter) { SPObject *obj = *iter; _reprs.push_back(obj->getRepr()); } @@ -372,7 +372,7 @@ SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) { gdouble max = sml ? 1e18 : 0; SPItem *ist = NULL; - for ( std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++ ) { + for ( std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end(); ++i) { Geom::OptRect obox = SP_ITEM(*i)->desktopPreferredBounds(); if (!obox || obox.isEmpty()) continue; Geom::Rect bbox = *obox; @@ -404,7 +404,7 @@ Geom::OptRect Selection::geometricBounds() const std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); Geom::OptRect bbox; - for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end(); ++iter) { bbox.unionWith(SP_ITEM(*iter)->desktopGeometricBounds()); } return bbox; @@ -415,7 +415,7 @@ Geom::OptRect Selection::visualBounds() const std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); Geom::OptRect bbox; - for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end(); ++iter) { bbox.unionWith(SP_ITEM(*iter)->desktopVisualBounds()); } return bbox; @@ -436,7 +436,7 @@ Geom::OptRect Selection::documentBounds(SPItem::BBoxType type) const std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); if (items.empty()) return bbox; - for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end(); ++iter) { SPItem *item = SP_ITEM(*iter); bbox |= item->documentBounds(type); } @@ -463,19 +463,21 @@ boost::optional<Geom::Point> Selection::center() const { } std::vector<Inkscape::SnapCandidatePoint> Selection::getSnapPoints(SnapPreferences const *snapprefs) const { - std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); - - SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs - snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER, false); // locally disable snapping to the item center std::vector<Inkscape::SnapCandidatePoint> p; - for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { - SPItem *this_item = *iter; - this_item->getSnappoints(p, &snapprefs_dummy); - - //Include the transformation origin for snapping - //For a selection or group only the overall center is considered, not for each item individually - if (snapprefs != NULL && snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER)) { - p.push_back(Inkscape::SnapCandidatePoint(this_item->getCenter(), SNAPSOURCE_ROTATION_CENTER)); + + if (snapprefs != NULL){ + SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs + snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER, false); // locally disable snapping to the item center + std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end(); ++iter) { + SPItem *this_item = *iter; + this_item->getSnappoints(p, &snapprefs_dummy); + + //Include the transformation origin for snapping + //For a selection or group only the overall center is considered, not for each item individually + if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER)) { + p.push_back(Inkscape::SnapCandidatePoint(this_item->getCenter(), SNAPSOURCE_ROTATION_CENTER)); + } } } @@ -484,7 +486,7 @@ std::vector<Inkscape::SnapCandidatePoint> Selection::getSnapPoints(SnapPreferenc void Selection::_removeObjectDescendants(SPObject *obj) { std::vector<SPObject*> toremove; - for ( std::list<SPObject*>::const_iterator iter=_objs.begin();iter!=_objs.end();iter++ ) { + for ( std::list<SPObject*>::const_iterator iter=_objs.begin();iter!=_objs.end(); ++iter) { SPObject *sel_obj= dynamic_cast<SPObject*>(*iter); SPObject *parent = sel_obj->parent; while (parent) { @@ -495,7 +497,7 @@ void Selection::_removeObjectDescendants(SPObject *obj) { parent = parent->parent; } } - for ( std::vector<SPObject*>::const_iterator iter=toremove.begin();iter!=toremove.end();iter++ ) { + for ( std::vector<SPObject*>::const_iterator iter=toremove.begin();iter!=toremove.end(); ++iter) { _remove(*iter); } } @@ -522,7 +524,7 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const { size_t Selection::numberOfLayers() { std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); std::set<SPObject*> layers; - for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end(); ++iter) { SPObject *layer = _layers->layerForObject(*iter); layers.insert(layer); } @@ -532,7 +534,7 @@ size_t Selection::numberOfLayers() { size_t Selection::numberOfParents() { std::vector<SPItem*> const items = const_cast<Selection *>(this)->itemList(); std::set<SPObject*> parents; - for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end();iter++ ) { + for ( std::vector<SPItem*>::const_iterator iter=items.begin();iter!=items.end(); ++iter) { SPObject *parent = (*iter)->parent; parents.insert(parent); } diff --git a/src/snap.cpp b/src/snap.cpp index 5a4a047b2..4721283c3 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -710,7 +710,7 @@ void SnapManager::setupIgnoreSelection(SPDesktop const *desktop, Inkscape::Selection *sel = _desktop->selection; std::vector<SPItem*> const items = sel->itemList(); - for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++) { + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i) { _items_to_ignore.push_back(*i); } } diff --git a/src/sp-clippath.cpp b/src/sp-clippath.cpp index d66508eae..0c07d1b3d 100644 --- a/src/sp-clippath.cpp +++ b/src/sp-clippath.cpp @@ -308,7 +308,7 @@ const gchar *SPClipPath::create (std::vector<Inkscape::XML::Node*> &reprs, SPDoc const gchar *id = repr->attribute("id"); SPObject *clip_path_object = document->getObjectById(id); - for (std::vector<Inkscape::XML::Node*>::const_iterator it = reprs.begin(); it != reprs.end(); it++) { + for (std::vector<Inkscape::XML::Node*>::const_iterator it = reprs.begin(); it != reprs.end(); ++it) { Inkscape::XML::Node *node = (*it); SPItem *item = SP_ITEM(clip_path_object->appendChildRepr(node)); diff --git a/src/sp-clippath.h b/src/sp-clippath.h index c9a8c68df..8abe97f3f 100644 --- a/src/sp-clippath.h +++ b/src/sp-clippath.h @@ -93,10 +93,10 @@ protected: Inkscape::XML::Node * const owner_repr = owner->getRepr(); //XML Tree being used directly here while it shouldn't be... Inkscape::XML::Node * const obj_repr = obj->getRepr(); - char const * owner_name = NULL; - char const * owner_clippath = NULL; - char const * obj_name = NULL; - char const * obj_id = NULL; + char const * owner_name = ""; + char const * owner_clippath = ""; + char const * obj_name = ""; + char const * obj_id = ""; if (owner_repr != NULL) { owner_name = owner_repr->name(); owner_clippath = owner_repr->attribute("clippath"); diff --git a/src/sp-filter.cpp b/src/sp-filter.cpp index 1bde69dd1..c17c67fc5 100644 --- a/src/sp-filter.cpp +++ b/src/sp-filter.cpp @@ -246,7 +246,7 @@ void SPFilter::update(SPCtx *ctx, guint flags) { } childflags &= SP_OBJECT_MODIFIED_CASCADE; std::vector<SPObject*> l(this->childList(true, SPObject::ActionUpdate)); - for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();i++){ + for(std::vector<SPObject*>::const_iterator i=l.begin();i!=l.end();++i){ SPObject *child = *i; if( SP_IS_FILTER_PRIMITIVE( child ) ) { child->updateDisplay(ctx, childflags); diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index b9c124138..bbdf5f260 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -103,8 +103,8 @@ void SPGuide::set(unsigned int key, const gchar *value) { } break; case SP_ATTR_INKSCAPE_LABEL: - if (this->label) g_free(this->label); - + // this->label already freed in sp_guideline_set_label (src/display/guideline.cpp) + // see bug #1498444, bug #1469514 if (value) { this->label = g_strdup(value); } else { diff --git a/src/sp-hatch.cpp b/src/sp-hatch.cpp index ea4c5865a..2d938618c 100644 --- a/src/sp-hatch.cpp +++ b/src/sp-hatch.cpp @@ -113,7 +113,7 @@ void SPHatch::child_added(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) SPHatchPath *path_child = dynamic_cast<SPHatchPath *>(document->getObjectByRepr(child)); if (path_child) { - for (ViewIterator iter = _display.begin(); iter != _display.end(); iter++) { + for (ViewIterator iter = _display.begin(); iter != _display.end(); ++iter) { Geom::OptInterval extents = _calculateStripExtents(iter->bbox); Inkscape::DrawingItem *ac = path_child->show(iter->arenaitem->drawing(), iter->key, extents); diff --git a/src/sp-mask.cpp b/src/sp-mask.cpp index f8fb7aff4..5f7a2ec26 100644 --- a/src/sp-mask.cpp +++ b/src/sp-mask.cpp @@ -221,7 +221,7 @@ sp_mask_create (std::vector<Inkscape::XML::Node*> &reprs, SPDocument *document, const gchar *mask_id = repr->attribute("id"); SPObject *mask_object = document->getObjectById(mask_id); - for (std::vector<Inkscape::XML::Node*>::const_iterator it = reprs.begin(); it != reprs.end(); it++) { + for (std::vector<Inkscape::XML::Node*>::const_iterator it = reprs.begin(); it != reprs.end(); ++it) { Inkscape::XML::Node *node = (*it); SPItem *item = SP_ITEM(mask_object->appendChildRepr(node)); diff --git a/src/sp-mask.h b/src/sp-mask.h index 74bd4d66e..19786b1fd 100644 --- a/src/sp-mask.h +++ b/src/sp-mask.h @@ -86,10 +86,10 @@ protected: Inkscape::XML::Node * const owner_repr = owner->getRepr(); //XML Tree being used directly here while it shouldn't be... Inkscape::XML::Node * const obj_repr = obj->getRepr(); - char const * owner_name = NULL; - char const * owner_mask = NULL; - char const * obj_name = NULL; - char const * obj_id = NULL; + char const * owner_name = ""; + char const * owner_mask = ""; + char const * obj_name = ""; + char const * obj_id = ""; if (owner_repr != NULL) { owner_name = owner_repr->name(); owner_mask = owner_repr->attribute("mask"); diff --git a/src/sp-pattern.cpp b/src/sp-pattern.cpp index 755d3d162..dd351a8d5 100644 --- a/src/sp-pattern.cpp +++ b/src/sp-pattern.cpp @@ -244,7 +244,7 @@ void SPPattern::update(SPCtx *ctx, unsigned int flags) std::list<SPObject *> l; _getChildren(l); - for (SPObjectIterator it = l.begin(); it != l.end(); it++) { + for (SPObjectIterator it = l.begin(); it != l.end(); ++it) { SPObject *child = *it; sp_object_ref(child, NULL); @@ -270,7 +270,7 @@ void SPPattern::modified(unsigned int flags) std::list<SPObject *> l; _getChildren(l); - for (SPObjectIterator it = l.begin(); it != l.end(); it++) { + for (SPObjectIterator it = l.begin(); it != l.end(); ++it) { SPObject *child = *it; sp_object_ref(child, NULL); @@ -398,7 +398,7 @@ const gchar *SPPattern::produce(const std::vector<Inkscape::XML::Node *> &reprs, const gchar *pat_id = repr->attribute("id"); SPObject *pat_object = document->getObjectById(pat_id); - for (NodePtrIterator i = reprs.begin(); i != reprs.end(); i++) { + for (NodePtrIterator i = reprs.begin(); i != reprs.end(); ++i) { Inkscape::XML::Node *node = *i; SPItem *copy = SP_ITEM(pat_object->appendChildRepr(node)); diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 0792fb9c5..354fa45dc 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -525,7 +525,7 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a // resize each object in the selection if (separately) { std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (item) { Geom::OptRect obj_size = item->desktopVisualBounds(); @@ -581,7 +581,7 @@ bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop) // make sure all selected items are converted to paths first (i.e. rectangles) sp_selected_to_lpeitems(desktop); std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; _applyPathEffect(item, effectstack); } @@ -665,7 +665,7 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) // copy the defs used by all items std::vector<SPItem*> itemlist=selection->itemList(); cloned_elements.clear(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (item) { _copyUsedDefs(item); @@ -676,7 +676,7 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) // copy the representation of the items std::vector<SPObject*> sorted_items; - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++) + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i) sorted_items.push_back(*i); sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position_bool); @@ -692,7 +692,7 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) sorted_items.insert(sorted_items.end(),cloned_elements.begin(),cloned_elements.end()); - for(std::vector<SPObject*>::const_iterator i=sorted_items.begin();i!=sorted_items.end();i++){ + for(std::vector<SPObject*>::const_iterator i=sorted_items.begin();i!=sorted_items.end();++i){ SPItem *item = dynamic_cast<SPItem*>(*i); if (item) { Inkscape::XML::Node *obj = item->getRepr(); diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index da1c6d9fb..fbd050f8e 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -85,7 +85,7 @@ CloneTiler::CloneTiler () : { Gtk::Box *contents = _getContents(); contents->set_spacing(0); - + { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -101,7 +101,7 @@ CloneTiler::CloneTiler () : contents->pack_start (*Gtk::manage(Glib::wrap(mainbox)), true, true, 0); - GtkWidget *nb = gtk_notebook_new (); + nb = gtk_notebook_new (); gtk_box_pack_start (GTK_BOX (mainbox), nb, FALSE, FALSE, 0); @@ -662,7 +662,7 @@ CloneTiler::CloneTiler () : gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0); guint32 rgba = 0x000000ff | sp_svg_read_color (prefs->getString(prefs_path + "initial_color").data(), 0x000000ff); - color_picker = new Inkscape::UI::Widget::ColorPicker (*new Glib::ustring(_("Initial color of tiled clones")), *new Glib::ustring(_("Initial color for clones (works only if the original has unset fill or stroke)")), rgba, false); + color_picker = new Inkscape::UI::Widget::ColorPicker (*new Glib::ustring(_("Initial color of tiled clones")), *new Glib::ustring(_("Initial color for clones (works only if the original has unset fill or stroke or on spray tool in copy mode)")), rgba, false); color_changed_connection = color_picker->connectChanged (sigc::ptr_fun(on_picker_color_changed)); gtk_box_pack_start (GTK_BOX (hb), reinterpret_cast<GtkWidget*>(color_picker->gobj()), FALSE, FALSE, 0); @@ -776,8 +776,6 @@ CloneTiler::CloneTiler () : // Trace { GtkWidget *vb = clonetiler_new_tab (nb, _("_Trace")); - - { #if GTK_CHECK_VERSION(3,0,0) GtkWidget *hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, VB_MARGIN); @@ -787,11 +785,11 @@ CloneTiler::CloneTiler () : #endif gtk_box_pack_start (GTK_BOX (vb), hb, FALSE, FALSE, 0); - GtkWidget *b = gtk_check_button_new_with_label (_("Trace the drawing under the tiles")); + b = gtk_check_button_new_with_label (_("Trace the drawing under the clones/sprayed items")); g_object_set_data (G_OBJECT(b), "uncheckable", GINT_TO_POINTER(TRUE)); bool old = prefs->getBool(prefs_path + "dotrace"); gtk_toggle_button_set_active ((GtkToggleButton *) b, old); - gtk_widget_set_tooltip_text (b, _("For each clone, pick a value from the drawing in that clone's location and apply it to the clone")); + gtk_widget_set_tooltip_text (b, _("For each clone/sprayed item, pick a value from the drawing in its location and apply it")); gtk_box_pack_start (GTK_BOX (hb), b, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(b), "toggled", @@ -1001,6 +999,18 @@ CloneTiler::CloneTiler () : } } + { +#if GTK_CHECK_VERSION(3,0,0) + GtkWidget *hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, VB_MARGIN); + gtk_box_set_homogeneous(GTK_BOX(hb), FALSE); +#else + GtkWidget *hb = gtk_hbox_new(FALSE, VB_MARGIN); +#endif + gtk_box_pack_start (GTK_BOX (mainbox), hb, FALSE, FALSE, 0); + GtkWidget *l = gtk_label_new(_("")); + gtk_label_set_markup (GTK_LABEL(l), _("Apply to tiled clones:")); + gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0); + } // Rows/columns, width/height { #if GTK_CHECK_VERSION(3,0,0) @@ -1289,7 +1299,6 @@ CloneTiler::CloneTiler () : } gtk_widget_show_all (mainbox); - } show_all(); @@ -3005,6 +3014,13 @@ void CloneTiler::clonetiler_do_pick_toggled(GtkToggleButton *tb, GtkWidget *dlg) } } +void CloneTiler::show_page_trace() +{ + gtk_notebook_set_current_page(GTK_NOTEBOOK(nb),6); + gtk_toggle_button_set_active ((GtkToggleButton *) b, false); +} + + } } } diff --git a/src/ui/dialog/clonetiler.h b/src/ui/dialog/clonetiler.h index e5f5638b2..a8f1df0a0 100644 --- a/src/ui/dialog/clonetiler.h +++ b/src/ui/dialog/clonetiler.h @@ -31,7 +31,7 @@ public: virtual ~CloneTiler(); static CloneTiler &getInstance() { return *new CloneTiler(); } - + void show_page_trace(); protected: GtkWidget * clonetiler_new_tab(GtkWidget *nb, const gchar *label); @@ -113,6 +113,8 @@ private: CloneTiler& operator=(CloneTiler const &d); GtkWidget *dlg; + GtkWidget *nb; + GtkWidget *b; SPDesktop *desktop; DesktopTracker deskTrack; Inkscape::UI::Widget::ColorPicker *color_picker; diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 59fab7771..2fb5f9e3b 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -821,7 +821,7 @@ void Export::onAreaToggled () if (filename.empty()) { const gchar * id = "object"; const std::vector<XML::Node*> reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList(); - for(std::vector<XML::Node*>::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { + for(std::vector<XML::Node*>::const_iterator i=reprlst.begin(); reprlst.end() != i; ++i) { Inkscape::XML::Node * repr = *i; if (repr->attribute("id")) { id = repr->attribute("id"); @@ -1030,7 +1030,7 @@ void Export::onExport () gint export_count = 0; std::vector<SPItem*> itemlist=desktop->getSelection()->itemList(); - for(std::vector<SPItem*>::const_iterator i = itemlist.begin();i!=itemlist.end() && !interrupted ;i++){ + for(std::vector<SPItem*>::const_iterator i = itemlist.begin();i!=itemlist.end() && !interrupted ;++i){ SPItem *item = *i; prog_dlg->set_data("current", GINT_TO_POINTER(n)); @@ -1239,7 +1239,7 @@ void Export::onExport () DocumentUndo::setUndoSensitive(doc, false); reprlst = desktop->getSelection()->reprList(); - for(std::vector<Inkscape::XML::Node*>::const_iterator i=reprlst.begin(); reprlst.end() != i; i++) { + for(std::vector<Inkscape::XML::Node*>::const_iterator i=reprlst.begin(); reprlst.end() != i; ++i) { Inkscape::XML::Node * repr = *i; const gchar * temp_string; Glib::ustring dir = Glib::path_get_dirname(filename.c_str()); diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 22c8c76f2..08a58291d 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -1474,7 +1474,7 @@ void FilterEffectsDialog::FilterModifier::update_selection(Selection *sel) std::set<SPObject*> used; std::vector<SPItem*> itemlist=sel->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; ++i) { SPObject *obj = *i; SPStyle *style = obj->style; if (!style || !SP_IS_ITEM(obj)) { @@ -1555,7 +1555,7 @@ void FilterEffectsDialog::FilterModifier::on_selection_toggled(const Glib::ustri filter = 0; std::vector<SPItem*> itemlist=sel->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; ++i) { SPItem * item = *i; SPStyle *style = item->style; g_assert(style != NULL); @@ -1669,7 +1669,7 @@ void FilterEffectsDialog::FilterModifier::remove_filter() // Delete all references to this filter std::vector<SPItem*> x,y; std::vector<SPItem*> all = get_all_items(x, _desktop->currentRoot(), _desktop, false, false, true, y); - for(std::vector<SPItem*>::const_iterator i=all.begin(); all.end() != i; i++) { + for(std::vector<SPItem*>::const_iterator i=all.begin(); all.end() != i; ++i) { if (!SP_IS_ITEM(*i)) { continue; } diff --git a/src/ui/dialog/find.cpp b/src/ui/dialog/find.cpp index a8ac42a1b..0f368c5ac 100644 --- a/src/ui/dialog/find.cpp +++ b/src/ui/dialog/find.cpp @@ -561,7 +561,7 @@ std::vector<SPItem*> Find::filter_fields (std::vector<SPItem*> &l, bool exact, b std::vector<SPItem*> out; if (check_searchin_text.get_active()) { - for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); @@ -584,7 +584,7 @@ std::vector<SPItem*> Find::filter_fields (std::vector<SPItem*> &l, bool exact, b bool attrvalue = check_attributevalue.get_active(); if (ids) { - for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); if (item_id_match(item, text, exact, casematch)) { @@ -600,7 +600,7 @@ std::vector<SPItem*> Find::filter_fields (std::vector<SPItem*> &l, bool exact, b if (style) { - for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); @@ -617,7 +617,7 @@ std::vector<SPItem*> Find::filter_fields (std::vector<SPItem*> &l, bool exact, b if (attrname) { - for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); @@ -634,7 +634,7 @@ std::vector<SPItem*> Find::filter_fields (std::vector<SPItem*> &l, bool exact, b if (attrvalue) { - for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); @@ -651,7 +651,7 @@ std::vector<SPItem*> Find::filter_fields (std::vector<SPItem*> &l, bool exact, b if (font) { - for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; i++) { + for(std::vector<SPItem*>::const_reverse_iterator i=in.rbegin(); in.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); @@ -718,7 +718,7 @@ bool Find::item_type_match (SPItem *item) std::vector<SPItem*> Find::filter_types (std::vector<SPItem*> &l) { std::vector<SPItem*> n; - for(std::vector<SPItem*>::const_reverse_iterator i=l.rbegin(); l.rend() != i; i++) { + for(std::vector<SPItem*>::const_reverse_iterator i=l.rbegin(); l.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); @@ -762,7 +762,7 @@ std::vector<SPItem*> &Find::all_items (SPObject *r, std::vector<SPItem*> &l, boo std::vector<SPItem*> &Find::all_selection_items (Inkscape::Selection *s, std::vector<SPItem*> &l, SPObject *ancestor, bool hidden, bool locked) { std::vector<SPItem*> itemlist=s->itemList(); - for(std::vector<SPItem*>::const_reverse_iterator i=itemlist.rbegin(); itemlist.rend() != i; i++) { + for(std::vector<SPItem*>::const_reverse_iterator i=itemlist.rbegin(); itemlist.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast<SPItem *>(obj); g_assert(item != NULL); diff --git a/src/ui/dialog/font-substitution.cpp b/src/ui/dialog/font-substitution.cpp index 19506c6a3..f219f3db6 100644 --- a/src/ui/dialog/font-substitution.cpp +++ b/src/ui/dialog/font-substitution.cpp @@ -154,7 +154,7 @@ std::vector<SPItem*> FontSubstitution::getFontReplacedItems(SPDocument* doc, Gli std::map<SPItem *, Glib::ustring> mapFontStyles; allList = get_all_items(x, doc->getRoot(), desktop, false, false, true, y); - for(std::vector<SPItem*>::const_iterator i = allList.begin();i!=allList.end();i++){ + for(std::vector<SPItem*>::const_iterator i = allList.begin();i!=allList.end();++i){ SPItem *item = *i; SPStyle *style = item->style; Glib::ustring family = ""; diff --git a/src/ui/dialog/glyphs.cpp b/src/ui/dialog/glyphs.cpp index 7ca277ea2..56b001291 100644 --- a/src/ui/dialog/glyphs.cpp +++ b/src/ui/dialog/glyphs.cpp @@ -579,7 +579,7 @@ void GlyphsPanel::insertText() { SPItem *textItem = 0; std::vector<SPItem*> itemlist=targetDesktop->selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; ++i) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) { textItem = *i; break; @@ -689,7 +689,7 @@ void GlyphsPanel::calcCanInsert() { int items = 0; std::vector<SPItem*> itemlist=targetDesktop->selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; i++) { + for(std::vector<SPItem*>::const_iterator i=itemlist.begin(); itemlist.end() != i; ++i) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) { ++items; } diff --git a/src/ui/dialog/grid-arrange-tab.cpp b/src/ui/dialog/grid-arrange-tab.cpp index 086cbe45f..53c25c3d5 100644 --- a/src/ui/dialog/grid-arrange-tab.cpp +++ b/src/ui/dialog/grid-arrange-tab.cpp @@ -164,7 +164,7 @@ void GridArrangeTab::arrange() Inkscape::Selection *selection = desktop->getSelection(); const std::vector<SPItem*> items = selection ? selection->itemList() : std::vector<SPItem*>(); - for(std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end(); ++i){ SPItem *item = *i; Geom::OptRect b = item->documentVisualBounds(); if (!b) { @@ -202,7 +202,7 @@ void GridArrangeTab::arrange() cnt=0; const std::vector<SPItem*> sizes(sorted); - for (std::vector<SPItem*>::const_iterator i = sizes.begin();i!=sizes.end();i++) { + for (std::vector<SPItem*>::const_iterator i = sizes.begin();i!=sizes.end(); ++i) { SPItem *item = *i; Geom::OptRect b = item->documentVisualBounds(); if (b) { @@ -301,7 +301,7 @@ g_print("\n row = %f col = %f selection x= %f selection y = %f", total_row_h cnt=0; std::vector<SPItem*>::iterator it = sorted.begin(); - for (row_cnt=0; ((it != sorted.end()) && (row_cnt<NoOfRows)); row_cnt++) { + for (row_cnt=0; ((it != sorted.end()) && (row_cnt<NoOfRows)); ++row_cnt) { GSList *current_row = NULL; col_cnt = 0; diff --git a/src/ui/dialog/icon-preview.cpp b/src/ui/dialog/icon-preview.cpp index 77f120e1a..83656a1f2 100644 --- a/src/ui/dialog/icon-preview.cpp +++ b/src/ui/dialog/icon-preview.cpp @@ -363,7 +363,7 @@ void IconPreviewPanel::refreshPreview() //g_message("found a selection to play with"); std::vector<SPItem*> const items = sel->itemList(); - for(std::vector<SPItem*>::const_iterator i=items.begin();!target && i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i=items.begin();!target && i!=items.end();++i){ SPItem* item = *i; gchar const *id = item->getId(); if ( id ) { diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 14eaa65aa..fec49d484 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -601,7 +601,7 @@ void InkscapePreferences::initPageUI() _("Set the language for menus and number formats"), false); { - Glib::ustring sizeLabels[] = {_("Large"), _("Small"), _("Smaller")}; + Glib::ustring sizeLabels[] = {C_("Icon size", "Large"), C_("Icon size", "Small"), C_("Icon size", "Smaller")}; int sizeValues[] = {0, 1, 2}; _misc_small_tools.init( "/toolbox/tools/small", sizeLabels, sizeValues, G_N_ELEMENTS(sizeLabels), 0 ); @@ -686,7 +686,7 @@ void InkscapePreferences::initPageUI() _win_ontop_agressive.init ( _("Aggressive"), "/options/transientpolicy/value", 2, false, &_win_ontop_none); { - Glib::ustring defaultSizeLabels[] = {_("Small"), _("Large"), _("Maximized")}; + Glib::ustring defaultSizeLabels[] = {C_("Window size", "Small"), C_("Window size", "Large"), C_("Window size", "Maximized")}; int defaultSizeValues[] = {0, 1, 2}; _win_default_size.init( "/options/defaultwindowsize/value", defaultSizeLabels, defaultSizeValues, G_N_ELEMENTS(defaultSizeLabels), 1 ); diff --git a/src/ui/dialog/objects.cpp b/src/ui/dialog/objects.cpp index 835ecf35b..726df9a61 100644 --- a/src/ui/dialog/objects.cpp +++ b/src/ui/dialog/objects.cpp @@ -479,7 +479,7 @@ void ObjectsPanel::_objectsSelected( Selection *sel ) { _tree.get_selection()->unselect_all(); SPItem *item = NULL; std::vector<SPItem*> const items = sel->itemList(); - for(std::vector<SPItem*>::const_iterator i=items.begin(); i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i=items.begin(); i!=items.end(); ++i){ item = *i; if (setOpacity) { @@ -1614,11 +1614,11 @@ ObjectsPanel::ObjectsPanel() : _pending(0), _toggleEvent(0), _defer_target(), - _visibleHeader(_("V")), - _lockHeader(_("L")), - _typeHeader(_("T")), - _clipmaskHeader(_("CM")), - _highlightHeader(_("HL")), + _visibleHeader(C_("Visibility", "V")), + _lockHeader(C_("Lock", "L")), + _typeHeader(C_("Type", "T")), + _clipmaskHeader(C_("Clip and mask", "CM")), + _highlightHeader(C_("Highlight", "HL")), _nameHeader(_("Label")), _composite_vbox(false, 0), _opacity_vbox(false, 0), diff --git a/src/ui/dialog/pixelartdialog.cpp b/src/ui/dialog/pixelartdialog.cpp index 760391df6..f557ff0fc 100644 --- a/src/ui/dialog/pixelartdialog.cpp +++ b/src/ui/dialog/pixelartdialog.cpp @@ -373,7 +373,7 @@ void PixelArtDialogImpl::vectorize() } std::vector<SPItem*> const items = desktop->selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=items.begin(); i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i=items.begin(); i!=items.end();++i){ if ( !SP_IS_IMAGE(*i) ) continue; diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp index af1386e27..5ec1285c1 100644 --- a/src/ui/dialog/polar-arrange-tab.cpp +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -304,7 +304,7 @@ void PolarArrangeTab::arrange() bool arrangeOnFirstEllipse = arrangeOnEllipse && arrangeOnFirstCircleRadio.get_active(); int count = 0; - for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++) + for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();++i) { if(arrangeOnEllipse) { @@ -373,7 +373,7 @@ void PolarArrangeTab::arrange() Geom::Point realCenter = Geom::Point(cx, cy) * transformation; int i = 0; - for(std::vector<SPItem*>::const_iterator it=tmp.begin();it!=tmp.end();it++) + for(std::vector<SPItem*>::const_iterator it=tmp.begin();it!=tmp.end(); ++it) { SPItem *item = *it; diff --git a/src/ui/dialog/tags.cpp b/src/ui/dialog/tags.cpp index f36e3f18d..9b6f3219f 100644 --- a/src/ui/dialog/tags.cpp +++ b/src/ui/dialog/tags.cpp @@ -353,7 +353,7 @@ void TagsPanel::_objectsSelected( Selection *sel ) { _selectedConnection.block(); _tree.get_selection()->unselect_all(); std::vector<SPObject*> tmp=sel->list(); - for(std::vector<SPObject*>::const_iterator i=tmp.begin();i!=tmp.end();i++) + for(std::vector<SPObject*>::const_iterator i=tmp.begin();i!=tmp.end();++i) { SPObject *obj = *i; _store->foreach(sigc::bind<SPObject *>( sigc::mem_fun(*this, &TagsPanel::_checkForSelected), obj)); @@ -651,7 +651,7 @@ bool TagsPanel::_handleButtonEvent(GdkEventButton* event) if (SP_IS_TAG(obj)) { bool wasadded = false; std::vector<SPItem*> items=_desktop->selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){ SPObject *newobj = *i; bool addchild = true; for ( SPObject *child = obj->children; child != NULL; child = child->next) { diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index 7575cc854..05cf3a388 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -175,6 +175,19 @@ TextEdit::TextEdit() gtk_text_view_set_wrap_mode ((GtkTextView *) text_view, GTK_WRAP_WORD); #ifdef WITH_GTKSPELL +#ifdef WITH_GTKMM_3_0 +/* + TODO: Use computed xml:lang attribute of relevant element, if present, to specify the + language (either as 2nd arg of gtkspell_new_attach, or with explicit + gtkspell_set_language call in; see advanced.c example in gtkspell docs). + onReadSelection looks like a suitable place. +*/ + GtkSpellChecker * speller = gtk_spell_checker_new(); + + if (! gtk_spell_checker_attach(speller, GTK_TEXT_VIEW(text_view))) { + g_print("gtkspell error:\n"); + } +#else GError *error = NULL; /* @@ -188,6 +201,7 @@ TextEdit::TextEdit() g_error_free(error); } #endif +#endif gtk_widget_set_size_request (text_view, -1, 64); gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), TRUE); @@ -430,7 +444,7 @@ SPItem *TextEdit::getSelectedTextItem (void) return NULL; std::vector<SPItem*> tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList(); - for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++) + for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();++i) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) return *i; @@ -448,7 +462,7 @@ unsigned TextEdit::getSelectedTextCount (void) unsigned int items = 0; std::vector<SPItem*> tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList(); - for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++) + for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();++i) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) ++items; @@ -558,7 +572,7 @@ void TextEdit::onApply() SPCSSAttr *css = fillTextStyle (); sp_desktop_set_style(desktop, css, true); - for(std::vector<SPItem*>::const_iterator i=item_list.begin();i!=item_list.end();i++){ + for(std::vector<SPItem*>::const_iterator i=item_list.begin();i!=item_list.end();++i){ // apply style to the reprs of all text objects in the selection if (SP_IS_TEXT (*i)) { diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index 6049368f5..ae972bbbd 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -812,7 +812,7 @@ void Transformation::applyPageScale(Inkscape::Selection *selection) bool preserve = prefs->getBool("/options/preservetransform/value", false); if (prefs->getBool("/dialogs/transformation/applyseparately")) { std::vector<SPItem*> tmp=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++){ + for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();++i){ SPItem *item = *i; Geom::OptRect bbox_pref = item->desktopPreferredBounds(); Geom::OptRect bbox_geom = item->desktopGeometricBounds(); @@ -876,7 +876,7 @@ void Transformation::applyPageRotate(Inkscape::Selection *selection) if (prefs->getBool("/dialogs/transformation/applyseparately")) { std::vector<SPItem*> tmp=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++){ + for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();++i){ SPItem *item = *i; sp_item_rotate_rel(item, Geom::Rotate (angle*M_PI/180.0)); } @@ -896,7 +896,7 @@ void Transformation::applyPageSkew(Inkscape::Selection *selection) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/dialogs/transformation/applyseparately")) { std::vector<SPItem*> items=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();++i){ SPItem *item = *i; if (!_units_skew.isAbsolute()) { // percentage @@ -998,7 +998,7 @@ void Transformation::applyPageTransform(Inkscape::Selection *selection) if (_check_replace_matrix.get_active()) { std::vector<SPItem*> tmp=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();i++){ + for(std::vector<SPItem*>::const_iterator i=tmp.begin();i!=tmp.end();++i){ SPItem *item = *i; item->set_item_transform(displayed); item->updateRepr(); diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index 0a36877ff..b84d16686 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -1307,7 +1307,7 @@ void cc_selection_set_avoid(bool const set_avoid) int changes = 0; std::vector<SPItem*> l = selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=l.begin();i!=l.end();i++) { + for(std::vector<SPItem*>::const_iterator i=l.begin();i!=l.end(); ++i) { SPItem *item = *i; char const *value = (set_avoid) ? "true" : NULL; diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index e416fd7ef..83ecf7a0a 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -682,7 +682,7 @@ void EraserTool::set_to_accumulated() { if ( !toWorkOn.empty() ) { if ( eraserMode ) { - for (std::vector<SPItem*>::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); i++){ + for (std::vector<SPItem*>::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); ++i){ SPItem *item = *i; if ( eraserMode ) { @@ -701,7 +701,7 @@ void EraserTool::set_to_accumulated() { if ( !selection->isEmpty() ) { // If the item was not completely erased, track the new remainder. std::vector<SPItem*> nowSel(selection->itemList()); - for (std::vector<SPItem*>::const_iterator i2 = nowSel.begin();i2!=nowSel.end();i2++) { + for (std::vector<SPItem*>::const_iterator i2 = nowSel.begin();i2!=nowSel.end();++i2) { remainingItems.push_back(*i2); } } @@ -711,11 +711,11 @@ void EraserTool::set_to_accumulated() { } } } else { - for (std::vector<SPItem*> ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { + for (std::vector<SPItem*> ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();++i) { sp_object_ref( *i, 0 ); } - for (std::vector<SPItem*>::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();i++) { + for (std::vector<SPItem*>::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();++i) { SPItem *item = *i; item->deleteObject(true); sp_object_unref(item); diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index 603458983..bcb0b12b7 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -495,7 +495,7 @@ bool GradientTool::root_handler(GdkEvent* event) { sp_gradient_context_add_stop_near_point(this, SP_ITEM(selection->itemList().front()), this->mousepoint_doc, event->button.time); } else { std::vector<SPItem*> items=selection->itemList(); - for (std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++) { + for (std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();++i) { SPItem *item = *i; SPGradientType new_type = (SPGradientType) prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR); Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE; @@ -910,7 +910,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta sp_repr_css_set_property(css, "fill-opacity", "1.0"); std::vector<SPItem*> itemlist = selection->itemList(); - for (std::vector<SPItem*>::const_iterator i = itemlist.begin();i!=itemlist.end();i++) { + for (std::vector<SPItem*>::const_iterator i = itemlist.begin();i!=itemlist.end();++i) { //FIXME: see above sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp index 13e47f3a6..9bbc1ac20 100644 --- a/src/ui/tools/lpe-tool.cpp +++ b/src/ui/tools/lpe-tool.cpp @@ -397,7 +397,7 @@ lpetool_create_measuring_items(LpeTool *lc, Inkscape::Selection *selection) gchar *arc_length; double lengthval; std::vector<SPItem*> items=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){ if (SP_IS_PATH(*i)) { path = SP_PATH(*i); curve = path->getCurve(); diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 570f3e796..06f32ba5c 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -4,6 +4,7 @@ * Authors: * Felipe Correa da Silva Sanches <juca@members.fsf.org> * Jon A. Cruz <jon@joncruz.org> + * Jabiertxo Arraiza <jabier.arraiza@marker.es> * * Copyright (C) 2011 Authors * @@ -14,40 +15,57 @@ #include <gdk/gdkkeysyms.h> #include <boost/none_t.hpp> #include "util/units.h" -#include "macros.h" #include "display/curve.h" -#include "sp-shape.h" -#include "sp-text.h" -#include "sp-flowtext.h" -#include "text-editing.h" -#include "display/sp-ctrlline.h" #include "display/sodipodi-ctrl.h" +#include "display/sp-ctrlline.h" +#include "display/sp-canvas.h" #include "display/sp-canvas-item.h" #include "display/sp-canvas-util.h" -#include "desktop.h" -#include "document.h" -#include "pixmaps/cursor-measure.xpm" -#include "preferences.h" -#include "inkscape.h" - +#include "svg/svg.h" +#include "svg/svg-color.h" #include "ui/tools/measure-tool.h" #include "ui/tools/freehand-base.h" -#include "display/canvas-text.h" -#include "path-chemistry.h" -#include "2geom/line.h" +#include <2geom/line.h> #include <2geom/path-intersection.h> #include <2geom/pathvector.h> #include <2geom/crossing.h> #include <2geom/angle.h> -#include "snap.h" +#include <2geom/transforms.h> #include "sp-namedview.h" +#include "sp-shape.h" +#include "sp-text.h" +#include "sp-flowtext.h" +#include "sp-defs.h" +#include "sp-item.h" +#include "sp-root.h" +#include "macros.h" +#include "svg/stringstream.h" +#include "rubberband.h" +#include "path-chemistry.h" +#include "desktop.h" +#include "document.h" +#include "document-undo.h" +#include "viewbox.h" +#include "snap.h" +#include "text-editing.h" +#include "pixmaps/cursor-measure.xpm" +#include "preferences.h" +#include "inkscape.h" +#include "knot.h" #include "enums.h" -#include "ui/control-manager.h" #include "knot-enums.h" +#include "desktop-style.h" +#include "verbs.h" +#include <glibmm/i18n.h> using Inkscape::ControlManager; using Inkscape::CTLINE_SECONDARY; using Inkscape::Util::unit_table; +using Inkscape::DocumentUndo; + +#define MT_KNOT_COLOR_NORMAL 0xffffff00 +#define MT_KNOT_COLOR_MOUSEOVER 0xff000000 + namespace Inkscape { namespace UI { @@ -55,16 +73,14 @@ namespace Tools { std::vector<Inkscape::Display::TemporaryItem*> measure_tmp_items; -const std::string& MeasureTool::getPrefsPath() { - return MeasureTool::prefsPath; +const std::string& MeasureTool::getPrefsPath() +{ + return MeasureTool::prefsPath; } const std::string MeasureTool::prefsPath = "/tools/measure"; -namespace -{ - -gint const DIMENSION_OFFSET = 35; +namespace { /** * Simple class to use for removing label overlap. @@ -87,14 +103,16 @@ bool SortLabelPlacement(LabelPlacement const &first, LabelPlacement const &secon } } -void repositionOverlappingLabels(std::vector<LabelPlacement> &placements, SPDesktop *desktop, Geom::Point const &normal, double fontsize) +//precision is for give the number of decimal positions +//of the label to calculate label width +void repositionOverlappingLabels(std::vector<LabelPlacement> &placements, SPDesktop *desktop, Geom::Point const &normal, double fontsize, int precision) { std::sort(placements.begin(), placements.end(), SortLabelPlacement); double border = 3; Geom::Rect box; { - Geom::Point tmp(fontsize * 8 + (border * 2), fontsize + (border * 2)); + Geom::Point tmp(fontsize * (6 + precision) + (border * 2), fontsize + (border * 2)); tmp = desktop->w2d(tmp); box = Geom::Rect(-tmp[Geom::X] / 2, -tmp[Geom::Y] / 2, tmp[Geom::X] / 2, tmp[Geom::Y] / 2); } @@ -175,6 +193,76 @@ Geom::Point calcAngleDisplayAnchor(SPDesktop *desktop, double angle, double base } /** + * Create a measure iten in current document. + * + * @param pathv the path to create. + * @param markers, if the path resuts get markers. + * @param color of the stroke. + * @param measure_repr container element. + */ +void setMeasureItem(Geom::PathVector pathv, bool is_curve, bool markers, guint32 color, Inkscape::XML::Node *measure_repr) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if(!desktop) { + return; + } + SPDocument *doc = desktop->getDocument(); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + Inkscape::XML::Node *repr; + repr = xml_doc->createElement("svg:path"); + gchar *str = sp_svg_write_path(pathv); + SPCSSAttr *css = sp_repr_css_attr_new(); + Geom::Coord strokewidth = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse().expansionX(); + std::stringstream stroke_width; + stroke_width.imbue(std::locale::classic()); + if(measure_repr) { + stroke_width << strokewidth / desktop->current_zoom(); + } else { + stroke_width << strokewidth; + } + sp_repr_css_set_property (css, "stroke-width", stroke_width.str().c_str()); + sp_repr_css_set_property (css, "fill", "none"); + if(color) { + gchar color_line[64]; + sp_svg_write_color (color_line, sizeof(color_line), color); + sp_repr_css_set_property (css, "stroke", color_line); + } else { + sp_repr_css_set_property (css, "stroke", "#ff0000"); + } + char const * stroke_linecap = is_curve ? "butt" : "square"; + sp_repr_css_set_property (css, "stroke-linecap", stroke_linecap); + sp_repr_css_set_property (css, "stroke-linejoin", "miter"); + sp_repr_css_set_property (css, "stroke-miterlimit", "4"); + sp_repr_css_set_property (css, "stroke-dasharray", "none"); + if(measure_repr) { + sp_repr_css_set_property (css, "stroke-opacity", "0.5"); + } else { + sp_repr_css_set_property (css, "stroke-opacity", "1"); + } + if(markers) { + sp_repr_css_set_property (css, "marker-start", "url(#Arrow2Sstart)"); + sp_repr_css_set_property (css, "marker-end", "url(#Arrow2Send)"); + } + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + repr->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + g_assert( str != NULL ); + repr->setAttribute("d", str); + g_free(str); + if(measure_repr) { + measure_repr->addChild(repr, NULL); + Inkscape::GC::release(repr); + } else { + SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr)); + Inkscape::GC::release(repr); + item->updateRepr(); + desktop->getSelection()->clear(); + desktop->getSelection()->add(item); + } +} + +/** * Given an angle, the arc center and edge point, draw an arc segment centered around that edge point. * * @param desktop the desktop that is being used. @@ -182,8 +270,9 @@ Geom::Point calcAngleDisplayAnchor(SPDesktop *desktop, double angle, double base * @param end the point that ends at the edge of the arc segment. * @param anchor the anchor point for displaying the text label. * @param angle the angle of the arc segment to draw. + * @param measure_rpr the container of the curve if converted to items. */ -void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom::Point const &end, Geom::Point const &anchor, double angle) +void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom::Point const &end, Geom::Point const &anchor, double angle, Inkscape::XML::Node *measure_repr = NULL) { // Given that we have a point on the arc's edge and the angle of the arc, we need to get the two endpoints. @@ -191,7 +280,7 @@ void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom double sideLen = std::abs((end - center).length()); if (sideLen > 0.0) { double factor = std::min(1.0, textLen / sideLen); - + // arc start Geom::Point p1 = end * (Geom::Affine(Geom::Translate(-center)) * Geom::Affine(Geom::Scale(factor)) @@ -221,22 +310,186 @@ void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom SPCtrlCurve *curve = ControlManager::getManager().createControlCurve(desktop->getTempGroup(), p1, p2, p3, p4, CTLINE_SECONDARY); measure_tmp_items.push_back(desktop->add_temporary_canvasitem(SP_CANVAS_ITEM(curve), 0, true)); + if(measure_repr) { + Geom::PathVector pathv; + Geom::Path path; + path.start(desktop->doc2dt(p1)); + path.appendNew<Geom::CubicBezier>(desktop->doc2dt(p2),desktop->doc2dt(p3),desktop->doc2dt(p4)); + pathv.push_back(path); + pathv *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + if(!pathv.empty()) { + setMeasureItem(pathv, true, false, 0xff00007f, measure_repr); + } + } } } } // namespace - MeasureTool::MeasureTool() : ToolBase(cursor_measure_xpm, 4, 4) , grabbed(NULL) { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + start_p = readMeasurePoint(true); + end_p = readMeasurePoint(false); + dimension_offset = 35; + // create the knots + this->knot_start = new SPKnot(desktop, N_("Measure start")); + this->knot_start->setMode(SP_KNOT_MODE_XOR); + this->knot_start->setFill(MT_KNOT_COLOR_NORMAL, MT_KNOT_COLOR_MOUSEOVER, MT_KNOT_COLOR_MOUSEOVER); + this->knot_start->setStroke(0x0000007f, 0x0000007f, 0x0000007f); + this->knot_start->setShape(SP_KNOT_SHAPE_CIRCLE); + this->knot_start->updateCtrl(); + this->knot_end = new SPKnot(desktop, N_("Measure end")); + this->knot_end->setMode(SP_KNOT_MODE_XOR); + this->knot_end->setFill(MT_KNOT_COLOR_NORMAL, MT_KNOT_COLOR_MOUSEOVER, MT_KNOT_COLOR_MOUSEOVER); + this->knot_end->setStroke(0x0000007f, 0x0000007f, 0x0000007f); + this->knot_end->setShape(SP_KNOT_SHAPE_CIRCLE); + this->knot_end->updateCtrl(); + Geom::Rect display_area = desktop->get_display_area(); + if(display_area.interiorContains(start_p) && display_area.interiorContains(end_p) && end_p != Geom::Point()) { + this->knot_start->moveto(start_p); + this->knot_start->show(); + this->knot_end->moveto(end_p); + this->knot_end->show(); + showCanvasItems(); + } else { + start_p = Geom::Point(0,0); + end_p = Geom::Point(0,0); + writeMeasurePoint(start_p, true); + writeMeasurePoint(end_p, false); + } + + this->_knot_start_moved_connection = this->knot_start->moved_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotStartMovedHandler)); + this->_knot_start_ungrabbed_connection = this->knot_start->ungrabbed_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotUngrabbedHandler)); + this->_knot_end_moved_connection = this->knot_end->moved_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotEndMovedHandler)); + this->_knot_end_ungrabbed_connection = this->knot_end->ungrabbed_signal.connect(sigc::mem_fun(*this, &MeasureTool::knotUngrabbedHandler)); + } -MeasureTool::~MeasureTool() { +MeasureTool::~MeasureTool() +{ + this->_knot_start_moved_connection.disconnect(); + this->_knot_start_ungrabbed_connection.disconnect(); + this->_knot_end_moved_connection.disconnect(); + this->_knot_end_ungrabbed_connection.disconnect(); + + /* unref should call destroy */ + knot_unref(this->knot_start); + knot_unref(this->knot_end); + for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { + desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); + } + measure_tmp_items.clear(); } -void MeasureTool::finish() { +Geom::Point MeasureTool::readMeasurePoint(bool is_start) { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPNamedView *namedview = desktop->namedview; + if(!namedview) { + return Geom::Point(Geom::infinity(),Geom::infinity()); + } + char const * measure_point = is_start ? "inkscape:measure-start" : "inkscape:measure-end"; + char const * measure_point_data = namedview->getAttribute (measure_point); + if(!measure_point_data) { + measure_point_data = "0,0"; + namedview->setAttribute (measure_point, measure_point_data); + } + gchar ** strarray = g_strsplit(measure_point_data, ",", 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) { + Geom::Point point_data(newx, newy); + return point_data; + } + return Geom::Point(Geom::infinity(),Geom::infinity()); + +} + +void MeasureTool::writeMeasurePoint(Geom::Point point, bool is_start) { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPNamedView *namedview = desktop->namedview; + if(!namedview) { + return; + } + std::stringstream meassure_point_str; + meassure_point_str.imbue(std::locale::classic()); + meassure_point_str << point[Geom::X] << "," << point[Geom::Y]; + gchar const *measure_point = is_start ? "inkscape:measure-start" : "inkscape:measure-end"; + namedview->setAttribute (measure_point, meassure_point_str.str().c_str()); +} + +//This function is used to reverse the Measure, I do it in two steps because when move the knot the +//start_ or the end_p are overwrite so I need the original values. +void MeasureTool::reverseKnots() +{ + Geom::Point start = start_p; + Geom::Point end = end_p; + this->knot_start->moveto(end); + this->knot_start->show(); + this->knot_end->moveto(start); + this->knot_end->show(); + start_p = end; + end_p = start; + this->showCanvasItems(); +} + +void MeasureTool::knotStartMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state) +{ + Geom::Point point = this->knot_start->position(); + if (state & GDK_CONTROL_MASK) { + spdc_endpoint_snap_rotation(this, point, end_p, state); + } else if (!(state & GDK_SHIFT_MASK)) { + SnapManager &snap_manager = desktop->namedview->snap_manager; + snap_manager.setup(desktop); + Inkscape::SnapCandidatePoint scp(point, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(this->knot_end->position()); + Inkscape::SnappedPoint sp = snap_manager.freeSnap(scp); + point = sp.getPoint(); + snap_manager.unSetup(); + } + if(start_p != point) { + start_p = point; + this->knot_start->moveto(start_p); + } + showCanvasItems(); +} + +void MeasureTool::knotEndMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state) +{ + Geom::Point point = this->knot_end->position(); + if (state & GDK_CONTROL_MASK) { + spdc_endpoint_snap_rotation(this, point, start_p, state); + } else if (!(state & GDK_SHIFT_MASK)) { + SnapManager &snap_manager = desktop->namedview->snap_manager; + snap_manager.setup(desktop); + Inkscape::SnapCandidatePoint scp(point, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(this->knot_start->position()); + Inkscape::SnappedPoint sp = snap_manager.freeSnap(scp); + point = sp.getPoint(); + snap_manager.unSetup(); + } + if(end_p != point) { + end_p = point; + this->knot_end->moveto(end_p); + } + showCanvasItems(); +} + +void MeasureTool::knotUngrabbedHandler(SPKnot */*knot*/, unsigned int state) +{ + this->knot_start->moveto(start_p); + this->knot_end->moveto(end_p); + showCanvasItems(); +} + + + +void MeasureTool::finish() +{ this->enableGrDrag(false); if (this->grabbed) { @@ -247,498 +500,773 @@ void MeasureTool::finish() { ToolBase::finish(); } -//void MeasureTool::setup() { -// ToolBase* ec = this; -// -//// if (SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->setup) { -//// SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->setup(ec); -//// } -// ToolBase::setup(); -//} - -//gint MeasureTool::item_handler(SPItem* item, GdkEvent* event) { -// gint ret = FALSE; -// -//// if (SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->item_handler) { -//// ret = SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->item_handler(event_context, item, event); -//// } -// ret = ToolBase::item_handler(item, event); -// -// return ret; -//} - static void calculate_intersections(SPDesktop * /*desktop*/, SPItem* item, Geom::PathVector const &lineseg, SPCurve *curve, std::vector<double> &intersections) { - curve->transform(item->i2doc_affine()); // Find all intersections of the control-line with this shape Geom::CrossingSet cs = Geom::crossings(lineseg, curve->get_pathvector()); Geom::delete_duplicates(cs[0]); // Reconstruct and store the points of intersection + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool only_visible = prefs->getBool("/tools/measure/only_visible", false); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; for (Geom::Crossings::const_iterator m = cs[0].begin(); m != cs[0].end(); ++m) { -#if 0 -//TODO: consider only visible intersections - Geom::Point intersection = lineseg[0].pointAt((*m).ta); - double eps = 0.0001; - SPDocument* doc = desktop->getDocument(); - if (((*m).ta > eps && - item == doc->getItemAtPoint(desktop->dkey, lineseg[0].pointAt((*m).ta - eps), false, NULL)) || + if(only_visible) { + double eps = 0.0001; + if (((*m).ta > eps && + item == desktop->getItemAtPoint(desktop->d2w(desktop->dt2doc(lineseg[0].pointAt((*m).ta - eps))), true, NULL)) || ((*m).ta + eps < 1 && - item == doc->getItemAtPoint(desktop->dkey, lineseg[0].pointAt((*m).ta + eps), false, NULL)) ) { + item == desktop->getItemAtPoint(desktop->d2w(desktop->dt2doc(lineseg[0].pointAt((*m).ta + eps))), true, NULL))) { + intersections.push_back((*m).ta); + } + } else { intersections.push_back((*m).ta); } -#else - intersections.push_back((*m).ta); - -#endif } } -bool MeasureTool::root_handler(GdkEvent* event) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); - +bool MeasureTool::root_handler(GdkEvent* event) +{ gint ret = FALSE; switch (event->type) { - case GDK_BUTTON_PRESS: { - Geom::Point const button_w(event->button.x, event->button.y); - explicitBase = boost::none; - lastEnd = boost::none; - start_point = desktop->w2d(button_w); - - if (event->button.button == 1 && !this->space_panning) { - // save drag origin - xp = static_cast<gint>(event->button.x); - yp = static_cast<gint>(event->button.y); - within_tolerance = true; - - ret = TRUE; - } + case GDK_BUTTON_PRESS: { + this->knot_start->hide(); + this->knot_end->hide(); + Geom::Point const button_w(event->button.x, event->button.y); + explicitBase = boost::none; + last_end = boost::none; + start_p = desktop->w2d(button_w); + + if (event->button.button == 1 && !this->space_panning) { + // save drag origin + start_p = desktop->w2d(Geom::Point(event->button.x, event->button.y)); + within_tolerance = true; + + ret = TRUE; + } - SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop); - m.freeSnapReturnByRef(start_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); - m.unSetup(); + SnapManager &snap_manager = desktop->namedview->snap_manager; + snap_manager.setup(desktop); + snap_manager.freeSnapReturnByRef(start_p, Inkscape::SNAPSOURCE_OTHER_HANDLE); + snap_manager.unSetup(); - sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), - GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK, - NULL, event->button.time); - this->grabbed = SP_CANVAS_ITEM(desktop->acetate); - break; - } - case GDK_KEY_PRESS: { - if ((event->key.keyval == GDK_KEY_Shift_L) || (event->key.keyval == GDK_KEY_Shift_R)) { - if (lastEnd) { - explicitBase = lastEnd; - } - } - break; + sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), + GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK, + NULL, event->button.time); + this->grabbed = SP_CANVAS_ITEM(desktop->acetate); + break; + } + case GDK_KEY_PRESS: { + if ((event->key.keyval == GDK_KEY_Shift_L) || (event->key.keyval == GDK_KEY_Shift_R)) { + explicitBase = end_p; } - case GDK_MOTION_NOTIFY: { - if (!((event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning)) { - if (!(event->motion.state & GDK_SHIFT_MASK)) { - Geom::Point const motion_w(event->motion.x, event->motion.y); - Geom::Point const motion_dt(desktop->w2d(motion_w)); - - SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop); + break; + } + case GDK_MOTION_NOTIFY: { + if (!(event->motion.state & GDK_BUTTON1_MASK)) { + if(!(event->motion.state & GDK_SHIFT_MASK)) { + Geom::Point const motion_w(event->motion.x, event->motion.y); + Geom::Point const motion_dt(desktop->w2d(motion_w)); - Inkscape::SnapCandidatePoint scp(motion_dt, Inkscape::SNAPSOURCE_OTHER_HANDLE); - scp.addOrigin(start_point); + SnapManager &snap_manager = desktop->namedview->snap_manager; + snap_manager.setup(desktop); - m.preSnap(scp); - m.unSetup(); - } - } else { - ret = TRUE; + Inkscape::SnapCandidatePoint scp(motion_dt, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(start_p); - if ( within_tolerance - && ( abs( static_cast<gint>(event->motion.x) - xp ) < tolerance ) - && ( abs( static_cast<gint>(event->motion.y) - yp ) < tolerance ) ) { - break; // do not drag if we're within tolerance from origin - } - // Once the user has moved farther than tolerance from the original location - // (indicating they intend to move the object, not click), then always process the - // motion notify coordinates as given (no snapping back to origin) - within_tolerance = false; - - //clear previous temporary canvas items, we'll draw new ones - for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { - desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); + snap_manager.preSnap(scp); + snap_manager.unSetup(); + } + } else { + ret = TRUE; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); + Geom::Point const motion_w(event->motion.x, event->motion.y); + if ( within_tolerance) { + if ( Geom::LInfty( motion_w - start_p ) < tolerance) { + return FALSE; // Do not drag if we're within tolerance from origin. } - - measure_tmp_items.clear(); - + } + // Once the user has moved farther than tolerance from the original location + // (indicating they intend to move the object, not click), then always process the + // motion notify coordinates as given (no snapping back to origin) + within_tolerance = false; + if(event->motion.time == 0 || !last_end || Geom::LInfty( motion_w - *last_end ) > (tolerance/4.0)) { Geom::Point const motion_w(event->motion.x, event->motion.y); Geom::Point const motion_dt(desktop->w2d(motion_w)); - Geom::Point end_point = motion_dt; + end_p = motion_dt; if (event->motion.state & GDK_CONTROL_MASK) { - spdc_endpoint_snap_rotation(this, end_point, start_point, event->motion.state); - } else { - if (!(event->motion.state & GDK_SHIFT_MASK)) { - SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop); - Inkscape::SnapCandidatePoint scp(end_point, Inkscape::SNAPSOURCE_OTHER_HANDLE); - scp.addOrigin(start_point); - Inkscape::SnappedPoint sp = m.freeSnap(scp); - end_point = sp.getPoint(); - m.unSetup(); - } - } - - Geom::PathVector lineseg; - Geom::Path p; - p.start(desktop->dt2doc(start_point)); - p.appendNew<Geom::LineSegment>(desktop->dt2doc(end_point)); - lineseg.push_back(p); - - double deltax = end_point[Geom::X] - start_point[Geom::X]; - double deltay = end_point[Geom::Y] - start_point[Geom::Y]; - double angle = atan2(deltay, deltax); - double baseAngle = 0; - - if (explicitBase) { - double deltax2 = explicitBase.get()[Geom::X] - start_point[Geom::X]; - double deltay2 = explicitBase.get()[Geom::Y] - start_point[Geom::Y]; - - baseAngle = atan2(deltay2, deltax2); - angle -= baseAngle; - - if (angle < -M_PI) { - angle += 2 * M_PI; - } else if (angle > M_PI) { - angle -= 2 * M_PI; - } + spdc_endpoint_snap_rotation(this, end_p, start_p, event->motion.state); + } else if (!(event->motion.state & GDK_SHIFT_MASK)) { + SnapManager &snap_manager = desktop->namedview->snap_manager; + snap_manager.setup(desktop); + Inkscape::SnapCandidatePoint scp(end_p, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(start_p); + Inkscape::SnappedPoint sp = snap_manager.freeSnap(scp); + end_p = sp.getPoint(); + snap_manager.unSetup(); } + showCanvasItems(); + last_end = motion_w ; + } + gobble_motion_events(GDK_BUTTON1_MASK); + } + break; + } + case GDK_BUTTON_RELEASE: { + this->knot_start->moveto(start_p); + this->knot_start->show(); + if(last_end) { + end_p = desktop->w2d(*last_end); + if (event->button.state & GDK_CONTROL_MASK) { + spdc_endpoint_snap_rotation(this, end_p, start_p, event->motion.state); + } else if (!(event->button.state & GDK_SHIFT_MASK)) { + SnapManager &snap_manager = desktop->namedview->snap_manager; + snap_manager.setup(desktop); + Inkscape::SnapCandidatePoint scp(end_p, Inkscape::SNAPSOURCE_OTHER_HANDLE); + scp.addOrigin(start_p); + Inkscape::SnappedPoint sp = snap_manager.freeSnap(scp); + end_p = sp.getPoint(); + snap_manager.unSetup(); + } + } + this->knot_end->moveto(end_p); + this->knot_end->show(); + showCanvasItems(); -//TODO: calculate NPOINTS -//800 seems to be a good value for 800x600 resolution -#define NPOINTS 800 + if (this->grabbed) { + sp_canvas_item_ungrab(this->grabbed, event->button.time); + this->grabbed = NULL; + } + break; + } + default: + break; + } + if (!ret) { + ret = ToolBase::root_handler(event); + } - std::vector<Geom::Point> points; + return ret; +} - for (double i = 0; i < NPOINTS; i++) { - points.push_back(desktop->d2w(start_point + (i / NPOINTS) * (end_point - start_point))); - } +void MeasureTool::setMarkers() +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPDocument *doc = desktop->getDocument(); + SPObject *arrowStart = doc->getObjectById("Arrow2Sstart"); + SPObject *arrowEnd = doc->getObjectById("Arrow2Send"); + if (!arrowStart) { + setMarker(true); + } + if(!arrowEnd) { + setMarker(false); + } +} +void MeasureTool::setMarker(bool isStart) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPDocument *doc = desktop->getDocument(); + SPDefs *defs = doc->getDefs(); + Inkscape::XML::Node *rmarker; + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + rmarker = xml_doc->createElement("svg:marker"); + rmarker->setAttribute("id", isStart ? "Arrow2Sstart" : "Arrow2Send"); + rmarker->setAttribute("inkscape:isstock", "true"); + rmarker->setAttribute("inkscape:stockid", isStart ? "Arrow2Sstart" : "Arrow2Send"); + rmarker->setAttribute("orient", "auto"); + rmarker->setAttribute("refX", "0.0"); + rmarker->setAttribute("refY", "0.0"); + rmarker->setAttribute("style", "overflow:visible;"); + SPItem *marker = SP_ITEM(defs->appendChildRepr(rmarker)); + Inkscape::GC::release(rmarker); + marker->updateRepr(); + Inkscape::XML::Node *rpath; + rpath = xml_doc->createElement("svg:path"); + rpath->setAttribute("d", "M 8.72,4.03 L -2.21,0.02 L 8.72,-4.00 C 6.97,-1.63 6.98,1.62 8.72,4.03 z"); + rpath->setAttribute("id", isStart ? "Arrow2SstartPath" : "Arrow2SendPath"); + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property (css, "stroke", "none"); + sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_set_property (css, "fill-opacity", "1"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + rpath->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + rpath->setAttribute("transform", isStart ? "scale(0.3) translate(-2.3,0)" : "scale(0.3) rotate(180) translate(-2.3,0)"); + SPItem *path = SP_ITEM(marker->appendChildRepr(rpath)); + Inkscape::GC::release(rpath); + path->updateRepr(); +} - // TODO: Felipe, why don't you simply iterate over all items, and test whether their bounding boxes intersect - // with the measurement line, instead of interpolating over 800 points? E.g. bbox_of_measurement_line.intersects(*bbox_of_item). - // That's also how the object-snapper works, see _findCandidates() in object-snapper.cpp. - - // TODO switch to a different variable name. The single letter 'l' is easy to misread. - - //select elements crossed by line segment: - std::vector<SPItem*> items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, points); - std::vector<double> intersection_times; - for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++) { - SPItem *item = *i; - - if (SP_IS_SHAPE(item)) { - calculate_intersections(desktop, item, lineseg, SP_SHAPE(item)->getCurve(), intersection_times); - } else { - if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { - Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin(); - do { - Inkscape::Text::Layout::iterator iter_next = iter; - iter_next.nextGlyph(); // iter_next is one glyph ahead from iter - if (iter == iter_next) { - break; - } - - // get path from iter to iter_next: - SPCurve *curve = te_get_layout(item)->convertToCurves(iter, iter_next); - iter = iter_next; // shift to next glyph - if (!curve) { - continue; // error converting this glyph - } - if (curve->is_empty()) { // whitespace glyph? - curve->unref(); - continue; - } - - curve->transform(item->i2doc_affine()); - - calculate_intersections(desktop, item, lineseg, curve, intersection_times); - - if (iter == te_get_layout(item)->end()) { - break; - } - } while (true); - } - } - } +void MeasureTool::toGuides() +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if(!desktop || !start_p.isFinite() || !end_p.isFinite() || start_p == end_p) { + return; + } + SPDocument *doc = desktop->getDocument(); + Geom::Point start = desktop->doc2dt(start_p) * desktop->doc2dt(); + Geom::Point end = desktop->doc2dt(end_p) * desktop->doc2dt(); + Geom::Ray ray(start,end); + SPNamedView *namedview = desktop->namedview; + if(!namedview) { + return; + } + setGuide(start,ray.angle(), _("Measure")); + if(explicitBase) { + explicitBase = *explicitBase * SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + ray.setPoints(start, *explicitBase); + if(ray.angle() != 0) { + setGuide(start,ray.angle(), _("Base")); + } + } + setGuide(start,0,""); + setGuide(start,Geom::deg_to_rad(90),_("Start")); + setGuide(end,0,_("End")); + setGuide(end,Geom::deg_to_rad(90),""); + showCanvasItems(true); + doc->ensureUpToDate(); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Add guides from measure tool")); +} - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (!prefs->getBool("/tools/measure/ignore_1st_and_last", true)) { - intersection_times.push_back(0); - intersection_times.push_back(1); - } +void MeasureTool::toItem() +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if(!desktop || !start_p.isFinite() || !end_p.isFinite() || start_p == end_p) { + return; + } + SPDocument *doc = desktop->getDocument(); + Geom::Ray ray(start_p,end_p); + guint32 line_color_primary = 0x0000ff7f; + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::XML::Node *rgroup = xml_doc->createElement("svg:g"); + showCanvasItems(false, true, rgroup); + setLine(start_p,end_p, false, line_color_primary, rgroup); + SPItem *measure_item = SP_ITEM(desktop->currentLayer()->appendChildRepr(rgroup)); + Inkscape::GC::release(rgroup); + measure_item->updateRepr(); + doc->ensureUpToDate(); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Convert measure to items")); + reset(); +} - Glib::ustring unit_name = prefs->getString("/tools/measure/unit"); - if (!unit_name.compare("")) { - unit_name = "px"; - } +void MeasureTool::toMarkDimension() +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if(!desktop || !start_p.isFinite() || !end_p.isFinite() || start_p == end_p) { + return; + } + SPDocument *doc = desktop->getDocument(); + setMarkers(); + Geom::Ray ray(start_p,end_p); + Geom::Point start = start_p + Geom::Point::polar(ray.angle(), 5); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + dimension_offset = prefs->getDouble("/tools/measure/offset", 5.0); + start = start + Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), -dimension_offset); + Geom::Point end = end_p + Geom::Point::polar(ray.angle(), -5); + end = end+ Geom::Point::polar(ray.angle() + Geom::deg_to_rad(90), -dimension_offset); + guint32 color = 0x000000ff; + setLine(start, end, true, color); + Glib::ustring unit_name = prefs->getString("/tools/measure/unit"); + if (!unit_name.compare("")) { + unit_name = "px"; + } + double fontsize = prefs->getDouble("/tools/measure/fontsize", 10.0); + int precision = prefs->getInt("/tools/measure/precision", 2); + std::stringstream precision_str; + precision_str.imbue(std::locale::classic()); + precision_str << "%." << precision << "f %s"; + Geom::Point middle = Geom::middle_point(start, end); + double totallengthval = (end_p - start_p).length(); + totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); + double scale = prefs->getDouble("/tools/measure/scale", 100.0) / 100.0; + gchar *totallength_str = g_strdup_printf(precision_str.str().c_str(), totallengthval * scale, unit_name.c_str()); + setLabelText(totallength_str, middle, fontsize, Geom::deg_to_rad(180) - ray.angle(), color); + g_free(totallength_str); + doc->ensureUpToDate(); + DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MEASURE,_("Add global measure line")); +} - double fontsize = prefs->getInt("/tools/measure/fontsize"); +void MeasureTool::setGuide(Geom::Point origin,double angle, const char *label) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPDocument *doc = desktop->getDocument(); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + SPRoot const *root = doc->getRoot(); + Geom::Affine affine(Geom::identity()); + if(root) { + affine *= root->c2p.inverse(); + } + SPNamedView *namedview = desktop->namedview; + if(!namedview) { + return; + } + origin *= affine; + //measure angle + Inkscape::XML::Node *guide; + guide = xml_doc->createElement("sodipodi:guide"); + std::stringstream position; + position.imbue(std::locale::classic()); + position << origin[Geom::X] << "," << origin[Geom::Y]; + guide->setAttribute("position", position.str().c_str() ); + guide->setAttribute("inkscape:color", "rgb(167,0,255)"); + guide->setAttribute("inkscape:label", label); + Geom::Point unit_vector = Geom::rot90(origin.polar(angle)); + std::stringstream angle_str; + angle_str.imbue(std::locale::classic()); + angle_str << unit_vector[Geom::X] << "," << unit_vector[Geom::Y]; + guide->setAttribute("orientation", angle_str.str().c_str()); + namedview->appendChild(guide); + Inkscape::GC::release(guide); +} - // Normal will be used for lines and text - Geom::Point windowNormal = Geom::unit_vector(Geom::rot90(desktop->d2w(end_point - start_point))); - Geom::Point normal = desktop->w2d(windowNormal); +void MeasureTool::setLine(Geom::Point start_point,Geom::Point end_point, bool markers, guint32 color, Inkscape::XML::Node *measure_repr) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if(!desktop || !start_p.isFinite() || !end_p.isFinite()) { + return; + } + Geom::PathVector pathv; + Geom::Path path; + path.start(desktop->doc2dt(start_point)); + path.appendNew<Geom::LineSegment>(desktop->doc2dt(end_point)); + pathv.push_back(path); + pathv *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + if(!pathv.empty()) { + setMeasureItem(pathv, false, markers, color, measure_repr); + } +} - std::vector<Geom::Point> intersections; - std::sort(intersection_times.begin(), intersection_times.end()); - for (std::vector<double>::iterator iter_t = intersection_times.begin(); iter_t != intersection_times.end(); iter_t++) { - intersections.push_back(lineseg[0].pointAt(*iter_t)); - } +void MeasureTool::setPoint(Geom::Point origin, Inkscape::XML::Node *measure_repr) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if(!desktop || !origin.isFinite()) { + return; + } + char const * svgd; + svgd = "m 0.707,0.707 6.586,6.586 m 0,-6.586 -6.586,6.586"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + Geom::Scale scale = Geom::Scale(desktop->current_zoom()).inverse(); + pathv *= Geom::Translate(Geom::Point(-3.5,-3.5)); + pathv *= scale; + pathv *= Geom::Translate(Geom::Point() - (scale.vector() * 0.5)); + pathv *= Geom::Translate(desktop->doc2dt(origin)); + pathv *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + if (!pathv.empty()) { + guint32 line_color_secondary = 0xff0000ff; + setMeasureItem(pathv, false, false, line_color_secondary, measure_repr); + } +} - std::vector<LabelPlacement> placements; - for (size_t idx = 1; idx < intersections.size(); ++idx) { - LabelPlacement placement; - placement.lengthVal = (intersections[idx] - intersections[idx - 1]).length(); - placement.lengthVal = Inkscape::Util::Quantity::convert(placement.lengthVal, "px", unit_name); - placement.offset = DIMENSION_OFFSET; - placement.start = desktop->doc2dt( (intersections[idx - 1] + intersections[idx]) / 2 ); - placement.end = placement.start - (normal * placement.offset); +void MeasureTool::setLabelText(const char *value, Geom::Point pos, double fontsize, Geom::Coord angle, guint32 background, Inkscape::XML::Node *measure_repr, CanvasTextAnchorPositionEnum text_anchor) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + /* Create <text> */ + pos = desktop->doc2dt(pos); + Inkscape::XML::Node *rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + + + /* Set style */ + sp_desktop_apply_style_tool(desktop, rtext, "/tools/text", true); + if(measure_repr) { + sp_repr_set_svg_double(rtext, "x", 2); + sp_repr_set_svg_double(rtext, "y", 2); + } else { + sp_repr_set_svg_double(rtext, "x", 0); + sp_repr_set_svg_double(rtext, "y", 0); + } - placements.push_back(placement); - } + /* Create <tspan> */ + Inkscape::XML::Node *rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + SPCSSAttr *css = sp_repr_css_attr_new(); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + if(measure_repr) { + font_size << fontsize; + } else { + font_size << fontsize << "pt"; + } + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "font-style", "normal"); + sp_repr_css_set_property (css, "font-weight", "normal"); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + if(measure_repr) { + sp_repr_css_set_property (css, "fill", "#FFFFFF"); + } else { + sp_repr_css_set_property (css, "fill", "#000000"); + } + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + /* Create TEXT */ + Inkscape::XML::Node *rstring = xml_doc->createTextNode(value); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + SPItem *text_item = SP_ITEM(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + text_item->updateRepr(); + Geom::OptRect bbox = text_item->geometricBounds(); + if (!measure_repr && bbox) { + Geom::Point center = bbox->midpoint(); + text_item->transform *= Geom::Translate(center).inverse(); + pos += Geom::Point::polar(angle+ Geom::deg_to_rad(90), -bbox->height()); + } + if(measure_repr) { + /* Create <group> */ + Inkscape::XML::Node *rgroup = xml_doc->createElement("svg:g"); + /* Create <rect> */ + Inkscape::XML::Node *rrect = xml_doc->createElement("svg:rect"); + SPCSSAttr *css = sp_repr_css_attr_new (); + gchar color_line[64]; + sp_svg_write_color (color_line, sizeof(color_line), background); + sp_repr_css_set_property (css, "fill", color_line); + sp_repr_css_set_property (css, "fill-opacity", "0.5"); + sp_repr_css_set_property (css, "stroke-width", "0"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + rrect->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + sp_repr_set_svg_double(rgroup, "x", 0); + sp_repr_set_svg_double(rgroup, "y", 0); + sp_repr_set_svg_double(rrect, "x", -bbox->width()/2.0); + sp_repr_set_svg_double(rrect, "y", -bbox->height()); + sp_repr_set_svg_double(rrect, "width", bbox->width() + 6); + sp_repr_set_svg_double(rrect, "height", bbox->height() + 6); + Inkscape::XML::Node *rtextitem = text_item->getRepr(); + text_item->deleteObject(); + rgroup->addChild(rtextitem, NULL); + Inkscape::GC::release(rtextitem); + rgroup->addChild(rrect, NULL); + Inkscape::GC::release(rrect); + SPItem *text_item_box = SP_ITEM(desktop->currentLayer()->appendChildRepr(rgroup)); + Geom::Scale scale = Geom::Scale(desktop->current_zoom()).inverse(); + if(bbox && text_anchor == TEXT_ANCHOR_CENTER) { + text_item_box->transform *= Geom::Translate(bbox->midpoint() - Geom::Point(1.0,1.0)).inverse(); + } + text_item_box->transform *= scale; + text_item_box->transform *= Geom::Translate(Geom::Point() - (scale.vector() * 0.5)); + text_item_box->transform *= Geom::Translate(pos); + text_item_box->transform *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + text_item_box->updateRepr(); + text_item_box->doWriteTransform(text_item_box->getRepr(), text_item_box->transform, NULL, true); + Inkscape::XML::Node *rlabel = text_item_box->getRepr(); + text_item_box->deleteObject(); + measure_repr->addChild(rlabel, NULL); + Inkscape::GC::release(rlabel); + } else { + text_item->transform *= Geom::Rotate(angle); + text_item->transform *= Geom::Translate(pos); + text_item->transform *= SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); + text_item->doWriteTransform(text_item->getRepr(), text_item->transform, NULL, true); + } +} - // Adjust positions - repositionOverlappingLabels(placements, desktop, windowNormal, fontsize); - - for (std::vector<LabelPlacement>::iterator it = placements.begin(); it != placements.end(); ++it) - { - LabelPlacement &place = *it; - - // TODO cleanup memory, Glib::ustring, etc.: - gchar *measure_str = g_strdup_printf("%.2f %s", place.lengthVal, unit_name.c_str()); - SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), - desktop, - place.end, - measure_str); - sp_canvastext_set_fontsize(canvas_tooltip, fontsize); - canvas_tooltip->rgba = 0xffffffff; - canvas_tooltip->rgba_background = 0x0000007f; - canvas_tooltip->outline = false; - canvas_tooltip->background = true; - canvas_tooltip->anchor_position = TEXT_ANCHOR_CENTER; - - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); - g_free(measure_str); - } +void MeasureTool::reset() +{ + this->knot_start->hide(); + this->knot_end->hide(); + for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { + desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); + } + measure_tmp_items.clear(); +} - Geom::Point angleDisplayPt = calcAngleDisplayAnchor(desktop, angle, baseAngle, - start_point, end_point, - fontsize); - - { - // TODO cleanup memory, Glib::ustring, etc.: - gchar *angle_str = g_strdup_printf("%.2f °", angle * 180/M_PI); - - SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), - desktop, - angleDisplayPt, - angle_str); - sp_canvastext_set_fontsize(canvas_tooltip, fontsize); - canvas_tooltip->rgba = 0xffffffff; - canvas_tooltip->rgba_background = 0x337f337f; - canvas_tooltip->outline = false; - canvas_tooltip->background = true; - canvas_tooltip->anchor_position = TEXT_ANCHOR_CENTER; - - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); - g_free(angle_str); - } +void MeasureTool::setMeasureCanvasText(bool is_angle, double precision, double amount, double fontsize, Glib::ustring unit_name, Geom::Point position, guint32 background, CanvasTextAnchorPositionEnum text_anchor, bool to_item, Inkscape::XML::Node *measure_repr) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + std::stringstream precision_str; + precision_str.imbue(std::locale::classic()); + if(is_angle){ + precision_str << "%." << precision << "f °"; + } else { + precision_str << "%." << precision << "f %s"; + } + gchar *measure_str = g_strdup_printf(precision_str.str().c_str(), amount, unit_name.c_str()); + SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), + desktop, + position, + measure_str); + sp_canvastext_set_fontsize(canvas_tooltip, fontsize); + canvas_tooltip->rgba = 0xffffffff; + canvas_tooltip->rgba_background = background; + canvas_tooltip->outline = false; + canvas_tooltip->background = true; + canvas_tooltip->anchor_position = text_anchor; + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); + if(to_item) { + setLabelText(measure_str, position, fontsize, 0, background, measure_repr); + } + g_free(measure_str); +} - { - double totallengthval = (end_point - start_point).length(); - totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); - - // TODO cleanup memory, Glib::ustring, etc.: - gchar *totallength_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); - SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), - desktop, - end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), - totallength_str); - sp_canvastext_set_fontsize(canvas_tooltip, fontsize); - canvas_tooltip->rgba = 0xffffffff; - canvas_tooltip->rgba_background = 0x3333337f; - canvas_tooltip->outline = false; - canvas_tooltip->background = true; - canvas_tooltip->anchor_position = TEXT_ANCHOR_LEFT; - - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); - g_free(totallength_str); - } +void MeasureTool::setMeasureCanvasItem(Geom::Point position, bool to_item, Inkscape::XML::Node *measure_repr){ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPCanvasItem * canvasitem = sp_canvas_item_new(desktop->getTempGroup(), + SP_TYPE_CTRL, + "anchor", SP_ANCHOR_CENTER, + "size", 8.0, + "stroked", TRUE, + "stroke_color", 0xff0000ff, + "mode", SP_KNOT_MODE_XOR, + "shape", SP_KNOT_SHAPE_CROSS, + NULL ); + + SP_CTRL(canvasitem)->moveto(position); + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvasitem, 0)); + if(to_item) { + setPoint(position, measure_repr); + } +} - if (intersections.size() > 2) { - double totallengthval = (intersections[intersections.size()-1] - intersections[0]).length(); - totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); - - // TODO cleanup memory, Glib::ustring, etc.: - gchar *total_str = g_strdup_printf("%.2f %s", totallengthval, unit_name.c_str()); - SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), - desktop, - desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * 60, - total_str); - sp_canvastext_set_fontsize(canvas_tooltip, fontsize); - canvas_tooltip->rgba = 0xffffffff; - canvas_tooltip->rgba_background = 0x33337f7f; - canvas_tooltip->outline = false; - canvas_tooltip->background = true; - canvas_tooltip->anchor_position = TEXT_ANCHOR_CENTER; - - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvas_tooltip, 0)); - g_free(total_str); - } +void MeasureTool::setMeasureCanvasControlLine(Geom::Point start, Geom::Point end, bool to_item, Inkscape::CtrlLineType ctrl_line_type, Inkscape::XML::Node *measure_repr){ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPCtrlLine *control_line = ControlManager::getManager().createControlLine(desktop->getTempGroup(), + start, + end, + ctrl_line_type); + measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); + gint32 color = ctrl_line_type == CTLINE_PRIMARY ? 0x0000ff7f : 0xff00007f; + if(to_item) { + setLine(start, + end, + false, + color, + measure_repr); + } +} - // Now that text has been added, we can add lines and controls so that they go underneath - - for (size_t idx = 0; idx < intersections.size(); ++idx) { - // Display the intersection indicator (i.e. the cross) - SPCanvasItem * canvasitem = sp_canvas_item_new(desktop->getTempGroup(), - SP_TYPE_CTRL, - "anchor", SP_ANCHOR_CENTER, - "size", 8.0, - "stroked", TRUE, - "stroke_color", 0xff0000ff, - "mode", SP_KNOT_MODE_XOR, - "shape", SP_KNOT_SHAPE_CROSS, - NULL ); - - SP_CTRL(canvasitem)->moveto(desktop->doc2dt(intersections[idx])); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvasitem, 0)); - } +void MeasureTool::showCanvasItems(bool to_guides, bool to_item, Inkscape::XML::Node *measure_repr) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if(!desktop || !start_p.isFinite() || !end_p.isFinite() || start_p == end_p) { + return; + } + writeMeasurePoint(start_p, true); + writeMeasurePoint(end_p, false); + //clear previous temporary canvas items, we'll draw new ones + for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { + desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); + } + measure_tmp_items.clear(); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + bool show_in_between = prefs->getBool("/tools/measure/show_in_between", true); + bool all_layers = prefs->getBool("/tools/measure/all_layers", true); + dimension_offset = 70; + Geom::PathVector lineseg; + Geom::Path p; + p.start(desktop->dt2doc(start_p)); + p.appendNew<Geom::LineSegment>(desktop->dt2doc(end_p)); + lineseg.push_back(p); + + double angle = atan2(end_p - start_p); + double baseAngle = 0; + + if (explicitBase) { + baseAngle = atan2(explicitBase.get() - start_p); + angle -= baseAngle; + } - // Since adding goes to the bottom, do all lines last. - - // draw main control line - { - SPCtrlLine *control_line = ControlManager::getManager().createControlLine(desktop->getTempGroup(), - start_point, - end_point); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - - if ((end_point[Geom::X] != start_point[Geom::X]) && (end_point[Geom::Y] != start_point[Geom::Y])) { - double length = std::abs((end_point - start_point).length()); - Geom::Point anchorEnd = start_point; - anchorEnd[Geom::X] += length; - if (explicitBase) { - anchorEnd *= (Geom::Affine(Geom::Translate(-start_point)) - * Geom::Affine(Geom::Rotate(baseAngle)) - * Geom::Affine(Geom::Translate(start_point))); - } - - SPCtrlLine *control_line = ControlManager::getManager().createControlLine(desktop->getTempGroup(), - start_point, - anchorEnd, - CTLINE_SECONDARY); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - - createAngleDisplayCurve(desktop, start_point, end_point, angleDisplayPt, angle); + std::vector<SPItem*> items; + Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); + r->setMode(RUBBERBAND_MODE_TOUCHPATH); + if(!show_in_between) { + r->start(desktop,start_p); + r->move(end_p); + items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers, 2); + r->stop(); + r->setMode(RUBBERBAND_MODE_TOUCHPATH); + r->start(desktop,end_p); + r->move(start_p); + std::vector<SPItem*> items_reverse = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers, 2); + r->stop(); + if(items_reverse.size() == 2 && items_reverse[1] != items[0] && items_reverse[1] != items[1]) { + items.push_back(items_reverse[1]); + } + if(items_reverse.size() >= 1 && items_reverse[0] != items[1]) { + items.push_back(items_reverse[0]); + } + } else { + r->start(desktop,start_p); + r->move(end_p); + items = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints(), all_layers); + r->stop(); + } + std::vector<double> intersection_times; + for (std::vector<SPItem*>::const_iterator i=items.begin(); i!=items.end(); i++) { + SPItem *item = *i; + if (SP_IS_SHAPE(item)) { + calculate_intersections(desktop, item, lineseg, SP_SHAPE(item)->getCurve(), intersection_times); + } else { + if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { + Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin(); + do { + Inkscape::Text::Layout::iterator iter_next = iter; + iter_next.nextGlyph(); // iter_next is one glyph ahead from iter + if (iter == iter_next) { + break; } - } - - if (intersections.size() > 2) { - ControlManager &mgr = ControlManager::getManager(); - SPCtrlLine *control_line = 0; - control_line = mgr.createControlLine(desktop->getTempGroup(), - desktop->doc2dt(intersections[0]) + normal * 60, - desktop->doc2dt(intersections[intersections.size() - 1]) + normal * 60); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - - control_line = mgr.createControlLine(desktop->getTempGroup(), - desktop->doc2dt(intersections[0]), - desktop->doc2dt(intersections[0]) + normal * 65); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - - control_line = mgr.createControlLine(desktop->getTempGroup(), - desktop->doc2dt(intersections[intersections.size() - 1]), - desktop->doc2dt(intersections[intersections.size() - 1]) + normal * 65); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - } - // call-out lines - for (std::vector<LabelPlacement>::iterator it = placements.begin(); it != placements.end(); ++it) - { - LabelPlacement &place = *it; - - ControlManager &mgr = ControlManager::getManager(); - SPCtrlLine *control_line = mgr.createControlLine(desktop->getTempGroup(), - place.start, - place.end, - CTLINE_SECONDARY); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); - } + // get path from iter to iter_next: + SPCurve *curve = te_get_layout(item)->convertToCurves(iter, iter_next); + iter = iter_next; // shift to next glyph + if (!curve) { + continue; // error converting this glyph + } + if (curve->is_empty()) { // whitespace glyph? + curve->unref(); + continue; + } - { - for (size_t idx = 1; idx < intersections.size(); ++idx) { - Geom::Point measure_text_pos = (intersections[idx - 1] + intersections[idx]) / 2; + curve->transform(item->i2doc_affine()); - ControlManager &mgr = ControlManager::getManager(); - SPCtrlLine *control_line = mgr.createControlLine(desktop->getTempGroup(), - desktop->doc2dt(measure_text_pos), - desktop->doc2dt(measure_text_pos) - (normal * DIMENSION_OFFSET), - CTLINE_SECONDARY); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(control_line, 0)); + calculate_intersections(desktop, item, lineseg, curve, intersection_times); + if (iter == te_get_layout(item)->end()) { + break; } - } + } while (true); + } + } + } + Glib::ustring unit_name = prefs->getString("/tools/measure/unit"); + if (!unit_name.compare("")) { + unit_name = "px"; + } + double scale = prefs->getDouble("/tools/measure/scale", 100.0) / 100.0; + double fontsize = prefs->getDouble("/tools/measure/fontsize", 10.0); + // Normal will be used for lines and text + Geom::Point windowNormal = Geom::unit_vector(Geom::rot90(desktop->d2w(end_p - start_p))); + Geom::Point normal = desktop->w2d(windowNormal); + + std::vector<Geom::Point> intersections; + std::sort(intersection_times.begin(), intersection_times.end()); + for (std::vector<double>::iterator iter_t = intersection_times.begin(); iter_t != intersection_times.end(); iter_t++) { + if(show_in_between) { + intersections.push_back(lineseg[0].pointAt(*iter_t)); + } + } + if(!show_in_between && intersection_times.size() > 1) { + intersections.push_back(lineseg[0].pointAt(intersection_times[0])); + intersections.push_back(lineseg[0].pointAt(intersection_times[intersection_times.size()-1])); + } + if (!prefs->getBool("/tools/measure/ignore_1st_and_last", true)) { + intersections.insert(intersections.begin(),lineseg[0].pointAt(0)); + intersections.push_back(lineseg[0].pointAt(1)); + } + std::vector<LabelPlacement> placements; + for (size_t idx = 1; idx < intersections.size(); ++idx) { + LabelPlacement placement; + placement.lengthVal = (intersections[idx] - intersections[idx - 1]).length(); + placement.lengthVal = Inkscape::Util::Quantity::convert(placement.lengthVal, "px", unit_name); + placement.offset = dimension_offset / 2; + placement.start = desktop->doc2dt( (intersections[idx - 1] + intersections[idx]) / 2 ); + placement.end = placement.start - (normal * placement.offset); + + placements.push_back(placement); + } + int precision = prefs->getInt("/tools/measure/precision", 2); + // Adjust positions + repositionOverlappingLabels(placements, desktop, windowNormal, fontsize, precision); + for (std::vector<LabelPlacement>::iterator it = placements.begin(); it != placements.end(); ++it) { + LabelPlacement &place = *it; + setMeasureCanvasText(false, precision, place.lengthVal * scale, fontsize, unit_name, place.end, 0x0000007f, TEXT_ANCHOR_CENTER, to_item, measure_repr); + } + Geom::Point angleDisplayPt = calcAngleDisplayAnchor(desktop, angle, baseAngle, + start_p, end_p, + fontsize); + { + setMeasureCanvasText(true, precision, Geom::rad_to_deg(angle), fontsize, unit_name, angleDisplayPt, 0x337f337f, TEXT_ANCHOR_CENTER, to_item, measure_repr); + } - // Initial point - { - SPCanvasItem * canvasitem = sp_canvas_item_new(desktop->getTempGroup(), - SP_TYPE_CTRL, - "anchor", SP_ANCHOR_CENTER, - "size", 8.0, - "stroked", TRUE, - "stroke_color", 0xff0000ff, - "mode", SP_KNOT_MODE_XOR, - "shape", SP_KNOT_SHAPE_CROSS, - NULL ); - - SP_CTRL(canvasitem)->moveto(start_point); - measure_tmp_items.push_back(desktop->add_temporary_canvasitem(canvasitem, 0)); - } + { + double totallengthval = (end_p - start_p).length(); + totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); + Geom::Point origin = end_p + desktop->w2d(Geom::Point(3*fontsize, -fontsize)); + setMeasureCanvasText(false, precision, totallengthval * scale, fontsize, unit_name, origin, 0x3333337f, TEXT_ANCHOR_LEFT, to_item, measure_repr); + } - lastEnd = end_point; // track in case we get a anchoring key-press later + if (intersections.size() > 2) { + double totallengthval = (intersections[intersections.size()-1] - intersections[0]).length(); + totallengthval = Inkscape::Util::Quantity::convert(totallengthval, "px", unit_name); + Geom::Point origin = desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal * dimension_offset; + setMeasureCanvasText(false, precision, totallengthval * scale, fontsize, unit_name, origin, 0x33337f7f, TEXT_ANCHOR_CENTER, to_item, measure_repr); + } + + // Initial point + { + setMeasureCanvasItem(start_p, false, measure_repr); + } - gobble_motion_events(GDK_BUTTON1_MASK); + // Now that text has been added, we can add lines and controls so that they go underneath + for (size_t idx = 0; idx < intersections.size(); ++idx) { + setMeasureCanvasItem(desktop->doc2dt(intersections[idx]), to_item, measure_repr); + if(to_guides) { + gchar *cross_number; + if (!prefs->getBool("/tools/measure/ignore_1st_and_last", true)) { + cross_number= g_strdup_printf(_("Crossing %d"), idx); + } else { + cross_number= g_strdup_printf(_("Crossing %d"), idx + 1); } - break; - } - case GDK_BUTTON_RELEASE: { - sp_event_context_discard_delayed_snap_event(this); - explicitBase = boost::none; - lastEnd = boost::none; - - //clear all temporary canvas items related to the measurement tool. - for (size_t idx = 0; idx < measure_tmp_items.size(); ++idx) { - desktop->remove_temporary_canvasitem(measure_tmp_items[idx]); + if (!prefs->getBool("/tools/measure/ignore_1st_and_last", true) && idx == 0) { + setGuide(desktop->doc2dt(intersections[idx]), angle + Geom::deg_to_rad(90), ""); + } else { + setGuide(desktop->doc2dt(intersections[idx]), angle + Geom::deg_to_rad(90), cross_number); } + g_free(cross_number); + } + } + // Since adding goes to the bottom, do all lines last. - measure_tmp_items.clear(); + // draw main control line + { + setMeasureCanvasControlLine(start_p, end_p, false, CTLINE_PRIMARY, measure_repr); + double length = std::abs((end_p - start_p).length()); + Geom::Point anchorEnd = start_p; + anchorEnd[Geom::X] += length; + if (explicitBase) { + anchorEnd *= (Geom::Affine(Geom::Translate(-start_p)) + * Geom::Affine(Geom::Rotate(baseAngle)) + * Geom::Affine(Geom::Translate(start_p))); + } + setMeasureCanvasControlLine(start_p, anchorEnd, to_item, CTLINE_SECONDARY, measure_repr); + createAngleDisplayCurve(desktop, start_p, end_p, angleDisplayPt, angle, measure_repr); + } - if (this->grabbed) { - sp_canvas_item_ungrab(this->grabbed, event->button.time); - this->grabbed = NULL; - } + if (intersections.size() > 2) { + setMeasureCanvasControlLine(desktop->doc2dt(intersections[0]) + normal * dimension_offset, desktop->doc2dt(intersections[intersections.size() - 1]) + normal * dimension_offset, to_item, CTLINE_PRIMARY , measure_repr); + + setMeasureCanvasControlLine(desktop->doc2dt(intersections[0]), desktop->doc2dt(intersections[0]) + normal * dimension_offset, to_item, CTLINE_PRIMARY , measure_repr); - xp = 0; - yp = 0; - break; - } - default: - break; + setMeasureCanvasControlLine(desktop->doc2dt(intersections[intersections.size() - 1]), desktop->doc2dt(intersections[intersections.size() - 1]) + normal * dimension_offset, to_item, CTLINE_PRIMARY , measure_repr); } - if (!ret) { - ret = ToolBase::root_handler(event); + // call-out lines + for (std::vector<LabelPlacement>::iterator it = placements.begin(); it != placements.end(); ++it) { + LabelPlacement &place = *it; + setMeasureCanvasControlLine(place.start, place.end, to_item, CTLINE_SECONDARY, measure_repr); } - return ret; + { + for (size_t idx = 1; idx < intersections.size(); ++idx) { + Geom::Point measure_text_pos = (intersections[idx - 1] + intersections[idx]) / 2; + setMeasureCanvasControlLine(desktop->doc2dt(measure_text_pos), desktop->doc2dt(measure_text_pos) - (normal * dimension_offset / 2), to_item, CTLINE_SECONDARY, measure_repr); + } + } } } diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h index 9701ba6ea..3bdc9b9c4 100644 --- a/src/ui/tools/measure-tool.h +++ b/src/ui/tools/measure-tool.h @@ -6,41 +6,72 @@ * * Authors: * Felipe Correa da Silva Sanches <juca@members.fsf.org> - * + * Jabiertxo Arraiza <jabier.arraiza@marker.es> * Copyright (C) 2011 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include <stddef.h> +#include <sigc++/sigc++.h> #include "ui/tools/tool-base.h" #include <2geom/point.h> +#include "display/canvas-text.h" +#include "ui/control-manager.h" #include <boost/optional.hpp> #define SP_MEASURE_CONTEXT(obj) (dynamic_cast<Inkscape::UI::Tools::MeasureTool*>((Inkscape::UI::Tools::ToolBase*)obj)) #define SP_IS_MEASURE_CONTEXT(obj) (dynamic_cast<const Inkscape::UI::Tools::MeasureTool*>((const Inkscape::UI::Tools::ToolBase*)obj) != NULL) +class SPKnot; + namespace Inkscape { namespace UI { namespace Tools { class MeasureTool : public ToolBase { public: - MeasureTool(); - virtual ~MeasureTool(); - - static const std::string prefsPath; + MeasureTool(); + virtual ~MeasureTool(); - virtual void finish(); - virtual bool root_handler(GdkEvent* event); + static const std::string prefsPath; - virtual const std::string& getPrefsPath(); + virtual void finish(); + virtual bool root_handler(GdkEvent* event); + virtual void showCanvasItems(bool to_guides = false, bool to_item = false, Inkscape::XML::Node *measure_repr = NULL); + virtual void reverseKnots(); + virtual void toGuides(); + virtual void toMarkDimension(); + virtual void toItem(); + virtual void reset(); + virtual void setMarkers(); + virtual void setMarker(bool isStart); + virtual const std::string& getPrefsPath(); + Geom::Point readMeasurePoint(bool is_start); + void writeMeasurePoint(Geom::Point point, bool is_start); + void setGuide(Geom::Point origin, double angle, const char *label); + void setPoint(Geom::Point origin, Inkscape::XML::Node *measure_repr); + void setLine(Geom::Point start_point,Geom::Point end_point, bool markers, guint32 color, Inkscape::XML::Node *measure_repr = NULL); + void setMeasureCanvasText(bool is_angle, double precision, double amount, double fontsize, Glib::ustring unit_name, Geom::Point position, guint32 background, CanvasTextAnchorPositionEnum text_anchor, bool to_item, Inkscape::XML::Node *measure_repr); + void setMeasureCanvasItem(Geom::Point position, bool to_item, Inkscape::XML::Node *measure_repr); + void setMeasureCanvasControlLine(Geom::Point start, Geom::Point end, bool to_item, Inkscape::CtrlLineType ctrl_line_type, Inkscape::XML::Node *measure_repr); + void setLabelText(const char *value, Geom::Point pos, double fontsize, Geom::Coord angle, guint32 background , Inkscape::XML::Node *measure_repr = NULL, CanvasTextAnchorPositionEnum text_anchor = TEXT_ANCHOR_CENTER ); + void knotStartMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state); + void knotEndMovedHandler(SPKnot */*knot*/, Geom::Point const &ppointer, guint state); + void knotUngrabbedHandler(SPKnot */*knot*/, unsigned int /*state*/); private: - SPCanvasItem* grabbed; - - Geom::Point start_point; + SPCanvasItem* grabbed; boost::optional<Geom::Point> explicitBase; - boost::optional<Geom::Point> lastEnd; + boost::optional<Geom::Point> last_end; + SPKnot *knot_start; + SPKnot *knot_end; + gint dimension_offset; + Geom::Point start_p; + Geom::Point end_p; + sigc::connection _knot_start_moved_connection; + sigc::connection _knot_start_ungrabbed_connection; + sigc::connection _knot_end_moved_connection; + sigc::connection _knot_end_ungrabbed_connection; }; } @@ -48,3 +79,14 @@ private: } #endif // SEEN_SP_MEASURING_CONTEXT_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index e2be5ca4b..7de2a0b04 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -12,6 +12,7 @@ * Steren GIANNINI (steren.giannini@gmail.com) * Jon A. Cruz <jon@joncruz.org> * Abhishek Sharma + * Jabiertxo Arraiza <jabier.arraiza@marker.es> * * Copyright (C) 2009 authors * @@ -48,7 +49,15 @@ #include "sp-path.h" #include "path-chemistry.h" +// For color picking +#include "display/drawing.h" +#include "display/drawing-context.h" +#include "display/cairo-utils.h" +#include "desktop-style.h" +#include "svg/svg-color.h" + #include "sp-text.h" +#include "sp-root.h" #include "sp-flowtext.h" #include "display/sp-canvas.h" #include "display/canvas-bpath.h" @@ -88,6 +97,17 @@ namespace Inkscape { namespace UI { namespace Tools { +enum { + PICK_COLOR, + PICK_OPACITY, + PICK_R, + PICK_G, + PICK_B, + PICK_H, + PICK_S, + PICK_L +}; + const std::string& SprayTool::getPrefsPath() { return SprayTool::prefsPath; } @@ -133,7 +153,9 @@ SprayTool::SprayTool() : ToolBase(cursor_spray_xpm, 4, 4, false) , pressure(TC_DEFAULT_PRESSURE) , dragging(false) - , usepressure(false) + , usepressurewidth(false) + , usepressurepopulation(false) + , usepressurescale(false) , usetilt(false) , usetext(false) , width(0.2) @@ -151,6 +173,25 @@ SprayTool::SprayTool() , is_dilating(false) , has_dilated(false) , dilate_area(NULL) + , no_overlap(false) + , picker(false) + , pick_center(true) + , pick_inverse_value(false) + , pick_fill(false) + , pick_stroke(false) + , pick_no_overlap(false) + , over_transparent(true) + , over_no_transparent(true) + , offset(0) + , pick(0) + , do_trace(false) + , pick_to_size(false) + , pick_to_presence(false) + , pick_to_color(false) + , pick_to_opacity(false) + , invert_picked(false) + , gamma_picked(0) + , rand_picked(0) { } @@ -211,6 +252,15 @@ void SprayTool::setup() { this->is_drawing = false; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool("/dialogs/clonetiler/dotrace", false); + if (prefs->getBool("/tools/spray/selcue")) { + this->enableSelectionCue(); + } + if (prefs->getBool("/tools/spray/gradientdrag")) { + this->enableGrDrag(); + } + sp_event_context_read(this, "distrib"); sp_event_context_read(this, "width"); sp_event_context_read(this, "ratio"); @@ -221,16 +271,33 @@ void SprayTool::setup() { sp_event_context_read(this, "population"); sp_event_context_read(this, "mean"); sp_event_context_read(this, "standard_deviation"); - sp_event_context_read(this, "usepressure"); + sp_event_context_read(this, "usepressurewidth"); + sp_event_context_read(this, "usepressurepopulation"); + sp_event_context_read(this, "usepressurescale"); sp_event_context_read(this, "Scale"); + sp_event_context_read(this, "offset"); + sp_event_context_read(this, "picker"); + sp_event_context_read(this, "pick_center"); + sp_event_context_read(this, "pick_inverse_value"); + sp_event_context_read(this, "pick_fill"); + sp_event_context_read(this, "pick_stroke"); + sp_event_context_read(this, "pick_no_overlap"); + sp_event_context_read(this, "over_no_transparent"); + sp_event_context_read(this, "over_transparent"); + sp_event_context_read(this, "no_overlap"); +} +void SprayTool::setCloneTilerPrefs() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (prefs->getBool("/tools/spray/selcue")) { - this->enableSelectionCue(); - } - if (prefs->getBool("/tools/spray/gradientdrag")) { - this->enableGrDrag(); - } + this->do_trace = prefs->getBool("/dialogs/clonetiler/dotrace", false); + this->pick = prefs->getInt("/dialogs/clonetiler/pick"); + this->pick_to_size = prefs->getBool("/dialogs/clonetiler/pick_to_size", false); + this->pick_to_presence = prefs->getBool("/dialogs/clonetiler/pick_to_presence", false); + this->pick_to_color = prefs->getBool("/dialogs/clonetiler/pick_to_color", false); + this->pick_to_opacity = prefs->getBool("/dialogs/clonetiler/pick_to_opacity", false); + this->rand_picked = 0.01 * prefs->getDoubleLimited("/dialogs/clonetiler/rand_picked", 0, 0, 100); + this->invert_picked = prefs->getBool("/dialogs/clonetiler/invert_picked", false); + this->gamma_picked = prefs->getDoubleLimited("/dialogs/clonetiler/gamma_picked", 0, -10, 10); } void SprayTool::set(const Inkscape::Preferences::Entry& val) { @@ -241,8 +308,12 @@ void SprayTool::set(const Inkscape::Preferences::Entry& val) { this->update_cursor(false); } else if (path == "width") { this->width = 0.01 * CLAMP(val.getInt(10), 1, 100); - } else if (path == "usepressure") { - this->usepressure = val.getBool(); + } else if (path == "usepressurewidth") { + this->usepressurewidth = val.getBool(); + } else if (path == "usepressurepopulation") { + this->usepressurepopulation = val.getBool(); + } else if (path == "usepressurescale") { + this->usepressurescale = val.getBool(); } else if (path == "population") { this->population = 0.01 * CLAMP(val.getInt(10), 1, 100); } else if (path == "rotation_variation") { @@ -260,6 +331,26 @@ void SprayTool::set(const Inkscape::Preferences::Entry& val) { this->tilt = CLAMP(val.getDouble(0.1), 0, 1000.0); } else if (path == "ratio") { this->ratio = CLAMP(val.getDouble(), 0.0, 0.9); + } else if (path == "offset") { + this->offset = val.getDoubleLimited(100.0, 0, 1000.0); + } else if (path == "pick_center") { + this->pick_center = val.getBool(true); + } else if (path == "pick_inverse_value") { + this->pick_inverse_value = val.getBool(false); + } else if (path == "pick_fill") { + this->pick_fill = val.getBool(false); + } else if (path == "pick_stroke") { + this->pick_stroke = val.getBool(false); + } else if (path == "pick_no_overlap") { + this->pick_no_overlap = val.getBool(false); + } else if (path == "over_no_transparent") { + this->over_no_transparent = val.getBool(true); + } else if (path == "over_transparent") { + this->over_transparent = val.getBool(true); + } else if (path == "no_overlap") { + this->no_overlap = val.getBool(false); + } else if (path == "picker") { + this->picker = val.getBool(false); } } @@ -272,9 +363,15 @@ static void sp_spray_extinput(SprayTool *tc, GdkEvent *event) } } +static double get_width(SprayTool *tc) +{ + double pressure = (tc->usepressurewidth? tc->pressure / TC_DEFAULT_PRESSURE : 1); + return pressure * tc->width; +} + static double get_dilate_radius(SprayTool *tc) { - return 250 * tc->width/SP_EVENT_CONTEXT(tc)->desktop->current_zoom(); + return 250 * get_width(tc)/SP_EVENT_CONTEXT(tc)->desktop->current_zoom(); } static double get_path_mean(SprayTool *tc) @@ -289,11 +386,16 @@ static double get_path_standard_deviation(SprayTool *tc) static double get_population(SprayTool *tc) { - double pressure = (tc->usepressure? tc->pressure / TC_DEFAULT_PRESSURE : 1); - //g_warning("Pressure, population: %f, %f", pressure, pressure * tc->population); + double pressure = (tc->usepressurepopulation? tc->pressure / TC_DEFAULT_PRESSURE : 1); return pressure * tc->population; } +static double get_pressure(SprayTool *tc) +{ + double pressure = tc->pressure / TC_DEFAULT_PRESSURE; + return pressure; +} + static double get_move_mean(SprayTool *tc) { return tc->mean; @@ -332,6 +434,435 @@ static void random_position(double &radius, double &angle, double &a, double &s, } +static void sp_spray_transform_path(SPItem * item, Geom::Path &path, Geom::Affine affine, Geom::Point center){ + path *= i2anc_affine(static_cast<SPItem *>(item->parent), NULL).inverse(); + path *= item->transform.inverse(); + Geom::Affine dt2p; + if (item->parent) { + dt2p = static_cast<SPItem *>(item->parent)->i2dt_affine().inverse(); + } else { + SPDesktop *dt = SP_ACTIVE_DESKTOP; + dt2p = dt->dt2doc(); + } + Geom::Affine i2dt = item->i2dt_affine() * Geom::Translate(center).inverse() * affine * Geom::Translate(center); + path *= i2dt * dt2p; + path *= i2anc_affine(static_cast<SPItem *>(item->parent), NULL); +} + +/** +Randomizes \a val by \a rand, with 0 < val < 1 and all values (including 0, 1) having the same +probability of being displaced. + */ +double randomize01(double val, double rand) +{ + double base = MIN (val - rand, 1 - 2*rand); + if (base < 0) { + base = 0; + } + val = base + g_random_double_range (0, MIN (2 * rand, 1 - base)); + return CLAMP(val, 0, 1); // this should be unnecessary with the above provisions, but just in case... +} + +guint32 getPickerData(Geom::IntRect area){ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + double R = 0, G = 0, B = 0, A = 0; + cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, area.width(), area.height()); + sp_canvas_arena_render_surface(SP_CANVAS_ARENA(desktop->getDrawing()), s, area); + ink_cairo_surface_average_color(s, R, G, B, A); + cairo_surface_destroy(s); + //this can fix the bug #1511998 if confirmed + if( A == 0 || A < 1e-6){ + R = 1; + G = 1; + B = 1; + } + return SP_RGBA32_F_COMPOSE(R, G, B, A); +} + +static void showHidden(std::vector<SPItem *> items_down){ + for (std::vector<SPItem *>::const_iterator k=items_down.begin(); k!=items_down.end(); ++k) { + SPItem *item_hidden = *k; + item_hidden->setHidden(false); + item_hidden->updateRepr(); + } +} +//todo: maybe move same parameter to preferences +static bool fit_item(SPDesktop *desktop, + SPItem *item, + Geom::OptRect bbox, + Geom::Point &move, + Geom::Point center, + gint mode, + double angle, + double &_scale, + double scale, + bool picker, + bool pick_center, + bool pick_inverse_value, + bool pick_fill, + bool pick_stroke, + bool pick_no_overlap, + bool over_no_transparent, + bool over_transparent, + bool no_overlap, + double offset, + SPCSSAttr *css, + bool trace_scale, + int pick, + bool do_trace, + bool pick_to_size, + bool pick_to_presence, + bool pick_to_color, + bool pick_to_opacity, + bool invert_picked, + double gamma_picked , + double rand_picked) +{ + SPDocument *doc = item->document; + double width = bbox->width(); + double height = bbox->height(); + double offset_width = (offset * width)/100.0 - (width); + if(offset_width < 0 ){ + offset_width = 0; + } + double offset_height = (offset * height)/100.0 - (height); + if(offset_height < 0 ){ + offset_height = 0; + } + if(picker && pick_to_size && !trace_scale && do_trace){ + _scale = 0.1; + } + Geom::OptRect bbox_procesed = Geom::Rect(Geom::Point(bbox->left() - offset_width, bbox->top() - offset_height),Geom::Point(bbox->right() + offset_width, bbox->bottom() + offset_height)); + Geom::Path path; + path.start(Geom::Point(bbox_procesed->left(), bbox_procesed->top())); + path.appendNew<Geom::LineSegment>(Geom::Point(bbox_procesed->right(), bbox_procesed->top())); + path.appendNew<Geom::LineSegment>(Geom::Point(bbox_procesed->right(), bbox_procesed->bottom())); + path.appendNew<Geom::LineSegment>(Geom::Point(bbox_procesed->left(), bbox_procesed->bottom())); + path.close(true); + sp_spray_transform_path(item, path, Geom::Scale(_scale), center); + sp_spray_transform_path(item, path, Geom::Scale(scale), center); + sp_spray_transform_path(item, path, Geom::Rotate(angle), center); + path *= Geom::Translate(move); + path *= desktop->doc2dt(); + bbox_procesed = path.boundsFast(); + double bbox_left_main = bbox_procesed->left(); + double bbox_right_main = bbox_procesed->right(); + double bbox_top_main = bbox_procesed->top(); + double bbox_bottom_main = bbox_procesed->bottom(); + double width_transformed = bbox_procesed->width(); + double height_transformed = bbox_procesed->height(); + Geom::Point mid_point = desktop->d2w(bbox_procesed->midpoint()); + Geom::IntRect area = Geom::IntRect::from_xywh(floor(mid_point[Geom::X]), floor(mid_point[Geom::Y]), 1, 1); + guint32 rgba = getPickerData(area); + guint32 rgba2 = 0xffffff00; + Geom::Rect rect_sprayed(desktop->d2w(Geom::Point(bbox_left_main,bbox_top_main)), desktop->d2w(Geom::Point(bbox_right_main,bbox_bottom_main))); + if (!rect_sprayed.hasZeroArea()) { + rgba2 = getPickerData(rect_sprayed.roundOutwards()); + } + if(pick_no_overlap) { + if(rgba != rgba2) { + if(mode != SPRAY_MODE_ERASER) { + return false; + } + } + } + if(!pick_center) { + rgba = rgba2; + } + if(!over_transparent && (SP_RGBA32_A_F(rgba) == 0 || SP_RGBA32_A_F(rgba) < 1e-6)) { + if(mode != SPRAY_MODE_ERASER) { + return false; + } + } + if(!over_no_transparent && SP_RGBA32_A_F(rgba) > 0) { + if(mode != SPRAY_MODE_ERASER) { + return false; + } + } + if(offset < 100 ) { + offset_width = ((99.0 - offset) * width_transformed)/100.0 - width_transformed; + offset_height = ((99.0 - offset) * height_transformed)/100.0 - height_transformed; + } else { + offset_width = 0; + offset_height = 0; + } + std::vector<SPItem*> items_down = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *bbox_procesed); + Inkscape::Selection *selection = desktop->getSelection(); + if (selection->isEmpty()) { + return false; + } + std::vector<SPItem*> const items_selected(selection->itemList()); + std::vector<SPItem*> items_down_erased; + for (std::vector<SPItem*>::const_iterator i=items_down.begin(); i!=items_down.end(); i++) { + SPItem *item_down = *i; + Geom::OptRect bbox_down = item_down->documentVisualBounds(); + width = bbox_down->width(); + height = bbox_down->height(); + double bbox_left = bbox_down->left(); + double bbox_top = bbox_down->top(); + gchar const * item_down_sharp = g_strdup_printf("#%s", item_down->getId()); + items_down_erased.push_back(item_down); + for (std::vector<SPItem*>::const_iterator j=items_selected.begin(); j!=items_selected.end(); j++) { + SPItem *item_selected = *j; + gchar const * spray_origin; + if(!item_selected->getAttribute("inkscape:spray-origin")){ + spray_origin = g_strdup_printf("#%s", item_selected->getId()); + } else { + spray_origin = item_selected->getAttribute("inkscape:spray-origin"); + } + if(strcmp(item_down_sharp, spray_origin) == 0 || + (item_down->getAttribute("inkscape:spray-origin") && + strcmp(item_down->getAttribute("inkscape:spray-origin"),spray_origin) == 0 )) + { + if(mode == SPRAY_MODE_ERASER) { + if(strcmp(item_down_sharp, spray_origin) != 0 && !selection->includes(item_down) ){ + item_down->deleteObject(); + items_down_erased.pop_back(); + break; + } + } else if(no_overlap) { + if(!(offset_width < 0 && offset_height < 0 && std::abs(bbox_left - bbox_left_main) > std::abs(offset_width) && + std::abs(bbox_top - bbox_top_main) > std::abs(offset_height))){ + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ + showHidden(items_down); + } + return false; + } + } else if(picker || over_transparent || over_no_transparent) { + item_down->setHidden(true); + item_down->updateRepr(); + } + } + } + } + if(mode == SPRAY_MODE_ERASER){ + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ + showHidden(items_down_erased); + } + return false; + } + if(picker || over_transparent || over_no_transparent){ + if(!no_overlap){ + doc->ensureUpToDate(); + rgba = getPickerData(area); + if (!rect_sprayed.hasZeroArea()) { + rgba2 = getPickerData(rect_sprayed.roundOutwards()); + } + } + if(pick_no_overlap){ + if(rgba != rgba2){ + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ + showHidden(items_down); + } + return false; + } + } + if(!pick_center){ + rgba = rgba2; + } + double opacity = 1.0; + gchar color_string[32]; *color_string = 0; + float r = SP_RGBA32_R_F(rgba); + float g = SP_RGBA32_G_F(rgba); + float b = SP_RGBA32_B_F(rgba); + float a = SP_RGBA32_A_F(rgba); + if(!over_transparent && (a == 0 || a < 1e-6)){ + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ + showHidden(items_down); + } + return false; + } + if(!over_no_transparent && a > 0){ + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ + showHidden(items_down); + } + return false; + } + + if(picker && do_trace){ + float hsl[3]; + sp_color_rgb_to_hsl_floatv (hsl, r, g, b); + + gdouble val = 0; + switch (pick) { + case PICK_COLOR: + val = 1 - hsl[2]; // inverse lightness; to match other picks where black = max + break; + case PICK_OPACITY: + val = a; + break; + case PICK_R: + val = r; + break; + case PICK_G: + val = g; + break; + case PICK_B: + val = b; + break; + case PICK_H: + val = hsl[0]; + break; + case PICK_S: + val = hsl[1]; + break; + case PICK_L: + val = 1 - hsl[2]; + break; + default: + break; + } + + if (rand_picked > 0) { + val = randomize01 (val, rand_picked); + r = randomize01 (r, rand_picked); + g = randomize01 (g, rand_picked); + b = randomize01 (b, rand_picked); + } + + if (gamma_picked != 0) { + double power; + if (gamma_picked > 0) + power = 1/(1 + fabs(gamma_picked)); + else + power = 1 + fabs(gamma_picked); + + val = pow (val, power); + r = pow ((double)r, (double)power); + g = pow ((double)g, (double)power); + b = pow ((double)b, (double)power); + } + + if (invert_picked) { + val = 1 - val; + r = 1 - r; + g = 1 - g; + b = 1 - b; + } + + val = CLAMP (val, 0, 1); + r = CLAMP (r, 0, 1); + g = CLAMP (g, 0, 1); + b = CLAMP (b, 0, 1); + + // recompose tweaked color + rgba = SP_RGBA32_F_COMPOSE(r, g, b, a); + if (pick_to_size) { + if(!trace_scale){ + if(pick_inverse_value) { + _scale = 1.0 - val; + } else { + _scale = val; + } + if(_scale == 0.0) { + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ + showHidden(items_down); + } + return false; + } + if(!fit_item(desktop + , item + , bbox + , move + , center + , mode + , angle + , _scale + , scale + , picker + , pick_center + , pick_inverse_value + , pick_fill + , pick_stroke + , pick_no_overlap + , over_no_transparent + , over_transparent + , no_overlap + , offset + , css + , true + , pick + , do_trace + , pick_to_size + , pick_to_presence + , pick_to_color + , pick_to_opacity + , invert_picked + , gamma_picked + , rand_picked) + ) + { + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ + showHidden(items_down); + } + return false; + } + } + } + + if (pick_to_opacity) { + if(pick_inverse_value) { + opacity *= 1.0 - val; + } else { + opacity *= val; + } + std::stringstream opacity_str; + opacity_str.imbue(std::locale::classic()); + opacity_str << opacity; + sp_repr_css_set_property(css, "opacity", opacity_str.str().c_str()); + } + if (pick_to_presence) { + if (g_random_double_range (0, 1) > val) { + //Hidding the element is a way to retain original + //behaviour of tiled clones for presence option. + sp_repr_css_set_property(css, "opacity", "0"); + } + } + if (pick_to_color) { + sp_svg_write_color(color_string, sizeof(color_string), rgba); + if(pick_fill){ + sp_repr_css_set_property(css, "fill", color_string); + } + if(pick_stroke){ + sp_repr_css_set_property(css, "stroke", color_string); + } + } + if (opacity < 1e-6) { // invisibly transparent, skip + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ + showHidden(items_down); + } + return false; + } + } + if(!do_trace){ + if(!pick_center){ + rgba = rgba2; + } + if (pick_inverse_value) { + r = 1 - SP_RGBA32_R_F(rgba); + g = 1 - SP_RGBA32_G_F(rgba); + b = 1 - SP_RGBA32_B_F(rgba); + } else { + r = SP_RGBA32_R_F(rgba); + g = SP_RGBA32_G_F(rgba); + b = SP_RGBA32_B_F(rgba); + } + rgba = SP_RGBA32_F_COMPOSE(r, g, b, a); + sp_svg_write_color(color_string, sizeof(color_string), rgba); + if(pick_fill){ + sp_repr_css_set_property(css, "fill", color_string); + } + if(pick_stroke){ + sp_repr_css_set_property(css, "stroke", color_string); + } + } + if(!no_overlap && (picker || over_transparent || over_no_transparent)){ + showHidden(items_down); + } + } + return true; +} + static bool sp_spray_recursive(SPDesktop *desktop, Inkscape::Selection *selection, SPItem *item, @@ -348,7 +879,28 @@ static bool sp_spray_recursive(SPDesktop *desktop, double ratio, double tilt, double rotation_variation, - gint _distrib) + gint _distrib, + bool no_overlap, + bool picker, + bool pick_center, + bool pick_inverse_value, + bool pick_fill, + bool pick_stroke, + bool pick_no_overlap, + bool over_no_transparent, + bool over_transparent, + double offset, + bool usepressurescale, + double pressure, + int pick, + bool do_trace, + bool pick_to_size, + bool pick_to_presence, + bool pick_to_color, + bool pick_to_opacity, + bool invert_picked, + double gamma_picked , + double rand_picked) { bool did = false; @@ -364,34 +916,83 @@ static bool sp_spray_recursive(SPDesktop *desktop, double _fid = g_random_double_range(0, 1); double angle = g_random_double_range( - rotation_variation / 100.0 * M_PI , rotation_variation / 100.0 * M_PI ); double _scale = g_random_double_range( 1.0 - scale_variation / 100.0, 1.0 + scale_variation / 100.0 ); + if(usepressurescale){ + _scale = pressure; + } double dr; double dp; random_position( dr, dp, mean, standard_deviation, _distrib ); dr=dr*radius; - if (mode == SPRAY_MODE_COPY) { + if (mode == SPRAY_MODE_COPY || mode == SPRAY_MODE_ERASER) { Geom::OptRect a = item->documentVisualBounds(); if (a) { - SPItem *item_copied; if(_fid <= population) { - // Duplicate SPDocument *doc = item->document; + gchar const * spray_origin; + if(!item->getAttribute("inkscape:spray-origin")){ + spray_origin = g_strdup_printf("#%s", item->getId()); + } else { + spray_origin = item->getAttribute("inkscape:spray-origin"); + } + Geom::Point center = item->getCenter(); + Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); + SPCSSAttr *css = sp_repr_css_attr_new(); + if(no_overlap || picker || !over_transparent || !over_no_transparent){ + if(!fit_item(desktop + , item + , a + , move + , center + , mode + , angle + , _scale + , scale + , picker + , pick_center + , pick_inverse_value + , pick_fill + , pick_stroke + , pick_no_overlap + , over_no_transparent + , over_transparent + , no_overlap + , offset + , css + , false + , pick + , do_trace + , pick_to_size + , pick_to_presence + , pick_to_color + , pick_to_opacity + , invert_picked + , gamma_picked + , rand_picked)){ + return false; + } + } + SPItem *item_copied; + // Duplicate Inkscape::XML::Document* xml_doc = doc->getReprDoc(); Inkscape::XML::Node *old_repr = item->getRepr(); Inkscape::XML::Node *parent = old_repr->parent(); Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); + if(!copy->attribute("inkscape:spray-origin")){ + copy->setAttribute("inkscape:spray-origin", spray_origin); + } parent->appendChild(copy); - SPObject *new_obj = doc->getObjectByRepr(copy); item_copied = dynamic_cast<SPItem *>(new_obj); // Conversion object->item - Geom::Point center=item->getCenter(); - sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale,_scale)); - sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale,scale)); - + sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(_scale)); + sp_spray_scale_rel(center,desktop, item_copied, Geom::Scale(scale)); sp_spray_rotate_rel(center,desktop,item_copied, Geom::Rotate(angle)); // Move the cursor p - Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); + Inkscape::GC::release(copy); + if(picker){ + sp_desktop_apply_css_recursive(item_copied, css, true); + } did = true; } } @@ -404,7 +1005,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, int i=1; std::vector<SPItem*> items=selection->itemList(); - for(std::vector<SPItem*>::const_iterator it=items.begin();it!=items.end();it++){ + for(std::vector<SPItem*>::const_iterator it=items.begin();it!=items.end(); ++it){ SPItem *item1 = *it; if (i == 1) { parent_item = item1; @@ -425,6 +1026,13 @@ static bool sp_spray_recursive(SPDesktop *desktop, if (_fid <= population) { // Rules the population of objects sprayed // Duplicates the parent item Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc); + gchar const * spray_origin; + if(!copy->attribute("inkscape:spray-origin")){ + spray_origin = g_strdup_printf("#%s", old_repr->attribute("id")); + copy->setAttribute("inkscape:spray-origin", spray_origin); + } else { + spray_origin = copy->attribute("inkscape:spray-origin"); + } parent->appendChild(copy); SPObject *new_obj = doc->getObjectByRepr(copy); item_copied = dynamic_cast<SPItem *>(new_obj); @@ -456,8 +1064,52 @@ static bool sp_spray_recursive(SPDesktop *desktop, Geom::OptRect a = item->documentVisualBounds(); if (a) { if(_fid <= population) { - SPItem *item_copied; SPDocument *doc = item->document; + gchar const * spray_origin; + if(!item->getAttribute("inkscape:spray-origin")){ + spray_origin = g_strdup_printf("#%s", item->getId()); + } else { + spray_origin = item->getAttribute("inkscape:spray-origin"); + } + Geom::Point center=item->getCenter(); + Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); + SPCSSAttr *css = sp_repr_css_attr_new(); + if(no_overlap || picker || !over_transparent || !over_no_transparent){ + if(!fit_item(desktop + , item + , a + , move + , center + , mode + , angle + , _scale + , scale + , picker + , pick_center + , pick_inverse_value + , pick_fill + , pick_stroke + , pick_no_overlap + , over_no_transparent + , over_transparent + , no_overlap + , offset + , css + , true + , pick + , do_trace + , pick_to_size + , pick_to_presence + , pick_to_color + , pick_to_opacity + , invert_picked + , gamma_picked + , rand_picked)) + { + return false; + } + } + SPItem *item_copied; Inkscape::XML::Document* xml_doc = doc->getReprDoc(); Inkscape::XML::Node *old_repr = item->getRepr(); Inkscape::XML::Node *parent = old_repr->parent(); @@ -467,6 +1119,9 @@ static bool sp_spray_recursive(SPDesktop *desktop, // Ad the clone to the list of the parent's children parent->appendChild(clone); // Generates the link between parent and child attributes + if(!clone->attribute("inkscape:spray-origin")){ + clone->setAttribute("inkscape:spray-origin", spray_origin); + } gchar *href_str = g_strdup_printf("#%s", old_repr->attribute("id")); clone->setAttribute("xlink:href", href_str, false); g_free(href_str); @@ -474,15 +1129,14 @@ static bool sp_spray_recursive(SPDesktop *desktop, SPObject *clone_object = doc->getObjectByRepr(clone); // Conversion object->item item_copied = dynamic_cast<SPItem *>(clone_object); - Geom::Point center = item->getCenter(); sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(_scale, _scale)); sp_spray_scale_rel(center, desktop, item_copied, Geom::Scale(scale, scale)); sp_spray_rotate_rel(center, desktop, item_copied, Geom::Rotate(angle)); - Geom::Point move = (Geom::Point(cos(tilt)*cos(dp)*dr/(1-ratio)+sin(tilt)*sin(dp)*dr/(1+ratio), -sin(tilt)*cos(dp)*dr/(1-ratio)+cos(tilt)*sin(dp)*dr/(1+ratio)))+(p-a->midpoint()); sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y])); - + if(picker){ + sp_desktop_apply_css_recursive(item_copied, css, true); + } Inkscape::GC::release(clone); - did = true; } } @@ -520,22 +1174,57 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point { std::vector<SPItem*> const items(selection->itemList()); - for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end(); ++i){ SPItem *item = *i; g_assert(item != NULL); sp_object_ref(item); } - for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end(); ++i){ SPItem *item = *i; g_assert(item != NULL); - - if (sp_spray_recursive(desktop, selection, item, p, vector, tc->mode, radius, population, tc->scale, tc->scale_variation, reverse, move_mean, move_standard_deviation, tc->ratio, tc->tilt, tc->rotation_variation, tc->distrib)) { + if (sp_spray_recursive(desktop + , selection + , item + , p, vector + , tc->mode + , radius + , population + , tc->scale + , tc->scale_variation + , reverse + , move_mean + , move_standard_deviation + , tc->ratio + , tc->tilt + , tc->rotation_variation + , tc->distrib + , tc->no_overlap + , tc->picker + , tc->pick_center + , tc->pick_inverse_value + , tc->pick_fill + , tc->pick_stroke + , tc->pick_no_overlap + , tc->over_no_transparent + , tc->over_transparent + , tc->offset + , tc->usepressurescale + , get_pressure(tc) + , tc->pick + , tc->do_trace + , tc->pick_to_size + , tc->pick_to_presence + , tc->pick_to_color + , tc->pick_to_opacity + , tc->invert_picked + , tc->gamma_picked + , tc->rand_picked)) { did = true; } } - for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end(); ++i){ SPItem *item = *i; g_assert(item != NULL); sp_object_unref(item); @@ -577,7 +1266,7 @@ bool SprayTool::root_handler(GdkEvent* event) { if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { return TRUE; } - + this->setCloneTilerPrefs(); Geom::Point const motion_w(event->button.x, event->button.y); Geom::Point const motion_dt(desktop->w2d(motion_w)); this->last_push = desktop->dt2doc(motion_dt); diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index 8df730201..c81110b37 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -12,6 +12,7 @@ * Benoît LAVORATA * Vincent MONTAGNE * Pierre BARBRY-BLOT + * Jabiertxo ARRAIZA * * Copyright (C) 2009 authors * @@ -46,7 +47,8 @@ namespace Tools { enum { SPRAY_MODE_COPY, SPRAY_MODE_CLONE, - SPRAY_MODE_SINGLE_PATH, + SPRAY_MODE_SINGLE_PATH, + SPRAY_MODE_ERASER, SPRAY_OPTION, }; @@ -62,7 +64,9 @@ public: /* attributes */ bool dragging; /* mouse state: mouse is dragging */ - bool usepressure; + bool usepressurewidth; + bool usepressurepopulation; + bool usepressurescale; bool usetilt; bool usetext; @@ -86,13 +90,32 @@ public: bool has_dilated; Geom::Point last_push; SPCanvasItem *dilate_area; - + bool no_overlap; + bool picker; + bool pick_center; + bool pick_inverse_value; + bool pick_fill; + bool pick_stroke; + bool pick_no_overlap; + bool over_transparent; + bool over_no_transparent; + double offset; + int pick; + bool do_trace; + bool pick_to_size; + bool pick_to_presence; + bool pick_to_color; + bool pick_to_opacity; + bool invert_picked; + double gamma_picked; + double rand_picked; sigc::connection style_set_connection; static const std::string prefsPath; virtual void setup(); virtual void set(const Inkscape::Preferences::Entry& val); + virtual void setCloneTilerPrefs(); virtual bool root_handler(GdkEvent* event); virtual const std::string& getPrefsPath(); diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index 94f7aa135..39a7a3f0b 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -1077,7 +1077,7 @@ sp_tweak_dilate (TweakTool *tc, Geom::Point event_p, Geom::Point p, Geom::Point double color_force = MIN(sqrt(path_force)/20.0, 1); std::vector<SPItem*> items=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end(); ++i){ SPItem *item = *i; if (is_color_mode (tc->mode)) { diff --git a/src/ui/widget/font-variants.cpp b/src/ui/widget/font-variants.cpp index 5d1e40971..62598dead 100644 --- a/src/ui/widget/font-variants.cpp +++ b/src/ui/widget/font-variants.cpp @@ -35,41 +35,41 @@ namespace Widget { FontVariants::FontVariants () : Gtk::VBox (), - _ligatures_frame ( Glib::ustring(_("Ligatures" )) ), - _ligatures_common ( Glib::ustring(_("Common" )) ), - _ligatures_discretionary ( Glib::ustring(_("Discretionary")) ), - _ligatures_historical ( Glib::ustring(_("Historical" )) ), - _ligatures_contextual ( Glib::ustring(_("Contextual" )) ), - - _position_frame ( Glib::ustring(_("Position" )) ), - _position_normal ( Glib::ustring(_("Normal" )) ), - _position_sub ( Glib::ustring(_("Subscript" )) ), - _position_super ( Glib::ustring(_("Superscript" )) ), - - _caps_frame ( Glib::ustring(_("Capitals" )) ), - _caps_normal ( Glib::ustring(_("Normal" )) ), - _caps_small ( Glib::ustring(_("Small" )) ), - _caps_all_small ( Glib::ustring(_("All small" )) ), - _caps_petite ( Glib::ustring(_("Petite" )) ), - _caps_all_petite ( Glib::ustring(_("All petite" )) ), - _caps_unicase ( Glib::ustring(_("Unicase" )) ), - _caps_titling ( Glib::ustring(_("Titling" )) ), - - _numeric_frame ( Glib::ustring(_("Numeric" )) ), - _numeric_lining ( Glib::ustring(_("Lining" )) ), - _numeric_old_style ( Glib::ustring(_("Old Style" )) ), - _numeric_default_style ( Glib::ustring(_("Default Style")) ), - _numeric_proportional ( Glib::ustring(_("Proportional" )) ), - _numeric_tabular ( Glib::ustring(_("Tabular" )) ), - _numeric_default_width ( Glib::ustring(_("Default Width")) ), - _numeric_diagonal ( Glib::ustring(_("Diagonal" )) ), - _numeric_stacked ( Glib::ustring(_("Stacked" )) ), - _numeric_default_fractions( Glib::ustring(_("Default Fractions")) ), - _numeric_ordinal ( Glib::ustring(_("Ordinal" )) ), - _numeric_slashed_zero ( Glib::ustring(_("Slashed Zero" )) ), - - _feature_frame ( Glib::ustring(_("Feature Settings")) ), - _feature_label ( Glib::ustring(_("Selection has different Feature Settings!")) ), + _ligatures_frame ( Glib::ustring(C_("Font variant", "Ligatures" )) ), + _ligatures_common ( Glib::ustring(C_("Font variant", "Common" )) ), + _ligatures_discretionary ( Glib::ustring(C_("Font variant", "Discretionary")) ), + _ligatures_historical ( Glib::ustring(C_("Font variant", "Historical" )) ), + _ligatures_contextual ( Glib::ustring(C_("Font variant", "Contextual" )) ), + + _position_frame ( Glib::ustring(C_("Font variant", "Position" )) ), + _position_normal ( Glib::ustring(C_("Font variant", "Normal" )) ), + _position_sub ( Glib::ustring(C_("Font variant", "Subscript" )) ), + _position_super ( Glib::ustring(C_("Font variant", "Superscript" )) ), + + _caps_frame ( Glib::ustring(C_("Font variant", "Capitals" )) ), + _caps_normal ( Glib::ustring(C_("Font variant", "Normal" )) ), + _caps_small ( Glib::ustring(C_("Font variant", "Small" )) ), + _caps_all_small ( Glib::ustring(C_("Font variant", "All small" )) ), + _caps_petite ( Glib::ustring(C_("Font variant", "Petite" )) ), + _caps_all_petite ( Glib::ustring(C_("Font variant", "All petite" )) ), + _caps_unicase ( Glib::ustring(C_("Font variant", "Unicase" )) ), + _caps_titling ( Glib::ustring(C_("Font variant", "Titling" )) ), + + _numeric_frame ( Glib::ustring(C_("Font variant", "Numeric" )) ), + _numeric_lining ( Glib::ustring(C_("Font variant", "Lining" )) ), + _numeric_old_style ( Glib::ustring(C_("Font variant", "Old Style" )) ), + _numeric_default_style ( Glib::ustring(C_("Font variant", "Default Style")) ), + _numeric_proportional ( Glib::ustring(C_("Font variant", "Proportional" )) ), + _numeric_tabular ( Glib::ustring(C_("Font variant", "Tabular" )) ), + _numeric_default_width ( Glib::ustring(C_("Font variant", "Default Width")) ), + _numeric_diagonal ( Glib::ustring(C_("Font variant", "Diagonal" )) ), + _numeric_stacked ( Glib::ustring(C_("Font variant", "Stacked" )) ), + _numeric_default_fractions( Glib::ustring(C_("Font variant", "Default Fractions")) ), + _numeric_ordinal ( Glib::ustring(C_("Font variant", "Ordinal" )) ), + _numeric_slashed_zero ( Glib::ustring(C_("Font variant", "Slashed Zero" )) ), + + _feature_frame ( Glib::ustring(C_("Font variant", "Feature Settings")) ), + _feature_label ( Glib::ustring(C_("Font variant", "Selection has different Feature Settings!")) ), _ligatures_changed( false ), _position_changed( false ), diff --git a/src/unclump.cpp b/src/unclump.cpp index 81c958937..2c6840425 100644 --- a/src/unclump.cpp +++ b/src/unclump.cpp @@ -172,7 +172,7 @@ static double unclump_average (SPItem *item, std::list<SPItem*> &others) { int n = 0; double sum = 0; - for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();i++) { + for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();++i) { SPItem *other = *i; if (other == item) @@ -196,7 +196,7 @@ static SPItem *unclump_closest (SPItem *item, std::list<SPItem*> &others) double min = HUGE_VAL; SPItem *closest = NULL; - for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();i++) { + for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();++i) { SPItem *other = *i; if (other == item) @@ -219,7 +219,7 @@ static SPItem *unclump_farest (SPItem *item, std::list<SPItem*> &others) { double max = -HUGE_VAL; SPItem *farest = NULL; - for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();i++) { + for (std::list<SPItem*>::const_iterator i = others.begin(); i != others.end();++i) { SPItem *other = *i; if (other == item) @@ -259,7 +259,7 @@ unclump_remove_behind (SPItem *item, SPItem *closest, std::list<SPItem*> &rest) double val_item = A * it[Geom::X] + B * it[Geom::Y] + C; std::vector<SPItem*> out; - for (std::list<SPItem*>::const_reverse_iterator i = rest.rbegin(); i != rest.rend();i++) { + for (std::list<SPItem*>::const_reverse_iterator i = rest.rbegin(); i != rest.rend();++i) { SPItem *other = *i; if (other == item) @@ -336,7 +336,7 @@ unclump (std::vector<SPItem*> &items) c_cache.clear(); wh_cache.clear(); - for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end();i++) { // for each original/clone x: + for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end();++i) { // for each original/clone x: SPItem *item = *i; std::list<SPItem*> nei; diff --git a/src/uri.cpp b/src/uri.cpp index 2eaf4ecc1..49bdab63c 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -148,7 +148,7 @@ gchar *URI::to_native_filename(gchar const* uri) throw(BadURIException) * Does not check if the returned path is the local document's path (local) * and thus redundent. Caller is expected to check against the document's path. */ -const std::string URI::getFullPath(std::string const base) const { +const std::string URI::getFullPath(std::string const &base) const { if (!_impl->getPath()) { return ""; } @@ -104,7 +104,7 @@ public: static char *to_native_filename(char const* uri) throw(BadURIException); - const std::string getFullPath(std::string const base) const; + const std::string getFullPath(std::string const &base) const; char *toNativeFilename() const throw(BadURIException); diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index 71418e238..7b872e8b1 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -98,7 +98,7 @@ sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *v bool modmade = false; std::vector<SPItem*> itemlist=desktop->getSelection()->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { @@ -164,7 +164,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) if ( ege_select_one_action_get_active(act) != 0 ) { std::vector<SPItem*> itemlist=desktop->getSelection()->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -175,7 +175,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) } } else { std::vector<SPItem*> itemlist=desktop->getSelection()->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -265,7 +265,7 @@ static void sp_arc_toolbox_selection_changed(Inkscape::Selection *selection, GOb purge_repr_listener( tbl, tbl ); std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { n_selected++; diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index 1c99f283d..8cc254bd2 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -98,7 +98,7 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl bool modmade = false; std::vector<SPItem*> itemlist=desktop->getSelection()->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (Inkscape::UI::Tools::cc_item_is_connector(item)) { @@ -145,7 +145,7 @@ static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) bool modmade = false; std::vector<SPItem*> itemlist=desktop->getSelection()->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (Inkscape::UI::Tools::cc_item_is_connector(item)) { diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index fa5eabab4..a57c891e5 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -570,7 +570,7 @@ void FillNStroke::updateFromPaint() } } - for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end(); ++i){ //FIXME: see above if (kind == FILL) { sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); @@ -596,7 +596,7 @@ void FillNStroke::updateFromPaint() // We have changed from another gradient type, or modified spread/units within // this gradient type. vector = sp_gradient_ensure_vector_normalized(vector); - for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end(); ++i){ //FIXME: see above if (kind == FILL) { sp_repr_css_change_recursive((*i)->getRepr(), css, "style"); @@ -642,7 +642,7 @@ void FillNStroke::updateFromPaint() // cannot just call sp_desktop_set_style, because we don't want to touch those // objects who already have the same root pattern but through a different href // chain. FIXME: move this to a sp_item_set_pattern - for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end(); ++i){ Inkscape::XML::Node *selrepr = (*i)->getRepr(); if ( (kind == STROKE) && !selrepr) { continue; diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index 6743dd23a..b24615126 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -117,7 +117,7 @@ void gr_apply_gradient(Inkscape::Selection *selection, GrDrag *drag, SPGradient // If no drag or no dragger selected, act on selection std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ gr_apply_gradient_to_item(*i, gr, initialType, initialMode, initialMode); } } @@ -219,7 +219,7 @@ void gr_get_dt_selected_gradient(Inkscape::Selection *selection, SPGradient *&gr SPGradient *gradient = 0; std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i;// get the items gradient, not the getVector() version SPStyle *style = item->style; SPPaintServer *server = 0; @@ -287,7 +287,7 @@ void gr_read_selection( Inkscape::Selection *selection, // If no selected dragger, read desktop selection std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; SPStyle *style = item->style; diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 5a4785b1f..67c128dd2 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -33,11 +33,16 @@ #include "measure-toolbar.h" #include "desktop.h" +#include "inkscape.h" +#include "message-stack.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" #include "widgets/ege-output-action.h" #include "preferences.h" #include "toolbox.h" +#include "widgets/ink-action.h" +#include "ui/icon-names.h" +#include "ui/tools/measure-tool.h" #include "ui/widget/unit-tracker.h" using Inkscape::UI::Widget::UnitTracker; @@ -45,11 +50,26 @@ using Inkscape::Util::Unit; using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; using Inkscape::UI::PrefPusher; +using Inkscape::UI::Tools::MeasureTool; //######################## //## Measure Toolbox ## //######################## +/** Temporary hack: Returns the node tool in the active desktop. + * Will go away during tool refactoring. */ +static MeasureTool *get_measure_tool() +{ + MeasureTool *tool = 0; + if (SP_ACTIVE_DESKTOP ) { + Inkscape::UI::Tools::ToolBase *ec = SP_ACTIVE_DESKTOP->event_context; + if (SP_IS_MEASURE_CONTEXT(ec)) { + tool = static_cast<MeasureTool*>(ec); + } + } + return tool; +} + static void sp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl) { @@ -57,17 +77,176 @@ sp_measure_fontsize_value_changed(GtkAdjustment *adj, GObject *tbl) if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt(Glib::ustring("/tools/measure/fontsize"), + prefs->setDouble(Glib::ustring("/tools/measure/fontsize"), + gtk_adjustment_get_value(adj)); + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } + } +} + +static void +sp_measure_offset_value_changed(GtkAdjustment *adj, GObject *tbl) +{ + SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); + + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble(Glib::ustring("/tools/measure/offset"), gtk_adjustment_get_value(adj)); + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } } } -static void measure_unit_changed(GtkAction* /*act*/, GObject* tbl) +static void sp_measure_scale_value_changed(GtkAdjustment *adj, GObject *tbl) +{ + SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); + + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble(Glib::ustring("/tools/measure/scale"), + gtk_adjustment_get_value(adj)); + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } + } +} + +static void +sp_measure_precision_value_changed(GtkAdjustment *adj, GObject *tbl) +{ + SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data( tbl, "desktop" )); + + if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setInt(Glib::ustring("/tools/measure/precision"), + gtk_adjustment_get_value(adj)); + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } + } +} + +static void +sp_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; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setString("/tools/measure/unit", unit); + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } +} + +static void +sp_toggle_ignore_1st_and_last( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/measure/ignore_1st_and_last", active); + SPDesktop *desktop = static_cast<SPDesktop *>(data); + if ( active ) { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Start and end measures inactive.")); + } else { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Start and end measures active.")); + } + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } +} + +static void +sp_toggle_only_visible( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/measure/only_visible", active); + SPDesktop *desktop = static_cast<SPDesktop *>(data); + if ( active ) { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Show only visible crossings.")); + } else { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Show all crossings.")); + } + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } +} + +static void +sp_toggle_all_layers( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/measure/all_layers", active); + SPDesktop *desktop = static_cast<SPDesktop *>(data); + if ( active ) { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Use all layers in the measure.")); + } else { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Use current layer in the measure.")); + } + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } +} + +static void +sp_toggle_show_in_between( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/measure/show_in_between", active); + SPDesktop *desktop = static_cast<SPDesktop *>(data); + if ( active ) { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Compute all elements.")); + } else { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Compute max lenght.")); + } + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->showCanvasItems(); + } +} +static void +sp_reverse_knots(void){ + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->reverseKnots(); + } +} + +static void +sp_to_mark_dimension(void){ + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->toMarkDimension(); + } +} + +static void +sp_to_guides(void){ + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->toGuides(); + } +} + +static void +sp_to_item(void){ + MeasureTool *mt = get_measure_tool(); + if (mt) { + mt->toItem(); + } } void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, GObject* holder) @@ -79,22 +258,22 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G g_object_set_data( holder, "tracker", tracker ); EgeAdjustmentAction *eact = 0; + Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); /* Font Size */ { eact = create_adjustment_action( "MeasureFontSizeAction", _("Font Size"), _("Font Size:"), _("The font size to be used in the measurement labels"), - "/tools/measure/fontsize", 0.0, + "/tools/measure/fontsize", 10.0, GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, - 10, 36, 1.0, 4.0, + 1.0, 36.0, 1.0, 4.0, 0, 0, 0, - sp_measure_fontsize_value_changed); - gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + sp_measure_fontsize_value_changed, NULL, 0 , 2); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact)); } - - // units label + /* units label */ { EgeOutputAction* act = ege_output_action_new( "measure_units_label", _("Units:"), _("The units to be used for the measurements"), 0 ); ege_output_action_set_use_markup( act, TRUE ); @@ -102,12 +281,136 @@ void sp_measure_toolbox_prep(SPDesktop * desktop, GtkActionGroup* mainActions, G gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); } - // units menu + /* units menu */ { GtkAction* act = tracker->createAction( "MeasureUnitsAction", _("Units:"), _("The units to be used for the measurements") ); - g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(measure_unit_changed), holder ); + g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_measure_unit_changed), holder ); gtk_action_group_add_action( mainActions, act ); } + + /* Precission */ + { + eact = create_adjustment_action( "MeasurePrecisionAction", + _("Precision"), _("Precision:"), + _("Decimal precision of measure"), + "/tools/measure/precision", 2, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, + 0, 10, 1, 0, + 0, 0, 0, + sp_measure_precision_value_changed, NULL, 0 ,0); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact)); + } + + /* Scale */ + { + eact = create_adjustment_action( "MeasureScaleAction", + _("Scale %"), _("Scale %:"), + _("Scale the results"), + "/tools/measure/scale", 100.0, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, + 0.0, 90000.0, 1.0, 4.0, + 0, 0, 0, + sp_measure_scale_value_changed, NULL, 0 , 3); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + } + + /* Offset */ + { + eact = create_adjustment_action( "MeasureOffsetAction", + _("Offset"), _("Offset:"), + _("The offset size"), + "/tools/measure/offset", 5.0, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, + 0.0, 90000.0, 1.0, 4.0, + 0, 0, 0, + sp_measure_offset_value_changed, NULL, 0 , 2); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + } + + /* ignore_1st_and_last */ + { + InkToggleAction* act = ink_toggle_action_new( "MeasureIgnore1stAndLast", + _("Ignore first and last"), + _("Ignore first and last"), + INKSCAPE_ICON("draw-geometry-line-segment"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/ignore_1st_and_last", true) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_ignore_1st_and_last), desktop) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + /* only visible */ + { + InkToggleAction* act = ink_toggle_action_new( "MeasureOnlyVisible", + _("Only visible intersections"), + _("Only visible intersections"), + INKSCAPE_ICON("zoom"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/only_visible", true) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_only_visible), desktop) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + /* measure imbetweens */ + { + InkToggleAction* act = ink_toggle_action_new( "MeasureInBettween", + _("Show measures between items"), + _("Show measures between items"), + INKSCAPE_ICON("distribute-randomize"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/show_in_between", true) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_show_in_between), desktop) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + /* measure only current layer */ + { + InkToggleAction* act = ink_toggle_action_new( "MeasureAllLayers", + _("Measure all layers"), + _("Measure all layers"), + INKSCAPE_ICON("dialog-layers"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/measure/all_layers", true) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_all_layers), desktop) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + /* toogle start end */ + { + InkAction* act = ink_action_new( "MeasureReverse", + _("Reverse measure"), + _("Reverse measure"), + INKSCAPE_ICON("draw-geometry-mirror"), + secondarySize ); + g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_reverse_knots), 0 ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + /* to guides */ + { + InkAction* act = ink_action_new( "MeasureToGuides", + _("To guides"), + _("To guides"), + INKSCAPE_ICON("guides"), + secondarySize ); + g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_guides), 0 ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + /* to mark dimensions */ + { + InkAction* act = ink_action_new( "MeasureMarkDimension", + _("Mark Dimension"), + _("Mark Dimension"), + INKSCAPE_ICON("tool-pointer"), + secondarySize ); + g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_mark_dimension), 0 ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + /* to item */ + { + InkAction* act = ink_action_new( "MeasureToItem", + _("Convert to item"), + _("Convert to item"), + INKSCAPE_ICON("path-reverse"), + secondarySize ); + g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(sp_to_item), 0 ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } } // end of sp_measure_toolbox_prep() diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index bef9129b9..4e0b6d68b 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -90,7 +90,7 @@ void ms_read_selection( Inkscape::Selection *selection, ms_type = SP_MESH_TYPE_COONS; std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; SPStyle *style = item->style; @@ -217,7 +217,7 @@ void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMesh *&ms_sel SPMesh *gradient = 0; std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i;// get the items gradient, not the getVector() version SPStyle *style = item->style; SPPaintServer *server = 0; diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index 96ba699dc..bc27d003c 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -107,7 +107,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ if (SP_IS_RECT(*i)) { if (gtk_adjustment_get_value(adj) != 0) { (SP_RECT(*i)->*setter)(Quantity::convert(gtk_adjustment_get_value(adj), unit, "px")); @@ -244,7 +244,7 @@ static void sp_rect_toolbox_selection_changed(Inkscape::Selection *selection, GO purge_repr_listener( tbl, tbl ); std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ if (SP_IS_RECT(*i)) { n_selected++; item = *i; diff --git a/src/widgets/sp-xmlview-attr-list.cpp b/src/widgets/sp-xmlview-attr-list.cpp index dd763aea5..a4c00db7c 100644 --- a/src/widgets/sp-xmlview-attr-list.cpp +++ b/src/widgets/sp-xmlview-attr-list.cpp @@ -145,6 +145,7 @@ void sp_xmlview_attr_list_select_row_by_key(SPXMLViewAttrList * list, const gcha break; } valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(list->store), &iter); + // cppcheck-suppress nullPointer // a string was copied in n by gtk_tree_model_get if (n) { g_free(n); } @@ -181,6 +182,7 @@ event_attr_changed (Inkscape::XML::Node * /*repr*/, } row++; valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(list->store), &iter); + // cppcheck-suppress nullPointer // a string was copied in n by gtk_tree_model_get if (n) { g_free(n); } diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp index 751a60f06..7e7398091 100644 --- a/src/widgets/spiral-toolbar.cpp +++ b/src/widgets/spiral-toolbar.cpp @@ -80,7 +80,7 @@ static void sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustr bool modmade = false; std::vector<SPItem*> itemlist=desktop->getSelection()->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ SPItem *item = *i; if (SP_IS_SPIRAL(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -196,7 +196,7 @@ static void sp_spiral_toolbox_selection_changed(Inkscape::Selection *selection, purge_repr_listener( tbl, tbl ); std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ SPItem *item = *i; if (SP_IS_SPIRAL(item)) { n_selected++; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 183814b7e..1774ba418 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -15,10 +15,11 @@ * Tavmjong Bah <tavmjong@free.fr> * Abhishek Sharma * Kris De Gussem <Kris.DeGussem@gmail.com> + * Jabiertxo Arraiza <jabier.arraiza@marker.es> * * Copyright (C) 2004 David Turner * Copyright (C) 2003 MenTaLguY - * Copyright (C) 1999-2011 authors + * Copyright (C) 1999-2015 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information @@ -28,18 +29,24 @@ # include "config.h" #endif -#include <glibmm/i18n.h> +#include <gtkmm.h> #include "spray-toolbar.h" #include "desktop.h" +#include "inkscape.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" #include "widgets/ege-select-one-action.h" #include "widgets/ink-action.h" #include "preferences.h" #include "toolbox.h" +#include "ui/dialog/clonetiler.h" +#include "ui/dialog/dialog-manager.h" +#include "ui/dialog/panel-dialog.h" #include "ui/icon-names.h" +#include <glibmm/i18n.h> + using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; using Inkscape::UI::PrefPusher; @@ -53,6 +60,74 @@ using Inkscape::UI::PrefPusher; //## Spray ## //######################## +static void sp_stb_sensitivize( GObject *tbl ) +{ + GtkAction* offset = GTK_ACTION( g_object_get_data(tbl, "offset") ); + GtkAction* spray_scale = GTK_ACTION( g_object_get_data(tbl, "spray_scale") ); + GtkAdjustment *adj_offset = ege_adjustment_action_get_adjustment( EGE_ADJUSTMENT_ACTION(offset) ); + GtkAdjustment *adj_scale = ege_adjustment_action_get_adjustment( EGE_ADJUSTMENT_ACTION(spray_scale) ); + GtkToggleAction *no_overlap = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "no_overlap") ); + GtkToggleAction *picker = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "picker") ); + GtkAction* picker_action = GTK_ACTION( g_object_get_data(tbl, "picker") ); + GtkToggleAction *usepressurescale = GTK_TOGGLE_ACTION( g_object_get_data(tbl, "usepressurescale") ); + GtkAction *pick_fill = GTK_ACTION( g_object_get_data(tbl, "pick_fill") ); + GtkAction *pick_stroke = GTK_ACTION( g_object_get_data(tbl, "pick_stroke") ); + GtkAction *pick_inverse_value = GTK_ACTION( g_object_get_data(tbl, "pick_inverse_value") ); + GtkAction *pick_center = GTK_ACTION( g_object_get_data(tbl, "pick_center") ); + gtk_adjustment_set_value( adj_offset, 100.0 ); + if (gtk_toggle_action_get_active(no_overlap) && gtk_action_get_sensitive(picker_action)) { + gtk_action_set_sensitive( offset, TRUE ); + } else { + gtk_action_set_sensitive( offset, FALSE ); + } + if (gtk_toggle_action_get_active(usepressurescale)) { + gtk_adjustment_set_value( adj_scale, 0.0 ); + gtk_action_set_sensitive( spray_scale, FALSE ); + } else { + gtk_action_set_sensitive( spray_scale, TRUE ); + } + if(gtk_toggle_action_get_active(picker) && gtk_action_get_sensitive(picker_action)){ + gtk_action_set_sensitive( pick_fill, TRUE ); + gtk_action_set_sensitive( pick_stroke, TRUE ); + gtk_action_set_sensitive( pick_inverse_value, TRUE ); + gtk_action_set_sensitive( pick_center, TRUE ); + } else { + gtk_action_set_sensitive( pick_fill, FALSE ); + gtk_action_set_sensitive( pick_stroke, FALSE ); + gtk_action_set_sensitive( pick_inverse_value, FALSE ); + gtk_action_set_sensitive( pick_center, FALSE ); + } +} + +static void sp_spray_erase_sensitivize( GObject *tbl, bool sensitive){ + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "no_overlap") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "over_no_transparent") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "over_transparent") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "pick_no_overlap") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "pick_stroke") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "pick_fill") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "pick_inverse_value") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "pick_center") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "picker") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "offset") ), sensitive ); + gtk_action_set_sensitive( GTK_ACTION( g_object_get_data(tbl, "spray_rotation") ), sensitive ); + sp_stb_sensitivize( tbl ); +} + +Inkscape::UI::Dialog::CloneTiler *get_clone_tiler_panel(SPDesktop *desktop) +{ + if (Inkscape::UI::Dialog::PanelDialogBase *panel_dialog = + dynamic_cast<Inkscape::UI::Dialog::PanelDialogBase *>(desktop->_dlg_mgr->getDialog("CloneTiler"))) { + try { + Inkscape::UI::Dialog::CloneTiler &clone_tiler = + dynamic_cast<Inkscape::UI::Dialog::CloneTiler &>(panel_dialog->getPanel()); + return &clone_tiler; + } catch (std::exception &e) { } + } + + return 0; +} + static void sp_spray_width_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -74,11 +149,16 @@ static void sp_spray_standard_deviation_value_changed( GtkAdjustment *adj, GObje gtk_adjustment_get_value(adj)); } -static void sp_spray_mode_changed( EgeSelectOneAction *act, GObject * /*tbl*/ ) +static void sp_spray_mode_changed( EgeSelectOneAction *act, GObject * tbl ) { int mode = ege_select_one_action_get_active( act ); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setInt("/tools/spray/mode", mode); + if(mode != 3){ + sp_spray_erase_sensitivize(tbl, true); + } else { + sp_spray_erase_sensitivize(tbl, false); + } } static void sp_spray_population_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) @@ -102,12 +182,105 @@ static void sp_spray_scale_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ gtk_adjustment_get_value(adj)); } +static void sp_spray_offset_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble( "/tools/spray/offset", + gtk_adjustment_get_value(adj)); +} + +static void sp_toggle_no_overlap( GtkToggleAction* act, gpointer data) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/no_overlap", active); + GObject *tbl = G_OBJECT(data); + sp_stb_sensitivize(tbl); +} + +static void sp_toggle_pressure_scale( GtkToggleAction* act, gpointer data) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/usepressurescale", active); + if(active == true){ + prefs->setDouble("/tools/spray/scale_variation", 0); + } + GObject *tbl = G_OBJECT(data); + sp_stb_sensitivize( tbl ); +} + +static void sp_toggle_over_no_transparent( GtkToggleAction* act, gpointer data) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/over_no_transparent", active); +} + +static void sp_toggle_over_transparent( GtkToggleAction* act, gpointer data) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/over_transparent", active); +} + + +static void sp_toggle_picker( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/picker", active); + if(active == true){ + prefs->setBool("/dialogs/clonetiler/dotrace", false); + SPDesktop *dt = SP_ACTIVE_DESKTOP; + if (Inkscape::UI::Dialog::CloneTiler *ct = get_clone_tiler_panel(dt)){ + dt->_dlg_mgr->showDialog("CloneTiler"); + ct->show_page_trace(); + } + } + GObject *tbl = G_OBJECT(data); + sp_stb_sensitivize(tbl); +} + +static void sp_toggle_pick_center( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/pick_center", active); +} + +static void sp_toggle_pick_fill( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/pick_fill", active); +} + +static void sp_toggle_pick_stroke( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/pick_stroke", active); +} + +static void sp_toggle_pick_no_overlap( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/pick_no_overlap", active); +} + +static void sp_toggle_pick_inverse_value( GtkToggleAction* act, gpointer data ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + gboolean active = gtk_toggle_action_get_active(act); + prefs->setBool("/tools/spray/pick_inverse_value", active); +} void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - { /* Width */ gchar const* labels[] = {_("(narrow spray)"), 0, 0, 0, _("(default)"), 0, 0, 0, 0, _("(broad spray)")}; @@ -123,7 +296,20 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); } + + /* Use Pressure Width button */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayPressureWidthAction", + _("Pressure"), + _("Use the pressure of the input device to alter the width of spray area"), + INKSCAPE_ICON("draw-use-pressure"), + Inkscape::ICON_SIZE_DECORATION ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/spray/usepressurewidth"); + g_signal_connect(holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); + } + { /* Mean */ gchar const* labels[] = {_("(default)"), 0, 0, 0, 0, 0, 0, _("(maximum mean)")}; @@ -158,7 +344,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj /* Mode */ { - GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING ); + GtkListStore* model = gtk_list_store_new( 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING ); GtkTreeIter iter; gtk_list_store_append( model, &iter ); @@ -174,6 +360,7 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj 1, _("Spray clones of the initial selection"), 2, INKSCAPE_ICON("spray-mode-clone"), -1 ); + #ifdef ENABLE_SPRAY_MODE_SINGLE_PATH gtk_list_store_append( model, &iter ); gtk_list_store_set( model, &iter, @@ -182,6 +369,14 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj 2, INKSCAPE_ICON("spray-mode-union"), -1 ); #endif + + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("Delete sprayed items"), + 1, _("Delete sprayed items from selection"), + 2, INKSCAPE_ICON("draw-eraser"), + -1 ); + EgeSelectOneAction* act = ege_select_one_action_new( "SprayModeAction", _("Mode"), (""), NULL, GTK_TREE_MODEL(model) ); g_object_set( act, "short_label", _("Mode:"), NULL ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); @@ -218,15 +413,15 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj g_object_set_data( holder, "spray_population", eact ); } - /* Use Pressure button */ + /* Use Pressure Population button */ { - InkToggleAction* act = ink_toggle_action_new( "SprayPressureAction", + InkToggleAction* act = ink_toggle_action_new( "SprayPressurePopulationAction", _("Pressure"), _("Use the pressure of the input device to alter the amount of sprayed objects"), INKSCAPE_ICON("draw-use-pressure"), Inkscape::ICON_SIZE_DECORATION ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); - PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/spray/usepressure"); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/spray/usepressurepopulation"); g_signal_connect(holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); } @@ -267,8 +462,152 @@ void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj g_object_set_data( holder, "spray_scale", eact ); } + /* Use Pressure Scale button */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayPressureScaleAction", + _("Pressure"), + _("Use the pressure of the input device to alter the scale of new items"), + INKSCAPE_ICON("draw-use-pressure"), + Inkscape::ICON_SIZE_DECORATION); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/usepressurescale", false) ); + g_object_set_data( holder, "usepressurescale", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pressure_scale), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Picker */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayPickColorAction", + _("Pick color from the drawing. You can use clonetiler trace dialog for avanced effects. In clone mode original fill or stroke colors must be unset."), + _("Pick color from the drawing. You can use clonetiler trace dialog for avanced effects. In clone mode original fill or stroke colors must be unset."), + INKSCAPE_ICON("color-picker"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/picker", false) ); + g_object_set_data( holder, "picker", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_picker), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Pick from center */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayPickCenterAction", + _("Pick from center instead average area."), + _("Pick from center instead average area."), + INKSCAPE_ICON("snap-bounding-box-center"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pick_center", true) ); + g_object_set_data( holder, "pick_center", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_center), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Inverse Value Size */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayPickInverseValueAction", + _("Inversed pick value, retaining color in advanced trace mode"), + _("Inversed pick value, retaining color in advanced trace mode"), + INKSCAPE_ICON("object-tweak-shrink"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pick_inverse_value", false) ); + g_object_set_data( holder, "pick_inverse_value", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_inverse_value), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Pick Fill */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayPickFillAction", + _("Apply picked color to fill"), + _("Apply picked color to fill"), + INKSCAPE_ICON("paint-solid"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pick_fill", false) ); + g_object_set_data( holder, "pick_fill", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_fill), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + /* Pick Stroke */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayPickStrokeAction", + _("Apply picked color to stroke"), + _("Apply picked color to stroke"), + INKSCAPE_ICON("no-marker"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pick_stroke", false) ); + g_object_set_data( holder, "pick_stroke", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_stroke), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Pick No Overlap */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayPickNoOverlapAction", + _("No overlap between colors"), + _("No overlap between colors"), + INKSCAPE_ICON("symbol-bigger"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/pick_no_overlap", false) ); + g_object_set_data( holder, "pick_no_overlap", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_pick_no_overlap), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + /* Over Transparent */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayOverTransparentAction", + _("Apply over transparent areas"), + _("Apply over transparent areas"), + INKSCAPE_ICON("object-hidden"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/over_transparent", true) ); + g_object_set_data( holder, "over_transparent", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_over_transparent), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Over No Transparent */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayOverNoTransparentAction", + _("Apply over no transparent areas"), + _("Apply over no transparent areas"), + INKSCAPE_ICON("object-visible"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/over_no_transparent", true) ); + g_object_set_data( holder, "over_no_transparent", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_over_no_transparent), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Overlap */ + { + InkToggleAction* act = ink_toggle_action_new( "SprayNoOverlapAction", + _("Prevent overlapping objects"), + _("Prevent overlapping objects"), + INKSCAPE_ICON("distribute-randomize"), + secondarySize ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/spray/no_overlap", false) ); + g_object_set_data( holder, "no_overlap", act ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_toggle_no_overlap), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + } + + /* Offset */ + { + gchar const* labels[] = {_("(minimum offset)"), 0, 0, 0, _("(default)"), 0, 0, _("(maximum offset)")}; + gdouble values[] = {0, 25, 50, 75, 100, 150, 200, 1000}; + EgeAdjustmentAction *eact = create_adjustment_action( "SprayToolOffsetAction", + _("Offset %"), _("Offset %:"), + _("Increase to segregate objects more (value in percent)"), + "/tools/spray/offset", 100, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, + 0, 1000, 1, 4, + labels, values, G_N_ELEMENTS(labels), + sp_spray_offset_value_changed, NULL, 0 , 0); + g_object_set_data( holder, "offset", eact ); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + } + sp_spray_erase_sensitivize(holder, prefs->getInt("/tools/spray/mode") != 3); } diff --git a/src/widgets/spray-toolbar.h b/src/widgets/spray-toolbar.h index d1d5c7b4c..30d8233ca 100644 --- a/src/widgets/spray-toolbar.h +++ b/src/widgets/spray-toolbar.h @@ -21,7 +21,7 @@ * * Copyright (C) 2004 David Turner * Copyright (C) 2003 MenTaLguY - * Copyright (C) 1999-2011 authors + * Copyright (C) 1999-2015 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index 96005d7df..741fd38ad 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -84,7 +84,7 @@ static void sp_stb_magnitude_value_changed( GtkAdjustment *adj, GObject *dataKlu Inkscape::Selection *selection = desktop->getSelection(); std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -129,7 +129,7 @@ static void sp_stb_proportion_value_changed( GtkAdjustment *adj, GObject *dataKl bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -186,7 +186,7 @@ static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *d } std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -225,7 +225,7 @@ static void sp_stb_rounded_value_changed( GtkAdjustment *adj, GObject *dataKludg Inkscape::Selection *selection = desktop->getSelection(); std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -265,7 +265,7 @@ static void sp_stb_randomized_value_changed( GtkAdjustment *adj, GObject *dataKl Inkscape::Selection *selection = desktop->getSelection(); std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { Inkscape::XML::Node *repr = item->getRepr(); @@ -368,7 +368,7 @@ sp_star_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) purge_repr_listener( tbl, tbl ); std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { n_selected++; diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index d05b3b994..43dffec56 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -480,7 +480,7 @@ void StrokeStyle::markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, Inkscape::Selection *selection = spw->desktop->getSelection(); std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (!SP_IS_SHAPE(item) || SP_IS_RECT(item)) { // can't set marker to rect, until it's converted to using <path> continue; @@ -981,7 +981,7 @@ StrokeStyle::scaleLine() int ndash; dashSelector->get_dash(&ndash, &dash, &offset); - for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){ + for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){ /* Set stroke width */ double width; if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { @@ -1156,7 +1156,7 @@ StrokeStyle::updateAllMarkers(std::vector<SPItem*> const &objects) }; bool all_texts = true; - for(std::vector<SPItem*>::const_iterator i=objects.begin();i!=objects.end();i++){ + for(std::vector<SPItem*>::const_iterator i=objects.begin();i!=objects.end();++i){ if (!SP_IS_TEXT (*i)) { all_texts = false; break; diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 7b22e4af7..c49fbccaa 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -155,7 +155,7 @@ static void sp_text_fontfamily_value_changed( Ink_ComboBoxEntry_Action *act, GOb act->active = 0; // New family is always at top of list. } - std::pair<Glib::ustring,Glib::ustring> ui = fontlister->set_font_family( act->active ); + fontlister->set_font_family( act->active ); // active text set in sp_text_toolbox_selection_changed() SPCSSAttr *css = sp_repr_css_attr_new (); @@ -373,7 +373,7 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl ) // move the x of all texts to preserve the same bbox Inkscape::Selection *selection = desktop->getSelection(); std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ if (SP_IS_TEXT(*i)) { SPItem *item = *i; @@ -526,7 +526,7 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl ) Inkscape::Selection *selection = desktop->getSelection(); bool modmade = false; std::vector<SPItem*> itemlist=selection->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ if (SP_IS_TEXT (*i)) { (*i)->getRepr()->setAttribute("sodipodi:linespacing", sp_repr_css_property (css, "line-height", NULL)); modmade = true; @@ -871,7 +871,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // Find out if we have flowed text now so we can use it several places gboolean isFlow = false; std::vector<SPItem*> itemlist=SP_ACTIVE_DESKTOP->getSelection()->itemList(); - for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end();i++){ + for(std::vector<SPItem*>::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ // const gchar* id = reinterpret_cast<SPItem *>(items->data)->getId(); // std::cout << " " << id << std::endl; if( SP_IS_FLOWTEXT(*i)) { @@ -1165,7 +1165,7 @@ static void sp_text_toolbox_select_cb( GtkEntry* entry, GtkEntryIconPosition /*p SPDocument *document = desktop->getDocument(); std::vector<SPItem*> x,y; std::vector<SPItem*> allList = get_all_items(x, document->getRoot(), desktop, false, false, true, y); - for(std::vector<SPItem*>::const_reverse_iterator i=allList.rbegin();i!=allList.rend();i++){ + for(std::vector<SPItem*>::const_reverse_iterator i=allList.rbegin();i!=allList.rend(); ++i){ SPItem *item = *i; SPStyle *style = item->style; diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index a1c32352c..3e79e038a 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -16,10 +16,11 @@ * Tavmjong Bah <tavmjong@free.fr> * Abhishek Sharma * Kris De Gussem <Kris.DeGussem@gmail.com> + * Jabiertxo Arraiza <jabier.arraiza@marker.es> * * Copyright (C) 2004 David Turner * Copyright (C) 2003 MenTaLguY - * Copyright (C) 1999-2011 authors + * Copyright (C) 1999-2015 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information @@ -309,14 +310,28 @@ static gchar const * ui_descr = " <toolitem action='SprayModeAction' />" " <separator />" " <toolitem action='SprayWidthAction' />" + " <toolitem action='SprayPressureWidthAction' />" " <toolitem action='SprayPopulationAction' />" - " <toolitem action='SprayPressureAction' />" + " <toolitem action='SprayPressurePopulationAction' />" " <separator />" " <toolitem action='SprayRotationAction' />" " <toolitem action='SprayScaleAction' />" + " <toolitem action='SprayPressureScaleAction' />" " <separator />" " <toolitem action='SprayStandard_deviationAction' />" " <toolitem action='SprayMeanAction' />" + " <separator />" + " <toolitem action='SprayOverNoTransparentAction' />" + " <toolitem action='SprayOverTransparentAction' />" + " <toolitem action='SprayPickNoOverlapAction' />" + " <toolitem action='SprayNoOverlapAction' />" + " <toolitem action='SprayToolOffsetAction' />" + " <separator />" + " <toolitem action='SprayPickColorAction' />" + " <toolitem action='SprayPickFillAction' />" + " <toolitem action='SprayPickStrokeAction' />" + " <toolitem action='SprayPickInverseValueAction' />" + " <toolitem action='SprayPickCenterAction' />" " </toolbar>" " <toolbar name='ZoomToolbar'>" @@ -339,9 +354,23 @@ static gchar const * ui_descr = " <toolbar name='MeasureToolbar'>" " <toolitem action='MeasureFontSizeAction' />" " <separator />" + " <toolitem action='MeasurePrecisionAction' />" + " <separator />" + " <toolitem action='MeasureScaleAction' />" + " <separator />" + " <toolitem action='MeasureOffsetAction' />" + " <separator />" " <toolitem action='measure_units_label' />" " <toolitem action='MeasureUnitsAction' />" - " </toolbar>" + " <toolitem action='MeasureIgnore1stAndLast' />" + " <toolitem action='MeasureInBettween' />" + " <toolitem action='MeasureOnlyVisible' />" + " <toolitem action='MeasureAllLayers' />" + " <toolitem action='MeasureReverse' />" + " <toolitem action='MeasureToGuides' />" + " <toolitem action='MeasureMarkDimension' />" + " <toolitem action='MeasureToItem' />" + " </toolbar>" " <toolbar name='StarToolbar'>" " <separator />" diff --git a/src/widgets/tweak-toolbar.cpp b/src/widgets/tweak-toolbar.cpp index a5d90fc3d..e2c0daf6e 100644 --- a/src/widgets/tweak-toolbar.cpp +++ b/src/widgets/tweak-toolbar.cpp @@ -288,7 +288,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj NULL, Inkscape::ICON_SIZE_DECORATION ); //TRANSLATORS: "H" here stands for hue - g_object_set( act, "short_label", _("H"), NULL ); + g_object_set( act, "short_label", C_("Hue", "H"), NULL ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_doh), desktop ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/doh", true) ); @@ -304,7 +304,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj NULL, Inkscape::ICON_SIZE_DECORATION ); //TRANSLATORS: "S" here stands for Saturation - g_object_set( act, "short_label", _("S"), NULL ); + g_object_set( act, "short_label", C_("Saturation", "S"), NULL ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_dos), desktop ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/dos", true) ); @@ -320,7 +320,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj NULL, Inkscape::ICON_SIZE_DECORATION ); //TRANSLATORS: "L" here stands for Lightness - g_object_set( act, "short_label", _("L"), NULL ); + g_object_set( act, "short_label", C_("Lightness", "L"), NULL ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_dol), desktop ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/dol", true) ); @@ -336,7 +336,7 @@ void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObj NULL, Inkscape::ICON_SIZE_DECORATION ); //TRANSLATORS: "O" here stands for Opacity - g_object_set( act, "short_label", _("O"), NULL ); + g_object_set( act, "short_label", C_("Opacity", "O"), NULL ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_doo), desktop ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/doo", true) ); |
