From 28f0575a7b937a968c52c5d5faa695d5dc107139 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Sat, 12 Jul 2008 15:33:37 +0000 Subject: [PATCH] add simplified feed_path_to_cairo functions --- src/display/inkscape-cairo.cpp | 52 ++++++++++++++++++++++++++++++---- src/display/inkscape-cairo.h | 2 ++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/display/inkscape-cairo.cpp b/src/display/inkscape-cairo.cpp index 069727064..9210af1f4 100644 --- a/src/display/inkscape-cairo.cpp +++ b/src/display/inkscape-cairo.cpp @@ -156,8 +156,12 @@ feed_curve_to_cairo (cairo_t *ct, NArtBpath const *bpath, NR::Matrix trans, NR:: } +/* + * Can be called recursively. + * If optimize_stroke == false, the view Rect is not used. + */ static void -feed_curve_to_cairo(cairo_t *cr, Geom::Curve const &c, Geom::Matrix & trans, Geom::Rect view, bool optimize_stroke) +feed_curve_to_cairo(cairo_t *cr, Geom::Curve const &c, Geom::Matrix const & trans, Geom::Rect view, bool optimize_stroke) { if( dynamic_cast(&c) || dynamic_cast(&c) || @@ -229,7 +233,32 @@ feed_curve_to_cairo(cairo_t *cr, Geom::Curve const &c, Geom::Matrix & trans, Geo } -/** Feeds path-creating calls to the cairo context translating them from the SPCurve, with the given transform and shift */ +/** Feeds path-creating calls to the cairo context translating them from the Path, with the given transform and shift */ +void +feed_path_to_cairo (cairo_t *ct, Geom::Path const &path) +{ + if (path.empty()) + return; + + cairo_move_to(ct, path.initialPoint()[0], path.initialPoint()[1] ); + + for(Geom::Path::const_iterator cit = path.begin(); cit != path.end_open(); ++cit) { + feed_curve_to_cairo(ct, *cit, Geom::identity(), Geom::Rect(), false); // optimize_stroke is false, so the view rect is not used + } + + if (path.closed()) { + cairo_line_to(ct, path.initialPoint()[0], path.initialPoint()[1]); +// cairo_close_path(ct); + /* I think we should use cairo_close_path(ct) here but it doesn't work. (the closing line is not rendered completely) + According to cairo documentation: + The behavior of cairo_close_path() is distinct from simply calling cairo_line_to() with the equivalent coordinate + in the case of stroking. When a closed sub-path is stroked, there are no caps on the ends of the sub-path. Instead, + there is a line join connecting the final and initial segments of the sub-path. + */ + } +} + +/** Feeds path-creating calls to the cairo context translating them from the Path, with the given transform and shift */ void feed_path_to_cairo (cairo_t *ct, Geom::Path const &path, Geom::Matrix trans, NR::Maybe area, bool optimize_stroke, double stroke_width) { @@ -255,8 +284,9 @@ feed_path_to_cairo (cairo_t *ct, Geom::Path const &path, Geom::Matrix trans, NR: if (path.closed()) { cairo_line_to(ct, initial[0], initial[1]); - // I think we should use cairo_close_path(ct) here but it doesn't work. (the closing line is not rendered completely) - /* according to cairo documentation: +// cairo_close_path(ct); + /* I think we should use cairo_close_path(ct) here but it doesn't work. (the closing line is not rendered completely) + According to cairo documentation: The behavior of cairo_close_path() is distinct from simply calling cairo_line_to() with the equivalent coordinate in the case of stroking. When a closed sub-path is stroked, there are no caps on the ends of the sub-path. Instead, there is a line join connecting the final and initial segments of the sub-path. @@ -264,7 +294,7 @@ feed_path_to_cairo (cairo_t *ct, Geom::Path const &path, Geom::Matrix trans, NR: } } -/** Feeds path-creating calls to the cairo context translating them from the SPCurve, with the given transform and shift */ +/** Feeds path-creating calls to the cairo context translating them from the PathVector, with the given transform and shift */ void feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv, Geom::Matrix trans, NR::Maybe area, bool optimize_stroke, double stroke_width) { @@ -278,6 +308,18 @@ feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv, Geom::Matr } } +/** Feeds path-creating calls to the cairo context translating them from the PathVector */ +void +feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv) +{ + if (pathv.empty()) + return; + + for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it) { + feed_path_to_cairo(ct, *it); + } +} + /* Local Variables: mode:c++ diff --git a/src/display/inkscape-cairo.h b/src/display/inkscape-cairo.h index 5ac073c52..02a145a33 100644 --- a/src/display/inkscape-cairo.h +++ b/src/display/inkscape-cairo.h @@ -23,8 +23,10 @@ class SPCanvasBuf; cairo_t *nr_create_cairo_context_canvasbuf (NRRectL *area, SPCanvasBuf *b); cairo_t *nr_create_cairo_context (NRRectL *area, NRPixBlock *pb); void feed_curve_to_cairo (cairo_t *ct, NArtBpath const *bpath, NR::Matrix trans, NR::Maybe area, bool optimize_stroke, double stroke_width); +void feed_path_to_cairo (cairo_t *ct, Geom::Path const &path); void feed_path_to_cairo (cairo_t *ct, Geom::Path const &path, Geom::Matrix trans, NR::Maybe area, bool optimize_stroke, double stroke_width); void feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv, Geom::Matrix trans, NR::Maybe area, bool optimize_stroke, double stroke_width); +void feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv); #endif /* -- 2.30.2