Update contrib.
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Print some text, to be checked by eye
21 #include "../tlib/testbase.h"
26 enum {EDrawModeFonts,EDrawModeCharJust,EDrawModeWordJust};
28 _LIT(KTestFontTypefaceName,"DejaVu Sans Condensed");
30 class CTextWindow : public CTWin
33 CTextWindow(TTextTest *aTest);
34 void SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
36 void WinKeyL(const TKeyEvent &aKey,const TTime &aTime);
37 void ResetPrintLine();
38 void Print(const CFont *aFont, const TDesC &aText);
39 void PrintLine(const CFont *aFont, const TDesC &aText);
41 void PrintStylesL(const TDesC &aText, TFontSpec &aFontSpec, const TFontStyle &aFontStyle);
42 void DrawCharJustified(const TDesC &aText);
43 void DrawWordJustified(const TDesC &aText);
45 void SetDrawMode(TInt aMode);
57 class TTextTest : public CTestBase
70 GLDEF_C CTestBase *CreateTextTest()
72 return(new(ELeave) TTextTest());
75 CTextWindow::CTextWindow(TTextTest *aTest) : CTWin(), iDrawMode(EDrawModeWordJust), iTest(aTest)
78 void CTextWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
80 ConstructExtLD(*parent,pos,size);
83 iNumTypeFaces=Client()->iScreen->NumTypefaces();
86 void CTextWindow::ResetPrintLine()
92 void CTextWindow::PrintDivider()
94 iGc->DrawLine(TPoint(0,iYpos+5),TPoint(Size().iWidth,iYpos+5));
98 void CTextWindow::Print(const CFont *aFont, const TDesC &aText)
100 iGc->DrawText(aText, TPoint(iXpos, iYpos+aFont->AscentInPixels()));
101 iXpos+=aFont->TextWidthInPixels(aText);
104 void CTextWindow::PrintLine(const CFont *aFont, const TDesC &aText)
106 iGc->DrawText(aText, TPoint(iXpos, iYpos+aFont->AscentInPixels()));
108 iYpos+=aFont->HeightInPixels()+2;
111 TBool CTextWindow::NextPage()
113 if (iTypeFaceIndex==(iNumTypeFaces-1))
119 void CTextWindow::PrintStylesL(const TDesC &aText, TFontSpec &aFontSpec, const TFontStyle &aFontStyle)
121 aFontSpec.iFontStyle=aFontStyle;
122 User::LeaveIfError(Client()->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iTmpFont, aFontSpec));
123 iGc->UseFont(iTmpFont);
124 Print(iTmpFont,aText);
125 iGc->SetUnderlineStyle(EUnderlineOn);
126 Print(iTmpFont,_L("Underline, "));
127 iGc->SetStrikethroughStyle(EStrikethroughOn);
128 Print(iTmpFont,_L("Strikethrough/underline, "));
129 iGc->SetUnderlineStyle(EUnderlineOff);
130 PrintLine(iTmpFont,_L("Strikethrough"));
131 iGc->SetStrikethroughStyle(EStrikethroughOff);
132 Client()->iScreen->ReleaseFont(iTmpFont);
136 void CTextWindow::DrawCharJustified(const TDesC &aText)
138 iGc->SetCharJustification(Size().iWidth-10-iTmpFont->TextWidthInPixels(aText),aText.Length()-1);
139 PrintLine(iTmpFont, aText);
142 void CTextWindow::DrawWordJustified(const TDesC &aText)
145 for(TInt index=0;index<aText.Length();index++)
146 if (aText[index]==' ')
148 iGc->SetWordJustification(Size().iWidth-10-iTmpFont->TextWidthInPixels(aText),count);
149 PrintLine(iTmpFont, aText);
152 void CTextWindow::Draw()
153 //This function is virtual and so cannot have an 'L' at the end of it's name
159 case EDrawModeWordJust:
160 User::LeaveIfError(Client()->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iTmpFont, TFontSpec(KTestFontTypefaceName,200)));
161 iGc->UseFont(iTmpFont);
162 DrawWordJustified(_L("Hello World"));
163 DrawWordJustified(_L("One Two Three Four Five Six Seven"));
164 DrawWordJustified(_L("AA B CC D"));
165 DrawWordJustified(_L("ONEWORD"));
167 Client()->iScreen->ReleaseFont(iTmpFont);
170 case EDrawModeCharJust:
171 User::LeaveIfError(Client()->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iTmpFont, TFontSpec(KTestFontTypefaceName,200)));
172 iGc->UseFont(iTmpFont);
173 DrawCharJustified(_L("Hello World"));
174 DrawCharJustified(_L("One Two Three Four Five Six Seven"));
175 DrawCharJustified(_L("AA B CC D"));
176 DrawCharJustified(_L("ONEWORD"));
178 Client()->iScreen->ReleaseFont(iTmpFont);
183 TTypefaceSupport typefaceSupport;
184 Client()->iScreen->TypefaceSupport(typefaceSupport,iTypeFaceIndex);
186 TBuf16<KMaxTypefaceNameLength> tmpBuf;
187 tmpBuf.Copy(typefaceSupport.iTypeface.iName);
188 title.Append(tmpBuf);
189 title.AppendFormat(TRefByValue<const TDesC>(_L(", Heights (Min=%d, Max=%d, Num=%d)")),typefaceSupport.iMinHeightInTwips,typefaceSupport.iMaxHeightInTwips,typefaceSupport.iNumHeights);
190 PrintLine(iFont,title);
192 for (TInt tfHeight=0;tfHeight<typefaceSupport.iNumHeights;tfHeight++)
194 TFontSpec fspec(typefaceSupport.iTypeface.iName,Client()->iScreen->FontHeightInTwips(iTypeFaceIndex,tfHeight));
195 PrintStylesL(_L("Normal, "), fspec, TFontStyle());
196 PrintStylesL(_L("Bold, "), fspec, TFontStyle(EPostureUpright,EStrokeWeightBold,EPrintPosNormal));
197 PrintStylesL(_L("Italic, "), fspec, TFontStyle(EPostureItalic,EStrokeWeightNormal,EPrintPosNormal));
198 PrintStylesL(_L("Bold/italic, "), fspec, TFontStyle(EPostureItalic,EStrokeWeightBold,EPrintPosNormal));
199 if (iYpos>Size().iHeight)
207 void CTextWindow::WinKeyL(const TKeyEvent &aKey,const TTime &)
209 if (iDrawMode!=EDrawModeFonts || (aKey.iCode==EKeyEscape || NextPage()))
210 CActiveScheduler::Stop();
215 void CTextWindow::SetDrawMode(TInt aDrawMode)
221 TTextTest::TTextTest() : CTestBase(_L("Text"))
224 TTextTest::~TTextTest()
229 void TTextTest::ConstructL()
231 CTextWindow *win=new(ELeave) CTextWindow(this);
232 win->SetUpLD(TPoint(0,0),Client()->iScreen->SizeInPixels(),Client()->iGroup,*Client()->iGc);
234 Client()->iGroup->SetCurrentWindow(iWin);
235 Client()->iGroup->GroupWin()->SetOrdinalPosition(0);
238 TestState TTextTest::DoTestL()
243 LogSubTest(_L("SetWordJustification"),1);
244 iWin->SetDrawMode(EDrawModeWordJust);
245 CActiveScheduler::Start();
249 LogSubTest(_L("SetCharJustification"),2);
250 iWin->SetDrawMode(EDrawModeCharJust);
251 CActiveScheduler::Start();
255 LogSubTest(_L("Text 1"),3);
256 iWin->SetDrawMode(EDrawModeFonts);
257 CActiveScheduler::Start();