From 74d18f102cb65a67ac5d8640085878284362eaeb Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Fri, 17 Oct 2014 17:03:52 -0700 Subject: Refactoring hatch to remove memory leaks (bad GTKish casting macros) and uninitialized value. (bzr r13622) --- src/extension/internal/cairo-render-context.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/extension/internal/cairo-render-context.cpp') diff --git a/src/extension/internal/cairo-render-context.cpp b/src/extension/internal/cairo-render-context.cpp index 7e61cdbbb..cb414b3b2 100644 --- a/src/extension/internal/cairo-render-context.cpp +++ b/src/extension/internal/cairo-render-context.cpp @@ -1132,8 +1132,8 @@ CairoRenderContext::_createPatternPainter(SPPaintServer const *const paintserver cairo_pattern_t* CairoRenderContext::_createHatchPainter(SPPaintServer const *const paintserver, Geom::OptRect const &pbox) { - g_assert( SP_IS_HATCH(paintserver) ); - SPHatch *hatch = SP_HATCH(paintserver); + SPHatch const *hatch = dynamic_cast(paintserver); + g_assert( hatch ); g_assert(hatch->pitch() > 0); @@ -1141,7 +1141,9 @@ CairoRenderContext::_createHatchPainter(SPPaintServer const *const paintserver, Inkscape::Drawing drawing; unsigned dkey = SPItem::display_key_new(1); - hatch->show(drawing, dkey, pbox); + // TODO need to refactor 'evil' referenced code for const correctness. + SPHatch *evil = const_cast(hatch); + evil->show(drawing, dkey, pbox); SPHatch::RenderInfo render_info = hatch->calculateRenderInfo(dkey); Geom::Rect tile_rect = render_info.tile_rect; @@ -1177,8 +1179,7 @@ CairoRenderContext::_createHatchPainter(SPPaintServer const *const paintserver, pattern_ctx->transform(Geom::Translate(-overflow_right_strip, 0.0)); pattern_ctx->pushState(); - std::vector children; - hatch->hatchPaths(children); + std::vector children(evil->hatchPaths()); for (int i = 0; i < overflow_steps; i++) { for (std::vector::iterator iter = children.begin(); iter != children.end(); iter++) { @@ -1200,7 +1201,7 @@ CairoRenderContext::_createHatchPainter(SPPaintServer const *const paintserver, pattern_transform = render_info.pattern_to_user_transform.inverse() * drawing_transform; ink_cairo_pattern_set_matrix(result, pattern_transform); - hatch->hide(dkey); + evil->hide(dkey); delete pattern_ctx; return result; @@ -1260,7 +1261,7 @@ CairoRenderContext::_createPatternForPaintServer(SPPaintServer const *const pain } } else if (SP_IS_PATTERN (paintserver)) { pattern = _createPatternPainter(paintserver, pbox); - } else if (SP_IS_HATCH (paintserver)) { + } else if ( dynamic_cast(paintserver) ) { pattern = _createHatchPainter(paintserver, pbox); } else { return NULL; @@ -1331,8 +1332,8 @@ CairoRenderContext::_setFillStyle(SPStyle const *const style, Geom::OptRect cons if (paint_server && paint_server->isValid()) { g_assert(SP_IS_GRADIENT(SP_STYLE_FILL_SERVER(style)) - || SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style)) - || SP_IS_HATCH(SP_STYLE_FILL_SERVER(style))); + || SP_IS_PATTERN(SP_STYLE_FILL_SERVER(style)) + || dynamic_cast(SP_STYLE_FILL_SERVER(style))); cairo_pattern_t *pattern = _createPatternForPaintServer(paint_server, pbox, alpha); if (pattern) { @@ -1369,7 +1370,7 @@ CairoRenderContext::_setStrokeStyle(SPStyle const *style, Geom::OptRect const &p g_assert( style->stroke.isPaintserver() || SP_IS_GRADIENT(SP_STYLE_STROKE_SERVER(style)) || SP_IS_PATTERN(SP_STYLE_STROKE_SERVER(style)) - || SP_IS_HATCH(SP_STYLE_STROKE_SERVER(style))); + || dynamic_cast(SP_STYLE_STROKE_SERVER(style))); cairo_pattern_t *pattern = _createPatternForPaintServer(SP_STYLE_STROKE_SERVER(style), pbox, alpha); -- cgit v1.2.3