Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Revision as of 02:35, 26 July 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to define and choose scalable text

From Wiki
Jump to: navigation, search
Article Metadata
Created: antonypr (26 Jun 2007)
Last edited: hamishwillee (26 Jul 2012)

This article explains how to define and choose scalable text in S60 2nd FP3 or newer. Scalable text allows the developers to display different variant of the "same text" depending on the screen resolution. For example, a simple label may display more text in landscape mode, compared to the portrait mode.

The two pictures below show an example of scalable text. The shorter text is displayed in the portrait mode because the space is limited. The longer one is displayed in the landscape mode because there is more space.

Multipletext portrait.png Multipletext landscape.png


Defining scalable text

A Scalable text is normally defined in the resource file (.rss) or localization file (.loc). Each variant is separated with 0x0001. For example:

#define Str_Text_Example1 "This is a very long Hello World"<0x0001>"Hello World"

The example above defines a scalable text that contains two variant, i.e. "This is a very long Hello World" and "Hello World".

There can be two or more variants defined in the scalable text. For example:

"This is a very long Hello World"<0x0001>"Long Hello World"<0x0001>"Hello World".

The scalable text above contains three variants.

Using scalable text in control

Using scalable text in a control, such as label or list box, is straightforward. All S60 controls are aware of scalable text. They will choose the longest variant that can fit on the selected area.


HBufC* labelString = StringLoader::LoadLC(R_TEXT_EXAMPLE1);
CleanupStack::PopAndDestroy(); // labelString

Choosing scalable text manually

If the scalable text is going to be displayed not in S60 control, the variant has to be chosen manually. For example, the method CFbsBitGc::DrawText() is not aware of scalable text.

In this case, choosing the variant has to be done manually using AknUtils::ChooseScalableText(). This method chooses the variant based on two parameters, i.e.:

  • The font used to display the text.
  • The maximum width of the area (in pixel) where the text is going to be displayed.


CWindowGc& gc = SystemGc();
gc.Clear( aRect );
// Select the font.
const CFont* font = CCoeEnv::Static()->NormalFont();
// Load the scalable text.
HBufC* labelString = StringLoader::LoadLC(R_TEXT_EXAMPLE1);
// Choose the best variant based on the string, font and pixel width.
TPtrC outputText = AknTextUtils::ChooseScalableText(
*labelString, *font, Rect().Width());
// Draw the text to the screen.
gc.DrawText(outputText, TPoint(10, 20));
CleanupStack::PopAndDestroy(); // labelString

Internal links

This page was last modified on 26 July 2012, at 02:35.
48 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.