Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 TPdrResource::TPdrResource():
25 void TPdrResource::InternalizeL(RReadStream& aStream)
27 iId = aStream.ReadUint8L();
31 CPdrTranslation::CPdrTranslation():
35 __DECLARE_NAME(_S("CPdrTranslation"));
38 CPdrTranslation::~CPdrTranslation()
43 void CPdrTranslation::InternalizeL(RReadStream& aStream)
45 iFrom = aStream.ReadUint16L();
46 iTo=HBufC8::NewL(aStream,KMaxCommandStringMaxLength);
49 CPdrTranslates::CPdrTranslates():
50 iStreamId(KNullStreamId),
52 iTranslationList(NULL)
54 __DECLARE_NAME(_S("CPdrTranslates"));
57 void CPdrTranslates::InternalizeL(RReadStream& aStream)
59 TInt size=aStream.ReadInt32L();
60 iTranslationList = new(ELeave) CPdrTranslation*[size];
61 for (TInt i=0; i<size; i++)
63 iTranslationList[i]=new(ELeave) CPdrTranslation;
65 iTranslationList[i]->InternalizeL(aStream);
69 CPdrTranslates::~CPdrTranslates()
71 for (; iNumTranslations>0; iNumTranslations--)
72 delete iTranslationList[iNumTranslations-1];
73 delete[] iTranslationList;
76 HBufC8* CPdrTranslates::TranslateStringL(const TDesC& aString) const
78 CPdrTranslation** pEnd=iTranslationList+iNumTranslations;
79 TInt length1=aString.Length(),length2=length1;
82 for (TInt i=0; i<length1; i++)
84 for (CPdrTranslation** p=iTranslationList; p<pEnd; p++)
85 if (aString[i]==(*p)->iFrom)
86 length2+=(*p)->iTo->Des().Length()-1;
89 HBufC8* string2=HBufC8::NewL(length2);
90 string2->Des().Copy(aString);
93 CleanupStack::PushL(string2);
94 HBufC8* string1=HBufC8::NewL(length1);
95 string1->Des().Copy(aString);
97 for (TInt i=0; i<length1; i++)
99 for (CPdrTranslation** p=iTranslationList; p<pEnd; p++)
101 if (aString[i]==(*p)->iFrom)
103 if ((*p)->iTo->Des().Length()==1)
105 string2->Des()[j]=(*p)->iTo->Des()[0];
109 string2->Des().SetLength(j);
110 string2->Des().Append((*p)->iTo->Des());
111 j+=(*p)->iTo->Des().Length()-1;
114 string2->Des().SetLength(j+1);
115 string2->Des().Append(string1->Des().Mid(i+1));
128 CWidthsCodeSection::CWidthsCodeSection():
132 __DECLARE_NAME(_S("CWidthsCodeSection"));
135 void CWidthsCodeSection::InternalizeL(RReadStream& aStream)
137 iCodeSection.iStart = aStream.ReadUint16L();
138 iCodeSection.iEnd = aStream.ReadUint16L();
139 iNumWidths = aStream.ReadInt32L();
140 iWidthList = new(ELeave) TUint16[iNumWidths];
141 TUint16* pEnd = iWidthList+iNumWidths;
142 for (TUint16* p=iWidthList; p<pEnd; p++)
143 *p = aStream.ReadUint16L();
146 CWidthsCodeSection::~CWidthsCodeSection()
153 CFontInfo::CFontInfo(TStreamId aStreamId):
154 iStreamId(aStreamId),
156 iMaxCharWidthInPixels(0),
157 iMaxNormalCharWidthInPixels(0),
159 iCodeSectionList(NULL)
161 __DECLARE_NAME(_S("CFontInfo"));
164 void CFontInfo::InternalizeL(RReadStream &aStream)
166 iAscentInPixels = aStream.ReadUint16L();
167 iMaxCharWidthInPixels = aStream.ReadUint16L();
168 iMaxNormalCharWidthInPixels = aStream.ReadUint16L();
169 TInt size = aStream.ReadInt32L();
170 iCodeSectionList = new(ELeave) CWidthsCodeSection*[size];
171 for (TInt i=0; i<size; i++)
173 iCodeSectionList[i]=new(ELeave) CWidthsCodeSection;
175 iCodeSectionList[i]->InternalizeL(aStream);
179 CFontInfo::~CFontInfo()
181 for (; iNumCodeSections>0; iNumCodeSections--)
182 delete iCodeSectionList[iNumCodeSections-1];
183 delete[] iCodeSectionList;
186 TInt CFontInfo::CharWidthInPixels(TChar aChar) const
188 TInt width=0,code=TUint(aChar);
189 for (TInt i=0; i<iNumCodeSections; i++)
191 CWidthsCodeSection* p=iCodeSectionList[i];
192 if ((code>=p->iCodeSection.iStart) && (code<=p->iCodeSection.iEnd))
194 if (p->iNumWidths==1)
195 width=p->iWidthList[0];
197 width = *((p->iWidthList)+(code-p->iCodeSection.iStart));
203 TInt CFontInfo::NumCodeSections() const
205 return iNumCodeSections;
208 TCodeSection CFontInfo::CodeSection(TInt anIndex) const
210 return iCodeSectionList[anIndex]->iCodeSection;
213 TPdrStyle::TPdrStyle():
214 iIsAvailable(EFalse),
215 iFontInfoStreamId(KNullStreamId)
219 void TPdrStyle::InternalizeL(RReadStream &aStream)
221 iIsAvailable = aStream.ReadUint8L();
222 aStream >> iFontInfoStreamId;
225 TPdrFontHeight::TPdrFontHeight():
233 void TPdrFontHeight::InternalizeL(RReadStream& aStream)
235 aStream >> iCommandString;
236 iHeightInTwips = aStream.ReadInt32L();
237 iWidthScale = aStream.ReadInt32L();
238 for (TInt style=EStyleNormal; style<(EStyleBoldItalic+1); style++)
239 iStyle[style].InternalizeL(aStream);
242 TPdrScalableFontHeight::TPdrScalableFontHeight():
244 iHeightMinInTwips(0),
245 iHeightMaxInTwips(0),
246 iHeightDeltaInTwips(0),
251 void TPdrScalableFontHeight::InternalizeL(RReadStream& aStream)
253 aStream >> iCommandString;
254 iHeightMinInTwips = aStream.ReadInt32L();
255 iHeightMaxInTwips = aStream.ReadInt32L();
256 iHeightDeltaInTwips = aStream.ReadInt32L();
257 for (TInt style=EStyleNormal; style<(EStyleBoldItalic+1); style++)
258 iStyle[style].InternalizeL(aStream);
261 CTypefaceFonts::CTypefaceFonts():
264 iFontHeightList(NULL),
265 iScalableFontHeight(NULL),
268 __DECLARE_NAME(_S("CTypefaceFonts"));
271 void CTypefaceFonts::InternalizeL(RReadStream& aStream)
273 iTypeface.InternalizeL(aStream);
274 TInt isscalable = aStream.ReadInt8L();
277 iNumFontHeights = aStream.ReadInt32L();
278 iFontHeightList = new(ELeave) TPdrFontHeight[iNumFontHeights];
279 TPdrFontHeight *pStart=iFontHeightList, *pEnd=pStart+iNumFontHeights;
280 for (TPdrFontHeight *p=pStart; p<pEnd; p++)
281 p->InternalizeL(aStream);
285 iScalableFontHeight = new(ELeave) TPdrScalableFontHeight;
286 iScalableFontHeight->InternalizeL(aStream);
288 aStream >> iTranslates;
291 CTypefaceFonts::~CTypefaceFonts()
296 delete[] iFontHeightList;
297 iFontHeightList=NULL;
301 delete iScalableFontHeight;
302 iScalableFontHeight=NULL;
306 TInt CTypefaceFonts::IsScalable() const
308 return !iNumFontHeights;
311 TInt CTypefaceFonts::NumFontHeights() const
315 num = iNumFontHeights;
317 num = ((iScalableFontHeight->iHeightMaxInTwips-iScalableFontHeight->iHeightMinInTwips)/iScalableFontHeight->iHeightDeltaInTwips) + 1;
321 TInt CTypefaceFonts::FontHeightInTwips(TInt aHeightIndex) const
324 __ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndex<NumFontHeights()),Panic(EPdrHeightIndexOutOfRange));
326 height = iFontHeightList[aHeightIndex].iHeightInTwips;
328 height = iScalableFontHeight->iHeightMinInTwips + (iScalableFontHeight->iHeightDeltaInTwips*aHeightIndex);
332 TInt CTypefaceFonts::FontInfoHeightInTwips(TInt aHeightIndex) const
335 __ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndex<NumFontHeights()),Panic(EPdrHeightIndexOutOfRange));
337 height = iFontHeightList[aHeightIndex].iHeightInTwips/iFontHeightList[aHeightIndex].iWidthScale;
339 height = KScalableWidthTableHeightInTwips;
343 void CTypefaceFonts::CommandString(TDes8& aDes,TInt aHeightIndex) const
345 __ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndex<NumFontHeights()),Panic(EPdrHeightIndexOutOfRange));
347 aDes=iFontHeightList[aHeightIndex].iCommandString;
350 TInt heightinpoints=FontHeightInTwips(aHeightIndex)/KTwipsPerPoint;
351 aDes.Format(iScalableFontHeight->iCommandString,heightinpoints);
355 TPdrStyle* CTypefaceFonts::Style(TInt aHeightIndex,TFontStyle& aFontStyle) const
357 TPdrStyle* style=NULL;
358 TStyleIndex index=StyleIndex(aFontStyle);
359 __ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndex<NumFontHeights()),Panic(EPdrHeightIndexOutOfRange));
361 style = iFontHeightList[aHeightIndex].iStyle+index;
363 style = iScalableFontHeight->iStyle+index;
367 TTypeface CTypefaceFonts::Typeface()
372 TStyleIndex CTypefaceFonts::StyleIndex(TFontStyle& aFontStyle) const
375 if (aFontStyle.StrokeWeight()==EStrokeWeightNormal)
377 if (aFontStyle.Posture()==EPostureUpright)
384 if (aFontStyle.Posture()==EPostureUpright)
387 index=EStyleBoldItalic;