sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "PDRBODY.H" sl@0: #include "PDRSTD.H" sl@0: sl@0: TPdrResource::TPdrResource(): sl@0: iId(0), sl@0: iString() sl@0: { sl@0: } sl@0: sl@0: void TPdrResource::InternalizeL(RReadStream& aStream) sl@0: { sl@0: iId = aStream.ReadUint8L(); sl@0: aStream >> iString; sl@0: } sl@0: sl@0: CPdrTranslation::CPdrTranslation(): sl@0: iFrom(0), sl@0: iTo(NULL) sl@0: { sl@0: __DECLARE_NAME(_S("CPdrTranslation")); sl@0: } sl@0: sl@0: CPdrTranslation::~CPdrTranslation() sl@0: { sl@0: delete iTo; sl@0: } sl@0: sl@0: void CPdrTranslation::InternalizeL(RReadStream& aStream) sl@0: { sl@0: iFrom = aStream.ReadUint16L(); sl@0: iTo=HBufC8::NewL(aStream,KMaxCommandStringMaxLength); sl@0: } sl@0: sl@0: CPdrTranslates::CPdrTranslates(): sl@0: iStreamId(KNullStreamId), sl@0: iNumTranslations(0), sl@0: iTranslationList(NULL) sl@0: { sl@0: __DECLARE_NAME(_S("CPdrTranslates")); sl@0: } sl@0: sl@0: void CPdrTranslates::InternalizeL(RReadStream& aStream) sl@0: { sl@0: TInt size=aStream.ReadInt32L(); sl@0: iTranslationList = new(ELeave) CPdrTranslation*[size]; sl@0: for (TInt i=0; iInternalizeL(aStream); sl@0: } sl@0: } sl@0: sl@0: CPdrTranslates::~CPdrTranslates() sl@0: { sl@0: for (; iNumTranslations>0; iNumTranslations--) sl@0: delete iTranslationList[iNumTranslations-1]; sl@0: delete[] iTranslationList; sl@0: } sl@0: sl@0: HBufC8* CPdrTranslates::TranslateStringL(const TDesC& aString) const sl@0: { sl@0: CPdrTranslation** pEnd=iTranslationList+iNumTranslations; sl@0: TInt length1=aString.Length(),length2=length1; sl@0: if (iNumTranslations) sl@0: { sl@0: for (TInt i=0; iiFrom) sl@0: length2+=(*p)->iTo->Des().Length()-1; sl@0: } sl@0: } sl@0: HBufC8* string2=HBufC8::NewL(length2); sl@0: string2->Des().Copy(aString); sl@0: if (iNumTranslations) sl@0: { sl@0: CleanupStack::PushL(string2); sl@0: HBufC8* string1=HBufC8::NewL(length1); sl@0: string1->Des().Copy(aString); sl@0: TInt j=0; sl@0: for (TInt i=0; iiFrom) sl@0: { sl@0: if ((*p)->iTo->Des().Length()==1) sl@0: { sl@0: string2->Des()[j]=(*p)->iTo->Des()[0]; sl@0: } sl@0: else sl@0: { sl@0: string2->Des().SetLength(j); sl@0: string2->Des().Append((*p)->iTo->Des()); sl@0: j+=(*p)->iTo->Des().Length()-1; sl@0: if ((i+1)Des().SetLength(j+1); sl@0: string2->Des().Append(string1->Des().Mid(i+1)); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: j++; sl@0: } sl@0: delete string1; sl@0: CleanupStack::Pop(); sl@0: } sl@0: return string2; sl@0: } sl@0: sl@0: CWidthsCodeSection::CWidthsCodeSection(): sl@0: iNumWidths(0), sl@0: iWidthList(NULL) sl@0: { sl@0: __DECLARE_NAME(_S("CWidthsCodeSection")); sl@0: } sl@0: sl@0: void CWidthsCodeSection::InternalizeL(RReadStream& aStream) sl@0: { sl@0: iCodeSection.iStart = aStream.ReadUint16L(); sl@0: iCodeSection.iEnd = aStream.ReadUint16L(); sl@0: iNumWidths = aStream.ReadInt32L(); sl@0: iWidthList = new(ELeave) TUint16[iNumWidths]; sl@0: TUint16* pEnd = iWidthList+iNumWidths; sl@0: for (TUint16* p=iWidthList; pInternalizeL(aStream); sl@0: } sl@0: } sl@0: sl@0: CFontInfo::~CFontInfo() sl@0: { sl@0: for (; iNumCodeSections>0; iNumCodeSections--) sl@0: delete iCodeSectionList[iNumCodeSections-1]; sl@0: delete[] iCodeSectionList; sl@0: } sl@0: sl@0: TInt CFontInfo::CharWidthInPixels(TChar aChar) const sl@0: { sl@0: TInt width=0,code=TUint(aChar); sl@0: for (TInt i=0; i=p->iCodeSection.iStart) && (code<=p->iCodeSection.iEnd)) sl@0: { sl@0: if (p->iNumWidths==1) sl@0: width=p->iWidthList[0]; sl@0: else sl@0: width = *((p->iWidthList)+(code-p->iCodeSection.iStart)); sl@0: } sl@0: } sl@0: return width; sl@0: } sl@0: sl@0: TInt CFontInfo::NumCodeSections() const sl@0: { sl@0: return iNumCodeSections; sl@0: } sl@0: sl@0: TCodeSection CFontInfo::CodeSection(TInt anIndex) const sl@0: { sl@0: return iCodeSectionList[anIndex]->iCodeSection; sl@0: } sl@0: sl@0: TPdrStyle::TPdrStyle(): sl@0: iIsAvailable(EFalse), sl@0: iFontInfoStreamId(KNullStreamId) sl@0: { sl@0: } sl@0: sl@0: void TPdrStyle::InternalizeL(RReadStream &aStream) sl@0: { sl@0: iIsAvailable = aStream.ReadUint8L(); sl@0: aStream >> iFontInfoStreamId; sl@0: } sl@0: sl@0: TPdrFontHeight::TPdrFontHeight(): sl@0: iCommandString(), sl@0: iHeightInTwips(0), sl@0: iWidthScale(1), sl@0: iStyle() sl@0: { sl@0: } sl@0: sl@0: void TPdrFontHeight::InternalizeL(RReadStream& aStream) sl@0: { sl@0: aStream >> iCommandString; sl@0: iHeightInTwips = aStream.ReadInt32L(); sl@0: iWidthScale = aStream.ReadInt32L(); sl@0: for (TInt style=EStyleNormal; style<(EStyleBoldItalic+1); style++) sl@0: iStyle[style].InternalizeL(aStream); sl@0: } sl@0: sl@0: TPdrScalableFontHeight::TPdrScalableFontHeight(): sl@0: iCommandString(), sl@0: iHeightMinInTwips(0), sl@0: iHeightMaxInTwips(0), sl@0: iHeightDeltaInTwips(0), sl@0: iStyle() sl@0: { sl@0: } sl@0: sl@0: void TPdrScalableFontHeight::InternalizeL(RReadStream& aStream) sl@0: { sl@0: aStream >> iCommandString; sl@0: iHeightMinInTwips = aStream.ReadInt32L(); sl@0: iHeightMaxInTwips = aStream.ReadInt32L(); sl@0: iHeightDeltaInTwips = aStream.ReadInt32L(); sl@0: for (TInt style=EStyleNormal; style<(EStyleBoldItalic+1); style++) sl@0: iStyle[style].InternalizeL(aStream); sl@0: } sl@0: sl@0: CTypefaceFonts::CTypefaceFonts(): sl@0: iTypeface(), sl@0: iNumFontHeights(0), sl@0: iFontHeightList(NULL), sl@0: iScalableFontHeight(NULL), sl@0: iTranslates() sl@0: { sl@0: __DECLARE_NAME(_S("CTypefaceFonts")); sl@0: } sl@0: sl@0: void CTypefaceFonts::InternalizeL(RReadStream& aStream) sl@0: { sl@0: iTypeface.InternalizeL(aStream); sl@0: TInt isscalable = aStream.ReadInt8L(); sl@0: if (!isscalable) sl@0: { sl@0: iNumFontHeights = aStream.ReadInt32L(); sl@0: iFontHeightList = new(ELeave) TPdrFontHeight[iNumFontHeights]; sl@0: TPdrFontHeight *pStart=iFontHeightList, *pEnd=pStart+iNumFontHeights; sl@0: for (TPdrFontHeight *p=pStart; pInternalizeL(aStream); sl@0: } sl@0: else sl@0: { sl@0: iScalableFontHeight = new(ELeave) TPdrScalableFontHeight; sl@0: iScalableFontHeight->InternalizeL(aStream); sl@0: } sl@0: aStream >> iTranslates; sl@0: } sl@0: sl@0: CTypefaceFonts::~CTypefaceFonts() sl@0: { sl@0: if (!IsScalable()) sl@0: { sl@0: iNumFontHeights=0; sl@0: delete[] iFontHeightList; sl@0: iFontHeightList=NULL; sl@0: } sl@0: else sl@0: { sl@0: delete iScalableFontHeight; sl@0: iScalableFontHeight=NULL; sl@0: } sl@0: } sl@0: sl@0: TInt CTypefaceFonts::IsScalable() const sl@0: { sl@0: return !iNumFontHeights; sl@0: } sl@0: sl@0: TInt CTypefaceFonts::NumFontHeights() const sl@0: { sl@0: TInt num; sl@0: if (!IsScalable()) sl@0: num = iNumFontHeights; sl@0: else sl@0: num = ((iScalableFontHeight->iHeightMaxInTwips-iScalableFontHeight->iHeightMinInTwips)/iScalableFontHeight->iHeightDeltaInTwips) + 1; sl@0: return num; sl@0: } sl@0: sl@0: TInt CTypefaceFonts::FontHeightInTwips(TInt aHeightIndex) const sl@0: { sl@0: TInt height=0; sl@0: __ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndexiHeightMinInTwips + (iScalableFontHeight->iHeightDeltaInTwips*aHeightIndex); sl@0: return height; sl@0: } sl@0: sl@0: TInt CTypefaceFonts::FontInfoHeightInTwips(TInt aHeightIndex) const sl@0: { sl@0: TInt height=0; sl@0: __ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndex=0) && (aHeightIndexiCommandString,heightinpoints); sl@0: } sl@0: } sl@0: sl@0: TPdrStyle* CTypefaceFonts::Style(TInt aHeightIndex,TFontStyle& aFontStyle) const sl@0: { sl@0: TPdrStyle* style=NULL; sl@0: TStyleIndex index=StyleIndex(aFontStyle); sl@0: __ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndexiStyle+index; sl@0: return style; sl@0: } sl@0: sl@0: TTypeface CTypefaceFonts::Typeface() sl@0: { sl@0: return iTypeface; sl@0: } sl@0: sl@0: TStyleIndex CTypefaceFonts::StyleIndex(TFontStyle& aFontStyle) const sl@0: { sl@0: TStyleIndex index; sl@0: if (aFontStyle.StrokeWeight()==EStrokeWeightNormal) sl@0: { sl@0: if (aFontStyle.Posture()==EPostureUpright) sl@0: index=EStyleNormal; sl@0: else sl@0: index=EStyleItalic; sl@0: } sl@0: else sl@0: { sl@0: if (aFontStyle.Posture()==EPostureUpright) sl@0: index=EStyleBold; sl@0: else sl@0: index=EStyleBoldItalic; sl@0: } sl@0: return index; sl@0: }