os/graphics/windowing/windowserver/test/tman/TTEXT.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1995-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
// Print some text, to be checked by eye
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include <e32svr.h>
sl@0
    20
#include "W32STD.H"
sl@0
    21
#include "../tlib/testbase.h"
sl@0
    22
#include "TMAN.H"
sl@0
    23
sl@0
    24
class TTextTest;
sl@0
    25
sl@0
    26
enum {EDrawModeFonts,EDrawModeCharJust,EDrawModeWordJust};
sl@0
    27
sl@0
    28
_LIT(KTestFontTypefaceName,"DejaVu Sans Condensed");
sl@0
    29
sl@0
    30
class CTextWindow : public CTWin
sl@0
    31
	{
sl@0
    32
public:
sl@0
    33
	CTextWindow(TTextTest *aTest);
sl@0
    34
	void SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc);
sl@0
    35
	void Draw();
sl@0
    36
	void WinKeyL(const TKeyEvent &aKey,const TTime &aTime);
sl@0
    37
	void ResetPrintLine();
sl@0
    38
	void Print(const CFont *aFont, const TDesC &aText);
sl@0
    39
	void PrintLine(const CFont *aFont, const TDesC &aText);
sl@0
    40
	void PrintDivider();
sl@0
    41
	void PrintStylesL(const TDesC &aText, TFontSpec &aFontSpec, const TFontStyle &aFontStyle);
sl@0
    42
	void DrawCharJustified(const TDesC &aText);
sl@0
    43
	void DrawWordJustified(const TDesC &aText);
sl@0
    44
	TBool NextPage();
sl@0
    45
	void SetDrawMode(TInt aMode);
sl@0
    46
private:
sl@0
    47
	TInt iDrawMode;
sl@0
    48
	TTextTest *iTest;
sl@0
    49
	CFbsFont *iTmpFont;
sl@0
    50
	TInt iNumTypeFaces;
sl@0
    51
	TInt iTypeFaceIndex;
sl@0
    52
	TInt iXStartPos;
sl@0
    53
	TInt iYpos;
sl@0
    54
	TInt iXpos;
sl@0
    55
	};
sl@0
    56
sl@0
    57
class TTextTest : public CTestBase
sl@0
    58
	{
sl@0
    59
public:
sl@0
    60
	TTextTest();
sl@0
    61
	~TTextTest();
sl@0
    62
	TestState DoTestL();
sl@0
    63
	void ConstructL();
sl@0
    64
private:
sl@0
    65
	CTextWindow *iWin;
sl@0
    66
	TSize iWinSize;
sl@0
    67
	TInt iState;
sl@0
    68
	};
sl@0
    69
sl@0
    70
GLDEF_C CTestBase *CreateTextTest()
sl@0
    71
	{
sl@0
    72
	return(new(ELeave) TTextTest());
sl@0
    73
	}
sl@0
    74
sl@0
    75
CTextWindow::CTextWindow(TTextTest *aTest) : CTWin(), iDrawMode(EDrawModeWordJust), iTest(aTest)
sl@0
    76
	{}
sl@0
    77
sl@0
    78
void CTextWindow::SetUpLD(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
sl@0
    79
	{
sl@0
    80
	ConstructExtLD(*parent,pos,size);
sl@0
    81
	Activate();
sl@0
    82
	AssignGC(aGc);
sl@0
    83
	iNumTypeFaces=Client()->iScreen->NumTypefaces();
sl@0
    84
	}
sl@0
    85
sl@0
    86
void CTextWindow::ResetPrintLine()
sl@0
    87
	{
sl@0
    88
	iXpos=iXStartPos=5;
sl@0
    89
	iYpos=2;
sl@0
    90
	}
sl@0
    91
sl@0
    92
void CTextWindow::PrintDivider()
sl@0
    93
	{
sl@0
    94
	iGc->DrawLine(TPoint(0,iYpos+5),TPoint(Size().iWidth,iYpos+5));
sl@0
    95
	iYpos+=10;
sl@0
    96
	}
sl@0
    97
sl@0
    98
void CTextWindow::Print(const CFont *aFont, const TDesC &aText)
sl@0
    99
	{
sl@0
   100
	iGc->DrawText(aText, TPoint(iXpos, iYpos+aFont->AscentInPixels()));
sl@0
   101
	iXpos+=aFont->TextWidthInPixels(aText);
sl@0
   102
	}
sl@0
   103
sl@0
   104
void CTextWindow::PrintLine(const CFont *aFont, const TDesC &aText)
sl@0
   105
	{
sl@0
   106
	iGc->DrawText(aText, TPoint(iXpos, iYpos+aFont->AscentInPixels()));
sl@0
   107
	iXpos=iXStartPos;
sl@0
   108
	iYpos+=aFont->HeightInPixels()+2;
sl@0
   109
	}
sl@0
   110
sl@0
   111
TBool CTextWindow::NextPage()
sl@0
   112
	{
sl@0
   113
	if (iTypeFaceIndex==(iNumTypeFaces-1))
sl@0
   114
		return(ETrue);
sl@0
   115
	++iTypeFaceIndex;
sl@0
   116
	return(EFalse);
sl@0
   117
	}
sl@0
   118
sl@0
   119
void CTextWindow::PrintStylesL(const TDesC &aText, TFontSpec &aFontSpec, const TFontStyle &aFontStyle)
sl@0
   120
	{
sl@0
   121
	aFontSpec.iFontStyle=aFontStyle;
sl@0
   122
	User::LeaveIfError(Client()->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iTmpFont, aFontSpec));
sl@0
   123
	iGc->UseFont(iTmpFont);
sl@0
   124
	Print(iTmpFont,aText);
sl@0
   125
	iGc->SetUnderlineStyle(EUnderlineOn);
sl@0
   126
	Print(iTmpFont,_L("Underline, "));
sl@0
   127
	iGc->SetStrikethroughStyle(EStrikethroughOn);
sl@0
   128
	Print(iTmpFont,_L("Strikethrough/underline, "));
sl@0
   129
	iGc->SetUnderlineStyle(EUnderlineOff);
sl@0
   130
	PrintLine(iTmpFont,_L("Strikethrough"));
sl@0
   131
	iGc->SetStrikethroughStyle(EStrikethroughOff);
sl@0
   132
	Client()->iScreen->ReleaseFont(iTmpFont);
sl@0
   133
	iTmpFont=NULL;
sl@0
   134
	}
sl@0
   135
sl@0
   136
void CTextWindow::DrawCharJustified(const TDesC &aText)
sl@0
   137
	{
sl@0
   138
	iGc->SetCharJustification(Size().iWidth-10-iTmpFont->TextWidthInPixels(aText),aText.Length()-1);
sl@0
   139
	PrintLine(iTmpFont, aText);
sl@0
   140
	}
sl@0
   141
sl@0
   142
void CTextWindow::DrawWordJustified(const TDesC &aText)
sl@0
   143
	{
sl@0
   144
	TInt count=0;
sl@0
   145
	for(TInt index=0;index<aText.Length();index++)
sl@0
   146
		if (aText[index]==' ')
sl@0
   147
			count++;
sl@0
   148
	iGc->SetWordJustification(Size().iWidth-10-iTmpFont->TextWidthInPixels(aText),count);
sl@0
   149
	PrintLine(iTmpFont, aText);
sl@0
   150
	}
sl@0
   151
sl@0
   152
void CTextWindow::Draw()
sl@0
   153
//This function is virtual and so cannot have an 'L' at the end of it's name
sl@0
   154
	{
sl@0
   155
	iGc->Clear();
sl@0
   156
	ResetPrintLine();
sl@0
   157
	switch(iDrawMode)
sl@0
   158
		{
sl@0
   159
	case EDrawModeWordJust:
sl@0
   160
		User::LeaveIfError(Client()->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iTmpFont, TFontSpec(KTestFontTypefaceName,200)));
sl@0
   161
		iGc->UseFont(iTmpFont);
sl@0
   162
		DrawWordJustified(_L("Hello World"));
sl@0
   163
		DrawWordJustified(_L("One Two Three Four Five Six Seven"));
sl@0
   164
		DrawWordJustified(_L("AA    B        CC D"));
sl@0
   165
		DrawWordJustified(_L("ONEWORD"));
sl@0
   166
		iGc->DiscardFont();
sl@0
   167
		Client()->iScreen->ReleaseFont(iTmpFont);
sl@0
   168
		iTmpFont=NULL;
sl@0
   169
		break;
sl@0
   170
	case EDrawModeCharJust:
sl@0
   171
		User::LeaveIfError(Client()->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iTmpFont, TFontSpec(KTestFontTypefaceName,200)));
sl@0
   172
		iGc->UseFont(iTmpFont);
sl@0
   173
		DrawCharJustified(_L("Hello World"));
sl@0
   174
		DrawCharJustified(_L("One Two Three Four Five Six Seven"));
sl@0
   175
		DrawCharJustified(_L("AA    B        CC D"));
sl@0
   176
		DrawCharJustified(_L("ONEWORD"));
sl@0
   177
		iGc->DiscardFont();
sl@0
   178
		Client()->iScreen->ReleaseFont(iTmpFont);
sl@0
   179
		iTmpFont=NULL;
sl@0
   180
		break;
sl@0
   181
	case EDrawModeFonts:
sl@0
   182
		{
sl@0
   183
		TTypefaceSupport typefaceSupport;
sl@0
   184
		Client()->iScreen->TypefaceSupport(typefaceSupport,iTypeFaceIndex);
sl@0
   185
		TBuf<0x40> title;
sl@0
   186
		TBuf16<KMaxTypefaceNameLength> tmpBuf;
sl@0
   187
		tmpBuf.Copy(typefaceSupport.iTypeface.iName);
sl@0
   188
		title.Append(tmpBuf);
sl@0
   189
		title.AppendFormat(TRefByValue<const TDesC>(_L(", Heights (Min=%d, Max=%d, Num=%d)")),typefaceSupport.iMinHeightInTwips,typefaceSupport.iMaxHeightInTwips,typefaceSupport.iNumHeights);
sl@0
   190
		PrintLine(iFont,title);
sl@0
   191
		PrintDivider();
sl@0
   192
		for (TInt tfHeight=0;tfHeight<typefaceSupport.iNumHeights;tfHeight++)
sl@0
   193
			{
sl@0
   194
			TFontSpec fspec(typefaceSupport.iTypeface.iName,Client()->iScreen->FontHeightInTwips(iTypeFaceIndex,tfHeight));
sl@0
   195
			PrintStylesL(_L("Normal, "), fspec, TFontStyle());
sl@0
   196
			PrintStylesL(_L("Bold, "), fspec, TFontStyle(EPostureUpright,EStrokeWeightBold,EPrintPosNormal));
sl@0
   197
			PrintStylesL(_L("Italic, "), fspec, TFontStyle(EPostureItalic,EStrokeWeightNormal,EPrintPosNormal));
sl@0
   198
			PrintStylesL(_L("Bold/italic, "), fspec, TFontStyle(EPostureItalic,EStrokeWeightBold,EPrintPosNormal));
sl@0
   199
			if (iYpos>Size().iHeight)
sl@0
   200
				break;
sl@0
   201
			}
sl@0
   202
		}
sl@0
   203
		break;
sl@0
   204
		}
sl@0
   205
	}
sl@0
   206
sl@0
   207
void CTextWindow::WinKeyL(const TKeyEvent &aKey,const TTime &)
sl@0
   208
	{
sl@0
   209
	if (iDrawMode!=EDrawModeFonts || (aKey.iCode==EKeyEscape || NextPage()))
sl@0
   210
		CActiveScheduler::Stop();
sl@0
   211
	else
sl@0
   212
		iWin.Invalidate();
sl@0
   213
	}
sl@0
   214
sl@0
   215
void CTextWindow::SetDrawMode(TInt aDrawMode)
sl@0
   216
	{
sl@0
   217
	iDrawMode=aDrawMode;
sl@0
   218
	iWin.Invalidate();
sl@0
   219
	}
sl@0
   220
sl@0
   221
TTextTest::TTextTest() : CTestBase(_L("Text"))
sl@0
   222
	{}
sl@0
   223
sl@0
   224
TTextTest::~TTextTest()
sl@0
   225
	{
sl@0
   226
	CTWin::Delete(iWin);
sl@0
   227
	}
sl@0
   228
sl@0
   229
void TTextTest::ConstructL()
sl@0
   230
	{
sl@0
   231
	CTextWindow *win=new(ELeave) CTextWindow(this);
sl@0
   232
	win->SetUpLD(TPoint(0,0),Client()->iScreen->SizeInPixels(),Client()->iGroup,*Client()->iGc);
sl@0
   233
	iWin=win;
sl@0
   234
	Client()->iGroup->SetCurrentWindow(iWin);
sl@0
   235
	Client()->iGroup->GroupWin()->SetOrdinalPosition(0);
sl@0
   236
	}
sl@0
   237
sl@0
   238
TestState TTextTest::DoTestL()
sl@0
   239
	{
sl@0
   240
	switch(iState)
sl@0
   241
		{
sl@0
   242
		case 0:
sl@0
   243
			LogSubTest(_L("SetWordJustification"),1);
sl@0
   244
			iWin->SetDrawMode(EDrawModeWordJust);
sl@0
   245
 			CActiveScheduler::Start();
sl@0
   246
			iState++;
sl@0
   247
			break;
sl@0
   248
		case 1:
sl@0
   249
			LogSubTest(_L("SetCharJustification"),2);
sl@0
   250
			iWin->SetDrawMode(EDrawModeCharJust);
sl@0
   251
			CActiveScheduler::Start();
sl@0
   252
			iState++;
sl@0
   253
			break;
sl@0
   254
		case 2:
sl@0
   255
			LogSubTest(_L("Text 1"),3);
sl@0
   256
			iWin->SetDrawMode(EDrawModeFonts);
sl@0
   257
			CActiveScheduler::Start();
sl@0
   258
			iState++;
sl@0
   259
			break;
sl@0
   260
		default:
sl@0
   261
			return(EFinished);
sl@0
   262
		}
sl@0
   263
	return(ENext);
sl@0
   264
	}
sl@0
   265