os/graphics/graphicstest/uibench/s60/src/tests_fonts/tcomplexfonts.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
 // All rights reserved.
sl@0
     3
 // This component and the accompanying materials are made available
sl@0
     4
 // under the terms of "Eclipse Public License v1.0"
sl@0
     5
 // which accompanies this distribution, and is available
sl@0
     6
 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
 //
sl@0
     8
 // Initial Contributors:
sl@0
     9
 // Nokia Corporation - initial contribution.
sl@0
    10
 //
sl@0
    11
 // Contributors:
sl@0
    12
 //
sl@0
    13
 // Description:
sl@0
    14
 //
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
 @internalComponent - Internal Symbian test code 
sl@0
    20
*/
sl@0
    21
sl@0
    22
sl@0
    23
#include "tcomplexfonts.h"
sl@0
    24
#include "fontdefs.h"
sl@0
    25
#include "twindow.h"
sl@0
    26
sl@0
    27
#include <w32std.h>
sl@0
    28
#include <coefontprovider.h>
sl@0
    29
sl@0
    30
sl@0
    31
_LIT(KTestStep0010, "GRAPHICS-UI-BENCH-S60-0010");
sl@0
    32
sl@0
    33
_LIT(KSemaphore, "SemDrawSync"); // Name of the global semaphore
sl@0
    34
sl@0
    35
sl@0
    36
// constants to define the format of the text
sl@0
    37
const TInt KHeadingParagraph = 0;
sl@0
    38
const TInt KClassParagraph = 2;
sl@0
    39
const TInt KDescriptionHeading = 4;
sl@0
    40
const TInt KDerivationHeading = 10;
sl@0
    41
const TInt KFirstDerivation = 12;
sl@0
    42
const TInt KLastDerivation = 16;
sl@0
    43
sl@0
    44
const TInt KHeaderFontSize = 13 * 20; // in TWIPs
sl@0
    45
const TInt KBodyFontSize = 8 * 20; // in TWIPs
sl@0
    46
const TInt KBodyLineSpacing = 10; // in TWIPs
sl@0
    47
const TInt KBodyIndent = 300; // in TWIPs
sl@0
    48
sl@0
    49
const TInt KIterationsToTest = 50; // number of iterations
sl@0
    50
sl@0
    51
sl@0
    52
CTComplexFonts::CTComplexFonts()
sl@0
    53
	{
sl@0
    54
	SetTestStepName(KTComplexFonts);
sl@0
    55
	}
sl@0
    56
sl@0
    57
void CTComplexFonts::InitUIL(CCoeEnv* aCoeEnv)
sl@0
    58
    {
sl@0
    59
    CComplexFontsAppUi* appUi = new(ELeave) CComplexFontsAppUi();
sl@0
    60
    CleanupStack::PushL(appUi);
sl@0
    61
    appUi->ConstructL();
sl@0
    62
    aCoeEnv->SetAppUi(appUi);
sl@0
    63
    CleanupStack::Pop(appUi);
sl@0
    64
    }
sl@0
    65
sl@0
    66
TVerdict CTComplexFonts::doTestStepPreambleL()
sl@0
    67
    {
sl@0
    68
    // The semaphore has to be created before, otherwise the control can't open it.
sl@0
    69
    TESTNOERRORL(iSemaphore.CreateGlobal(KSemaphore, 0));
sl@0
    70
    return CTe_ConeStepBase::doTestStepPreambleL();
sl@0
    71
    }
sl@0
    72
sl@0
    73
TVerdict CTComplexFonts::doTestStepPostambleL()
sl@0
    74
    {
sl@0
    75
    GenerateEventL(TRawEvent::EButton1Up);
sl@0
    76
    iSemaphore.Close();
sl@0
    77
    return CTe_ConeStepBase::doTestStepPostambleL(); 
sl@0
    78
    }
sl@0
    79
sl@0
    80
/**
sl@0
    81
    Override of base class pure virtual
sl@0
    82
    Our implementation only gets called if the base class doTestStepPreambleL() did
sl@0
    83
    not leave.
sl@0
    84
    
sl@0
    85
    @return - TVerdict code
sl@0
    86
*/
sl@0
    87
TVerdict CTComplexFonts::doTestStepL()
sl@0
    88
	{
sl@0
    89
	SetTestStepName(KTestStep0010);
sl@0
    90
	TRAPD(err, DrawComplexFontsL());
sl@0
    91
	if (err != KErrNone)
sl@0
    92
	    {
sl@0
    93
	    SetTestStepResult(EAbort);
sl@0
    94
	    }
sl@0
    95
	return TestStepResult();
sl@0
    96
	}
sl@0
    97
sl@0
    98
/**
sl@0
    99
@SYMTestCaseID
sl@0
   100
GRAPHICS-UI-BENCH-S60-0010
sl@0
   101
sl@0
   102
@SYMTestCaseDesc
sl@0
   103
Tests how long it takes format and draw a CRichText object.
sl@0
   104
sl@0
   105
@SYMTestActions
sl@0
   106
Create a complex font control. Format and draw the text control each time
sl@0
   107
it receives a left pointer down event. The test step and the drawing of the
sl@0
   108
control is synchronized with a Semaphore. 
sl@0
   109
sl@0
   110
@SYMTestExpectedResults
sl@0
   111
Test should pass and display the average framerate for the test.
sl@0
   112
*/
sl@0
   113
void CTComplexFonts::DrawComplexFontsL()
sl@0
   114
    {
sl@0
   115
    iProfiler->InitResults();
sl@0
   116
    for(TInt i = KIterationsToTest; i > 0; --i)
sl@0
   117
        {
sl@0
   118
        GenerateEventL(TRawEvent::EButton1Down);
sl@0
   119
        iSemaphore.Wait();
sl@0
   120
        }
sl@0
   121
    iProfiler->MarkResultSetL();
sl@0
   122
    TSize screenSize = CTWindow::GetDisplaySizeInPixels();
sl@0
   123
    iProfiler->ResultsAnalysisFrameRate(KTestStep0010, 0, 0, 0, KIterationsToTest, screenSize.iWidth * screenSize.iHeight);
sl@0
   124
    }
sl@0
   125
sl@0
   126
/**
sl@0
   127
 * Generates events to communicate with the control. Each time the control receives an event
sl@0
   128
 * it redraws itself. That's necessary because the draw method can't be called directly from
sl@0
   129
 * a different thread.
sl@0
   130
 */
sl@0
   131
void CTComplexFonts::GenerateEventL(TRawEvent::TType aEventType)
sl@0
   132
    {
sl@0
   133
    TRawEvent rawEvent;
sl@0
   134
    rawEvent.Set(aEventType, 0, 0);
sl@0
   135
    User::LeaveIfError(UserSvr::AddEvent(rawEvent));
sl@0
   136
    }
sl@0
   137
sl@0
   138
sl@0
   139
CComplexFontsAppUi::CComplexFontsAppUi()
sl@0
   140
    {
sl@0
   141
    // Empty
sl@0
   142
    }
sl@0
   143
sl@0
   144
void CComplexFontsAppUi::ConstructL()
sl@0
   145
    {
sl@0
   146
    BaseConstructL(ENoAppResourceFile);
sl@0
   147
    iComplexFontsControl = CComplexFontsControl::NewL();
sl@0
   148
    AddToStackL(iComplexFontsControl);
sl@0
   149
    }
sl@0
   150
sl@0
   151
CComplexFontsAppUi::~CComplexFontsAppUi()
sl@0
   152
    {
sl@0
   153
    RemoveFromStack(iComplexFontsControl);
sl@0
   154
    delete iComplexFontsControl;
sl@0
   155
    }
sl@0
   156
sl@0
   157
sl@0
   158
CComplexFontsControl* CComplexFontsControl::NewLC(const CCoeControl* aParent)
sl@0
   159
	{
sl@0
   160
	CComplexFontsControl* self;
sl@0
   161
	self = new(ELeave) CComplexFontsControl();
sl@0
   162
	CleanupStack::PushL(self);
sl@0
   163
	self->ConstructL(aParent);
sl@0
   164
	return self;
sl@0
   165
	}
sl@0
   166
sl@0
   167
CComplexFontsControl* CComplexFontsControl::NewL(const CCoeControl* aParent)
sl@0
   168
	{
sl@0
   169
	CComplexFontsControl* self;
sl@0
   170
	self = CComplexFontsControl::NewLC(aParent);
sl@0
   171
	CleanupStack::Pop(self);
sl@0
   172
	return self;
sl@0
   173
	}
sl@0
   174
sl@0
   175
CComplexFontsControl::CComplexFontsControl() : iWsSession(CCoeEnv::Static()->WsSession())
sl@0
   176
    {
sl@0
   177
    // empty
sl@0
   178
    }
sl@0
   179
sl@0
   180
CComplexFontsControl::~CComplexFontsControl()
sl@0
   181
	{
sl@0
   182
	delete iTextView;
sl@0
   183
	delete iLayout;
sl@0
   184
	delete iRichText;
sl@0
   185
	delete iCharFormatLayer;
sl@0
   186
	delete iParaFormatLayer;
sl@0
   187
	delete iScreen;
sl@0
   188
	iSemaphore.Close();
sl@0
   189
	}
sl@0
   190
sl@0
   191
/**
sl@0
   192
 * Constructs the text control with the complex fonts.
sl@0
   193
 */
sl@0
   194
void CComplexFontsControl::ConstructL(const CCoeControl* aParent)
sl@0
   195
    {
sl@0
   196
    User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore));
sl@0
   197
    if (aParent)
sl@0
   198
        {
sl@0
   199
        SetContainerWindowL(*aParent);
sl@0
   200
        }
sl@0
   201
    else
sl@0
   202
        {
sl@0
   203
        CreateWindowL();
sl@0
   204
        }
sl@0
   205
    // Create text object, text view and layout.
sl@0
   206
    iParaFormatLayer = CParaFormatLayer::NewL(); 
sl@0
   207
    iCharFormatLayer = CCharFormatLayer::NewL();
sl@0
   208
    // Create an empty rich text object
sl@0
   209
    iRichText = CRichText::NewL(iParaFormatLayer, iCharFormatLayer);
sl@0
   210
    
sl@0
   211
    iScreen = new(ELeave) CWsScreenDevice(ControlEnv()->WsSession());
sl@0
   212
    User::LeaveIfError(iScreen->Construct()); // default screen used
sl@0
   213
    
sl@0
   214
    TPixelsAndRotation pixelsAndRotation;
sl@0
   215
    iScreen->GetDefaultScreenSizeAndRotation(pixelsAndRotation);
sl@0
   216
    
sl@0
   217
    // Create the text layout, (required by text view),
sl@0
   218
    // with the text object and a wrap width (=width of view rect)
sl@0
   219
    iLayout = CTextLayout::NewL(iRichText,pixelsAndRotation.iPixelSize.iWidth);
sl@0
   220
    
sl@0
   221
    // Create text view
sl@0
   222
    iTextView = CTextView::NewL(iLayout, pixelsAndRotation.iPixelSize,
sl@0
   223
            iScreen, iScreen, &Window(), 0, // no window group
sl@0
   224
            &iCoeEnv->WsSession()); // new view
sl@0
   225
        
sl@0
   226
    SetRect(TRect(TPoint(0, 0), pixelsAndRotation.iPixelSize));
sl@0
   227
sl@0
   228
    // load up text
sl@0
   229
    iRichText->InsertL(0, KComplexFontsText);
sl@0
   230
sl@0
   231
    // break up into paragraphs for CRichText by replacing \n characters in original text
sl@0
   232
    // with CEditableText::EParagraphDelimiter
sl@0
   233
    TPtrC complexFontsTextPtr(KComplexFontsText);
sl@0
   234
    TInt eos = complexFontsTextPtr.Length();
sl@0
   235
    for (TInt paragraphBreakLocation = 0; paragraphBreakLocation < eos; paragraphBreakLocation++)
sl@0
   236
        {
sl@0
   237
        if (complexFontsTextPtr[paragraphBreakLocation] == '\n')
sl@0
   238
            {
sl@0
   239
            iRichText->DeleteL(paragraphBreakLocation, 1);
sl@0
   240
            iRichText->InsertL(paragraphBreakLocation, CEditableText::EParagraphDelimiter);
sl@0
   241
            }
sl@0
   242
        }
sl@0
   243
    
sl@0
   244
    TCharFormat charFormat;
sl@0
   245
    TCharFormatMask charFormatMask;
sl@0
   246
    // format the first paragraph "Class RWindow" as orange and a bit bigger than the body
sl@0
   247
    charFormat.iFontPresentation.iTextColor= TLogicalRgb(TRgb(0x0099ff));
sl@0
   248
    charFormatMask.SetAttrib(EAttColor);
sl@0
   249
    charFormat.iFontSpec.iHeight = KHeaderFontSize; 
sl@0
   250
    charFormatMask.SetAttrib(EAttFontHeight);
sl@0
   251
    
sl@0
   252
    TInt headerLength = 0;
sl@0
   253
    TInt headerStart = iRichText->CharPosOfParagraph(headerLength, KHeadingParagraph);
sl@0
   254
    iRichText->ApplyCharFormatL(charFormat, charFormatMask, headerStart, headerLength);
sl@0
   255
    charFormatMask.ClearAll();
sl@0
   256
sl@0
   257
    // format "Class" as Sans Serif
sl@0
   258
    charFormat.iFontSpec.iTypeface.iName = KNokiaSeries60Font;
sl@0
   259
    charFormatMask.SetAttrib(EAttFontTypeface);
sl@0
   260
    iRichText->ApplyCharFormatL(charFormat, charFormatMask, headerStart, 5);
sl@0
   261
    charFormatMask.ClearAll();
sl@0
   262
sl@0
   263
    // make the rest of the text smaller  
sl@0
   264
    charFormat.iFontSpec.iHeight = KBodyFontSize;
sl@0
   265
    charFormatMask.SetAttrib(EAttFontHeight);
sl@0
   266
    TInt textLength = iRichText->DocumentLength();
sl@0
   267
    iRichText->ApplyCharFormatL(charFormat, charFormatMask, headerLength, textLength - headerLength);
sl@0
   268
    charFormatMask.ClearAll();
sl@0
   269
sl@0
   270
    TParaFormatMask paraFormatMask;
sl@0
   271
    // crunch main body a bit closer together to show more on the little screen
sl@0
   272
    // and indent left margin 
sl@0
   273
    iParaFormat.iLineSpacingInTwips = KBodyLineSpacing;
sl@0
   274
    paraFormatMask.SetAttrib(EAttLineSpacing);
sl@0
   275
    iParaFormat.iLineSpacingControl = CParaFormat::ELineSpacingExactlyInPixels;
sl@0
   276
    paraFormatMask.SetAttrib(EAttLineSpacingControl);
sl@0
   277
    iParaFormat.iLeftMarginInTwips = KBodyIndent;
sl@0
   278
    paraFormatMask.SetAttrib(EAttLeftMargin);
sl@0
   279
    iRichText->ApplyParaFormatL(&iParaFormat, paraFormatMask, headerLength, textLength - headerLength);
sl@0
   280
    paraFormatMask.ClearAll();
sl@0
   281
sl@0
   282
    TInt length = 0;
sl@0
   283
    TInt start = 0;
sl@0
   284
    
sl@0
   285
    // put a grey background on "class RWindow : public RDrawableWindow;"
sl@0
   286
    start = iRichText->CharPosOfParagraph(length, KClassParagraph);
sl@0
   287
    iParaFormat.iFillColor = TLogicalRgb(TRgb(0xdddddd));
sl@0
   288
    paraFormatMask.SetAttrib(EAttFillColor);
sl@0
   289
    iRichText->ApplyParaFormatL(&iParaFormat, paraFormatMask, start, length);
sl@0
   290
    paraFormatMask.ClearAll();
sl@0
   291
    
sl@0
   292
    // make "Description" and "Derivation" subheadings bold
sl@0
   293
    charFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
sl@0
   294
    charFormatMask.SetAttrib(EAttFontStrokeWeight);
sl@0
   295
    start = iRichText->CharPosOfParagraph(length, KDescriptionHeading);
sl@0
   296
    iRichText->ApplyCharFormatL(charFormat, charFormatMask, start, length);
sl@0
   297
    start = iRichText->CharPosOfParagraph(length, KDerivationHeading);
sl@0
   298
    iRichText->ApplyCharFormatL(charFormat, charFormatMask, start, length);
sl@0
   299
    charFormatMask.ClearAll();
sl@0
   300
    
sl@0
   301
    // all the paragraphs between and including "Description" and "Derivation" are in sans serif 
sl@0
   302
    // (the default CRichText font is serif)
sl@0
   303
    TInt paragraphNumber = 0;
sl@0
   304
sl@0
   305
    charFormat.iFontSpec.iTypeface.iName = KNokiaSeries60Font;
sl@0
   306
    charFormatMask.SetAttrib(EAttFontTypeface);
sl@0
   307
    for (paragraphNumber = KDescriptionHeading; paragraphNumber <= KDerivationHeading; paragraphNumber++)
sl@0
   308
        {
sl@0
   309
        start = iRichText->CharPosOfParagraph(length, paragraphNumber);
sl@0
   310
        iRichText->ApplyCharFormatL(charFormat, charFormatMask, start, length);
sl@0
   311
        }
sl@0
   312
    charFormatMask.ClearAll();
sl@0
   313
    
sl@0
   314
    // for each line in the "Derivation" section
sl@0
   315
    //  progressively indent left margin
sl@0
   316
    //  make class name blue underlined (it starts two characters after the 
sl@0
   317
    //    beginning of each paragraph and goes to the space before the '-')
sl@0
   318
    //  make descriptive text sans serif (from the '-' to the end of the paragraph)
sl@0
   319
    paraFormatMask.SetAttrib(EAttLeftMargin);
sl@0
   320
    charFormat.iFontPresentation.iTextColor= TLogicalRgb(TRgb(0xA27316));
sl@0
   321
    charFormat.iFontPresentation.iUnderline = EUnderlineOn;
sl@0
   322
    for (paragraphNumber = KFirstDerivation; paragraphNumber <= KLastDerivation; paragraphNumber++)
sl@0
   323
        {
sl@0
   324
        iParaFormat.iLeftMarginInTwips = (paragraphNumber - KFirstDerivation + 2)*KBodyIndent;
sl@0
   325
        start = iRichText->CharPosOfParagraph(length, paragraphNumber);
sl@0
   326
        iRichText->ApplyParaFormatL(&iParaFormat, paraFormatMask, start, length);
sl@0
   327
        TInt dash = 0;
sl@0
   328
        for (dash = start; dash < start + length; dash++)
sl@0
   329
            {
sl@0
   330
            if (complexFontsTextPtr[dash] == '-')
sl@0
   331
                {
sl@0
   332
                break;
sl@0
   333
                }
sl@0
   334
            }
sl@0
   335
        charFormatMask.SetAttrib(EAttColor);
sl@0
   336
        charFormatMask.SetAttrib(EAttFontUnderline);
sl@0
   337
        TInt classNameLength = (dash - 1) - (start + 2);
sl@0
   338
        iRichText->ApplyCharFormatL(charFormat, charFormatMask, start + 2, classNameLength);
sl@0
   339
        charFormatMask.ClearAll();
sl@0
   340
        charFormatMask.SetAttrib(EAttFontTypeface);
sl@0
   341
        TInt descriptionLength = length - classNameLength - 4;
sl@0
   342
        iRichText->ApplyCharFormatL(charFormat, charFormatMask, dash, descriptionLength);
sl@0
   343
        charFormatMask.ClearAll();
sl@0
   344
        }
sl@0
   345
    paraFormatMask.ClearAll();
sl@0
   346
    
sl@0
   347
    if (!aParent)
sl@0
   348
        {
sl@0
   349
        ActivateL();
sl@0
   350
        }
sl@0
   351
    }
sl@0
   352
sl@0
   353
/**
sl@0
   354
 * The test meassures how long it takes to format and draw the text view.
sl@0
   355
 * Most time is spend with formatting the text.
sl@0
   356
 */
sl@0
   357
void CComplexFontsControl::Draw(const TRect& aRect) const
sl@0
   358
	{
sl@0
   359
	TRAPD(err,iTextView->FormatTextL());
sl@0
   360
	if (err == KErrNone)
sl@0
   361
	    {
sl@0
   362
	    TRAP(err,iTextView->DrawL(aRect));
sl@0
   363
	    }
sl@0
   364
	}
sl@0
   365
sl@0
   366
/**
sl@0
   367
 * Draws the text control if a pointer down event is received.
sl@0
   368
 */
sl@0
   369
void CComplexFontsControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
sl@0
   370
    {
sl@0
   371
    if (aPointerEvent.iType == TPointerEvent::EButton1Down)
sl@0
   372
        {
sl@0
   373
        DrawNow();
sl@0
   374
        iWsSession.Flush();
sl@0
   375
        iWsSession.Finish();
sl@0
   376
        iSemaphore.Signal();
sl@0
   377
        }
sl@0
   378
    }