From c696b220274514b2fe6c39d09f546653960a0291 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Wobst?= Date: Thu, 20 Nov 2008 03:09:31 +0000 Subject: [PATCH] implement style.fillrule git-svn-id: https://pyx.svn.sourceforge.net/svnroot/pyx/trunk/pyx@3003 069f4177-920e-0410-937b-c2a4a81bcd90 --- CHANGES | 2 ++ manual/graphics.tex | 3 +++ pyx/canvas.py | 5 +++-- pyx/deco.py | 25 ++++++++++++++++++++----- pyx/style.py | 19 +++++++++++++++++++ 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index a277a749..1cfca1c1 100644 --- a/CHANGES +++ b/CHANGES @@ -123,6 +123,8 @@ TODO: - text module: - fix two bugs in the read pipe of the texrunner (thanks to Laurence Tratt and Eric Faurot) + - style module: + - implement style.fillrule - bitmap module: - add support for transparent bitmaps (in postscript stencil masking only) diff --git a/manual/graphics.tex b/manual/graphics.tex index 43d0a22e..40c25ecf 100644 --- a/manual/graphics.tex +++ b/manual/graphics.tex @@ -325,6 +325,9 @@ Attribute category & description & examples\\ \class{style.fillstyle} & style used for path filling & \class{color.color}\newline\class{pattern.pattern} \\ +\class{style.filltype} & type of path filling & +\code{style.filltype.nonzero_winding} (default)\newline\code{style.filltype.even_odd} +\\ \class{deformer.deformer} & operations changing the shape of the path & diff --git a/pyx/canvas.py b/pyx/canvas.py index 8e2e3931..a035c3b1 100644 --- a/pyx/canvas.py +++ b/pyx/canvas.py @@ -214,13 +214,14 @@ class _canvas(canvasitem.canvasitem): """ attrs = attr.mergeattrs(attrs) - attr.checkattrs(attrs, [deco.deco, deformer.deformer, style.fillstyle, style.strokestyle]) + attr.checkattrs(attrs, [deco.deco, deformer.deformer, style.fillstyle, style.strokestyle, style.fillrule]) for adeformer in attr.getattrs(attrs, [deformer.deformer]): path = adeformer.deform(path) styles = attr.getattrs(attrs, [style.fillstyle, style.strokestyle]) - dp = deco.decoratedpath(path, styles=styles) + fillrule, = attr.getattrs(attrs, [style.fillrule]) or [style.fillrule.nonzero_winding] + dp = deco.decoratedpath(path, styles=styles, fillrule=fillrule) # add path decorations and modify path accordingly for adeco in attr.getattrs(attrs, [deco.deco]): diff --git a/pyx/deco.py b/pyx/deco.py index 155b689b..0d4ade6c 100644 --- a/pyx/deco.py +++ b/pyx/deco.py @@ -44,7 +44,7 @@ class decoratedpath(canvasitem.canvasitem): def __init__(self, path, strokepath=None, fillpath=None, styles=None, strokestyles=None, fillstyles=None, - ornaments=None): + ornaments=None, fillrule=style.fillrule.nonzero_winding): self.path = path @@ -62,6 +62,9 @@ class decoratedpath(canvasitem.canvasitem): else: self.ornaments = ornaments + # the fillrule is either fillrule.nonzero_winding or fillrule.even_odd + self.fillrule = fillrule + self.nostrokeranges = None def ensurenormpath(self): @@ -157,7 +160,10 @@ class decoratedpath(canvasitem.canvasitem): if self.fillstyles: _writestyles(self.fillstyles, context(), registry, bbox) - file.write("fill\n") + if self.fillrule.even_odd: + file.write("eofill\n") + else: + file.write("fill\n") file.write("grestore\n") acontext = context() @@ -177,7 +183,10 @@ class decoratedpath(canvasitem.canvasitem): file.write("gsave\n") _writestyles(self.fillstyles, context(), registry, bbox) - file.write("fill\n") + if self.fillrule.even_odd: + file.write("eofill\n") + else: + file.write("fill\n") bbox += fillpath.bbox() if self.fillstyles: @@ -255,7 +264,10 @@ class decoratedpath(canvasitem.canvasitem): if self.strokestyles: _writestrokestyles(self.strokestyles, acontext, registry, bbox) - file.write("B\n") # both stroke and fill + if self.fillrule.even_odd: + file.write("B*\n") + else: + file.write("B\n") # both stroke and fill # take linewidth into account for bbox when stroking a path bbox += strokepath.bbox().enlarged_pt(0.5*acontext.linewidth_pt) @@ -266,7 +278,10 @@ class decoratedpath(canvasitem.canvasitem): file.write("q\n") # gsave _writefillstyles(self.fillstyles, context(), registry, bbox) - file.write("f\n") # fill + if self.fillrule.even_odd: + file.write("f*\n") + else: + file.write("f\n") # fill bbox += fillpath.bbox() if self.fillstyles: diff --git a/pyx/style.py b/pyx/style.py index 8fd798ea..2a47f673 100644 --- a/pyx/style.py +++ b/pyx/style.py @@ -193,3 +193,22 @@ linewidth.THIck = linewidth(_defaultlinewidth*math.sqrt(16)) linewidth.THICk = linewidth(_defaultlinewidth*math.sqrt(32)) linewidth.THICK = linewidth(_defaultlinewidth*math.sqrt(64)) linewidth.clear = attr.clearclass(linewidth) + + +class fillrule(attr.exclusiveattr): + + """defines the fill rule to be used""" + + def __init__(self, even_odd): + attr.exclusiveattr.__init__(self, fillrule) + self.even_odd = even_odd + + def processPS(self, file, writer, context, registry, bbox): + pass + + def processPDF(self, file, writer, context, registry, bbox): + pass + +fillrule.nonzero_winding = fillrule(0) +fillrule.even_odd = fillrule(1) +fillrule.clear = attr.clearclass(fillrule) -- 2.11.4.GIT