Symbian
Symbian OS Library

FAQ-0797 How can I find out what the physical size of a text string will be when displayed?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: Text Layout & Formatting
Created: 05/31/2002 Modified: 06/05/2002
Number: FAQ-0797
Platform: ER5, Symbian OS v6.0, Symbian OS v6.1

Question:
I want to display a text string in a limited space on screen and need to know if it's too long so I can, say, split it into two lines or reduce the font size. How can I get this information?

Answer:
CFont has a function TextWidthInPixels(TDesC&) which does just this for the text displayed in the chosen font.

    CFont* font;
    ...
    TPtrC myLongString = ...;
    TInt width = font->TextWidthInPixels(myLongString);