sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <s32file.h>
|
sl@0
|
20 |
#include "FNTSTORE.H"
|
sl@0
|
21 |
#include "FNTBODY_OLD.H"
|
sl@0
|
22 |
#include <graphics/openfontconstants.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
TBitmapCodeSectionOld::TBitmapCodeSectionOld(RHeap* aHeap)
|
sl@0
|
25 |
: TCodeSection(),
|
sl@0
|
26 |
iHeap(aHeap),
|
sl@0
|
27 |
iOffsetsId(),
|
sl@0
|
28 |
iCharacterOffsetsListOffset(0),
|
sl@0
|
29 |
iBitmapId(),
|
sl@0
|
30 |
iBitmapOffset(0)
|
sl@0
|
31 |
{
|
sl@0
|
32 |
}
|
sl@0
|
33 |
|
sl@0
|
34 |
void TBitmapCodeSectionOld::InternalizeL(RReadStream &aStream)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
iStart = aStream.ReadUint16L();
|
sl@0
|
37 |
iEnd = aStream.ReadUint16L();
|
sl@0
|
38 |
aStream >> iOffsetsId;
|
sl@0
|
39 |
aStream >> iBitmapId;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
|
sl@0
|
42 |
void TBitmapCodeSectionOld::RestoreComponentsL(const CStreamStore& aStreamStore)
|
sl@0
|
43 |
{
|
sl@0
|
44 |
if (iCharacterOffsetsListOffset == 0)
|
sl@0
|
45 |
{
|
sl@0
|
46 |
RStoreReadStream stream;
|
sl@0
|
47 |
stream.OpenLC(aStreamStore, iOffsetsId);
|
sl@0
|
48 |
InternalizeOffsetsL(stream);
|
sl@0
|
49 |
CleanupStack::PopAndDestroy();
|
sl@0
|
50 |
}
|
sl@0
|
51 |
if (iBitmapOffset == 0)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
RStoreReadStream stream;
|
sl@0
|
54 |
stream.OpenLC(aStreamStore, iBitmapId);
|
sl@0
|
55 |
InternalizeBitmapL(stream);
|
sl@0
|
56 |
CleanupStack::PopAndDestroy();
|
sl@0
|
57 |
}
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
void TBitmapCodeSectionOld::FixUpComponents(TInt aFileAddress)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
TBitmapFontCharacterOffset* characterOffsetsList = (TBitmapFontCharacterOffset*) (aFileAddress + sizeof(TInt) + iOffsetsId.Value());
|
sl@0
|
63 |
iCharacterOffsetsListOffset = TInt(characterOffsetsList);
|
sl@0
|
64 |
iOffsetsId = KNullStreamId;
|
sl@0
|
65 |
TUint8* bitmap = (TUint8*) (aFileAddress + sizeof(TInt) + iBitmapId.Value());
|
sl@0
|
66 |
iBitmapOffset = TInt(bitmap);
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
void TBitmapCodeSectionOld::DeleteComponents()
|
sl@0
|
70 |
{
|
sl@0
|
71 |
if (iCharacterOffsetsListOffset)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
iHeap->Free(CharacterOffsetsList());
|
sl@0
|
74 |
iCharacterOffsetsListOffset = 0;
|
sl@0
|
75 |
}
|
sl@0
|
76 |
if (iBitmapOffset)
|
sl@0
|
77 |
{
|
sl@0
|
78 |
iHeap->Free(Bitmap());
|
sl@0
|
79 |
iBitmapOffset = 0;
|
sl@0
|
80 |
}
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
void TBitmapCodeSectionOld::operator delete(TAny *aThis)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
if (((TBitmapCodeSectionOld *)aThis)->iHeap)
|
sl@0
|
86 |
{
|
sl@0
|
87 |
((TBitmapCodeSectionOld *)aThis)->iHeap->Free(aThis);
|
sl@0
|
88 |
}
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
void TBitmapCodeSectionOld::InternalizeOffsetsL(RReadStream &aStream)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
TInt size = aStream.ReadInt32L();
|
sl@0
|
94 |
TBitmapFontCharacterOffset* characterOffsetsList = (TBitmapFontCharacterOffset*)iHeap->AllocL(sizeof(TBitmapFontCharacterOffset) * size);
|
sl@0
|
95 |
iCharacterOffsetsListOffset = TInt(characterOffsetsList) - TInt(this);
|
sl@0
|
96 |
TBitmapFontCharacterOffset* pEnd = characterOffsetsList + size;
|
sl@0
|
97 |
for (TBitmapFontCharacterOffset* p = characterOffsetsList; p < pEnd; p++)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
p->InternalizeL(aStream);
|
sl@0
|
100 |
}
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
void TBitmapCodeSectionOld::InternalizeBitmapL(RReadStream &aStream)
|
sl@0
|
104 |
{
|
sl@0
|
105 |
TInt size = aStream.ReadInt32L();
|
sl@0
|
106 |
TUint8* bitmap = (TUint8*)iHeap->AllocL(size);
|
sl@0
|
107 |
iBitmapOffset = TInt(bitmap) - TInt(this);
|
sl@0
|
108 |
aStream.ReadL(bitmap, size);
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
TBitmapFontCharacterOffset* TBitmapCodeSectionOld::CharacterOffsetsList() const
|
sl@0
|
112 |
{
|
sl@0
|
113 |
if (iOffsetsId == KNullStreamId)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
return (TBitmapFontCharacterOffset*)iCharacterOffsetsListOffset;
|
sl@0
|
116 |
}
|
sl@0
|
117 |
TInt charOffsList = TInt(this) + iCharacterOffsetsListOffset;
|
sl@0
|
118 |
return (TBitmapFontCharacterOffset*)charOffsList;
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
TUint8* TBitmapCodeSectionOld::Bitmap() const
|
sl@0
|
122 |
{
|
sl@0
|
123 |
if (iOffsetsId == KNullStreamId)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
return (TUint8*)iBitmapOffset;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
TInt bitmap = TInt(this)+iBitmapOffset;
|
sl@0
|
128 |
return (TUint8*)bitmap;
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
CFontBitmapOld::CFontBitmapOld(RHeap* aHeap, CFontStoreFile* aFontStoreFile)
|
sl@0
|
132 |
: iHeap(aHeap),
|
sl@0
|
133 |
iFontStoreFileOffset(0),
|
sl@0
|
134 |
iUid(KNullUid),
|
sl@0
|
135 |
iPosture(0),
|
sl@0
|
136 |
iStrokeWeight(0),
|
sl@0
|
137 |
iIsProportional(0),
|
sl@0
|
138 |
iIsInRAM(!aFontStoreFile->iFileAddress),
|
sl@0
|
139 |
iUsageCount(1),
|
sl@0
|
140 |
iCellHeightInPixels(0),
|
sl@0
|
141 |
iAscentInPixels(0),
|
sl@0
|
142 |
iMaxCharWidthInPixels(0),
|
sl@0
|
143 |
iMaxNormalCharWidthInPixels(0),
|
sl@0
|
144 |
iBitmapEncoding(0),
|
sl@0
|
145 |
iNumCodeSections(0),
|
sl@0
|
146 |
iCodeSectionListOffset(0),
|
sl@0
|
147 |
iCharacterMetricsTable(aHeap)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
iFontStoreFileOffset = TInt(aFontStoreFile) - TInt(this);
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
void CFontBitmapOld::InternalizeL(RReadStream &aStream)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
aStream >> iUid;
|
sl@0
|
155 |
iPosture = aStream.ReadInt8L();
|
sl@0
|
156 |
iStrokeWeight = aStream.ReadInt8L();
|
sl@0
|
157 |
iIsProportional = aStream.ReadInt8L();
|
sl@0
|
158 |
iCellHeightInPixels = aStream.ReadInt8L();
|
sl@0
|
159 |
iAscentInPixels = aStream.ReadInt8L();
|
sl@0
|
160 |
iMaxCharWidthInPixels = aStream.ReadInt8L();
|
sl@0
|
161 |
iMaxNormalCharWidthInPixels = aStream.ReadInt8L();
|
sl@0
|
162 |
iBitmapEncoding = aStream.ReadInt32L();
|
sl@0
|
163 |
iCharacterMetricsTable.InternalizeL(aStream);
|
sl@0
|
164 |
const TBool fixup = FontStoreFile()->iFileAddress;
|
sl@0
|
165 |
if (fixup)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
iCharacterMetricsTable.FixUp(FontStoreFile()->iFileAddress);
|
sl@0
|
168 |
}
|
sl@0
|
169 |
iNumCodeSections = aStream.ReadInt32L();
|
sl@0
|
170 |
TBitmapCodeSectionOld* codesectionlist = (TBitmapCodeSectionOld*)User::LeaveIfNull(iHeap->AllocL(iNumCodeSections * sizeof(TBitmapCodeSectionOld)));
|
sl@0
|
171 |
iCodeSectionListOffset = TInt(codesectionlist) - TInt(this);
|
sl@0
|
172 |
for (TInt i = 0; i < iNumCodeSections; i++)
|
sl@0
|
173 |
{
|
sl@0
|
174 |
new(codesectionlist + i) TBitmapCodeSectionOld(iHeap);
|
sl@0
|
175 |
codesectionlist[i].InternalizeL(aStream);
|
sl@0
|
176 |
if (fixup)
|
sl@0
|
177 |
codesectionlist[i].FixUpComponents(FontStoreFile()->iFileAddress);
|
sl@0
|
178 |
}
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
void CFontBitmapOld::UseL()
|
sl@0
|
182 |
{
|
sl@0
|
183 |
iUsageCount++;
|
sl@0
|
184 |
if (iUsageCount == 2)
|
sl@0
|
185 |
RestoreComponentsL();
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
void CFontBitmapOld::Release()
|
sl@0
|
189 |
{
|
sl@0
|
190 |
iUsageCount--;
|
sl@0
|
191 |
if (!iUsageCount)
|
sl@0
|
192 |
{
|
sl@0
|
193 |
delete this;
|
sl@0
|
194 |
}
|
sl@0
|
195 |
}
|
sl@0
|
196 |
|
sl@0
|
197 |
/*
|
sl@0
|
198 |
Get the metrics for a given character.
|
sl@0
|
199 |
Return aBytes as null if the character aCode doesn't exist in the font.
|
sl@0
|
200 |
*/
|
sl@0
|
201 |
TBitmapFontCharacterMetrics CFontBitmapOld::CharacterMetrics(TInt aCode, const TUint8*& aBytes) const
|
sl@0
|
202 |
{
|
sl@0
|
203 |
const TBitmapCodeSectionOld* matchSection = NULL;
|
sl@0
|
204 |
const TBitmapCodeSectionOld* const lastSection = CodeSectionList() + iNumCodeSections - 1;
|
sl@0
|
205 |
|
sl@0
|
206 |
TBitmapFontCharacterOffset offset;
|
sl@0
|
207 |
aBytes = NULL;
|
sl@0
|
208 |
|
sl@0
|
209 |
TBitmapFontCharacterMetrics metrics;
|
sl@0
|
210 |
const TBitmapCodeSectionOld* startSearchBand = CodeSectionList();
|
sl@0
|
211 |
TInt numCodeSectionsRemaining = iNumCodeSections;
|
sl@0
|
212 |
while (numCodeSectionsRemaining >= 1)
|
sl@0
|
213 |
{
|
sl@0
|
214 |
TInt halfNumCodeSectionsRemaining = numCodeSectionsRemaining/2;
|
sl@0
|
215 |
const TBitmapCodeSectionOld* centralSearchBand = startSearchBand+halfNumCodeSectionsRemaining;
|
sl@0
|
216 |
if ((aCode >= centralSearchBand->iStart) && (aCode <= centralSearchBand->iEnd))
|
sl@0
|
217 |
{
|
sl@0
|
218 |
matchSection = centralSearchBand;
|
sl@0
|
219 |
break;
|
sl@0
|
220 |
}
|
sl@0
|
221 |
else if ((aCode < centralSearchBand->iStart) || (centralSearchBand == lastSection))
|
sl@0
|
222 |
numCodeSectionsRemaining = halfNumCodeSectionsRemaining;
|
sl@0
|
223 |
else
|
sl@0
|
224 |
{
|
sl@0
|
225 |
startSearchBand = centralSearchBand + 1;
|
sl@0
|
226 |
numCodeSectionsRemaining -= halfNumCodeSectionsRemaining + 1;
|
sl@0
|
227 |
}
|
sl@0
|
228 |
}
|
sl@0
|
229 |
|
sl@0
|
230 |
if (matchSection)
|
sl@0
|
231 |
{
|
sl@0
|
232 |
offset =* ((matchSection->CharacterOffsetsList()) + (aCode-matchSection->iStart));
|
sl@0
|
233 |
|
sl@0
|
234 |
// Fill characters within code section.
|
sl@0
|
235 |
// Recursive call ensures that a valid metric is always returned.
|
sl@0
|
236 |
if (offset.iBitmapOffset == KFillCharacterOffset)
|
sl@0
|
237 |
{
|
sl@0
|
238 |
return CharacterMetrics(KReplacementCharacter, aBytes);
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
aBytes = matchSection->Bitmap() + offset.iBitmapOffset;
|
sl@0
|
242 |
|
sl@0
|
243 |
// retrieve metric index from encoded 1 or 2 bytes
|
sl@0
|
244 |
TInt index = 0;
|
sl@0
|
245 |
TUint8 byte1 = (TUint8)*aBytes;
|
sl@0
|
246 |
const TInt switchMask = 0x1;
|
sl@0
|
247 |
const TBool oneByteIndex =! (byte1 & switchMask);
|
sl@0
|
248 |
byte1 = TUint8(byte1 >> 1);
|
sl@0
|
249 |
if (oneByteIndex)
|
sl@0
|
250 |
{
|
sl@0
|
251 |
index = byte1;
|
sl@0
|
252 |
aBytes += 1;
|
sl@0
|
253 |
}
|
sl@0
|
254 |
else
|
sl@0
|
255 |
{
|
sl@0
|
256 |
const TUint8 byte2 = (TUint8)(*(aBytes + 1));
|
sl@0
|
257 |
index = byte1 + (byte2 * 128);
|
sl@0
|
258 |
aBytes += 2;
|
sl@0
|
259 |
}
|
sl@0
|
260 |
// Copy metric from table
|
sl@0
|
261 |
metrics =* iCharacterMetricsTable.Metric(index);
|
sl@0
|
262 |
}
|
sl@0
|
263 |
return metrics;
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
void CFontBitmapOld::operator delete(TAny *aThis)
|
sl@0
|
267 |
{
|
sl@0
|
268 |
if (((CFontBitmapOld *)aThis)->iHeap)
|
sl@0
|
269 |
{
|
sl@0
|
270 |
((CFontBitmapOld *)aThis)->iHeap->Free(aThis);
|
sl@0
|
271 |
}
|
sl@0
|
272 |
}
|
sl@0
|
273 |
|
sl@0
|
274 |
void CFontBitmapOld::SetPosture(TFontPosture aPosture)
|
sl@0
|
275 |
{
|
sl@0
|
276 |
iPosture = (TInt8)aPosture;
|
sl@0
|
277 |
}
|
sl@0
|
278 |
|
sl@0
|
279 |
TFontPosture CFontBitmapOld::Posture()
|
sl@0
|
280 |
{
|
sl@0
|
281 |
return (TFontPosture)iPosture; // iPosture is always smaller than TFontPosture
|
sl@0
|
282 |
}
|
sl@0
|
283 |
|
sl@0
|
284 |
void CFontBitmapOld::SetStrokeWeight(TFontStrokeWeight aStrokeWeight)
|
sl@0
|
285 |
{
|
sl@0
|
286 |
iStrokeWeight = (TInt8)aStrokeWeight;
|
sl@0
|
287 |
}
|
sl@0
|
288 |
|
sl@0
|
289 |
TFontStrokeWeight CFontBitmapOld::StrokeWeight()
|
sl@0
|
290 |
{
|
sl@0
|
291 |
return (TFontStrokeWeight)iStrokeWeight;
|
sl@0
|
292 |
}
|
sl@0
|
293 |
|
sl@0
|
294 |
void CFontBitmapOld::SetIsProportional(TBool aIsProportional)
|
sl@0
|
295 |
{
|
sl@0
|
296 |
iIsProportional = (TInt8)aIsProportional;
|
sl@0
|
297 |
}
|
sl@0
|
298 |
|
sl@0
|
299 |
TBool CFontBitmapOld::IsProportional()
|
sl@0
|
300 |
{
|
sl@0
|
301 |
return iIsProportional;
|
sl@0
|
302 |
}
|
sl@0
|
303 |
|
sl@0
|
304 |
CFontStoreFile* CFontBitmapOld::FontStoreFile() const
|
sl@0
|
305 |
{
|
sl@0
|
306 |
TInt fsf = TInt(this) + iFontStoreFileOffset;
|
sl@0
|
307 |
return (CFontStoreFile*)fsf;
|
sl@0
|
308 |
}
|
sl@0
|
309 |
|
sl@0
|
310 |
CFontBitmapOld::~CFontBitmapOld()
|
sl@0
|
311 |
{
|
sl@0
|
312 |
DeleteComponents();
|
sl@0
|
313 |
iHeap->Free(CodeSectionList());
|
sl@0
|
314 |
iCodeSectionListOffset = 0;
|
sl@0
|
315 |
}
|
sl@0
|
316 |
|
sl@0
|
317 |
void CFontBitmapOld::RestoreComponentsL()
|
sl@0
|
318 |
{
|
sl@0
|
319 |
if (iIsInRAM)
|
sl@0
|
320 |
{
|
sl@0
|
321 |
CStreamStore& store =* FontStoreFile()->iFileStore;
|
sl@0
|
322 |
for (TInt i = 0; i < iNumCodeSections; i++)
|
sl@0
|
323 |
{
|
sl@0
|
324 |
CodeSectionList()[i].RestoreComponentsL(store);
|
sl@0
|
325 |
}
|
sl@0
|
326 |
iCharacterMetricsTable.RestoreL(store);
|
sl@0
|
327 |
}
|
sl@0
|
328 |
}
|
sl@0
|
329 |
|
sl@0
|
330 |
void CFontBitmapOld::DeleteComponents()
|
sl@0
|
331 |
{
|
sl@0
|
332 |
if (iIsInRAM)
|
sl@0
|
333 |
{
|
sl@0
|
334 |
for (TInt i = 0; i < iNumCodeSections; i++)
|
sl@0
|
335 |
{
|
sl@0
|
336 |
CodeSectionList()[i].DeleteComponents();
|
sl@0
|
337 |
}
|
sl@0
|
338 |
iCharacterMetricsTable.Delete();
|
sl@0
|
339 |
}
|
sl@0
|
340 |
}
|
sl@0
|
341 |
|
sl@0
|
342 |
TBitmapCodeSectionOld* CFontBitmapOld::CodeSectionList() const
|
sl@0
|
343 |
{
|
sl@0
|
344 |
TInt bcs = TInt(this) + iCodeSectionListOffset;
|
sl@0
|
345 |
return (TBitmapCodeSectionOld*)bcs;
|
sl@0
|
346 |
}
|
sl@0
|
347 |
|