summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 09ff61b)
raw | patch | inline | side by side (parent: 09ff61b)
author | Johan Engelen <goejendaagh@zonnet.nl> | |
Sat, 10 Apr 2010 15:21:01 +0000 (17:21 +0200) | ||
committer | Johan Engelen <goejendaagh@zonnet.nl> | |
Sat, 10 Apr 2010 15:21:01 +0000 (17:21 +0200) |
* increasing boundingbox calculation precision for selection to marker, selection to pattern and fit canvas to selection
src/selection-chemistry.cpp | patch | blob | history | |
src/sp-shape.cpp | patch | blob | history | |
src/splivarot.cpp | patch | blob | history | |
src/splivarot.h | patch | blob | history |
index 730467ee548bd90479e73f974addfe32c101eb49..cc153aa71719ba965e57a88b27d31b59c88b8a1a 100644 (file)
}
sp_document_ensure_up_to_date(doc);
- Geom::OptRect r = selection->bounds();
+ Geom::OptRect r = selection->bounds(SPItem::RENDERING_BBOX);
boost::optional<Geom::Point> c = selection->center();
if ( !r || !c ) {
return;
}
sp_document_ensure_up_to_date(doc);
- Geom::OptRect r = selection->bounds();
+ Geom::OptRect r = selection->bounds(SPItem::RENDERING_BBOX);
if ( !r ) {
return;
}
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to fit canvas to."));
return false;
}
- Geom::OptRect const bbox(desktop->selection->bounds());
+ Geom::OptRect const bbox(desktop->selection->bounds(SPItem::RENDERING_BBOX));
if (bbox) {
doc->fitToRect(*bbox, with_margins);
return true;
diff --git a/src/sp-shape.cpp b/src/sp-shape.cpp
index de564813720785f7671fb1a8b66885bfc7b07a3a..dadcb5f57d522e72ec9f10f8b7da0d9fd3d8ddec 100644 (file)
--- a/src/sp-shape.cpp
+++ b/src/sp-shape.cpp
#include "util/mathfns.h" // for triangle_area()
+#include "splivarot.h" // for bounding box calculation
+
#define noSHAPE_VERBOSE
static void sp_shape_class_init (SPShapeClass *klass);
@@ -541,166 +543,193 @@ static void sp_shape_bbox(SPItem const *item, NRRect *bbox, Geom::Matrix const &
cbbox.x1 = (*geombbox)[0][1];
cbbox.y1 = (*geombbox)[1][1];
- if ((SPItem::BBoxType) flags != SPItem::GEOMETRIC_BBOX) {
-
- SPStyle* style=SP_OBJECT_STYLE (item);
- if (!style->stroke.isNone()) {
- double const scale = transform.descrim();
- if ( fabs(style->stroke_width.computed * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord
- double const width = MAX(0.125, style->stroke_width.computed * scale);
- if ( fabs(cbbox.x1-cbbox.x0) > -0.00001 && fabs(cbbox.y1-cbbox.y0) > -0.00001 ) {
- cbbox.x0-=0.5*width;
- cbbox.x1+=0.5*width;
- cbbox.y0-=0.5*width;
- cbbox.y1+=0.5*width;
+ switch ((SPItem::BBoxType) flags) {
+ case SPItem::GEOMETRIC_BBOX: {
+ // do nothing
+ break;
+ }
+ case SPItem::RENDERING_BBOX: {
+ // convert the stroke to a path and calculate that path's geometric bbox
+ SPStyle* style=SP_OBJECT_STYLE (item);
+ if (!style->stroke.isNone()) {
+ Geom::PathVector *pathv = item_outline(item);
+ if (pathv) {
+ Geom::OptRect geomstrokebbox = bounds_exact_transformed(*pathv, transform);
+ if (geomstrokebbox) {
+ NRRect strokebbox;
+ strokebbox.x0 = (*geomstrokebbox)[0][0];
+ strokebbox.y0 = (*geomstrokebbox)[1][0];
+ strokebbox.x1 = (*geomstrokebbox)[0][1];
+ strokebbox.y1 = (*geomstrokebbox)[1][1];
+ nr_rect_d_union (&cbbox, &cbbox, &strokebbox);
+ }
+ delete pathv;
}
}
+ break;
}
-
- // Union with bboxes of the markers, if any
- if (sp_shape_has_markers (shape)) {
- /** \todo make code prettier! */
- Geom::PathVector const & pathv = shape->curve->get_pathvector();
- // START marker
- for (unsigned i = 0; i < 2; i++) { // SP_MARKER_LOC and SP_MARKER_LOC_START
- if ( shape->marker[i] ) {
- SPMarker* marker = SP_MARKER (shape->marker[i]);
- SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (marker));
-
- if (marker_item) {
- Geom::Matrix tr(sp_shape_marker_get_transform_at_start(pathv.begin()->front()));
- if (!marker->orient_auto) {
- Geom::Point transl = tr.translation();
- tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
- }
- if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
- tr = Geom::Scale(style->stroke_width.computed) * tr;
- }
-
- // total marker transform
- tr = marker_item->transform * marker->c2p * tr * transform;
-
- // get bbox of the marker with that transform
- NRRect marker_bbox;
- sp_item_invoke_bbox (marker_item, &marker_bbox, from_2geom(tr), true);
- // union it with the shape bbox
- nr_rect_d_union (&cbbox, &cbbox, &marker_bbox);
+ default:
+ case SPItem::APPROXIMATE_BBOX: {
+ SPStyle* style=SP_OBJECT_STYLE (item);
+ if (!style->stroke.isNone()) {
+ double const scale = transform.descrim();
+ if ( fabs(style->stroke_width.computed * scale) > 0.01 ) { // sinon c'est 0=oon veut pas de bord
+ double const width = MAX(0.125, style->stroke_width.computed * scale);
+ if ( fabs(cbbox.x1-cbbox.x0) > -0.00001 && fabs(cbbox.y1-cbbox.y0) > -0.00001 ) {
+ cbbox.x0-=0.5*width;
+ cbbox.x1+=0.5*width;
+ cbbox.y0-=0.5*width;
+ cbbox.y1+=0.5*width;
}
}
}
- // MID marker
- for (unsigned i = 0; i < 3; i += 2) { // SP_MARKER_LOC and SP_MARKER_LOC_MID
- SPMarker* marker = SP_MARKER (shape->marker[i]);
- if ( !shape->marker[i] ) continue;
- SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (marker));
- if ( !marker_item ) 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
- {
- Geom::Matrix tr(sp_shape_marker_get_transform_at_start(path_it->front()));
- if (!marker->orient_auto) {
- Geom::Point transl = tr.translation();
- tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
- }
- if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
- tr = Geom::Scale(style->stroke_width.computed) * tr;
- }
- tr = marker_item->transform * marker->c2p * tr * transform;
- NRRect marker_bbox;
- sp_item_invoke_bbox (marker_item, &marker_bbox, from_2geom(tr), true);
- nr_rect_d_union (&cbbox, &cbbox, &marker_bbox);
- }
- // 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 */
-
- SPMarker* marker = SP_MARKER (shape->marker[i]);
- SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (marker));
-
- if (marker_item) {
- Geom::Matrix tr(sp_shape_marker_get_transform(*curve_it1, *curve_it2));
- if (!marker->orient_auto) {
- Geom::Point transl = tr.translation();
- tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
- }
- if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
- tr = Geom::Scale(style->stroke_width.computed) * tr;
- }
- tr = marker_item->transform * marker->c2p * tr * transform;
- NRRect marker_bbox;
- sp_item_invoke_bbox (marker_item, &marker_bbox, from_2geom(tr), true);
- nr_rect_d_union (&cbbox, &cbbox, &marker_bbox);
+
+ // Union with bboxes of the markers, if any
+ if (sp_shape_has_markers (shape)) {
+ /** \todo make code prettier! */
+ Geom::PathVector const & pathv = shape->curve->get_pathvector();
+ // START marker
+ for (unsigned i = 0; i < 2; i++) { // SP_MARKER_LOC and SP_MARKER_LOC_START
+ if ( shape->marker[i] ) {
+ SPMarker* marker = SP_MARKER (shape->marker[i]);
+ SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (marker));
+
+ if (marker_item) {
+ Geom::Matrix tr(sp_shape_marker_get_transform_at_start(pathv.begin()->front()));
+ if (!marker->orient_auto) {
+ Geom::Point transl = tr.translation();
+ tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
+ }
+ if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
+ tr = Geom::Scale(style->stroke_width.computed) * tr;
}
- ++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 tr = sp_shape_marker_get_transform_at_end(lastcurve);
- if (!marker->orient_auto) {
- Geom::Point transl = tr.translation();
- tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
- }
- if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
- tr = Geom::Scale(style->stroke_width.computed) * tr;
+ // total marker transform
+ tr = marker_item->transform * marker->c2p * tr * transform;
+
+ // get bbox of the marker with that transform
+ NRRect marker_bbox;
+ sp_item_invoke_bbox (marker_item, &marker_bbox, from_2geom(tr), true);
+ // union it with the shape bbox
+ nr_rect_d_union (&cbbox, &cbbox, &marker_bbox);
}
- tr = marker_item->transform * marker->c2p * tr * transform;
- NRRect marker_bbox;
- sp_item_invoke_bbox (marker_item, &marker_bbox, tr, true);
- nr_rect_d_union (&cbbox, &cbbox, &marker_bbox);
}
}
- }
- // END marker
- for (unsigned i = 0; i < 4; i += 3) { // SP_MARKER_LOC and SP_MARKER_LOC_END
- if ( shape->marker[i] ) {
+ // MID marker
+ for (unsigned i = 0; i < 3; i += 2) { // SP_MARKER_LOC and SP_MARKER_LOC_MID
SPMarker* marker = SP_MARKER (shape->marker[i]);
+ if ( !shape->marker[i] ) continue;
SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (marker));
+ if ( !marker_item ) continue;
- if (marker_item) {
- /* Get reference to last curve in the path.
- * For moveto-only path, this returns the "closing line segment". */
- Geom::Path const &path_last = pathv.back();
- unsigned int index = path_last.size_default();
- if (index > 0) {
- index--;
+ 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
+ {
+ Geom::Matrix tr(sp_shape_marker_get_transform_at_start(path_it->front()));
+ if (!marker->orient_auto) {
+ Geom::Point transl = tr.translation();
+ tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
+ }
+ if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
+ tr = Geom::Scale(style->stroke_width.computed) * tr;
+ }
+ tr = marker_item->transform * marker->c2p * tr * transform;
+ NRRect marker_bbox;
+ sp_item_invoke_bbox (marker_item, &marker_bbox, from_2geom(tr), true);
+ nr_rect_d_union (&cbbox, &cbbox, &marker_bbox);
}
- Geom::Curve const &lastcurve = path_last[index];
+ // 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 */
+
+ SPMarker* marker = SP_MARKER (shape->marker[i]);
+ SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (marker));
+
+ if (marker_item) {
+ Geom::Matrix tr(sp_shape_marker_get_transform(*curve_it1, *curve_it2));
+ if (!marker->orient_auto) {
+ Geom::Point transl = tr.translation();
+ tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
+ }
+ if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
+ tr = Geom::Scale(style->stroke_width.computed) * tr;
+ }
+ tr = marker_item->transform * marker->c2p * tr * transform;
+ NRRect marker_bbox;
+ sp_item_invoke_bbox (marker_item, &marker_bbox, from_2geom(tr), true);
+ nr_rect_d_union (&cbbox, &cbbox, &marker_bbox);
+ }
- Geom::Matrix tr = sp_shape_marker_get_transform_at_end(lastcurve);
- if (!marker->orient_auto) {
- Geom::Point transl = tr.translation();
- tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
+ ++curve_it1;
+ ++curve_it2;
+ }
}
- if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
- tr = Geom::Scale(style->stroke_width.computed) * tr;
+ // END position
+ if ( path_it != (pathv.end()-1) && !path_it->empty()) {
+ Geom::Curve const &lastcurve = path_it->back_default();
+ Geom::Matrix tr = sp_shape_marker_get_transform_at_end(lastcurve);
+ if (!marker->orient_auto) {
+ Geom::Point transl = tr.translation();
+ tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
+ }
+ if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
+ tr = Geom::Scale(style->stroke_width.computed) * tr;
+ }
+ tr = marker_item->transform * marker->c2p * tr * transform;
+ NRRect marker_bbox;
+ sp_item_invoke_bbox (marker_item, &marker_bbox, tr, true);
+ nr_rect_d_union (&cbbox, &cbbox, &marker_bbox);
}
+ }
+ }
+ // END marker
+ for (unsigned i = 0; i < 4; i += 3) { // SP_MARKER_LOC and SP_MARKER_LOC_END
+ if ( shape->marker[i] ) {
+ SPMarker* marker = SP_MARKER (shape->marker[i]);
+ SPItem* marker_item = sp_item_first_item_child (SP_OBJECT (marker));
+
+ if (marker_item) {
+ /* Get reference to last curve in the path.
+ * For moveto-only path, this returns the "closing line segment". */
+ Geom::Path const &path_last = pathv.back();
+ unsigned int index = path_last.size_default();
+ if (index > 0) {
+ index--;
+ }
+ Geom::Curve const &lastcurve = path_last[index];
+
+ Geom::Matrix tr = sp_shape_marker_get_transform_at_end(lastcurve);
+ if (!marker->orient_auto) {
+ Geom::Point transl = tr.translation();
+ tr = Geom::Rotate::from_degrees(marker->orient) * Geom::Translate(transl);
+ }
+ if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
+ tr = Geom::Scale(style->stroke_width.computed) * tr;
+ }
- // total marker transform
- tr = marker_item->transform * marker->c2p * tr * transform;
+ // total marker transform
+ tr = marker_item->transform * marker->c2p * tr * transform;
- // get bbox of the marker with that transform
- NRRect marker_bbox;
- sp_item_invoke_bbox (marker_item, &marker_bbox, tr, true);
- // union it with the shape bbox
- nr_rect_d_union (&cbbox, &cbbox, &marker_bbox);
+ // get bbox of the marker with that transform
+ NRRect marker_bbox;
+ sp_item_invoke_bbox (marker_item, &marker_bbox, tr, true);
+ // union it with the shape bbox
+ nr_rect_d_union (&cbbox, &cbbox, &marker_bbox);
+ }
}
}
}
- }
- }
+ break;
+ } // end case approximate bbox type
+ } // end switch bboxtype
// copy our bbox to the variable we're given
*bbox = cbbox;
diff --git a/src/splivarot.cpp b/src/splivarot.cpp
index 085dfeda0a52595bd027f5c06b3b8a94c423ed10..db9f729752a26d29071ca1a328c6f70a8144db77 100644 (file)
--- a/src/splivarot.cpp
+++ b/src/splivarot.cpp
@@ -624,6 +624,250 @@ void sp_selected_path_outline_add_marker( SPObject *marker_object, Geom::Matrix
}
}
+static
+void item_outline_add_marker( SPObject const *marker_object, Geom::Matrix marker_transform,
+ Geom::Scale stroke_scale, Geom::Matrix transform,
+ Geom::PathVector* pathv_in )
+{
+ SPMarker* marker = SP_MARKER (marker_object);
+ SPItem* marker_item = sp_item_first_item_child(SP_OBJECT(marker_object));
+
+ Geom::Matrix tr(marker_transform);
+ if (marker->markerUnits == SP_MARKER_UNITS_STROKEWIDTH) {
+ tr = stroke_scale * tr;
+ }
+ // total marker transform
+ tr = marker_item->transform * marker->c2p * tr * transform;
+
+ Geom::PathVector* marker_pathv = item_outline(marker_item);
+
+ if (marker_pathv) {
+ for (unsigned int j=0; j < marker_pathv->size(); j++) {
+ pathv_in->push_back((*marker_pathv)[j] * tr);
+ }
+ delete marker_pathv;
+ }
+}
+
+/**
+ * Returns a pathvector that is the outline of the stroked item, with markers.
+ * item must be SPShape of SPText.
+ */
+Geom::PathVector* item_outline(SPItem const *item)
+{
+ Geom::PathVector *ret_pathv = NULL;
+
+ if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item))
+ return ret_pathv;
+
+ // no stroke: no outline
+ if (!SP_OBJECT_STYLE(item) || SP_OBJECT_STYLE(item)->stroke.noneSet) {
+ return ret_pathv;
+ }
+
+ SPCurve *curve = NULL;
+ if (SP_IS_SHAPE(item)) {
+ curve = sp_shape_get_curve(SP_SHAPE(item));
+ } else if (SP_IS_TEXT(item)) {
+ curve = SP_TEXT(item)->getNormalizedBpath();
+ }
+ if (curve == NULL) {
+ return ret_pathv;
+ }
+
+ // remember old stroke style, to be set on fill
+ SPStyle *i_style = SP_OBJECT_STYLE(item);
+
+ Geom::Matrix const transform(item->transform);
+ float const scale = transform.descrim();
+
+ float o_width, o_miter;
+ JoinType o_join;
+ ButtType o_butt;
+ {
+ o_width = i_style->stroke_width.computed;
+ if (o_width < 0.1) {
+ o_width = 0.1;
+ }
+ o_miter = i_style->stroke_miterlimit.value * o_width;
+
+ switch (i_style->stroke_linejoin.computed) {
+ case SP_STROKE_LINEJOIN_MITER:
+ o_join = join_pointy;
+ break;
+ case SP_STROKE_LINEJOIN_ROUND:
+ o_join = join_round;
+ break;
+ default:
+ o_join = join_straight;
+ break;
+ }
+
+ switch (i_style->stroke_linecap.computed) {
+ case SP_STROKE_LINECAP_SQUARE:
+ o_butt = butt_square;
+ break;
+ case SP_STROKE_LINECAP_ROUND:
+ o_butt = butt_round;
+ break;
+ default:
+ o_butt = butt_straight;
+ break;
+ }
+ }
+
+ // Livarots outline of arcs is broken. So convert the path to linear and cubics only, for which the outline is created correctly.
+ Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers( curve->get_pathvector() );
+
+ Path *orig = new Path;
+ orig->LoadPathVector(pathv);
+
+ Path *res = new Path;
+ res->SetBackData(false);
+
+ if (i_style->stroke_dash.n_dash) {
+ // For dashed strokes, use Stroke method, because Outline can't do dashes
+ // However Stroke adds lots of extra nodes _or_ makes the path crooked, so consider this a temporary workaround
+
+ orig->ConvertWithBackData(0.1);
+
+ orig->DashPolylineFromStyle(i_style, scale, 0);
+
+ Shape* theShape = new Shape;
+ orig->Stroke(theShape, false, 0.5*o_width, o_join, o_butt,
+ 0.5 * o_miter);
+ orig->Outline(res, 0.5 * o_width, o_join, o_butt, 0.5 * o_miter);
+
+ Shape *theRes = new Shape;
+
+ theRes->ConvertToShape(theShape, fill_positive);
+
+ Path *originaux[1];
+ originaux[0] = res;
+ theRes->ConvertToForme(orig, 1, originaux);
+
+ res->Coalesce(5.0);
+
+ delete theShape;
+ delete theRes;
+ } else {
+ orig->Outline(res, 0.5 * o_width, o_join, o_butt, 0.5 * o_miter);
+
+ orig->Coalesce(0.5 * o_width);
+
+ Shape *theShape = new Shape;
+ Shape *theRes = new Shape;
+
+ res->ConvertWithBackData(1.0);
+ res->Fill(theShape, 0);
+ theRes->ConvertToShape(theShape, fill_positive);
+
+ Path *originaux[1];
+ originaux[0] = res;
+ theRes->ConvertToForme(orig, 1, originaux);
+
+ delete theShape;
+ delete theRes;
+ }
+
+ if (orig->descr_cmd.size() <= 1) {
+ // ca a merd\8e, ou bien le resultat est vide
+ delete res;
+ delete orig;
+ curve->unref();
+ return ret_pathv;
+ }
+
+
+ if (res->descr_cmd.size() > 1) { // if there's 0 or 1 node left, drop this path altogether
+ ret_pathv = orig->MakePathVector();
+
+ if (SP_IS_SHAPE(item) && sp_shape_has_markers (SP_SHAPE(item))) {
+ SPShape *shape = SP_SHAPE(item);
+
+ Geom::PathVector const & pathv = curve->get_pathvector();
+
+ // 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()));
+ item_outline_add_marker( marker_obj, m,
+ Geom::Scale(i_style->stroke_width.computed), transform,
+ ret_pathv );
+ }
+ }
+ // 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
+ {
+ Geom::Matrix const m (sp_shape_marker_get_transform_at_start(path_it->front()));
+ item_outline_add_marker( midmarker_obj, m,
+ Geom::Scale(i_style->stroke_width.computed), transform,
+ ret_pathv );
+ }
+ // 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));
+ item_outline_add_marker( midmarker_obj, m,
+ Geom::Scale(i_style->stroke_width.computed), transform,
+ ret_pathv);
+
+ ++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);
+ item_outline_add_marker( midmarker_obj, m,
+ Geom::Scale(i_style->stroke_width.computed), transform,
+ ret_pathv );
+ }
+ }
+ }
+ // 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". */
+ Geom::Path const &path_last = pathv.back();
+ unsigned int index = path_last.size_default();
+ if (index > 0) {
+ index--;
+ }
+ Geom::Curve const &lastcurve = path_last[index];
+
+ Geom::Matrix const m = sp_shape_marker_get_transform_at_end(lastcurve);
+ item_outline_add_marker( marker_obj, m,
+ Geom::Scale(i_style->stroke_width.computed), transform,
+ ret_pathv );
+ }
+ }
+ }
+
+ curve->unref();
+ }
+
+ delete res;
+ delete orig;
+
+ return ret_pathv;
+}
+
void
sp_selected_path_outline(SPDesktop *desktop)
{
diff --git a/src/splivarot.h b/src/splivarot.h
index dce31a1ad6eb1f7454a97d4f6111f185baa43568..ff9f4f5774fe19d30160af9534825605bc7d1d35 100644 (file)
--- a/src/splivarot.h
+++ b/src/splivarot.h
// outline of a curve
// uses the stroke-width
void sp_selected_path_outline (SPDesktop *desktop);
+Geom::PathVector* item_outline(SPItem const *item);
// simplifies a path (removes small segments and the like)
void sp_selected_path_simplify (SPDesktop *desktop);