week 10 bug fix submission: Bug 1892, Bug 1897, Bug 1319. Also 3 or 4 documents were found to contain code blocks with SFL, which has been fixed. Partial fix for broken links, links to Forum Nokia, and the 'Symbian platform' terminology issues.
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License
"Eclipse Public License v1.0" which accompanies this distribution,
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
Nokia Corporation - initial contribution.
Contributors:
-->
<!DOCTYPE concept
PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept xml:lang="en" id="GUID-6AE2F937-69BB-5330-A2B5-44D37FA1DE16"><title>Using TZoomFactor and MGraphicsDeviceMap</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>This topic provides examples that demonstrate the effects of different zoom factors on text and graphics. Example code displays some text, a rectangle, and a bitmap at various different zoom factors, with commentary text set at a fixed zoom factor. </p> <section><title>Setting up a TZoomFactor</title> <p>The following fragment of code demonstrates how to set up a zoom factor object. The zoom factor is first set to 1-to-1 (no zoom) using the value <codeph>TZoomFactor::EZoomOneToOne</codeph>. Then it is shown how to set a zoom factor by multiplying or dividing <codeph>EZoomOneToOne</codeph>. </p> <p>In actual applications, for example, one zoom factor could be used for the client area of an application which can be zoomed, and another for drawing menus and button-bars which should not be zoomed. </p> <codeblock id="GUID-9EB63708-5DD8-53DB-9317-BA777C6A774F" xml:space="preserve">// Create zoom factor object
TZoomFactor devicemap(iCoeEnv->ScreenDevice());
// Set zoom factor at 1 to 1
devicemap.SetZoomFactor(TZoomFactor::EZoomOneToOne);
// Set zoom factor at 200%
devicemap.SetZoomFactor(TZoomFactor::EZoomOneToOne*2);</codeblock> </section> <section><title>Twips to pixels conversions using a zoom factor</title> <ol id="GUID-C7A9D77A-4074-513E-96C8-64771CD9DBE9"><li id="GUID-08C11537-63B4-5CC6-AA18-EFF020908395"><p>Define a rectangle in twips </p> </li> <li id="GUID-D91476D5-2244-5AA3-8536-C78A4A6DD4B5"><p>Use the device map’s conversion function <codeph>TwipsToPixels()</codeph> to convert the rectangles co-ordinates into pixels </p> </li> <li id="GUID-2CDC8C9B-D04C-5DF7-BD15-0E6C03E46F35"><p>Draw the rectangle using <codeph>DrawRect()</codeph> in the graphics context <codeph>gc</codeph> </p> </li> </ol> <codeblock id="GUID-FCC32729-1CC6-526B-AF25-2EB75916FD9D" xml:space="preserve">// set up example box in twips
TRect boxInTwips(TPoint(0,0),TPoint(500,300));
// convert rectangle co-ordinates into pixels
TRect boxInPixels = deviceMap->TwipsToPixels(boxInTwips);
gc.DrawRect(boxInPixels);</codeblock> <p> <b>Note</b>: The actual conversion that <codeph>TwipsToPixels()</codeph> applies is dependent on the device map’s zoom factor setting, and the twips to pixels mapping of the graphics device which the device map is associated with. </p> </section> <section><title>Drawing text using a zoom factor</title> <p>This fragment of code shows how to draw text using a zoom factor. </p> <ol id="GUID-EF916973-472C-5CF8-8DA7-0C57811C610E"><li id="GUID-BD44D220-1803-5DE4-AEB2-7384B7AEAE11"><p>Create a font specification (in this case for a 10 point Times New Roman font) </p> </li> <li id="GUID-6F7C648C-C126-5E5D-BCDE-EEB700556BA2"><p>Find the nearest device font, using <codeph>MGraphicsDeviceMap::GetNearestFontInTwips()</codeph>, to that specified. This takes into account the map’s zoom factor and twips to pixel mapping. </p> </li> <li id="GUID-C0A1C89C-5061-5D64-88AC-010C942E978D"><p>Use this device font to draw the text using <codeph>CGraphicsContext::DrawText()</codeph> </p> </li> <li id="GUID-531E3DEF-30EA-5526-854B-9848909950A3"><p>Discard the font using <codeph>CGraphicsContext::DiscardFont()</codeph> and <codeph>MGraphicsDeviceMap::ReleaseFont()</codeph> </p> </li> </ol> <codeblock id="GUID-9EAEF125-A4BE-5157-9DE9-2A2C458AA9B2" xml:space="preserve">// set up absolute font-spec and text box for 200 twip Roman font
TFontSpec fontSpec(_L("Times New Roman"),200);
// find the nearest font to the specified one
CFont* screenFont;
deviceMap->GetNearestFontInTwips(screenFont,fontSpec);
// use it for this graphics context
gc.UseFont(screenFont);
gc.DrawText(_L("some example text"),TPoint(20,20));
// discard and release font
gc.DiscardFont();
deviceMap->ReleaseFont(screenFont);</codeblock> <p> <b>Note</b>: Due to the overhead of running <codeph>GetNearestFontInTwips()</codeph>, the caller would normally cache any fonts provided by it at the start of an application and after each change to the zoom factor, and only release them when the application is exited or the zoom factor changed. </p> </section> <section><title>Zooming bitmaps</title> <p>You can draw a bitmap to the graphics device, scaled according to the current zoom factor. </p> <ol id="GUID-8D34A01B-6AFC-50AE-8361-F4DACDF5F996"><li id="GUID-8DEB5B9C-9645-5E87-8246-3DAF8E7A8ABB"><p>Define a rectangle in twips </p> </li> <li id="GUID-655DAAF4-D6F9-5DDD-8B6F-532BC8F67AE3"><p>Use the device map’s conversion function <codeph>TwipsToPixels()</codeph> to convert the rectangle's co-ordinates into pixels according to the current zoom factor. </p> </li> <li id="GUID-30E099EC-7864-5836-800B-BE06998AED0F"><p>Draw the bitmap using <codeph>DrawBitmap()</codeph> stretched/compressed into the rectangle. </p> </li> </ol> <codeblock id="GUID-CE18C461-47D0-587F-9DE0-2F7D200AB261" xml:space="preserve">// set up rectangle for bitmap to be stretched into
TRect bitmapRectInTwips(TPoint(0,0),TPoint(500,500));
TRect bitmapRectInPixels = iLeftMap->TwipsToPixels(bitmapRectInTwips);
bitmapRectInPixels.iTl.iY+=125;
bitmapRectInPixels.iBr.iY+=125;
bitmapRectInPixels.iTl.iX+=100;
bitmapRectInPixels.iBr.iX+=100;
// draw the bitmap, stretched into the rectangle
SystemGc.DrawBitmap(bitmapRectInPixels, iBitmap);</codeblock> </section> </conbody><related-links><link href="GUID-067BC702-4F66-5CAF-952D-7CFA35F5EB1E.dita"><linktext>Twip to Pixel Mapping</linktext> </link> <link href="GUID-1E68A78A-52E5-5DF7-B540-85C7194E4617.dita"><linktext>Graphics Device Interface Tutorials</linktext> </link> <link href="GUID-E9FF94D2-AFFD-54A4-A6C2-00929BC70DB0.dita"><linktext>Bitmaps</linktext> </link> </related-links></concept>