|
1 // Copyright (c) 1997-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 #include <pdrstore.h> |
|
17 #include <banddev.h> |
|
18 #include "PDRBODY.H" |
|
19 #include "PDRSTD.H" |
|
20 #include "pdrtext.h" |
|
21 |
|
22 EXPORT_C CPdrResources::CPdrResources(): |
|
23 iNumResources(0), |
|
24 iResourceList(NULL) |
|
25 { |
|
26 __DECLARE_NAME(_S("CPdrResources")); |
|
27 } |
|
28 |
|
29 EXPORT_C void CPdrResources::RestoreL(CStreamStore& aStore, TStreamId aStreamId) |
|
30 { |
|
31 RStoreReadStream stream; |
|
32 stream.OpenLC(aStore, aStreamId); |
|
33 iNumResources = stream.ReadInt32L(); |
|
34 iResourceList = new(ELeave) TPdrResource[iNumResources]; |
|
35 for (TInt i = 0; i < iNumResources; i++) |
|
36 iResourceList[i].InternalizeL(stream); |
|
37 CleanupStack::PopAndDestroy(); |
|
38 } |
|
39 |
|
40 EXPORT_C CPdrResources::~CPdrResources() |
|
41 { |
|
42 delete[] iResourceList; |
|
43 iResourceList = NULL; |
|
44 iNumResources = 0; |
|
45 } |
|
46 |
|
47 EXPORT_C TPtrC8 CPdrResources::ResourceString(TInt anId) const |
|
48 { |
|
49 TPtrC8 ptr; |
|
50 TPdrResource* pEnd = iResourceList + iNumResources; |
|
51 TPdrResource* p ; |
|
52 for( p = iResourceList; (p < pEnd) && (p->iId != anId); p++) |
|
53 { |
|
54 } |
|
55 if (p < pEnd) |
|
56 ptr.Set(p->iString); |
|
57 return ptr; |
|
58 } |
|
59 |
|
60 CInfoFont::CInfoFont(TInt aBaselineOffsetInPixels, const TFontSpec& aFontSpecInTwips, TInt aFontInfoHeightInTwips, TInt aHeightInPixels, CPdrTranslates* aTranslates, const TDesC8& aCommandString, CPdrDevice* aPdrDevice): |
|
61 CFont(), |
|
62 iCommandString(aCommandString), |
|
63 iBaselineOffsetInPixels(aBaselineOffsetInPixels), |
|
64 iFontSpecInTwips(aFontSpecInTwips), |
|
65 iFontInfoHeightInTwips(aFontInfoHeightInTwips), |
|
66 iHeightInPixels(aHeightInPixels), |
|
67 iFontInfo(NULL), |
|
68 iTranslates(aTranslates), |
|
69 iPdrDevice(aPdrDevice), |
|
70 iRealFont(NULL) |
|
71 { |
|
72 CreateBandedFontIfRequired(); |
|
73 } |
|
74 |
|
75 CInfoFont::~CInfoFont() |
|
76 { |
|
77 if (iRealFont) |
|
78 if (iPdrDevice->iControl) |
|
79 ((CPdrControl*)(iPdrDevice->iControl))->BandedDevice()->ReleaseFont(iRealFont); |
|
80 } |
|
81 |
|
82 void CInfoFont::CreateBandedFontIfRequired() |
|
83 { |
|
84 if (!iRealFont) |
|
85 { |
|
86 if (iPdrDevice->iControl) |
|
87 { |
|
88 if (((CPdrControl*)(iPdrDevice->iControl))->BandedDevice()) |
|
89 ((CPdrControl*)(iPdrDevice->iControl))->BandedDevice()->GetNearestFontToDesignHeightInTwips(iRealFont, iFontSpecInTwips); |
|
90 } |
|
91 } |
|
92 } |
|
93 |
|
94 EXPORT_C TUid CInfoFont::DoTypeUid() const |
|
95 { |
|
96 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
97 return TUid::Uid(KCInfoFontUidVal); |
|
98 } |
|
99 |
|
100 EXPORT_C TInt CInfoFont::DoHeightInPixels() const |
|
101 { |
|
102 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
103 return iHeightInPixels; |
|
104 } |
|
105 |
|
106 EXPORT_C TInt CInfoFont::DoAscentInPixels() const |
|
107 { |
|
108 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
109 return Height(iFontInfo->iAscentInPixels); |
|
110 } |
|
111 |
|
112 EXPORT_C TInt CInfoFont::DoCharWidthInPixels(TChar aChar) const |
|
113 { |
|
114 TInt width; |
|
115 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
116 if (RepertoireContains(aChar)) |
|
117 { |
|
118 width = iFontInfo->CharWidthInPixels(TUint(aChar)); |
|
119 width = Width(width); |
|
120 } |
|
121 else |
|
122 { |
|
123 if (iRealFont) |
|
124 width = iRealFont->CharWidthInPixels(TUint(aChar)); |
|
125 else |
|
126 width = 0; |
|
127 } |
|
128 return width; |
|
129 } |
|
130 |
|
131 EXPORT_C TInt CInfoFont::DoTextWidthInPixels(const TDesC &aText) const |
|
132 { |
|
133 TMeasureTextOutput output; |
|
134 TInt advance_width = MeasureText(aText,NULL,&output); |
|
135 return Max(advance_width,output.iBounds.Width()); |
|
136 } |
|
137 |
|
138 EXPORT_C TInt CInfoFont::DoBaselineOffsetInPixels() const |
|
139 { |
|
140 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
141 return iBaselineOffsetInPixels; |
|
142 } |
|
143 |
|
144 EXPORT_C TInt CInfoFont::DoTextCount(const TDesC &aText, TInt aWidthInPixels) const |
|
145 { |
|
146 TInt count = 0; |
|
147 TInt width = 0; |
|
148 TInt length = aText.Length(); |
|
149 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
150 for (count = 0; (count < length) && ((width += MeasureText(aText.Mid(count, 1))) < aWidthInPixels); ) |
|
151 { |
|
152 count++; |
|
153 } |
|
154 return count; |
|
155 } |
|
156 |
|
157 EXPORT_C TInt CInfoFont::DoTextCount(const TDesC &aText, TInt aWidthInPixels, TInt &aExcessWidthInPixels) const |
|
158 { |
|
159 TInt count = TextCount(aText, aWidthInPixels); |
|
160 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
161 aExcessWidthInPixels = aWidthInPixels - MeasureText(aText.Left(count)); |
|
162 return count; |
|
163 } |
|
164 |
|
165 EXPORT_C TInt CInfoFont::DoMaxCharWidthInPixels() const |
|
166 { |
|
167 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
168 TInt width = Width(iFontInfo->iMaxCharWidthInPixels); |
|
169 if (iRealFont) |
|
170 return Max(iRealFont->MaxCharWidthInPixels(),width); |
|
171 return width; |
|
172 } |
|
173 |
|
174 EXPORT_C TInt CInfoFont::DoMaxNormalCharWidthInPixels() const |
|
175 { |
|
176 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
177 TInt width = Width(iFontInfo->iMaxNormalCharWidthInPixels); |
|
178 if (iRealFont) |
|
179 return Max(iRealFont->MaxNormalCharWidthInPixels(),width); |
|
180 return width; |
|
181 } |
|
182 |
|
183 EXPORT_C TFontSpec CInfoFont::DoFontSpecInTwips() const |
|
184 { |
|
185 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
186 return iFontSpecInTwips; |
|
187 } |
|
188 |
|
189 EXPORT_C HBufC8* CInfoFont::TranslateStringL(const TDesC& aString) const |
|
190 { |
|
191 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
192 return iTranslates->TranslateStringL(aString); |
|
193 } |
|
194 |
|
195 EXPORT_C TPtrC8 CInfoFont::CommandString() const |
|
196 { |
|
197 TPtrC8 ptr; |
|
198 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
199 ptr.Set(iCommandString); |
|
200 return ptr; |
|
201 } |
|
202 |
|
203 EXPORT_C TBool CInfoFont::RepertoireContains(TChar aChar) const |
|
204 { |
|
205 CFontInfo* fontInfo = FontInfo(); |
|
206 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
207 for (TInt i = 0; i < fontInfo->NumCodeSections(); i++) |
|
208 { |
|
209 if (((TInt)(TUint)aChar >= fontInfo->CodeSection(i).iStart) && ((TInt)(TUint)aChar<= fontInfo->CodeSection(i).iEnd)) |
|
210 return ETrue; |
|
211 } |
|
212 return EFalse; |
|
213 } |
|
214 |
|
215 EXPORT_C TBool CInfoFont::AllCharsInFontRepertoire(const TDesC& aString, TInt& aFirstCharNotInRepertoire, TInt& aLength) const |
|
216 { |
|
217 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
218 for (aFirstCharNotInRepertoire = 0; aFirstCharNotInRepertoire < aString.Length(); aFirstCharNotInRepertoire++) |
|
219 if (!(RepertoireContains(aString[aFirstCharNotInRepertoire]))) |
|
220 { |
|
221 if (aFirstCharNotInRepertoire == 0) |
|
222 { // Work out length |
|
223 for (aLength = aFirstCharNotInRepertoire; aLength < aString.Length(); aLength++) |
|
224 if ((RepertoireContains(aString[aLength]))) |
|
225 break; |
|
226 } |
|
227 return EFalse; |
|
228 } |
|
229 return ETrue; |
|
230 } |
|
231 |
|
232 CFont* CInfoFont::RealFont() const |
|
233 { |
|
234 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
235 return iRealFont; |
|
236 } |
|
237 |
|
238 TInt CInfoFont::Width(TInt aNum) const |
|
239 { |
|
240 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
241 return (aNum * iFontSpecInTwips.iHeight + (iFontInfoHeightInTwips / 2)) / iFontInfoHeightInTwips; |
|
242 } |
|
243 |
|
244 TInt CInfoFont::Height(TInt aNum) const |
|
245 { |
|
246 CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); |
|
247 return (aNum * iFontSpecInTwips.iHeight + (iFontInfoHeightInTwips / 2)) / iFontInfoHeightInTwips; |
|
248 } |
|
249 |
|
250 EXPORT_C void TTypefaceFontsEntry::InternalizeL(RReadStream& aStream) |
|
251 { |
|
252 aStream >> iStreamId; |
|
253 iNotInPortrait = aStream.ReadUint8L(); |
|
254 iNotInLandscape = aStream.ReadUint8L(); |
|
255 } |
|
256 |
|
257 EXPORT_C CPdrModelInfo::CPdrModelInfo(): |
|
258 iFlags(0), |
|
259 iKPixelWidthInTwips(0), |
|
260 iKPixelHeightInTwips(0), |
|
261 iPortraitOffsetInPixels(), |
|
262 iLandscapeOffsetInPixels(), |
|
263 // iMinMarginsInPixels(), |
|
264 iDisplayMode(EGray2), |
|
265 iNumTypefaceFonts(0), |
|
266 iTypefaceFontsEntryList(NULL), |
|
267 iResourcesStreamId(KNullStreamId), |
|
268 iSpareStreamId(KNullStreamId) |
|
269 { |
|
270 __DECLARE_NAME(_S("CPdrModelInfo")); |
|
271 } |
|
272 |
|
273 EXPORT_C CPdrModelInfo::~CPdrModelInfo() |
|
274 { |
|
275 delete[] iTypefaceFontsEntryList; |
|
276 } |
|
277 |
|
278 EXPORT_C void CPdrModelInfo::InternalizeL(RReadStream& aStream) |
|
279 { |
|
280 TInt pdrtranversion = aStream.ReadInt32L(); |
|
281 if (pdrtranversion < KPdrtranVersion) |
|
282 User::Leave(KErrNotSupported); |
|
283 iFlags = aStream.ReadInt32L(); |
|
284 iKPixelWidthInTwips = aStream.ReadInt32L(); |
|
285 iKPixelHeightInTwips = aStream.ReadInt32L(); |
|
286 iPortraitOffsetInPixels.iX = aStream.ReadInt32L(); |
|
287 iPortraitOffsetInPixels.iY = aStream.ReadInt32L(); |
|
288 iLandscapeOffsetInPixels.iX = aStream.ReadInt32L(); |
|
289 iLandscapeOffsetInPixels.iY = aStream.ReadInt32L(); |
|
290 iMinMarginsInPixels.InternalizeL(aStream); |
|
291 iDisplayMode = (TDisplayMode)aStream.ReadInt32L(); |
|
292 iNumTypefaceFonts = aStream.ReadInt32L(); |
|
293 iTypefaceFontsEntryList = new(ELeave) TTypefaceFontsEntry[iNumTypefaceFonts]; |
|
294 TTypefaceFontsEntry* pEnd = iTypefaceFontsEntryList+iNumTypefaceFonts; |
|
295 for(TTypefaceFontsEntry* p = iTypefaceFontsEntryList; p < pEnd; p++) |
|
296 p->InternalizeL(aStream); |
|
297 aStream >> iResourcesStreamId; |
|
298 aStream >> iSpareStreamId; |
|
299 } |
|
300 |
|
301 CPdrTypefaceStore::CPdrTypefaceStore(CStreamStore& aStore, TInt aKPixelHeightInTwips, CPdrDevice* aPdrDevice): |
|
302 iPdrDevice(aPdrDevice), |
|
303 iStore(&aStore), |
|
304 iKPixelHeightInTwips(aKPixelHeightInTwips) |
|
305 { |
|
306 } |
|
307 |
|
308 void CPdrTypefaceStore::ConstructL(TInt aNumTypefaceFonts, TTypefaceFontsEntry* aTypefaceFontsEntryList, TPageSpec::TPageOrientation aPageOrientation) |
|
309 { |
|
310 CTypefaceStore::ConstructL(); |
|
311 iTranslatesList = new(ELeave) CArrayPtrFlat<CPdrTranslates>(8); |
|
312 iTypefaceFontsList = new(ELeave) CArrayPtrFlat<CTypefaceFonts>(8); |
|
313 iPortraitTypefaceFontsList = new(ELeave) CArrayPtrFlat<CTypefaceFonts>(8); |
|
314 iLandscapeTypefaceFontsList = new(ELeave) CArrayPtrFlat<CTypefaceFonts>(8); |
|
315 iFontInfoList = new(ELeave) CArrayPtrFlat<CFontInfo>(8); |
|
316 for (TInt i = 0; i < aNumTypefaceFonts; i++) |
|
317 { |
|
318 CTypefaceFonts* typefacefonts = new(ELeave) CTypefaceFonts; |
|
319 CleanupStack::PushL(typefacefonts); |
|
320 RStoreReadStream stream; |
|
321 stream.OpenLC(*iStore, aTypefaceFontsEntryList[i].iStreamId); |
|
322 typefacefonts->InternalizeL(stream); |
|
323 CleanupStack::PopAndDestroy(); |
|
324 iTypefaceFontsList->AppendL(typefacefonts); |
|
325 CleanupStack::Pop(); |
|
326 typefacefonts->iTranslates=TranslatesL(typefacefonts->iTranslates.AsId()); |
|
327 if (!aTypefaceFontsEntryList[i].iNotInPortrait) |
|
328 iPortraitTypefaceFontsList->AppendL(typefacefonts); |
|
329 if (!aTypefaceFontsEntryList[i].iNotInLandscape) |
|
330 iLandscapeTypefaceFontsList->AppendL(typefacefonts); |
|
331 } |
|
332 SetPageOrientation(aPageOrientation); |
|
333 } |
|
334 |
|
335 EXPORT_C CPdrTypefaceStore* CPdrTypefaceStore::NewL(CStreamStore& aStore, TInt aNumTypefacesFonts, TTypefaceFontsEntry* aTypefaceFontsEntryList, TPageSpec::TPageOrientation aPageOrientation, TInt aKPixelHeightInTwips, CPdrDevice* aPdrDevice) |
|
336 { |
|
337 CPdrTypefaceStore* typefacestore = new(ELeave) CPdrTypefaceStore(aStore, aKPixelHeightInTwips, aPdrDevice); |
|
338 CleanupStack::PushL(typefacestore); |
|
339 typefacestore->ConstructL(aNumTypefacesFonts, aTypefaceFontsEntryList, aPageOrientation); |
|
340 CleanupStack::Pop(); |
|
341 return typefacestore; |
|
342 } |
|
343 |
|
344 EXPORT_C CPdrTypefaceStore::~CPdrTypefaceStore() |
|
345 { |
|
346 if (iTranslatesList) |
|
347 iTranslatesList->ResetAndDestroy(); |
|
348 delete iTranslatesList; |
|
349 if (iTypefaceFontsList) |
|
350 iTypefaceFontsList->ResetAndDestroy(); |
|
351 delete iTypefaceFontsList; |
|
352 delete iPortraitTypefaceFontsList; |
|
353 delete iLandscapeTypefaceFontsList; |
|
354 if (iFontInfoList) |
|
355 iFontInfoList->ResetAndDestroy(); |
|
356 delete iFontInfoList; |
|
357 } |
|
358 |
|
359 /** |
|
360 @internalTechnology |
|
361 */ |
|
362 EXPORT_C TInt CPdrTypefaceStore::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec) |
|
363 { |
|
364 return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec); |
|
365 } |
|
366 |
|
367 /** |
|
368 @internalTechnology |
|
369 */ |
|
370 EXPORT_C TInt CPdrTypefaceStore::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec) |
|
371 { |
|
372 aFont = NULL; |
|
373 const TInt count = iCurrentTypefaceFontsList->Count(); |
|
374 if (count) |
|
375 { |
|
376 TInt index = 0; |
|
377 TTypeface typeface = aFontSpec.iTypeface; |
|
378 for (index = 0; (index < count) && typeface.iName.CompareF((*iCurrentTypefaceFontsList)[index]->Typeface().iName); index++) |
|
379 { // tries matching typeface name |
|
380 } |
|
381 if (index == count) |
|
382 { |
|
383 if (!typeface.IsSymbol()) |
|
384 { |
|
385 for (index = 0; (index < count) && (((*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()) || |
|
386 (typeface.IsProportional() != (*iCurrentTypefaceFontsList)[index]->Typeface().IsProportional()) || |
|
387 (typeface.IsSerif() != (*iCurrentTypefaceFontsList)[index]->Typeface().IsSerif())); index++) |
|
388 { // tries matching typeface flags |
|
389 } |
|
390 if (index == count) |
|
391 for (index = 0; (index < count) && (((*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()) || |
|
392 (typeface.IsProportional() != (*iCurrentTypefaceFontsList)[index]->Typeface().IsProportional())); index++) |
|
393 { // tries matching typeface flag |
|
394 } |
|
395 if (index == count) |
|
396 for (index = 0; (index < count) && ((*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()); index++) |
|
397 { // tries matching typeface flag |
|
398 } |
|
399 } |
|
400 else |
|
401 { |
|
402 for (index = 0; (index < count) && (!(*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()); index++) |
|
403 { // finds first symbol typeface |
|
404 } |
|
405 } |
|
406 } |
|
407 if (index == count) |
|
408 index = 0; |
|
409 CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[index]; |
|
410 if (typefacefonts->NumFontHeights()) |
|
411 { |
|
412 TFontSpec fontspec(aFontSpec); |
|
413 fontspec.iTypeface = typefacefonts->Typeface(); |
|
414 TInt i = GetNearestFontHeightIndex(index, aFontSpec.iHeight); |
|
415 fontspec.iHeight = typefacefonts->FontHeightInTwips(i); |
|
416 if (fontspec.iFontStyle.PrintPosition() != EPrintPosNormal) |
|
417 { |
|
418 i = GetNearestFontHeightIndex(index, SuperSubHeight(fontspec.iHeight, fontspec.iFontStyle.PrintPosition())); |
|
419 } |
|
420 fontspec.iFontStyle = GetNearestFontStyle(index, i, fontspec.iFontStyle); |
|
421 TInt heightintwips = typefacefonts->FontHeightInTwips(i); |
|
422 TInt height = VerticalTwipsToPixels(heightintwips); |
|
423 if (IsFontLoaded(aFont, fontspec, height)) |
|
424 return KErrNone; |
|
425 TInt baselineoffset = BaselineOffset(VerticalTwipsToPixels(fontspec.iHeight), fontspec.iFontStyle.PrintPosition()); |
|
426 TInt fontinfoheight = ((fontspec.iHeight * typefacefonts->FontInfoHeightInTwips(i) + (heightintwips / 2))) / heightintwips; |
|
427 CPdrTranslates* translates = typefacefonts->iTranslates; |
|
428 TCommandString commandstring; |
|
429 typefacefonts->CommandString(commandstring, i); |
|
430 TStreamId fontinfostreamid = typefacefonts->Style(i, fontspec.iFontStyle)->iFontInfoStreamId; |
|
431 TRAPD(ret, aFont = NewFontL(baselineoffset, fontspec, fontinfoheight, height, translates, commandstring, fontinfostreamid)); |
|
432 return ret; |
|
433 } |
|
434 } |
|
435 return KErrNotFound; |
|
436 } |
|
437 |
|
438 /** |
|
439 @internalTechnology |
|
440 */ |
|
441 EXPORT_C TInt CPdrTypefaceStore::GetNearestFontToMaxHeightInTwips(CFont*& /*aFont*/, const TFontSpec& /*aFontSpec*/, TInt /* aMaxHeight */) |
|
442 { |
|
443 return KErrNotSupported; |
|
444 } |
|
445 |
|
446 EXPORT_C TInt CPdrTypefaceStore::NumTypefaces() const |
|
447 { |
|
448 return iCurrentTypefaceFontsList->Count(); |
|
449 } |
|
450 |
|
451 EXPORT_C TInt CPdrTypefaceStore::FontHeightInTwips(TInt aTypefaceIndex, TInt aHeightIndex) const |
|
452 { |
|
453 TInt height = 0; |
|
454 __ASSERT_DEBUG((aTypefaceIndex >= 0) && (aTypefaceIndex < NumTypefaces()), Panic(EPdrHeightIndexOutOfRange)); |
|
455 CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex]; |
|
456 height = typefacefonts->FontHeightInTwips(aHeightIndex); |
|
457 return height; |
|
458 } |
|
459 |
|
460 EXPORT_C void CPdrTypefaceStore::TypefaceSupport(TTypefaceSupport &aTypefaceSupport, TInt aTypefaceIndex) const |
|
461 { |
|
462 __ASSERT_DEBUG((aTypefaceIndex >= 0) && (aTypefaceIndex < NumTypefaces()), Panic(EPdrHeightIndexOutOfRange)); |
|
463 CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex]; |
|
464 aTypefaceSupport.iTypeface = typefacefonts->Typeface(); |
|
465 aTypefaceSupport.iIsScalable = typefacefonts->IsScalable(); |
|
466 aTypefaceSupport.iNumHeights = typefacefonts->NumFontHeights(); |
|
467 aTypefaceSupport.iMinHeightInTwips = FontHeightInTwips(aTypefaceIndex, 0); // Font heights must be in ascending order |
|
468 aTypefaceSupport.iMaxHeightInTwips = FontHeightInTwips(aTypefaceIndex, aTypefaceSupport.iNumHeights - 1); |
|
469 } |
|
470 |
|
471 EXPORT_C void CPdrTypefaceStore::SetPageOrientation(TPageSpec::TPageOrientation aPageOrientation) |
|
472 { |
|
473 if (aPageOrientation == TPageSpec::EPortrait) |
|
474 iCurrentTypefaceFontsList = iPortraitTypefaceFontsList; |
|
475 else |
|
476 iCurrentTypefaceFontsList = iLandscapeTypefaceFontsList; |
|
477 } |
|
478 |
|
479 CFontInfo* CPdrTypefaceStore::FontInfoL(TStreamId aStreamId) const |
|
480 { |
|
481 CFontInfo* fontinfo; |
|
482 TInt i; |
|
483 const TInt count = iFontInfoList->Count(); |
|
484 for (i = 0; (i < count) && ((*iFontInfoList)[i]->iStreamId != aStreamId); i++) |
|
485 { // Searches for FontInfo with same Id |
|
486 } |
|
487 if (i < count) // Found |
|
488 fontinfo = (*iFontInfoList)[i]; |
|
489 else // Not found |
|
490 { |
|
491 RStoreReadStream stream; |
|
492 fontinfo = new(ELeave) CFontInfo(aStreamId); |
|
493 CleanupStack::PushL(fontinfo); |
|
494 stream.OpenLC(*iStore, aStreamId); |
|
495 fontinfo->InternalizeL(stream); |
|
496 CleanupStack::PopAndDestroy(); |
|
497 iFontInfoList->AppendL(fontinfo); |
|
498 CleanupStack::Pop(); |
|
499 } |
|
500 return fontinfo; |
|
501 } |
|
502 |
|
503 CPdrTranslates* CPdrTypefaceStore::TranslatesL(TStreamId aStreamId) const |
|
504 { |
|
505 CPdrTranslates* translates; |
|
506 TInt i; |
|
507 const TInt count = iTranslatesList->Count(); |
|
508 for (i = 0; (i < count) && ((*iTranslatesList)[i]->iStreamId != aStreamId); i++) |
|
509 { // Searches for Translate with same Id |
|
510 } |
|
511 if (i < count) // Found |
|
512 translates = (*iTranslatesList)[i]; |
|
513 else // Not found |
|
514 { |
|
515 RStoreReadStream stream; |
|
516 translates = new(ELeave) CPdrTranslates; |
|
517 CleanupStack::PushL(translates); |
|
518 translates->iStreamId = aStreamId; |
|
519 stream.OpenLC(*iStore, aStreamId); |
|
520 translates->InternalizeL(stream); |
|
521 CleanupStack::PopAndDestroy(); |
|
522 iTranslatesList->AppendL(translates); |
|
523 CleanupStack::Pop(); |
|
524 } |
|
525 return translates; |
|
526 } |
|
527 |
|
528 TInt CPdrTypefaceStore::GetNearestFontHeightIndex(TInt aTypefaceIndex, TInt aHeightInTwips) const |
|
529 { |
|
530 CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex]; |
|
531 TInt i; |
|
532 TInt size = typefacefonts->NumFontHeights(); |
|
533 for (i = size - 1; (i > 0) && (aHeightInTwips < typefacefonts->FontHeightInTwips(i)); i--) |
|
534 { // Finds fontheight less than or equal to fontspec height |
|
535 } |
|
536 return i; |
|
537 } |
|
538 |
|
539 TFontStyle CPdrTypefaceStore::GetNearestFontStyle(TInt aTypefaceIndex, TInt aHeightIndex, const TFontStyle& aFontStyle) const |
|
540 { |
|
541 TFontStyle fontstyle(aFontStyle); |
|
542 CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex]; |
|
543 while (!typefacefonts->Style(aHeightIndex, fontstyle)->iIsAvailable) |
|
544 { // finds first available style |
|
545 if ((fontstyle.StrokeWeight() == EStrokeWeightBold) && (fontstyle.Posture() == EPostureItalic)) |
|
546 fontstyle.SetPosture(EPostureUpright); |
|
547 else |
|
548 { |
|
549 fontstyle.SetPosture(EPostureUpright); |
|
550 fontstyle.SetStrokeWeight(EStrokeWeightNormal); |
|
551 } |
|
552 } |
|
553 return fontstyle; |
|
554 } |
|
555 |
|
556 TBool CPdrTypefaceStore::IsFontLoaded(CFont*& aFont, const TFontSpec& aFontSpecInTwips, TInt aHeightInPixels) const |
|
557 /** |
|
558 @see CFbsTypefaceStore::IsFontLoaded |
|
559 @see CFontStore::IsFontLoaded |
|
560 */ |
|
561 { |
|
562 TInt i = 0; |
|
563 const TInt count = iFontAccess->Count(); |
|
564 for (; i < count && |
|
565 !(aHeightInPixels == (*iFontAccess)[i].iFont->HeightInPixels() && |
|
566 aFontSpecInTwips == (*iFontAccess)[i].iFont->FontSpecInTwips()); i++) |
|
567 { |
|
568 } |
|
569 if (i < count) |
|
570 { |
|
571 aFont = (*iFontAccess)[i].iFont; |
|
572 (*iFontAccess)[i].iAccessCount++; |
|
573 return ETrue; |
|
574 } |
|
575 return EFalse; |
|
576 } |
|
577 |
|
578 CInfoFont* CPdrTypefaceStore::NewFontL(TInt aBaselineOffsetInPixels, const TFontSpec& aFontSpecInTwips, TInt aFontInfoHeightInTwips, TInt aHeightInPixels, CPdrTranslates* aTranslates, const TDesC8& aCommandString, TStreamId aFontInfoStreamId) |
|
579 { |
|
580 CInfoFont* infofont = new(ELeave) CInfoFont(aBaselineOffsetInPixels, aFontSpecInTwips, aFontInfoHeightInTwips, aHeightInPixels, aTranslates, aCommandString, iPdrDevice); |
|
581 CleanupStack::PushL(infofont); |
|
582 AddFontL(infofont); |
|
583 CleanupStack::Pop(); |
|
584 TRAPD(ret, infofont->iFontInfo = FontInfoL(aFontInfoStreamId)); |
|
585 if (ret != KErrNone) |
|
586 { |
|
587 ReleaseFont(infofont); |
|
588 User::Leave(ret); |
|
589 } |
|
590 return infofont; |
|
591 } |
|
592 |
|
593 TInt CPdrTypefaceStore::VerticalTwipsToPixels(TInt aTwipsHeight) const |
|
594 { |
|
595 return (1000 * aTwipsHeight + (iKPixelHeightInTwips / 2)) / iKPixelHeightInTwips; |
|
596 } |