os/graphics/printingservices/printerdriversupport/src/PDRSTORE.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <pdrstore.h>
sl@0
    17
#include <banddev.h>
sl@0
    18
#include "PDRBODY.H"
sl@0
    19
#include "PDRSTD.H"
sl@0
    20
#include "pdrtext.h"
sl@0
    21
sl@0
    22
EXPORT_C CPdrResources::CPdrResources():
sl@0
    23
	iNumResources(0),
sl@0
    24
	iResourceList(NULL)
sl@0
    25
	{
sl@0
    26
	__DECLARE_NAME(_S("CPdrResources"));
sl@0
    27
	}
sl@0
    28
sl@0
    29
EXPORT_C void CPdrResources::RestoreL(CStreamStore& aStore, TStreamId aStreamId)
sl@0
    30
	{
sl@0
    31
	RStoreReadStream stream;
sl@0
    32
	stream.OpenLC(aStore, aStreamId);
sl@0
    33
	iNumResources = stream.ReadInt32L();
sl@0
    34
	iResourceList = new(ELeave) TPdrResource[iNumResources];
sl@0
    35
	for (TInt i = 0; i < iNumResources; i++)
sl@0
    36
		iResourceList[i].InternalizeL(stream);
sl@0
    37
	CleanupStack::PopAndDestroy();
sl@0
    38
	}
sl@0
    39
sl@0
    40
EXPORT_C CPdrResources::~CPdrResources()
sl@0
    41
	{
sl@0
    42
	delete[] iResourceList;
sl@0
    43
	iResourceList = NULL;
sl@0
    44
	iNumResources = 0;
sl@0
    45
	}
sl@0
    46
sl@0
    47
EXPORT_C TPtrC8 CPdrResources::ResourceString(TInt anId) const
sl@0
    48
	{
sl@0
    49
	TPtrC8 ptr;
sl@0
    50
	TPdrResource* pEnd = iResourceList + iNumResources;
sl@0
    51
	TPdrResource* p ;
sl@0
    52
	for( p = iResourceList; (p < pEnd) && (p->iId != anId); p++)
sl@0
    53
		{
sl@0
    54
		}
sl@0
    55
	if (p < pEnd)
sl@0
    56
		ptr.Set(p->iString);
sl@0
    57
	return ptr;
sl@0
    58
	}
sl@0
    59
sl@0
    60
CInfoFont::CInfoFont(TInt aBaselineOffsetInPixels, const TFontSpec& aFontSpecInTwips, TInt aFontInfoHeightInTwips, TInt aHeightInPixels, CPdrTranslates* aTranslates, const TDesC8& aCommandString, CPdrDevice* aPdrDevice):
sl@0
    61
	CFont(),
sl@0
    62
	iCommandString(aCommandString),	
sl@0
    63
	iBaselineOffsetInPixels(aBaselineOffsetInPixels),
sl@0
    64
	iFontSpecInTwips(aFontSpecInTwips),
sl@0
    65
	iFontInfoHeightInTwips(aFontInfoHeightInTwips),
sl@0
    66
	iHeightInPixels(aHeightInPixels),
sl@0
    67
	iFontInfo(NULL),
sl@0
    68
	iTranslates(aTranslates),
sl@0
    69
	iPdrDevice(aPdrDevice),
sl@0
    70
	iRealFont(NULL)
sl@0
    71
	{
sl@0
    72
	CreateBandedFontIfRequired();
sl@0
    73
	}
sl@0
    74
sl@0
    75
CInfoFont::~CInfoFont()
sl@0
    76
	{
sl@0
    77
	if (iRealFont)
sl@0
    78
		if (iPdrDevice->iControl)
sl@0
    79
			((CPdrControl*)(iPdrDevice->iControl))->BandedDevice()->ReleaseFont(iRealFont);
sl@0
    80
	}
sl@0
    81
sl@0
    82
void CInfoFont::CreateBandedFontIfRequired()
sl@0
    83
	{
sl@0
    84
	if (!iRealFont)
sl@0
    85
		{
sl@0
    86
		if (iPdrDevice->iControl)
sl@0
    87
			{
sl@0
    88
			if (((CPdrControl*)(iPdrDevice->iControl))->BandedDevice())
sl@0
    89
				((CPdrControl*)(iPdrDevice->iControl))->BandedDevice()->GetNearestFontToDesignHeightInTwips(iRealFont, iFontSpecInTwips);
sl@0
    90
			}
sl@0
    91
		}
sl@0
    92
	}
sl@0
    93
sl@0
    94
EXPORT_C TUid CInfoFont::DoTypeUid() const
sl@0
    95
	{
sl@0
    96
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
    97
	return TUid::Uid(KCInfoFontUidVal);
sl@0
    98
	}
sl@0
    99
sl@0
   100
EXPORT_C TInt CInfoFont::DoHeightInPixels() const
sl@0
   101
	{
sl@0
   102
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   103
	return iHeightInPixels;
sl@0
   104
	}
sl@0
   105
sl@0
   106
EXPORT_C TInt CInfoFont::DoAscentInPixels() const
sl@0
   107
	{
sl@0
   108
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   109
	return Height(iFontInfo->iAscentInPixels);
sl@0
   110
	}
sl@0
   111
sl@0
   112
EXPORT_C TInt CInfoFont::DoCharWidthInPixels(TChar aChar) const
sl@0
   113
	{
sl@0
   114
	TInt width;
sl@0
   115
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   116
	if (RepertoireContains(aChar))
sl@0
   117
		{
sl@0
   118
		width = iFontInfo->CharWidthInPixels(TUint(aChar));
sl@0
   119
		width = Width(width);
sl@0
   120
		}
sl@0
   121
	else
sl@0
   122
		{
sl@0
   123
		if (iRealFont)
sl@0
   124
			width = iRealFont->CharWidthInPixels(TUint(aChar));
sl@0
   125
		else
sl@0
   126
			width = 0;
sl@0
   127
		}
sl@0
   128
	return width;
sl@0
   129
	}
sl@0
   130
sl@0
   131
EXPORT_C TInt CInfoFont::DoTextWidthInPixels(const TDesC &aText) const
sl@0
   132
	{
sl@0
   133
	TMeasureTextOutput output;
sl@0
   134
	TInt advance_width = MeasureText(aText,NULL,&output);
sl@0
   135
	return Max(advance_width,output.iBounds.Width());
sl@0
   136
	}
sl@0
   137
sl@0
   138
EXPORT_C TInt CInfoFont::DoBaselineOffsetInPixels() const
sl@0
   139
	{
sl@0
   140
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   141
	return iBaselineOffsetInPixels;
sl@0
   142
	}
sl@0
   143
sl@0
   144
EXPORT_C TInt CInfoFont::DoTextCount(const TDesC &aText, TInt aWidthInPixels) const
sl@0
   145
	{
sl@0
   146
	TInt count = 0;
sl@0
   147
	TInt width = 0;
sl@0
   148
	TInt length = aText.Length();
sl@0
   149
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   150
	for (count = 0; (count < length) && ((width += MeasureText(aText.Mid(count, 1))) < aWidthInPixels); )
sl@0
   151
		{
sl@0
   152
		count++;
sl@0
   153
		}
sl@0
   154
	return count;
sl@0
   155
	}
sl@0
   156
sl@0
   157
EXPORT_C TInt CInfoFont::DoTextCount(const TDesC &aText, TInt aWidthInPixels, TInt &aExcessWidthInPixels) const
sl@0
   158
	{
sl@0
   159
	TInt count = TextCount(aText, aWidthInPixels);
sl@0
   160
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   161
	aExcessWidthInPixels = aWidthInPixels - MeasureText(aText.Left(count));
sl@0
   162
	return count;
sl@0
   163
	}
sl@0
   164
sl@0
   165
EXPORT_C TInt CInfoFont::DoMaxCharWidthInPixels() const
sl@0
   166
	{
sl@0
   167
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   168
	TInt width = Width(iFontInfo->iMaxCharWidthInPixels);
sl@0
   169
	if (iRealFont)
sl@0
   170
		return Max(iRealFont->MaxCharWidthInPixels(),width);
sl@0
   171
	return width;
sl@0
   172
	}
sl@0
   173
sl@0
   174
EXPORT_C TInt CInfoFont::DoMaxNormalCharWidthInPixels() const
sl@0
   175
	{
sl@0
   176
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   177
	TInt width = Width(iFontInfo->iMaxNormalCharWidthInPixels);
sl@0
   178
	if (iRealFont)
sl@0
   179
		return Max(iRealFont->MaxNormalCharWidthInPixels(),width);
sl@0
   180
	return width;
sl@0
   181
	}
sl@0
   182
sl@0
   183
EXPORT_C TFontSpec CInfoFont::DoFontSpecInTwips() const
sl@0
   184
	{
sl@0
   185
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   186
	return iFontSpecInTwips;	
sl@0
   187
	}
sl@0
   188
sl@0
   189
EXPORT_C HBufC8* CInfoFont::TranslateStringL(const TDesC& aString) const  
sl@0
   190
	{
sl@0
   191
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   192
	return iTranslates->TranslateStringL(aString);
sl@0
   193
	}
sl@0
   194
sl@0
   195
EXPORT_C TPtrC8 CInfoFont::CommandString() const
sl@0
   196
	{
sl@0
   197
	TPtrC8 ptr;
sl@0
   198
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   199
	ptr.Set(iCommandString);
sl@0
   200
	return ptr;
sl@0
   201
	}
sl@0
   202
sl@0
   203
EXPORT_C TBool CInfoFont::RepertoireContains(TChar aChar) const
sl@0
   204
	{
sl@0
   205
	CFontInfo* fontInfo = FontInfo();
sl@0
   206
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   207
	for (TInt i = 0; i < fontInfo->NumCodeSections(); i++)
sl@0
   208
		{
sl@0
   209
		if (((TInt)(TUint)aChar >= fontInfo->CodeSection(i).iStart) && ((TInt)(TUint)aChar<= fontInfo->CodeSection(i).iEnd))
sl@0
   210
			return ETrue;
sl@0
   211
		}
sl@0
   212
	return EFalse;
sl@0
   213
	}
sl@0
   214
sl@0
   215
EXPORT_C TBool CInfoFont::AllCharsInFontRepertoire(const TDesC& aString, TInt& aFirstCharNotInRepertoire, TInt& aLength) const
sl@0
   216
	{
sl@0
   217
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   218
	for (aFirstCharNotInRepertoire = 0; aFirstCharNotInRepertoire < aString.Length(); aFirstCharNotInRepertoire++)
sl@0
   219
		if (!(RepertoireContains(aString[aFirstCharNotInRepertoire])))
sl@0
   220
			{
sl@0
   221
			if (aFirstCharNotInRepertoire == 0)
sl@0
   222
				{	// Work out length
sl@0
   223
				for (aLength = aFirstCharNotInRepertoire; aLength < aString.Length(); aLength++)
sl@0
   224
					if ((RepertoireContains(aString[aLength])))
sl@0
   225
						break;
sl@0
   226
				}
sl@0
   227
			return EFalse;
sl@0
   228
			}
sl@0
   229
	return ETrue;
sl@0
   230
	}
sl@0
   231
sl@0
   232
CFont* CInfoFont::RealFont() const
sl@0
   233
	{
sl@0
   234
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   235
	return iRealFont;
sl@0
   236
	}
sl@0
   237
sl@0
   238
TInt CInfoFont::Width(TInt aNum) const
sl@0
   239
	{
sl@0
   240
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   241
	return (aNum * iFontSpecInTwips.iHeight + (iFontInfoHeightInTwips / 2)) / iFontInfoHeightInTwips;
sl@0
   242
	}
sl@0
   243
sl@0
   244
TInt CInfoFont::Height(TInt aNum) const
sl@0
   245
	{
sl@0
   246
	CONST_CAST(CInfoFont*,this)->CreateBandedFontIfRequired();
sl@0
   247
	return (aNum * iFontSpecInTwips.iHeight + (iFontInfoHeightInTwips / 2)) / iFontInfoHeightInTwips;
sl@0
   248
	}
sl@0
   249
sl@0
   250
EXPORT_C void TTypefaceFontsEntry::InternalizeL(RReadStream& aStream)
sl@0
   251
	{
sl@0
   252
	aStream >> iStreamId;
sl@0
   253
	iNotInPortrait = aStream.ReadUint8L();
sl@0
   254
	iNotInLandscape = aStream.ReadUint8L();
sl@0
   255
	}
sl@0
   256
sl@0
   257
EXPORT_C CPdrModelInfo::CPdrModelInfo():
sl@0
   258
	iFlags(0),
sl@0
   259
	iKPixelWidthInTwips(0),
sl@0
   260
	iKPixelHeightInTwips(0),
sl@0
   261
	iPortraitOffsetInPixels(),
sl@0
   262
	iLandscapeOffsetInPixels(),
sl@0
   263
//	iMinMarginsInPixels(),
sl@0
   264
	iDisplayMode(EGray2),
sl@0
   265
	iNumTypefaceFonts(0),
sl@0
   266
	iTypefaceFontsEntryList(NULL),
sl@0
   267
	iResourcesStreamId(KNullStreamId),
sl@0
   268
	iSpareStreamId(KNullStreamId)
sl@0
   269
	{
sl@0
   270
	__DECLARE_NAME(_S("CPdrModelInfo"));
sl@0
   271
	}
sl@0
   272
sl@0
   273
EXPORT_C CPdrModelInfo::~CPdrModelInfo()
sl@0
   274
	{
sl@0
   275
	delete[] iTypefaceFontsEntryList;
sl@0
   276
	}
sl@0
   277
sl@0
   278
EXPORT_C void CPdrModelInfo::InternalizeL(RReadStream& aStream)
sl@0
   279
	{
sl@0
   280
	TInt pdrtranversion = aStream.ReadInt32L();
sl@0
   281
	if (pdrtranversion < KPdrtranVersion)
sl@0
   282
		User::Leave(KErrNotSupported);
sl@0
   283
	iFlags = aStream.ReadInt32L();
sl@0
   284
	iKPixelWidthInTwips = aStream.ReadInt32L();
sl@0
   285
	iKPixelHeightInTwips = aStream.ReadInt32L();
sl@0
   286
	iPortraitOffsetInPixels.iX = aStream.ReadInt32L();
sl@0
   287
	iPortraitOffsetInPixels.iY = aStream.ReadInt32L();
sl@0
   288
	iLandscapeOffsetInPixels.iX = aStream.ReadInt32L();
sl@0
   289
	iLandscapeOffsetInPixels.iY = aStream.ReadInt32L();
sl@0
   290
	iMinMarginsInPixels.InternalizeL(aStream);
sl@0
   291
	iDisplayMode = (TDisplayMode)aStream.ReadInt32L();
sl@0
   292
	iNumTypefaceFonts = aStream.ReadInt32L();
sl@0
   293
	iTypefaceFontsEntryList = new(ELeave) TTypefaceFontsEntry[iNumTypefaceFonts];
sl@0
   294
	TTypefaceFontsEntry* pEnd = iTypefaceFontsEntryList+iNumTypefaceFonts;
sl@0
   295
	for(TTypefaceFontsEntry* p = iTypefaceFontsEntryList; p < pEnd; p++)
sl@0
   296
		p->InternalizeL(aStream);
sl@0
   297
	aStream >> iResourcesStreamId; 
sl@0
   298
	aStream >> iSpareStreamId; 
sl@0
   299
	}
sl@0
   300
sl@0
   301
CPdrTypefaceStore::CPdrTypefaceStore(CStreamStore& aStore, TInt aKPixelHeightInTwips, CPdrDevice* aPdrDevice):
sl@0
   302
	iPdrDevice(aPdrDevice),
sl@0
   303
	iStore(&aStore),
sl@0
   304
	iKPixelHeightInTwips(aKPixelHeightInTwips)
sl@0
   305
	{
sl@0
   306
	}
sl@0
   307
sl@0
   308
void CPdrTypefaceStore::ConstructL(TInt aNumTypefaceFonts, TTypefaceFontsEntry* aTypefaceFontsEntryList, TPageSpec::TPageOrientation aPageOrientation)
sl@0
   309
	{
sl@0
   310
	CTypefaceStore::ConstructL();
sl@0
   311
	iTranslatesList = new(ELeave) CArrayPtrFlat<CPdrTranslates>(8);
sl@0
   312
	iTypefaceFontsList = new(ELeave) CArrayPtrFlat<CTypefaceFonts>(8);
sl@0
   313
	iPortraitTypefaceFontsList = new(ELeave) CArrayPtrFlat<CTypefaceFonts>(8);
sl@0
   314
	iLandscapeTypefaceFontsList = new(ELeave) CArrayPtrFlat<CTypefaceFonts>(8);
sl@0
   315
	iFontInfoList = new(ELeave) CArrayPtrFlat<CFontInfo>(8);
sl@0
   316
	for (TInt i = 0; i < aNumTypefaceFonts; i++)
sl@0
   317
		{
sl@0
   318
		CTypefaceFonts* typefacefonts = new(ELeave) CTypefaceFonts;
sl@0
   319
		CleanupStack::PushL(typefacefonts);
sl@0
   320
		RStoreReadStream stream;
sl@0
   321
		stream.OpenLC(*iStore, aTypefaceFontsEntryList[i].iStreamId);
sl@0
   322
		typefacefonts->InternalizeL(stream);
sl@0
   323
		CleanupStack::PopAndDestroy();
sl@0
   324
		iTypefaceFontsList->AppendL(typefacefonts);
sl@0
   325
		CleanupStack::Pop();
sl@0
   326
		typefacefonts->iTranslates=TranslatesL(typefacefonts->iTranslates.AsId());
sl@0
   327
		if (!aTypefaceFontsEntryList[i].iNotInPortrait)
sl@0
   328
			iPortraitTypefaceFontsList->AppendL(typefacefonts);
sl@0
   329
		if (!aTypefaceFontsEntryList[i].iNotInLandscape)
sl@0
   330
			iLandscapeTypefaceFontsList->AppendL(typefacefonts);
sl@0
   331
		}
sl@0
   332
	SetPageOrientation(aPageOrientation);
sl@0
   333
	}
sl@0
   334
sl@0
   335
EXPORT_C CPdrTypefaceStore* CPdrTypefaceStore::NewL(CStreamStore& aStore, TInt aNumTypefacesFonts, TTypefaceFontsEntry* aTypefaceFontsEntryList, TPageSpec::TPageOrientation aPageOrientation, TInt aKPixelHeightInTwips, CPdrDevice* aPdrDevice)
sl@0
   336
	{
sl@0
   337
	CPdrTypefaceStore* typefacestore = new(ELeave) CPdrTypefaceStore(aStore, aKPixelHeightInTwips, aPdrDevice);
sl@0
   338
	CleanupStack::PushL(typefacestore);
sl@0
   339
	typefacestore->ConstructL(aNumTypefacesFonts, aTypefaceFontsEntryList, aPageOrientation);
sl@0
   340
	CleanupStack::Pop();
sl@0
   341
	return typefacestore;
sl@0
   342
	}
sl@0
   343
sl@0
   344
EXPORT_C CPdrTypefaceStore::~CPdrTypefaceStore()
sl@0
   345
	{
sl@0
   346
	if (iTranslatesList)
sl@0
   347
		iTranslatesList->ResetAndDestroy();
sl@0
   348
	delete iTranslatesList;
sl@0
   349
	if (iTypefaceFontsList)
sl@0
   350
		iTypefaceFontsList->ResetAndDestroy();
sl@0
   351
	delete iTypefaceFontsList;
sl@0
   352
	delete iPortraitTypefaceFontsList;
sl@0
   353
	delete iLandscapeTypefaceFontsList;
sl@0
   354
	if (iFontInfoList)
sl@0
   355
		iFontInfoList->ResetAndDestroy();
sl@0
   356
	delete iFontInfoList;
sl@0
   357
	}
sl@0
   358
sl@0
   359
/**
sl@0
   360
@internalTechnology
sl@0
   361
*/
sl@0
   362
EXPORT_C TInt CPdrTypefaceStore::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
sl@0
   363
	{
sl@0
   364
	return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
sl@0
   365
	}
sl@0
   366
sl@0
   367
/**
sl@0
   368
@internalTechnology
sl@0
   369
*/
sl@0
   370
EXPORT_C TInt CPdrTypefaceStore::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
sl@0
   371
	{
sl@0
   372
	aFont = NULL;
sl@0
   373
	const TInt count = iCurrentTypefaceFontsList->Count();
sl@0
   374
	if (count)
sl@0
   375
		{
sl@0
   376
		TInt index = 0;
sl@0
   377
		TTypeface typeface = aFontSpec.iTypeface;
sl@0
   378
		for (index = 0; (index < count) && typeface.iName.CompareF((*iCurrentTypefaceFontsList)[index]->Typeface().iName); index++)
sl@0
   379
			{ // tries matching typeface name
sl@0
   380
			}
sl@0
   381
		if (index == count)
sl@0
   382
			{
sl@0
   383
			if (!typeface.IsSymbol())
sl@0
   384
				{
sl@0
   385
				for (index = 0; (index < count) && (((*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()) ||
sl@0
   386
													(typeface.IsProportional() != (*iCurrentTypefaceFontsList)[index]->Typeface().IsProportional()) || 
sl@0
   387
													(typeface.IsSerif() != (*iCurrentTypefaceFontsList)[index]->Typeface().IsSerif())); index++)
sl@0
   388
					{ // tries matching typeface flags
sl@0
   389
					}
sl@0
   390
				if (index == count)
sl@0
   391
					for (index = 0; (index < count) && (((*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()) ||
sl@0
   392
														(typeface.IsProportional() != (*iCurrentTypefaceFontsList)[index]->Typeface().IsProportional())); index++)
sl@0
   393
						{ // tries matching typeface flag
sl@0
   394
						}
sl@0
   395
				if (index == count)
sl@0
   396
					for (index = 0; (index < count) && ((*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()); index++)
sl@0
   397
						{ // tries matching typeface flag
sl@0
   398
						}
sl@0
   399
				}
sl@0
   400
			else
sl@0
   401
				{
sl@0
   402
				for (index = 0; (index < count) && (!(*iCurrentTypefaceFontsList)[index]->Typeface().IsSymbol()); index++)
sl@0
   403
					{ // finds first symbol typeface
sl@0
   404
					}
sl@0
   405
				}
sl@0
   406
			}
sl@0
   407
		if (index == count)
sl@0
   408
			index = 0;
sl@0
   409
		CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[index];
sl@0
   410
		if (typefacefonts->NumFontHeights())
sl@0
   411
			{
sl@0
   412
			TFontSpec fontspec(aFontSpec);
sl@0
   413
			fontspec.iTypeface = typefacefonts->Typeface();
sl@0
   414
			TInt i = GetNearestFontHeightIndex(index, aFontSpec.iHeight);
sl@0
   415
			fontspec.iHeight = typefacefonts->FontHeightInTwips(i);
sl@0
   416
			if (fontspec.iFontStyle.PrintPosition() != EPrintPosNormal)
sl@0
   417
				{
sl@0
   418
				i = GetNearestFontHeightIndex(index, SuperSubHeight(fontspec.iHeight, fontspec.iFontStyle.PrintPosition()));
sl@0
   419
				}
sl@0
   420
			fontspec.iFontStyle = GetNearestFontStyle(index, i, fontspec.iFontStyle);
sl@0
   421
			TInt heightintwips = typefacefonts->FontHeightInTwips(i);
sl@0
   422
			TInt height = VerticalTwipsToPixels(heightintwips);
sl@0
   423
			if (IsFontLoaded(aFont, fontspec, height))
sl@0
   424
				return KErrNone;
sl@0
   425
			TInt baselineoffset = BaselineOffset(VerticalTwipsToPixels(fontspec.iHeight), fontspec.iFontStyle.PrintPosition());
sl@0
   426
			TInt fontinfoheight = ((fontspec.iHeight * typefacefonts->FontInfoHeightInTwips(i) + (heightintwips / 2))) / heightintwips;
sl@0
   427
			CPdrTranslates* translates = typefacefonts->iTranslates;
sl@0
   428
			TCommandString commandstring;
sl@0
   429
			typefacefonts->CommandString(commandstring, i);
sl@0
   430
			TStreamId fontinfostreamid = typefacefonts->Style(i, fontspec.iFontStyle)->iFontInfoStreamId;
sl@0
   431
			TRAPD(ret, aFont = NewFontL(baselineoffset, fontspec, fontinfoheight, height, translates, commandstring, fontinfostreamid));
sl@0
   432
			return ret;
sl@0
   433
			}
sl@0
   434
		}
sl@0
   435
	return KErrNotFound;
sl@0
   436
	}
sl@0
   437
sl@0
   438
/**
sl@0
   439
@internalTechnology
sl@0
   440
*/
sl@0
   441
EXPORT_C TInt CPdrTypefaceStore::GetNearestFontToMaxHeightInTwips(CFont*& /*aFont*/, const TFontSpec& /*aFontSpec*/, TInt /* aMaxHeight */)
sl@0
   442
	{
sl@0
   443
	return KErrNotSupported;
sl@0
   444
	}
sl@0
   445
sl@0
   446
EXPORT_C TInt CPdrTypefaceStore::NumTypefaces() const
sl@0
   447
	{
sl@0
   448
	return iCurrentTypefaceFontsList->Count();
sl@0
   449
	}
sl@0
   450
sl@0
   451
EXPORT_C TInt CPdrTypefaceStore::FontHeightInTwips(TInt aTypefaceIndex, TInt aHeightIndex) const
sl@0
   452
	{
sl@0
   453
	TInt height = 0;
sl@0
   454
	__ASSERT_DEBUG((aTypefaceIndex >= 0) && (aTypefaceIndex < NumTypefaces()), Panic(EPdrHeightIndexOutOfRange));
sl@0
   455
	CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex];
sl@0
   456
	height = typefacefonts->FontHeightInTwips(aHeightIndex);
sl@0
   457
	return height;
sl@0
   458
	}
sl@0
   459
sl@0
   460
EXPORT_C void CPdrTypefaceStore::TypefaceSupport(TTypefaceSupport &aTypefaceSupport, TInt aTypefaceIndex) const
sl@0
   461
	{
sl@0
   462
	__ASSERT_DEBUG((aTypefaceIndex >= 0) && (aTypefaceIndex < NumTypefaces()), Panic(EPdrHeightIndexOutOfRange));
sl@0
   463
	CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex];
sl@0
   464
	aTypefaceSupport.iTypeface = typefacefonts->Typeface();
sl@0
   465
	aTypefaceSupport.iIsScalable = typefacefonts->IsScalable();
sl@0
   466
	aTypefaceSupport.iNumHeights = typefacefonts->NumFontHeights();
sl@0
   467
	aTypefaceSupport.iMinHeightInTwips = FontHeightInTwips(aTypefaceIndex, 0);  // Font heights must be in ascending order
sl@0
   468
	aTypefaceSupport.iMaxHeightInTwips = FontHeightInTwips(aTypefaceIndex, aTypefaceSupport.iNumHeights - 1);
sl@0
   469
	}
sl@0
   470
sl@0
   471
EXPORT_C void CPdrTypefaceStore::SetPageOrientation(TPageSpec::TPageOrientation aPageOrientation)
sl@0
   472
	{
sl@0
   473
	if (aPageOrientation == TPageSpec::EPortrait)
sl@0
   474
		iCurrentTypefaceFontsList = iPortraitTypefaceFontsList;
sl@0
   475
	else
sl@0
   476
		iCurrentTypefaceFontsList = iLandscapeTypefaceFontsList;
sl@0
   477
	}
sl@0
   478
sl@0
   479
CFontInfo* CPdrTypefaceStore::FontInfoL(TStreamId aStreamId) const
sl@0
   480
	{
sl@0
   481
	CFontInfo* fontinfo;
sl@0
   482
	TInt i;
sl@0
   483
	const TInt count = iFontInfoList->Count();
sl@0
   484
	for (i = 0; (i < count) && ((*iFontInfoList)[i]->iStreamId != aStreamId); i++)
sl@0
   485
		{  // Searches for FontInfo with same Id
sl@0
   486
		}
sl@0
   487
	if (i < count)  // Found
sl@0
   488
		fontinfo = (*iFontInfoList)[i];
sl@0
   489
	else			// Not found
sl@0
   490
		{
sl@0
   491
		RStoreReadStream stream;
sl@0
   492
		fontinfo = new(ELeave) CFontInfo(aStreamId);
sl@0
   493
		CleanupStack::PushL(fontinfo);
sl@0
   494
		stream.OpenLC(*iStore, aStreamId);
sl@0
   495
		fontinfo->InternalizeL(stream);
sl@0
   496
		CleanupStack::PopAndDestroy();
sl@0
   497
		iFontInfoList->AppendL(fontinfo);
sl@0
   498
		CleanupStack::Pop();
sl@0
   499
		}
sl@0
   500
	return fontinfo;
sl@0
   501
	}
sl@0
   502
sl@0
   503
CPdrTranslates* CPdrTypefaceStore::TranslatesL(TStreamId aStreamId) const
sl@0
   504
	{
sl@0
   505
	CPdrTranslates* translates;
sl@0
   506
	TInt i;
sl@0
   507
	const TInt count = iTranslatesList->Count();
sl@0
   508
	for (i = 0; (i < count) && ((*iTranslatesList)[i]->iStreamId != aStreamId); i++)
sl@0
   509
		{  // Searches for Translate with same Id
sl@0
   510
		}
sl@0
   511
	if (i < count)  // Found
sl@0
   512
		translates = (*iTranslatesList)[i];
sl@0
   513
	else			// Not found
sl@0
   514
		{
sl@0
   515
		RStoreReadStream stream;
sl@0
   516
		translates = new(ELeave) CPdrTranslates;
sl@0
   517
		CleanupStack::PushL(translates);
sl@0
   518
		translates->iStreamId = aStreamId;
sl@0
   519
		stream.OpenLC(*iStore, aStreamId);
sl@0
   520
		translates->InternalizeL(stream);
sl@0
   521
		CleanupStack::PopAndDestroy();
sl@0
   522
		iTranslatesList->AppendL(translates);
sl@0
   523
		CleanupStack::Pop();
sl@0
   524
		}
sl@0
   525
	return translates;
sl@0
   526
	}
sl@0
   527
sl@0
   528
TInt CPdrTypefaceStore::GetNearestFontHeightIndex(TInt aTypefaceIndex, TInt aHeightInTwips) const
sl@0
   529
	{
sl@0
   530
	CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex];
sl@0
   531
	TInt i;
sl@0
   532
	TInt size = typefacefonts->NumFontHeights();
sl@0
   533
	for (i = size - 1; (i > 0) && (aHeightInTwips < typefacefonts->FontHeightInTwips(i)); i--)
sl@0
   534
		{  //  Finds fontheight less than or equal to fontspec height
sl@0
   535
		}
sl@0
   536
	return i;
sl@0
   537
	}
sl@0
   538
sl@0
   539
TFontStyle CPdrTypefaceStore::GetNearestFontStyle(TInt aTypefaceIndex, TInt aHeightIndex, const TFontStyle& aFontStyle) const
sl@0
   540
	{
sl@0
   541
	TFontStyle fontstyle(aFontStyle);
sl@0
   542
	CTypefaceFonts* typefacefonts = (*iCurrentTypefaceFontsList)[aTypefaceIndex];
sl@0
   543
	while (!typefacefonts->Style(aHeightIndex, fontstyle)->iIsAvailable)
sl@0
   544
		{  //  finds first available style
sl@0
   545
		if ((fontstyle.StrokeWeight() == EStrokeWeightBold) && (fontstyle.Posture() == EPostureItalic))
sl@0
   546
			fontstyle.SetPosture(EPostureUpright);
sl@0
   547
		else
sl@0
   548
			{
sl@0
   549
			fontstyle.SetPosture(EPostureUpright);
sl@0
   550
			fontstyle.SetStrokeWeight(EStrokeWeightNormal);
sl@0
   551
			}
sl@0
   552
		}
sl@0
   553
	return fontstyle;
sl@0
   554
	}
sl@0
   555
sl@0
   556
TBool CPdrTypefaceStore::IsFontLoaded(CFont*& aFont, const TFontSpec& aFontSpecInTwips, TInt aHeightInPixels) const
sl@0
   557
/**
sl@0
   558
@see CFbsTypefaceStore::IsFontLoaded
sl@0
   559
@see CFontStore::IsFontLoaded
sl@0
   560
*/
sl@0
   561
	{
sl@0
   562
	TInt i = 0;
sl@0
   563
	const TInt count = iFontAccess->Count();
sl@0
   564
	for (; i < count &&
sl@0
   565
			!(aHeightInPixels  == (*iFontAccess)[i].iFont->HeightInPixels() &&
sl@0
   566
			  aFontSpecInTwips == (*iFontAccess)[i].iFont->FontSpecInTwips()); i++)
sl@0
   567
		{
sl@0
   568
		}
sl@0
   569
	if (i < count)
sl@0
   570
		{
sl@0
   571
		aFont = (*iFontAccess)[i].iFont;
sl@0
   572
		(*iFontAccess)[i].iAccessCount++;
sl@0
   573
		return ETrue;
sl@0
   574
		}
sl@0
   575
	return EFalse;
sl@0
   576
	}
sl@0
   577
sl@0
   578
CInfoFont* CPdrTypefaceStore::NewFontL(TInt aBaselineOffsetInPixels, const TFontSpec& aFontSpecInTwips, TInt aFontInfoHeightInTwips, TInt aHeightInPixels, CPdrTranslates* aTranslates, const TDesC8& aCommandString, TStreamId aFontInfoStreamId)
sl@0
   579
	{
sl@0
   580
	CInfoFont* infofont = new(ELeave) CInfoFont(aBaselineOffsetInPixels, aFontSpecInTwips, aFontInfoHeightInTwips, aHeightInPixels, aTranslates, aCommandString, iPdrDevice);
sl@0
   581
	CleanupStack::PushL(infofont);
sl@0
   582
	AddFontL(infofont);
sl@0
   583
	CleanupStack::Pop();
sl@0
   584
	TRAPD(ret, infofont->iFontInfo = FontInfoL(aFontInfoStreamId));
sl@0
   585
	if (ret != KErrNone)
sl@0
   586
		{
sl@0
   587
		ReleaseFont(infofont);
sl@0
   588
		User::Leave(ret);
sl@0
   589
		}
sl@0
   590
	return infofont;
sl@0
   591
	}
sl@0
   592
sl@0
   593
TInt CPdrTypefaceStore::VerticalTwipsToPixels(TInt aTwipsHeight) const
sl@0
   594
	{
sl@0
   595
	return (1000 * aTwipsHeight + (iKPixelHeightInTwips / 2)) / iKPixelHeightInTwips;
sl@0
   596
	}