diff --git a/src/splivarot.cpp b/src/splivarot.cpp
index 0996ca53812e2a2d9aa61520c86ea2f42faed796..085dfeda0a52595bd027f5c06b3b8a94c423ed10 100644 (file)
--- a/src/splivarot.cpp
+++ b/src/splivarot.cpp
#include "display/canvas-bpath.h"
#include "display/curve.h"
#include <glibmm/i18n.h>
-#include "prefs-utils.h"
+#include "preferences.h"
-#include "libnr/n-art-bpath.h"
-#include "libnr/nr-path.h"
#include "xml/repr.h"
#include "xml/repr-sorting.h"
#include <2geom/pathvector.h>
-#include <libnr/nr-matrix-fns.h>
-#include <libnr/nr-matrix-ops.h>
-#include <libnr/nr-matrix-translate-ops.h>
#include <libnr/nr-scale-matrix-ops.h>
-#include <libnr/n-art-bpath-2geom.h>
#include "helper/geom.h"
#include "livarot/Path.h"
@@ -133,8 +127,8 @@ sp_selected_path_boolop(SPDesktop *desktop, bool_op bop, const unsigned int verb
}
if (g_slist_length(il) > 2) {
- if (bop == bool_op_diff || bop == bool_op_symdiff || bop == bool_op_cut || bop == bool_op_slice ) {
- desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Select <b>exactly 2 paths</b> to perform difference, XOR, division, or path cut."));
+ if (bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice ) {
+ desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Select <b>exactly 2 paths</b> to perform difference, division, or path cut."));
return;
}
}
@@ -144,8 +138,7 @@ sp_selected_path_boolop(SPDesktop *desktop, bool_op bop, const unsigned int verb
// topmost object (differences, cuts)
bool reverseOrderForOp = false;
- // mettre les elements de la liste dans l'ordre pour ces operations
- if (bop == bool_op_diff || bop == bool_op_symdiff || bop == bool_op_cut || bop == bool_op_slice) {
+ if (bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice) {
// check in the tree to find which element of the selection list is topmost (for 2-operand commands only)
Inkscape::XML::Node *a = SP_OBJECT_REPR(il->data);
Inkscape::XML::Node *b = SP_OBJECT_REPR(il->next->data);
@@ -437,7 +430,7 @@ sp_selected_path_boolop(SPDesktop *desktop, bool_op bop, const unsigned int verb
// get the source path object
SPObject *source;
- if ( bop == bool_op_diff || bop == bool_op_symdiff || bop == bool_op_cut || bop == bool_op_slice ) {
+ if ( bop == bool_op_diff || bop == bool_op_cut || bop == bool_op_slice ) {
if (reverseOrderForOp) {
source = SP_OBJECT(il->data);
} else {
@@ -458,11 +451,11 @@ sp_selected_path_boolop(SPDesktop *desktop, bool_op bop, const unsigned int verb
// adjust style properties that depend on a possible transform in the source object in order
// to get a correct style attribute for the new path
SPItem* item_source = SP_ITEM(source);
- NR::Matrix i2root(sp_item_i2root_affine(item_source));
- sp_item_adjust_stroke(item_source, NR::expansion(i2root));
- sp_item_adjust_pattern(item_source, i2root);
- sp_item_adjust_gradient(item_source, i2root);
- sp_item_adjust_livepatheffect(item_source, i2root);
+ Geom::Matrix i2doc(sp_item_i2doc_affine(item_source));
+ sp_item_adjust_stroke(item_source, i2doc.descrim());
+ sp_item_adjust_pattern(item_source, i2doc);
+ sp_item_adjust_gradient(item_source, i2doc);
+ sp_item_adjust_livepatheffect(item_source, i2doc);
Inkscape::XML::Node *repr_source = SP_OBJECT_REPR(source);
@@ -491,7 +484,7 @@ sp_selected_path_boolop(SPDesktop *desktop, bool_op bop, const unsigned int verb
// premultiply by the inverse of parent's repr
SPItem *parent_item = SP_ITEM(sp_desktop_document(desktop)->getObjectByRepr(parent));
- NR::Matrix local (sp_item_i2doc_affine(parent_item));
+ Geom::Matrix local (sp_item_i2doc_affine(parent_item));
gchar *transform = sp_svg_transform_write(local.inverse());
// now that we have the result, add it on the canvas
@@ -607,13 +600,14 @@ sp_selected_path_boolop(SPDesktop *desktop, bool_op bop, const unsigned int verb
}
static
-void sp_selected_path_outline_add_marker( SPObject *marker_object, Geom::Matrix marker_transform, NR::scale stroke_scale, NR::Matrix transform,
- Inkscape::XML::Node *g_repr, Inkscape::XML::Document *xml_doc, SPDocument * doc )
+void sp_selected_path_outline_add_marker( SPObject *marker_object, Geom::Matrix marker_transform,
+ Geom::Scale stroke_scale, Geom::Matrix transform,
+ Inkscape::XML::Node *g_repr, Inkscape::XML::Document *xml_doc, SPDocument * doc )
{
SPMarker* marker = SP_MARKER (marker_object);
SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (marker_object));
- NR::Matrix tr(marker_transform);
+ Geom::Matrix tr(marker_transform);
if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
tr = stroke_scale * tr;
sp_repr_css_unset_property(ncss, "marker-end");
}
- NR::Matrix const transform(item->transform);
- float const scale = NR::expansion(transform);
+ Geom::Matrix const transform(item->transform);
+ float const scale = transform.descrim();
gchar const *mask = SP_OBJECT_REPR(item)->attribute("mask");
gchar const *clip_path = SP_OBJECT_REPR(item)->attribute("clip-path");
SPShape *shape = SP_SHAPE(item);
Geom::PathVector const & pathv = curve->get_pathvector();
- for(Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) {
- if ( SPObject *marker_obj = shape->marker[SP_MARKER_LOC_START] ) {
- Geom::Matrix const m (sp_shape_marker_get_transform_at_start(path_it->front()));
+
+ // START marker
+ for (int i = 0; i < 2; i++) { // SP_MARKER_LOC and SP_MARKER_LOC_START
+ if ( SPObject *marker_obj = shape->marker[i] ) {
+ Geom::Matrix const m (sp_shape_marker_get_transform_at_start(pathv.front().front()));
sp_selected_path_outline_add_marker( marker_obj, m,
- NR::scale(i_style->stroke_width.computed), transform,
+ Geom::Scale(i_style->stroke_width.computed), transform,
g_repr, xml_doc, doc );
}
-
- SPObject *midmarker_obj = shape->marker[SP_MARKER_LOC_MID];
- if ( midmarker_obj && (path_it->size_default() > 1) ) {
- Geom::Path::const_iterator curve_it1 = path_it->begin(); // incoming curve
- Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); // outgoing curve
- while (curve_it2 != path_it->end_default())
+ }
+ // MID marker
+ for (int i = 0; i < 3; i += 2) { // SP_MARKER_LOC and SP_MARKER_LOC_MID
+ SPObject *midmarker_obj = shape->marker[i];
+ if (!midmarker_obj) continue;
+ for(Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) {
+ // START position
+ if ( path_it != pathv.begin()
+ && ! ((path_it == (pathv.end()-1)) && (path_it->size_default() == 0)) ) // if this is the last path and it is a moveto-only, there is no mid marker there
{
- /* Put marker between curve_it1 and curve_it2.
- * Loop to end_default (so including closing segment), because when a path is closed,
- * there should be a midpoint marker between last segment and closing straight line segment
- */
- Geom::Matrix const m (sp_shape_marker_get_transform(*curve_it1, *curve_it2));
+ Geom::Matrix const m (sp_shape_marker_get_transform_at_start(path_it->front()));
sp_selected_path_outline_add_marker( midmarker_obj, m,
- NR::scale(i_style->stroke_width.computed), transform,
+ Geom::Scale(i_style->stroke_width.computed), transform,
+ g_repr, xml_doc, doc );
+ }
+ // MID position
+ if (path_it->size_default() > 1) {
+ Geom::Path::const_iterator curve_it1 = path_it->begin(); // incoming curve
+ Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); // outgoing curve
+ while (curve_it2 != path_it->end_default())
+ {
+ /* Put marker between curve_it1 and curve_it2.
+ * Loop to end_default (so including closing segment), because when a path is closed,
+ * there should be a midpoint marker between last segment and closing straight line segment
+ */
+ Geom::Matrix const m (sp_shape_marker_get_transform(*curve_it1, *curve_it2));
+ sp_selected_path_outline_add_marker(midmarker_obj, m,
+ Geom::Scale(i_style->stroke_width.computed), transform,
+ g_repr, xml_doc, doc);
+
+ ++curve_it1;
+ ++curve_it2;
+ }
+ }
+ // END position
+ if ( path_it != (pathv.end()-1) && !path_it->empty()) {
+ Geom::Curve const &lastcurve = path_it->back_default();
+ Geom::Matrix const m = sp_shape_marker_get_transform_at_end(lastcurve);
+ sp_selected_path_outline_add_marker( midmarker_obj, m,
+ Geom::Scale(i_style->stroke_width.computed), transform,
g_repr, xml_doc, doc );
-
- ++curve_it1;
- ++curve_it2;
}
}
-
- if ( SPObject *marker_obj = shape->marker[SP_MARKER_LOC_END] ) {
+ }
+ // END marker
+ for (int i = 0; i < 4; i += 3) { // SP_MARKER_LOC and SP_MARKER_LOC_END
+ if ( SPObject *marker_obj = shape->marker[i] ) {
/* Get reference to last curve in the path.
* For moveto-only path, this returns the "closing line segment". */
- unsigned int index = path_it->size_default();
+ Geom::Path const &path_last = pathv.back();
+ unsigned int index = path_last.size_default();
if (index > 0) {
index--;
}
- Geom::Curve const &lastcurve = (*path_it)[index];
+ Geom::Curve const &lastcurve = path_last[index];
Geom::Matrix const m = sp_shape_marker_get_transform_at_end(lastcurve);
sp_selected_path_outline_add_marker( marker_obj, m,
- NR::scale(i_style->stroke_width.computed), transform,
+ Geom::Scale(i_style->stroke_width.computed), transform,
g_repr, xml_doc, doc );
}
}
void
sp_selected_path_offset(SPDesktop *desktop)
{
- double prefOffset = prefs_get_double_attribute("options.defaultoffsetwidth", "value", 1.0);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ double prefOffset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0);
sp_selected_path_do_offset(desktop, true, prefOffset);
}
void
sp_selected_path_inset(SPDesktop *desktop)
{
- double prefOffset = prefs_get_double_attribute("options.defaultoffsetwidth", "value", 1.0);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ double prefOffset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0);
sp_selected_path_do_offset(desktop, false, prefOffset);
}
@@ -1051,9 +1075,9 @@ sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updat
return;
}
- NR::Matrix const transform(item->transform);
+ Geom::Matrix const transform(item->transform);
- sp_item_write_transform(item, SP_OBJECT_REPR(item), NR::identity());
+ sp_item_write_transform(item, SP_OBJECT_REPR(item), Geom::identity());
style = g_strdup(SP_OBJECT(item)->repr->attribute("style"));
@@ -1095,9 +1119,8 @@ sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updat
}
{
- double prefOffset = 1.0;
- prefOffset = prefs_get_double_attribute("options.defaultoffsetwidth", "value", prefOffset);
- o_width = prefOffset;
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ o_width = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0);
}
if (o_width < 0.01)
@@ -1277,9 +1300,9 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset)
continue;
}
- NR::Matrix const transform(item->transform);
+ Geom::Matrix const transform(item->transform);
- sp_item_write_transform(item, SP_OBJECT_REPR(item), NR::identity());
+ sp_item_write_transform(item, SP_OBJECT_REPR(item), Geom::identity());
gchar *style = g_strdup(SP_OBJECT_REPR(item)->attribute("style"));
return false;
}
+ // correct virtual size by full transform (bug #166937)
+ size /= sp_item_i2doc_affine(item).descrim();
+
// save the transform, to re-apply it after simplification
- NR::Matrix const transform(item->transform);
+ Geom::Matrix const transform(item->transform);
/*
reset the transform, effectively transforming the item by transform.inverse();
this is necessary so that the item is transformed twice back and forth,
allowing all compensations to cancel out regardless of the preferences
*/
- sp_item_write_transform(item, SP_OBJECT_REPR(item), NR::identity());
+ sp_item_write_transform(item, SP_OBJECT_REPR(item), Geom::identity());
gchar *style = g_strdup(SP_OBJECT_REPR(item)->attribute("style"));
gchar *mask = g_strdup(SP_OBJECT_REPR(item)->attribute("mask"));
g_free(clip_path);
}
+ // restore path effect
+ repr->setAttribute("inkscape:path-effect", patheffect);
+
// path
gchar *str = orig->svg_dump_path();
if (patheffect)
// reapply the transform
sp_item_write_transform(newitem, repr, transform);
- // restore path effect
- repr->setAttribute("inkscape:path-effect", patheffect);
-
// restore title & description
if (title) {
newitem->setTitle(title);
float angleLimit, bool breakableAngles,
bool modifySelection)
{
- bool simplifyIndividualPaths =
- (bool) prefs_get_int_attribute("options.simplifyindividualpaths", "value", 0);
-
- gchar *simplificationType;
- if (simplifyIndividualPaths) {
- simplificationType = _("Simplifying paths (separately):");
- } else {
- simplificationType = _("Simplifying paths:");
- }
-
- bool didSomething = false;
-
- boost::optional<NR::Rect> selectionBbox = selection->bounds();
- if (!selectionBbox) {
- return false;
- }
- gdouble selectionSize = L2(selectionBbox->dimensions());
-
- gdouble simplifySize = selectionSize;
-
- int pathsSimplified = 0;
- int totalPathCount = g_slist_length(items);
-
- // set "busy" cursor
- desktop->setWaitingCursor();
-
- for (; items != NULL; items = items->next) {
- SPItem *item = (SPItem *) items->data;
-
- if (!(SP_IS_GROUP(item) || SP_IS_SHAPE(item) || SP_IS_TEXT(item)))
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ bool simplifyIndividualPaths = prefs->getBool("/options/simplifyindividualpaths/value");
+
+ gchar *simplificationType;
+ if (simplifyIndividualPaths) {
+ simplificationType = _("Simplifying paths (separately):");
+ } else {
+ simplificationType = _("Simplifying paths:");
+ }
+
+ bool didSomething = false;
+
+ Geom::OptRect selectionBbox = selection->bounds();
+ if (!selectionBbox) {
+ return false;
+ }
+ gdouble selectionSize = L2(selectionBbox->dimensions());
+
+ gdouble simplifySize = selectionSize;
+
+ int pathsSimplified = 0;
+ int totalPathCount = g_slist_length(items);
+
+ // set "busy" cursor
+ desktop->setWaitingCursor();
+
+ for (; items != NULL; items = items->next) {
+ SPItem *item = (SPItem *) items->data;
+
+ if (!(SP_IS_GROUP(item) || SP_IS_SHAPE(item) || SP_IS_TEXT(item)))
continue;
- if (simplifyIndividualPaths) {
- boost::optional<NR::Rect> itemBbox = item->getBounds(sp_item_i2d_affine(item));
- if (itemBbox) {
- simplifySize = L2(itemBbox->dimensions());
- } else {
- simplifySize = 0;
- }
- }
-
- pathsSimplified++;
-
- if (pathsSimplified % 20 == 0) {
- gchar *message = g_strdup_printf(_("%s <b>%d</b> of <b>%d</b> paths simplified..."), simplificationType, pathsSimplified, totalPathCount);
- desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, message);
- }
-
- didSomething |= sp_selected_path_simplify_item(desktop, selection, item,
- threshold, justCoalesce, angleLimit, breakableAngles, simplifySize, modifySelection);
- }
-
- desktop->clearWaitingCursor();
-
- if (pathsSimplified > 20) {
- desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, g_strdup_printf(_("<b>%d</b> paths simplified."), pathsSimplified));
- }
-
- return didSomething;
+ if (simplifyIndividualPaths) {
+ Geom::OptRect itemBbox = item->getBounds(sp_item_i2d_affine(item));
+ if (itemBbox) {
+ simplifySize = L2(itemBbox->dimensions());
+ } else {
+ simplifySize = 0;
+ }
+ }
+
+ pathsSimplified++;
+
+ if (pathsSimplified % 20 == 0) {
+ gchar *message = g_strdup_printf(_("%s <b>%d</b> of <b>%d</b> paths simplified..."),
+ simplificationType, pathsSimplified, totalPathCount);
+ desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, message);
+ }
+
+ didSomething |= sp_selected_path_simplify_item(desktop, selection, item,
+ threshold, justCoalesce, angleLimit, breakableAngles, simplifySize, modifySelection);
+ }
+
+ desktop->clearWaitingCursor();
+
+ if (pathsSimplified > 20) {
+ desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, g_strdup_printf(_("<b>%d</b> paths simplified."), pathsSimplified));
+ }
+
+ return didSomething;
}
void
void
sp_selected_path_simplify(SPDesktop *desktop)
{
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
gdouble simplifyThreshold =
- prefs_get_double_attribute("options.simplifythreshold", "value", 0.003);
- bool simplifyJustCoalesce =
- (bool) prefs_get_int_attribute("options.simplifyjustcoalesce", "value", 0);
+ prefs->getDouble("/options/simplifythreshold/value", 0.003);
+ bool simplifyJustCoalesce = prefs->getBool("/options/simplifyjustcoalesce/value", 0);
//Get the current time
GTimeVal currentTimeVal;
return curve; // do not forget to unref the curve at some point!
}
-Path *bpath_to_Path(NArtBpath const *bpath)
-{
- Path *dest = new Path;
- dest->SetBackData(false);
- {
- int i;
- bool closed = false;
- float lastX = 0.0;
- float lastY = 0.0;
-
- for (i = 0; bpath[i].code != NR_END; i++) {
- switch (bpath[i].code) {
- case NR_LINETO:
- lastX = bpath[i].x3;
- lastY = bpath[i].y3;
- {
- NR::Point tmp(lastX, lastY);
- dest->LineTo(tmp);
- }
- break;
-
- case NR_CURVETO:
- {
- NR::Point tmp, tms, tme;
- tmp[0]=bpath[i].x3;
- tmp[1]=bpath[i].y3;
- tms[0]=3 * (bpath[i].x1 - lastX);
- tms[1]=3 * (bpath[i].y1 - lastY);
- tme[0]=3 * (bpath[i].x3 - bpath[i].x2);
- tme[1]=3 * (bpath[i].y3 - bpath[i].y2);
- dest->CubicTo(tmp,tms,tme);
- }
- lastX = bpath[i].x3;
- lastY = bpath[i].y3;
- break;
-
- case NR_MOVETO_OPEN:
- case NR_MOVETO:
- if (closed)
- dest->Close();
- closed = (bpath[i].code == NR_MOVETO);
- lastX = bpath[i].x3;
- lastY = bpath[i].y3;
- {
- NR::Point tmp(lastX, lastY);
- dest->MoveTo(tmp);
- }
- break;
- default:
- break;
- }
- }
- if (closed)
- dest->Close();
- }
- return dest;
-}
-
-boost::optional<Path::cut_position> get_nearest_position_on_Path(Path *path, NR::Point p, unsigned seg)
+boost::optional<Path::cut_position> get_nearest_position_on_Path(Path *path, Geom::Point p, unsigned seg)
{
//get nearest position on path
Path::cut_position pos = path->PointToCurvilignPosition(p, seg);
return pos;
}
-NR::Point get_point_on_Path(Path *path, int piece, double t)
+Geom::Point get_point_on_Path(Path *path, int piece, double t)
{
- NR::Point p;
+ Geom::Point p;
path->PointAt(piece, t, p);
return p;
}