1.

How Do I Use Pango Instead Of Gdkfont For Font Handling In A Gtkdrawingarea?

Answer»

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()

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()



Discussion

No Comment Found