03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The second case will cause problems even when the phone supplies fonts with a wide range<br />

of sizes. If this situation is not dealt with properly, then the width of text at low zoom factors<br />

does not scale in proportion to the height. As can be seen in the following diagram, this can<br />

cause the text to be too wide for the surrounding box:<br />

Figure 15.6<br />

When getting a CFont from a TFontSpec you are converting from a twips size to a pixel<br />

size and, as you would expect, the height and width of a font will scale proportionately. But a<br />

character cannot be displayed in a width smaller than that of a pixel so, if the width scales to<br />

less than this, the excess will accumulate, character by character, along the length of the<br />

text.<br />

One sensible solution at such low zoom factors is to calculate the width of the whole string in<br />

twips, convert the result to pixels and simply draw a horizontal line of the appropriate length.<br />

You might want to support these low zoom factors in order to display the shape of words,<br />

sentences and paragraphs even when the font is too small to read, so eventually you can<br />

just make out where the capital letters are and, with even lower zoom states, just where the<br />

paragraphs are. This requirement applies to a print preview, for example. The Symbian OS<br />

rich text view, unlike our example application, can properly handle and display fonts even<br />

smaller than a pixel, using techniques such as that described above. Not all smartphone<br />

views will have to support this, so for many phones it is not actually an issue.<br />

Drawing the text<br />

We are now back to the hello view class's DrawInRect() function, in which we will see<br />

how our allocated font is used.<br />

void CExampleHelloView:: DrawInRect(const MGraphicsDeviceMap& aMap,<br />

CGraphicsContext& aGc, const TRect& aDeviceRect, CFont* aFont)<br />

{<br />

//Draw some text<br />

if (iFullRedraw)<br />

{<br />

aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);<br />

aGc.SetBrushColor(KRgbWhite);<br />

}<br />

else aGc.SetBrushStyle(CGraphicsContext::ENullBrush);<br />

aGc.SetPenStyle(CGraphicsContext::ESolidPen);<br />

aGc.SetPenColor(KRgbBlack);<br />

aGc.UseFont(aFont);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!