manua has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

Is there a way to find the height of text, that a string will take defined in textlabel. As we can can the width with $txt->advanccewidth(), I am looking for similar function in terms of vertical height.

Also, can we specify the vertical alignment in textlabel.

Thanks

Replies are listed 'Best First'.
Re: Vertical Height of textlabel
by zentara (Cardinal) on Feb 18, 2010 at 18:09 UTC
    It is usually called font metrics.

    It depends on what toolkit you are using, but yes you usually can find what is called the "bounding box" or bbox of the text. The thing to watch out for is the fact that labels tend to be text oriented, so that height is actually the number of text lines, like 1, 2 , or 3; wheras width is the actual pixel width of the entire string. So you might get a height as 1, but width as 240.

    You can look at Gtk2::Label for the complexity. It can be done, but usually you design for size flexibility, where label wrap length varies depending on the size of the main window. Also see Tk font metrics


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku