1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/test/tman/TTEXT.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,265 @@
1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Print some text, to be checked by eye
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32std.h>
1.22 +#include <e32svr.h>
1.23 +#include "W32STD.H"
1.24 +#include "../tlib/testbase.h"
1.25 +#include "TMAN.H"
1.26 +
1.27 +class TTextTest;
1.28 +
1.29 +enum {EDrawModeFonts,EDrawModeCharJust,EDrawModeWordJust};
1.30 +
1.31 +_LIT(KTestFontTypefaceName,"DejaVu Sans Condensed");
1.32 +
1.33 +class CTextWindow : public CTWin
1.34 + {
1.35 +public:
1.36 + CTextWindow(TTextTest *aTest);
1.37 + void SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
1.38 + void Draw();
1.39 + void WinKeyL(const TKeyEvent &aKey,const TTime &aTime);
1.40 + void ResetPrintLine();
1.41 + void Print(const CFont *aFont, const TDesC &aText);
1.42 + void PrintLine(const CFont *aFont, const TDesC &aText);
1.43 + void PrintDivider();
1.44 + void PrintStylesL(const TDesC &aText, TFontSpec &aFontSpec, const TFontStyle &aFontStyle);
1.45 + void DrawCharJustified(const TDesC &aText);
1.46 + void DrawWordJustified(const TDesC &aText);
1.47 + TBool NextPage();
1.48 + void SetDrawMode(TInt aMode);
1.49 +private:
1.50 + TInt iDrawMode;
1.51 + TTextTest *iTest;
1.52 + CFbsFont *iTmpFont;
1.53 + TInt iNumTypeFaces;
1.54 + TInt iTypeFaceIndex;
1.55 + TInt iXStartPos;
1.56 + TInt iYpos;
1.57 + TInt iXpos;
1.58 + };
1.59 +
1.60 +class TTextTest : public CTestBase
1.61 + {
1.62 +public:
1.63 + TTextTest();
1.64 + ~TTextTest();
1.65 + TestState DoTestL();
1.66 + void ConstructL();
1.67 +private:
1.68 + CTextWindow *iWin;
1.69 + TSize iWinSize;
1.70 + TInt iState;
1.71 + };
1.72 +
1.73 +GLDEF_C CTestBase *CreateTextTest()
1.74 + {
1.75 + return(new(ELeave) TTextTest());
1.76 + }
1.77 +
1.78 +CTextWindow::CTextWindow(TTextTest *aTest) : CTWin(), iDrawMode(EDrawModeWordJust), iTest(aTest)
1.79 + {}
1.80 +
1.81 +void CTextWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
1.82 + {
1.83 + ConstructExtLD(*parent,pos,size);
1.84 + Activate();
1.85 + AssignGC(aGc);
1.86 + iNumTypeFaces=Client()->iScreen->NumTypefaces();
1.87 + }
1.88 +
1.89 +void CTextWindow::ResetPrintLine()
1.90 + {
1.91 + iXpos=iXStartPos=5;
1.92 + iYpos=2;
1.93 + }
1.94 +
1.95 +void CTextWindow::PrintDivider()
1.96 + {
1.97 + iGc->DrawLine(TPoint(0,iYpos+5),TPoint(Size().iWidth,iYpos+5));
1.98 + iYpos+=10;
1.99 + }
1.100 +
1.101 +void CTextWindow::Print(const CFont *aFont, const TDesC &aText)
1.102 + {
1.103 + iGc->DrawText(aText, TPoint(iXpos, iYpos+aFont->AscentInPixels()));
1.104 + iXpos+=aFont->TextWidthInPixels(aText);
1.105 + }
1.106 +
1.107 +void CTextWindow::PrintLine(const CFont *aFont, const TDesC &aText)
1.108 + {
1.109 + iGc->DrawText(aText, TPoint(iXpos, iYpos+aFont->AscentInPixels()));
1.110 + iXpos=iXStartPos;
1.111 + iYpos+=aFont->HeightInPixels()+2;
1.112 + }
1.113 +
1.114 +TBool CTextWindow::NextPage()
1.115 + {
1.116 + if (iTypeFaceIndex==(iNumTypeFaces-1))
1.117 + return(ETrue);
1.118 + ++iTypeFaceIndex;
1.119 + return(EFalse);
1.120 + }
1.121 +
1.122 +void CTextWindow::PrintStylesL(const TDesC &aText, TFontSpec &aFontSpec, const TFontStyle &aFontStyle)
1.123 + {
1.124 + aFontSpec.iFontStyle=aFontStyle;
1.125 + User::LeaveIfError(Client()->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iTmpFont, aFontSpec));
1.126 + iGc->UseFont(iTmpFont);
1.127 + Print(iTmpFont,aText);
1.128 + iGc->SetUnderlineStyle(EUnderlineOn);
1.129 + Print(iTmpFont,_L("Underline, "));
1.130 + iGc->SetStrikethroughStyle(EStrikethroughOn);
1.131 + Print(iTmpFont,_L("Strikethrough/underline, "));
1.132 + iGc->SetUnderlineStyle(EUnderlineOff);
1.133 + PrintLine(iTmpFont,_L("Strikethrough"));
1.134 + iGc->SetStrikethroughStyle(EStrikethroughOff);
1.135 + Client()->iScreen->ReleaseFont(iTmpFont);
1.136 + iTmpFont=NULL;
1.137 + }
1.138 +
1.139 +void CTextWindow::DrawCharJustified(const TDesC &aText)
1.140 + {
1.141 + iGc->SetCharJustification(Size().iWidth-10-iTmpFont->TextWidthInPixels(aText),aText.Length()-1);
1.142 + PrintLine(iTmpFont, aText);
1.143 + }
1.144 +
1.145 +void CTextWindow::DrawWordJustified(const TDesC &aText)
1.146 + {
1.147 + TInt count=0;
1.148 + for(TInt index=0;index<aText.Length();index++)
1.149 + if (aText[index]==' ')
1.150 + count++;
1.151 + iGc->SetWordJustification(Size().iWidth-10-iTmpFont->TextWidthInPixels(aText),count);
1.152 + PrintLine(iTmpFont, aText);
1.153 + }
1.154 +
1.155 +void CTextWindow::Draw()
1.156 +//This function is virtual and so cannot have an 'L' at the end of it's name
1.157 + {
1.158 + iGc->Clear();
1.159 + ResetPrintLine();
1.160 + switch(iDrawMode)
1.161 + {
1.162 + case EDrawModeWordJust:
1.163 + User::LeaveIfError(Client()->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iTmpFont, TFontSpec(KTestFontTypefaceName,200)));
1.164 + iGc->UseFont(iTmpFont);
1.165 + DrawWordJustified(_L("Hello World"));
1.166 + DrawWordJustified(_L("One Two Three Four Five Six Seven"));
1.167 + DrawWordJustified(_L("AA B CC D"));
1.168 + DrawWordJustified(_L("ONEWORD"));
1.169 + iGc->DiscardFont();
1.170 + Client()->iScreen->ReleaseFont(iTmpFont);
1.171 + iTmpFont=NULL;
1.172 + break;
1.173 + case EDrawModeCharJust:
1.174 + User::LeaveIfError(Client()->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iTmpFont, TFontSpec(KTestFontTypefaceName,200)));
1.175 + iGc->UseFont(iTmpFont);
1.176 + DrawCharJustified(_L("Hello World"));
1.177 + DrawCharJustified(_L("One Two Three Four Five Six Seven"));
1.178 + DrawCharJustified(_L("AA B CC D"));
1.179 + DrawCharJustified(_L("ONEWORD"));
1.180 + iGc->DiscardFont();
1.181 + Client()->iScreen->ReleaseFont(iTmpFont);
1.182 + iTmpFont=NULL;
1.183 + break;
1.184 + case EDrawModeFonts:
1.185 + {
1.186 + TTypefaceSupport typefaceSupport;
1.187 + Client()->iScreen->TypefaceSupport(typefaceSupport,iTypeFaceIndex);
1.188 + TBuf<0x40> title;
1.189 + TBuf16<KMaxTypefaceNameLength> tmpBuf;
1.190 + tmpBuf.Copy(typefaceSupport.iTypeface.iName);
1.191 + title.Append(tmpBuf);
1.192 + title.AppendFormat(TRefByValue<const TDesC>(_L(", Heights (Min=%d, Max=%d, Num=%d)")),typefaceSupport.iMinHeightInTwips,typefaceSupport.iMaxHeightInTwips,typefaceSupport.iNumHeights);
1.193 + PrintLine(iFont,title);
1.194 + PrintDivider();
1.195 + for (TInt tfHeight=0;tfHeight<typefaceSupport.iNumHeights;tfHeight++)
1.196 + {
1.197 + TFontSpec fspec(typefaceSupport.iTypeface.iName,Client()->iScreen->FontHeightInTwips(iTypeFaceIndex,tfHeight));
1.198 + PrintStylesL(_L("Normal, "), fspec, TFontStyle());
1.199 + PrintStylesL(_L("Bold, "), fspec, TFontStyle(EPostureUpright,EStrokeWeightBold,EPrintPosNormal));
1.200 + PrintStylesL(_L("Italic, "), fspec, TFontStyle(EPostureItalic,EStrokeWeightNormal,EPrintPosNormal));
1.201 + PrintStylesL(_L("Bold/italic, "), fspec, TFontStyle(EPostureItalic,EStrokeWeightBold,EPrintPosNormal));
1.202 + if (iYpos>Size().iHeight)
1.203 + break;
1.204 + }
1.205 + }
1.206 + break;
1.207 + }
1.208 + }
1.209 +
1.210 +void CTextWindow::WinKeyL(const TKeyEvent &aKey,const TTime &)
1.211 + {
1.212 + if (iDrawMode!=EDrawModeFonts || (aKey.iCode==EKeyEscape || NextPage()))
1.213 + CActiveScheduler::Stop();
1.214 + else
1.215 + iWin.Invalidate();
1.216 + }
1.217 +
1.218 +void CTextWindow::SetDrawMode(TInt aDrawMode)
1.219 + {
1.220 + iDrawMode=aDrawMode;
1.221 + iWin.Invalidate();
1.222 + }
1.223 +
1.224 +TTextTest::TTextTest() : CTestBase(_L("Text"))
1.225 + {}
1.226 +
1.227 +TTextTest::~TTextTest()
1.228 + {
1.229 + CTWin::Delete(iWin);
1.230 + }
1.231 +
1.232 +void TTextTest::ConstructL()
1.233 + {
1.234 + CTextWindow *win=new(ELeave) CTextWindow(this);
1.235 + win->SetUpLD(TPoint(0,0),Client()->iScreen->SizeInPixels(),Client()->iGroup,*Client()->iGc);
1.236 + iWin=win;
1.237 + Client()->iGroup->SetCurrentWindow(iWin);
1.238 + Client()->iGroup->GroupWin()->SetOrdinalPosition(0);
1.239 + }
1.240 +
1.241 +TestState TTextTest::DoTestL()
1.242 + {
1.243 + switch(iState)
1.244 + {
1.245 + case 0:
1.246 + LogSubTest(_L("SetWordJustification"),1);
1.247 + iWin->SetDrawMode(EDrawModeWordJust);
1.248 + CActiveScheduler::Start();
1.249 + iState++;
1.250 + break;
1.251 + case 1:
1.252 + LogSubTest(_L("SetCharJustification"),2);
1.253 + iWin->SetDrawMode(EDrawModeCharJust);
1.254 + CActiveScheduler::Start();
1.255 + iState++;
1.256 + break;
1.257 + case 2:
1.258 + LogSubTest(_L("Text 1"),3);
1.259 + iWin->SetDrawMode(EDrawModeFonts);
1.260 + CActiveScheduler::Start();
1.261 + iState++;
1.262 + break;
1.263 + default:
1.264 + return(EFinished);
1.265 + }
1.266 + return(ENext);
1.267 + }
1.268 +