32
|
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 |
iMetricsOnHeap(EFalse)
|
|
222 |
{}
|
|
223 |
|
|
224 |
void TCharacterMetricsTable::InternalizeL(RReadStream& aStream)
|
|
225 |
{
|
|
226 |
iMetricsStartId = aStream.ReadInt32L();
|
|
227 |
iNumberOfMetrics = aStream.ReadInt32L();
|
|
228 |
}
|
|
229 |
|
|
230 |
void TCharacterMetricsTable::InternalizeMetricsL(RReadStream& aStream)
|
|
231 |
{
|
|
232 |
aStream.ReadInt32L(); // size
|
|
233 |
TBitmapFontCharacterMetrics* charactermetricslist = static_cast<TBitmapFontCharacterMetrics*>(iHeap->AllocL(sizeof(TBitmapFontCharacterMetrics) * iNumberOfMetrics));
|
|
234 |
iMetricsOnHeap = ETrue;
|
|
235 |
// Offset from this to location on the heap ('cos the file is not in ROM)
|
|
236 |
iCharacterMetricsStartPtr = reinterpret_cast<TInt>(charactermetricslist) - reinterpret_cast<TInt>(this);
|
|
237 |
TBitmapFontCharacterMetrics* pEnd = charactermetricslist + iNumberOfMetrics;
|
|
238 |
for (TBitmapFontCharacterMetrics* p = charactermetricslist; p < pEnd; p++)
|
|
239 |
{
|
|
240 |
p->InternalizeL(aStream);
|
|
241 |
}
|
|
242 |
}
|
|
243 |
|
|
244 |
void TCharacterMetricsTable::RestoreL(const CStreamStore& aStreamStore)
|
|
245 |
{
|
|
246 |
if (iCharacterMetricsStartPtr == 0)
|
|
247 |
{ // We haven't already read it in from RAM file
|
|
248 |
RStoreReadStream stream;
|
|
249 |
stream.OpenLC(aStreamStore, iMetricsStartId);
|
|
250 |
InternalizeMetricsL(stream);
|
|
251 |
CleanupStack::PopAndDestroy();
|
|
252 |
}
|
|
253 |
}
|
|
254 |
|
|
255 |
void TCharacterMetricsTable::FixUp(TInt aFileAddress)
|
|
256 |
{
|
|
257 |
TBitmapFontCharacterMetrics* charactermetricslist = reinterpret_cast<TBitmapFontCharacterMetrics*>(aFileAddress + sizeof(TInt) + iMetricsStartId.Value());
|
|
258 |
iCharacterMetricsStartPtr = TInt(charactermetricslist); // Ptr to location in a ROM file
|
|
259 |
iMetricsStartId = KNullStreamId;
|
|
260 |
iMetricsOnHeap = EFalse;
|
|
261 |
}
|
|
262 |
|
|
263 |
void TCharacterMetricsTable::Delete()
|
|
264 |
{ // This routine is only called if the font file is in RAM, not ROM, and therefore the metrics have been stashed on the heap
|
|
265 |
if (iMetricsOnHeap && iCharacterMetricsStartPtr)
|
|
266 |
{
|
|
267 |
iHeap->Free(reinterpret_cast<TAny*>(MetricsFromOffset(0)));
|
|
268 |
iCharacterMetricsStartPtr = 0;
|
|
269 |
iMetricsOnHeap = EFalse;
|
|
270 |
}
|
|
271 |
}
|
|
272 |
|
|
273 |
const TBitmapFontCharacterMetrics* TCharacterMetricsTable::Metric(TInt aIndex) const
|
|
274 |
{
|
|
275 |
__ASSERT_DEBUG((aIndex >= 0) && (aIndex <= iNumberOfMetrics), Panic(EFntMetricsIndexOutOfBounds));
|
|
276 |
// Sometimes the start ptr is to a metrics heap item and sometimes it points into a ROM file
|
|
277 |
if (iMetricsOnHeap)
|
|
278 |
{
|
|
279 |
// Start ptr is to metrics heap item
|
|
280 |
return MetricsFromOffset(aIndex);
|
|
281 |
}
|
|
282 |
else
|
|
283 |
{
|
|
284 |
// Start ptr is to a file in ROM
|
|
285 |
return reinterpret_cast<const TBitmapFontCharacterMetrics*> (iCharacterMetricsStartPtr + (aIndex * sizeof(TBitmapFontCharacterMetrics)));
|
|
286 |
}
|
|
287 |
}
|
|
288 |
|
|
289 |
TInt TCharacterMetricsTable::NumberOfMetrics() const
|
|
290 |
{
|
|
291 |
return iNumberOfMetrics;
|
|
292 |
}
|
|
293 |
|
|
294 |
TBitmapFontCharacterMetrics* TCharacterMetricsTable::MetricsFromOffset(TInt aIndex) const
|
|
295 |
{
|
|
296 |
__ASSERT_DEBUG(iMetricsOnHeap,Panic(EFntMetricsNotOnHeap));
|
|
297 |
return reinterpret_cast<TBitmapFontCharacterMetrics*>(reinterpret_cast<TInt>(this) + iCharacterMetricsStartPtr+ (aIndex * sizeof(TBitmapFontCharacterMetrics)));
|
|
298 |
}
|
|
299 |
|
|
300 |
CFontBitmap::CFontBitmap(RHeap* aHeap, CFontStoreFile* aFontStoreFile)
|
|
301 |
: iHeap(aHeap),
|
|
302 |
iFontStoreFileOffset(0),
|
|
303 |
iUid(KNullUid),
|
|
304 |
iPosture(0),
|
|
305 |
iStrokeWeight(0),
|
|
306 |
iIsProportional(0),
|
|
307 |
iIsInRAM(!aFontStoreFile->iFileAddress),
|
|
308 |
iUsageCount(1),
|
|
309 |
iCellHeightInPixels(0),
|
|
310 |
iAscentInPixels(0),
|
|
311 |
iMaxCharWidthInPixels(0),
|
|
312 |
iMaxNormalCharWidthInPixels(0),
|
|
313 |
iBitmapEncoding(0),
|
|
314 |
iNumCodeSections(0),
|
|
315 |
iCodeSectionListOffset(0),
|
|
316 |
iCharacterMetricsTable(aHeap),
|
|
317 |
iComponentsRestored(EFalse),
|
|
318 |
iAllocMemCounter_Offsets(0),
|
|
319 |
iAllocMemCounter_Bitmaps(0),
|
|
320 |
iFontCapitalAscent(0),
|
|
321 |
iFontMaxAscent(0),
|
|
322 |
iFontStandardDescent(0),
|
|
323 |
iFontMaxDescent(0),
|
|
324 |
iFontLineGap(0)
|
|
325 |
{
|
|
326 |
iFontStoreFileOffset = TInt(aFontStoreFile) - TInt(this);
|
|
327 |
}
|
|
328 |
|
|
329 |
void CFontBitmap::InternalizeL(RReadStream &aStream, TInt aFontVersion)
|
|
330 |
{
|
|
331 |
aStream >> iUid;
|
|
332 |
iPosture = aStream.ReadInt8L();
|
|
333 |
iStrokeWeight = aStream.ReadInt8L();
|
|
334 |
iIsProportional = aStream.ReadInt8L();
|
|
335 |
iCellHeightInPixels = aStream.ReadInt8L();
|
|
336 |
iAscentInPixels = aStream.ReadInt8L();
|
|
337 |
iMaxCharWidthInPixels = aStream.ReadInt8L();
|
|
338 |
iMaxNormalCharWidthInPixels = aStream.ReadInt8L();
|
|
339 |
if ( aFontVersion >= KFnttranVersion )
|
|
340 |
{ // read the new metrics in
|
|
341 |
iFontCapitalAscent = aStream.ReadInt8L();
|
|
342 |
iFontMaxAscent = aStream.ReadInt8L();
|
|
343 |
iFontStandardDescent = aStream.ReadInt8L();
|
|
344 |
iFontMaxDescent = aStream.ReadInt8L();
|
|
345 |
iFontLineGap = aStream.ReadInt8L();
|
|
346 |
}
|
|
347 |
else // synthesize the extra metrics (data compatibility with third party bitmap fonts for old phones)
|
|
348 |
{
|
|
349 |
iFontMaxAscent = iFontCapitalAscent = iAscentInPixels;
|
|
350 |
iFontMaxDescent = iFontStandardDescent = iCellHeightInPixels - iAscentInPixels;
|
|
351 |
iFontLineGap = ( ( iCellHeightInPixels * 12 ) + 5) / 10; // 1.2 times design height
|
|
352 |
}
|
|
353 |
iBitmapEncoding = aStream.ReadInt32L();
|
|
354 |
iCharacterMetricsTable.InternalizeL(aStream);
|
|
355 |
const TBool fixup = FontStoreFile()->iFileAddress;
|
|
356 |
if (fixup)
|
|
357 |
{
|
|
358 |
iCharacterMetricsTable.FixUp(FontStoreFile()->iFileAddress);
|
|
359 |
}
|
|
360 |
iNumCodeSections = aStream.ReadInt32L();
|
|
361 |
TBitmapCodeSection* codesectionlist = (TBitmapCodeSection*)User::LeaveIfNull(iHeap->AllocL(iNumCodeSections * sizeof(TBitmapCodeSection)));
|
|
362 |
iCodeSectionListOffset = TInt(codesectionlist) - TInt(this);
|
|
363 |
for (TInt i = 0; i < iNumCodeSections; i++)
|
|
364 |
{
|
|
365 |
new(codesectionlist + i) TBitmapCodeSection;
|
|
366 |
codesectionlist[i].InternalizeL(aStream);
|
|
367 |
if (fixup)
|
|
368 |
codesectionlist[i].FixUpComponents(FontStoreFile()->iFileAddress);
|
|
369 |
}
|
|
370 |
}
|
|
371 |
|
|
372 |
void CFontBitmap::UseL()
|
|
373 |
{
|
|
374 |
// Note object is created with a Usage Count of 1.
|
|
375 |
// So incrementing to 2 normally indicates the first external reference.
|
|
376 |
iUsageCount++;
|
|
377 |
if (iUsageCount == 2)
|
|
378 |
{
|
|
379 |
RestoreComponentsL();
|
|
380 |
}
|
|
381 |
}
|
|
382 |
|
|
383 |
void CFontBitmap::Release()
|
|
384 |
{
|
|
385 |
iUsageCount--;
|
|
386 |
if (!iUsageCount)
|
|
387 |
{ // object and all its users have closed
|
|
388 |
delete this;
|
|
389 |
}
|
|
390 |
}
|
|
391 |
|
|
392 |
/*
|
|
393 |
Get the metrics for a given character.
|
|
394 |
Return aBytes as null if the character aCode doesn't exist in the font.
|
|
395 |
*/
|
|
396 |
TBitmapFontCharacterMetrics CFontBitmap::CharacterMetrics(TInt aCode, const TUint8*& aBytes) const
|
|
397 |
{
|
|
398 |
const TBitmapCodeSection* matchSection = NULL;
|
|
399 |
const TBitmapCodeSection* const lastSection = CodeSectionList() + iNumCodeSections - 1;
|
|
400 |
|
|
401 |
TBitmapFontCharacterOffset offset;
|
|
402 |
aBytes = NULL;
|
|
403 |
|
|
404 |
TBitmapFontCharacterMetrics metrics;
|
|
405 |
const TBitmapCodeSection* startSearchBand = CodeSectionList();
|
|
406 |
TInt numCodeSectionsRemaining = iNumCodeSections;
|
|
407 |
while (numCodeSectionsRemaining >= 1)
|
|
408 |
{
|
|
409 |
TInt halfNumCodeSectionsRemaining = numCodeSectionsRemaining/2;
|
|
410 |
const TBitmapCodeSection* centralSearchBand = startSearchBand+halfNumCodeSectionsRemaining;
|
|
411 |
if ((aCode >= centralSearchBand->iStart) && (aCode <= centralSearchBand->iEnd))
|
|
412 |
{
|
|
413 |
matchSection = centralSearchBand;
|
|
414 |
break;
|
|
415 |
}
|
|
416 |
else if ((aCode < centralSearchBand->iStart) || (centralSearchBand == lastSection))
|
|
417 |
numCodeSectionsRemaining = halfNumCodeSectionsRemaining;
|
|
418 |
else
|
|
419 |
{
|
|
420 |
startSearchBand = centralSearchBand + 1;
|
|
421 |
numCodeSectionsRemaining -= halfNumCodeSectionsRemaining + 1;
|
|
422 |
}
|
|
423 |
}
|
|
424 |
|
|
425 |
if (matchSection)
|
|
426 |
{
|
|
427 |
offset =* ((matchSection->CharacterOffsetsList(iIsInRAM)) + (aCode-matchSection->iStart));
|
|
428 |
|
|
429 |
// Fill characters within code section.
|
|
430 |
// Recursive call ensures that a valid metric is always returned.
|
|
431 |
if (offset.iBitmapOffset == KFillCharacterOffset)
|
|
432 |
{
|
|
433 |
return CharacterMetrics(KReplacementCharacter, aBytes);
|
|
434 |
}
|
|
435 |
|
|
436 |
aBytes = matchSection->Bitmap(iIsInRAM) + offset.iBitmapOffset;
|
|
437 |
|
|
438 |
// retrieve metric index from encoded 1 or 2 bytes
|
|
439 |
TInt index = 0;
|
|
440 |
TUint8 byte1 = (TUint8)*aBytes;
|
|
441 |
const TInt switchMask = 0x1;
|
|
442 |
const TBool oneByteIndex =! (byte1 & switchMask);
|
|
443 |
byte1 = TUint8(byte1 >> 1);
|
|
444 |
if (oneByteIndex)
|
|
445 |
{
|
|
446 |
index = byte1;
|
|
447 |
aBytes += 1;
|
|
448 |
}
|
|
449 |
else
|
|
450 |
{
|
|
451 |
const TUint8 byte2 = (TUint8)(*(aBytes + 1));
|
|
452 |
index = byte1 + (byte2 * 128);
|
|
453 |
aBytes += 2;
|
|
454 |
}
|
|
455 |
// Copy metric from table
|
|
456 |
metrics =* iCharacterMetricsTable.Metric(index);
|
|
457 |
}
|
|
458 |
return metrics;
|
|
459 |
}
|
|
460 |
|
|
461 |
void CFontBitmap::operator delete(TAny *aThis)
|
|
462 |
{
|
|
463 |
if (((CFontBitmap *)aThis)->iHeap)
|
|
464 |
{
|
|
465 |
((CFontBitmap *)aThis)->iHeap->Free(aThis);
|
|
466 |
}
|
|
467 |
}
|
|
468 |
|
|
469 |
void CFontBitmap::SetPosture(TFontPosture aPosture)
|
|
470 |
{
|
|
471 |
iPosture = (TInt8)aPosture;
|
|
472 |
}
|
|
473 |
|
|
474 |
TFontPosture CFontBitmap::Posture() const
|
|
475 |
{
|
|
476 |
return (TFontPosture)iPosture; // iPosture is always smaller than TFontPosture
|
|
477 |
}
|
|
478 |
|
|
479 |
void CFontBitmap::SetStrokeWeight(TFontStrokeWeight aStrokeWeight)
|
|
480 |
{
|
|
481 |
iStrokeWeight = (TInt8)aStrokeWeight;
|
|
482 |
}
|
|
483 |
|
|
484 |
TFontStrokeWeight CFontBitmap::StrokeWeight() const
|
|
485 |
{
|
|
486 |
return (TFontStrokeWeight)iStrokeWeight;
|
|
487 |
}
|
|
488 |
|
|
489 |
void CFontBitmap::SetIsProportional(TBool aIsProportional)
|
|
490 |
{
|
|
491 |
iIsProportional = (TInt8)aIsProportional;
|
|
492 |
}
|
|
493 |
|
|
494 |
TBool CFontBitmap::IsProportional() const
|
|
495 |
{
|
|
496 |
return iIsProportional;
|
|
497 |
}
|
|
498 |
|
|
499 |
CFontStoreFile* CFontBitmap::FontStoreFile() const
|
|
500 |
{
|
|
501 |
TInt fsf = TInt(this) + iFontStoreFileOffset;
|
|
502 |
return (CFontStoreFile*)fsf;
|
|
503 |
}
|
|
504 |
|
|
505 |
CFontBitmap::~CFontBitmap()
|
|
506 |
{
|
|
507 |
DeleteComponents();
|
|
508 |
TBitmapCodeSection* codeSectionList = CodeSectionList();
|
|
509 |
if(TUint32(this) != TUint32(codeSectionList))
|
|
510 |
{
|
|
511 |
iHeap->Free(codeSectionList);
|
|
512 |
}
|
|
513 |
iCodeSectionListOffset = 0;
|
|
514 |
}
|
|
515 |
|
|
516 |
//We have to count how many offsets and bitmaps are allocated successfully because if
|
|
517 |
//some of codesection's Internalize..L fails we have to deallocate the right amount of
|
|
518 |
//data.
|
|
519 |
void CFontBitmap::RestoreComponentsL()
|
|
520 |
{
|
|
521 |
if (iIsInRAM)
|
|
522 |
{
|
|
523 |
if(!iComponentsRestored)
|
|
524 |
{
|
|
525 |
iAllocMemCounter_Offsets = 0;
|
|
526 |
iAllocMemCounter_Bitmaps = 0;
|
|
527 |
CStreamStore& store =* FontStoreFile()->iFileStore;
|
|
528 |
for (TInt i = 0; i < iNumCodeSections; i++)
|
|
529 |
{
|
|
530 |
CodeSectionList()[i].InternalizeOffsetsL(store, iHeap, iAllocMemCounter_Offsets);
|
|
531 |
CodeSectionList()[i].InternalizeBitmapL(store, iHeap, iAllocMemCounter_Bitmaps);
|
|
532 |
}
|
|
533 |
iCharacterMetricsTable.RestoreL(store);
|
|
534 |
}
|
|
535 |
iComponentsRestored = ETrue;
|
|
536 |
}
|
|
537 |
}
|
|
538 |
|
|
539 |
void CFontBitmap::DeleteComponents()
|
|
540 |
{
|
|
541 |
if (iIsInRAM)
|
|
542 |
{
|
|
543 |
TInt i;
|
|
544 |
for (i = 0; i < iAllocMemCounter_Offsets; i++)
|
|
545 |
{
|
|
546 |
CodeSectionList()[i].DeleteOffsets(iHeap);
|
|
547 |
}
|
|
548 |
for (i = 0; i < iAllocMemCounter_Bitmaps; i++)
|
|
549 |
{
|
|
550 |
CodeSectionList()[i].DeleteBitmap(iHeap);
|
|
551 |
}
|
|
552 |
iCharacterMetricsTable.Delete();
|
|
553 |
}
|
|
554 |
iAllocMemCounter_Offsets = 0;
|
|
555 |
iAllocMemCounter_Bitmaps = 0;
|
|
556 |
iComponentsRestored = EFalse;
|
|
557 |
}
|
|
558 |
|
|
559 |
TBitmapCodeSection* CFontBitmap::CodeSectionList() const
|
|
560 |
{
|
|
561 |
TInt bcs = TInt(this) + iCodeSectionListOffset;
|
|
562 |
return (TBitmapCodeSection*)bcs;
|
|
563 |
}
|
|
564 |
|
|
565 |
TTypefaceFontBitmap::TTypefaceFontBitmap()
|
|
566 |
: iTypeface(NULL),
|
|
567 |
iFontBitmap(NULL),
|
|
568 |
iHeightFactor(1),
|
|
569 |
iWidthFactor(1)
|
|
570 |
{
|
|
571 |
}
|
|
572 |
|
|
573 |
TTypefaceFontBitmap::TTypefaceFontBitmap(TTypeface* aTypeface,CFontBitmap* aFontBitmap)
|
|
574 |
: iTypeface(aTypeface),
|
|
575 |
iFontBitmap(aFontBitmap),
|
|
576 |
iHeightFactor(1),
|
|
577 |
iWidthFactor(1)
|
|
578 |
{
|
|
579 |
}
|
|
580 |
|
|
581 |
TInt TTypefaceFontBitmap::HeightInPixels() const
|
|
582 |
{
|
|
583 |
return iFontBitmap->iCellHeightInPixels * iHeightFactor;
|
|
584 |
}
|