[pygtk] Getting the pixel dimensions of a monospace font
Noam Raphael
noamraph at gmail.com
Sun Aug 31 20:29:09 WST 2008
Ok, I found a solution. Here's what I did:
tv = self.textview
context = tv.get_pango_context()
metrics = context.get_metrics(tv.style.font_desc,
context.get_language())
width = pango.PIXELS(metrics.get_approximate_digit_width()*81)
height = pango.PIXELS(
(metrics.get_ascent() + metrics.get_descent())*30)
self.window_main.set_default_size(width, height)
Have a good day,
Noam
2008/8/31, Noam Raphael <noamraph at gmail.com>:
> Hello,
>
> I have a TextView which uses a monospace font. I would like to set its
> width (by using textview.props.width_request = width) to the width of
> 80 characters. The question is, how can I know the width and height,
> in pixels, of a character?
>
> Thanks,
>
> Noam
>
More information about the pygtk
mailing list