From: johanengelen Date: Fri, 4 Jul 2008 22:41:45 +0000 (+0000) Subject: convert a path to guides using 2geom calls X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1a32c2168b3c9c2150ffe55b7ec8e2c52805fb3a;p=inkscape.git convert a path to guides using 2geom calls --- diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 962be5cb5..8327cb88d 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -146,29 +146,27 @@ sp_path_convert_to_guides(SPItem *item) { SPPath *path = SP_PATH(item); - SPDocument *doc = SP_OBJECT_DOCUMENT(path); - std::list > pts; - - NR::Matrix const i2d (from_2geom(sp_item_i2d_affine(SP_ITEM(path)))); - SPCurve *curve = SP_SHAPE(path)->curve; if (!curve) return; - NArtBpath const *bpath = SP_CURVE_BPATH(curve); - - NR::Point last_pt; - NR::Point pt; - for (int i = 0; bpath[i].code != NR_END; i++){ - if (bpath[i].code == NR_LINETO) { - /* we only convert straight line segments (converting curve segments would be unintuitive) */ - pt = bpath[i].c(3) * i2d; - pts.push_back(std::make_pair(last_pt.to_2geom(), pt.to_2geom())); - } - /* remember current point for potential reuse in the next step - (e.g., in case this was an NR_MOVETO or NR_MOVETO_OPEN) */ - last_pt = bpath[i].c(3) * i2d; + std::list > pts; + + Geom::Matrix const i2d (sp_item_i2d_affine(SP_ITEM(path))); + + Geom::PathVector const & pv = curve->get_pathvector(); + for(Geom::PathVector::const_iterator pit = pv.begin(); pit != pv.end(); ++pit) { + for(Geom::Path::const_iterator cit = pit->begin(); cit != pit->end_default(); ++cit) { + // only add curves for straight line segments + if( dynamic_cast(&*cit) || + dynamic_cast(&*cit) || + dynamic_cast(&*cit) ) + { + pts.push_back(std::make_pair(cit->initialPoint() * i2d, cit->finalPoint() * i2d)); + } + } } + SPDocument *doc = SP_OBJECT_DOCUMENT(path); sp_guide_pt_pairs_to_guides(doc, pts); }