PyCairo – How to Preserve the clip ?
Last Updated :
23 Jan, 2022
In this article we will learn how we can preserve the clip using PyCairo in python. Preserving the clip means to establish a new clip region by intersecting the current clip region with the current path as it would be filled by Context.fill() and according to the current fill rule.
PyCairo : Pycairo is a Python module providing bindings for the Cairo graphics library. This library is used for creating SVG i.e vector files in python. The easiest and quickest way to open an SVG file to view it (read only) is with a modern web browser like Chrome, Firefox, Edge, or Internet Explorer—nearly all of them should provide some sort of rendering support for the SVG format.
SVG file is a graphics file that uses a two-dimensional vector graphic format created by the World Wide Web Consortium (W3C). It describes images using a text format that is based on XML. SVG files are developed as a standard format for displaying vector graphics on the web.
In order to this we will use clip_preserve() method with the Context object
Syntax : context.clip_preserve()
Argument : It takes no arguments
Return : It returns none
Note: The current clip region affects all drawing operations by effectively masking out any changes to the surface that are outside the current clip region.
Example :
Python3
import cairo
with cairo.SVGSurface( "geek1.svg" , 700 , 700 ) as surface:
context = cairo.Context(surface)
context.arc( 100 , 60 , 40 , 0 , 1 * 22 / 7 )
context.stroke()
context.arc( 300 , 60 , 40 , 0 , 1 * 22 / 7 )
context.close_path()
context.clip_preserve()
context.stroke()
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...