From f462dfdfac6230f8e549c902cdf8de91d13c89e8 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Sat, 29 Sep 2012 19:54:31 +0200 Subject: [PATCH] Canvas: default fill-rule to evenodd and make it configurable --- src/Canvas/elements/path.cxx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Canvas/elements/path.cxx b/src/Canvas/elements/path.cxx index a80ba70a2..c9875a8b1 100644 --- a/src/Canvas/elements/path.cxx +++ b/src/Canvas/elements/path.cxx @@ -44,6 +44,7 @@ namespace canvas _paint_fill(VG_INVALID_HANDLE), _attributes_dirty(~0), _mode(0), + _fill_rule(VG_EVEN_ODD), _stroke_width(1), _stroke_linecap(VG_CAP_BUTT) { @@ -112,6 +113,21 @@ namespace canvas } } + /** + * Set path fill rule ("pseudo-nonzero" or "evenodd") + * + * @warning As the current nonzero implementation causes sever artifacts + * for every concave path we call it pseudo-nonzero, so that + * everyone is warned that it won't work as expected :) + */ + void setFillRule(const std::string& fill_rule) + { + if( fill_rule == "pseudo-nonzero" ) + _fill_rule = VG_NON_ZERO; + else // if( fill_rule == "evenodd" ) + _fill_rule = VG_EVEN_ODD; + } + /** * Set path stroke paint ("none" if no stroke) */ @@ -232,7 +248,7 @@ namespace canvas { vgSetPaint(_paint_fill, VG_FILL_PATH); - vgSeti(VG_FILL_RULE, VG_NON_ZERO); // TODO make user configurable + vgSeti(VG_FILL_RULE, _fill_rule); } // And finally draw the path @@ -297,6 +313,7 @@ namespace canvas VGbitfield _mode; osg::Vec4f _fill_color; + VGFillRule _fill_rule; osg::Vec4f _stroke_color; VGfloat _stroke_width; std::vector _stroke_dash; @@ -383,6 +400,7 @@ namespace canvas PathDrawable *path = _path.get(); addStyle("fill", &PathDrawable::setFill, path); + addStyle("fill-rule", &PathDrawable::setFillRule, path); addStyle("stroke", &PathDrawable::setStroke, path); addStyle("stroke-width", &PathDrawable::setStrokeWidth, path); addStyle("stroke-dasharray", &PathDrawable::setStrokeDashArray, path);