
As the two images below show, you can set the width of your pango layout so that text is output within a narrow or wide space. To do this, you simply call the set_width method in pango.Layout.
The sample code below shows how this is done. Note how the width argument itself is in relatively large units (at least for sugar-jhbuild).
import pango
...
class TextWidget(gtk.DrawingArea):
def __init__(self):
...
#create a pango layout. Leave text argument to be empty string since we want to use markup
self.pango_context = self.create_pango_context()
self.pango_layout = self.create_pango_layout('')
#Make the width of the pango layout to be relatively narrow
self.pango_layout.set_width(200000)
#Make the width of the pango layout to be relatively wide.
self.pango_layout.set_width(800000)
...
There are two ways in which you can customize how fonts are displayed in your activity.
You set th default font properties throughout your layout.
Using Pango markup, you customize specific blocks of text in your Pango layout.
To customize the default font throughout your layout, you call the method when you create and initialize your Pango layout.
import pango
...
#create a pango layout. Leave text argument to be empty string since we want to use markup
self.pango_context = self.create_pango_context()
self.pango_layout = self.create_pango_layout('')
#Set the default font style for this pango layout
self.pango_layout.set_font_description(pango.FontDescription('serif Ultra-bold italic 14'))
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-51835-4.html
很棒