|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * TestLayout.cpp test jig for CTmTextLayout |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "TestLayout.h" |
|
21 #include "TGraphicsContext.h" |
|
22 #include "TMINTERP.H" |
|
23 |
|
24 #include <txtrich.h> |
|
25 |
|
26 #include <e32test.h> |
|
27 /** |
|
28 Constructor. |
|
29 @param aRichText |
|
30 Text to be formatted. |
|
31 @param aDeviceMap |
|
32 Formatting and drawing device. |
|
33 @internalComponent |
|
34 */ |
|
35 CETextSource::CETextSource(const CRichText& aRichText, |
|
36 MGraphicsDeviceMap* aDeviceMap) |
|
37 : iRichText(&aRichText), iDeviceMap(aDeviceMap) |
|
38 { |
|
39 } |
|
40 |
|
41 /** |
|
42 Gets the length of the document. |
|
43 @return |
|
44 The number of Unicode UTF16 codes in the document. |
|
45 @internalComponent |
|
46 */ |
|
47 TInt CETextSource::DocumentLength() const |
|
48 { |
|
49 return iRichText->DocumentLength(); |
|
50 } |
|
51 |
|
52 /** |
|
53 Gets a run of text of constant formatting. |
|
54 @param aPos |
|
55 Start of the text to get. |
|
56 @param aText |
|
57 Segment of text to return. |
|
58 @param aFormat |
|
59 Format of the segment of text. |
|
60 @internalComponent |
|
61 */ |
|
62 void CETextSource::GetText(TInt aPos, TPtrC& aText, TTmCharFormat& aFormat) const |
|
63 { |
|
64 TCharFormat characterFormat; |
|
65 iRichText->GetChars(aText, characterFormat, aPos); |
|
66 aFormat = characterFormat; |
|
67 } |
|
68 |
|
69 /** |
|
70 Gets the format of the paragraph at aPos. |
|
71 @param aPos |
|
72 Character index. |
|
73 @param aFormat |
|
74 Returns the format. |
|
75 @internalComponent |
|
76 */ |
|
77 void CETextSource::GetParagraphFormatL(TInt aPos, RTmParFormat& aFormat) const |
|
78 { |
|
79 CParaFormat* format = CParaFormat::NewLC(); |
|
80 iRichText->GetParagraphFormatL(format, aPos); |
|
81 aFormat.CopyL(*format); |
|
82 CleanupStack::PopAndDestroy(format); |
|
83 } |
|
84 |
|
85 /** |
|
86 Returns the start of the paragraph containing aPos. |
|
87 @param aPos |
|
88 Character index. |
|
89 @return |
|
90 Character index of the start of the paragraph. |
|
91 @internalComponent |
|
92 */ |
|
93 TInt CETextSource::ParagraphStart(TInt aPos) const |
|
94 { |
|
95 iRichText->ParagraphNumberForPos(aPos); |
|
96 return aPos; |
|
97 } |
|
98 |
|
99 /** |
|
100 Gets a pointer to the picture at aPos. |
|
101 @param aPos |
|
102 Character index. |
|
103 @return |
|
104 A pointer to the picture at aPos if there is one. 0 otherwise. |
|
105 @internalComponent |
|
106 */ |
|
107 CPicture* CETextSource::PictureL(TInt aPos) const |
|
108 { |
|
109 return iRichText->PictureHandleL(aPos); |
|
110 } |
|
111 |
|
112 /** |
|
113 Creates a new CTestTmTextLayout. |
|
114 @param aText |
|
115 Text to format. |
|
116 @param aWrapWidth |
|
117 Width to format at. |
|
118 @return |
|
119 The newly constructed object. |
|
120 @internalComponent |
|
121 */ |
|
122 CTestTmTextLayout* CTestTmTextLayout::NewLC( |
|
123 const CRichText& aText, TInt aWrapWidth) |
|
124 { |
|
125 CTestTmTextLayout* r = new CTestTmTextLayout; |
|
126 CleanupStack::PushL(r); |
|
127 r->ConstructL(aText, aWrapWidth); |
|
128 return r; |
|
129 } |
|
130 |
|
131 /** |
|
132 Creates a new CTestTmTextLayout. |
|
133 @param aText |
|
134 Text to format. |
|
135 @param aWrapWidth |
|
136 Width to format at. |
|
137 @param aTransliterate |
|
138 Function to transform aText with if required. 0 if no transformation is to |
|
139 take place. |
|
140 @return |
|
141 The newly constructed object. |
|
142 @internalComponent |
|
143 */ |
|
144 CTestTmTextLayout* CTestTmTextLayout::NewLC( |
|
145 const TDesC& aText, TInt aWrapWidth, TransliterationFn* aTransliterate) |
|
146 { |
|
147 CTestTmTextLayout* r = new CTestTmTextLayout; |
|
148 CleanupStack::PushL(r); |
|
149 r->iParagraphFormatLayer = CParaFormatLayer::NewL(); |
|
150 r->iCharacterFormatLayer = CCharFormatLayer::NewL(); |
|
151 HBufC* buf = HBufC::NewLC(aText.Length()); |
|
152 TPtr des = buf->Des(); |
|
153 if (aTransliterate) |
|
154 aTransliterate(aText, des); |
|
155 else |
|
156 des.Copy(aText); |
|
157 r->iRichText = CRichText::NewL( |
|
158 r->iParagraphFormatLayer, r->iCharacterFormatLayer); |
|
159 r->iRichText->InsertL(0, *buf); |
|
160 CleanupStack::PopAndDestroy(buf); |
|
161 r->ConstructL(*r->iRichText, aWrapWidth); |
|
162 return r; |
|
163 } |
|
164 |
|
165 /** |
|
166 Destructor. |
|
167 @internalComponent |
|
168 */ |
|
169 CTestTmTextLayout::~CTestTmTextLayout() |
|
170 { |
|
171 delete iLayout; |
|
172 delete iSource; |
|
173 delete iDevice; |
|
174 delete iRichText; |
|
175 delete iCharacterFormatLayer; |
|
176 delete iParagraphFormatLayer; |
|
177 } |
|
178 |
|
179 /** |
|
180 Constructs a new CTestTmTextLayout. |
|
181 @param aText |
|
182 Text to format. |
|
183 @param aWrapWidth |
|
184 Width to format at. |
|
185 @return |
|
186 The newly constructed object. |
|
187 @internalComponent |
|
188 */ |
|
189 void CTestTmTextLayout::ConstructL(const CRichText& aText, TInt aWrapWidth) |
|
190 { |
|
191 iLayout = new (ELeave) CTmTextLayout; |
|
192 TSize screen(aWrapWidth, 100); |
|
193 iDevice = CTestGraphicsDevice::NewL(screen, 0); |
|
194 iSource = new (ELeave) CETextSource(aText, iDevice); |
|
195 iFormatParam.iWrapWidth = aWrapWidth; |
|
196 iFormatParam.iFlags = TTmFormatParamBase::EWrap; |
|
197 iLayout->SetTextL(*iSource, iFormatParam); |
|
198 } |
|
199 |
|
200 /** |
|
201 Reformats the text. |
|
202 @param aIn |
|
203 Reformatting parameters. |
|
204 @param aOut |
|
205 Reformatting result. |
|
206 @internalComponent |
|
207 */ |
|
208 void CTestTmTextLayout::FormatL(const TTmReformatParam& aIn, TTmReformatResult& aOut) |
|
209 { |
|
210 iLayout->FormatL(iFormatParam, aIn, aOut); |
|
211 } |
|
212 |
|
213 /** |
|
214 @SYMTestCaseID SYSLIB-FORM-UT-1887 |
|
215 @SYMTestCaseDesc Testing CTmTextLayout::FindAdjacentChunks() API |
|
216 @SYMTestPriority Low |
|
217 @SYMTestActions Tests by finding the text chunks adjoining a given document position. When pos=-1,FindAdjacentChunks() returns false |
|
218 @SYMTestExpectedResults Tests must not fail |
|
219 @SYMREQ REQ0000 |
|
220 */ |
|
221 void CTestTmTextLayout::TestAdjacentChunks() |
|
222 { |
|
223 RTest test(_L(" @SYMTestCaseID:SYSLIB-FORM-UT-1887 FindAdjacentChunks")); |
|
224 for (TInt pos = -1; pos != 4; ++pos) |
|
225 { |
|
226 for (TInt type = 0; type != 4; ++type) |
|
227 { |
|
228 TTmDocPosSpec posSpec(pos,static_cast<TTmDocPosSpec::TType>(type)); |
|
229 CTmTextLayout::TTmChunkDescription left; |
|
230 CTmTextLayout::TTmChunkDescription right; |
|
231 TBool result = iLayout->FindAdjacentChunks(posSpec,left,right); |
|
232 if(pos==-1) |
|
233 test(result==0); |
|
234 } |
|
235 } |
|
236 test.Close(); |
|
237 } |