diff -r f345bda72bc4 -r 43e37759235e Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_fonts_8cpp_source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/_fonts_8cpp_source.html Tue Mar 30 16:16:55 2010 +0100 @@ -0,0 +1,106 @@ + + +
+ +00001 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). +00002 // All rights reserved. +00003 // This component and the accompanying materials are made available +00004 // under the terms of "Eclipse Public License v1.0" +00005 // which accompanies this distribution, and is available +00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". +00007 // +00008 // Initial Contributors: +00009 // Nokia Corporation - initial contribution. +00010 // +00011 // Contributors: +00012 // +00013 // Description: +00014 // +00015 +00016 #include "FontsGraphicsControl.h" +00017 #include <coemain.h> +00018 +00019 CFontControl::CFontControl() { +00020 // find the number of typefaces +00021 iNumTypefaces = iCoeEnv->ScreenDevice()->NumTypefaces(); +00022 // set the number of phases to the number of typefaces +00023 SetMaxPhases(iNumTypefaces); +00024 } +00025 +00026 void CFontControl::UpdateModelL() +00027 { +00028 // set up zoom factor & graphics device map for getting fonts and drawing text +00029 iZoomFactor.SetGraphicsDeviceMap(iCoeEnv->ScreenDevice()); +00030 iZoomFactor.SetZoomFactor(TZoomFactor::EZoomOneToOne); +00031 iDeviceMap = &iZoomFactor; +00032 +00033 // find the font to display this phase +00034 TTypefaceSupport* myTypefaceSupport = new TTypefaceSupport; +00035 iCoeEnv->ScreenDevice()->TypefaceSupport(*myTypefaceSupport,Phase()); +00036 iCurrentFont = myTypefaceSupport->iTypeface.iName.Des(); +00037 +00038 // set up descriptor for commentary area +00039 _LIT(KFormat,"Typeface index=%d. Name=%S. Num heights=%d. (Num typefaces=%d)"); +00040 TBuf<128> commentaryText; +00041 commentaryText.Format(KFormat,Phase(),&iCurrentFont,myTypefaceSupport->iNumHeights,iNumTypefaces); +00042 iGraphObserver->NotifyStatus(commentaryText); +00043 delete myTypefaceSupport; +00044 }; +00045 +00046 void CFontControl::Draw(const TRect& /* aRect */) const +00047 { +00048 // setup screen for example +00049 CWindowGc& gc=SystemGc(); +00050 gc.Clear(); +00051 +00052 // create a centered rectangle of the default size +00053 TRect screenRect=Rect(); +00054 +00055 // set up absolute font-spec and text box for 300 twip font +00056 TFontSpec fontSpec(iCurrentFont,300); +00057 // find the nearest font to the specified one +00058 CFont* screenFont; +00059 iDeviceMap->GetNearestFontInTwips(screenFont,fontSpec); +00060 // use it for this graphics context +00061 gc.UseFont(screenFont); +00062 +00063 // get height of screen box +00064 TInt screenHeight=screenRect.Height(); +00065 // get font height +00066 TInt textHeight = screenFont->HeightInPixels(); +00067 +00068 // set up the positioning of the character set rows +00069 TInt exampleMargin = 0; +00070 TInt currentOffset = ((screenHeight+textHeight)/2) - (TInt)(textHeight*2.4); +00071 +00072 // set up descriptors to hold Unicode characters 32 to 255 +00073 TBuf<50> buffer; +00074 TInt endPoint[6] = {64,96,138,182,216,255}; +00075 TInt count = 32; +00076 for(TInt pass=0;pass<=5;pass++) { +00077 while (count<=endPoint[pass]) { +00078 buffer.Append((TUint)count); +00079 count++; +00080 } +00081 // draw the row in the current font +00082 gc.DrawText(buffer,screenRect,currentOffset,CGraphicsContext::ECenter,exampleMargin); +00083 currentOffset = currentOffset + (TInt)(textHeight*1.2); +00084 buffer.Zero(); +00085 } +00086 +00087 // discard and release font +00088 gc.DiscardFont(); +00089 iDeviceMap->ReleaseFont(screenFont); +00090 } +