Skip to content

Is is possible to draw polygon with interior? #2314

Answered by JorjMcKie
sharon-br asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, this is possible using one of the non-zero-winding or even-odd rules. Example:

import fitz
doc=fitz.open()
page=doc.new_page()
r1 = fitz.Rect(100,100,200,200)
r2 = r1 + (20,20,-20,-20)
shape = page.new_shape()
shape.draw_rect(r1)
shape.draw_rect(r2)
shape.finish(fill=(1,1,0),even_odd=True)
shape.commit()
doc.save("x.pdf")

Gives you this:

Important:
The graphic elements you want to include in such a reglement must belong to the scope of the same Shape.finish() method - like shown above.

If letting even_odd default to False, non-zero-winding is used as the rule. In that case, the above effect will not occur if drawing happens in this way, because both figures are drawn in the same dir…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by sharon-br
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2313 on March 30, 2023 12:46.