From: johanengelen Date: Sat, 12 Jul 2008 15:44:30 +0000 (+0000) Subject: * remove code duplication from pdf-cairo extension X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=813d38872d464e1992025f8dc9fa593142b807d9;p=inkscape.git * remove code duplication from pdf-cairo extension * try to fix line closing bug when using cairo. didn't succeed --- diff --git a/src/display/inkscape-cairo.cpp b/src/display/inkscape-cairo.cpp index 9210af1f4..e41d93952 100644 --- a/src/display/inkscape-cairo.cpp +++ b/src/display/inkscape-cairo.cpp @@ -233,8 +233,8 @@ feed_curve_to_cairo(cairo_t *cr, Geom::Curve const &c, Geom::Matrix const & tran } -/** Feeds path-creating calls to the cairo context translating them from the Path, with the given transform and shift */ -void +/** Feeds path-creating calls to the cairo context translating them from the Path */ +static void feed_path_to_cairo (cairo_t *ct, Geom::Path const &path) { if (path.empty()) @@ -259,7 +259,7 @@ feed_path_to_cairo (cairo_t *ct, Geom::Path const &path) } /** Feeds path-creating calls to the cairo context translating them from the Path, with the given transform and shift */ -void +static void feed_path_to_cairo (cairo_t *ct, Geom::Path const &path, Geom::Matrix trans, NR::Maybe area, bool optimize_stroke, double stroke_width) { if (!area || area->isEmpty()) @@ -303,6 +303,8 @@ feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv, Geom::Matr if (pathv.empty()) return; + cairo_new_path(ct); + for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it) { feed_path_to_cairo(ct, *it, trans, area, optimize_stroke, stroke_width); } @@ -315,6 +317,8 @@ feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv) if (pathv.empty()) return; + cairo_new_path(ct); + for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it) { feed_path_to_cairo(ct, *it); } diff --git a/src/display/inkscape-cairo.h b/src/display/inkscape-cairo.h index 02a145a33..43cafa4bc 100644 --- a/src/display/inkscape-cairo.h +++ b/src/display/inkscape-cairo.h @@ -23,8 +23,6 @@ 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); diff --git a/src/extension/internal/pdf-cairo.cpp b/src/extension/internal/pdf-cairo.cpp index 6dfed9e82..813724e71 100644 --- a/src/extension/internal/pdf-cairo.cpp +++ b/src/extension/internal/pdf-cairo.cpp @@ -48,6 +48,7 @@ #include #include "display/nr-arena-item.h" #include "display/canvas-bpath.h" +#include "display/inkscape-cairo.h" #include "sp-item.h" #include "style.h" #include "sp-linear-gradient.h" @@ -600,9 +601,9 @@ PrintCairoPDF::fill(Inkscape::Extension::Print *mod, Geom::PathVector const &pat cairo_save(cr); print_fill_style(cr, style, pbox); - NArtBpath * bpath = BPath_from_2GeomPath(pathv); - print_bpath(cr, bpath); - g_free(bpath); + + feed_pathvector_to_cairo(cr, pathv); + if (style->fill_rule.computed == SP_WIND_RULE_EVENODD) { cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); } else { @@ -700,9 +701,8 @@ PrintCairoPDF::stroke(Inkscape::Extension::Print *mod, Geom::PathVector const &p cairo_save(cr); print_stroke_style(cr, style, pbox); - NArtBpath * bpath = BPath_from_2GeomPath(pathv); - print_bpath(cr, bpath); - g_free(bpath); + + feed_pathvector_to_cairo(cr, pathv); cairo_stroke(cr); cairo_restore(cr); @@ -988,43 +988,6 @@ PrintCairoPDF::text(Inkscape::Extension::Print *mod, char const *text, NR::Point /* Helper functions */ -void -PrintCairoPDF::print_bpath(cairo_t *cr, NArtBpath const *bp) -{ - cairo_new_path(cr); - bool closed = false; - while (bp->code != NR_END) { - switch (bp->code) { - case NR_MOVETO: - if (closed) { - cairo_close_path(cr); - } - closed = true; - cairo_move_to(cr, bp->x3, bp->y3); - break; - case NR_MOVETO_OPEN: - if (closed) { - cairo_close_path(cr); - } - closed = false; - cairo_move_to(cr, bp->x3, bp->y3); - break; - case NR_LINETO: - cairo_line_to(cr, bp->x3, bp->y3); - break; - case NR_CURVETO: - cairo_curve_to(cr, bp->x1, bp->y1, bp->x2, bp->y2, bp->x3, bp->y3); - break; - default: - break; - } - bp += 1; - } - if (closed) { - cairo_close_path(cr); - } -} - static void _concat_transform(cairo_t *cr, double xx, double yx, double xy, double yy, double x0, double y0) { diff --git a/src/extension/internal/pdf-cairo.h b/src/extension/internal/pdf-cairo.h index 8e2764fa4..f45d7a4cd 100644 --- a/src/extension/internal/pdf-cairo.h +++ b/src/extension/internal/pdf-cairo.h @@ -50,7 +50,6 @@ class PrintCairoPDF : public Inkscape::Extension::Implementation::Implementation unsigned short _dpi; bool _bitmap; - void print_bpath(cairo_t *cr, NArtBpath const *bp); cairo_pattern_t *create_pattern_for_paint(SPPaintServer const *const paintserver, NRRect const *pbox, float alpha); void print_fill_style(cairo_t *cr, SPStyle const *const style, NRRect const *pbox);