1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicstest/uibench/s60/src/tests_fonts/tcomplexfonts.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,378 @@
1.4 + // Copyright (c) 2006-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 + //
1.18 +
1.19 +/**
1.20 + @file
1.21 + @test
1.22 + @internalComponent - Internal Symbian test code
1.23 +*/
1.24 +
1.25 +
1.26 +#include "tcomplexfonts.h"
1.27 +#include "fontdefs.h"
1.28 +#include "twindow.h"
1.29 +
1.30 +#include <w32std.h>
1.31 +#include <coefontprovider.h>
1.32 +
1.33 +
1.34 +_LIT(KTestStep0010, "GRAPHICS-UI-BENCH-S60-0010");
1.35 +
1.36 +_LIT(KSemaphore, "SemDrawSync"); // Name of the global semaphore
1.37 +
1.38 +
1.39 +// constants to define the format of the text
1.40 +const TInt KHeadingParagraph = 0;
1.41 +const TInt KClassParagraph = 2;
1.42 +const TInt KDescriptionHeading = 4;
1.43 +const TInt KDerivationHeading = 10;
1.44 +const TInt KFirstDerivation = 12;
1.45 +const TInt KLastDerivation = 16;
1.46 +
1.47 +const TInt KHeaderFontSize = 13 * 20; // in TWIPs
1.48 +const TInt KBodyFontSize = 8 * 20; // in TWIPs
1.49 +const TInt KBodyLineSpacing = 10; // in TWIPs
1.50 +const TInt KBodyIndent = 300; // in TWIPs
1.51 +
1.52 +const TInt KIterationsToTest = 50; // number of iterations
1.53 +
1.54 +
1.55 +CTComplexFonts::CTComplexFonts()
1.56 + {
1.57 + SetTestStepName(KTComplexFonts);
1.58 + }
1.59 +
1.60 +void CTComplexFonts::InitUIL(CCoeEnv* aCoeEnv)
1.61 + {
1.62 + CComplexFontsAppUi* appUi = new(ELeave) CComplexFontsAppUi();
1.63 + CleanupStack::PushL(appUi);
1.64 + appUi->ConstructL();
1.65 + aCoeEnv->SetAppUi(appUi);
1.66 + CleanupStack::Pop(appUi);
1.67 + }
1.68 +
1.69 +TVerdict CTComplexFonts::doTestStepPreambleL()
1.70 + {
1.71 + // The semaphore has to be created before, otherwise the control can't open it.
1.72 + TESTNOERRORL(iSemaphore.CreateGlobal(KSemaphore, 0));
1.73 + return CTe_ConeStepBase::doTestStepPreambleL();
1.74 + }
1.75 +
1.76 +TVerdict CTComplexFonts::doTestStepPostambleL()
1.77 + {
1.78 + GenerateEventL(TRawEvent::EButton1Up);
1.79 + iSemaphore.Close();
1.80 + return CTe_ConeStepBase::doTestStepPostambleL();
1.81 + }
1.82 +
1.83 +/**
1.84 + Override of base class pure virtual
1.85 + Our implementation only gets called if the base class doTestStepPreambleL() did
1.86 + not leave.
1.87 +
1.88 + @return - TVerdict code
1.89 +*/
1.90 +TVerdict CTComplexFonts::doTestStepL()
1.91 + {
1.92 + SetTestStepName(KTestStep0010);
1.93 + TRAPD(err, DrawComplexFontsL());
1.94 + if (err != KErrNone)
1.95 + {
1.96 + SetTestStepResult(EAbort);
1.97 + }
1.98 + return TestStepResult();
1.99 + }
1.100 +
1.101 +/**
1.102 +@SYMTestCaseID
1.103 +GRAPHICS-UI-BENCH-S60-0010
1.104 +
1.105 +@SYMTestCaseDesc
1.106 +Tests how long it takes format and draw a CRichText object.
1.107 +
1.108 +@SYMTestActions
1.109 +Create a complex font control. Format and draw the text control each time
1.110 +it receives a left pointer down event. The test step and the drawing of the
1.111 +control is synchronized with a Semaphore.
1.112 +
1.113 +@SYMTestExpectedResults
1.114 +Test should pass and display the average framerate for the test.
1.115 +*/
1.116 +void CTComplexFonts::DrawComplexFontsL()
1.117 + {
1.118 + iProfiler->InitResults();
1.119 + for(TInt i = KIterationsToTest; i > 0; --i)
1.120 + {
1.121 + GenerateEventL(TRawEvent::EButton1Down);
1.122 + iSemaphore.Wait();
1.123 + }
1.124 + iProfiler->MarkResultSetL();
1.125 + TSize screenSize = CTWindow::GetDisplaySizeInPixels();
1.126 + iProfiler->ResultsAnalysisFrameRate(KTestStep0010, 0, 0, 0, KIterationsToTest, screenSize.iWidth * screenSize.iHeight);
1.127 + }
1.128 +
1.129 +/**
1.130 + * Generates events to communicate with the control. Each time the control receives an event
1.131 + * it redraws itself. That's necessary because the draw method can't be called directly from
1.132 + * a different thread.
1.133 + */
1.134 +void CTComplexFonts::GenerateEventL(TRawEvent::TType aEventType)
1.135 + {
1.136 + TRawEvent rawEvent;
1.137 + rawEvent.Set(aEventType, 0, 0);
1.138 + User::LeaveIfError(UserSvr::AddEvent(rawEvent));
1.139 + }
1.140 +
1.141 +
1.142 +CComplexFontsAppUi::CComplexFontsAppUi()
1.143 + {
1.144 + // Empty
1.145 + }
1.146 +
1.147 +void CComplexFontsAppUi::ConstructL()
1.148 + {
1.149 + BaseConstructL(ENoAppResourceFile);
1.150 + iComplexFontsControl = CComplexFontsControl::NewL();
1.151 + AddToStackL(iComplexFontsControl);
1.152 + }
1.153 +
1.154 +CComplexFontsAppUi::~CComplexFontsAppUi()
1.155 + {
1.156 + RemoveFromStack(iComplexFontsControl);
1.157 + delete iComplexFontsControl;
1.158 + }
1.159 +
1.160 +
1.161 +CComplexFontsControl* CComplexFontsControl::NewLC(const CCoeControl* aParent)
1.162 + {
1.163 + CComplexFontsControl* self;
1.164 + self = new(ELeave) CComplexFontsControl();
1.165 + CleanupStack::PushL(self);
1.166 + self->ConstructL(aParent);
1.167 + return self;
1.168 + }
1.169 +
1.170 +CComplexFontsControl* CComplexFontsControl::NewL(const CCoeControl* aParent)
1.171 + {
1.172 + CComplexFontsControl* self;
1.173 + self = CComplexFontsControl::NewLC(aParent);
1.174 + CleanupStack::Pop(self);
1.175 + return self;
1.176 + }
1.177 +
1.178 +CComplexFontsControl::CComplexFontsControl() : iWsSession(CCoeEnv::Static()->WsSession())
1.179 + {
1.180 + // empty
1.181 + }
1.182 +
1.183 +CComplexFontsControl::~CComplexFontsControl()
1.184 + {
1.185 + delete iTextView;
1.186 + delete iLayout;
1.187 + delete iRichText;
1.188 + delete iCharFormatLayer;
1.189 + delete iParaFormatLayer;
1.190 + delete iScreen;
1.191 + iSemaphore.Close();
1.192 + }
1.193 +
1.194 +/**
1.195 + * Constructs the text control with the complex fonts.
1.196 + */
1.197 +void CComplexFontsControl::ConstructL(const CCoeControl* aParent)
1.198 + {
1.199 + User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore));
1.200 + if (aParent)
1.201 + {
1.202 + SetContainerWindowL(*aParent);
1.203 + }
1.204 + else
1.205 + {
1.206 + CreateWindowL();
1.207 + }
1.208 + // Create text object, text view and layout.
1.209 + iParaFormatLayer = CParaFormatLayer::NewL();
1.210 + iCharFormatLayer = CCharFormatLayer::NewL();
1.211 + // Create an empty rich text object
1.212 + iRichText = CRichText::NewL(iParaFormatLayer, iCharFormatLayer);
1.213 +
1.214 + iScreen = new(ELeave) CWsScreenDevice(ControlEnv()->WsSession());
1.215 + User::LeaveIfError(iScreen->Construct()); // default screen used
1.216 +
1.217 + TPixelsAndRotation pixelsAndRotation;
1.218 + iScreen->GetDefaultScreenSizeAndRotation(pixelsAndRotation);
1.219 +
1.220 + // Create the text layout, (required by text view),
1.221 + // with the text object and a wrap width (=width of view rect)
1.222 + iLayout = CTextLayout::NewL(iRichText,pixelsAndRotation.iPixelSize.iWidth);
1.223 +
1.224 + // Create text view
1.225 + iTextView = CTextView::NewL(iLayout, pixelsAndRotation.iPixelSize,
1.226 + iScreen, iScreen, &Window(), 0, // no window group
1.227 + &iCoeEnv->WsSession()); // new view
1.228 +
1.229 + SetRect(TRect(TPoint(0, 0), pixelsAndRotation.iPixelSize));
1.230 +
1.231 + // load up text
1.232 + iRichText->InsertL(0, KComplexFontsText);
1.233 +
1.234 + // break up into paragraphs for CRichText by replacing \n characters in original text
1.235 + // with CEditableText::EParagraphDelimiter
1.236 + TPtrC complexFontsTextPtr(KComplexFontsText);
1.237 + TInt eos = complexFontsTextPtr.Length();
1.238 + for (TInt paragraphBreakLocation = 0; paragraphBreakLocation < eos; paragraphBreakLocation++)
1.239 + {
1.240 + if (complexFontsTextPtr[paragraphBreakLocation] == '\n')
1.241 + {
1.242 + iRichText->DeleteL(paragraphBreakLocation, 1);
1.243 + iRichText->InsertL(paragraphBreakLocation, CEditableText::EParagraphDelimiter);
1.244 + }
1.245 + }
1.246 +
1.247 + TCharFormat charFormat;
1.248 + TCharFormatMask charFormatMask;
1.249 + // format the first paragraph "Class RWindow" as orange and a bit bigger than the body
1.250 + charFormat.iFontPresentation.iTextColor= TLogicalRgb(TRgb(0x0099ff));
1.251 + charFormatMask.SetAttrib(EAttColor);
1.252 + charFormat.iFontSpec.iHeight = KHeaderFontSize;
1.253 + charFormatMask.SetAttrib(EAttFontHeight);
1.254 +
1.255 + TInt headerLength = 0;
1.256 + TInt headerStart = iRichText->CharPosOfParagraph(headerLength, KHeadingParagraph);
1.257 + iRichText->ApplyCharFormatL(charFormat, charFormatMask, headerStart, headerLength);
1.258 + charFormatMask.ClearAll();
1.259 +
1.260 + // format "Class" as Sans Serif
1.261 + charFormat.iFontSpec.iTypeface.iName = KNokiaSeries60Font;
1.262 + charFormatMask.SetAttrib(EAttFontTypeface);
1.263 + iRichText->ApplyCharFormatL(charFormat, charFormatMask, headerStart, 5);
1.264 + charFormatMask.ClearAll();
1.265 +
1.266 + // make the rest of the text smaller
1.267 + charFormat.iFontSpec.iHeight = KBodyFontSize;
1.268 + charFormatMask.SetAttrib(EAttFontHeight);
1.269 + TInt textLength = iRichText->DocumentLength();
1.270 + iRichText->ApplyCharFormatL(charFormat, charFormatMask, headerLength, textLength - headerLength);
1.271 + charFormatMask.ClearAll();
1.272 +
1.273 + TParaFormatMask paraFormatMask;
1.274 + // crunch main body a bit closer together to show more on the little screen
1.275 + // and indent left margin
1.276 + iParaFormat.iLineSpacingInTwips = KBodyLineSpacing;
1.277 + paraFormatMask.SetAttrib(EAttLineSpacing);
1.278 + iParaFormat.iLineSpacingControl = CParaFormat::ELineSpacingExactlyInPixels;
1.279 + paraFormatMask.SetAttrib(EAttLineSpacingControl);
1.280 + iParaFormat.iLeftMarginInTwips = KBodyIndent;
1.281 + paraFormatMask.SetAttrib(EAttLeftMargin);
1.282 + iRichText->ApplyParaFormatL(&iParaFormat, paraFormatMask, headerLength, textLength - headerLength);
1.283 + paraFormatMask.ClearAll();
1.284 +
1.285 + TInt length = 0;
1.286 + TInt start = 0;
1.287 +
1.288 + // put a grey background on "class RWindow : public RDrawableWindow;"
1.289 + start = iRichText->CharPosOfParagraph(length, KClassParagraph);
1.290 + iParaFormat.iFillColor = TLogicalRgb(TRgb(0xdddddd));
1.291 + paraFormatMask.SetAttrib(EAttFillColor);
1.292 + iRichText->ApplyParaFormatL(&iParaFormat, paraFormatMask, start, length);
1.293 + paraFormatMask.ClearAll();
1.294 +
1.295 + // make "Description" and "Derivation" subheadings bold
1.296 + charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
1.297 + charFormatMask.SetAttrib(EAttFontStrokeWeight);
1.298 + start = iRichText->CharPosOfParagraph(length, KDescriptionHeading);
1.299 + iRichText->ApplyCharFormatL(charFormat, charFormatMask, start, length);
1.300 + start = iRichText->CharPosOfParagraph(length, KDerivationHeading);
1.301 + iRichText->ApplyCharFormatL(charFormat, charFormatMask, start, length);
1.302 + charFormatMask.ClearAll();
1.303 +
1.304 + // all the paragraphs between and including "Description" and "Derivation" are in sans serif
1.305 + // (the default CRichText font is serif)
1.306 + TInt paragraphNumber = 0;
1.307 +
1.308 + charFormat.iFontSpec.iTypeface.iName = KNokiaSeries60Font;
1.309 + charFormatMask.SetAttrib(EAttFontTypeface);
1.310 + for (paragraphNumber = KDescriptionHeading; paragraphNumber <= KDerivationHeading; paragraphNumber++)
1.311 + {
1.312 + start = iRichText->CharPosOfParagraph(length, paragraphNumber);
1.313 + iRichText->ApplyCharFormatL(charFormat, charFormatMask, start, length);
1.314 + }
1.315 + charFormatMask.ClearAll();
1.316 +
1.317 + // for each line in the "Derivation" section
1.318 + // progressively indent left margin
1.319 + // make class name blue underlined (it starts two characters after the
1.320 + // beginning of each paragraph and goes to the space before the '-')
1.321 + // make descriptive text sans serif (from the '-' to the end of the paragraph)
1.322 + paraFormatMask.SetAttrib(EAttLeftMargin);
1.323 + charFormat.iFontPresentation.iTextColor= TLogicalRgb(TRgb(0xA27316));
1.324 + charFormat.iFontPresentation.iUnderline = EUnderlineOn;
1.325 + for (paragraphNumber = KFirstDerivation; paragraphNumber <= KLastDerivation; paragraphNumber++)
1.326 + {
1.327 + iParaFormat.iLeftMarginInTwips = (paragraphNumber - KFirstDerivation + 2)*KBodyIndent;
1.328 + start = iRichText->CharPosOfParagraph(length, paragraphNumber);
1.329 + iRichText->ApplyParaFormatL(&iParaFormat, paraFormatMask, start, length);
1.330 + TInt dash = 0;
1.331 + for (dash = start; dash < start + length; dash++)
1.332 + {
1.333 + if (complexFontsTextPtr[dash] == '-')
1.334 + {
1.335 + break;
1.336 + }
1.337 + }
1.338 + charFormatMask.SetAttrib(EAttColor);
1.339 + charFormatMask.SetAttrib(EAttFontUnderline);
1.340 + TInt classNameLength = (dash - 1) - (start + 2);
1.341 + iRichText->ApplyCharFormatL(charFormat, charFormatMask, start + 2, classNameLength);
1.342 + charFormatMask.ClearAll();
1.343 + charFormatMask.SetAttrib(EAttFontTypeface);
1.344 + TInt descriptionLength = length - classNameLength - 4;
1.345 + iRichText->ApplyCharFormatL(charFormat, charFormatMask, dash, descriptionLength);
1.346 + charFormatMask.ClearAll();
1.347 + }
1.348 + paraFormatMask.ClearAll();
1.349 +
1.350 + if (!aParent)
1.351 + {
1.352 + ActivateL();
1.353 + }
1.354 + }
1.355 +
1.356 +/**
1.357 + * The test meassures how long it takes to format and draw the text view.
1.358 + * Most time is spend with formatting the text.
1.359 + */
1.360 +void CComplexFontsControl::Draw(const TRect& aRect) const
1.361 + {
1.362 + TRAPD(err,iTextView->FormatTextL());
1.363 + if (err == KErrNone)
1.364 + {
1.365 + TRAP(err,iTextView->DrawL(aRect));
1.366 + }
1.367 + }
1.368 +
1.369 +/**
1.370 + * Draws the text control if a pointer down event is received.
1.371 + */
1.372 +void CComplexFontsControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
1.373 + {
1.374 + if (aPointerEvent.iType == TPointerEvent::EButton1Down)
1.375 + {
1.376 + DrawNow();
1.377 + iWsSession.Flush();
1.378 + iWsSession.Finish();
1.379 + iSemaphore.Signal();
1.380 + }
1.381 + }