Text Extents

Learn about text extents.

What are text extents?

The font size gives us control of the nominal size of the font. The text extents tell us the exact size of a particular text string, when rendered with the current font. To be precise, they pinpoint the rectangle around the area that will be marked when we paint the text.

The Context and text_extents functions return a Pycairo TextExtents object (which behaves much like a tuple). Here is an example of this:

xbearing, ybearing, width, height, dx, dy = ctx.text_extents('Xyz')

The text_extents function accepts a string. It calculates the extents of the string and returns the TextExtents object, which we unpack into 6 variables. Here is an example of this:

Get hands-on with 1200+ tech skills courses.