PyCairo – Creating Text Paths
In this article, we will learn how we can display text and converting text into paths using PyCairo in python. You can convert a text string to a path. Once you have the path then you can fill it (that will look similar to just displaying text the normal way), or just outline it, or both.
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.
Steps of Implementation :
- Import the Pycairo module.
- Create a SVG surface object and add context to it.
- Setting text font size and style using set_font_size ( ) , select_font_face( )
- Display the text using show_path ( )
- Setting path color and width using set_source_rgb ( ) , set_line_width( )
Below is the implementation :
Example 2 :
Please Login to comment...