From: johanengelen Date: Sun, 31 Aug 2008 14:02:18 +0000 (+0000) Subject: cairo-render-context extension implementation converted to 2geom X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b5ea3ee18029be0e1660324cb5df658ec6dc99d3;p=inkscape.git cairo-render-context extension implementation converted to 2geom --- diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index 09d4fc74c..2434e454b 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -27,14 +27,6 @@ #include #include - -#include -#include -#include -#include -#include -#include -#include #include <2geom/pathvector.h> #include @@ -45,6 +37,7 @@ #include "display/nr-arena-group.h" #include "display/curve.h" #include "display/canvas-bpath.h" +#include "display/inkscape-cairo.h" #include "sp-item.h" #include "sp-item-group.h" #include "style.h" @@ -678,7 +671,7 @@ CairoRenderContext::popLayer(void) } void -CairoRenderContext::addClipPath(NArtBpath const *bp, SPIEnum const *fill_rule) +CairoRenderContext::addClipPath(Geom::PathVector const &pv, SPIEnum const *fill_rule) { g_assert( _is_valid ); @@ -689,7 +682,7 @@ CairoRenderContext::addClipPath(NArtBpath const *bp, SPIEnum const *fill_rule) } else { cairo_set_fill_rule(_cr, CAIRO_FILL_RULE_WINDING); } - addBpath(bp); + addPathVector(pv); } void @@ -1252,25 +1245,14 @@ CairoRenderContext::_setStrokeStyle(SPStyle const *style, NRRect const *pbox) bool CairoRenderContext::renderPathVector(Geom::PathVector const & pathv, SPStyle const *style, NRRect const *pbox) -{ - NArtBpath * bpath = BPath_from_2GeomPath (pathv); - const_NRBPath bp; - bp.path = bpath; - bool retvalue = renderPath(&bp, style, pbox); - g_free(bpath); - return retvalue; -} - -bool -CairoRenderContext::renderPath(const_NRBPath const *bpath, SPStyle const *style, NRRect const *pbox) { g_assert( _is_valid ); if (_render_mode == RENDER_MODE_CLIP) { if (_clip_mode == CLIP_MODE_PATH) { - addClipPath(bpath->path, &style->fill_rule); + addClipPath(pathv, &style->fill_rule); } else { - setBpath(bpath->path); + setPathVector(pathv); if (style->fill_rule.value == SP_WIND_RULE_EVENODD) { cairo_set_fill_rule(_cr, CAIRO_FILL_RULE_EVEN_ODD); } else { @@ -1295,7 +1277,7 @@ CairoRenderContext::renderPath(const_NRBPath const *bpath, SPStyle const *style, if (!style->fill.isNone()) { _setFillStyle(style, pbox); - setBpath(bpath->path); + setPathVector(pathv); if (style->fill_rule.value == SP_WIND_RULE_EVENODD) { cairo_set_fill_rule(_cr, CAIRO_FILL_RULE_EVEN_ODD); @@ -1312,7 +1294,7 @@ CairoRenderContext::renderPath(const_NRBPath const *bpath, SPStyle const *style, if (!style->stroke.isNone()) { _setStrokeStyle(style, pbox); if (style->fill.isNone()) - setBpath(bpath->path); + setPathVector(pathv); cairo_stroke(_cr); } @@ -1523,47 +1505,16 @@ CairoRenderContext::renderGlyphtext(PangoFont *font, Geom::Matrix const *font_ma /* Helper functions */ void -CairoRenderContext::addBpath(NArtBpath const *bp) +CairoRenderContext::setPathVector(Geom::PathVector const &pv) { - 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); - } + cairo_new_path(_cr); + addPathVector(pv); } void -CairoRenderContext::setBpath(NArtBpath const *bp) +CairoRenderContext::addPathVector(Geom::PathVector const &pv) { - cairo_new_path(_cr); - if (bp) - addBpath(bp); + feed_pathvector_to_cairo(_cr, pv); } void diff --git a/src/extension/internal/cairo-render-context.h b/src/extension/internal/cairo-render-context.h index fe76cb105..e92418085 100644 --- a/src/extension/internal/cairo-render-context.h +++ b/src/extension/internal/cairo-render-context.h @@ -114,8 +114,8 @@ public: void setClipMode(CairoClipMode mode); CairoClipMode getClipMode(void) const; - void addBpath(NArtBpath const *bp); - void setBpath(NArtBpath const *bp); + void addPathVector(Geom::PathVector const &pv); + void setPathVector(Geom::PathVector const &pv); void pushLayer(void); void popLayer(void); @@ -133,7 +133,7 @@ public: void getParentTransform(Geom::Matrix *copy) const; /* Clipping methods */ - void addClipPath(NArtBpath const *bp, SPIEnum const *fill_rule); + void addClipPath(Geom::PathVector const &pv, SPIEnum const *fill_rule); void addClippingRect(double x, double y, double width, double height); /* Rendering methods */