1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/printingservices/printerdriversupport/src/PDRSTORE.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,596 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <pdrstore.h>
1.20 +#include <banddev.h>
1.21 +#include "PDRBODY.H"
1.22 +#include "PDRSTD.H"
1.23 +#include "pdrtext.h"
1.24 +
1.25 +EXPORT_C CPdrResources::CPdrResources():
1.26 + iNumResources(0),
1.27 + iResourceList(NULL)
1.28 + {
1.29 + __DECLARE_NAME(_S("CPdrResources"));
1.30 + }
1.31 +
1.32 +EXPORT_C void CPdrResources::RestoreL(CStreamStore& aStore, TStreamId aStreamId)
1.33 + {
1.34 + RStoreReadStream stream;
1.35 + stream.OpenLC(aStore, aStreamId);
1.36 + iNumResources = stream.ReadInt32L();
1.37 + iResourceList = new(ELeave) TPdrResource[iNumResources];
1.38 + for (TInt i = 0; i < iNumResources; i++)
1.39 + iResourceList[i].InternalizeL(stream);
1.40 + CleanupStack::PopAndDestroy();
1.41 + }
1.42 +
1.43 +EXPORT_C CPdrResources::~CPdrResources()
1.44 + {
1.45 + delete[] iResourceList;
1.46 + iResourceList = NULL;
1.47 + iNumResources = 0;
1.48 + }
1.49 +
1.50 +EXPORT_C TPtrC8 CPdrResources::ResourceString(TInt anId) const
1.51 + {
1.52 + TPtrC8 ptr;
1.53 + TPdrResource* pEnd = iResourceList + iNumResources;
1.54 + TPdrResource* p ;
1.55 + for( p = iResourceList; (p < pEnd) && (p->iId != anId); p++)
1.56 + {
1.57 + }
1.58 + if (p < pEnd)
1.59 + ptr.Set(p->iString);
1.60 + return ptr;
1.61 + }
1.62 +
1.63 +CInfoFont::CInfoFont(TInt aBaselineOffsetInPixels, const TFontSpec& aFontSpecInTwips, TInt aFontInfoHeightInTwips, TInt aHeightInPixels, CPdrTranslates* aTranslates, const TDesC8& aCommandString, CPdrDevice* aPdrDevice):
1.64 + CFont(),
1.65 + iCommandString(aCommandString),
1.66 + iBaselineOffsetInPixels(aBaselineOffsetInPixels),
1.67 + iFontSpecInTwips(aFontSpecInTwips),
1.68 + iFontInfoHeightInTwips(aFontInfoHeightInTwips),
1.69 + iHeightInPixels(aHeightInPixels),
1.70 + iFontInfo(NULL),
1.71 + iTranslates(aTranslates),
1.72 + iPdrDevice(aPdrDevice),
1.73 + iRealFont(NULL)
1.74 + {
1.75 + CreateBandedFontIfRequired();
1.76 + }
1.77 +
1.78 +CInfoFont::~CInfoFont()
1.79 + {
1.80 + if (iRealFont)
1.81 + if (iPdrDevice->iControl)
1.82 + ((CPdrControl*)(iPdrDevice->iControl))->BandedDevice()->ReleaseFont(iRealFont);
1.83 + }
1.84 +
1.85 +void CInfoFont::CreateBandedFontIfRequired()
1.86 + {
1.87 + if (!iRealFont)
1.88 + {
1.89 + if (iPdrDevice->iControl)
1.90 + {
1.91 + if (((CPdrControl*)(iPdrDevice->iControl))->BandedDevice())
1.92 + ((CPdrControl*)(iPdrDevice->iControl))->BandedDevice()->GetNearestFontToDesignHeightInTwips(iRealFont, iFontSpecInTwips);
1.93 + }
1.94 + }
1.95 + }
1.96 +
1.97 +EXPORT_C TUid CInfoFont::DoTypeUid() const
1.98 + {
1.99 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.100 + return TUid::Uid(KCInfoFontUidVal);
1.101 + }
1.102 +
1.103 +EXPORT_C TInt CInfoFont::DoHeightInPixels() const
1.104 + {
1.105 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.106 + return iHeightInPixels;
1.107 + }
1.108 +
1.109 +EXPORT_C TInt CInfoFont::DoAscentInPixels() const
1.110 + {
1.111 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.112 + return Height(iFontInfo->iAscentInPixels);
1.113 + }
1.114 +
1.115 +EXPORT_C TInt CInfoFont::DoCharWidthInPixels(TChar aChar) const
1.116 + {
1.117 + TInt width;
1.118 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.119 + if (RepertoireContains(aChar))
1.120 + {
1.121 + width = iFontInfo->CharWidthInPixels(TUint(aChar));
1.122 + width = Width(width);
1.123 + }
1.124 + else
1.125 + {
1.126 + if (iRealFont)
1.127 + width = iRealFont->CharWidthInPixels(TUint(aChar));
1.128 + else
1.129 + width = 0;
1.130 + }
1.131 + return width;
1.132 + }
1.133 +
1.134 +EXPORT_C TInt CInfoFont::DoTextWidthInPixels(const TDesC &aText) const
1.135 + {
1.136 + TMeasureTextOutput output;
1.137 + TInt advance_width = MeasureText(aText,NULL,&output);
1.138 + return Max(advance_width,output.iBounds.Width());
1.139 + }
1.140 +
1.141 +EXPORT_C TInt CInfoFont::DoBaselineOffsetInPixels() const
1.142 + {
1.143 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.144 + return iBaselineOffsetInPixels;
1.145 + }
1.146 +
1.147 +EXPORT_C TInt CInfoFont::DoTextCount(const TDesC &aText, TInt aWidthInPixels) const
1.148 + {
1.149 + TInt count = 0;
1.150 + TInt width = 0;
1.151 + TInt length = aText.Length();
1.152 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.153 + for (count = 0; (count < length) && ((width += MeasureText(aText.Mid(count, 1))) < aWidthInPixels); )
1.154 + {
1.155 + count++;
1.156 + }
1.157 + return count;
1.158 + }
1.159 +
1.160 +EXPORT_C TInt CInfoFont::DoTextCount(const TDesC &aText, TInt aWidthInPixels, TInt &aExcessWidthInPixels) const
1.161 + {
1.162 + TInt count = TextCount(aText, aWidthInPixels);
1.163 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.164 + aExcessWidthInPixels = aWidthInPixels - MeasureText(aText.Left(count));
1.165 + return count;
1.166 + }
1.167 +
1.168 +EXPORT_C TInt CInfoFont::DoMaxCharWidthInPixels() const
1.169 + {
1.170 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.171 + TInt width = Width(iFontInfo->iMaxCharWidthInPixels);
1.172 + if (iRealFont)
1.173 + return Max(iRealFont->MaxCharWidthInPixels(),width);
1.174 + return width;
1.175 + }
1.176 +
1.177 +EXPORT_C TInt CInfoFont::DoMaxNormalCharWidthInPixels() const
1.178 + {
1.179 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.180 + TInt width = Width(iFontInfo->iMaxNormalCharWidthInPixels);
1.181 + if (iRealFont)
1.182 + return Max(iRealFont->MaxNormalCharWidthInPixels(),width);
1.183 + return width;
1.184 + }
1.185 +
1.186 +EXPORT_C TFontSpec CInfoFont::DoFontSpecInTwips() const
1.187 + {
1.188 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.189 + return iFontSpecInTwips;
1.190 + }
1.191 +
1.192 +EXPORT_C HBufC8* CInfoFont::TranslateStringL(const TDesC& aString) const
1.193 + {
1.194 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.195 + return iTranslates->TranslateStringL(aString);
1.196 + }
1.197 +
1.198 +EXPORT_C TPtrC8 CInfoFont::CommandString() const
1.199 + {
1.200 + TPtrC8 ptr;
1.201 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.202 + ptr.Set(iCommandString);
1.203 + return ptr;
1.204 + }
1.205 +
1.206 +EXPORT_C TBool CInfoFont::RepertoireContains(TChar aChar) const
1.207 + {
1.208 + CFontInfo* fontInfo = FontInfo();
1.209 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.210 + for (TInt i = 0; i < fontInfo->NumCodeSections(); i++)
1.211 + {
1.212 + if (((TInt)(TUint)aChar >= fontInfo->CodeSection(i).iStart) && ((TInt)(TUint)aChar<= fontInfo->CodeSection(i).iEnd))
1.213 + return ETrue;
1.214 + }
1.215 + return EFalse;
1.216 + }
1.217 +
1.218 +EXPORT_C TBool CInfoFont::AllCharsInFontRepertoire(const TDesC& aString, TInt& aFirstCharNotInRepertoire, TInt& aLength) const
1.219 + {
1.220 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.221 + for (aFirstCharNotInRepertoire = 0; aFirstCharNotInRepertoire < aString.Length(); aFirstCharNotInRepertoire++)
1.222 + if (!(RepertoireContains(aString[aFirstCharNotInRepertoire])))
1.223 + {
1.224 + if (aFirstCharNotInRepertoire == 0)
1.225 + { // Work out length
1.226 + for (aLength = aFirstCharNotInRepertoire; aLength < aString.Length(); aLength++)
1.227 + if ((RepertoireContains(aString[aLength])))
1.228 + break;
1.229 + }
1.230 + return EFalse;
1.231 + }
1.232 + return ETrue;
1.233 + }
1.234 +
1.235 +CFont* CInfoFont::RealFont() const
1.236 + {
1.237 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.238 + return iRealFont;
1.239 + }
1.240 +
1.241 +TInt CInfoFont::Width(TInt aNum) const
1.242 + {
1.243 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.244 + return (aNum * iFontSpecInTwips.iHeight + (iFontInfoHeightInTwips / 2)) / iFontInfoHeightInTwips;
1.245 + }
1.246 +
1.247 +TInt CInfoFont::Height(TInt aNum) const
1.248 + {
1.249 + CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
1.250 + return (aNum * iFontSpecInTwips.iHeight + (iFontInfoHeightInTwips / 2)) / iFontInfoHeightInTwips;
1.251 + }
1.252 +
1.253 +EXPORT_C void TTypefaceFontsEntry::InternalizeL(RReadStream& aStream)
1.254 + {
1.255 + aStream >> iStreamId;
1.256 + iNotInPortrait = aStream.ReadUint8L();
1.257 + iNotInLandscape = aStream.ReadUint8L();
1.258 + }
1.259 +
1.260 +EXPORT_C CPdrModelInfo::CPdrModelInfo():
1.261 + iFlags(0),
1.262 + iKPixelWidthInTwips(0),
1.263 + iKPixelHeightInTwips(0),
1.264 + iPortraitOffsetInPixels(),
1.265 + iLandscapeOffsetInPixels(),
1.266 +// iMinMarginsInPixels(),
1.267 + iDisplayMode(EGray2),
1.268 + iNumTypefaceFonts(0),
1.269 + iTypefaceFontsEntryList(NULL),
1.270 + iResourcesStreamId(KNullStreamId),
1.271 + iSpareStreamId(KNullStreamId)
1.272 + {
1.273 + __DECLARE_NAME(_S("CPdrModelInfo"));
1.274 + }
1.275 +
1.276 +EXPORT_C CPdrModelInfo::~CPdrModelInfo()
1.277 + {
1.278 + delete[] iTypefaceFontsEntryList;
1.279 + }
1.280 +
1.281 +EXPORT_C void CPdrModelInfo::InternalizeL(RReadStream& aStream)
1.282 + {
1.283 + TInt pdrtranversion = aStream.ReadInt32L();
1.284 + if (pdrtranversion < KPdrtranVersion)
1.285 + User::Leave(KErrNotSupported);
1.286 + iFlags = aStream.ReadInt32L();
1.287 + iKPixelWidthInTwips = aStream.ReadInt32L();
1.288 + iKPixelHeightInTwips = aStream.ReadInt32L();
1.289 + iPortraitOffsetInPixels.iX = aStream.ReadInt32L();
1.290 + iPortraitOffsetInPixels.iY = aStream.ReadInt32L();
1.291 + iLandscapeOffsetInPixels.iX = aStream.ReadInt32L();
1.292 + iLandscapeOffsetInPixels.iY = aStream.ReadInt32L();
1.293 + iMinMarginsInPixels.InternalizeL(aStream);
1.294 + iDisplayMode = (TDisplayMode)aStream.ReadInt32L();
1.295 + iNumTypefaceFonts = aStream.ReadInt32L();
1.296 + iTypefaceFontsEntryList = new(ELeave) TTypefaceFontsEntry[iNumTypefaceFonts];
1.297 + TTypefaceFontsEntry* pEnd = iTypefaceFontsEntryList+iNumTypefaceFonts;
1.298 + for(TTypefaceFontsEntry* p = iTypefaceFontsEntryList; p < pEnd; p++)
1.299 + p->InternalizeL(aStream);
1.300 + aStream >> iResourcesStreamId;
1.301 + aStream >> iSpareStreamId;
1.302 + }
1.303 +
1.304 +CPdrTypefaceStore::CPdrTypefaceStore(CStreamStore& aStore, TInt aKPixelHeightInTwips, CPdrDevice* aPdrDevice):
1.305 + iPdrDevice(aPdrDevice),
1.306 + iStore(&aStore),
1.307 + iKPixelHeightInTwips(aKPixelHeightInTwips)
1.308 + {
1.309 + }
1.310 +
1.311 +void CPdrTypefaceStore::ConstructL(TInt aNumTypefaceFonts, TTypefaceFontsEntry* aTypefaceFontsEntryList, TPageSpec::TPageOrientation aPageOrientation)
1.312 + {
1.313 + CTypefaceStore::ConstructL();
1.314 + iTranslatesList = new(ELeave) CArrayPtrFlat<CPdrTranslates>(8);
1.315 + iTypefaceFontsList = new(ELeave) CArrayPtrFlat<CTypefaceFonts>(8);
1.316 + iPortraitTypefaceFontsList = new(ELeave) CArrayPtrFlat<CTypefaceFonts>(8);
1.317 + iLandscapeTypefaceFontsList = new(ELeave) CArrayPtrFlat<CTypefaceFonts>(8);
1.318 + iFontInfoList = new(ELeave) CArrayPtrFlat<CFontInfo>(8);
1.319 + for (TInt i = 0; i < aNumTypefaceFonts; i++)
1.320 + {
1.321 + CTypefaceFonts* typefacefonts = new(ELeave) CTypefaceFonts;
1.322 + CleanupStack::PushL(typefacefonts);
1.323 + RStoreReadStream stream;
1.324 + stream.OpenLC(*iStore, aTypefaceFontsEntryList[i].iStreamId);
1.325 + typefacefonts->InternalizeL(stream);
1.326 + CleanupStack::PopAndDestroy();
1.327 + iTypefaceFontsList->AppendL(typefacefonts);
1.328 + CleanupStack::Pop();
1.329 + typefacefonts->iTranslates=TranslatesL(typefacefonts->iTranslates.AsId());
1.330 + if (!aTypefaceFontsEntryList[i].iNotInPortrait)
1.331 + iPortraitTypefaceFontsList->AppendL(typefacefonts);
1.332 + if (!aTypefaceFontsEntryList[i].iNotInLandscape)
1.333 + iLandscapeTypefaceFontsList->AppendL(typefacefonts);
1.334 + }
1.335 + SetPageOrientation(aPageOrientation);
1.336 + }
1.337 +
1.338 +EXPORT_C CPdrTypefaceStore* CPdrTypefaceStore::NewL(CStreamStore& aStore, TInt aNumTypefacesFonts, TTypefaceFontsEntry* aTypefaceFontsEntryList, TPageSpec::TPageOrientation aPageOrientation, TInt aKPixelHeightInTwips, CPdrDevice* aPdrDevice)
1.339 + {
1.340 + CPdrTypefaceStore* typefacestore = new(ELeave) CPdrTypefaceStore(aStore, aKPixelHeightInTwips, aPdrDevice);
1.341 + CleanupStack::PushL(typefacestore);
1.342 + typefacestore->ConstructL(aNumTypefacesFonts, aTypefaceFontsEntryList, aPageOrientation);
1.343 + CleanupStack::Pop();
1.344 + return typefacestore;
1.345 + }
1.346 +
1.347 +EXPORT_C CPdrTypefaceStore::~CPdrTypefaceStore()
1.348 + {
1.349 + if (iTranslatesList)
1.350 + iTranslatesList->ResetAndDestroy();
1.351 + delete iTranslatesList;
1.352 + if (iTypefaceFontsList)
1.353 + iTypefaceFontsList->ResetAndDestroy();
1.354 + delete iTypefaceFontsList;
1.355 + delete iPortraitTypefaceFontsList;
1.356 + delete iLandscapeTypefaceFontsList;
1.357 + if (iFontInfoList)
1.358 + iFontInfoList->ResetAndDestroy();
1.359 + delete iFontInfoList;
1.360 + }
1.361 +
1.362 +/**
1.363 +@internalTechnology
1.364 +*/
1.365 +EXPORT_C TInt CPdrTypefaceStore::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
1.366 + {
1.367 + return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
1.368 + }
1.369 +
1.370 +/**
1.371 +@internalTechnology
1.372 +*/
1.373 +EXPORT_C TInt CPdrTypefaceStore::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
1.374 + {
1.375 + aFont = NULL;
1.376 + const TInt count = iCurrentTypefaceFontsList->Count();
1.377 + if (count)
1.378 + {
1.379 + TInt index = 0;
1.380 + TTypeface typeface = aFontSpec.iTypeface;
1.381 + for (index = 0; (index < count) && typeface.iName.CompareF((*iCurrentTypefaceFontsList)[index]->Typeface().iName); index++)
1.382 + { // tries matching typeface name
1.383 + }
1.384 + if (index == count)
1.385 + {
1.386 + if (!typeface.IsSymbol())
1.387 + {
1.388 + for (index = 0; (index < count) && (((*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()) ||
1.389 + (typeface.IsProportional() != (*iCurrentTypefaceFontsList)[index]->Typeface().IsProportional()) ||
1.390 + (typeface.IsSerif() != (*iCurrentTypefaceFontsList)[index]->Typeface().IsSerif())); index++)
1.391 + { // tries matching typeface flags
1.392 + }
1.393 + if (index == count)
1.394 + for (index = 0; (index < count) && (((*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()) ||
1.395 + (typeface.IsProportional() != (*iCurrentTypefaceFontsList)[index]->Typeface().IsProportional())); index++)
1.396 + { // tries matching typeface flag
1.397 + }
1.398 + if (index == count)
1.399 + for (index = 0; (index < count) && ((*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()); index++)
1.400 + { // tries matching typeface flag
1.401 + }
1.402 + }
1.403 + else
1.404 + {
1.405 + for (index = 0; (index < count) && (!(*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()); index++)
1.406 + { // finds first symbol typeface
1.407 + }
1.408 + }
1.409 + }
1.410 + if (index == count)
1.411 + index = 0;
1.412 + CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[index];
1.413 + if (typefacefonts->NumFontHeights())
1.414 + {
1.415 + TFontSpec fontspec(aFontSpec);
1.416 + fontspec.iTypeface = typefacefonts->Typeface();
1.417 + TInt i = GetNearestFontHeightIndex(index, aFontSpec.iHeight);
1.418 + fontspec.iHeight = typefacefonts->FontHeightInTwips(i);
1.419 + if (fontspec.iFontStyle.PrintPosition() != EPrintPosNormal)
1.420 + {
1.421 + i = GetNearestFontHeightIndex(index, SuperSubHeight(fontspec.iHeight, fontspec.iFontStyle.PrintPosition()));
1.422 + }
1.423 + fontspec.iFontStyle = GetNearestFontStyle(index, i, fontspec.iFontStyle);
1.424 + TInt heightintwips = typefacefonts->FontHeightInTwips(i);
1.425 + TInt height = VerticalTwipsToPixels(heightintwips);
1.426 + if (IsFontLoaded(aFont, fontspec, height))
1.427 + return KErrNone;
1.428 + TInt baselineoffset = BaselineOffset(VerticalTwipsToPixels(fontspec.iHeight), fontspec.iFontStyle.PrintPosition());
1.429 + TInt fontinfoheight = ((fontspec.iHeight * typefacefonts->FontInfoHeightInTwips(i) + (heightintwips / 2))) / heightintwips;
1.430 + CPdrTranslates* translates = typefacefonts->iTranslates;
1.431 + TCommandString commandstring;
1.432 + typefacefonts->CommandString(commandstring, i);
1.433 + TStreamId fontinfostreamid = typefacefonts->Style(i, fontspec.iFontStyle)->iFontInfoStreamId;
1.434 + TRAPD(ret, aFont = NewFontL(baselineoffset, fontspec, fontinfoheight, height, translates, commandstring, fontinfostreamid));
1.435 + return ret;
1.436 + }
1.437 + }
1.438 + return KErrNotFound;
1.439 + }
1.440 +
1.441 +/**
1.442 +@internalTechnology
1.443 +*/
1.444 +EXPORT_C TInt CPdrTypefaceStore::GetNearestFontToMaxHeightInTwips(CFont*& /*aFont*/, const TFontSpec& /*aFontSpec*/, TInt /* aMaxHeight */)
1.445 + {
1.446 + return KErrNotSupported;
1.447 + }
1.448 +
1.449 +EXPORT_C TInt CPdrTypefaceStore::NumTypefaces() const
1.450 + {
1.451 + return iCurrentTypefaceFontsList->Count();
1.452 + }
1.453 +
1.454 +EXPORT_C TInt CPdrTypefaceStore::FontHeightInTwips(TInt aTypefaceIndex, TInt aHeightIndex) const
1.455 + {
1.456 + TInt height = 0;
1.457 + __ASSERT_DEBUG((aTypefaceIndex >= 0) && (aTypefaceIndex < NumTypefaces()), Panic(EPdrHeightIndexOutOfRange));
1.458 + CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex];
1.459 + height = typefacefonts->FontHeightInTwips(aHeightIndex);
1.460 + return height;
1.461 + }
1.462 +
1.463 +EXPORT_C void CPdrTypefaceStore::TypefaceSupport(TTypefaceSupport &aTypefaceSupport, TInt aTypefaceIndex) const
1.464 + {
1.465 + __ASSERT_DEBUG((aTypefaceIndex >= 0) && (aTypefaceIndex < NumTypefaces()), Panic(EPdrHeightIndexOutOfRange));
1.466 + CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex];
1.467 + aTypefaceSupport.iTypeface = typefacefonts->Typeface();
1.468 + aTypefaceSupport.iIsScalable = typefacefonts->IsScalable();
1.469 + aTypefaceSupport.iNumHeights = typefacefonts->NumFontHeights();
1.470 + aTypefaceSupport.iMinHeightInTwips = FontHeightInTwips(aTypefaceIndex, 0); // Font heights must be in ascending order
1.471 + aTypefaceSupport.iMaxHeightInTwips = FontHeightInTwips(aTypefaceIndex, aTypefaceSupport.iNumHeights - 1);
1.472 + }
1.473 +
1.474 +EXPORT_C void CPdrTypefaceStore::SetPageOrientation(TPageSpec::TPageOrientation aPageOrientation)
1.475 + {
1.476 + if (aPageOrientation == TPageSpec::EPortrait)
1.477 + iCurrentTypefaceFontsList = iPortraitTypefaceFontsList;
1.478 + else
1.479 + iCurrentTypefaceFontsList = iLandscapeTypefaceFontsList;
1.480 + }
1.481 +
1.482 +CFontInfo* CPdrTypefaceStore::FontInfoL(TStreamId aStreamId) const
1.483 + {
1.484 + CFontInfo* fontinfo;
1.485 + TInt i;
1.486 + const TInt count = iFontInfoList->Count();
1.487 + for (i = 0; (i < count) && ((*iFontInfoList)[i]->iStreamId != aStreamId); i++)
1.488 + { // Searches for FontInfo with same Id
1.489 + }
1.490 + if (i < count) // Found
1.491 + fontinfo = (*iFontInfoList)[i];
1.492 + else // Not found
1.493 + {
1.494 + RStoreReadStream stream;
1.495 + fontinfo = new(ELeave) CFontInfo(aStreamId);
1.496 + CleanupStack::PushL(fontinfo);
1.497 + stream.OpenLC(*iStore, aStreamId);
1.498 + fontinfo->InternalizeL(stream);
1.499 + CleanupStack::PopAndDestroy();
1.500 + iFontInfoList->AppendL(fontinfo);
1.501 + CleanupStack::Pop();
1.502 + }
1.503 + return fontinfo;
1.504 + }
1.505 +
1.506 +CPdrTranslates* CPdrTypefaceStore::TranslatesL(TStreamId aStreamId) const
1.507 + {
1.508 + CPdrTranslates* translates;
1.509 + TInt i;
1.510 + const TInt count = iTranslatesList->Count();
1.511 + for (i = 0; (i < count) && ((*iTranslatesList)[i]->iStreamId != aStreamId); i++)
1.512 + { // Searches for Translate with same Id
1.513 + }
1.514 + if (i < count) // Found
1.515 + translates = (*iTranslatesList)[i];
1.516 + else // Not found
1.517 + {
1.518 + RStoreReadStream stream;
1.519 + translates = new(ELeave) CPdrTranslates;
1.520 + CleanupStack::PushL(translates);
1.521 + translates->iStreamId = aStreamId;
1.522 + stream.OpenLC(*iStore, aStreamId);
1.523 + translates->InternalizeL(stream);
1.524 + CleanupStack::PopAndDestroy();
1.525 + iTranslatesList->AppendL(translates);
1.526 + CleanupStack::Pop();
1.527 + }
1.528 + return translates;
1.529 + }
1.530 +
1.531 +TInt CPdrTypefaceStore::GetNearestFontHeightIndex(TInt aTypefaceIndex, TInt aHeightInTwips) const
1.532 + {
1.533 + CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex];
1.534 + TInt i;
1.535 + TInt size = typefacefonts->NumFontHeights();
1.536 + for (i = size - 1; (i > 0) && (aHeightInTwips < typefacefonts->FontHeightInTwips(i)); i--)
1.537 + { // Finds fontheight less than or equal to fontspec height
1.538 + }
1.539 + return i;
1.540 + }
1.541 +
1.542 +TFontStyle CPdrTypefaceStore::GetNearestFontStyle(TInt aTypefaceIndex, TInt aHeightIndex, const TFontStyle& aFontStyle) const
1.543 + {
1.544 + TFontStyle fontstyle(aFontStyle);
1.545 + CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex];
1.546 + while (!typefacefonts->Style(aHeightIndex, fontstyle)->iIsAvailable)
1.547 + { // finds first available style
1.548 + if ((fontstyle.StrokeWeight() == EStrokeWeightBold) && (fontstyle.Posture() == EPostureItalic))
1.549 + fontstyle.SetPosture(EPostureUpright);
1.550 + else
1.551 + {
1.552 + fontstyle.SetPosture(EPostureUpright);
1.553 + fontstyle.SetStrokeWeight(EStrokeWeightNormal);
1.554 + }
1.555 + }
1.556 + return fontstyle;
1.557 + }
1.558 +
1.559 +TBool CPdrTypefaceStore::IsFontLoaded(CFont*& aFont, const TFontSpec& aFontSpecInTwips, TInt aHeightInPixels) const
1.560 +/**
1.561 +@see CFbsTypefaceStore::IsFontLoaded
1.562 +@see CFontStore::IsFontLoaded
1.563 +*/
1.564 + {
1.565 + TInt i = 0;
1.566 + const TInt count = iFontAccess->Count();
1.567 + for (; i < count &&
1.568 + !(aHeightInPixels == (*iFontAccess)[i].iFont->HeightInPixels() &&
1.569 + aFontSpecInTwips == (*iFontAccess)[i].iFont->FontSpecInTwips()); i++)
1.570 + {
1.571 + }
1.572 + if (i < count)
1.573 + {
1.574 + aFont = (*iFontAccess)[i].iFont;
1.575 + (*iFontAccess)[i].iAccessCount++;
1.576 + return ETrue;
1.577 + }
1.578 + return EFalse;
1.579 + }
1.580 +
1.581 +CInfoFont* CPdrTypefaceStore::NewFontL(TInt aBaselineOffsetInPixels, const TFontSpec& aFontSpecInTwips, TInt aFontInfoHeightInTwips, TInt aHeightInPixels, CPdrTranslates* aTranslates, const TDesC8& aCommandString, TStreamId aFontInfoStreamId)
1.582 + {
1.583 + CInfoFont* infofont = new(ELeave) CInfoFont(aBaselineOffsetInPixels, aFontSpecInTwips, aFontInfoHeightInTwips, aHeightInPixels, aTranslates, aCommandString, iPdrDevice);
1.584 + CleanupStack::PushL(infofont);
1.585 + AddFontL(infofont);
1.586 + CleanupStack::Pop();
1.587 + TRAPD(ret, infofont->iFontInfo = FontInfoL(aFontInfoStreamId));
1.588 + if (ret != KErrNone)
1.589 + {
1.590 + ReleaseFont(infofont);
1.591 + User::Leave(ret);
1.592 + }
1.593 + return infofont;
1.594 + }
1.595 +
1.596 +TInt CPdrTypefaceStore::VerticalTwipsToPixels(TInt aTwipsHeight) const
1.597 + {
1.598 + return (1000 * aTwipsHeight + (iKPixelHeightInTwips / 2)) / iKPixelHeightInTwips;
1.599 + }