examples/Graphics/Fonts/Fonts.cpp

00001 /*
00002 Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 #include "FontsGraphicsControl.h"
00032 #include <coemain.h>
00033 
00034 CFontControl::CFontControl() {
00035         // find the number of typefaces
00036         iNumTypefaces = iCoeEnv->ScreenDevice()->NumTypefaces();
00037         // set the number of phases to the number of typefaces
00038         SetMaxPhases(iNumTypefaces);
00039 }
00040 
00041 void CFontControl::UpdateModelL()
00042         {
00043         // set up zoom factor & graphics device map for getting fonts and drawing text
00044         iZoomFactor.SetGraphicsDeviceMap(iCoeEnv->ScreenDevice());
00045         iZoomFactor.SetZoomFactor(TZoomFactor::EZoomOneToOne);
00046         iDeviceMap = &iZoomFactor;
00047 
00048         // find the font to display this phase
00049         TTypefaceSupport* myTypefaceSupport = new TTypefaceSupport;
00050         iCoeEnv->ScreenDevice()->TypefaceSupport(*myTypefaceSupport,Phase());
00051         iCurrentFont = myTypefaceSupport->iTypeface.iName.Des();
00052 
00053         // set up descriptor for commentary area
00054         _LIT(KFormat,"Typeface index=%d. Name=%S. Num heights=%d. (Num typefaces=%d)");
00055         TBuf<128> commentaryText;
00056         commentaryText.Format(KFormat,Phase(),&iCurrentFont,myTypefaceSupport->iNumHeights,iNumTypefaces);
00057         iGraphObserver->NotifyStatus(commentaryText);
00058         delete myTypefaceSupport;
00059         };
00060 
00061 void CFontControl::Draw(const TRect& /* aRect */) const
00062         {
00063         // setup screen for example
00064         CWindowGc& gc=SystemGc();
00065         gc.Clear();     
00066         
00067         // create a centered rectangle of the default size
00068         TRect screenRect=Rect();
00069 
00070         // set up absolute font-spec and text box for 300 twip font
00071         TFontSpec fontSpec(iCurrentFont,300);
00072         // find the nearest font to the specified one
00073         CFont* screenFont;                                                                              
00074         iDeviceMap->GetNearestFontInTwips(screenFont,fontSpec);
00075         // use it for this graphics context
00076         gc.UseFont(screenFont);
00077 
00078         // get height of screen box
00079     TInt screenHeight=screenRect.Height();
00080         // get font height
00081     TInt textHeight = screenFont->HeightInPixels();
00082 
00083         // set up the positioning of the character set rows
00084         TInt exampleMargin = 0;
00085         TInt currentOffset = ((screenHeight+textHeight)/2) - (TInt)(textHeight*2.4);
00086 
00087         // set up descriptors to hold Unicode characters 32 to 255
00088         TBuf<50> buffer;
00089         TInt endPoint[6] = {64,96,138,182,216,255};
00090         TInt count = 32;
00091         for(TInt pass=0;pass<=5;pass++) {
00092                 while (count<=endPoint[pass]) {
00093                         buffer.Append((TUint)count);
00094                         count++;
00095                 }
00096                 // draw the row in the current font
00097                 gc.DrawText(buffer,screenRect,currentOffset,CGraphicsContext::ECenter,exampleMargin);   
00098                 currentOffset = currentOffset + (TInt)(textHeight*1.2);
00099                 buffer.Zero();
00100         }
00101 
00102         // discard and release font
00103         gc.DiscardFont();
00104         iDeviceMap->ReleaseFont(screenFont);    
00105         }

Generated by  doxygen 1.6.2