|
1 /* |
|
2 * Copyright (c) 1996-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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <s32file.h> |
|
20 #include <fntstore.h> |
|
21 #include "FNTBODY.H" |
|
22 #include <graphics/openfontconstants.h> |
|
23 |
|
24 CFontStoreFile::CFontStoreFile() |
|
25 : iCollectionUid(KNullUid), |
|
26 iUsageCount(1), |
|
27 iFileStore(NULL), |
|
28 iFileAddress(0), |
|
29 iDataStreamId(KNullStreamId) |
|
30 { |
|
31 } |
|
32 |
|
33 void CFontStoreFile::ConstructL(const TParse& aParse,RFs& aFs) |
|
34 { |
|
35 TInt drive; |
|
36 User::LeaveIfError(RFs::CharToDrive(aParse.Drive()[0], drive)); |
|
37 TDriveInfo driveinfo; |
|
38 User::LeaveIfError(aFs.Drive(driveinfo, drive)); |
|
39 RFile file; |
|
40 |
|
41 // store the filename |
|
42 iFullName = aParse.FullName().AllocL(); |
|
43 User::LeaveIfError(file.Open(aFs, *iFullName, EFileStream | EFileRead | EFileShareReadersOnly)); |
|
44 |
|
45 // check to see if the fonts are stored on ROM. Note that NAND != rom so font files in NAND devices |
|
46 // must be handled as if they were in RAM. A NULL pointer returned by IsFileInRom means its RAM |
|
47 |
|
48 if (aFs.IsFileInRom(*iFullName)!=NULL) |
|
49 { |
|
50 // fonts are stored on a XIP (execute in place) device |
|
51 TInt ret = file.Seek(ESeekAddress, iFileAddress); |
|
52 |
|
53 if (ret != KErrNone) |
|
54 { |
|
55 file.Close(); |
|
56 User::Leave(ret); |
|
57 } |
|
58 } |
|
59 |
|
60 // convert RFile into a CDirectFileStore |
|
61 CDirectFileStore* fileStore = CDirectFileStore::FromLC(file); |
|
62 |
|
63 if (fileStore->Type()[1] != TUid::Uid(KFontStoreFileUidVal)) |
|
64 User::Leave(KErrNotSupported); |
|
65 TStreamId headerid = fileStore->Root(); |
|
66 RStoreReadStream stream; |
|
67 stream.OpenLC(*fileStore, headerid); |
|
68 TInt fnttranversion = stream.ReadInt32L(); |
|
69 // This works for version 42 (with new metrics) and for earlier versions |
|
70 // which will synthesize the required metrics. It may have to be changed |
|
71 // if the version number is incremented again. |
|
72 if (fnttranversion < (KFnttranVersion - 1) && fnttranversion != KFnttran7650Version) |
|
73 User::Leave(KErrNotSupported); |
|
74 iFontVersion = fnttranversion; |
|
75 stream >> iCollectionUid; |
|
76 iKPixelAspectRatio = stream.ReadInt32L(); |
|
77 stream >> iDataStreamId; |
|
78 CleanupStack::PopAndDestroy(&stream); // close root stream |
|
79 // ensure font data stream can be opened |
|
80 stream.OpenLC(*fileStore, iDataStreamId); |
|
81 CleanupStack::PopAndDestroy(&stream); // close font stream |
|
82 // transfer ownership of fileStore |
|
83 CleanupStack::Pop(fileStore); |
|
84 iFileStore = fileStore; |
|
85 } |
|
86 |
|
87 CFontStoreFile* CFontStoreFile::NewL(const TParse& aParse, RFs& aFs) |
|
88 { |
|
89 CFontStoreFile* fontstorefile = new(ELeave) CFontStoreFile; |
|
90 CleanupStack::PushL(fontstorefile); |
|
91 fontstorefile->ConstructL(aParse, aFs); |
|
92 CleanupStack::Pop(); |
|
93 return fontstorefile; |
|
94 } |
|
95 |
|
96 CFontStoreFile::~CFontStoreFile() |
|
97 { |
|
98 delete iFullName; |
|
99 iFullName = NULL; |
|
100 delete iFileStore; |
|
101 iFileStore = NULL; |
|
102 } |
|
103 |
|
104 TBitmapCodeSection::TBitmapCodeSection() |
|
105 : TCodeSection(), |
|
106 iCharacterData(), |
|
107 iBitmapData() |
|
108 { |
|
109 } |
|
110 |
|
111 //This method is called from CFontBitmap::InternalizeL. |
|
112 //We have to read stream IDs from the stream, not offsets. |
|
113 //Obviously the method is called once per life time of |
|
114 //CFontBitmap instance. |
|
115 void TBitmapCodeSection::InternalizeL(RReadStream &aStream) |
|
116 { |
|
117 iStart = aStream.ReadUint16L(); |
|
118 iEnd = aStream.ReadUint16L(); |
|
119 aStream >> iCharacterData.iOffsetsId; |
|
120 aStream >> iBitmapData.iBitmapId; |
|
121 } |
|
122 |
|
123 //This method is called from CFontBitmap::RestoreComponentsL - |
|
124 //if the CFontBitmap instance is in RAM and CFontBitmap::iComponentsRestored is EFalse. |
|
125 //We use here stream IDs, not offsets. |
|
126 //If the memory allocation for the offsets doesn't fail - aAllocMemCounter is incremented |
|
127 //After calling of TBitmapCodeSection::InternalizeOffsetsL character metrics streamID is no more valid - |
|
128 //we have valid character metrics offset into RAM memory. |
|
129 void TBitmapCodeSection::InternalizeOffsetsL(const CStreamStore& aStreamStore, RHeap* aHeap, TInt& aAllocMemCounter) |
|
130 { |
|
131 RStoreReadStream stream; |
|
132 stream.OpenLC(aStreamStore, iCharacterData.iOffsetsId); |
|
133 |
|
134 TInt size = stream.ReadInt32L(); |
|
135 TBitmapFontCharacterOffset* characterOffsetsList = (TBitmapFontCharacterOffset*)aHeap->AllocL(sizeof(TBitmapFontCharacterOffset) * size); |
|
136 aAllocMemCounter++; |
|
137 iCharacterData.iCharacterOffsetsListOffset = TInt(characterOffsetsList) - TInt(this); |
|
138 TBitmapFontCharacterOffset* pEnd = characterOffsetsList + size; |
|
139 for (TBitmapFontCharacterOffset* p = characterOffsetsList; p < pEnd; p++) |
|
140 { |
|
141 p->InternalizeL(stream); |
|
142 } |
|
143 |
|
144 CleanupStack::PopAndDestroy(); |
|
145 } |
|
146 |
|
147 //This method is called from CFontBitmap::RestoreComponentsL - |
|
148 //if the CFontBitmap instance is in RAM and CFontBitmap::iComponentsRestored is EFalse. |
|
149 //We use here stream IDs, not offsets. |
|
150 //If the memory allocation for the bitmap doesn't fail - aAllocMemCounter is incremented |
|
151 //After calling of TBitmapCodeSection::InternalizeBitmapL bitmap streamID is no more valid - |
|
152 //we have valid bitmap offset into RAM memory. |
|
153 void TBitmapCodeSection::InternalizeBitmapL(const CStreamStore& aStreamStore, RHeap* aHeap, TInt& aAllocMemCounter) |
|
154 { |
|
155 RStoreReadStream stream; |
|
156 stream.OpenLC(aStreamStore, iBitmapData.iBitmapId); |
|
157 |
|
158 TInt size = stream.ReadInt32L(); |
|
159 TUint8* bitmap = (TUint8*)aHeap->AllocL(size); |
|
160 aAllocMemCounter++; |
|
161 iBitmapData.iBitmapOffset = TInt(bitmap) - TInt(this); |
|
162 stream.ReadL(bitmap, size); |
|
163 |
|
164 CleanupStack::PopAndDestroy(); |
|
165 } |
|
166 |
|
167 //This method is called from CFontBitmap::InternalizeL if the |
|
168 //CFontBitmap instance is in ROM. |
|
169 //We use here stream IDs to calculate offsets. |
|
170 //After calling of TBitmapCodeSection::FixUpComponents streamIDs are no more valid - |
|
171 //we have valid offsets into ROM memory. |
|
172 //Obviously the method is called once per life time of |
|
173 //CFontBitmap instance. |
|
174 void TBitmapCodeSection::FixUpComponents(TInt aFileAddress) |
|
175 { |
|
176 TBitmapFontCharacterOffset* characterOffsetsList = (TBitmapFontCharacterOffset*) (aFileAddress + sizeof(TInt) + iCharacterData.iOffsetsId); |
|
177 iCharacterData.iCharacterOffsetsListOffset = TInt(characterOffsetsList); |
|
178 TUint8* bitmap = (TUint8*) (aFileAddress + sizeof(TInt) + iBitmapData.iBitmapId); |
|
179 iBitmapData.iBitmapOffset = TInt(bitmap); |
|
180 } |
|
181 |
|
182 //This method is caled from CFontBitmap::DeleteComponents(), |
|
183 //only if the CFontBitmap instance is in RAM. |
|
184 void TBitmapCodeSection::DeleteOffsets(RHeap* aHeap) |
|
185 { |
|
186 TBitmapFontCharacterOffset* charactersOffsetsList = CharacterOffsetsList(ETrue); |
|
187 if(TUint32(this) != TUint32(charactersOffsetsList)) |
|
188 { |
|
189 aHeap->Free(charactersOffsetsList); |
|
190 } |
|
191 } |
|
192 |
|
193 //This method is caled from CFontBitmap::DeleteComponents(), |
|
194 //only if the CFontBitmap instance is in RAM. |
|
195 void TBitmapCodeSection::DeleteBitmap(RHeap* aHeap) |
|
196 { |
|
197 TUint8* bitmap = Bitmap(ETrue); |
|
198 if(TUint32(this) != TUint32(bitmap)) |
|
199 { |
|
200 aHeap->Free(bitmap); |
|
201 } |
|
202 } |
|
203 |
|
204 TBitmapFontCharacterOffset* TBitmapCodeSection::CharacterOffsetsList(TBool aIsInRAM) const |
|
205 { |
|
206 return reinterpret_cast <TBitmapFontCharacterOffset*> |
|
207 (iCharacterData.iCharacterOffsetsListOffset + (aIsInRAM ? TInt(this) : 0)); |
|
208 } |
|
209 |
|
210 TUint8* TBitmapCodeSection::Bitmap(TBool aIsInRAM) const |
|
211 { |
|
212 return reinterpret_cast <TUint8*> |
|
213 (iBitmapData.iBitmapOffset + (aIsInRAM ? TInt(this) : 0)); |
|
214 } |
|
215 |
|
216 TCharacterMetricsTable::TCharacterMetricsTable(RHeap* aHeap) |
|
217 : iHeap(aHeap), |
|
218 iMetricsStartId(KNullStreamId), |
|
219 iCharacterMetricsStartPtr(0), |
|
220 iNumberOfMetrics(0) |
|
221 {} |
|
222 |
|
223 void TCharacterMetricsTable::InternalizeL(RReadStream& aStream) |
|
224 { |
|
225 iMetricsStartId = aStream.ReadInt32L(); |
|
226 iNumberOfMetrics = aStream.ReadInt32L(); |
|
227 } |
|
228 |
|
229 void TCharacterMetricsTable::InternalizeMetricsL(RReadStream& aStream) |
|
230 { |
|
231 aStream.ReadInt32L(); // size |
|
232 TBitmapFontCharacterMetrics* charactermetricslist = static_cast<TBitmapFontCharacterMetrics*>(iHeap->AllocL(sizeof(TBitmapFontCharacterMetrics) * iNumberOfMetrics)); |
|
233 |
|
234 iCharacterMetricsStartPtr = TInt(charactermetricslist); // Ptr to location on the heap ('cos the file is not in ROM) |
|
235 TBitmapFontCharacterMetrics* pEnd = charactermetricslist + iNumberOfMetrics; |
|
236 for (TBitmapFontCharacterMetrics* p = charactermetricslist; p < pEnd; p++) |
|
237 { |
|
238 p->InternalizeL(aStream); |
|
239 } |
|
240 } |
|
241 |
|
242 void TCharacterMetricsTable::RestoreL(const CStreamStore& aStreamStore) |
|
243 { |
|
244 if (iCharacterMetricsStartPtr == 0) |
|
245 { // We haven't already read it in from RAM file |
|
246 RStoreReadStream stream; |
|
247 stream.OpenLC(aStreamStore, iMetricsStartId); |
|
248 InternalizeMetricsL(stream); |
|
249 CleanupStack::PopAndDestroy(); |
|
250 } |
|
251 } |
|
252 |
|
253 void TCharacterMetricsTable::FixUp(TInt aFileAddress) |
|
254 { |
|
255 TBitmapFontCharacterMetrics* charactermetricslist = reinterpret_cast<TBitmapFontCharacterMetrics*>(aFileAddress + sizeof(TInt) + iMetricsStartId.Value()); |
|
256 iCharacterMetricsStartPtr = TInt(charactermetricslist); // Ptr to location in a ROM file |
|
257 iMetricsStartId = KNullStreamId; |
|
258 } |
|
259 |
|
260 void TCharacterMetricsTable::Delete() |
|
261 { // This routine is only called if the font file is in RAM, not ROM, and therefore the metrics have been stashed on the heap |
|
262 if (iCharacterMetricsStartPtr) |
|
263 { |
|
264 iHeap->Free(reinterpret_cast<TAny*>(iCharacterMetricsStartPtr)); |
|
265 iCharacterMetricsStartPtr = 0; |
|
266 } |
|
267 } |
|
268 |
|
269 const TBitmapFontCharacterMetrics* TCharacterMetricsTable::Metric(TInt aIndex) const |
|
270 { |
|
271 __ASSERT_DEBUG((aIndex >= 0) && (aIndex <= iNumberOfMetrics), Panic(EFntMetricsIndexOutOfBounds)); |
|
272 // Sometimes the start ptr is to a metrics heap item and sometimes it points into a ROM file |
|
273 return reinterpret_cast<const TBitmapFontCharacterMetrics*>(iCharacterMetricsStartPtr + (aIndex * sizeof(TBitmapFontCharacterMetrics))); |
|
274 } |
|
275 |
|
276 TInt TCharacterMetricsTable::NumberOfMetrics() const |
|
277 { |
|
278 return iNumberOfMetrics; |
|
279 } |
|
280 |
|
281 CFontBitmap::CFontBitmap(RHeap* aHeap, CFontStoreFile* aFontStoreFile) |
|
282 : iHeap(aHeap), |
|
283 iFontStoreFileOffset(0), |
|
284 iUid(KNullUid), |
|
285 iPosture(0), |
|
286 iStrokeWeight(0), |
|
287 iIsProportional(0), |
|
288 iIsInRAM(!aFontStoreFile->iFileAddress), |
|
289 iUsageCount(1), |
|
290 iCellHeightInPixels(0), |
|
291 iAscentInPixels(0), |
|
292 iMaxCharWidthInPixels(0), |
|
293 iMaxNormalCharWidthInPixels(0), |
|
294 iBitmapEncoding(0), |
|
295 iNumCodeSections(0), |
|
296 iCodeSectionListOffset(0), |
|
297 iCharacterMetricsTable(aHeap), |
|
298 iComponentsRestored(EFalse), |
|
299 iAllocMemCounter_Offsets(0), |
|
300 iAllocMemCounter_Bitmaps(0), |
|
301 iFontCapitalAscent(0), |
|
302 iFontMaxAscent(0), |
|
303 iFontStandardDescent(0), |
|
304 iFontMaxDescent(0), |
|
305 iFontLineGap(0) |
|
306 { |
|
307 iFontStoreFileOffset = TInt(aFontStoreFile) - TInt(this); |
|
308 } |
|
309 |
|
310 void CFontBitmap::InternalizeL(RReadStream &aStream, TInt aFontVersion) |
|
311 { |
|
312 aStream >> iUid; |
|
313 iPosture = aStream.ReadInt8L(); |
|
314 iStrokeWeight = aStream.ReadInt8L(); |
|
315 iIsProportional = aStream.ReadInt8L(); |
|
316 iCellHeightInPixels = aStream.ReadInt8L(); |
|
317 iAscentInPixels = aStream.ReadInt8L(); |
|
318 iMaxCharWidthInPixels = aStream.ReadInt8L(); |
|
319 iMaxNormalCharWidthInPixels = aStream.ReadInt8L(); |
|
320 if ( aFontVersion >= KFnttranVersion ) |
|
321 { // read the new metrics in |
|
322 iFontCapitalAscent = aStream.ReadInt8L(); |
|
323 iFontMaxAscent = aStream.ReadInt8L(); |
|
324 iFontStandardDescent = aStream.ReadInt8L(); |
|
325 iFontMaxDescent = aStream.ReadInt8L(); |
|
326 iFontLineGap = aStream.ReadInt8L(); |
|
327 } |
|
328 else // synthesize the extra metrics (data compatibility with third party bitmap fonts for old phones) |
|
329 { |
|
330 iFontMaxAscent = iFontCapitalAscent = iAscentInPixels; |
|
331 iFontMaxDescent = iFontStandardDescent = iCellHeightInPixels - iAscentInPixels; |
|
332 iFontLineGap = ( ( iCellHeightInPixels * 12 ) + 5) / 10; // 1.2 times design height |
|
333 } |
|
334 iBitmapEncoding = aStream.ReadInt32L(); |
|
335 iCharacterMetricsTable.InternalizeL(aStream); |
|
336 const TBool fixup = FontStoreFile()->iFileAddress; |
|
337 if (fixup) |
|
338 { |
|
339 iCharacterMetricsTable.FixUp(FontStoreFile()->iFileAddress); |
|
340 } |
|
341 iNumCodeSections = aStream.ReadInt32L(); |
|
342 TBitmapCodeSection* codesectionlist = (TBitmapCodeSection*)User::LeaveIfNull(iHeap->AllocL(iNumCodeSections * sizeof(TBitmapCodeSection))); |
|
343 iCodeSectionListOffset = TInt(codesectionlist) - TInt(this); |
|
344 for (TInt i = 0; i < iNumCodeSections; i++) |
|
345 { |
|
346 new(codesectionlist + i) TBitmapCodeSection; |
|
347 codesectionlist[i].InternalizeL(aStream); |
|
348 if (fixup) |
|
349 codesectionlist[i].FixUpComponents(FontStoreFile()->iFileAddress); |
|
350 } |
|
351 } |
|
352 |
|
353 void CFontBitmap::UseL() |
|
354 { |
|
355 // Note object is created with a Usage Count of 1. |
|
356 // So incrementing to 2 normally indicates the first external reference. |
|
357 iUsageCount++; |
|
358 if (iUsageCount == 2) |
|
359 { |
|
360 RestoreComponentsL(); |
|
361 } |
|
362 } |
|
363 |
|
364 void CFontBitmap::Release() |
|
365 { |
|
366 iUsageCount--; |
|
367 if (!iUsageCount) |
|
368 { // object and all its users have closed |
|
369 delete this; |
|
370 } |
|
371 } |
|
372 |
|
373 /* |
|
374 Get the metrics for a given character. |
|
375 Return aBytes as null if the character aCode doesn't exist in the font. |
|
376 */ |
|
377 TBitmapFontCharacterMetrics CFontBitmap::CharacterMetrics(TInt aCode, const TUint8*& aBytes) const |
|
378 { |
|
379 const TBitmapCodeSection* matchSection = NULL; |
|
380 const TBitmapCodeSection* const lastSection = CodeSectionList() + iNumCodeSections - 1; |
|
381 |
|
382 TBitmapFontCharacterOffset offset; |
|
383 aBytes = NULL; |
|
384 |
|
385 TBitmapFontCharacterMetrics metrics; |
|
386 const TBitmapCodeSection* startSearchBand = CodeSectionList(); |
|
387 TInt numCodeSectionsRemaining = iNumCodeSections; |
|
388 while (numCodeSectionsRemaining >= 1) |
|
389 { |
|
390 TInt halfNumCodeSectionsRemaining = numCodeSectionsRemaining/2; |
|
391 const TBitmapCodeSection* centralSearchBand = startSearchBand+halfNumCodeSectionsRemaining; |
|
392 if ((aCode >= centralSearchBand->iStart) && (aCode <= centralSearchBand->iEnd)) |
|
393 { |
|
394 matchSection = centralSearchBand; |
|
395 break; |
|
396 } |
|
397 else if ((aCode < centralSearchBand->iStart) || (centralSearchBand == lastSection)) |
|
398 numCodeSectionsRemaining = halfNumCodeSectionsRemaining; |
|
399 else |
|
400 { |
|
401 startSearchBand = centralSearchBand + 1; |
|
402 numCodeSectionsRemaining -= halfNumCodeSectionsRemaining + 1; |
|
403 } |
|
404 } |
|
405 |
|
406 if (matchSection) |
|
407 { |
|
408 offset =* ((matchSection->CharacterOffsetsList(iIsInRAM)) + (aCode-matchSection->iStart)); |
|
409 |
|
410 // Fill characters within code section. |
|
411 // Recursive call ensures that a valid metric is always returned. |
|
412 if (offset.iBitmapOffset == KFillCharacterOffset) |
|
413 { |
|
414 return CharacterMetrics(KReplacementCharacter, aBytes); |
|
415 } |
|
416 |
|
417 aBytes = matchSection->Bitmap(iIsInRAM) + offset.iBitmapOffset; |
|
418 |
|
419 // retrieve metric index from encoded 1 or 2 bytes |
|
420 TInt index = 0; |
|
421 TUint8 byte1 = (TUint8)*aBytes; |
|
422 const TInt switchMask = 0x1; |
|
423 const TBool oneByteIndex =! (byte1 & switchMask); |
|
424 byte1 = TUint8(byte1 >> 1); |
|
425 if (oneByteIndex) |
|
426 { |
|
427 index = byte1; |
|
428 aBytes += 1; |
|
429 } |
|
430 else |
|
431 { |
|
432 const TUint8 byte2 = (TUint8)(*(aBytes + 1)); |
|
433 index = byte1 + (byte2 * 128); |
|
434 aBytes += 2; |
|
435 } |
|
436 // Copy metric from table |
|
437 metrics =* iCharacterMetricsTable.Metric(index); |
|
438 } |
|
439 return metrics; |
|
440 } |
|
441 |
|
442 void CFontBitmap::operator delete(TAny *aThis) |
|
443 { |
|
444 if (((CFontBitmap *)aThis)->iHeap) |
|
445 { |
|
446 ((CFontBitmap *)aThis)->iHeap->Free(aThis); |
|
447 } |
|
448 } |
|
449 |
|
450 void CFontBitmap::SetPosture(TFontPosture aPosture) |
|
451 { |
|
452 iPosture = (TInt8)aPosture; |
|
453 } |
|
454 |
|
455 TFontPosture CFontBitmap::Posture() const |
|
456 { |
|
457 return (TFontPosture)iPosture; // iPosture is always smaller than TFontPosture |
|
458 } |
|
459 |
|
460 void CFontBitmap::SetStrokeWeight(TFontStrokeWeight aStrokeWeight) |
|
461 { |
|
462 iStrokeWeight = (TInt8)aStrokeWeight; |
|
463 } |
|
464 |
|
465 TFontStrokeWeight CFontBitmap::StrokeWeight() const |
|
466 { |
|
467 return (TFontStrokeWeight)iStrokeWeight; |
|
468 } |
|
469 |
|
470 void CFontBitmap::SetIsProportional(TBool aIsProportional) |
|
471 { |
|
472 iIsProportional = (TInt8)aIsProportional; |
|
473 } |
|
474 |
|
475 TBool CFontBitmap::IsProportional() const |
|
476 { |
|
477 return iIsProportional; |
|
478 } |
|
479 |
|
480 CFontStoreFile* CFontBitmap::FontStoreFile() const |
|
481 { |
|
482 TInt fsf = TInt(this) + iFontStoreFileOffset; |
|
483 return (CFontStoreFile*)fsf; |
|
484 } |
|
485 |
|
486 CFontBitmap::~CFontBitmap() |
|
487 { |
|
488 DeleteComponents(); |
|
489 TBitmapCodeSection* codeSectionList = CodeSectionList(); |
|
490 if(TUint32(this) != TUint32(codeSectionList)) |
|
491 { |
|
492 iHeap->Free(codeSectionList); |
|
493 } |
|
494 iCodeSectionListOffset = 0; |
|
495 } |
|
496 |
|
497 //We have to count how many offsets and bitmaps are allocated successfully because if |
|
498 //some of codesection's Internalize..L fails we have to deallocate the right amount of |
|
499 //data. |
|
500 void CFontBitmap::RestoreComponentsL() |
|
501 { |
|
502 if (iIsInRAM) |
|
503 { |
|
504 if(!iComponentsRestored) |
|
505 { |
|
506 iAllocMemCounter_Offsets = 0; |
|
507 iAllocMemCounter_Bitmaps = 0; |
|
508 CStreamStore& store =* FontStoreFile()->iFileStore; |
|
509 for (TInt i = 0; i < iNumCodeSections; i++) |
|
510 { |
|
511 CodeSectionList()[i].InternalizeOffsetsL(store, iHeap, iAllocMemCounter_Offsets); |
|
512 CodeSectionList()[i].InternalizeBitmapL(store, iHeap, iAllocMemCounter_Bitmaps); |
|
513 } |
|
514 iCharacterMetricsTable.RestoreL(store); |
|
515 } |
|
516 iComponentsRestored = ETrue; |
|
517 } |
|
518 } |
|
519 |
|
520 void CFontBitmap::DeleteComponents() |
|
521 { |
|
522 if (iIsInRAM) |
|
523 { |
|
524 TInt i; |
|
525 for (i = 0; i < iAllocMemCounter_Offsets; i++) |
|
526 { |
|
527 CodeSectionList()[i].DeleteOffsets(iHeap); |
|
528 } |
|
529 for (i = 0; i < iAllocMemCounter_Bitmaps; i++) |
|
530 { |
|
531 CodeSectionList()[i].DeleteBitmap(iHeap); |
|
532 } |
|
533 iCharacterMetricsTable.Delete(); |
|
534 } |
|
535 iAllocMemCounter_Offsets = 0; |
|
536 iAllocMemCounter_Bitmaps = 0; |
|
537 iComponentsRestored = EFalse; |
|
538 } |
|
539 |
|
540 TBitmapCodeSection* CFontBitmap::CodeSectionList() const |
|
541 { |
|
542 TInt bcs = TInt(this) + iCodeSectionListOffset; |
|
543 return (TBitmapCodeSection*)bcs; |
|
544 } |
|
545 |
|
546 TTypefaceFontBitmap::TTypefaceFontBitmap() |
|
547 : iTypeface(NULL), |
|
548 iFontBitmap(NULL), |
|
549 iHeightFactor(1), |
|
550 iWidthFactor(1) |
|
551 { |
|
552 } |
|
553 |
|
554 TTypefaceFontBitmap::TTypefaceFontBitmap(TTypeface* aTypeface,CFontBitmap* aFontBitmap) |
|
555 : iTypeface(aTypeface), |
|
556 iFontBitmap(aFontBitmap), |
|
557 iHeightFactor(1), |
|
558 iWidthFactor(1) |
|
559 { |
|
560 } |
|
561 |
|
562 TInt TTypefaceFontBitmap::HeightInPixels() const |
|
563 { |
|
564 return iFontBitmap->iCellHeightInPixels * iHeightFactor; |
|
565 } |