os/graphics/printingservices/printerdriversupport/src/PDRBODY.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 "PDRBODY.H"
sl@0
    17
#include "PDRSTD.H"
sl@0
    18
sl@0
    19
TPdrResource::TPdrResource():
sl@0
    20
	iId(0),
sl@0
    21
	iString()
sl@0
    22
	{
sl@0
    23
	}
sl@0
    24
sl@0
    25
void TPdrResource::InternalizeL(RReadStream& aStream)
sl@0
    26
	{
sl@0
    27
	iId = aStream.ReadUint8L();
sl@0
    28
	aStream >> iString;
sl@0
    29
	}
sl@0
    30
sl@0
    31
CPdrTranslation::CPdrTranslation():
sl@0
    32
	iFrom(0),
sl@0
    33
	iTo(NULL)
sl@0
    34
	{
sl@0
    35
	__DECLARE_NAME(_S("CPdrTranslation"));
sl@0
    36
	}
sl@0
    37
sl@0
    38
CPdrTranslation::~CPdrTranslation()
sl@0
    39
	{
sl@0
    40
	delete iTo;
sl@0
    41
	}
sl@0
    42
sl@0
    43
void CPdrTranslation::InternalizeL(RReadStream& aStream)
sl@0
    44
	{
sl@0
    45
	iFrom = aStream.ReadUint16L();
sl@0
    46
	iTo=HBufC8::NewL(aStream,KMaxCommandStringMaxLength);
sl@0
    47
	}
sl@0
    48
sl@0
    49
CPdrTranslates::CPdrTranslates():
sl@0
    50
	iStreamId(KNullStreamId),
sl@0
    51
	iNumTranslations(0),
sl@0
    52
	iTranslationList(NULL)
sl@0
    53
	{
sl@0
    54
	__DECLARE_NAME(_S("CPdrTranslates"));
sl@0
    55
	}
sl@0
    56
sl@0
    57
void CPdrTranslates::InternalizeL(RReadStream& aStream)
sl@0
    58
	{
sl@0
    59
	TInt size=aStream.ReadInt32L();
sl@0
    60
	iTranslationList = new(ELeave) CPdrTranslation*[size];
sl@0
    61
	for (TInt i=0; i<size; i++)
sl@0
    62
		{
sl@0
    63
		iTranslationList[i]=new(ELeave) CPdrTranslation;
sl@0
    64
		iNumTranslations++;
sl@0
    65
		iTranslationList[i]->InternalizeL(aStream);
sl@0
    66
		}
sl@0
    67
	}
sl@0
    68
sl@0
    69
CPdrTranslates::~CPdrTranslates()
sl@0
    70
	{
sl@0
    71
	for (; iNumTranslations>0; iNumTranslations--)
sl@0
    72
		delete iTranslationList[iNumTranslations-1];
sl@0
    73
	delete[] iTranslationList;
sl@0
    74
	}
sl@0
    75
sl@0
    76
HBufC8* CPdrTranslates::TranslateStringL(const TDesC& aString) const 
sl@0
    77
	{
sl@0
    78
	CPdrTranslation** pEnd=iTranslationList+iNumTranslations;
sl@0
    79
	TInt length1=aString.Length(),length2=length1;
sl@0
    80
	if (iNumTranslations)
sl@0
    81
		{
sl@0
    82
		for (TInt i=0; i<length1; i++)
sl@0
    83
			{
sl@0
    84
			for (CPdrTranslation** p=iTranslationList; p<pEnd; p++)
sl@0
    85
				if (aString[i]==(*p)->iFrom)
sl@0
    86
					length2+=(*p)->iTo->Des().Length()-1;
sl@0
    87
			}
sl@0
    88
		}
sl@0
    89
	HBufC8* string2=HBufC8::NewL(length2);
sl@0
    90
	string2->Des().Copy(aString);	
sl@0
    91
	if (iNumTranslations)
sl@0
    92
		{
sl@0
    93
		CleanupStack::PushL(string2);	
sl@0
    94
		HBufC8* string1=HBufC8::NewL(length1);
sl@0
    95
		string1->Des().Copy(aString);	
sl@0
    96
		TInt j=0;
sl@0
    97
		for (TInt i=0; i<length1; i++)
sl@0
    98
			{
sl@0
    99
			for (CPdrTranslation** p=iTranslationList; p<pEnd; p++)
sl@0
   100
				{
sl@0
   101
				if (aString[i]==(*p)->iFrom)
sl@0
   102
					{
sl@0
   103
					if ((*p)->iTo->Des().Length()==1)
sl@0
   104
						{
sl@0
   105
						string2->Des()[j]=(*p)->iTo->Des()[0];
sl@0
   106
						}
sl@0
   107
					else
sl@0
   108
						{
sl@0
   109
						string2->Des().SetLength(j);
sl@0
   110
						string2->Des().Append((*p)->iTo->Des());
sl@0
   111
						j+=(*p)->iTo->Des().Length()-1;
sl@0
   112
						if ((i+1)<length1)
sl@0
   113
							{
sl@0
   114
							string2->Des().SetLength(j+1);
sl@0
   115
							string2->Des().Append(string1->Des().Mid(i+1));
sl@0
   116
							}
sl@0
   117
						}
sl@0
   118
					}
sl@0
   119
				}
sl@0
   120
			j++;
sl@0
   121
			}
sl@0
   122
		delete string1;
sl@0
   123
		CleanupStack::Pop();
sl@0
   124
		}
sl@0
   125
	return string2;
sl@0
   126
	}
sl@0
   127
sl@0
   128
CWidthsCodeSection::CWidthsCodeSection():
sl@0
   129
	iNumWidths(0),
sl@0
   130
	iWidthList(NULL)
sl@0
   131
	{
sl@0
   132
	__DECLARE_NAME(_S("CWidthsCodeSection"));
sl@0
   133
	}
sl@0
   134
sl@0
   135
void CWidthsCodeSection::InternalizeL(RReadStream& aStream)
sl@0
   136
	{
sl@0
   137
	iCodeSection.iStart = aStream.ReadUint16L();
sl@0
   138
	iCodeSection.iEnd = aStream.ReadUint16L();
sl@0
   139
	iNumWidths = aStream.ReadInt32L();
sl@0
   140
	iWidthList = new(ELeave) TUint16[iNumWidths];
sl@0
   141
	TUint16* pEnd = iWidthList+iNumWidths;
sl@0
   142
	for (TUint16* p=iWidthList; p<pEnd; p++)
sl@0
   143
		*p = aStream.ReadUint16L();
sl@0
   144
	}
sl@0
   145
sl@0
   146
CWidthsCodeSection::~CWidthsCodeSection()
sl@0
   147
	{
sl@0
   148
	delete[] iWidthList;
sl@0
   149
	iNumWidths=0;
sl@0
   150
	iWidthList=NULL;
sl@0
   151
	}
sl@0
   152
sl@0
   153
CFontInfo::CFontInfo(TStreamId aStreamId):
sl@0
   154
	iStreamId(aStreamId),
sl@0
   155
	iAscentInPixels(0),
sl@0
   156
	iMaxCharWidthInPixels(0),
sl@0
   157
	iMaxNormalCharWidthInPixels(0),
sl@0
   158
	iNumCodeSections(0),
sl@0
   159
	iCodeSectionList(NULL)
sl@0
   160
	{
sl@0
   161
	__DECLARE_NAME(_S("CFontInfo"));
sl@0
   162
	}
sl@0
   163
sl@0
   164
void CFontInfo::InternalizeL(RReadStream &aStream)
sl@0
   165
	{
sl@0
   166
	iAscentInPixels = aStream.ReadUint16L();
sl@0
   167
	iMaxCharWidthInPixels = aStream.ReadUint16L();
sl@0
   168
	iMaxNormalCharWidthInPixels = aStream.ReadUint16L();
sl@0
   169
	TInt size = aStream.ReadInt32L();
sl@0
   170
	iCodeSectionList = new(ELeave) CWidthsCodeSection*[size];
sl@0
   171
	for (TInt i=0; i<size; i++)
sl@0
   172
		{
sl@0
   173
		iCodeSectionList[i]=new(ELeave) CWidthsCodeSection;
sl@0
   174
		iNumCodeSections++;
sl@0
   175
		iCodeSectionList[i]->InternalizeL(aStream);
sl@0
   176
		}
sl@0
   177
	}
sl@0
   178
sl@0
   179
CFontInfo::~CFontInfo()
sl@0
   180
	{
sl@0
   181
	for (; iNumCodeSections>0; iNumCodeSections--)
sl@0
   182
		delete iCodeSectionList[iNumCodeSections-1];
sl@0
   183
	delete[] iCodeSectionList;
sl@0
   184
	}
sl@0
   185
sl@0
   186
TInt CFontInfo::CharWidthInPixels(TChar aChar) const
sl@0
   187
	{
sl@0
   188
	TInt width=0,code=TUint(aChar);
sl@0
   189
	for (TInt i=0; i<iNumCodeSections; i++)
sl@0
   190
		{
sl@0
   191
		CWidthsCodeSection* p=iCodeSectionList[i];
sl@0
   192
		if ((code>=p->iCodeSection.iStart) && (code<=p->iCodeSection.iEnd))
sl@0
   193
			{
sl@0
   194
			if (p->iNumWidths==1)
sl@0
   195
				width=p->iWidthList[0];
sl@0
   196
			else 
sl@0
   197
				width = *((p->iWidthList)+(code-p->iCodeSection.iStart));
sl@0
   198
			}
sl@0
   199
		}
sl@0
   200
	return width;
sl@0
   201
	}
sl@0
   202
sl@0
   203
TInt CFontInfo::NumCodeSections() const
sl@0
   204
	{
sl@0
   205
	return iNumCodeSections;
sl@0
   206
	}
sl@0
   207
sl@0
   208
TCodeSection CFontInfo::CodeSection(TInt anIndex) const
sl@0
   209
	{
sl@0
   210
	return iCodeSectionList[anIndex]->iCodeSection;
sl@0
   211
	}
sl@0
   212
sl@0
   213
TPdrStyle::TPdrStyle():
sl@0
   214
	iIsAvailable(EFalse),
sl@0
   215
	iFontInfoStreamId(KNullStreamId)
sl@0
   216
	{
sl@0
   217
	}
sl@0
   218
sl@0
   219
void TPdrStyle::InternalizeL(RReadStream &aStream)
sl@0
   220
	{
sl@0
   221
	iIsAvailable = aStream.ReadUint8L();
sl@0
   222
	aStream >> iFontInfoStreamId;
sl@0
   223
	}	
sl@0
   224
sl@0
   225
TPdrFontHeight::TPdrFontHeight():
sl@0
   226
	iCommandString(),
sl@0
   227
	iHeightInTwips(0),
sl@0
   228
	iWidthScale(1),
sl@0
   229
	iStyle() 
sl@0
   230
	{
sl@0
   231
	}
sl@0
   232
sl@0
   233
void TPdrFontHeight::InternalizeL(RReadStream& aStream)
sl@0
   234
	{
sl@0
   235
	aStream >> iCommandString;
sl@0
   236
	iHeightInTwips = aStream.ReadInt32L();
sl@0
   237
	iWidthScale = aStream.ReadInt32L();
sl@0
   238
	for (TInt style=EStyleNormal; style<(EStyleBoldItalic+1); style++)
sl@0
   239
		iStyle[style].InternalizeL(aStream);
sl@0
   240
	}
sl@0
   241
sl@0
   242
TPdrScalableFontHeight::TPdrScalableFontHeight():
sl@0
   243
	iCommandString(),
sl@0
   244
	iHeightMinInTwips(0),
sl@0
   245
	iHeightMaxInTwips(0),
sl@0
   246
	iHeightDeltaInTwips(0),
sl@0
   247
	iStyle() 
sl@0
   248
	{
sl@0
   249
	}
sl@0
   250
sl@0
   251
void TPdrScalableFontHeight::InternalizeL(RReadStream& aStream)
sl@0
   252
	{
sl@0
   253
	aStream >> iCommandString;
sl@0
   254
	iHeightMinInTwips = aStream.ReadInt32L();
sl@0
   255
	iHeightMaxInTwips = aStream.ReadInt32L();
sl@0
   256
	iHeightDeltaInTwips = aStream.ReadInt32L();
sl@0
   257
	for (TInt style=EStyleNormal; style<(EStyleBoldItalic+1); style++)
sl@0
   258
		iStyle[style].InternalizeL(aStream);
sl@0
   259
	}
sl@0
   260
sl@0
   261
CTypefaceFonts::CTypefaceFonts():
sl@0
   262
	iTypeface(),
sl@0
   263
	iNumFontHeights(0),
sl@0
   264
	iFontHeightList(NULL),
sl@0
   265
	iScalableFontHeight(NULL),
sl@0
   266
	iTranslates()
sl@0
   267
	{
sl@0
   268
	__DECLARE_NAME(_S("CTypefaceFonts"));
sl@0
   269
	}
sl@0
   270
sl@0
   271
void CTypefaceFonts::InternalizeL(RReadStream& aStream)
sl@0
   272
	{
sl@0
   273
	iTypeface.InternalizeL(aStream);
sl@0
   274
	TInt isscalable = aStream.ReadInt8L();
sl@0
   275
 	if (!isscalable)
sl@0
   276
		{
sl@0
   277
		iNumFontHeights = aStream.ReadInt32L();
sl@0
   278
		iFontHeightList = new(ELeave) TPdrFontHeight[iNumFontHeights];
sl@0
   279
		TPdrFontHeight *pStart=iFontHeightList, *pEnd=pStart+iNumFontHeights;
sl@0
   280
		for (TPdrFontHeight *p=pStart; p<pEnd; p++)
sl@0
   281
			p->InternalizeL(aStream);
sl@0
   282
		}
sl@0
   283
	else
sl@0
   284
		{
sl@0
   285
		iScalableFontHeight = new(ELeave) TPdrScalableFontHeight;
sl@0
   286
		iScalableFontHeight->InternalizeL(aStream);
sl@0
   287
		}
sl@0
   288
	aStream >> iTranslates;
sl@0
   289
	}
sl@0
   290
sl@0
   291
CTypefaceFonts::~CTypefaceFonts()
sl@0
   292
	{
sl@0
   293
	if (!IsScalable())
sl@0
   294
		{
sl@0
   295
		iNumFontHeights=0;
sl@0
   296
		delete[] iFontHeightList;
sl@0
   297
		iFontHeightList=NULL;
sl@0
   298
		}
sl@0
   299
	else
sl@0
   300
		{
sl@0
   301
		delete iScalableFontHeight;
sl@0
   302
		iScalableFontHeight=NULL;
sl@0
   303
		}
sl@0
   304
	}
sl@0
   305
sl@0
   306
TInt CTypefaceFonts::IsScalable() const
sl@0
   307
	{
sl@0
   308
	return !iNumFontHeights;
sl@0
   309
	}
sl@0
   310
sl@0
   311
TInt CTypefaceFonts::NumFontHeights() const
sl@0
   312
	{
sl@0
   313
	TInt num;
sl@0
   314
	if (!IsScalable())
sl@0
   315
		num = iNumFontHeights;
sl@0
   316
	else
sl@0
   317
		num = ((iScalableFontHeight->iHeightMaxInTwips-iScalableFontHeight->iHeightMinInTwips)/iScalableFontHeight->iHeightDeltaInTwips) + 1;
sl@0
   318
	return num;
sl@0
   319
	}
sl@0
   320
sl@0
   321
TInt CTypefaceFonts::FontHeightInTwips(TInt aHeightIndex) const
sl@0
   322
	{
sl@0
   323
	TInt height=0;
sl@0
   324
	__ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndex<NumFontHeights()),Panic(EPdrHeightIndexOutOfRange));
sl@0
   325
	if (!IsScalable())
sl@0
   326
		height = iFontHeightList[aHeightIndex].iHeightInTwips;
sl@0
   327
	else
sl@0
   328
		height = iScalableFontHeight->iHeightMinInTwips + (iScalableFontHeight->iHeightDeltaInTwips*aHeightIndex);
sl@0
   329
	return height;
sl@0
   330
	}
sl@0
   331
sl@0
   332
TInt CTypefaceFonts::FontInfoHeightInTwips(TInt aHeightIndex) const
sl@0
   333
	{
sl@0
   334
	TInt height=0;
sl@0
   335
	__ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndex<NumFontHeights()),Panic(EPdrHeightIndexOutOfRange));
sl@0
   336
	if (!IsScalable())
sl@0
   337
		height = iFontHeightList[aHeightIndex].iHeightInTwips/iFontHeightList[aHeightIndex].iWidthScale;
sl@0
   338
	else
sl@0
   339
		height = KScalableWidthTableHeightInTwips;
sl@0
   340
	return height;
sl@0
   341
	}
sl@0
   342
sl@0
   343
void CTypefaceFonts::CommandString(TDes8& aDes,TInt aHeightIndex) const
sl@0
   344
	{
sl@0
   345
	__ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndex<NumFontHeights()),Panic(EPdrHeightIndexOutOfRange));
sl@0
   346
	if (!IsScalable())
sl@0
   347
		aDes=iFontHeightList[aHeightIndex].iCommandString;
sl@0
   348
	else
sl@0
   349
		{
sl@0
   350
		TInt heightinpoints=FontHeightInTwips(aHeightIndex)/KTwipsPerPoint;
sl@0
   351
		aDes.Format(iScalableFontHeight->iCommandString,heightinpoints);
sl@0
   352
		}
sl@0
   353
	}
sl@0
   354
sl@0
   355
TPdrStyle* CTypefaceFonts::Style(TInt aHeightIndex,TFontStyle& aFontStyle) const
sl@0
   356
	{
sl@0
   357
	TPdrStyle* style=NULL;
sl@0
   358
	TStyleIndex index=StyleIndex(aFontStyle);
sl@0
   359
	__ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndex<NumFontHeights()),Panic(EPdrHeightIndexOutOfRange));
sl@0
   360
	if (!IsScalable())
sl@0
   361
		style = iFontHeightList[aHeightIndex].iStyle+index;
sl@0
   362
	else
sl@0
   363
		style = iScalableFontHeight->iStyle+index;
sl@0
   364
	return style;
sl@0
   365
	}
sl@0
   366
sl@0
   367
TTypeface CTypefaceFonts::Typeface()
sl@0
   368
	{
sl@0
   369
	return iTypeface;
sl@0
   370
	}
sl@0
   371
sl@0
   372
TStyleIndex CTypefaceFonts::StyleIndex(TFontStyle& aFontStyle) const
sl@0
   373
	{
sl@0
   374
	TStyleIndex index;
sl@0
   375
	if (aFontStyle.StrokeWeight()==EStrokeWeightNormal)
sl@0
   376
		{
sl@0
   377
		if (aFontStyle.Posture()==EPostureUpright)
sl@0
   378
			index=EStyleNormal;
sl@0
   379
		else
sl@0
   380
			index=EStyleItalic;
sl@0
   381
		}
sl@0
   382
	else
sl@0
   383
		{
sl@0
   384
		if (aFontStyle.Posture()==EPostureUpright)
sl@0
   385
			index=EStyleBold;
sl@0
   386
		else
sl@0
   387
			index=EStyleBoldItalic;
sl@0
   388
		}
sl@0
   389
	return index;
sl@0
   390
	}