First public contribution.
1 // Copyright (c) 2006-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.
19 @internalComponent - Internal Symbian test code
23 #include "tcomplexfonts.h"
28 #include <coefontprovider.h>
31 _LIT(KTestStep0010, "GRAPHICS-UI-BENCH-S60-0010");
33 _LIT(KSemaphore, "SemDrawSync"); // Name of the global semaphore
36 // constants to define the format of the text
37 const TInt KHeadingParagraph = 0;
38 const TInt KClassParagraph = 2;
39 const TInt KDescriptionHeading = 4;
40 const TInt KDerivationHeading = 10;
41 const TInt KFirstDerivation = 12;
42 const TInt KLastDerivation = 16;
44 const TInt KHeaderFontSize = 13 * 20; // in TWIPs
45 const TInt KBodyFontSize = 8 * 20; // in TWIPs
46 const TInt KBodyLineSpacing = 10; // in TWIPs
47 const TInt KBodyIndent = 300; // in TWIPs
49 const TInt KIterationsToTest = 50; // number of iterations
52 CTComplexFonts::CTComplexFonts()
54 SetTestStepName(KTComplexFonts);
57 void CTComplexFonts::InitUIL(CCoeEnv* aCoeEnv)
59 CComplexFontsAppUi* appUi = new(ELeave) CComplexFontsAppUi();
60 CleanupStack::PushL(appUi);
62 aCoeEnv->SetAppUi(appUi);
63 CleanupStack::Pop(appUi);
66 TVerdict CTComplexFonts::doTestStepPreambleL()
68 // The semaphore has to be created before, otherwise the control can't open it.
69 TESTNOERRORL(iSemaphore.CreateGlobal(KSemaphore, 0));
70 return CTe_ConeStepBase::doTestStepPreambleL();
73 TVerdict CTComplexFonts::doTestStepPostambleL()
75 GenerateEventL(TRawEvent::EButton1Up);
77 return CTe_ConeStepBase::doTestStepPostambleL();
81 Override of base class pure virtual
82 Our implementation only gets called if the base class doTestStepPreambleL() did
85 @return - TVerdict code
87 TVerdict CTComplexFonts::doTestStepL()
89 SetTestStepName(KTestStep0010);
90 TRAPD(err, DrawComplexFontsL());
93 SetTestStepResult(EAbort);
95 return TestStepResult();
100 GRAPHICS-UI-BENCH-S60-0010
103 Tests how long it takes format and draw a CRichText object.
106 Create a complex font control. Format and draw the text control each time
107 it receives a left pointer down event. The test step and the drawing of the
108 control is synchronized with a Semaphore.
110 @SYMTestExpectedResults
111 Test should pass and display the average framerate for the test.
113 void CTComplexFonts::DrawComplexFontsL()
115 iProfiler->InitResults();
116 for(TInt i = KIterationsToTest; i > 0; --i)
118 GenerateEventL(TRawEvent::EButton1Down);
121 iProfiler->MarkResultSetL();
122 TSize screenSize = CTWindow::GetDisplaySizeInPixels();
123 iProfiler->ResultsAnalysisFrameRate(KTestStep0010, 0, 0, 0, KIterationsToTest, screenSize.iWidth * screenSize.iHeight);
127 * Generates events to communicate with the control. Each time the control receives an event
128 * it redraws itself. That's necessary because the draw method can't be called directly from
129 * a different thread.
131 void CTComplexFonts::GenerateEventL(TRawEvent::TType aEventType)
134 rawEvent.Set(aEventType, 0, 0);
135 User::LeaveIfError(UserSvr::AddEvent(rawEvent));
139 CComplexFontsAppUi::CComplexFontsAppUi()
144 void CComplexFontsAppUi::ConstructL()
146 BaseConstructL(ENoAppResourceFile);
147 iComplexFontsControl = CComplexFontsControl::NewL();
148 AddToStackL(iComplexFontsControl);
151 CComplexFontsAppUi::~CComplexFontsAppUi()
153 RemoveFromStack(iComplexFontsControl);
154 delete iComplexFontsControl;
158 CComplexFontsControl* CComplexFontsControl::NewLC(const CCoeControl* aParent)
160 CComplexFontsControl* self;
161 self = new(ELeave) CComplexFontsControl();
162 CleanupStack::PushL(self);
163 self->ConstructL(aParent);
167 CComplexFontsControl* CComplexFontsControl::NewL(const CCoeControl* aParent)
169 CComplexFontsControl* self;
170 self = CComplexFontsControl::NewLC(aParent);
171 CleanupStack::Pop(self);
175 CComplexFontsControl::CComplexFontsControl() : iWsSession(CCoeEnv::Static()->WsSession())
180 CComplexFontsControl::~CComplexFontsControl()
185 delete iCharFormatLayer;
186 delete iParaFormatLayer;
192 * Constructs the text control with the complex fonts.
194 void CComplexFontsControl::ConstructL(const CCoeControl* aParent)
196 User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore));
199 SetContainerWindowL(*aParent);
205 // Create text object, text view and layout.
206 iParaFormatLayer = CParaFormatLayer::NewL();
207 iCharFormatLayer = CCharFormatLayer::NewL();
208 // Create an empty rich text object
209 iRichText = CRichText::NewL(iParaFormatLayer, iCharFormatLayer);
211 iScreen = new(ELeave) CWsScreenDevice(ControlEnv()->WsSession());
212 User::LeaveIfError(iScreen->Construct()); // default screen used
214 TPixelsAndRotation pixelsAndRotation;
215 iScreen->GetDefaultScreenSizeAndRotation(pixelsAndRotation);
217 // Create the text layout, (required by text view),
218 // with the text object and a wrap width (=width of view rect)
219 iLayout = CTextLayout::NewL(iRichText,pixelsAndRotation.iPixelSize.iWidth);
222 iTextView = CTextView::NewL(iLayout, pixelsAndRotation.iPixelSize,
223 iScreen, iScreen, &Window(), 0, // no window group
224 &iCoeEnv->WsSession()); // new view
226 SetRect(TRect(TPoint(0, 0), pixelsAndRotation.iPixelSize));
229 iRichText->InsertL(0, KComplexFontsText);
231 // break up into paragraphs for CRichText by replacing \n characters in original text
232 // with CEditableText::EParagraphDelimiter
233 TPtrC complexFontsTextPtr(KComplexFontsText);
234 TInt eos = complexFontsTextPtr.Length();
235 for (TInt paragraphBreakLocation = 0; paragraphBreakLocation < eos; paragraphBreakLocation++)
237 if (complexFontsTextPtr[paragraphBreakLocation] == '\n')
239 iRichText->DeleteL(paragraphBreakLocation, 1);
240 iRichText->InsertL(paragraphBreakLocation, CEditableText::EParagraphDelimiter);
244 TCharFormat charFormat;
245 TCharFormatMask charFormatMask;
246 // format the first paragraph "Class RWindow" as orange and a bit bigger than the body
247 charFormat.iFontPresentation.iTextColor= TLogicalRgb(TRgb(0x0099ff));
248 charFormatMask.SetAttrib(EAttColor);
249 charFormat.iFontSpec.iHeight = KHeaderFontSize;
250 charFormatMask.SetAttrib(EAttFontHeight);
252 TInt headerLength = 0;
253 TInt headerStart = iRichText->CharPosOfParagraph(headerLength, KHeadingParagraph);
254 iRichText->ApplyCharFormatL(charFormat, charFormatMask, headerStart, headerLength);
255 charFormatMask.ClearAll();
257 // format "Class" as Sans Serif
258 charFormat.iFontSpec.iTypeface.iName = KNokiaSeries60Font;
259 charFormatMask.SetAttrib(EAttFontTypeface);
260 iRichText->ApplyCharFormatL(charFormat, charFormatMask, headerStart, 5);
261 charFormatMask.ClearAll();
263 // make the rest of the text smaller
264 charFormat.iFontSpec.iHeight = KBodyFontSize;
265 charFormatMask.SetAttrib(EAttFontHeight);
266 TInt textLength = iRichText->DocumentLength();
267 iRichText->ApplyCharFormatL(charFormat, charFormatMask, headerLength, textLength - headerLength);
268 charFormatMask.ClearAll();
270 TParaFormatMask paraFormatMask;
271 // crunch main body a bit closer together to show more on the little screen
272 // and indent left margin
273 iParaFormat.iLineSpacingInTwips = KBodyLineSpacing;
274 paraFormatMask.SetAttrib(EAttLineSpacing);
275 iParaFormat.iLineSpacingControl = CParaFormat::ELineSpacingExactlyInPixels;
276 paraFormatMask.SetAttrib(EAttLineSpacingControl);
277 iParaFormat.iLeftMarginInTwips = KBodyIndent;
278 paraFormatMask.SetAttrib(EAttLeftMargin);
279 iRichText->ApplyParaFormatL(&iParaFormat, paraFormatMask, headerLength, textLength - headerLength);
280 paraFormatMask.ClearAll();
285 // put a grey background on "class RWindow : public RDrawableWindow;"
286 start = iRichText->CharPosOfParagraph(length, KClassParagraph);
287 iParaFormat.iFillColor = TLogicalRgb(TRgb(0xdddddd));
288 paraFormatMask.SetAttrib(EAttFillColor);
289 iRichText->ApplyParaFormatL(&iParaFormat, paraFormatMask, start, length);
290 paraFormatMask.ClearAll();
292 // make "Description" and "Derivation" subheadings bold
293 charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
294 charFormatMask.SetAttrib(EAttFontStrokeWeight);
295 start = iRichText->CharPosOfParagraph(length, KDescriptionHeading);
296 iRichText->ApplyCharFormatL(charFormat, charFormatMask, start, length);
297 start = iRichText->CharPosOfParagraph(length, KDerivationHeading);
298 iRichText->ApplyCharFormatL(charFormat, charFormatMask, start, length);
299 charFormatMask.ClearAll();
301 // all the paragraphs between and including "Description" and "Derivation" are in sans serif
302 // (the default CRichText font is serif)
303 TInt paragraphNumber = 0;
305 charFormat.iFontSpec.iTypeface.iName = KNokiaSeries60Font;
306 charFormatMask.SetAttrib(EAttFontTypeface);
307 for (paragraphNumber = KDescriptionHeading; paragraphNumber <= KDerivationHeading; paragraphNumber++)
309 start = iRichText->CharPosOfParagraph(length, paragraphNumber);
310 iRichText->ApplyCharFormatL(charFormat, charFormatMask, start, length);
312 charFormatMask.ClearAll();
314 // for each line in the "Derivation" section
315 // progressively indent left margin
316 // make class name blue underlined (it starts two characters after the
317 // beginning of each paragraph and goes to the space before the '-')
318 // make descriptive text sans serif (from the '-' to the end of the paragraph)
319 paraFormatMask.SetAttrib(EAttLeftMargin);
320 charFormat.iFontPresentation.iTextColor= TLogicalRgb(TRgb(0xA27316));
321 charFormat.iFontPresentation.iUnderline = EUnderlineOn;
322 for (paragraphNumber = KFirstDerivation; paragraphNumber <= KLastDerivation; paragraphNumber++)
324 iParaFormat.iLeftMarginInTwips = (paragraphNumber - KFirstDerivation + 2)*KBodyIndent;
325 start = iRichText->CharPosOfParagraph(length, paragraphNumber);
326 iRichText->ApplyParaFormatL(&iParaFormat, paraFormatMask, start, length);
328 for (dash = start; dash < start + length; dash++)
330 if (complexFontsTextPtr[dash] == '-')
335 charFormatMask.SetAttrib(EAttColor);
336 charFormatMask.SetAttrib(EAttFontUnderline);
337 TInt classNameLength = (dash - 1) - (start + 2);
338 iRichText->ApplyCharFormatL(charFormat, charFormatMask, start + 2, classNameLength);
339 charFormatMask.ClearAll();
340 charFormatMask.SetAttrib(EAttFontTypeface);
341 TInt descriptionLength = length - classNameLength - 4;
342 iRichText->ApplyCharFormatL(charFormat, charFormatMask, dash, descriptionLength);
343 charFormatMask.ClearAll();
345 paraFormatMask.ClearAll();
354 * The test meassures how long it takes to format and draw the text view.
355 * Most time is spend with formatting the text.
357 void CComplexFontsControl::Draw(const TRect& aRect) const
359 TRAPD(err,iTextView->FormatTextL());
362 TRAP(err,iTextView->DrawL(aRect));
367 * Draws the text control if a pointer down event is received.
369 void CComplexFontsControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
371 if (aPointerEvent.iType == TPointerEvent::EButton1Down)