Code

* remove code duplication from pdf-cairo extension
authorjohanengelen <johanengelen@users.sourceforge.net>
Sat, 12 Jul 2008 15:44:30 +0000 (15:44 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Sat, 12 Jul 2008 15:44:30 +0000 (15:44 +0000)
* try to fix line closing bug when using cairo. didn't succeed

src/display/inkscape-cairo.cpp
src/display/inkscape-cairo.h
src/extension/internal/pdf-cairo.cpp
src/extension/internal/pdf-cairo.h

index 9210af1f41c35ed18e6280c6c79a9ee436fb8501..e41d93952c9e36a47224f66a3b110899fa5cf9cd 100644 (file)
@@ -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<NR::Rect> 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);
     }
index 02a145a331913ee4eff768b5961d62a805ed984e..43cafa4bc5d66d1de3d709c5dcfd02570c4ee8b1 100644 (file)
@@ -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<NR::Rect> 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<NR::Rect> area, bool optimize_stroke, double stroke_width);
 void feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv, Geom::Matrix trans, NR::Maybe<NR::Rect> area, bool optimize_stroke, double stroke_width);
 void feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv);
 
index 6dfed9e8247cc1846dec0b3c9c87076d007db0f9..813724e718a62500a576dd0e5ad008be67619b97 100644 (file)
@@ -48,6 +48,7 @@
 #include <glibmm/i18n.h>
 #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)
 {
index 8e2764fa41f479f013ef04fcc685a60129d4ee3c..f45d7a4cddbc26568eb5c464b0e0e77ed2e3fa32 100644 (file)
@@ -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);