Question

is there a way to fill everything outside of a closed path (polygon)?

Background: I'd like to render some maps with coastlines - so sometimes I need to fill the sea with blue color, so I thought it would be the easiest and in my situation the most efficient to fill everything outside of this coastline polygon with blue color.

Thanks in advance!

Was it helpful?

Solution

You can add a rectangle covering the whole drawing area to your coastline path and set the fill rule to cairo.FILL_RULE_EVEN_ODD. Calling fill() after this fills the area outside your original path. (If you choose the correct orientation for your rectangle you can skip setting the fill rule.)

OTHER TIPS

Draw a big blue rectangle over the entire cairo surface and then draw your coastline on top of that?

While you could create a closed path the size of the surface and then fill it with a solidpattern (the fill rule won't matter for a simple rectangle), it would be easier to just use the context paint() method which will fill the current clip region (that is initially set to the entire surface). It's important to do this before drawing the map/coastline boundaries and filling them so they will be on top of the background.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top