1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/printingservices/printerdriversupport/src/PDRBODY.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,390 @@
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 "PDRBODY.H"
1.20 +#include "PDRSTD.H"
1.21 +
1.22 +TPdrResource::TPdrResource():
1.23 + iId(0),
1.24 + iString()
1.25 + {
1.26 + }
1.27 +
1.28 +void TPdrResource::InternalizeL(RReadStream& aStream)
1.29 + {
1.30 + iId = aStream.ReadUint8L();
1.31 + aStream >> iString;
1.32 + }
1.33 +
1.34 +CPdrTranslation::CPdrTranslation():
1.35 + iFrom(0),
1.36 + iTo(NULL)
1.37 + {
1.38 + __DECLARE_NAME(_S("CPdrTranslation"));
1.39 + }
1.40 +
1.41 +CPdrTranslation::~CPdrTranslation()
1.42 + {
1.43 + delete iTo;
1.44 + }
1.45 +
1.46 +void CPdrTranslation::InternalizeL(RReadStream& aStream)
1.47 + {
1.48 + iFrom = aStream.ReadUint16L();
1.49 + iTo=HBufC8::NewL(aStream,KMaxCommandStringMaxLength);
1.50 + }
1.51 +
1.52 +CPdrTranslates::CPdrTranslates():
1.53 + iStreamId(KNullStreamId),
1.54 + iNumTranslations(0),
1.55 + iTranslationList(NULL)
1.56 + {
1.57 + __DECLARE_NAME(_S("CPdrTranslates"));
1.58 + }
1.59 +
1.60 +void CPdrTranslates::InternalizeL(RReadStream& aStream)
1.61 + {
1.62 + TInt size=aStream.ReadInt32L();
1.63 + iTranslationList = new(ELeave) CPdrTranslation*[size];
1.64 + for (TInt i=0; i<size; i++)
1.65 + {
1.66 + iTranslationList[i]=new(ELeave) CPdrTranslation;
1.67 + iNumTranslations++;
1.68 + iTranslationList[i]->InternalizeL(aStream);
1.69 + }
1.70 + }
1.71 +
1.72 +CPdrTranslates::~CPdrTranslates()
1.73 + {
1.74 + for (; iNumTranslations>0; iNumTranslations--)
1.75 + delete iTranslationList[iNumTranslations-1];
1.76 + delete[] iTranslationList;
1.77 + }
1.78 +
1.79 +HBufC8* CPdrTranslates::TranslateStringL(const TDesC& aString) const
1.80 + {
1.81 + CPdrTranslation** pEnd=iTranslationList+iNumTranslations;
1.82 + TInt length1=aString.Length(),length2=length1;
1.83 + if (iNumTranslations)
1.84 + {
1.85 + for (TInt i=0; i<length1; i++)
1.86 + {
1.87 + for (CPdrTranslation** p=iTranslationList; p<pEnd; p++)
1.88 + if (aString[i]==(*p)->iFrom)
1.89 + length2+=(*p)->iTo->Des().Length()-1;
1.90 + }
1.91 + }
1.92 + HBufC8* string2=HBufC8::NewL(length2);
1.93 + string2->Des().Copy(aString);
1.94 + if (iNumTranslations)
1.95 + {
1.96 + CleanupStack::PushL(string2);
1.97 + HBufC8* string1=HBufC8::NewL(length1);
1.98 + string1->Des().Copy(aString);
1.99 + TInt j=0;
1.100 + for (TInt i=0; i<length1; i++)
1.101 + {
1.102 + for (CPdrTranslation** p=iTranslationList; p<pEnd; p++)
1.103 + {
1.104 + if (aString[i]==(*p)->iFrom)
1.105 + {
1.106 + if ((*p)->iTo->Des().Length()==1)
1.107 + {
1.108 + string2->Des()[j]=(*p)->iTo->Des()[0];
1.109 + }
1.110 + else
1.111 + {
1.112 + string2->Des().SetLength(j);
1.113 + string2->Des().Append((*p)->iTo->Des());
1.114 + j+=(*p)->iTo->Des().Length()-1;
1.115 + if ((i+1)<length1)
1.116 + {
1.117 + string2->Des().SetLength(j+1);
1.118 + string2->Des().Append(string1->Des().Mid(i+1));
1.119 + }
1.120 + }
1.121 + }
1.122 + }
1.123 + j++;
1.124 + }
1.125 + delete string1;
1.126 + CleanupStack::Pop();
1.127 + }
1.128 + return string2;
1.129 + }
1.130 +
1.131 +CWidthsCodeSection::CWidthsCodeSection():
1.132 + iNumWidths(0),
1.133 + iWidthList(NULL)
1.134 + {
1.135 + __DECLARE_NAME(_S("CWidthsCodeSection"));
1.136 + }
1.137 +
1.138 +void CWidthsCodeSection::InternalizeL(RReadStream& aStream)
1.139 + {
1.140 + iCodeSection.iStart = aStream.ReadUint16L();
1.141 + iCodeSection.iEnd = aStream.ReadUint16L();
1.142 + iNumWidths = aStream.ReadInt32L();
1.143 + iWidthList = new(ELeave) TUint16[iNumWidths];
1.144 + TUint16* pEnd = iWidthList+iNumWidths;
1.145 + for (TUint16* p=iWidthList; p<pEnd; p++)
1.146 + *p = aStream.ReadUint16L();
1.147 + }
1.148 +
1.149 +CWidthsCodeSection::~CWidthsCodeSection()
1.150 + {
1.151 + delete[] iWidthList;
1.152 + iNumWidths=0;
1.153 + iWidthList=NULL;
1.154 + }
1.155 +
1.156 +CFontInfo::CFontInfo(TStreamId aStreamId):
1.157 + iStreamId(aStreamId),
1.158 + iAscentInPixels(0),
1.159 + iMaxCharWidthInPixels(0),
1.160 + iMaxNormalCharWidthInPixels(0),
1.161 + iNumCodeSections(0),
1.162 + iCodeSectionList(NULL)
1.163 + {
1.164 + __DECLARE_NAME(_S("CFontInfo"));
1.165 + }
1.166 +
1.167 +void CFontInfo::InternalizeL(RReadStream &aStream)
1.168 + {
1.169 + iAscentInPixels = aStream.ReadUint16L();
1.170 + iMaxCharWidthInPixels = aStream.ReadUint16L();
1.171 + iMaxNormalCharWidthInPixels = aStream.ReadUint16L();
1.172 + TInt size = aStream.ReadInt32L();
1.173 + iCodeSectionList = new(ELeave) CWidthsCodeSection*[size];
1.174 + for (TInt i=0; i<size; i++)
1.175 + {
1.176 + iCodeSectionList[i]=new(ELeave) CWidthsCodeSection;
1.177 + iNumCodeSections++;
1.178 + iCodeSectionList[i]->InternalizeL(aStream);
1.179 + }
1.180 + }
1.181 +
1.182 +CFontInfo::~CFontInfo()
1.183 + {
1.184 + for (; iNumCodeSections>0; iNumCodeSections--)
1.185 + delete iCodeSectionList[iNumCodeSections-1];
1.186 + delete[] iCodeSectionList;
1.187 + }
1.188 +
1.189 +TInt CFontInfo::CharWidthInPixels(TChar aChar) const
1.190 + {
1.191 + TInt width=0,code=TUint(aChar);
1.192 + for (TInt i=0; i<iNumCodeSections; i++)
1.193 + {
1.194 + CWidthsCodeSection* p=iCodeSectionList[i];
1.195 + if ((code>=p->iCodeSection.iStart) && (code<=p->iCodeSection.iEnd))
1.196 + {
1.197 + if (p->iNumWidths==1)
1.198 + width=p->iWidthList[0];
1.199 + else
1.200 + width = *((p->iWidthList)+(code-p->iCodeSection.iStart));
1.201 + }
1.202 + }
1.203 + return width;
1.204 + }
1.205 +
1.206 +TInt CFontInfo::NumCodeSections() const
1.207 + {
1.208 + return iNumCodeSections;
1.209 + }
1.210 +
1.211 +TCodeSection CFontInfo::CodeSection(TInt anIndex) const
1.212 + {
1.213 + return iCodeSectionList[anIndex]->iCodeSection;
1.214 + }
1.215 +
1.216 +TPdrStyle::TPdrStyle():
1.217 + iIsAvailable(EFalse),
1.218 + iFontInfoStreamId(KNullStreamId)
1.219 + {
1.220 + }
1.221 +
1.222 +void TPdrStyle::InternalizeL(RReadStream &aStream)
1.223 + {
1.224 + iIsAvailable = aStream.ReadUint8L();
1.225 + aStream >> iFontInfoStreamId;
1.226 + }
1.227 +
1.228 +TPdrFontHeight::TPdrFontHeight():
1.229 + iCommandString(),
1.230 + iHeightInTwips(0),
1.231 + iWidthScale(1),
1.232 + iStyle()
1.233 + {
1.234 + }
1.235 +
1.236 +void TPdrFontHeight::InternalizeL(RReadStream& aStream)
1.237 + {
1.238 + aStream >> iCommandString;
1.239 + iHeightInTwips = aStream.ReadInt32L();
1.240 + iWidthScale = aStream.ReadInt32L();
1.241 + for (TInt style=EStyleNormal; style<(EStyleBoldItalic+1); style++)
1.242 + iStyle[style].InternalizeL(aStream);
1.243 + }
1.244 +
1.245 +TPdrScalableFontHeight::TPdrScalableFontHeight():
1.246 + iCommandString(),
1.247 + iHeightMinInTwips(0),
1.248 + iHeightMaxInTwips(0),
1.249 + iHeightDeltaInTwips(0),
1.250 + iStyle()
1.251 + {
1.252 + }
1.253 +
1.254 +void TPdrScalableFontHeight::InternalizeL(RReadStream& aStream)
1.255 + {
1.256 + aStream >> iCommandString;
1.257 + iHeightMinInTwips = aStream.ReadInt32L();
1.258 + iHeightMaxInTwips = aStream.ReadInt32L();
1.259 + iHeightDeltaInTwips = aStream.ReadInt32L();
1.260 + for (TInt style=EStyleNormal; style<(EStyleBoldItalic+1); style++)
1.261 + iStyle[style].InternalizeL(aStream);
1.262 + }
1.263 +
1.264 +CTypefaceFonts::CTypefaceFonts():
1.265 + iTypeface(),
1.266 + iNumFontHeights(0),
1.267 + iFontHeightList(NULL),
1.268 + iScalableFontHeight(NULL),
1.269 + iTranslates()
1.270 + {
1.271 + __DECLARE_NAME(_S("CTypefaceFonts"));
1.272 + }
1.273 +
1.274 +void CTypefaceFonts::InternalizeL(RReadStream& aStream)
1.275 + {
1.276 + iTypeface.InternalizeL(aStream);
1.277 + TInt isscalable = aStream.ReadInt8L();
1.278 + if (!isscalable)
1.279 + {
1.280 + iNumFontHeights = aStream.ReadInt32L();
1.281 + iFontHeightList = new(ELeave) TPdrFontHeight[iNumFontHeights];
1.282 + TPdrFontHeight *pStart=iFontHeightList, *pEnd=pStart+iNumFontHeights;
1.283 + for (TPdrFontHeight *p=pStart; p<pEnd; p++)
1.284 + p->InternalizeL(aStream);
1.285 + }
1.286 + else
1.287 + {
1.288 + iScalableFontHeight = new(ELeave) TPdrScalableFontHeight;
1.289 + iScalableFontHeight->InternalizeL(aStream);
1.290 + }
1.291 + aStream >> iTranslates;
1.292 + }
1.293 +
1.294 +CTypefaceFonts::~CTypefaceFonts()
1.295 + {
1.296 + if (!IsScalable())
1.297 + {
1.298 + iNumFontHeights=0;
1.299 + delete[] iFontHeightList;
1.300 + iFontHeightList=NULL;
1.301 + }
1.302 + else
1.303 + {
1.304 + delete iScalableFontHeight;
1.305 + iScalableFontHeight=NULL;
1.306 + }
1.307 + }
1.308 +
1.309 +TInt CTypefaceFonts::IsScalable() const
1.310 + {
1.311 + return !iNumFontHeights;
1.312 + }
1.313 +
1.314 +TInt CTypefaceFonts::NumFontHeights() const
1.315 + {
1.316 + TInt num;
1.317 + if (!IsScalable())
1.318 + num = iNumFontHeights;
1.319 + else
1.320 + num = ((iScalableFontHeight->iHeightMaxInTwips-iScalableFontHeight->iHeightMinInTwips)/iScalableFontHeight->iHeightDeltaInTwips) + 1;
1.321 + return num;
1.322 + }
1.323 +
1.324 +TInt CTypefaceFonts::FontHeightInTwips(TInt aHeightIndex) const
1.325 + {
1.326 + TInt height=0;
1.327 + __ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndex<NumFontHeights()),Panic(EPdrHeightIndexOutOfRange));
1.328 + if (!IsScalable())
1.329 + height = iFontHeightList[aHeightIndex].iHeightInTwips;
1.330 + else
1.331 + height = iScalableFontHeight->iHeightMinInTwips + (iScalableFontHeight->iHeightDeltaInTwips*aHeightIndex);
1.332 + return height;
1.333 + }
1.334 +
1.335 +TInt CTypefaceFonts::FontInfoHeightInTwips(TInt aHeightIndex) const
1.336 + {
1.337 + TInt height=0;
1.338 + __ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndex<NumFontHeights()),Panic(EPdrHeightIndexOutOfRange));
1.339 + if (!IsScalable())
1.340 + height = iFontHeightList[aHeightIndex].iHeightInTwips/iFontHeightList[aHeightIndex].iWidthScale;
1.341 + else
1.342 + height = KScalableWidthTableHeightInTwips;
1.343 + return height;
1.344 + }
1.345 +
1.346 +void CTypefaceFonts::CommandString(TDes8& aDes,TInt aHeightIndex) const
1.347 + {
1.348 + __ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndex<NumFontHeights()),Panic(EPdrHeightIndexOutOfRange));
1.349 + if (!IsScalable())
1.350 + aDes=iFontHeightList[aHeightIndex].iCommandString;
1.351 + else
1.352 + {
1.353 + TInt heightinpoints=FontHeightInTwips(aHeightIndex)/KTwipsPerPoint;
1.354 + aDes.Format(iScalableFontHeight->iCommandString,heightinpoints);
1.355 + }
1.356 + }
1.357 +
1.358 +TPdrStyle* CTypefaceFonts::Style(TInt aHeightIndex,TFontStyle& aFontStyle) const
1.359 + {
1.360 + TPdrStyle* style=NULL;
1.361 + TStyleIndex index=StyleIndex(aFontStyle);
1.362 + __ASSERT_DEBUG((aHeightIndex>=0) && (aHeightIndex<NumFontHeights()),Panic(EPdrHeightIndexOutOfRange));
1.363 + if (!IsScalable())
1.364 + style = iFontHeightList[aHeightIndex].iStyle+index;
1.365 + else
1.366 + style = iScalableFontHeight->iStyle+index;
1.367 + return style;
1.368 + }
1.369 +
1.370 +TTypeface CTypefaceFonts::Typeface()
1.371 + {
1.372 + return iTypeface;
1.373 + }
1.374 +
1.375 +TStyleIndex CTypefaceFonts::StyleIndex(TFontStyle& aFontStyle) const
1.376 + {
1.377 + TStyleIndex index;
1.378 + if (aFontStyle.StrokeWeight()==EStrokeWeightNormal)
1.379 + {
1.380 + if (aFontStyle.Posture()==EPostureUpright)
1.381 + index=EStyleNormal;
1.382 + else
1.383 + index=EStyleItalic;
1.384 + }
1.385 + else
1.386 + {
1.387 + if (aFontStyle.Posture()==EPostureUpright)
1.388 + index=EStyleBold;
1.389 + else
1.390 + index=EStyleBoldItalic;
1.391 + }
1.392 + return index;
1.393 + }