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 sl@0: #include sl@0: #include "PDRBODY.H" sl@0: #include "PDRSTD.H" sl@0: #include "pdrtext.h" sl@0: sl@0: EXPORT_C CPdrResources::CPdrResources(): sl@0: iNumResources(0), sl@0: iResourceList(NULL) sl@0: { sl@0: __DECLARE_NAME(_S("CPdrResources")); sl@0: } sl@0: sl@0: EXPORT_C void CPdrResources::RestoreL(CStreamStore& aStore, TStreamId aStreamId) sl@0: { sl@0: RStoreReadStream stream; sl@0: stream.OpenLC(aStore, aStreamId); sl@0: iNumResources = stream.ReadInt32L(); sl@0: iResourceList = new(ELeave) TPdrResource[iNumResources]; sl@0: for (TInt i = 0; i < iNumResources; i++) sl@0: iResourceList[i].InternalizeL(stream); sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: EXPORT_C CPdrResources::~CPdrResources() sl@0: { sl@0: delete[] iResourceList; sl@0: iResourceList = NULL; sl@0: iNumResources = 0; sl@0: } sl@0: sl@0: EXPORT_C TPtrC8 CPdrResources::ResourceString(TInt anId) const sl@0: { sl@0: TPtrC8 ptr; sl@0: TPdrResource* pEnd = iResourceList + iNumResources; sl@0: TPdrResource* p ; sl@0: for( p = iResourceList; (p < pEnd) && (p->iId != anId); p++) sl@0: { sl@0: } sl@0: if (p < pEnd) sl@0: ptr.Set(p->iString); sl@0: return ptr; sl@0: } sl@0: sl@0: CInfoFont::CInfoFont(TInt aBaselineOffsetInPixels, const TFontSpec& aFontSpecInTwips, TInt aFontInfoHeightInTwips, TInt aHeightInPixels, CPdrTranslates* aTranslates, const TDesC8& aCommandString, CPdrDevice* aPdrDevice): sl@0: CFont(), sl@0: iCommandString(aCommandString), sl@0: iBaselineOffsetInPixels(aBaselineOffsetInPixels), sl@0: iFontSpecInTwips(aFontSpecInTwips), sl@0: iFontInfoHeightInTwips(aFontInfoHeightInTwips), sl@0: iHeightInPixels(aHeightInPixels), sl@0: iFontInfo(NULL), sl@0: iTranslates(aTranslates), sl@0: iPdrDevice(aPdrDevice), sl@0: iRealFont(NULL) sl@0: { sl@0: CreateBandedFontIfRequired(); sl@0: } sl@0: sl@0: CInfoFont::~CInfoFont() sl@0: { sl@0: if (iRealFont) sl@0: if (iPdrDevice->iControl) sl@0: ((CPdrControl*)(iPdrDevice->iControl))->BandedDevice()->ReleaseFont(iRealFont); sl@0: } sl@0: sl@0: void CInfoFont::CreateBandedFontIfRequired() sl@0: { sl@0: if (!iRealFont) sl@0: { sl@0: if (iPdrDevice->iControl) sl@0: { sl@0: if (((CPdrControl*)(iPdrDevice->iControl))->BandedDevice()) sl@0: ((CPdrControl*)(iPdrDevice->iControl))->BandedDevice()->GetNearestFontToDesignHeightInTwips(iRealFont, iFontSpecInTwips); sl@0: } sl@0: } sl@0: } sl@0: sl@0: EXPORT_C TUid CInfoFont::DoTypeUid() const sl@0: { sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: return TUid::Uid(KCInfoFontUidVal); sl@0: } sl@0: sl@0: EXPORT_C TInt CInfoFont::DoHeightInPixels() const sl@0: { sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: return iHeightInPixels; sl@0: } sl@0: sl@0: EXPORT_C TInt CInfoFont::DoAscentInPixels() const sl@0: { sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: return Height(iFontInfo->iAscentInPixels); sl@0: } sl@0: sl@0: EXPORT_C TInt CInfoFont::DoCharWidthInPixels(TChar aChar) const sl@0: { sl@0: TInt width; sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: if (RepertoireContains(aChar)) sl@0: { sl@0: width = iFontInfo->CharWidthInPixels(TUint(aChar)); sl@0: width = Width(width); sl@0: } sl@0: else sl@0: { sl@0: if (iRealFont) sl@0: width = iRealFont->CharWidthInPixels(TUint(aChar)); sl@0: else sl@0: width = 0; sl@0: } sl@0: return width; sl@0: } sl@0: sl@0: EXPORT_C TInt CInfoFont::DoTextWidthInPixels(const TDesC &aText) const sl@0: { sl@0: TMeasureTextOutput output; sl@0: TInt advance_width = MeasureText(aText,NULL,&output); sl@0: return Max(advance_width,output.iBounds.Width()); sl@0: } sl@0: sl@0: EXPORT_C TInt CInfoFont::DoBaselineOffsetInPixels() const sl@0: { sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: return iBaselineOffsetInPixels; sl@0: } sl@0: sl@0: EXPORT_C TInt CInfoFont::DoTextCount(const TDesC &aText, TInt aWidthInPixels) const sl@0: { sl@0: TInt count = 0; sl@0: TInt width = 0; sl@0: TInt length = aText.Length(); sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: for (count = 0; (count < length) && ((width += MeasureText(aText.Mid(count, 1))) < aWidthInPixels); ) sl@0: { sl@0: count++; sl@0: } sl@0: return count; sl@0: } sl@0: sl@0: EXPORT_C TInt CInfoFont::DoTextCount(const TDesC &aText, TInt aWidthInPixels, TInt &aExcessWidthInPixels) const sl@0: { sl@0: TInt count = TextCount(aText, aWidthInPixels); sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: aExcessWidthInPixels = aWidthInPixels - MeasureText(aText.Left(count)); sl@0: return count; sl@0: } sl@0: sl@0: EXPORT_C TInt CInfoFont::DoMaxCharWidthInPixels() const sl@0: { sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: TInt width = Width(iFontInfo->iMaxCharWidthInPixels); sl@0: if (iRealFont) sl@0: return Max(iRealFont->MaxCharWidthInPixels(),width); sl@0: return width; sl@0: } sl@0: sl@0: EXPORT_C TInt CInfoFont::DoMaxNormalCharWidthInPixels() const sl@0: { sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: TInt width = Width(iFontInfo->iMaxNormalCharWidthInPixels); sl@0: if (iRealFont) sl@0: return Max(iRealFont->MaxNormalCharWidthInPixels(),width); sl@0: return width; sl@0: } sl@0: sl@0: EXPORT_C TFontSpec CInfoFont::DoFontSpecInTwips() const sl@0: { sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: return iFontSpecInTwips; sl@0: } sl@0: sl@0: EXPORT_C HBufC8* CInfoFont::TranslateStringL(const TDesC& aString) const sl@0: { sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: return iTranslates->TranslateStringL(aString); sl@0: } sl@0: sl@0: EXPORT_C TPtrC8 CInfoFont::CommandString() const sl@0: { sl@0: TPtrC8 ptr; sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: ptr.Set(iCommandString); sl@0: return ptr; sl@0: } sl@0: sl@0: EXPORT_C TBool CInfoFont::RepertoireContains(TChar aChar) const sl@0: { sl@0: CFontInfo* fontInfo = FontInfo(); sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: for (TInt i = 0; i < fontInfo->NumCodeSections(); i++) sl@0: { sl@0: if (((TInt)(TUint)aChar >= fontInfo->CodeSection(i).iStart) && ((TInt)(TUint)aChar<= fontInfo->CodeSection(i).iEnd)) sl@0: return ETrue; sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: EXPORT_C TBool CInfoFont::AllCharsInFontRepertoire(const TDesC& aString, TInt& aFirstCharNotInRepertoire, TInt& aLength) const sl@0: { sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: for (aFirstCharNotInRepertoire = 0; aFirstCharNotInRepertoire < aString.Length(); aFirstCharNotInRepertoire++) sl@0: if (!(RepertoireContains(aString[aFirstCharNotInRepertoire]))) sl@0: { sl@0: if (aFirstCharNotInRepertoire == 0) sl@0: { // Work out length sl@0: for (aLength = aFirstCharNotInRepertoire; aLength < aString.Length(); aLength++) sl@0: if ((RepertoireContains(aString[aLength]))) sl@0: break; sl@0: } sl@0: return EFalse; sl@0: } sl@0: return ETrue; sl@0: } sl@0: sl@0: CFont* CInfoFont::RealFont() const sl@0: { sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: return iRealFont; sl@0: } sl@0: sl@0: TInt CInfoFont::Width(TInt aNum) const sl@0: { sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: return (aNum * iFontSpecInTwips.iHeight + (iFontInfoHeightInTwips / 2)) / iFontInfoHeightInTwips; sl@0: } sl@0: sl@0: TInt CInfoFont::Height(TInt aNum) const sl@0: { sl@0: CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired(); sl@0: return (aNum * iFontSpecInTwips.iHeight + (iFontInfoHeightInTwips / 2)) / iFontInfoHeightInTwips; sl@0: } sl@0: sl@0: EXPORT_C void TTypefaceFontsEntry::InternalizeL(RReadStream& aStream) sl@0: { sl@0: aStream >> iStreamId; sl@0: iNotInPortrait = aStream.ReadUint8L(); sl@0: iNotInLandscape = aStream.ReadUint8L(); sl@0: } sl@0: sl@0: EXPORT_C CPdrModelInfo::CPdrModelInfo(): sl@0: iFlags(0), sl@0: iKPixelWidthInTwips(0), sl@0: iKPixelHeightInTwips(0), sl@0: iPortraitOffsetInPixels(), sl@0: iLandscapeOffsetInPixels(), sl@0: // iMinMarginsInPixels(), sl@0: iDisplayMode(EGray2), sl@0: iNumTypefaceFonts(0), sl@0: iTypefaceFontsEntryList(NULL), sl@0: iResourcesStreamId(KNullStreamId), sl@0: iSpareStreamId(KNullStreamId) sl@0: { sl@0: __DECLARE_NAME(_S("CPdrModelInfo")); sl@0: } sl@0: sl@0: EXPORT_C CPdrModelInfo::~CPdrModelInfo() sl@0: { sl@0: delete[] iTypefaceFontsEntryList; sl@0: } sl@0: sl@0: EXPORT_C void CPdrModelInfo::InternalizeL(RReadStream& aStream) sl@0: { sl@0: TInt pdrtranversion = aStream.ReadInt32L(); sl@0: if (pdrtranversion < KPdrtranVersion) sl@0: User::Leave(KErrNotSupported); sl@0: iFlags = aStream.ReadInt32L(); sl@0: iKPixelWidthInTwips = aStream.ReadInt32L(); sl@0: iKPixelHeightInTwips = aStream.ReadInt32L(); sl@0: iPortraitOffsetInPixels.iX = aStream.ReadInt32L(); sl@0: iPortraitOffsetInPixels.iY = aStream.ReadInt32L(); sl@0: iLandscapeOffsetInPixels.iX = aStream.ReadInt32L(); sl@0: iLandscapeOffsetInPixels.iY = aStream.ReadInt32L(); sl@0: iMinMarginsInPixels.InternalizeL(aStream); sl@0: iDisplayMode = (TDisplayMode)aStream.ReadInt32L(); sl@0: iNumTypefaceFonts = aStream.ReadInt32L(); sl@0: iTypefaceFontsEntryList = new(ELeave) TTypefaceFontsEntry[iNumTypefaceFonts]; sl@0: TTypefaceFontsEntry* pEnd = iTypefaceFontsEntryList+iNumTypefaceFonts; sl@0: for(TTypefaceFontsEntry* p = iTypefaceFontsEntryList; p < pEnd; p++) sl@0: p->InternalizeL(aStream); sl@0: aStream >> iResourcesStreamId; sl@0: aStream >> iSpareStreamId; sl@0: } sl@0: sl@0: CPdrTypefaceStore::CPdrTypefaceStore(CStreamStore& aStore, TInt aKPixelHeightInTwips, CPdrDevice* aPdrDevice): sl@0: iPdrDevice(aPdrDevice), sl@0: iStore(&aStore), sl@0: iKPixelHeightInTwips(aKPixelHeightInTwips) sl@0: { sl@0: } sl@0: sl@0: void CPdrTypefaceStore::ConstructL(TInt aNumTypefaceFonts, TTypefaceFontsEntry* aTypefaceFontsEntryList, TPageSpec::TPageOrientation aPageOrientation) sl@0: { sl@0: CTypefaceStore::ConstructL(); sl@0: iTranslatesList = new(ELeave) CArrayPtrFlat(8); sl@0: iTypefaceFontsList = new(ELeave) CArrayPtrFlat(8); sl@0: iPortraitTypefaceFontsList = new(ELeave) CArrayPtrFlat(8); sl@0: iLandscapeTypefaceFontsList = new(ELeave) CArrayPtrFlat(8); sl@0: iFontInfoList = new(ELeave) CArrayPtrFlat(8); sl@0: for (TInt i = 0; i < aNumTypefaceFonts; i++) sl@0: { sl@0: CTypefaceFonts* typefacefonts = new(ELeave) CTypefaceFonts; sl@0: CleanupStack::PushL(typefacefonts); sl@0: RStoreReadStream stream; sl@0: stream.OpenLC(*iStore, aTypefaceFontsEntryList[i].iStreamId); sl@0: typefacefonts->InternalizeL(stream); sl@0: CleanupStack::PopAndDestroy(); sl@0: iTypefaceFontsList->AppendL(typefacefonts); sl@0: CleanupStack::Pop(); sl@0: typefacefonts->iTranslates=TranslatesL(typefacefonts->iTranslates.AsId()); sl@0: if (!aTypefaceFontsEntryList[i].iNotInPortrait) sl@0: iPortraitTypefaceFontsList->AppendL(typefacefonts); sl@0: if (!aTypefaceFontsEntryList[i].iNotInLandscape) sl@0: iLandscapeTypefaceFontsList->AppendL(typefacefonts); sl@0: } sl@0: SetPageOrientation(aPageOrientation); sl@0: } sl@0: sl@0: EXPORT_C CPdrTypefaceStore* CPdrTypefaceStore::NewL(CStreamStore& aStore, TInt aNumTypefacesFonts, TTypefaceFontsEntry* aTypefaceFontsEntryList, TPageSpec::TPageOrientation aPageOrientation, TInt aKPixelHeightInTwips, CPdrDevice* aPdrDevice) sl@0: { sl@0: CPdrTypefaceStore* typefacestore = new(ELeave) CPdrTypefaceStore(aStore, aKPixelHeightInTwips, aPdrDevice); sl@0: CleanupStack::PushL(typefacestore); sl@0: typefacestore->ConstructL(aNumTypefacesFonts, aTypefaceFontsEntryList, aPageOrientation); sl@0: CleanupStack::Pop(); sl@0: return typefacestore; sl@0: } sl@0: sl@0: EXPORT_C CPdrTypefaceStore::~CPdrTypefaceStore() sl@0: { sl@0: if (iTranslatesList) sl@0: iTranslatesList->ResetAndDestroy(); sl@0: delete iTranslatesList; sl@0: if (iTypefaceFontsList) sl@0: iTypefaceFontsList->ResetAndDestroy(); sl@0: delete iTypefaceFontsList; sl@0: delete iPortraitTypefaceFontsList; sl@0: delete iLandscapeTypefaceFontsList; sl@0: if (iFontInfoList) sl@0: iFontInfoList->ResetAndDestroy(); sl@0: delete iFontInfoList; sl@0: } sl@0: sl@0: /** sl@0: @internalTechnology sl@0: */ sl@0: EXPORT_C TInt CPdrTypefaceStore::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec) sl@0: { sl@0: return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec); sl@0: } sl@0: sl@0: /** sl@0: @internalTechnology sl@0: */ sl@0: EXPORT_C TInt CPdrTypefaceStore::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec) sl@0: { sl@0: aFont = NULL; sl@0: const TInt count = iCurrentTypefaceFontsList->Count(); sl@0: if (count) sl@0: { sl@0: TInt index = 0; sl@0: TTypeface typeface = aFontSpec.iTypeface; sl@0: for (index = 0; (index < count) && typeface.iName.CompareF((*iCurrentTypefaceFontsList)[index]->Typeface().iName); index++) sl@0: { // tries matching typeface name sl@0: } sl@0: if (index == count) sl@0: { sl@0: if (!typeface.IsSymbol()) sl@0: { sl@0: for (index = 0; (index < count) && (((*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()) || sl@0: (typeface.IsProportional() != (*iCurrentTypefaceFontsList)[index]->Typeface().IsProportional()) || sl@0: (typeface.IsSerif() != (*iCurrentTypefaceFontsList)[index]->Typeface().IsSerif())); index++) sl@0: { // tries matching typeface flags sl@0: } sl@0: if (index == count) sl@0: for (index = 0; (index < count) && (((*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()) || sl@0: (typeface.IsProportional() != (*iCurrentTypefaceFontsList)[index]->Typeface().IsProportional())); index++) sl@0: { // tries matching typeface flag sl@0: } sl@0: if (index == count) sl@0: for (index = 0; (index < count) && ((*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()); index++) sl@0: { // tries matching typeface flag sl@0: } sl@0: } sl@0: else sl@0: { sl@0: for (index = 0; (index < count) && (!(*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()); index++) sl@0: { // finds first symbol typeface sl@0: } sl@0: } sl@0: } sl@0: if (index == count) sl@0: index = 0; sl@0: CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[index]; sl@0: if (typefacefonts->NumFontHeights()) sl@0: { sl@0: TFontSpec fontspec(aFontSpec); sl@0: fontspec.iTypeface = typefacefonts->Typeface(); sl@0: TInt i = GetNearestFontHeightIndex(index, aFontSpec.iHeight); sl@0: fontspec.iHeight = typefacefonts->FontHeightInTwips(i); sl@0: if (fontspec.iFontStyle.PrintPosition() != EPrintPosNormal) sl@0: { sl@0: i = GetNearestFontHeightIndex(index, SuperSubHeight(fontspec.iHeight, fontspec.iFontStyle.PrintPosition())); sl@0: } sl@0: fontspec.iFontStyle = GetNearestFontStyle(index, i, fontspec.iFontStyle); sl@0: TInt heightintwips = typefacefonts->FontHeightInTwips(i); sl@0: TInt height = VerticalTwipsToPixels(heightintwips); sl@0: if (IsFontLoaded(aFont, fontspec, height)) sl@0: return KErrNone; sl@0: TInt baselineoffset = BaselineOffset(VerticalTwipsToPixels(fontspec.iHeight), fontspec.iFontStyle.PrintPosition()); sl@0: TInt fontinfoheight = ((fontspec.iHeight * typefacefonts->FontInfoHeightInTwips(i) + (heightintwips / 2))) / heightintwips; sl@0: CPdrTranslates* translates = typefacefonts->iTranslates; sl@0: TCommandString commandstring; sl@0: typefacefonts->CommandString(commandstring, i); sl@0: TStreamId fontinfostreamid = typefacefonts->Style(i, fontspec.iFontStyle)->iFontInfoStreamId; sl@0: TRAPD(ret, aFont = NewFontL(baselineoffset, fontspec, fontinfoheight, height, translates, commandstring, fontinfostreamid)); sl@0: return ret; sl@0: } sl@0: } sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: /** sl@0: @internalTechnology sl@0: */ sl@0: EXPORT_C TInt CPdrTypefaceStore::GetNearestFontToMaxHeightInTwips(CFont*& /*aFont*/, const TFontSpec& /*aFontSpec*/, TInt /* aMaxHeight */) sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrTypefaceStore::NumTypefaces() const sl@0: { sl@0: return iCurrentTypefaceFontsList->Count(); sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrTypefaceStore::FontHeightInTwips(TInt aTypefaceIndex, TInt aHeightIndex) const sl@0: { sl@0: TInt height = 0; sl@0: __ASSERT_DEBUG((aTypefaceIndex >= 0) && (aTypefaceIndex < NumTypefaces()), Panic(EPdrHeightIndexOutOfRange)); sl@0: CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex]; sl@0: height = typefacefonts->FontHeightInTwips(aHeightIndex); sl@0: return height; sl@0: } sl@0: sl@0: EXPORT_C void CPdrTypefaceStore::TypefaceSupport(TTypefaceSupport &aTypefaceSupport, TInt aTypefaceIndex) const sl@0: { sl@0: __ASSERT_DEBUG((aTypefaceIndex >= 0) && (aTypefaceIndex < NumTypefaces()), Panic(EPdrHeightIndexOutOfRange)); sl@0: CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex]; sl@0: aTypefaceSupport.iTypeface = typefacefonts->Typeface(); sl@0: aTypefaceSupport.iIsScalable = typefacefonts->IsScalable(); sl@0: aTypefaceSupport.iNumHeights = typefacefonts->NumFontHeights(); sl@0: aTypefaceSupport.iMinHeightInTwips = FontHeightInTwips(aTypefaceIndex, 0); // Font heights must be in ascending order sl@0: aTypefaceSupport.iMaxHeightInTwips = FontHeightInTwips(aTypefaceIndex, aTypefaceSupport.iNumHeights - 1); sl@0: } sl@0: sl@0: EXPORT_C void CPdrTypefaceStore::SetPageOrientation(TPageSpec::TPageOrientation aPageOrientation) sl@0: { sl@0: if (aPageOrientation == TPageSpec::EPortrait) sl@0: iCurrentTypefaceFontsList = iPortraitTypefaceFontsList; sl@0: else sl@0: iCurrentTypefaceFontsList = iLandscapeTypefaceFontsList; sl@0: } sl@0: sl@0: CFontInfo* CPdrTypefaceStore::FontInfoL(TStreamId aStreamId) const sl@0: { sl@0: CFontInfo* fontinfo; sl@0: TInt i; sl@0: const TInt count = iFontInfoList->Count(); sl@0: for (i = 0; (i < count) && ((*iFontInfoList)[i]->iStreamId != aStreamId); i++) sl@0: { // Searches for FontInfo with same Id sl@0: } sl@0: if (i < count) // Found sl@0: fontinfo = (*iFontInfoList)[i]; sl@0: else // Not found sl@0: { sl@0: RStoreReadStream stream; sl@0: fontinfo = new(ELeave) CFontInfo(aStreamId); sl@0: CleanupStack::PushL(fontinfo); sl@0: stream.OpenLC(*iStore, aStreamId); sl@0: fontinfo->InternalizeL(stream); sl@0: CleanupStack::PopAndDestroy(); sl@0: iFontInfoList->AppendL(fontinfo); sl@0: CleanupStack::Pop(); sl@0: } sl@0: return fontinfo; sl@0: } sl@0: sl@0: CPdrTranslates* CPdrTypefaceStore::TranslatesL(TStreamId aStreamId) const sl@0: { sl@0: CPdrTranslates* translates; sl@0: TInt i; sl@0: const TInt count = iTranslatesList->Count(); sl@0: for (i = 0; (i < count) && ((*iTranslatesList)[i]->iStreamId != aStreamId); i++) sl@0: { // Searches for Translate with same Id sl@0: } sl@0: if (i < count) // Found sl@0: translates = (*iTranslatesList)[i]; sl@0: else // Not found sl@0: { sl@0: RStoreReadStream stream; sl@0: translates = new(ELeave) CPdrTranslates; sl@0: CleanupStack::PushL(translates); sl@0: translates->iStreamId = aStreamId; sl@0: stream.OpenLC(*iStore, aStreamId); sl@0: translates->InternalizeL(stream); sl@0: CleanupStack::PopAndDestroy(); sl@0: iTranslatesList->AppendL(translates); sl@0: CleanupStack::Pop(); sl@0: } sl@0: return translates; sl@0: } sl@0: sl@0: TInt CPdrTypefaceStore::GetNearestFontHeightIndex(TInt aTypefaceIndex, TInt aHeightInTwips) const sl@0: { sl@0: CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex]; sl@0: TInt i; sl@0: TInt size = typefacefonts->NumFontHeights(); sl@0: for (i = size - 1; (i > 0) && (aHeightInTwips < typefacefonts->FontHeightInTwips(i)); i--) sl@0: { // Finds fontheight less than or equal to fontspec height sl@0: } sl@0: return i; sl@0: } sl@0: sl@0: TFontStyle CPdrTypefaceStore::GetNearestFontStyle(TInt aTypefaceIndex, TInt aHeightIndex, const TFontStyle& aFontStyle) const sl@0: { sl@0: TFontStyle fontstyle(aFontStyle); sl@0: CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex]; sl@0: while (!typefacefonts->Style(aHeightIndex, fontstyle)->iIsAvailable) sl@0: { // finds first available style sl@0: if ((fontstyle.StrokeWeight() == EStrokeWeightBold) && (fontstyle.Posture() == EPostureItalic)) sl@0: fontstyle.SetPosture(EPostureUpright); sl@0: else sl@0: { sl@0: fontstyle.SetPosture(EPostureUpright); sl@0: fontstyle.SetStrokeWeight(EStrokeWeightNormal); sl@0: } sl@0: } sl@0: return fontstyle; sl@0: } sl@0: sl@0: TBool CPdrTypefaceStore::IsFontLoaded(CFont*& aFont, const TFontSpec& aFontSpecInTwips, TInt aHeightInPixels) const sl@0: /** sl@0: @see CFbsTypefaceStore::IsFontLoaded sl@0: @see CFontStore::IsFontLoaded sl@0: */ sl@0: { sl@0: TInt i = 0; sl@0: const TInt count = iFontAccess->Count(); sl@0: for (; i < count && sl@0: !(aHeightInPixels == (*iFontAccess)[i].iFont->HeightInPixels() && sl@0: aFontSpecInTwips == (*iFontAccess)[i].iFont->FontSpecInTwips()); i++) sl@0: { sl@0: } sl@0: if (i < count) sl@0: { sl@0: aFont = (*iFontAccess)[i].iFont; sl@0: (*iFontAccess)[i].iAccessCount++; sl@0: return ETrue; sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: CInfoFont* CPdrTypefaceStore::NewFontL(TInt aBaselineOffsetInPixels, const TFontSpec& aFontSpecInTwips, TInt aFontInfoHeightInTwips, TInt aHeightInPixels, CPdrTranslates* aTranslates, const TDesC8& aCommandString, TStreamId aFontInfoStreamId) sl@0: { sl@0: CInfoFont* infofont = new(ELeave) CInfoFont(aBaselineOffsetInPixels, aFontSpecInTwips, aFontInfoHeightInTwips, aHeightInPixels, aTranslates, aCommandString, iPdrDevice); sl@0: CleanupStack::PushL(infofont); sl@0: AddFontL(infofont); sl@0: CleanupStack::Pop(); sl@0: TRAPD(ret, infofont->iFontInfo = FontInfoL(aFontInfoStreamId)); sl@0: if (ret != KErrNone) sl@0: { sl@0: ReleaseFont(infofont); sl@0: User::Leave(ret); sl@0: } sl@0: return infofont; sl@0: } sl@0: sl@0: TInt CPdrTypefaceStore::VerticalTwipsToPixels(TInt aTwipsHeight) const sl@0: { sl@0: return (1000 * aTwipsHeight + (iKPixelHeightInTwips / 2)) / iKPixelHeightInTwips; sl@0: }