588d3ec0fa6a767f9827216177deb390d1bd15b3
1 #define INKSCAPE_LPEGROUPBBOX_CPP
3 /*
4 * Copyright (C) Steren Giannini 2008 <steren.giannini@gmail.com>
5 *
6 * Released under GNU GPL, read the file 'COPYING' for more information
7 */
9 #include "live_effects/lpegroupbbox.h"
10 #include "sp-shape.h"
11 #include "sp-item.h"
12 #include "sp-path.h"
13 #include "sp-item-group.h"
14 #include "display/curve.h"
15 #include <libnr/n-art-bpath.h>
16 #include <libnr/nr-matrix-fns.h>
17 #include "libnr/n-art-bpath-2geom.h"
18 #include "svg/svg.h"
19 #include "ui/widget/scalar.h"
21 #include <2geom/sbasis.h>
22 #include <2geom/sbasis-geometric.h>
23 #include <2geom/bezier-to-sbasis.h>
24 #include <2geom/sbasis-to-bezier.h>
25 #include <2geom/d2.h>
26 #include <2geom/piecewise.h>
28 #include <algorithm>
30 using std::vector;
32 namespace Inkscape {
33 namespace LivePathEffect {
35 void
36 GroupBBoxEffect::recursive_original_bbox(SPGroup *group, Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2, std::vector<Geom::Path> & temppath)
37 {
38 std::vector<Geom::Path> tempsubpath;
39 GSList const *item_list = sp_item_group_item_list(group);
41 for ( GSList const *iter = item_list; iter; iter = iter->next )
42 {
43 SPObject *subitem = static_cast<SPObject *>(iter->data);
44 if (SP_IS_PATH(subitem))
45 {
46 //if there is not an original-d, just take the d
47 if(SP_OBJECT_REPR(subitem)->attribute("inkscape:original-d") != NULL)
48 tempsubpath = SVGD_to_2GeomPath(SP_OBJECT_REPR(subitem)->attribute("inkscape:original-d"));
49 else
50 tempsubpath = SVGD_to_2GeomPath(SP_OBJECT_REPR(subitem)->attribute("d"));
52 temppath.insert(temppath.end(), tempsubpath.begin(), tempsubpath.end());
53 }
54 else if (SP_IS_GROUP(subitem))
55 {
56 recursive_original_bbox(SP_GROUP(subitem), pwd2, temppath);
57 }
58 }
59 }
61 void
62 GroupBBoxEffect::original_bbox(SPLPEItem *lpeitem)
63 {
65 using namespace Geom;
66 Piecewise<D2<SBasis> > pwd2;
67 std::vector<Geom::Path> temppath;
70 if (SP_IS_PATH(lpeitem))
71 {
72 //TODO : this won't work well with LPE stacking
73 temppath = SVGD_to_2GeomPath( SP_OBJECT_REPR(lpeitem)->attribute("inkscape:original-d"));
74 }
75 else if (SP_IS_GROUP(lpeitem))
76 {
77 recursive_original_bbox(SP_GROUP(lpeitem), pwd2, temppath);
78 }
80 for (unsigned int i=0; i < temppath.size(); i++) {
81 pwd2.concat( temppath[i].toPwSb() );
82 }
84 D2<Piecewise<SBasis> > d2pw = make_cuts_independant(pwd2);
85 boundingbox_X = bounds_exact(d2pw[0]);
86 boundingbox_Y = bounds_exact(d2pw[1]);
87 }
89 } // namespace LivePathEffect
90 } /* namespace Inkscape */
92 /*
93 Local Variables:
94 mode:c++
95 c-file-style:"stroustrup"
96 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
97 indent-tabs-mode:nil
98 fill-column:99
99 End:
100 */
101 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :