Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get the size in pixels for a string

4 views
Skip to first unread message

Stéphane Thibaudeau

unread,
Mar 29, 2006, 9:35:37 AM3/29/06
to
Hi list !

Id like to know the width and height in pixels for a string given a
font family, size and style.
How could I do that ?

Thanks,
Stéphane.

Chris Alfeld

unread,
Mar 29, 2006, 9:59:33 AM3/29/06
to
This is undoubtedly overkill, but:

require 'tk'

f = TkFont.new('Courier 10')
width = f.measure("Hi There!")
height = f.metrics.assoc('linespace')[1]


0 new messages