| FAQ Index - Search - Recent Changes - Everything - Add entry |
4.9. How do I use pango instead of GdkFont for font handling in a GtkDrawingArea?
Create a font description with pango. You will then need a pango layout for the text you want to display. You have to tell the layout which font
description to use and draw it with the draw_layout() method instead of the draw_text() method.
import pango
# create a font description
font_desc = pango.FontDescription('Serif 12')
# create a layout for your drawing area
layout = darea.create_pango_layout('hello pango!')
# tell the layout which font description to use
layout.set_font_description(font_desc)
# draw the text with the draw_layout method
darea.window.draw_layout(gc, x, y, layout)
You can find out about the size of the text by using the get_pixel_size() method from your pango layout object. e.g.:
# get the pixel size of a layout text_width, text_height = layout.get_pixel_size()
