[EMAIL PROTECTED] wrote:

John Hunter <[EMAIL PROTECTED]> writes:


But I get an error when I run my code that I am not sure what to do
with. The code runs fine under linux. When I run it on win32, I get
a popup error on the call to win.show(), which reads:

GLib-ERROR**: gmem.c: 141: g_malloc():
failed to allocate 4294967294 bytes. aborting

I found the source of this problem and just wanted to post it in case
anyone else bumps into it. The section of my code which generated the
error contained

self._font=gtk.load_font("somefont")
do_something_with( self._font.width(self._text) )

This worked fine under 0.6.9. Under pygtk 1.99 in linux, the code did
not generate an error but the width calculation did not work either.
Under Windows 98 and 2000, I got the error I posted above. When I
use instead:

self._font.string_width(self._text)

all is well. Ditto for height and string_height.

This is because GTK 2.0 uses a more complex text handling system (Pango), that can be used to display more complex text (bi-di, multilingual, handles glyph combining, etc).

If you want to get some information about how big a particular bit of text is, you should construct a PangoLayout for the text, and then measure it.

The quickest way to create a PangoLayout using the style of a particular widget is like so:
layout = widget.create_pango_layout("foo")

You can then get the extents of the text like so:
ink_rect, logical_rect = layout.get_extents()

See the pango documentation for interpretation of these two rectangles.

(there is also a get_pixel_extents() method, but it is broken in 1.99.13 -- it returns the same result as get_extents(). Fixed in CVS though).

James.

--
Email: [EMAIL PROTECTED] | Linux.conf.au http://linux.conf.au/
WWW: http://www.daa.com.au/~james/ | Jan 22-25 Perth, Western Australia.


_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Reply via email to