Update contrib.
2 * Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 #include "FNTBODY_OLD.H"
22 #include <graphics/openfontconstants.h>
24 TBitmapCodeSectionOld::TBitmapCodeSectionOld(RHeap* aHeap)
28 iCharacterOffsetsListOffset(0),
34 void TBitmapCodeSectionOld::InternalizeL(RReadStream &aStream)
36 iStart = aStream.ReadUint16L();
37 iEnd = aStream.ReadUint16L();
38 aStream >> iOffsetsId;
42 void TBitmapCodeSectionOld::RestoreComponentsL(const CStreamStore& aStreamStore)
44 if (iCharacterOffsetsListOffset == 0)
46 RStoreReadStream stream;
47 stream.OpenLC(aStreamStore, iOffsetsId);
48 InternalizeOffsetsL(stream);
49 CleanupStack::PopAndDestroy();
51 if (iBitmapOffset == 0)
53 RStoreReadStream stream;
54 stream.OpenLC(aStreamStore, iBitmapId);
55 InternalizeBitmapL(stream);
56 CleanupStack::PopAndDestroy();
60 void TBitmapCodeSectionOld::FixUpComponents(TInt aFileAddress)
62 TBitmapFontCharacterOffset* characterOffsetsList = (TBitmapFontCharacterOffset*) (aFileAddress + sizeof(TInt) + iOffsetsId.Value());
63 iCharacterOffsetsListOffset = TInt(characterOffsetsList);
64 iOffsetsId = KNullStreamId;
65 TUint8* bitmap = (TUint8*) (aFileAddress + sizeof(TInt) + iBitmapId.Value());
66 iBitmapOffset = TInt(bitmap);
69 void TBitmapCodeSectionOld::DeleteComponents()
71 if (iCharacterOffsetsListOffset)
73 iHeap->Free(CharacterOffsetsList());
74 iCharacterOffsetsListOffset = 0;
78 iHeap->Free(Bitmap());
83 void TBitmapCodeSectionOld::operator delete(TAny *aThis)
85 if (((TBitmapCodeSectionOld *)aThis)->iHeap)
87 ((TBitmapCodeSectionOld *)aThis)->iHeap->Free(aThis);
91 void TBitmapCodeSectionOld::InternalizeOffsetsL(RReadStream &aStream)
93 TInt size = aStream.ReadInt32L();
94 TBitmapFontCharacterOffset* characterOffsetsList = (TBitmapFontCharacterOffset*)iHeap->AllocL(sizeof(TBitmapFontCharacterOffset) * size);
95 iCharacterOffsetsListOffset = TInt(characterOffsetsList) - TInt(this);
96 TBitmapFontCharacterOffset* pEnd = characterOffsetsList + size;
97 for (TBitmapFontCharacterOffset* p = characterOffsetsList; p < pEnd; p++)
99 p->InternalizeL(aStream);
103 void TBitmapCodeSectionOld::InternalizeBitmapL(RReadStream &aStream)
105 TInt size = aStream.ReadInt32L();
106 TUint8* bitmap = (TUint8*)iHeap->AllocL(size);
107 iBitmapOffset = TInt(bitmap) - TInt(this);
108 aStream.ReadL(bitmap, size);
111 TBitmapFontCharacterOffset* TBitmapCodeSectionOld::CharacterOffsetsList() const
113 if (iOffsetsId == KNullStreamId)
115 return (TBitmapFontCharacterOffset*)iCharacterOffsetsListOffset;
117 TInt charOffsList = TInt(this) + iCharacterOffsetsListOffset;
118 return (TBitmapFontCharacterOffset*)charOffsList;
121 TUint8* TBitmapCodeSectionOld::Bitmap() const
123 if (iOffsetsId == KNullStreamId)
125 return (TUint8*)iBitmapOffset;
127 TInt bitmap = TInt(this)+iBitmapOffset;
128 return (TUint8*)bitmap;
131 CFontBitmapOld::CFontBitmapOld(RHeap* aHeap, CFontStoreFile* aFontStoreFile)
133 iFontStoreFileOffset(0),
138 iIsInRAM(!aFontStoreFile->iFileAddress),
140 iCellHeightInPixels(0),
142 iMaxCharWidthInPixels(0),
143 iMaxNormalCharWidthInPixels(0),
146 iCodeSectionListOffset(0),
147 iCharacterMetricsTable(aHeap)
149 iFontStoreFileOffset = TInt(aFontStoreFile) - TInt(this);
152 void CFontBitmapOld::InternalizeL(RReadStream &aStream)
155 iPosture = aStream.ReadInt8L();
156 iStrokeWeight = aStream.ReadInt8L();
157 iIsProportional = aStream.ReadInt8L();
158 iCellHeightInPixels = aStream.ReadInt8L();
159 iAscentInPixels = aStream.ReadInt8L();
160 iMaxCharWidthInPixels = aStream.ReadInt8L();
161 iMaxNormalCharWidthInPixels = aStream.ReadInt8L();
162 iBitmapEncoding = aStream.ReadInt32L();
163 iCharacterMetricsTable.InternalizeL(aStream);
164 const TBool fixup = FontStoreFile()->iFileAddress;
167 iCharacterMetricsTable.FixUp(FontStoreFile()->iFileAddress);
169 iNumCodeSections = aStream.ReadInt32L();
170 TBitmapCodeSectionOld* codesectionlist = (TBitmapCodeSectionOld*)User::LeaveIfNull(iHeap->AllocL(iNumCodeSections * sizeof(TBitmapCodeSectionOld)));
171 iCodeSectionListOffset = TInt(codesectionlist) - TInt(this);
172 for (TInt i = 0; i < iNumCodeSections; i++)
174 new(codesectionlist + i) TBitmapCodeSectionOld(iHeap);
175 codesectionlist[i].InternalizeL(aStream);
177 codesectionlist[i].FixUpComponents(FontStoreFile()->iFileAddress);
181 void CFontBitmapOld::UseL()
184 if (iUsageCount == 2)
185 RestoreComponentsL();
188 void CFontBitmapOld::Release()
198 Get the metrics for a given character.
199 Return aBytes as null if the character aCode doesn't exist in the font.
201 TBitmapFontCharacterMetrics CFontBitmapOld::CharacterMetrics(TInt aCode, const TUint8*& aBytes) const
203 const TBitmapCodeSectionOld* matchSection = NULL;
204 const TBitmapCodeSectionOld* const lastSection = CodeSectionList() + iNumCodeSections - 1;
206 TBitmapFontCharacterOffset offset;
209 TBitmapFontCharacterMetrics metrics;
210 const TBitmapCodeSectionOld* startSearchBand = CodeSectionList();
211 TInt numCodeSectionsRemaining = iNumCodeSections;
212 while (numCodeSectionsRemaining >= 1)
214 TInt halfNumCodeSectionsRemaining = numCodeSectionsRemaining/2;
215 const TBitmapCodeSectionOld* centralSearchBand = startSearchBand+halfNumCodeSectionsRemaining;
216 if ((aCode >= centralSearchBand->iStart) && (aCode <= centralSearchBand->iEnd))
218 matchSection = centralSearchBand;
221 else if ((aCode < centralSearchBand->iStart) || (centralSearchBand == lastSection))
222 numCodeSectionsRemaining = halfNumCodeSectionsRemaining;
225 startSearchBand = centralSearchBand + 1;
226 numCodeSectionsRemaining -= halfNumCodeSectionsRemaining + 1;
232 offset =* ((matchSection->CharacterOffsetsList()) + (aCode-matchSection->iStart));
234 // Fill characters within code section.
235 // Recursive call ensures that a valid metric is always returned.
236 if (offset.iBitmapOffset == KFillCharacterOffset)
238 return CharacterMetrics(KReplacementCharacter, aBytes);
241 aBytes = matchSection->Bitmap() + offset.iBitmapOffset;
243 // retrieve metric index from encoded 1 or 2 bytes
245 TUint8 byte1 = (TUint8)*aBytes;
246 const TInt switchMask = 0x1;
247 const TBool oneByteIndex =! (byte1 & switchMask);
248 byte1 = TUint8(byte1 >> 1);
256 const TUint8 byte2 = (TUint8)(*(aBytes + 1));
257 index = byte1 + (byte2 * 128);
260 // Copy metric from table
261 metrics =* iCharacterMetricsTable.Metric(index);
266 void CFontBitmapOld::operator delete(TAny *aThis)
268 if (((CFontBitmapOld *)aThis)->iHeap)
270 ((CFontBitmapOld *)aThis)->iHeap->Free(aThis);
274 void CFontBitmapOld::SetPosture(TFontPosture aPosture)
276 iPosture = (TInt8)aPosture;
279 TFontPosture CFontBitmapOld::Posture()
281 return (TFontPosture)iPosture; // iPosture is always smaller than TFontPosture
284 void CFontBitmapOld::SetStrokeWeight(TFontStrokeWeight aStrokeWeight)
286 iStrokeWeight = (TInt8)aStrokeWeight;
289 TFontStrokeWeight CFontBitmapOld::StrokeWeight()
291 return (TFontStrokeWeight)iStrokeWeight;
294 void CFontBitmapOld::SetIsProportional(TBool aIsProportional)
296 iIsProportional = (TInt8)aIsProportional;
299 TBool CFontBitmapOld::IsProportional()
301 return iIsProportional;
304 CFontStoreFile* CFontBitmapOld::FontStoreFile() const
306 TInt fsf = TInt(this) + iFontStoreFileOffset;
307 return (CFontStoreFile*)fsf;
310 CFontBitmapOld::~CFontBitmapOld()
313 iHeap->Free(CodeSectionList());
314 iCodeSectionListOffset = 0;
317 void CFontBitmapOld::RestoreComponentsL()
321 CStreamStore& store =* FontStoreFile()->iFileStore;
322 for (TInt i = 0; i < iNumCodeSections; i++)
324 CodeSectionList()[i].RestoreComponentsL(store);
326 iCharacterMetricsTable.RestoreL(store);
330 void CFontBitmapOld::DeleteComponents()
334 for (TInt i = 0; i < iNumCodeSections; i++)
336 CodeSectionList()[i].DeleteComponents();
338 iCharacterMetricsTable.Delete();
342 TBitmapCodeSectionOld* CFontBitmapOld::CodeSectionList() const
344 TInt bcs = TInt(this) + iCodeSectionListOffset;
345 return (TBitmapCodeSectionOld*)bcs;