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