828c6104801212de586884a16ab2855207d24258
1 #define __SP_LIVAROT_C__
2 /*
3 * splivarot.cpp
4 * Inkscape
5 *
6 * Created by fred on Fri Dec 05 2003.
7 * tweaked endlessly by bulia byak <buliabyak@users.sf.net>
8 * public domain
9 *
10 */
12 /*
13 * contains lots of stitched pieces of path-chemistry.c
14 */
16 #ifdef HAVE_CONFIG_H
17 # include <config.h>
18 #endif
20 #include <vector>
21 #include "xml/repr.h"
22 #include "svg/svg.h"
23 #include "sp-path.h"
24 #include "sp-text.h"
25 #include "sp-item-group.h"
26 #include "style.h"
27 #include "inkscape.h"
28 #include "document.h"
29 #include "message-stack.h"
30 #include "selection.h"
31 #include "desktop-handles.h"
32 #include "desktop.h"
33 #include "display/canvas-bpath.h"
34 #include "display/curve.h"
35 #include <glibmm/i18n.h>
36 #include "prefs-utils.h"
38 #include "libnr/n-art-bpath.h"
39 #include "libnr/nr-path.h"
40 #include "xml/repr.h"
41 #include "xml/repr-sorting.h"
43 #include "livarot/Path.h"
44 #include "livarot/Shape.h"
46 #include "splivarot.h"
48 bool Ancetre(Inkscape::XML::Node *a, Inkscape::XML::Node *who);
50 void sp_selected_path_boolop(bool_op bop);
51 void sp_selected_path_do_offset(bool expand, double prefOffset);
52 void sp_selected_path_create_offset_object(int expand, bool updating);
54 void
55 sp_selected_path_union()
56 {
57 sp_selected_path_boolop(bool_op_union);
58 }
60 void
61 sp_selected_path_intersect()
62 {
63 sp_selected_path_boolop(bool_op_inters);
64 }
66 void
67 sp_selected_path_diff()
68 {
69 sp_selected_path_boolop(bool_op_diff);
70 }
72 void
73 sp_selected_path_symdiff()
74 {
75 sp_selected_path_boolop(bool_op_symdiff);
76 }
77 void
78 sp_selected_path_cut()
79 {
80 sp_selected_path_boolop(bool_op_cut);
81 }
82 void
83 sp_selected_path_slice()
84 {
85 sp_selected_path_boolop(bool_op_slice);
86 }
89 // boolean operations
90 // take the source paths from the file, do the operation, delete the originals and add the results
91 void
92 sp_selected_path_boolop(bool_op bop)
93 {
94 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
96 Inkscape::Selection *selection = sp_desktop_selection(desktop);
98 GSList *il = (GSList *) selection->itemList();
100 if (g_slist_length(il) < 2) {
101 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Select <b>at least 2 paths</b> to perform a boolean operation."));
102 return;
103 }
105 if (g_slist_length(il) > 2) {
106 if (bop == bool_op_diff || bop == bool_op_symdiff || bop == bool_op_cut || bop == bool_op_slice ) {
107 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Select <b>exactly 2 paths</b> to perform difference, XOR, division, or path cut."));
108 return;
109 }
110 }
112 // reverseOrderForOp marks whether the order of the list is the top->down order
113 // it's only used when there are 2 objects, and for operations who need to know the
114 // topmost object (differences, cuts)
115 bool reverseOrderForOp = false;
117 // mettre les elements de la liste dans l'ordre pour ces operations
118 if (bop == bool_op_diff || bop == bool_op_symdiff || bop == bool_op_cut || bop == bool_op_slice) {
119 // check in the tree to find which element of the selection list is topmost (for 2-operand commands only)
120 Inkscape::XML::Node *a = SP_OBJECT_REPR(il->data);
121 Inkscape::XML::Node *b = SP_OBJECT_REPR(il->next->data);
123 if (a == NULL || b == NULL) {
124 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Unable to determine the <b>z-order</b> of the objects selected for difference, XOR, division, or path cut."));
125 return;
126 }
128 if (Ancetre(a, b)) {
129 // a is the parent of b, already in the proper order
130 } else if (Ancetre(b, a)) {
131 // reverse order
132 reverseOrderForOp = true;
133 } else {
135 // objects are not in parent/child relationship;
136 // find their lowest common ancestor
137 Inkscape::XML::Node *dad = LCA(a, b);
138 if (dad == NULL) {
139 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Unable to determine the <b>z-order</b> of the objects selected for difference, XOR, division, or path cut."));
140 return;
141 }
143 // find the children of the LCA that lead from it to the a and b
144 Inkscape::XML::Node *as = AncetreFils(a, dad);
145 Inkscape::XML::Node *bs = AncetreFils(b, dad);
147 // find out which comes first
148 for (Inkscape::XML::Node *child = dad->firstChild(); child; child = child->next()) {
149 if (child == as) {
150 /* a first, so reverse. */
151 reverseOrderForOp = true;
152 break;
153 }
154 if (child == bs)
155 break;
156 }
157 }
158 }
160 il = g_slist_copy(il);
162 // first check if all the input objects have shapes
163 // otherwise bail out
164 for (GSList *l = il; l != NULL; l = l->next)
165 {
166 SPItem *item = SP_ITEM(l->data);
167 if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item))
168 {
169 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("One of the objects is <b>not a path</b>, cannot perform boolean operation."));
170 g_slist_free(il);
171 return;
172 }
173 }
175 // extract the livarot Paths from the source objects
176 // also get the winding rule specified in the style
177 int nbOriginaux = g_slist_length(il);
178 std::vector<Path *> originaux(nbOriginaux);
179 std::vector<FillRule> origWind(nbOriginaux);
180 int curOrig;
181 {
182 curOrig = 0;
183 for (GSList *l = il; l != NULL; l = l->next)
184 {
185 SPCSSAttr *css = sp_repr_css_attr(SP_OBJECT_REPR(il->data), "style");
186 gchar const *val = sp_repr_css_property(css, "fill-rule", NULL);
187 if (val && strcmp(val, "nonzero") == 0) {
188 origWind[curOrig]= fill_nonZero;
189 } else if (val && strcmp(val, "evenodd") == 0) {
190 origWind[curOrig]= fill_oddEven;
191 } else {
192 origWind[curOrig]= fill_nonZero;
193 }
195 originaux[curOrig] = Path_for_item((SPItem *) l->data, true, true);
196 if (originaux[curOrig] == NULL || originaux[curOrig]->descr_cmd.size() <= 1)
197 {
198 for (int i = curOrig; i >= 0; i--) delete originaux[i];
199 g_slist_free(il);
200 return;
201 }
202 curOrig++;
203 }
204 }
205 // reverse if needed
206 // note that the selection list keeps its order
207 if ( reverseOrderForOp ) {
208 Path* swap=originaux[0];originaux[0]=originaux[1];originaux[1]=swap;
209 FillRule swai=origWind[0]; origWind[0]=origWind[1]; origWind[1]=swai;
210 }
212 // and work
213 // some temporary instances, first
214 Shape *theShapeA = new Shape;
215 Shape *theShapeB = new Shape;
216 Shape *theShape = new Shape;
217 Path *res = new Path;
218 res->SetBackData(false);
219 Path::cut_position *toCut=NULL;
220 int nbToCut=0;
222 if ( bop == bool_op_inters || bop == bool_op_union || bop == bool_op_diff || bop == bool_op_symdiff ) {
223 // true boolean op
224 // get the polygons of each path, with the winding rule specified, and apply the operation iteratively
225 originaux[0]->ConvertWithBackData(0.1);
227 originaux[0]->Fill(theShape, 0);
229 theShapeA->ConvertToShape(theShape, origWind[0]);
231 curOrig = 1;
232 for (GSList *l = il->next; l != NULL; l = l->next) {
233 originaux[curOrig]->ConvertWithBackData(0.1);
235 originaux[curOrig]->Fill(theShape, curOrig);
237 theShapeB->ConvertToShape(theShape, origWind[curOrig]);
239 // les elements arrivent en ordre inverse dans la liste
240 theShape->Booleen(theShapeB, theShapeA, bop);
242 {
243 Shape *swap = theShape;
244 theShape = theShapeA;
245 theShapeA = swap;
246 }
247 curOrig++;
248 }
250 {
251 Shape *swap = theShape;
252 theShape = theShapeA;
253 theShapeA = swap;
254 }
256 } else if ( bop == bool_op_cut ) {
257 // cuts= sort of a bastard boolean operation, thus not the axact same modus operandi
258 // technically, the cut path is not necessarily a polygon (thus has no winding rule)
259 // it is just uncrossed, and cleaned from duplicate edges and points
260 // then it's fed to Booleen() which will uncross it against the other path
261 // then comes the trick: each edge of the cut path is duplicated (one in each direction),
262 // thus making a polygon. the weight of the edges of the cut are all 0, but
263 // the Booleen need to invert the ones inside the source polygon (for the subsequent
264 // ConvertToForme)
266 // the cut path needs to have the highest pathID in the back data
267 // that's how the Booleen() function knows it's an edge of the cut
269 // FIXME: this gives poor results, the final paths are full of extraneous nodes. Decreasing
270 // ConvertWithBackData parameter below simply increases the number of nodes, so for now I
271 // left it at 1.0. Investigate replacing this by a combination of difference and
272 // intersection of the same two paths. -- bb
273 {
274 Path* swap=originaux[0];originaux[0]=originaux[1];originaux[1]=swap;
275 int swai=origWind[0];origWind[0]=origWind[1];origWind[1]=(fill_typ)swai;
276 }
277 originaux[0]->ConvertWithBackData(1.0);
279 originaux[0]->Fill(theShape, 0);
281 theShapeA->ConvertToShape(theShape, origWind[0]);
283 originaux[1]->ConvertWithBackData(1.0);
285 originaux[1]->Fill(theShape, 1,false,false,false); //do not closeIfNeeded
287 theShapeB->ConvertToShape(theShape, fill_justDont); // fill_justDont doesn't computes winding numbers
289 // les elements arrivent en ordre inverse dans la liste
290 theShape->Booleen(theShapeB, theShapeA, bool_op_cut, 1);
292 } else if ( bop == bool_op_slice ) {
293 // slice is not really a boolean operation
294 // you just put the 2 shapes in a single polygon, uncross it
295 // the points where the degree is > 2 are intersections
296 // just check it's an intersection on the path you want to cut, and keep it
297 // the intersections you have found are then fed to ConvertPositionsToMoveTo() which will
298 // make new subpath at each one of these positions
299 // inversion pour l'op\8eration
300 {
301 Path* swap=originaux[0];originaux[0]=originaux[1];originaux[1]=swap;
302 int swai=origWind[0];origWind[0]=origWind[1];origWind[1]=(fill_typ)swai;
303 }
304 originaux[0]->ConvertWithBackData(1.0);
306 originaux[0]->Fill(theShapeA, 0,false,false,false); // don't closeIfNeeded
308 originaux[1]->ConvertWithBackData(1.0);
310 originaux[1]->Fill(theShapeA, 1,true,false,false);// don't closeIfNeeded and just dump in the shape, don't reset it
312 theShape->ConvertToShape(theShapeA, fill_justDont);
314 if ( theShape->hasBackData() ) {
315 // should always be the case, but ya never know
316 {
317 for (int i = 0; i < theShape->numberOfPoints(); i++) {
318 if ( theShape->getPoint(i).totalDegree() > 2 ) {
319 // possibly an intersection
320 // we need to check that at least one edge from the source path is incident to it
321 // before we declare it's an intersection
322 int cb = theShape->getPoint(i).incidentEdge[FIRST];
323 int nbOrig=0;
324 int nbOther=0;
325 int piece=-1;
326 float t=0.0;
327 while ( cb >= 0 && cb < theShape->numberOfEdges() ) {
328 if ( theShape->ebData[cb].pathID == 0 ) {
329 // the source has an edge incident to the point, get its position on the path
330 piece=theShape->ebData[cb].pieceID;
331 if ( theShape->getEdge(cb).st == i ) {
332 t=theShape->ebData[cb].tSt;
333 } else {
334 t=theShape->ebData[cb].tEn;
335 }
336 nbOrig++;
337 }
338 if ( theShape->ebData[cb].pathID == 1 ) nbOther++; // the cut is incident to this point
339 cb=theShape->NextAt(i, cb);
340 }
341 if ( nbOrig > 0 && nbOther > 0 ) {
342 // point incident to both path and cut: an intersection
343 // note that you only keep one position on the source; you could have degenerate
344 // cases where the source crosses itself at this point, and you wouyld miss an intersection
345 toCut=(Path::cut_position*)realloc(toCut, (nbToCut+1)*sizeof(Path::cut_position));
346 toCut[nbToCut].piece=piece;
347 toCut[nbToCut].t=t;
348 nbToCut++;
349 }
350 }
351 }
352 }
353 {
354 // i think it's useless now
355 int i = theShape->numberOfEdges() - 1;
356 for (;i>=0;i--) {
357 if ( theShape->ebData[i].pathID == 1 ) {
358 theShape->SubEdge(i);
359 }
360 }
361 }
363 }
364 }
366 int* nesting=NULL;
367 int* conts=NULL;
368 int nbNest=0;
369 // pour compenser le swap juste avant
370 if ( bop == bool_op_slice ) {
371 // theShape->ConvertToForme(res, nbOriginaux, originaux, true);
372 // res->ConvertForcedToMoveTo();
373 res->Copy(originaux[0]);
374 res->ConvertPositionsToMoveTo(nbToCut, toCut); // cut where you found intersections
375 free(toCut);
376 } else if ( bop == bool_op_cut ) {
377 // il faut appeler pour desallouer PointData (pas vital, mais bon)
378 // the Booleen() function did not deallocated the point_data array in theShape, because this
379 // function needs it.
380 // this function uses the point_data to get the winding number of each path (ie: is a hole or not)
381 // for later reconstruction in objects, you also need to extract which path is parent of holes (nesting info)
382 theShape->ConvertToFormeNested(res, nbOriginaux, &originaux[0], 1, nbNest, nesting, conts);
383 } else {
384 theShape->ConvertToForme(res, nbOriginaux, &originaux[0]);
385 }
387 delete theShape;
388 delete theShapeA;
389 delete theShapeB;
390 for (int i = 0; i < nbOriginaux; i++) delete originaux[i];
392 if (res->descr_cmd.size() <= 1)
393 {
394 // only one command, presumably a moveto: it isn't a path
395 for (GSList *l = il; l != NULL; l = l->next)
396 {
397 SP_OBJECT(l->data)->deleteObject();
398 }
399 sp_document_done(sp_desktop_document(desktop));
400 selection->clear();
402 delete res;
403 g_slist_free(il);
404 return;
405 }
407 // remember important aspects of the source path, to be restored
408 Inkscape::XML::Node *repr_source;
409 if ( bop == bool_op_diff || bop == bool_op_symdiff || bop == bool_op_cut || bop == bool_op_slice ) {
410 if (reverseOrderForOp) {
411 repr_source = SP_OBJECT_REPR(il->data);
412 } else {
413 repr_source = SP_OBJECT_REPR(il->next->data);
414 }
415 } else {
416 // find out the bottom object
417 GSList *sorted = g_slist_copy((GSList *) selection->reprList());
419 sorted = g_slist_sort(sorted, (GCompareFunc) sp_repr_compare_position);
420 repr_source = ((Inkscape::XML::Node *) sorted->data);
421 g_slist_free(sorted);
422 }
423 gint pos = repr_source->position();
424 Inkscape::XML::Node *parent = sp_repr_parent(repr_source);
425 char const *id = repr_source->attribute("id");
426 char const *style = repr_source->attribute("style");
429 // remove source paths
430 selection->clear();
431 for (GSList *l = il; l != NULL; l = l->next) {
432 // if this is the bottommost object,
433 if (!strcmp(SP_OBJECT_REPR(l->data)->attribute("id"), id)) {
434 // delete it so that its clones don't get alerted; this object will be restored shortly, with the same id
435 SP_OBJECT(l->data)->deleteObject(false);
436 } else {
437 // delete the object for real, so that its clones can take appropriate action
438 SP_OBJECT(l->data)->deleteObject();
439 }
440 }
441 g_slist_free(il);
443 // premultiply by the inverse of parent's repr
444 SPItem *parent_item = SP_ITEM(sp_desktop_document(desktop)->getObjectByRepr(parent));
445 NR::Matrix local = sp_item_i2doc_affine(parent_item);
446 gchar affinestr[80];
447 gchar *transform = NULL;
448 if (!local.test_identity() && sp_svg_transform_write(affinestr, 79, local.inverse())) {
449 transform = affinestr;
450 }
452 // now that we have the result, add it on the canvas
453 if ( bop == bool_op_cut || bop == bool_op_slice ) {
454 int nbRP=0;
455 Path** resPath;
456 if ( bop == bool_op_slice ) {
457 // there are moveto's at each intersection, but it's still one unique path
458 // so break it down and add each subpath independently
459 // we could call break_apart to do this, but while we have the description...
460 resPath=res->SubPaths(nbRP, false);
461 } else {
462 // cut operation is a bit wicked: you need to keep holes
463 // that's why you needed the nesting
464 // ConvertToFormeNested() dumped all the subpath in a single Path "res", so we need
465 // to get the path for each part of the polygon. that's why you need the nesting info:
466 // to know in wich subpath to add a subpath
467 resPath=res->SubPathsWithNesting(nbRP, true, nbNest, nesting, conts);
469 // cleaning
470 if ( conts ) free(conts);
471 if ( nesting ) free(nesting);
472 }
474 // add all the pieces resulting from cut or slice
475 for (int i=0;i<nbRP;i++) {
476 gchar *d = resPath[i]->svg_dump_path();
478 Inkscape::XML::Node *repr = sp_repr_new("svg:path");
479 repr->setAttribute("style", style);
480 repr->setAttribute("d", d);
481 g_free(d);
483 // for slice, remove fill
484 if (bop == bool_op_slice) {
485 SPCSSAttr *css;
487 css = sp_repr_css_attr_new();
488 sp_repr_css_set_property(css, "fill", "none");
490 sp_repr_css_change(repr, css, "style");
492 sp_repr_css_attr_unref(css);
493 }
495 // we assign the same id on all pieces, but it on adding to document, it will be changed on all except one
496 // this means it's basically random which of the pieces inherits the original's id and clones
497 // a better algorithm might figure out e.g. the biggest piece
498 repr->setAttribute("id", id);
500 repr->setAttribute("transform", transform);
502 // add the new repr to the parent
503 parent->appendChild(repr);
505 // move to the saved position
506 repr->setPosition(pos > 0 ? pos : 0);
508 selection->add(repr);
509 Inkscape::GC::release(repr);
511 delete resPath[i];
512 }
513 if ( resPath ) free(resPath);
515 } else {
516 gchar *d = res->svg_dump_path();
518 Inkscape::XML::Node *repr = sp_repr_new("svg:path");
519 repr->setAttribute("style", style);
521 repr->setAttribute("d", d);
522 g_free(d);
524 repr->setAttribute("transform", transform);
526 repr->setAttribute("id", id);
527 parent->appendChild(repr);
528 repr->setPosition(pos > 0 ? pos : 0);
530 selection->add(repr);
531 Inkscape::GC::release(repr);
532 }
534 sp_document_done(sp_desktop_document(desktop));
536 delete res;
537 }
540 void
541 sp_selected_path_outline()
542 {
543 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
545 Inkscape::Selection *selection = sp_desktop_selection(desktop);
547 if (selection->isEmpty()) {
548 // TRANSLATORS: "to outline" means "to convert stroke to path"
549 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to outline."));
550 return;
551 }
553 bool did = false;
555 for (GSList *items = g_slist_copy((GSList *) selection->itemList());
556 items != NULL;
557 items = items->next) {
559 SPItem *item = (SPItem *) items->data;
561 if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item))
562 continue;
564 SPCurve *curve = NULL;
565 if (SP_IS_SHAPE(item)) {
566 curve = sp_shape_get_curve(SP_SHAPE(item));
567 if (curve == NULL)
568 continue;
569 }
570 if (SP_IS_TEXT(item)) {
571 curve = SP_TEXT(item)->getNormalizedBpath();
572 if (curve == NULL)
573 continue;
574 }
576 { // pas de stroke pas de chocolat
577 SPCSSAttr *css = sp_repr_css_attr_inherited(SP_OBJECT_REPR(item), "style");
578 gchar const *val = sp_repr_css_property(css, "stroke", NULL);
580 if (val == NULL || strcmp(val, "none") == 0) {
581 sp_curve_unref(curve);
582 continue;
583 }
584 }
586 // remember old stroke style, to be set on fill
587 SPCSSAttr *ncss;
588 {
589 SPCSSAttr *ocss = sp_repr_css_attr_inherited(SP_OBJECT_REPR(item), "style");
590 gchar const *val = sp_repr_css_property(ocss, "stroke", NULL);
591 gchar const *opac = sp_repr_css_property(ocss, "stroke-opacity", NULL);
593 ncss = sp_repr_css_attr_new();
595 sp_repr_css_set_property(ncss, "stroke", "none");
596 sp_repr_css_set_property(ncss, "stroke-opacity", "1.0");
597 sp_repr_css_set_property(ncss, "fill", val);
598 if ( opac ) {
599 sp_repr_css_set_property(ncss, "fill-opacity", opac);
600 } else {
601 sp_repr_css_set_property(ncss, "fill-opacity", "1.0");
602 }
603 }
605 NR::Matrix const transform(item->transform);
606 gchar *style = g_strdup(SP_OBJECT_REPR(item)->attribute("style"));
608 float o_width, o_miter;
609 JoinType o_join;
610 ButtType o_butt;
612 {
613 SPStyle *i_style = SP_OBJECT(item)->style;
614 int jointype, captype;
616 jointype = i_style->stroke_linejoin.computed;
617 captype = i_style->stroke_linecap.computed;
618 o_width = i_style->stroke_width.computed;
620 switch (jointype) {
621 case SP_STROKE_LINEJOIN_MITER:
622 o_join = join_pointy;
623 break;
624 case SP_STROKE_LINEJOIN_ROUND:
625 o_join = join_round;
626 break;
627 default:
628 o_join = join_straight;
629 break;
630 }
632 switch (captype) {
633 case SP_STROKE_LINECAP_SQUARE:
634 o_butt = butt_square;
635 break;
636 case SP_STROKE_LINECAP_ROUND:
637 o_butt = butt_round;
638 break;
639 default:
640 o_butt = butt_straight;
641 break;
642 }
644 if (o_width < 0.1)
645 o_width = 0.1;
646 o_miter = i_style->stroke_miterlimit.value * o_width;
647 }
649 Path *orig = Path_for_item(item, false);
650 if (orig == NULL) {
651 g_free(style);
652 sp_curve_unref(curve);
653 continue;
654 }
656 Path *res = new Path;
657 res->SetBackData(false);
660 {
661 orig->Outline(res, 0.5 * o_width, o_join, o_butt, 0.5 * o_miter);
663 orig->Coalesce(0.5 * o_width);
665 Shape *theShape = new Shape;
666 Shape *theRes = new Shape;
668 res->ConvertWithBackData(1.0);
669 res->Fill(theShape, 0);
670 theRes->ConvertToShape(theShape, fill_positive);
672 Path *originaux[1];
673 originaux[0] = res;
674 theRes->ConvertToForme(orig, 1, originaux);
676 delete theShape;
677 delete theRes;
678 }
680 if (orig->descr_cmd.size() <= 1) {
681 // ca a merd\8e, ou bien le resultat est vide
682 delete res;
683 delete orig;
684 g_free(style);
685 continue;
686 }
688 did = true;
690 sp_curve_unref(curve);
691 // remember the position of the item
692 gint pos = SP_OBJECT_REPR(item)->position();
693 // remember parent
694 Inkscape::XML::Node *parent = SP_OBJECT_REPR(item)->parent();
695 // remember id
696 char const *id = SP_OBJECT_REPR(item)->attribute("id");
698 selection->remove(item);
699 SP_OBJECT(item)->deleteObject(false);
701 if (res->descr_cmd.size() > 1) { // if there's 0 or 1 node left, drop this path altogether
703 Inkscape::XML::Node *repr = sp_repr_new("svg:path");
705 // restore old style
706 repr->setAttribute("style", style);
708 // set old stroke style on fill
709 sp_repr_css_change(repr, ncss, "style");
711 sp_repr_css_attr_unref(ncss);
713 gchar *str = orig->svg_dump_path();
714 repr->setAttribute("d", str);
715 g_free(str);
717 // add the new repr to the parent
718 parent->appendChild(repr);
720 // move to the saved position
721 repr->setPosition(pos > 0 ? pos : 0);
723 repr->setAttribute("id", id);
725 SPItem *newitem = (SPItem *) sp_desktop_document(desktop)->getObjectByRepr(repr);
726 sp_item_write_transform(newitem, repr, transform);
728 selection->add(repr);
730 Inkscape::GC::release(repr);
731 }
733 delete res;
734 delete orig;
735 g_free(style);
737 }
739 if (did) {
740 sp_document_done(sp_desktop_document(desktop));
741 } else {
742 // TRANSLATORS: "to outline" means "to convert stroke to path"
743 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No stroked paths</b> to outline in the selection."));
744 return;
745 }
746 }
749 void
750 sp_selected_path_offset()
751 {
752 double prefOffset = prefs_get_double_attribute("options.defaultoffsetwidth", "value", 1.0);
754 sp_selected_path_do_offset(true, prefOffset);
755 }
756 void
757 sp_selected_path_inset()
758 {
759 double prefOffset = prefs_get_double_attribute("options.defaultoffsetwidth", "value", 1.0);
761 sp_selected_path_do_offset(false, prefOffset);
762 }
764 void
765 sp_selected_path_offset_screen(double pixels)
766 {
767 sp_selected_path_do_offset(true, pixels / SP_ACTIVE_DESKTOP->current_zoom());
768 }
770 void
771 sp_selected_path_inset_screen(double pixels)
772 {
773 sp_selected_path_do_offset(false, pixels / SP_ACTIVE_DESKTOP->current_zoom());
774 }
777 void sp_selected_path_create_offset_object_zero()
778 {
779 sp_selected_path_create_offset_object(0, false);
780 }
782 void sp_selected_path_create_offset()
783 {
784 sp_selected_path_create_offset_object(1, false);
785 }
786 void sp_selected_path_create_inset()
787 {
788 sp_selected_path_create_offset_object(-1, false);
789 }
791 void sp_selected_path_create_updating_offset_object_zero()
792 {
793 sp_selected_path_create_offset_object(0, true);
794 }
796 void sp_selected_path_create_updating_offset()
797 {
798 sp_selected_path_create_offset_object(1, true);
799 }
800 void sp_selected_path_create_updating_inset()
801 {
802 sp_selected_path_create_offset_object(-1, true);
803 }
805 void
806 sp_selected_path_create_offset_object(int expand, bool updating)
807 {
808 Inkscape::Selection *selection;
809 Inkscape::XML::Node *repr;
810 SPItem *item;
811 SPCurve *curve;
812 gchar *style, *str;
813 SPDesktop *desktop;
814 float o_width, o_miter;
815 JoinType o_join;
816 ButtType o_butt;
818 curve = NULL;
820 desktop = SP_ACTIVE_DESKTOP;
822 selection = sp_desktop_selection(desktop);
824 item = selection->singleItem();
826 if (item == NULL || ( !SP_IS_SHAPE(item) && !SP_IS_TEXT(item) ) ) {
827 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Selected object is <b>not a path</b>, cannot inset/outset."));
828 return;
829 }
830 if (SP_IS_SHAPE(item))
831 {
832 curve = sp_shape_get_curve(SP_SHAPE(item));
833 if (curve == NULL)
834 return;
835 }
836 if (SP_IS_TEXT(item))
837 {
838 curve = SP_TEXT(item)->getNormalizedBpath();
839 if (curve == NULL)
840 return;
841 }
843 NR::Matrix const transform(item->transform);
845 sp_item_write_transform(item, SP_OBJECT_REPR(item), NR::identity());
847 style = g_strdup(SP_OBJECT(item)->repr->attribute("style"));
849 // remember the position of the item
850 gint pos = SP_OBJECT_REPR(item)->position();
851 // remember parent
852 Inkscape::XML::Node *parent = SP_OBJECT_REPR(item)->parent();
854 {
855 SPStyle *i_style = SP_OBJECT(item)->style;
856 int jointype, captype;
858 jointype = i_style->stroke_linejoin.value;
859 captype = i_style->stroke_linecap.value;
860 o_width = i_style->stroke_width.computed;
861 if (jointype == SP_STROKE_LINEJOIN_MITER)
862 {
863 o_join = join_pointy;
864 }
865 else if (jointype == SP_STROKE_LINEJOIN_ROUND)
866 {
867 o_join = join_round;
868 }
869 else
870 {
871 o_join = join_straight;
872 }
873 if (captype == SP_STROKE_LINECAP_SQUARE)
874 {
875 o_butt = butt_square;
876 }
877 else if (captype == SP_STROKE_LINECAP_ROUND)
878 {
879 o_butt = butt_round;
880 }
881 else
882 {
883 o_butt = butt_straight;
884 }
886 {
887 double prefOffset = 1.0;
888 prefOffset = prefs_get_double_attribute("options.defaultoffsetwidth", "value", prefOffset);
889 o_width = prefOffset;
890 }
892 if (o_width < 0.01)
893 o_width = 0.01;
894 o_miter = i_style->stroke_miterlimit.value * o_width;
895 }
897 Path *orig = Path_for_item(item, true, false);
898 if (orig == NULL)
899 {
900 g_free(style);
901 sp_curve_unref(curve);
902 return;
903 }
905 Path *res = new Path;
906 res->SetBackData(false);
908 {
909 Shape *theShape = new Shape;
910 Shape *theRes = new Shape;
912 orig->ConvertWithBackData(1.0);
913 orig->Fill(theShape, 0);
915 SPCSSAttr *css = sp_repr_css_attr(SP_OBJECT_REPR(item), "style");
916 gchar const *val = sp_repr_css_property(css, "fill-rule", NULL);
917 if (val && strcmp(val, "nonzero") == 0)
918 {
919 theRes->ConvertToShape(theShape, fill_nonZero);
920 }
921 else if (val && strcmp(val, "evenodd") == 0)
922 {
923 theRes->ConvertToShape(theShape, fill_oddEven);
924 }
925 else
926 {
927 theRes->ConvertToShape(theShape, fill_nonZero);
928 }
930 Path *originaux[1];
931 originaux[0] = orig;
932 theRes->ConvertToForme(res, 1, originaux);
934 delete theShape;
935 delete theRes;
936 }
938 sp_curve_unref(curve);
940 if (res->descr_cmd.size() <= 1)
941 {
942 // pas vraiment de points sur le resultat
943 // donc il ne reste rien
944 sp_document_done(sp_desktop_document(desktop));
945 selection->clear();
947 delete res;
948 delete orig;
949 g_free(style);
950 return;
951 }
953 {
954 gchar tstr[80];
956 tstr[79] = '\0';
958 repr = sp_repr_new("svg:path");
959 repr->setAttribute("sodipodi:type", "inkscape:offset");
960 sp_repr_set_svg_double(repr, "inkscape:radius", ( expand > 0
961 ? o_width
962 : expand < 0
963 ? -o_width
964 : 0 ));
966 str = res->svg_dump_path();
967 repr->setAttribute("inkscape:original", str);
968 g_free(str);
970 if ( updating ) {
971 char const *id = SP_OBJECT(item)->repr->attribute("id");
972 char const *uri = g_strdup_printf("#%s", id);
973 repr->setAttribute("xlink:href", uri);
974 g_free((void *) uri);
975 } else {
976 repr->setAttribute("inkscape:href", NULL);
977 }
979 repr->setAttribute("style", style);
981 // add the new repr to the parent
982 parent->appendChild(repr);
984 // move to the saved position
985 repr->setPosition(pos > 0 ? pos : 0);
987 SPItem *nitem = (SPItem *) sp_desktop_document(desktop)->getObjectByRepr(repr);
989 if ( updating ) {
990 // on conserve l'original
991 // we reapply the transform to the original (offset will feel it)
992 sp_item_write_transform(item, SP_OBJECT_REPR(item), transform);
993 } else {
994 // delete original, apply the transform to the offset
995 SP_OBJECT(item)->deleteObject(false);
996 sp_item_write_transform(nitem, repr, transform);
997 }
999 // The object just created from a temporary repr is only a seed.
1000 // We need to invoke its write which will update its real repr (in particular adding d=)
1001 SP_OBJECT(nitem)->updateRepr();
1003 Inkscape::GC::release(repr);
1005 selection->set(nitem);
1006 }
1008 sp_document_done(sp_desktop_document(desktop));
1010 delete res;
1011 delete orig;
1013 g_free(style);
1014 }
1027 void
1028 sp_selected_path_do_offset(bool expand, double prefOffset)
1029 {
1030 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1032 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1034 if (selection->isEmpty()) {
1035 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to inset/outset."));
1036 return;
1037 }
1039 bool did = false;
1041 for (GSList *items = g_slist_copy((GSList *) selection->itemList());
1042 items != NULL;
1043 items = items->next) {
1045 SPItem *item = (SPItem *) items->data;
1047 if (!SP_IS_SHAPE(item) && !SP_IS_TEXT(item))
1048 continue;
1050 SPCurve *curve = NULL;
1051 if (SP_IS_SHAPE(item)) {
1052 curve = sp_shape_get_curve(SP_SHAPE(item));
1053 if (curve == NULL)
1054 continue;
1055 }
1056 if (SP_IS_TEXT(item)) {
1057 curve = SP_TEXT(item)->getNormalizedBpath();
1058 if (curve == NULL)
1059 continue;
1060 }
1062 NR::Matrix const transform(item->transform);
1064 sp_item_write_transform(item, SP_OBJECT_REPR(item), NR::identity());
1066 gchar *style = g_strdup(SP_OBJECT_REPR(item)->attribute("style"));
1068 float o_width, o_miter;
1069 JoinType o_join;
1070 ButtType o_butt;
1072 {
1073 SPStyle *i_style = SP_OBJECT(item)->style;
1074 int jointype, captype;
1076 jointype = i_style->stroke_linejoin.value;
1077 captype = i_style->stroke_linecap.value;
1078 o_width = i_style->stroke_width.computed;
1080 switch (jointype) {
1081 case SP_STROKE_LINEJOIN_MITER:
1082 o_join = join_pointy;
1083 break;
1084 case SP_STROKE_LINEJOIN_ROUND:
1085 o_join = join_round;
1086 break;
1087 default:
1088 o_join = join_straight;
1089 break;
1090 }
1092 switch (captype) {
1093 case SP_STROKE_LINECAP_SQUARE:
1094 o_butt = butt_square;
1095 break;
1096 case SP_STROKE_LINECAP_ROUND:
1097 o_butt = butt_round;
1098 break;
1099 default:
1100 o_butt = butt_straight;
1101 break;
1102 }
1104 o_width = prefOffset;
1106 if (o_width < 0.1)
1107 o_width = 0.1;
1108 o_miter = i_style->stroke_miterlimit.value * o_width;
1109 }
1111 Path *orig = Path_for_item(item, false);
1112 if (orig == NULL) {
1113 g_free(style);
1114 sp_curve_unref(curve);
1115 continue;
1116 }
1118 Path *res = new Path;
1119 res->SetBackData(false);
1121 {
1122 Shape *theShape = new Shape;
1123 Shape *theRes = new Shape;
1125 orig->ConvertWithBackData(0.03);
1126 orig->Fill(theShape, 0);
1128 SPCSSAttr *css = sp_repr_css_attr(SP_OBJECT_REPR(item), "style");
1129 gchar const *val = sp_repr_css_property(css, "fill-rule", NULL);
1130 if (val && strcmp(val, "nonzero") == 0)
1131 {
1132 theRes->ConvertToShape(theShape, fill_nonZero);
1133 }
1134 else if (val && strcmp(val, "evenodd") == 0)
1135 {
1136 theRes->ConvertToShape(theShape, fill_oddEven);
1137 }
1138 else
1139 {
1140 theRes->ConvertToShape(theShape, fill_nonZero);
1141 }
1143 // et maintenant: offset
1144 // methode inexacte
1145 /* Path *originaux[1];
1146 originaux[0] = orig;
1147 theRes->ConvertToForme(res, 1, originaux);
1149 if (expand) {
1150 res->OutsideOutline(orig, 0.5 * o_width, o_join, o_butt, o_miter);
1151 } else {
1152 res->OutsideOutline(orig, -0.5 * o_width, o_join, o_butt, o_miter);
1153 }
1155 orig->ConvertWithBackData(1.0);
1156 orig->Fill(theShape, 0);
1157 theRes->ConvertToShape(theShape, fill_positive);
1158 originaux[0] = orig;
1159 theRes->ConvertToForme(res, 1, originaux);
1161 if (o_width >= 0.5) {
1162 // res->Coalesce(1.0);
1163 res->ConvertEvenLines(1.0);
1164 res->Simplify(1.0);
1165 } else {
1166 // res->Coalesce(o_width);
1167 res->ConvertEvenLines(1.0*o_width);
1168 res->Simplify(1.0 * o_width);
1169 } */
1170 // methode par makeoffset
1172 if (expand)
1173 {
1174 theShape->MakeOffset(theRes, o_width, o_join, o_miter);
1175 }
1176 else
1177 {
1178 theShape->MakeOffset(theRes, -o_width, o_join, o_miter);
1179 }
1180 theRes->ConvertToShape(theShape, fill_positive);
1182 res->Reset();
1183 theRes->ConvertToForme(res);
1185 if (o_width >= 1.0)
1186 {
1187 res->ConvertEvenLines(1.0);
1188 res->Simplify(1.0);
1189 }
1190 else
1191 {
1192 res->ConvertEvenLines(1.0*o_width);
1193 res->Simplify(1.0 * o_width);
1194 }
1196 delete theShape;
1197 delete theRes;
1198 }
1200 did = true;
1202 sp_curve_unref(curve);
1203 // remember the position of the item
1204 gint pos = SP_OBJECT_REPR(item)->position();
1205 // remember parent
1206 Inkscape::XML::Node *parent = SP_OBJECT_REPR(item)->parent();
1207 // remember id
1208 char const *id = SP_OBJECT_REPR(item)->attribute("id");
1210 selection->remove(item);
1211 SP_OBJECT(item)->deleteObject(false);
1213 if (res->descr_cmd.size() > 1) { // if there's 0 or 1 node left, drop this path altogether
1215 gchar tstr[80];
1217 tstr[79] = '\0';
1219 Inkscape::XML::Node *repr = sp_repr_new("svg:path");
1221 repr->setAttribute("style", style);
1223 gchar *str = res->svg_dump_path();
1224 repr->setAttribute("d", str);
1225 g_free(str);
1227 // add the new repr to the parent
1228 parent->appendChild(repr);
1230 // move to the saved position
1231 repr->setPosition(pos > 0 ? pos : 0);
1233 SPItem *newitem = (SPItem *) sp_desktop_document(desktop)->getObjectByRepr(repr);
1235 // reapply the transform
1236 sp_item_write_transform(newitem, repr, transform);
1238 repr->setAttribute("id", id);
1240 selection->add(repr);
1242 Inkscape::GC::release(repr);
1243 }
1245 delete orig;
1246 delete res;
1247 }
1249 if (did) {
1250 sp_document_done(sp_desktop_document(desktop));
1251 } else {
1252 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No paths</b> to inset/outset in the selection."));
1253 return;
1254 }
1255 }
1259 //return true if we changed something, else false
1260 bool
1261 sp_selected_path_simplify_item(SPDesktop *desktop, Inkscape::Selection *selection, SPItem *item,
1262 float threshold, bool justCoalesce,
1263 float angleLimit, bool breakableAngles,
1264 gdouble size, bool modifySelection)
1265 {
1266 if (!(SP_IS_GROUP(item) || SP_IS_SHAPE(item) || SP_IS_TEXT(item)))
1267 return false;
1269 //If this is a group, do the children instead
1270 if (SP_IS_GROUP(item)) {
1272 bool didSomething = false;
1274 for ( GSList *children = sp_item_group_item_list(SP_GROUP(item));
1275 children ; children = children->next) {
1277 SPItem *child = (SPItem *) children->data;
1278 didSomething |= sp_selected_path_simplify_item(desktop, selection, child, threshold, justCoalesce,
1279 angleLimit, breakableAngles, size, false);
1280 }
1282 return didSomething;
1283 }
1286 SPCurve *curve = NULL;
1288 if (SP_IS_SHAPE(item)) {
1289 curve = sp_shape_get_curve(SP_SHAPE(item));
1290 if (!curve)
1291 return false;
1292 }
1294 if (SP_IS_TEXT(item)) {
1295 curve = SP_TEXT(item)->getNormalizedBpath();
1296 if (!curve)
1297 return false;
1298 }
1300 // save the transform, to re-apply it after simplification
1301 NR::Matrix const transform(item->transform);
1303 /*
1304 reset the transform, effectively transforming the item by transform.inverse();
1305 this is necessary so that the item is transformed twice back and forth,
1306 allowing all compensations to cancel out regardless of the preferences
1307 */
1308 sp_item_write_transform(item, SP_OBJECT_REPR(item), NR::identity());
1310 gchar *style = g_strdup(SP_OBJECT_REPR(item)->attribute("style"));
1312 Path *orig = Path_for_item(item, false);
1313 if (orig == NULL) {
1314 g_free(style);
1315 sp_curve_unref(curve);
1316 return false;
1317 }
1319 sp_curve_unref(curve);
1320 // remember the position of the item
1321 gint pos = SP_OBJECT_REPR(item)->position();
1322 // remember parent
1323 Inkscape::XML::Node *parent = SP_OBJECT_REPR(item)->parent();
1324 // remember id
1325 char const *id = SP_OBJECT_REPR(item)->attribute("id");
1327 //If a group was selected, to not change the selection list
1328 if (modifySelection)
1329 selection->remove(item);
1331 SP_OBJECT(item)->deleteObject(false);
1333 if ( justCoalesce ) {
1334 orig->Coalesce(threshold * size);
1335 } else {
1336 orig->ConvertEvenLines(threshold * size);
1337 orig->Simplify(threshold * size);
1338 }
1340 Inkscape::XML::Node *repr = sp_repr_new("svg:path");
1342 repr->setAttribute("style", style);
1344 gchar *str = orig->svg_dump_path();
1345 repr->setAttribute("d", str);
1346 g_free(str);
1348 // restore id
1349 repr->setAttribute("id", id);
1351 // add the new repr to the parent
1352 parent->appendChild(repr);
1354 // move to the saved position
1355 repr->setPosition(pos > 0 ? pos : 0);
1357 SPItem *newitem = (SPItem *) sp_desktop_document(desktop)->getObjectByRepr(repr);
1359 // reapply the transform
1360 sp_item_write_transform(newitem, repr, transform);
1362 //If we are not in a selected group
1363 if (modifySelection)
1364 selection->add(repr);
1366 Inkscape::GC::release(repr);
1368 // clean up
1369 if (orig) delete orig;
1371 return true;
1372 }
1375 void
1376 sp_selected_path_simplify_selection(float threshold, bool justCoalesce,
1377 float angleLimit, bool breakableAngles)
1378 {
1379 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1381 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1383 if (selection->isEmpty()) {
1384 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE,
1385 _("Select <b>path(s)</b> to simplify."));
1386 return;
1387 }
1389 // remember selection size
1390 NR::Rect bbox = selection->bounds();
1391 gdouble size = L2(bbox.dimensions());
1393 bool didSomething = false;
1395 //Loop through all of the items in the selection
1396 for (GSList *items = g_slist_copy((GSList *) selection->itemList());
1397 items != NULL; items = items->next) {
1399 SPItem *item = (SPItem *) items->data;
1401 if (!(SP_IS_GROUP(item) || SP_IS_SHAPE(item) || SP_IS_TEXT(item)))
1402 continue;
1404 didSomething |= sp_selected_path_simplify_item(desktop, selection, item,
1405 threshold, justCoalesce, angleLimit, breakableAngles, size, true);
1406 }
1409 if (didSomething)
1410 sp_document_done(sp_desktop_document(desktop));
1411 else
1412 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No paths</b> to simplify in the selection."));
1414 }
1417 // globals for keeping track of accelerated simplify
1418 static double previousTime = 0.0;
1419 static gdouble simplifyMultiply = 1.0;
1421 void
1422 sp_selected_path_simplify(void)
1423 {
1424 gdouble simplifyThreshold =
1425 prefs_get_double_attribute("options.simplifythreshold", "value", 0.003);
1426 bool simplifyJustCoalesce =
1427 (bool) prefs_get_int_attribute("options.simplifyjustcoalesce", "value", 0);
1429 //Get the current time
1430 GTimeVal currentTimeVal;
1431 g_get_current_time(¤tTimeVal);
1432 double currentTime = currentTimeVal.tv_sec * 1000000 +
1433 currentTimeVal.tv_usec;
1435 //Was the previous call to this function recent? (<0.5 sec)
1436 if (previousTime > 0.0 && currentTime - previousTime < 500000.0) {
1438 // add to the threshold 1/2 of its original value
1439 simplifyMultiply += 0.5;
1440 simplifyThreshold *= simplifyMultiply;
1442 } else {
1443 // reset to the default
1444 simplifyMultiply = 1;
1445 }
1447 //remember time for next call
1448 previousTime = currentTime;
1450 //g_print("%g\n", simplify_threshold);
1452 //Make the actual call
1453 sp_selected_path_simplify_selection(simplifyThreshold,
1454 simplifyJustCoalesce, 0.0, false);
1455 }
1459 // fonctions utilitaires
1461 bool
1462 Ancetre(Inkscape::XML::Node *a, Inkscape::XML::Node *who)
1463 {
1464 if (who == NULL || a == NULL)
1465 return false;
1466 if (who == a)
1467 return true;
1468 return Ancetre(sp_repr_parent(a), who);
1469 }
1471 Path *
1472 Path_for_item(SPItem *item, bool doTransformation, bool transformFull)
1473 {
1474 SPCurve *curve;
1476 if (!item)
1477 return NULL;
1479 if (SP_IS_SHAPE(item))
1480 {
1481 curve = sp_shape_get_curve(SP_SHAPE(item));
1482 }
1483 else if (SP_IS_TEXT(item))
1484 {
1485 curve = SP_TEXT(item)->getNormalizedBpath();
1486 }
1487 else
1488 {
1489 curve = NULL;
1490 }
1492 if (!curve)
1493 return NULL;
1494 NArtBpath *bpath = SP_CURVE_BPATH(curve);
1495 if (bpath == NULL)
1496 return NULL;
1498 if ( doTransformation ) {
1499 if (transformFull)
1500 bpath = nr_artpath_affine(SP_CURVE_BPATH(curve), sp_item_i2doc_affine(item));
1501 else
1502 bpath = nr_artpath_affine(SP_CURVE_BPATH(curve), item->transform);
1503 sp_curve_unref(curve);
1504 curve=NULL;
1505 } else {
1506 bpath=SP_CURVE_BPATH(curve);
1507 }
1509 Path *dest = new Path;
1510 dest->SetBackData(false);
1511 {
1512 int i;
1513 bool closed = false;
1514 float lastX = 0.0;
1515 float lastY = 0.0;
1517 for (i = 0; bpath[i].code != NR_END; i++) {
1518 switch (bpath[i].code) {
1519 case NR_LINETO:
1520 lastX = bpath[i].x3;
1521 lastY = bpath[i].y3;
1522 {
1523 NR::Point tmp(lastX, lastY);
1524 dest->LineTo(tmp);
1525 }
1526 break;
1528 case NR_CURVETO:
1529 {
1530 NR::Point tmp, tms, tme;
1531 tmp[0]=bpath[i].x3;
1532 tmp[1]=bpath[i].y3;
1533 tms[0]=3 * (bpath[i].x1 - lastX);
1534 tms[1]=3 * (bpath[i].y1 - lastY);
1535 tme[0]=3 * (bpath[i].x3 - bpath[i].x2);
1536 tme[1]=3 * (bpath[i].y3 - bpath[i].y2);
1537 dest->CubicTo(tmp,tms,tme);
1538 }
1539 lastX = bpath[i].x3;
1540 lastY = bpath[i].y3;
1541 break;
1543 case NR_MOVETO_OPEN:
1544 case NR_MOVETO:
1545 if (closed)
1546 dest->Close();
1547 closed = (bpath[i].code == NR_MOVETO);
1548 lastX = bpath[i].x3;
1549 lastY = bpath[i].y3;
1550 {
1551 NR::Point tmp(lastX, lastY);
1552 dest->MoveTo(tmp);
1553 }
1554 break;
1555 default:
1556 break;
1557 }
1558 }
1559 if (closed)
1560 dest->Close();
1561 }
1563 if ( doTransformation ) {
1564 if ( bpath ) nr_free(bpath);
1565 } else {
1566 sp_curve_unref(curve);
1567 }
1568 return dest;
1569 }
1571 NR::Maybe<Path::cut_position> get_nearest_position_on_Path(Path *path, NR::Point p)
1572 {
1573 //get nearest position on path
1574 Path::cut_position pos = path->PointToCurvilignPosition(p);
1575 return pos;
1576 }
1578 NR::Point get_point_on_Path(Path *path, int piece, double t)
1579 {
1580 NR::Point p;
1581 path->PointAt(piece, t, p);
1582 return p;
1583 }
1586 /*
1587 Local Variables:
1588 mode:c++
1589 c-file-style:"stroustrup"
1590 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1591 indent-tabs-mode:nil
1592 fill-column:99
1593 End:
1594 */
1595 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :