[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Get the size in pixels for a string

Stéphane Thibaudeau

3/29/2006 2:36:00 PM

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.

1 Answer

Chris Alfeld

3/29/2006 3:00:00 PM

0

This is undoubtedly overkill, but:

require 'tk'

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