PyCairo – How we Can transform a coordinate from device space to user space ?
Last Updated :
19 Oct, 2021
In this article, we will learn how we Can transform a coordinate from device space to user space using PyCairo in python. Transform a coordinate from device space to user space by multiplying the given point by the inverse of the current transformation matrix (CTM).
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. Nearly all web browsers support some sort of rendering for the SVG format.
SVG stands for Scalable Vector Graphics. It basically defines vector-based graphics in XML format. SVG graphics do NOT lose any quality if they are zoomed or resized. Every element and every attribute in SVG files can be animated.
In order to do this, we will use device_to_user() method with the Context object.
Syntax : context.device_to_user()
Argument : It takes x, y
Return : It returns x, y both float
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()
a = context.device_to_user( 10 , 10 )
context.stroke()
print (a)
|
Output :
(10.0, 10.0)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...