From 5209a05743e62584a7ec6afe050ffb0223f899f8 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Fri, 9 May 2008 09:37:08 +0000 Subject: [PATCH] - try to use more forward declarations for less dependencies on display/curve.h - change _bpath to private member of SPCurve, obtain and set with get_bpath and set_bpath. - added const methods, so protect changes to _bpath in SPCurve --- src/connector-context.cpp | 6 +- src/connector-context.h | 1 - src/display/canvas-axonomgrid.h | 1 - src/display/canvas-bpath.cpp | 4 +- src/display/canvas-grid.h | 1 - src/display/curve.cpp | 370 ++++++++++-------- src/display/curve.h | 45 ++- src/display/display-forward.h | 2 +- src/display/nr-arena-glyphs.h | 2 +- src/display/nr-arena-shape.cpp | 3 +- src/display/nr-arena-shape.h | 2 +- src/draw-context.cpp | 9 +- src/draw-context.h | 1 - src/dyna-draw-context.cpp | 18 +- src/dyna-draw-context.h | 1 - src/eraser-context.cpp | 16 +- src/extension/internal/pov-out.cpp | 2 +- src/libnrtype/Layout-TNG-Output.cpp | 1 + src/live_effects/effect.cpp | 11 +- src/live_effects/effect.h | 2 +- src/live_effects/lpe-bendpath.cpp | 4 +- src/live_effects/lpe-curvestitch.cpp | 4 +- src/live_effects/lpe-knot.cpp | 8 - src/live_effects/lpe-perspective_path.cpp | 2 - src/live_effects/lpe-skeleton.cpp | 18 - src/live_effects/lpe-skeleton.h | 1 - src/live_effects/lpe-sketch.cpp | 2 - src/live_effects/lpe-slant.cpp | 2 +- src/live_effects/lpe-spiro.cpp | 2 +- src/live_effects/lpe-vonkoch.cpp | 7 - src/live_effects/lpegroupbbox.cpp | 3 - src/live_effects/parameter/path-reference.cpp | 10 - src/nodepath.cpp | 2 +- src/object-snapper.cpp | 36 +- src/object-snapper.h | 6 +- src/path-chemistry.cpp | 4 +- src/pen-context.cpp | 2 +- src/pencil-context.cpp | 1 + src/sp-lpe-item.h | 2 +- src/sp-path.cpp | 4 +- src/sp-polygon.cpp | 4 +- src/sp-shape.cpp | 5 +- src/splivarot.cpp | 4 + src/tweak-context.cpp | 1 + src/tweak-context.h | 1 - src/verbs.cpp | 2 +- 46 files changed, 325 insertions(+), 310 deletions(-) diff --git a/src/connector-context.cpp b/src/connector-context.cpp index 07e512e06..3c1669fa6 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -73,7 +73,7 @@ #include "sp-namedview.h" #include "sp-text.h" #include "sp-flowtext.h" - +#include "display/curve.h" static void sp_connector_context_class_init(SPConnectorContextClass *klass); static void sp_connector_context_init(SPConnectorContext *conn_context); @@ -1252,7 +1252,7 @@ static bool cc_item_is_shape(SPItem *item) { if (SP_IS_PATH(item)) { SPCurve *curve = (SP_SHAPE(item))->curve; - if ( curve && !(curve->closed) ) { + if ( curve && !(curve->is_closed()) ) { // Open paths are connectors. return false; } @@ -1271,7 +1271,7 @@ bool cc_item_is_connector(SPItem *item) { if (SP_IS_PATH(item)) { if (SP_PATH(item)->connEndPair.isAutoRoutingConn()) { - g_assert( !(SP_SHAPE(item)->curve->closed) ); + g_assert( !(SP_SHAPE(item)->curve->is_closed()) ); return true; } } diff --git a/src/connector-context.h b/src/connector-context.h index 49c4c2a81..e8d9a4390 100644 --- a/src/connector-context.h +++ b/src/connector-context.h @@ -14,7 +14,6 @@ #include #include -#include "display/curve.h" #include "event-context.h" #include #include diff --git a/src/display/canvas-axonomgrid.h b/src/display/canvas-axonomgrid.h index 6c39860b9..668c59649 100644 --- a/src/display/canvas-axonomgrid.h +++ b/src/display/canvas-axonomgrid.h @@ -17,7 +17,6 @@ #include "ui/widget/registered-widget.h" #include "ui/widget/registry.h" -//#include "ui/widget/tolerance-slider.h" #include "xml/node-event-vector.h" diff --git a/src/display/canvas-bpath.cpp b/src/display/canvas-bpath.cpp index 6aa413623..a3327308c 100644 --- a/src/display/canvas-bpath.cpp +++ b/src/display/canvas-bpath.cpp @@ -142,7 +142,7 @@ sp_canvas_bpath_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i Path* thePath=new Path; thePath->LoadArtBPath(SP_CURVE_BPATH(cbp->curve), affine, true); thePath->Convert(0.25); - if ((cbp->fill_rgba & 0xff) && (cbp->curve->end > 2)) { + if ((cbp->fill_rgba & 0xff) && (cbp->curve->_end > 2)) { Shape* theShape=new Shape; thePath->Fill(theShape,0); if ( cbp->fill_shp == NULL ) cbp->fill_shp=new Shape; @@ -165,7 +165,7 @@ sp_canvas_bpath_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i } } } - if ((cbp->stroke_rgba & 0xff) && (cbp->curve->end > 1)) { + if ((cbp->stroke_rgba & 0xff) && (cbp->curve->_end > 1)) { JoinType join=join_straight; // Shape* theShape=new Shape; ButtType butt=butt_straight; diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h index 0ff2c65f1..a9e317534 100644 --- a/src/display/canvas-grid.h +++ b/src/display/canvas-grid.h @@ -23,7 +23,6 @@ #include "ui/widget/scalar-unit.h" #include "ui/widget/registered-widget.h" #include "ui/widget/registry.h" -//#include "ui/widget/tolerance-slider.h" #include "xml/node-event-vector.h" #include "snapper.h" #include "line-snapper.h" diff --git a/src/display/curve.cpp b/src/display/curve.cpp index e97b09744..5b2ac024b 100644 --- a/src/display/curve.cpp +++ b/src/display/curve.cpp @@ -16,7 +16,7 @@ * Released under GNU GPL */ -#include +#include "display/curve.h" #include #include @@ -38,16 +38,16 @@ static bool sp_bpath_closed(NArtBpath const bpath[]); * \param length Initial number of NArtBpath elements allocated for bpath (including NR_END * element). */ -SPCurve::SPCurve(gint length) - : refcount(1), +SPCurve::SPCurve(guint length) + : _refcount(1), _bpath(NULL), - end(0), - length(length), - substart(0), - hascpt(false), - posSet(false), - moving(false), - closed(false) + _end(0), + _length(length), + _substart(0), + _hascpt(false), + _posSet(false), + _moving(false), + _closed(false) { if (length <= 0) { g_error("SPCurve::SPCurve called with invalid length parameter"); @@ -71,15 +71,15 @@ SPCurve::new_from_foreign_bpath(NArtBpath const *bpath) SPCurve *curve = new SPCurve(); curve->_bpath = new_bpath; - curve->length = len; - curve->end = curve->length - 1; - gint i = curve->end; + curve->_length = len; + curve->_end = curve->_length - 1; + gint i = curve->_end; for (; i > 0; i--) if ((curve->_bpath[i].code == NR_MOVETO) || (curve->_bpath[i].code == NR_MOVETO_OPEN)) break; - curve->substart = i; - curve->closed = sp_bpath_closed(new_bpath); + curve->_substart = i; + curve->_closed = sp_bpath_closed(new_bpath); return curve; } @@ -128,7 +128,36 @@ SPCurve::~SPCurve() /* Methods */ /** - * Increase refcount of curve. + * Frees old path and sets new path + * This does not copy the bpath, so the new_bpath should not be deleted by caller + */ +void +SPCurve::set_bpath(NArtBpath * new_bpath) +{ + if (new_bpath && new_bpath != _bpath) { // FIXME, add function to SPCurve to change bpath? or a copy function? + if (_bpath) { + g_free(_bpath); //delete old bpath + } + _bpath = new_bpath; + } +} + +/** + * Get pointer to bpath data. Don't keep this reference too long, because the path might change by another function. + */ +NArtBpath const * +SPCurve::get_bpath() const +{ + return _bpath; +}; +NArtBpath * +SPCurve::get_bpath() +{ + return _bpath; +}; + +/** + * Increase _refcount of curve. * * \todo should this be shared with other refcounting code? */ @@ -137,7 +166,7 @@ SPCurve::ref() { g_return_val_if_fail(this != NULL, NULL); - refcount += 1; + _refcount += 1; return this; } @@ -152,9 +181,9 @@ SPCurve::unref() { g_return_val_if_fail(this != NULL, NULL); - refcount -= 1; + _refcount -= 1; - if (refcount < 1) { + if (_refcount < 1) { if (_bpath) { g_free(_bpath); _bpath = NULL; @@ -168,21 +197,21 @@ SPCurve::unref() /** * Add space for more paths in curve. */ -static void -sp_curve_ensure_space(SPCurve *curve, gint space) +void +SPCurve::ensure_space(guint space) { - g_return_if_fail(curve != NULL); + g_return_if_fail(this != NULL); g_return_if_fail(space > 0); - if (curve->end + space < curve->length) + if (_end + space < _length) return; if (space < SP_CURVE_LENSTEP) space = SP_CURVE_LENSTEP; - curve->_bpath = g_renew(NArtBpath, curve->_bpath, curve->length + space); + _bpath = g_renew(NArtBpath, _bpath, _length + space); - curve->length += space; + _length += space; } /** @@ -208,7 +237,7 @@ SPCurve::concat(GSList const *list) for (GSList const *l = list; l != NULL; l = l->next) { SPCurve *c = (SPCurve *) l->data; - length += c->end; + length += c->_end; } SPCurve *new_curve = new SPCurve(length + 1); @@ -217,21 +246,21 @@ SPCurve::concat(GSList const *list) for (GSList const *l = list; l != NULL; l = l->next) { SPCurve *c = (SPCurve *) l->data; - memcpy(bp, c->_bpath, c->end * sizeof(NArtBpath)); - bp += c->end; + memcpy(bp, c->_bpath, c->_end * sizeof(NArtBpath)); + bp += c->_end; } bp->code = NR_END; - new_curve->end = length; + new_curve->_end = length; gint i; - for (i = new_curve->end; i > 0; i--) { + for (i = new_curve->_end; i > 0; i--) { if ((new_curve->_bpath[i].code == NR_MOVETO) || (new_curve->_bpath[i].code == NR_MOVETO_OPEN) ) break; } - new_curve->substart = i; + new_curve->_substart = i; return new_curve; } @@ -247,18 +276,18 @@ SPCurve::split() const gint p = 0; GSList *l = NULL; - while (p < end) { + while (p < _end) { gint i = 1; while ((_bpath[p + i].code == NR_LINETO) || (_bpath[p + i].code == NR_CURVETO)) i++; SPCurve *new_curve = new SPCurve(i + 1); memcpy(new_curve->_bpath, _bpath + p, i * sizeof(NArtBpath)); - new_curve->end = i; + new_curve->_end = i; new_curve->_bpath[i].code = NR_END; - new_curve->substart = 0; - new_curve->closed = (new_curve->_bpath->code == NR_MOVETO); - new_curve->hascpt = (new_curve->_bpath->code == NR_MOVETO_OPEN); + new_curve->_substart = 0; + new_curve->_closed = (new_curve->_bpath->code == NR_MOVETO); + new_curve->_hascpt = (new_curve->_bpath->code == NR_MOVETO_OPEN); l = g_slist_prepend(l, new_curve); p += i; } @@ -275,7 +304,7 @@ tmpl_curve_transform(SPCurve *const curve, M const &m) { g_return_if_fail(curve != NULL); - for (gint i = 0; i < curve->end; i++) { + for (gint i = 0; i < curve->_end; i++) { NArtBpath *p = curve->_bpath + i; switch (p->code) { case NR_MOVETO: @@ -323,12 +352,12 @@ SPCurve::reset() g_return_if_fail(this != NULL); _bpath->code = NR_END; - end = 0; - substart = 0; - hascpt = false; - posSet = false; - moving = false; - closed = false; + _end = 0; + _substart = 0; + _hascpt = false; + _posSet = false; + _moving = false; + _closed = false; } /* Several consecutive movetos are ALLOWED */ @@ -349,12 +378,12 @@ void SPCurve::moveto(NR::Point const &p) { g_return_if_fail(this != NULL); - g_return_if_fail(!moving); + g_return_if_fail(!_moving); - substart = end; - hascpt = true; - posSet = true; - movePos = p; + _substart = _end; + _hascpt = true; + _posSet = true; + _movePos = p; } /** @@ -373,49 +402,49 @@ void SPCurve::lineto(gdouble x, gdouble y) { g_return_if_fail(this != NULL); - g_return_if_fail(hascpt); + g_return_if_fail(_hascpt); - if (moving) { + if (_moving) { /* fix endpoint */ - g_return_if_fail(!posSet); - g_return_if_fail(end > 1); - NArtBpath *bp = _bpath + end - 1; + g_return_if_fail(!_posSet); + g_return_if_fail(_end > 1); + NArtBpath *bp = _bpath + _end - 1; g_return_if_fail(bp->code == NR_LINETO); bp->x3 = x; bp->y3 = y; - moving = false; + _moving = false; return; } - if (posSet) { + if (_posSet) { /* start a new segment */ - sp_curve_ensure_space(this, 2); - NArtBpath *bp = _bpath + end; + ensure_space(2); + NArtBpath *bp = _bpath + _end; bp->code = NR_MOVETO_OPEN; - bp->setC(3, movePos); + bp->setC(3, _movePos); bp++; bp->code = NR_LINETO; bp->x3 = x; bp->y3 = y; bp++; bp->code = NR_END; - end += 2; - posSet = false; - closed = false; + _end += 2; + _posSet = false; + _closed = false; return; } /* add line */ - g_return_if_fail(end > 1); - sp_curve_ensure_space(this, 1); - NArtBpath *bp = _bpath + end; + g_return_if_fail(_end > 1); + ensure_space(1); + NArtBpath *bp = _bpath + _end; bp->code = NR_LINETO; bp->x3 = x; bp->y3 = y; bp++; bp->code = NR_END; - end++; + _end++; } /// Unused @@ -423,50 +452,50 @@ void SPCurve::lineto_moving(gdouble x, gdouble y) { g_return_if_fail(this != NULL); - g_return_if_fail(hascpt); + g_return_if_fail(_hascpt); - if (moving) { + if (_moving) { /* change endpoint */ - g_return_if_fail(!posSet); - g_return_if_fail(end > 1); - NArtBpath *bp = _bpath + end - 1; + g_return_if_fail(!_posSet); + g_return_if_fail(_end > 1); + NArtBpath *bp = _bpath + _end - 1; g_return_if_fail(bp->code == NR_LINETO); bp->x3 = x; bp->y3 = y; return; } - if (posSet) { + if (_posSet) { /* start a new segment */ - sp_curve_ensure_space(this, 2); - NArtBpath *bp = _bpath + end; + ensure_space(2); + NArtBpath *bp = _bpath + _end; bp->code = NR_MOVETO_OPEN; - bp->setC(3, movePos); + bp->setC(3, _movePos); bp++; bp->code = NR_LINETO; bp->x3 = x; bp->y3 = y; bp++; bp->code = NR_END; - end += 2; - posSet = false; - moving = true; - closed = false; + _end += 2; + _posSet = false; + _moving = true; + _closed = false; return; } /* add line */ - g_return_if_fail(end > 1); - sp_curve_ensure_space(this, 1); - NArtBpath *bp = _bpath + end; + g_return_if_fail(_end > 1); + ensure_space(1); + NArtBpath *bp = _bpath + _end; bp->code = NR_LINETO; bp->x3 = x; bp->y3 = y; bp++; bp->code = NR_END; - end++; - moving = true; + _end++; + _moving = true; } /** @@ -489,15 +518,15 @@ void SPCurve::curveto(gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdouble y2) { g_return_if_fail(this != NULL); - g_return_if_fail(hascpt); - g_return_if_fail(!moving); + g_return_if_fail(_hascpt); + g_return_if_fail(!_moving); - if (posSet) { + if (_posSet) { /* start a new segment */ - sp_curve_ensure_space(this, 2); - NArtBpath *bp = _bpath + end; + ensure_space(2); + NArtBpath *bp = _bpath + _end; bp->code = NR_MOVETO_OPEN; - bp->setC(3, movePos); + bp->setC(3, _movePos); bp++; bp->code = NR_CURVETO; bp->x1 = x0; @@ -508,17 +537,17 @@ SPCurve::curveto(gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdo bp->y3 = y2; bp++; bp->code = NR_END; - end += 2; - posSet = false; - closed = false; + _end += 2; + _posSet = false; + _closed = false; return; } /* add curve */ - g_return_if_fail(end > 1); - sp_curve_ensure_space(this, 1); - NArtBpath *bp = _bpath + end; + g_return_if_fail(_end > 1); + ensure_space(1); + NArtBpath *bp = _bpath + _end; bp->code = NR_CURVETO; bp->x1 = x0; bp->y1 = y0; @@ -528,7 +557,7 @@ SPCurve::curveto(gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdo bp->y3 = y2; bp++; bp->code = NR_END; - end++; + _end++; } /** @@ -538,25 +567,25 @@ void SPCurve::closepath() { g_return_if_fail(this != NULL); - g_return_if_fail(hascpt); - g_return_if_fail(!posSet); - g_return_if_fail(!moving); - g_return_if_fail(!closed); + g_return_if_fail(_hascpt); + g_return_if_fail(!_posSet); + g_return_if_fail(!_moving); + g_return_if_fail(!_closed); /* We need at least moveto, curveto, end. */ - g_return_if_fail(end - substart > 1); + g_return_if_fail(_end - _substart > 1); { - NArtBpath *bs = _bpath + substart; - NArtBpath *be = _bpath + end - 1; + NArtBpath *bs = _bpath + _substart; + NArtBpath *be = _bpath + _end - 1; if (bs->c(3) != be->c(3)) { lineto(bs->c(3)); - bs = _bpath + substart; + bs = _bpath + _substart; } bs->code = NR_MOVETO; } - closed = true; + _closed = true; for (NArtBpath const *bp = _bpath; bp->code != NR_END; bp++) { /** \todo @@ -564,12 +593,12 @@ SPCurve::closepath() * the closed boolean). */ if (bp->code == NR_MOVETO_OPEN) { - closed = false; + _closed = false; break; } } - hascpt = false; + _hascpt = false; } /** Like SPCurve::closepath() but sets the end point of the current @@ -581,22 +610,22 @@ void SPCurve::closepath_current() { g_return_if_fail(this != NULL); - g_return_if_fail(hascpt); - g_return_if_fail(!posSet); - g_return_if_fail(!closed); + g_return_if_fail(_hascpt); + g_return_if_fail(!_posSet); + g_return_if_fail(!_closed); /* We need at least moveto, curveto, end. */ - g_return_if_fail(end - substart > 1); + g_return_if_fail(_end - _substart > 1); { - NArtBpath *bs = _bpath + substart; - NArtBpath *be = _bpath + end - 1; + NArtBpath *bs = _bpath + _substart; + NArtBpath *be = _bpath + _end - 1; be->x3 = bs->x3; be->y3 = bs->y3; bs->code = NR_MOVETO; } - closed = true; + _closed = true; for (NArtBpath const *bp = _bpath; bp->code != NR_END; bp++) { /** \todo @@ -604,13 +633,13 @@ SPCurve::closepath_current() * the closed boolean). */ if (bp->code == NR_MOVETO_OPEN) { - closed = false; + _closed = false; break; } } - hascpt = false; - moving = false; + _hascpt = false; + _moving = false; } /** @@ -624,6 +653,15 @@ SPCurve::is_empty() const return (_bpath->code == NR_END); } +/** + * True iff all subpaths are closed. + */ +bool +SPCurve::is_closed() const +{ + return _closed; +} + /** * Return last subpath or NULL. */ @@ -632,11 +670,11 @@ SPCurve::last_bpath() const { g_return_val_if_fail(this != NULL, NULL); - if (end == 0) { + if (_end == 0) { return NULL; } - return _bpath + end - 1; + return _bpath + _end - 1; } /** @@ -647,7 +685,7 @@ SPCurve::first_bpath() const { g_return_val_if_fail(this != NULL, NULL); - if (end == 0) { + if (_end == 0) { return NULL; } @@ -666,19 +704,19 @@ SPCurve::first_point() const } /** - * Return the second point of first subpath or movePos if curve too short. + * Return the second point of first subpath or _movePos if curve too short. */ NR::Point SPCurve::second_point() const { g_return_val_if_fail(this != NULL, NR::Point(0, 0)); - if (end < 1) { - return movePos; + if (_end < 1) { + return _movePos; } NArtBpath *bpath = NULL; - if (end < 2) { + if (_end < 2) { bpath = _bpath; } else { bpath = _bpath + 1; @@ -688,18 +726,18 @@ SPCurve::second_point() const } /** - * Return the second-last point of last subpath or movePos if curve too short. + * Return the second-last point of last subpath or _movePos if curve too short. */ NR::Point SPCurve::penultimate_point() const { g_return_val_if_fail(this != NULL, NR::Point(0, 0)); - if (end < 2) { - return movePos; + if (_end < 2) { + return _movePos; } - NArtBpath *const bpath = _bpath + end - 2; + NArtBpath *const bpath = _bpath + _end - 2; g_return_val_if_fail(bpath != NULL, NR::Point(0, 0)); return bpath->c(3); } @@ -722,30 +760,30 @@ is_moveto(NRPathcode const c) } /** - * Returns \a curve but drawn in the opposite direction. + * Returns a *new* \a curve but drawn in the opposite direction. * Should result in the same shape, but * with all its markers drawn facing the other direction. **/ SPCurve * -SPCurve::reverse() const +SPCurve::create_reverse() const { /* We need at least moveto, curveto, end. */ - g_return_val_if_fail(end - substart > 1, NULL); + g_return_val_if_fail(_end - _substart > 1, NULL); - NArtBpath const *be = _bpath + end - 1; + NArtBpath const *be = _bpath + _end - 1; - g_assert(is_moveto(_bpath[substart].code)); + g_assert(is_moveto(_bpath[_substart].code)); g_assert(is_moveto(_bpath[0].code)); g_assert((be+1)->code == NR_END); - SPCurve *new_curve = new SPCurve(length); + SPCurve *new_curve = new SPCurve(_length); new_curve->moveto(be->c(3)); for (NArtBpath const *bp = be; ; --bp) { switch (bp->code) { case NR_MOVETO: - g_assert(new_curve->_bpath[new_curve->substart].code == NR_MOVETO_OPEN); - new_curve->_bpath[new_curve->substart].code = NR_MOVETO; + g_assert(new_curve->_bpath[new_curve->_substart].code == NR_MOVETO_OPEN); + new_curve->_bpath[new_curve->_substart].code = NR_MOVETO; /* FALL-THROUGH */ case NR_MOVETO_OPEN: if (bp == _bpath) { @@ -778,35 +816,35 @@ SPCurve::append(SPCurve const *curve2, g_return_if_fail(this != NULL); g_return_if_fail(curve2 != NULL); - if (curve2->end < 1) + if (curve2->_end < 1) return; NArtBpath const *bs = curve2->_bpath; - bool _closed = this->closed; + bool closed = this->_closed; for (NArtBpath const *bp = bs; bp->code != NR_END; bp++) { switch (bp->code) { case NR_MOVETO_OPEN: - if (use_lineto && hascpt) { + if (use_lineto && _hascpt) { lineto(bp->x3, bp->y3); use_lineto = FALSE; } else { - if (_closed) closepath(); + if (closed) closepath(); moveto(bp->x3, bp->y3); } - _closed = false; + closed = false; break; case NR_MOVETO: - if (use_lineto && hascpt) { + if (use_lineto && _hascpt) { lineto(bp->x3, bp->y3); use_lineto = FALSE; } else { - if (_closed) closepath(); + if (closed) closepath(); moveto(bp->x3, bp->y3); } - _closed = true; + closed = true; break; case NR_LINETO: @@ -822,7 +860,7 @@ SPCurve::append(SPCurve const *curve2, } } - if (_closed) { + if (closed) { closepath(); } } @@ -835,10 +873,10 @@ SPCurve::append_continuous(SPCurve const *c1, gdouble tolerance) { g_return_val_if_fail(this != NULL, NULL); g_return_val_if_fail(c1 != NULL, NULL); - g_return_val_if_fail(!closed, NULL); - g_return_val_if_fail(!c1->closed, NULL); + g_return_val_if_fail(!_closed, NULL); + g_return_val_if_fail(!c1->_closed, NULL); - if (c1->end < 1) { + if (c1->_end < 1) { return this; } @@ -853,18 +891,18 @@ SPCurve::append_continuous(SPCurve const *c1, gdouble tolerance) * fixme: Strictly we mess in case of multisegment mixed * open/close curves */ - bool _closed = false; + bool closed = false; for (bs = bs + 1; bs->code != NR_END; bs++) { switch (bs->code) { case NR_MOVETO_OPEN: - if (_closed) closepath(); + if (closed) closepath(); moveto(bs->x3, bs->y3); - _closed = false; + closed = false; break; case NR_MOVETO: - if (_closed) closepath(); + if (closed) closepath(); moveto(bs->x3, bs->y3); - _closed = true; + closed = true; break; case NR_LINETO: lineto(bs->x3, bs->y3); @@ -894,21 +932,21 @@ SPCurve::backspace() { g_return_if_fail(this != NULL); - if (end > 0) { - end -= 1; - if (end > 0) { - NArtBpath *bp = _bpath + end - 1; + if (_end > 0) { + _end -= 1; + if (_end > 0) { + NArtBpath *bp = _bpath + _end - 1; if ((bp->code == NR_MOVETO) || (bp->code == NR_MOVETO_OPEN) ) { - hascpt = true; - posSet = true; - closed = false; - movePos = bp->c(3); - end -= 1; + _hascpt = true; + _posSet = true; + _closed = false; + _movePos = bp->c(3); + _end -= 1; } } - _bpath[end].code = NR_END; + _bpath[_end].code = NR_END; } } @@ -993,7 +1031,7 @@ bezier_len(NR::Point const &c0, /** * Returns total length of curve, excluding length of closepath segments. */ -static double +double sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[]) { g_return_val_if_fail(curve != NULL, 0.); @@ -1005,7 +1043,7 @@ sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[]) } NR::Point prev(curve->_bpath->c(3)); - for (gint i = 1; i < curve->end; ++i) { + for (gint i = 1; i < curve->_end; ++i) { NArtBpath &p = curve->_bpath[i]; double seg_len = 0; switch (p.code) { @@ -1034,7 +1072,7 @@ sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[]) * Like sp_curve_distance_including_space(), but ensures that the * result >= 1e-18: uses 1 per segment if necessary. */ -static double +double sp_curve_nonzero_distance_including_space(SPCurve const *const curve, double seg2len[]) { double const real_dist(sp_curve_distance_including_space(curve, seg2len)); diff --git a/src/display/curve.h b/src/display/curve.h index 9cbb11529..28fce3132 100644 --- a/src/display/curve.h +++ b/src/display/curve.h @@ -27,27 +27,28 @@ class SPCurve { public: /* Constructors */ - SPCurve(gint length = SP_CURVE_LENSTEP); + SPCurve(guint length = SP_CURVE_LENSTEP); static SPCurve * new_from_bpath(NArtBpath *bpath); static SPCurve * new_from_foreign_bpath(NArtBpath const *bpath); static SPCurve * new_from_rect(NR::Maybe const &rect); virtual ~SPCurve(); - gint refcount; - NArtBpath *_bpath; - + void set_bpath(NArtBpath * new_bpath); + NArtBpath const * get_bpath() const; + NArtBpath * get_bpath(); + /// Index in bpath[] of NR_END element. - gint end; + guint _end; /// Allocated size (i.e., capacity) of bpath[] array. Not to be confused /// with the SP_CURVE_LENGTH macro, which returns the logical length of /// the path (i.e., index of NR_END). - gint length; + guint _length; /// Index in bpath[] of the start (i.e., moveto element) of the last /// subpath in this path. - gint substart; + guint _substart; /// Previous moveto position. /// \note This is used for coalescing moveto's, whereas if we're to @@ -55,21 +56,21 @@ public: /// midpoint markers. Ref: /// http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes /// (first subitem of the item about zero-length path segments) - NR::Point movePos; + NR::Point _movePos; /// True iff current point is defined. Initially false for a new curve; /// becomes true after moveto; becomes false on closepath. Curveto, /// lineto etc. require hascpt; hascpt remains true after lineto/curveto. - bool hascpt : 1; + bool _hascpt : 1; /// True iff previous was moveto. - bool posSet : 1; + bool _posSet : 1; /// True iff bpath end is moving. - bool moving : 1; + bool _moving : 1; /// True iff all subpaths are closed. - bool closed : 1; + bool _closed : 1; SPCurve * ref(); SPCurve * unref(); @@ -97,6 +98,7 @@ public: SPCurve * append_continuous(SPCurve const *c1, gdouble tolerance); bool is_empty() const; + bool is_closed() const; NArtBpath * last_bpath() const; NArtBpath * first_bpath() const; NR::Point first_point() const; @@ -105,20 +107,31 @@ public: NR::Point penultimate_point() const; void append(SPCurve const *curve2, bool use_lineto); - SPCurve * reverse() const; + SPCurve * create_reverse() const; void backspace(); static SPCurve * concat(GSList const *list); + void ensure_space(guint space); + +protected: + gint _refcount; + + NArtBpath *_bpath; + private: // Don't implement these: SPCurve(const SPCurve&); SPCurve& operator=(const SPCurve&); + + friend double sp_curve_distance_including_space(SPCurve const *const curve, double seg2len[]); + friend double sp_curve_nonzero_distance_including_space(SPCurve const *const curve, double seg2len[]); + template friend void tmpl_curve_transform(SPCurve *const curve, M const &m); }; -#define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->end) -#define SP_CURVE_BPATH(c) (((SPCurve const *)(c))->_bpath) -#define SP_CURVE_SEGMENT(c,i) (((SPCurve const *)(c))->_bpath + (i)) +#define SP_CURVE_LENGTH(c) (((SPCurve const *)(c))->_end) +#define SP_CURVE_BPATH(c) ((c)->get_bpath()) +#define SP_CURVE_SEGMENT(c,i) ((c)->get_bpath() + (i)) #endif /* !SEEN_DISPLAY_CURVE_H */ diff --git a/src/display/display-forward.h b/src/display/display-forward.h index 191aac61f..25c4a6e3d 100644 --- a/src/display/display-forward.h +++ b/src/display/display-forward.h @@ -9,7 +9,7 @@ struct SPCanvasItem; typedef struct _SPCanvasItemClass SPCanvasItemClass; struct SPCanvasGroup; struct SPCanvasGroupClass; -struct SPCurve; +class SPCurve; namespace Inkscape { namespace Display { diff --git a/src/display/nr-arena-glyphs.h b/src/display/nr-arena-glyphs.h index 0c0121160..ebf5cee6d 100644 --- a/src/display/nr-arena-glyphs.h +++ b/src/display/nr-arena-glyphs.h @@ -19,7 +19,7 @@ #include -#include +#include #include #include #include diff --git a/src/display/nr-arena-shape.cpp b/src/display/nr-arena-shape.cpp index 4df93a9a2..aba06068e 100644 --- a/src/display/nr-arena-shape.cpp +++ b/src/display/nr-arena-shape.cpp @@ -17,6 +17,7 @@ #include #include #include +#include "display/curve.h" #include #include #include @@ -431,7 +432,7 @@ void nr_arena_shape_update_fill(NRArenaShape *shape, NRGC *gc, NRRectL *area, bool force_shape) { if ((shape->_fill.paint.type() != NRArenaShape::Paint::NONE || force_shape) && - ((shape->curve->end > 2) || (SP_CURVE_BPATH(shape->curve)[1].code == NR_CURVETO)) ) { + ((shape->curve->_end > 2) || (SP_CURVE_BPATH(shape->curve)[1].code == NR_CURVETO)) ) { if (TRUE || !shape->fill_shp) { NR::Matrix cached_to_new = NR::identity(); int isometry = 0; diff --git a/src/display/nr-arena-shape.h b/src/display/nr-arena-shape.h index b371d2ede..2b56fbf75 100644 --- a/src/display/nr-arena-shape.h +++ b/src/display/nr-arena-shape.h @@ -17,7 +17,7 @@ #define NR_ARENA_SHAPE(obj) (NR_CHECK_INSTANCE_CAST ((obj), NR_TYPE_ARENA_SHAPE, NRArenaShape)) #define NR_IS_ARENA_SHAPE(obj) (NR_CHECK_INSTANCE_TYPE ((obj), NR_TYPE_ARENA_SHAPE)) -#include "display/curve.h" +#include "display/display-forward.h" #include "display/canvas-bpath.h" #include "forward.h" #include "sp-paint-server.h" diff --git a/src/draw-context.cpp b/src/draw-context.cpp index b48b34ed0..50799b55f 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -25,6 +25,7 @@ #include "svg/svg.h" #include #include "libnr/n-art-bpath.h" +#include "display/curve.h" #include "desktop.h" #include "desktop-affine.h" #include "desktop-handles.h" @@ -288,7 +289,7 @@ spdc_attach_selection(SPDrawContext *dc, Inkscape::Selection */*sel*/) for (GSList *l = dc->white_curves; l != NULL; l = l->next) { SPCurve *c; c = (SPCurve*)l->data; - g_return_if_fail( c->end > 1 ); + g_return_if_fail( c->_end > 1 ); if ( SP_CURVE_BPATH(c)->code == NR_MOVETO_OPEN ) { NArtBpath *s, *e; SPDrawAnchor *a; @@ -378,7 +379,7 @@ void spdc_endpoint_snap_free(SPEventContext const * const ec, NR::Point& p, guin static SPCurve * reverse_then_unref(SPCurve *orig) { - SPCurve *ret = orig->reverse(); + SPCurve *ret = orig->create_reverse(); orig->unref(); return ret; } @@ -431,11 +432,11 @@ spdc_concat_colors_and_flush(SPDrawContext *dc, gboolean forceclosed) if ( dc->sa && dc->ea && ( dc->sa->curve == dc->ea->curve ) && ( ( dc->sa != dc->ea ) - || dc->sa->curve->closed ) ) + || dc->sa->curve->is_closed() ) ) { // We hit bot start and end of single curve, closing paths SP_EVENT_CONTEXT_DESKTOP(dc)->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Closing path.")); - if (dc->sa->start && !(dc->sa->curve->closed) ) { + if (dc->sa->start && !(dc->sa->curve->is_closed()) ) { c = reverse_then_unref(c); } dc->sa->curve->append_continuous(c, 0.0625); diff --git a/src/draw-context.h b/src/draw-context.h index 59ec5a92f..5ac1a7d09 100644 --- a/src/draw-context.h +++ b/src/draw-context.h @@ -15,7 +15,6 @@ */ #include -#include "display/curve.h" #include "event-context.h" #include #include diff --git a/src/dyna-draw-context.cpp b/src/dyna-draw-context.cpp index 4de36d0d7..cc79dfd2e 100644 --- a/src/dyna-draw-context.cpp +++ b/src/dyna-draw-context.cpp @@ -35,7 +35,7 @@ #include "svg/svg.h" #include "display/canvas-bpath.h" #include "display/bezier-utils.h" - +#include "display/curve.h" #include #include "macros.h" #include "document.h" @@ -1127,24 +1127,24 @@ accumulate_calligraphic(SPDynaDrawContext *dc) { if ( !dc->cal1->is_empty() && !dc->cal2->is_empty() ) { dc->accumulated->reset(); /* Is this required ?? */ - SPCurve *rev_cal2 = dc->cal2->reverse(); + SPCurve *rev_cal2 = dc->cal2->create_reverse(); - g_assert(dc->cal1->end > 1); - g_assert(rev_cal2->end > 1); + g_assert(dc->cal1->_end > 1); + g_assert(rev_cal2->_end > 1); g_assert(SP_CURVE_SEGMENT(dc->cal1, 0)->code == NR_MOVETO_OPEN); g_assert(SP_CURVE_SEGMENT(rev_cal2, 0)->code == NR_MOVETO_OPEN); g_assert(SP_CURVE_SEGMENT(dc->cal1, 1)->code == NR_CURVETO); g_assert(SP_CURVE_SEGMENT(rev_cal2, 1)->code == NR_CURVETO); - g_assert(SP_CURVE_SEGMENT(dc->cal1, dc->cal1->end-1)->code == NR_CURVETO); - g_assert(SP_CURVE_SEGMENT(rev_cal2, rev_cal2->end-1)->code == NR_CURVETO); + g_assert(SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->code == NR_CURVETO); + g_assert(SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->code == NR_CURVETO); dc->accumulated->append(dc->cal1, FALSE); - add_cap(dc->accumulated, SP_CURVE_SEGMENT(dc->cal1, dc->cal1->end-1)->c(2), SP_CURVE_SEGMENT(dc->cal1, dc->cal1->end-1)->c(3), SP_CURVE_SEGMENT(rev_cal2, 0)->c(3), SP_CURVE_SEGMENT(rev_cal2, 1)->c(1), dc->cap_rounding); + add_cap(dc->accumulated, SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->c(2), SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->c(3), SP_CURVE_SEGMENT(rev_cal2, 0)->c(3), SP_CURVE_SEGMENT(rev_cal2, 1)->c(1), dc->cap_rounding); dc->accumulated->append(rev_cal2, TRUE); - add_cap(dc->accumulated, SP_CURVE_SEGMENT(rev_cal2, rev_cal2->end-1)->c(2), SP_CURVE_SEGMENT(rev_cal2, rev_cal2->end-1)->c(3), SP_CURVE_SEGMENT(dc->cal1, 0)->c(3), SP_CURVE_SEGMENT(dc->cal1, 1)->c(1), dc->cap_rounding); + add_cap(dc->accumulated, SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->c(2), SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->c(3), SP_CURVE_SEGMENT(dc->cal1, 0)->c(3), SP_CURVE_SEGMENT(dc->cal1, 1)->c(1), dc->cap_rounding); dc->accumulated->closepath(); @@ -1183,7 +1183,7 @@ fit_and_split(SPDynaDrawContext *dc, gboolean release) #endif /* Current calligraphic */ - if ( dc->cal1->end == 0 || dc->cal2->end == 0 ) { + if ( dc->cal1->_end == 0 || dc->cal2->_end == 0 ) { /* dc->npoints > 0 */ /* g_print("calligraphics(1|2) reset\n"); */ dc->cal1->reset(); diff --git a/src/dyna-draw-context.h b/src/dyna-draw-context.h index b3561b59a..40e6c6376 100644 --- a/src/dyna-draw-context.h +++ b/src/dyna-draw-context.h @@ -18,7 +18,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "display/curve.h" #include "event-context.h" #include #include diff --git a/src/eraser-context.cpp b/src/eraser-context.cpp index 295e75e87..3fe661f99 100644 --- a/src/eraser-context.cpp +++ b/src/eraser-context.cpp @@ -964,24 +964,24 @@ accumulate_eraser(SPEraserContext *dc) { if ( !dc->cal1->is_empty() && !dc->cal2->is_empty() ) { dc->accumulated->reset(); /* Is this required ?? */ - SPCurve *rev_cal2 = dc->cal2->reverse(); + SPCurve *rev_cal2 = dc->cal2->create_reverse(); - g_assert(dc->cal1->end > 1); - g_assert(rev_cal2->end > 1); + g_assert(dc->cal1->_end > 1); + g_assert(rev_cal2->_end > 1); g_assert(SP_CURVE_SEGMENT(dc->cal1, 0)->code == NR_MOVETO_OPEN); g_assert(SP_CURVE_SEGMENT(rev_cal2, 0)->code == NR_MOVETO_OPEN); g_assert(SP_CURVE_SEGMENT(dc->cal1, 1)->code == NR_CURVETO); g_assert(SP_CURVE_SEGMENT(rev_cal2, 1)->code == NR_CURVETO); - g_assert(SP_CURVE_SEGMENT(dc->cal1, dc->cal1->end-1)->code == NR_CURVETO); - g_assert(SP_CURVE_SEGMENT(rev_cal2, rev_cal2->end-1)->code == NR_CURVETO); + g_assert(SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->code == NR_CURVETO); + g_assert(SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->code == NR_CURVETO); dc->accumulated->append(dc->cal1, FALSE); - add_cap(dc->accumulated, SP_CURVE_SEGMENT(dc->cal1, dc->cal1->end-1)->c(2), SP_CURVE_SEGMENT(dc->cal1, dc->cal1->end-1)->c(3), SP_CURVE_SEGMENT(rev_cal2, 0)->c(3), SP_CURVE_SEGMENT(rev_cal2, 1)->c(1), dc->cap_rounding); + add_cap(dc->accumulated, SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->c(2), SP_CURVE_SEGMENT(dc->cal1, dc->cal1->_end-1)->c(3), SP_CURVE_SEGMENT(rev_cal2, 0)->c(3), SP_CURVE_SEGMENT(rev_cal2, 1)->c(1), dc->cap_rounding); dc->accumulated->append(rev_cal2, TRUE); - add_cap(dc->accumulated, SP_CURVE_SEGMENT(rev_cal2, rev_cal2->end-1)->c(2), SP_CURVE_SEGMENT(rev_cal2, rev_cal2->end-1)->c(3), SP_CURVE_SEGMENT(dc->cal1, 0)->c(3), SP_CURVE_SEGMENT(dc->cal1, 1)->c(1), dc->cap_rounding); + add_cap(dc->accumulated, SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->c(2), SP_CURVE_SEGMENT(rev_cal2, rev_cal2->_end-1)->c(3), SP_CURVE_SEGMENT(dc->cal1, 0)->c(3), SP_CURVE_SEGMENT(dc->cal1, 1)->c(1), dc->cap_rounding); dc->accumulated->closepath(); @@ -1020,7 +1020,7 @@ fit_and_split(SPEraserContext *dc, gboolean release) #endif /* Current eraser */ - if ( dc->cal1->end == 0 || dc->cal2->end == 0 ) { + if ( dc->cal1->_end == 0 || dc->cal2->_end == 0 ) { /* dc->npoints > 0 */ /* g_print("erasers(1|2) reset\n"); */ dc->cal1->reset(); diff --git a/src/extension/internal/pov-out.cpp b/src/extension/internal/pov-out.cpp index 0f04c6a1a..6dd62206c 100644 --- a/src/extension/internal/pov-out.cpp +++ b/src/extension/internal/pov-out.cpp @@ -330,7 +330,7 @@ void PovOutput::doCurves(SPDocument *doc) //Count the NR_CURVETOs/LINETOs int segmentCount=0; - NArtBpath *bp = SP_CURVE_BPATH(curve); + NArtBpath const *bp = SP_CURVE_BPATH(curve); for (int curveNr=0 ; curveNrcode == NR_CURVETO || bp->code == NR_LINETO) segmentCount++; diff --git a/src/libnrtype/Layout-TNG-Output.cpp b/src/libnrtype/Layout-TNG-Output.cpp index 5fa20c81c..f3fac4218 100755 --- a/src/libnrtype/Layout-TNG-Output.cpp +++ b/src/libnrtype/Layout-TNG-Output.cpp @@ -20,6 +20,7 @@ #include "font-instance.h" #include "svg/svg-length.h" #include "extension/internal/cairo-render-context.h" +#include "display/curve.h" namespace Inkscape { namespace Extension { diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 2cd88fd8b..f699248e4 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -164,18 +164,13 @@ Effect::doBeforeEffect (SPLPEItem */*lpeitem*/) void Effect::doEffect (SPCurve * curve) { - NArtBpath *new_bpath = doEffect_nartbpath(SP_CURVE_BPATH(curve)); + NArtBpath *new_bpath = doEffect_nartbpath(curve->get_bpath()); - if (new_bpath && new_bpath != SP_CURVE_BPATH(curve)) { // FIXME, add function to SPCurve to change bpath? or a copy function? - if (curve->_bpath) { - g_free(curve->_bpath); //delete old bpath - } - curve->_bpath = new_bpath; - } + curve->set_bpath(new_bpath); } NArtBpath * -Effect::doEffect_nartbpath (NArtBpath * path_in) +Effect::doEffect_nartbpath (NArtBpath const * path_in) { try { std::vector orig_pathv = BPath_to_2GeomPath(path_in); diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 58010358f..7ab4537f9 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -112,7 +112,7 @@ protected: // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling // doEffect(std::vector ) virtual NArtBpath * - doEffect_nartbpath (NArtBpath * path_in); + doEffect_nartbpath (NArtBpath const * path_in) __attribute__ ((deprecated)); virtual std::vector doEffect_path (std::vector const & path_in); virtual Geom::Piecewise > diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index c37f34ce7..6b9fbbb97 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -12,9 +12,7 @@ #include "sp-item.h" #include "sp-path.h" #include "sp-item-group.h" -#include "display/curve.h" -#include -#include +//#include #include "libnr/n-art-bpath-2geom.h" #include "svg/svg.h" #include "ui/widget/scalar.h" diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index 22f20b820..9cf9f2f26 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -14,8 +14,7 @@ */ #include "live_effects/lpe-curvestitch.h" -#include "display/curve.h" -#include + #include "sp-item.h" #include "sp-path.h" #include "libnr/n-art-bpath-2geom.h" @@ -30,7 +29,6 @@ #include <2geom/d2.h> #include <2geom/matrix.h> - #include "ui/widget/scalar.h" #include "libnr/nr-values.h" diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index 245b6df0f..5ac4a98d4 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -12,17 +12,9 @@ */ #include "live_effects/lpe-knot.h" -#include "display/curve.h" -#include #include <2geom/path.h> -//#include <2geom/sbasis.h> -//#include <2geom/sbasis-geometric.h> -//#include <2geom/bezier-to-sbasis.h> -//#include <2geom/sbasis-to-bezier.h> #include <2geom/d2.h> -//#include <2geom/sbasis-math.h> -//#include <2geom/piecewise.h> #include <2geom/crossing.h> #include <2geom/path-intersection.h> diff --git a/src/live_effects/lpe-perspective_path.cpp b/src/live_effects/lpe-perspective_path.cpp index 5be5970c1..57bc458a9 100644 --- a/src/live_effects/lpe-perspective_path.cpp +++ b/src/live_effects/lpe-perspective_path.cpp @@ -26,8 +26,6 @@ #include "document.h" #include "live_effects/lpe-perspective_path.h" -#include "display/curve.h" -#include #include "sp-item-group.h" #include "inkscape.h" diff --git a/src/live_effects/lpe-skeleton.cpp b/src/live_effects/lpe-skeleton.cpp index 571503d8e..04d61bd73 100644 --- a/src/live_effects/lpe-skeleton.cpp +++ b/src/live_effects/lpe-skeleton.cpp @@ -20,8 +20,6 @@ */ #include "live_effects/lpe-skeleton.h" -#include "display/curve.h" -#include // You might need to include other 2geom files. You can add them here: #include <2geom/path.h> @@ -55,22 +53,6 @@ LPESkeleton::doEffect (SPCurve * curve) // spice this up to make the effect actually *do* something! } -NArtBpath * -LPESkeleton::doEffect_nartbpath (NArtBpath * path_in) -{ - NArtBpath *path_out; - unsigned ret = 0; - while ( path_in[ret].code != NR_END ) { - ++ret; - } - unsigned len = ++ret; - path_out = g_new(NArtBpath, len); - - memcpy(path_out, path_in, len * sizeof(NArtBpath)); // spice this up to make the effect actually *do* something! - - return path_out; -} - std::vector LPESkeleton::doEffect_path (std::vector & path_in) { diff --git a/src/live_effects/lpe-skeleton.h b/src/live_effects/lpe-skeleton.h index 290b8a724..6522e9ca3 100644 --- a/src/live_effects/lpe-skeleton.h +++ b/src/live_effects/lpe-skeleton.h @@ -28,7 +28,6 @@ public: // Choose to implement one of the doEffect functions. You can delete or comment out the others. // virtual void doEffect (SPCurve * curve); -// virtual NArtBpath * doEffect_nartbpath (NArtBpath * path_in); // virtual std::vector doEffect_path (std::vector & path_in); virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); diff --git a/src/live_effects/lpe-sketch.cpp b/src/live_effects/lpe-sketch.cpp index 4fc6fc35d..d03200941 100644 --- a/src/live_effects/lpe-sketch.cpp +++ b/src/live_effects/lpe-sketch.cpp @@ -12,8 +12,6 @@ */ #include "live_effects/lpe-sketch.h" -#include "display/curve.h" -#include // You might need to include other 2geom files. You can add them here: #include <2geom/path.h> diff --git a/src/live_effects/lpe-slant.cpp b/src/live_effects/lpe-slant.cpp index 407e43992..7382d15e2 100644 --- a/src/live_effects/lpe-slant.cpp +++ b/src/live_effects/lpe-slant.cpp @@ -29,7 +29,7 @@ LPESlant::~LPESlant() void LPESlant::doEffect(SPCurve * curve) { - NArtBpath *bpath = curve->_bpath; + NArtBpath *bpath = curve->get_bpath(); int i = 0; while(bpath[i].code != NR_END) { bpath[i].y1 += (bpath[i].x1-center[Geom::X]) * factor; diff --git a/src/live_effects/lpe-spiro.cpp b/src/live_effects/lpe-spiro.cpp index a193b1a0a..6994b684b 100644 --- a/src/live_effects/lpe-spiro.cpp +++ b/src/live_effects/lpe-spiro.cpp @@ -99,7 +99,7 @@ LPESpiro::doEffect(SPCurve * curve) bezctx *bc = new_bezctx_ink(curve); int len = SP_CURVE_LENGTH(csrc); spiro_cp *path = g_new (spiro_cp, len + 1); - NArtBpath *bpath = csrc->_bpath; + NArtBpath *bpath = csrc->get_bpath(); int ib = 0; int ip = 0; bool closed = false; diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index 088d576b1..ee09221ed 100644 --- a/src/live_effects/lpe-vonkoch.cpp +++ b/src/live_effects/lpe-vonkoch.cpp @@ -9,13 +9,6 @@ #include #include "live_effects/lpe-vonkoch.h" -#include "sp-shape.h" -#include "sp-item.h" -#include "sp-path.h" -#include "display/curve.h" -#include -#include -#include "libnr/n-art-bpath-2geom.h" #include "svg/svg.h" #include "ui/widget/scalar.h" #include "nodepath.h" diff --git a/src/live_effects/lpegroupbbox.cpp b/src/live_effects/lpegroupbbox.cpp index 588d3ec0f..50f7599c0 100644 --- a/src/live_effects/lpegroupbbox.cpp +++ b/src/live_effects/lpegroupbbox.cpp @@ -11,9 +11,6 @@ #include "sp-item.h" #include "sp-path.h" #include "sp-item-group.h" -#include "display/curve.h" -#include -#include #include "libnr/n-art-bpath-2geom.h" #include "svg/svg.h" #include "ui/widget/scalar.h" diff --git a/src/live_effects/parameter/path-reference.cpp b/src/live_effects/parameter/path-reference.cpp index 78f270e64..a76fb1b32 100644 --- a/src/live_effects/parameter/path-reference.cpp +++ b/src/live_effects/parameter/path-reference.cpp @@ -8,18 +8,8 @@ #include "live_effects/parameter/path-reference.h" -#include -#include -#include - -#include "enums.h" - -#include "display/curve.h" -#include "livarot/Path.h" -#include "prefs-utils.h" #include "sp-shape.h" #include "sp-text.h" -#include "uri.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/nodepath.cpp b/src/nodepath.cpp index d50ec769e..d82b82f0d 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -181,7 +181,7 @@ Inkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPObject *object, return NULL; NArtBpath *bpath = curve->first_bpath(); - gint length = curve->end; + gint length = curve->_end; if (length == 0) { curve->unref(); return NULL; // prevent crash for one-node paths diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 4e3321567..ffb776dfe 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -232,9 +232,23 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuideToNodes(SnappedConstraints &s } } +/** + * Returns index of first NR_END bpath in array. + */ +static unsigned sp_bpath_length(NArtBpath const bpath[]) +{ + g_return_val_if_fail(bpath != NULL, FALSE); + unsigned ret = 0; + while ( bpath[ret].code != NR_END ) { + ++ret; + } + ++ret; + return ret; +} + void Inkscape::ObjectSnapper::_collectPaths(Inkscape::Snapper::PointType const &t, bool const &first_point, - NArtBpath *border_bpath) const + NArtBpath const *border_bpath) const { // Now, let's first collect all paths to snap to. If we have a whole bunch of points to snap, // e.g. when translating an item using the selector tool, then we will only do this for the @@ -254,8 +268,14 @@ void Inkscape::ObjectSnapper::_collectPaths(Inkscape::Snapper::PointType const & } // Consider the page border for snapping - if (border_bpath != NULL) { - _bpaths_to_snap_to->push_back(border_bpath); + if (border_bpath != NULL) { + // make our own copy of the const* + NArtBpath *new_bpath; + unsigned const len = sp_bpath_length(border_bpath); + new_bpath = g_new(NArtBpath, len); + memcpy(new_bpath, border_bpath, len * sizeof(NArtBpath)); + + _bpaths_to_snap_to->push_back(new_bpath); } for (std::vector::const_iterator i = _candidates->begin(); i != _candidates->end(); i++) { @@ -329,7 +349,7 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, bool const &first_point, std::vector *unselected_nodes, SPPath const *selected_path, - NArtBpath *border_bpath) const + NArtBpath const *border_bpath) const { _collectPaths(t, first_point, border_bpath); // Now we can finally do the real snapping, using the paths collected above @@ -482,7 +502,7 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, { // Consider the page's border for snapping to - NArtBpath *border_bpath = _snap_to_page_border ? _getBorderBPath() : NULL; + NArtBpath const *border_bpath = _snap_to_page_border ? _getBorderBPath() : NULL; _collectPaths(t, first_point, border_bpath); @@ -565,7 +585,7 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, } // Consider the page's border for snapping to - NArtBpath *border_bpath = _snap_to_page_border ? _getBorderBPath() : NULL; + NArtBpath const *border_bpath = _snap_to_page_border ? _getBorderBPath() : NULL; if (_snap_to_itempath || _snap_to_bboxpath || _snap_to_page_border) { unsigned n = (unselected_nodes == NULL) ? 0 : unselected_nodes->size(); @@ -687,9 +707,9 @@ void Inkscape::ObjectSnapper::_clear_paths() const _paths_to_snap_to->clear(); } -NArtBpath* Inkscape::ObjectSnapper::_getBorderBPath() const +NArtBpath const* Inkscape::ObjectSnapper::_getBorderBPath() const { - NArtBpath *border_bpath = NULL; + NArtBpath const *border_bpath = NULL; NR::Rect const border_rect = NR::Rect(NR::Point(0,0), NR::Point(sp_document_width(_named_view->document),sp_document_height(_named_view->document))); SPCurve const *border_curve = SPCurve::new_from_rect(border_rect); if (border_curve) { diff --git a/src/object-snapper.h b/src/object-snapper.h index 94c9e5a1c..95470ed45 100644 --- a/src/object-snapper.h +++ b/src/object-snapper.h @@ -110,7 +110,7 @@ private: bool const &first_point, std::vector *unselected_nodes, SPPath const *selected_path, - NArtBpath *border_bpath) const; + NArtBpath const *border_bpath) const; void _snapPathsConstrained(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, @@ -122,10 +122,10 @@ private: void _collectPaths(Inkscape::Snapper::PointType const &t, bool const &first_point, - NArtBpath *border_bpath = NULL) const; + NArtBpath const *border_bpath = NULL) const; void _clear_paths() const; - NArtBpath* _getBorderBPath() const; + NArtBpath const* _getBorderBPath() const; bool _snap_to_itemnode; bool _snap_to_itempath; diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index d43d950fb..5b57e326e 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -435,7 +435,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) // Prevent empty paths from being added to the document // otherwise we end up with zomby markup in the SVG file - if(curve->end <= 0) + if(curve->_end <= 0) { curve->unref(); return NULL; @@ -503,7 +503,7 @@ sp_selected_path_reverse() did = true; SPPath *path = SP_PATH(i->data); - SPCurve *rcurve = sp_path_get_curve_reference(path)->reverse(); + SPCurve *rcurve = sp_path_get_curve_reference(path)->create_reverse(); gchar *str = sp_svg_write_path(SP_CURVE_BPATH(rcurve)); if ( sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(path)) ) { diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 270b8148d..d286c6f6c 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -31,7 +31,7 @@ #include "message-context.h" #include "prefs-utils.h" #include "sp-path.h" - +#include "display/curve.h" #include "pixmaps/cursor-pen.xpm" #include "display/canvas-bpath.h" #include "display/sp-ctrlline.h" diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index 0ba44dc33..ae3a2fa48 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -41,6 +41,7 @@ #include "document.h" #include "desktop-style.h" #include "macros.h" +#include "display/curve.h" static void sp_pencil_context_class_init(SPPencilContextClass *klass); static void sp_pencil_context_init(SPPencilContext *pc); diff --git a/src/sp-lpe-item.h b/src/sp-lpe-item.h index d05b75cd0..b3e3d85fc 100644 --- a/src/sp-lpe-item.h +++ b/src/sp-lpe-item.h @@ -15,7 +15,7 @@ */ #include "sp-item.h" -#include "display/curve.h" +#include "display/display-forward.h" #define SP_TYPE_LPE_ITEM (sp_lpe_item_get_type()) #define SP_LPE_ITEM(o) (G_TYPE_CHECK_INSTANCE_CAST((o), SP_TYPE_LPE_ITEM, SPLPEItem)) diff --git a/src/sp-path.cpp b/src/sp-path.cpp index b25397a31..86bc83e2b 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -123,8 +123,8 @@ sp_nodes_in_path(SPPath *path) { SPCurve *curve = SP_SHAPE(path)->curve; if (!curve) return 0; - gint r = curve->end; - gint i = curve->length - 1; + gint r = curve->_end; + gint i = curve->_length - 1; if (i > r) i = r; // sometimes after switching from node editor length is wrong, e.g. f6 - draw - f2 - tab - f1, this fixes it for (; i >= 0; i --) if (SP_CURVE_BPATH(curve)[i].code == NR_MOVETO) diff --git a/src/sp-polygon.cpp b/src/sp-polygon.cpp index 23225d714..4d47778cf 100644 --- a/src/sp-polygon.cpp +++ b/src/sp-polygon.cpp @@ -208,13 +208,13 @@ static void sp_polygon_set(SPObject *object, unsigned int key, const gchar *valu if (has_error || *cptr != '\0') { /* TODO: Flag the document as in error, as per * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing. */ - } else if (curve->posSet) { + } else if (curve->_posSet) { /* We've done a moveto but no lineto. I'm not sure how we're supposed to represent * a single-point polygon in SPCurve: sp_curve_closepath at the time of writing * doesn't seem to like simply moveto followed by closepath. The following works, * but won't round-trip properly: I believe it will write as two points rather than * one. */ - curve->lineto(curve->movePos); + curve->lineto(curve->_movePos); } else if (hascpt) { curve->closepath(); } diff --git a/src/sp-shape.cpp b/src/sp-shape.cpp index 99ebdbe23..fff9de7d3 100644 --- a/src/sp-shape.cpp +++ b/src/sp-shape.cpp @@ -27,6 +27,7 @@ #include "macros.h" #include "display/nr-arena-shape.h" +#include "display/curve.h" #include "print.h" #include "document.h" #include "style.h" @@ -545,8 +546,8 @@ NR::Matrix sp_shape_marker_get_transform(SPShape const *shape, NArtBpath const *bp) { g_return_val_if_fail(( is_moveto(SP_CURVE_BPATH(shape->curve)[0].code) - && ( 0 < shape->curve->end ) - && ( SP_CURVE_BPATH(shape->curve)[shape->curve->end].code == NR_END ) ), + && ( 0 < shape->curve->_end ) + && ( SP_CURVE_BPATH(shape->curve)[shape->curve->_end].code == NR_END ) ), NR::Matrix(NR::translate(bp->c(3)))); double const angle1 = incoming_tangent(bp); double const angle2 = outgoing_tangent(bp); diff --git a/src/splivarot.cpp b/src/splivarot.cpp index a6bd60cd6..aec2b8f6e 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -1738,6 +1738,10 @@ Path_for_item(SPItem *item, bool doTransformation, bool transformFull) return dest; } +/* + * This function is buggy: it can either return a new NArtBpath, or an existing one. + * It is therefore unclear whether the caller must g_free the path or not! +*/ NArtBpath * bpath_for_curve(SPItem *item, SPCurve *curve, bool doTransformation, bool transformFull) { diff --git a/src/tweak-context.cpp b/src/tweak-context.cpp index d60282d71..e4b88ffea 100644 --- a/src/tweak-context.cpp +++ b/src/tweak-context.cpp @@ -67,6 +67,7 @@ #include "sp-flowtext.h" #include "display/canvas-bpath.h" #include "display/canvas-arena.h" +#include "display/curve.h" #include "livarot/Shape.h" #include "isnan.h" #include "prefs-utils.h" diff --git a/src/tweak-context.h b/src/tweak-context.h index 6a94a185b..2157ecdaa 100644 --- a/src/tweak-context.h +++ b/src/tweak-context.h @@ -12,7 +12,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "display/curve.h" #include "event-context.h" #include #include diff --git a/src/verbs.cpp b/src/verbs.cpp index 1fb179660..8ac2bec8b 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -83,7 +83,7 @@ #include "draw-context.h" #include "gradient-drag.h" #include "sp-guide.h" - +#include "display/curve.h" /** * \brief Return the name without underscores and ellipsis, for use in dialog -- 2.30.2