lafagnosticuifoundation/cone/tef/TConeTextDrawer.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent - Internal Symbian test code 
       
    19 */
       
    20 
       
    21 #include "TCone7Step.h"
       
    22 
       
    23 
       
    24 /**
       
    25 This test will draw a multi-line TBidiText clockwise one and a half laps from top left
       
    26 to top right (via bottom right to bottom left), in 9 steps.
       
    27 It draws a rectangle around clipping area (if any)  
       
    28 */
       
    29 TBool CCtlTestTextDrawer::TestTextDrawer(TInt aTextIndex, TBool aHorizontal, TRect *aClipRect, TRgb* aTextCol, TBool aCleanBackground, TBool aUp)
       
    30 	{	
       
    31 	ActivateGc();
       
    32 	CWindowGc& gc = SystemGc();
       
    33 	TRect rect = Rect();
       
    34 	if(aCleanBackground)
       
    35 		{
       
    36 		gc.Clear(rect);
       
    37 		}
       
    38 	TRgb textColor = aTextCol ? *aTextCol : KRgbBlack;
       
    39 	
       
    40 	CCoePlainTextDrawer* plainTextDrawer = CCoePlainTextDrawer::New(textColor);
       
    41 	XCoeTextDrawer textDrawer(*plainTextDrawer);
       
    42 	textDrawer.SetClipRect(aClipRect ? *aClipRect : rect);
       
    43 
       
    44 	if(aClipRect)
       
    45 		{
       
    46 		gc.SetPenColor(KRgbRed);
       
    47 		gc.DrawRect(*aClipRect);
       
    48 		gc.SetPenColor(textColor);
       
    49 		}
       
    50 		
       
    51 	TMargins8 margin;
       
    52 	margin.iLeft = 10;
       
    53 	margin.iRight = 20;
       
    54 	margin.iTop = 30;
       
    55 	margin.iBottom = 50;
       
    56 
       
    57 	textDrawer.SetMargins(margin);
       
    58 	TSize deltaMargin = margin.SizeDelta();
       
    59 
       
    60 	if(deltaMargin != TSize(0, 0)) 
       
    61 		{
       
    62 		TRect marginRect;
       
    63 		if(aHorizontal)
       
    64 			{
       
    65 			marginRect = margin.InnerRect(rect);
       
    66 			}
       
    67 		else
       
    68 			{//adjust matgins border to rotated text
       
    69 			marginRect = rect;
       
    70 			if(aUp)
       
    71 				{
       
    72 				marginRect.iTl.iX += margin.iTop;
       
    73 				marginRect.iTl.iY += margin.iRight;
       
    74 				marginRect.iBr.iX -= margin.iBottom;
       
    75 				marginRect.iBr.iY -= margin.iLeft;
       
    76 				}
       
    77 			else
       
    78 				{
       
    79 				marginRect.iTl.iX += margin.iBottom;
       
    80 				marginRect.iTl.iY += margin.iLeft;
       
    81 				marginRect.iBr.iX -= margin.iTop;
       
    82 				marginRect.iBr.iY -= margin.iRight;
       
    83 				}
       
    84 			}
       
    85 		gc.DrawRect(marginRect);
       
    86 		}
       
    87 	
       
    88 	TGulAlignment textAlign;
       
    89 	switch(aTextIndex)
       
    90 		{
       
    91 		// Test left, center, and right alignment with no application language set.
       
    92 		// This should result in left, center, and right alignment, as the script is LeftToRight (English).
       
    93 	case 0:
       
    94 		textAlign = TGulAlignment(EHLeftVTop);
       
    95 		break;
       
    96 	case 1:
       
    97 		textAlign = TGulAlignment(EHCenterVTop);
       
    98 		break;
       
    99 	case 2:
       
   100 		textAlign = TGulAlignment(EHRightVTop);
       
   101 		break;
       
   102 		
       
   103 		// Test left, center, and right MIRRORED alignment with Hebrew (RightToLeft) application language set.
       
   104 		// This shall result in the text being aligned right, center, and left, rather than the other way around
       
   105 	case 3:
       
   106 		textAlign = TGulAlignment(EHLeftVBottom);
       
   107 		plainTextDrawer->SetAppLanguage(ELangHebrew);
       
   108 		break;
       
   109 	case 4:
       
   110 		textAlign = TGulAlignment(EHCenterVBottom);
       
   111 		plainTextDrawer->SetAppLanguage(ELangHebrew);
       
   112 		break;
       
   113 	case 5:
       
   114 		textAlign = TGulAlignment(EHRightVBottom);
       
   115 		plainTextDrawer->SetAppLanguage(ELangHebrew);
       
   116 		break;
       
   117 		
       
   118 		// Test ABSOLUTE left, center, and right alignment with Hebrew (RightToLeft) application language set.
       
   119 		// This shall result in NO mirroring, i.e. text being displayed left, center, right.
       
   120 	case 6:
       
   121 		textAlign = TGulAlignment(EHLeftVTop);
       
   122 		textAlign.SetAbsoluteHAlignment(ETrue);
       
   123 		plainTextDrawer->SetAppLanguage(ELangHebrew);
       
   124 		break;
       
   125 	case 7:
       
   126 		textAlign = TGulAlignment(EHCenterVTop);
       
   127 		textAlign.SetAbsoluteHAlignment(ETrue);
       
   128 		plainTextDrawer->SetAppLanguage(ELangHebrew);
       
   129 		break;
       
   130 	case 8:
       
   131 		textAlign = TGulAlignment(EHRightVTop);
       
   132 		textAlign.SetAbsoluteHAlignment(ETrue);
       
   133 		plainTextDrawer->SetAppLanguage(ELangHebrew);
       
   134 		break;
       
   135 	default:
       
   136 		ASSERT(0);	
       
   137 		};
       
   138 
       
   139 
       
   140 	textDrawer->SetAlignment(textAlign);
       
   141 	
       
   142 	TBidiText* bidiText = TBidiText::NewL(KMultipleLineText(), 4);
       
   143 	bidiText->WrapText(rect.Width(), *iFont);
       
   144 	aHorizontal ?
       
   145 			textDrawer.DrawText(gc, *bidiText, rect, *iFont) :
       
   146 			textDrawer.DrawTextVertical(gc, *bidiText, rect, *iFont, aUp);
       
   147 	
       
   148 	delete bidiText;
       
   149 	
       
   150 	DeactivateGc();
       
   151 	iCoeEnv->Flush();
       
   152 	
       
   153 	return (textColor == textDrawer->TextColor());
       
   154 	}
       
   155 
       
   156 void CCtlTestTextDrawer::WidthOfText(TInt aLine, TInt& aWidthInPixels) const
       
   157 	{
       
   158 	TPtrC textInGivenLine(TCoeTextTypeAdaptor(KMultipleLineText).LineOfText(aLine, aWidthInPixels, *iFont));
       
   159 	}
       
   160 
       
   161 CCtlTestTextDrawer::CCtlTestTextDrawer()
       
   162 	{
       
   163 	}
       
   164 
       
   165 const CFont& CCtlTestTextDrawer::FontUsed() const
       
   166 	{
       
   167 	return *iFont;
       
   168 	}
       
   169 	
       
   170 CCtlTestTextDrawer::~CCtlTestTextDrawer()
       
   171 	{
       
   172 	iCoeEnv->ReleaseScreenFont(iFont);
       
   173 	}
       
   174 
       
   175 void CCtlTestTextDrawer::ConstructL()
       
   176 	{
       
   177 	TFontSpec fs;
       
   178 	_LIT(KTextFont,"DejaVu Sans Mono");
       
   179 	fs.iTypeface.iName = KTextFont;
       
   180 	fs.iHeight = 150;
       
   181 	iFont = iCoeEnv->CreateScreenFontL(fs);
       
   182 	CreateWindowL();
       
   183 	Window().SetBackgroundColor(KRgbCyan);
       
   184 	}
       
   185