1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/textrendering/texthandling/stext/TXTFRMAT.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,937 @@
1.4 +/*
1.5 +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include <e32std.h>
1.23 +#include <e32base.h>
1.24 +
1.25 +#include <gdi.h>
1.26 +#include "TXTFRMAT.H"
1.27 +
1.28 +#include "TXTSTD.H"
1.29 +#include "OstTraceDefinitions.h"
1.30 +#ifdef OST_TRACE_COMPILER_IN_USE
1.31 +#include "TXTFRMATTraces.h"
1.32 +#endif
1.33 +
1.34 +
1.35 +
1.36 +const TInt KParaDefaultLanguage=0;
1.37 +const TInt KParaDefaultLeftMargin=0;
1.38 +const TInt KParaDefaultRightMargin=0;
1.39 +const TInt KParaDefaultIndent=0;
1.40 +const CParaFormat::TAlignment KParaDefaultHorizAlign=CParaFormat::ELeftAlign;
1.41 +const CParaFormat::TAlignment KParaDefaultVertAlign=CParaFormat::EUnspecifiedAlign;
1.42 +const TInt KParaDefaultLineSpacing=200; // 200 twips = 10pt
1.43 +const CParaFormat::TLineSpacingControl KParaDefaultLineSpacingControl=CParaFormat::ELineSpacingAtLeastInTwips;
1.44 +const TInt KParaDefaultSpaceBefore=0;
1.45 +const TInt KParaDefaultSpaceAfter=0;
1.46 +const TBool KParaDefaultKeepTogether=EFalse;
1.47 +const TBool KParaDefaultKeepWithNext=EFalse;
1.48 +const TBool KParaDefaultStartNewPage=EFalse;
1.49 +const TBool KParaDefaultWidowOrphan=EFalse;
1.50 +const TBool KParaDefaultWrap=ETrue;
1.51 +const TInt KParaDefaultBorderMargin=0;
1.52 +const TInt KParaDefaultTabWidth=360; // 360 twips = 0.25"
1.53 +const TUint KParFormatBits = (2 << EAttTabStop) - 1;
1.54 +const TUint KCharFormatBits = (2 << (EAttFontHiddenText - EAttCharLanguage)) - 1;
1.55 +
1.56 +
1.57 +EXPORT_C TTabStop::TTabStop():
1.58 + iTwipsPosition(0),
1.59 + iType(ELeftTab)
1.60 +/** The default C++ constructor constructs a TTabStop. The twips position is
1.61 +initialised to zero and the alignment to ELeftTab. */
1.62 + {
1.63 + }
1.64 +
1.65 +EXPORT_C TTabStop::TTabStop(const TTabStop& aTabStop):
1.66 + iTwipsPosition(aTabStop.iTwipsPosition),
1.67 + iType(aTabStop.iType)
1.68 + {
1.69 + }
1.70 +
1.71 +EXPORT_C TTabStop& TTabStop::operator=(const TTabStop& aTabStop)
1.72 +/** Assigns the twips position and alignment of aTabStop to the current TTabStop.
1.73 +
1.74 +@param aTabStop The tab stop to assign to the current tab stop.
1.75 +@return The current tab stop. */
1.76 + {
1.77 + iTwipsPosition=aTabStop.iTwipsPosition;
1.78 + iType=aTabStop.iType;
1.79 + return *this;
1.80 + }
1.81 +
1.82 +EXPORT_C TBool TTabStop::operator==(const TTabStop& aTabStop)const
1.83 +/** Compares two tab stops for equality. To be equal, they must have the same
1.84 +twips position and alignment.
1.85 +
1.86 +@param aTabStop The tab stop to compare with the current tab stop.
1.87 +@return ETrue if both tab stops have the same twips position and alignment.
1.88 +EFalse if not. */
1.89 + {
1.90 + if (iTwipsPosition!=aTabStop.iTwipsPosition)
1.91 + return EFalse;
1.92 + if (iType!=aTabStop.iType)
1.93 + return EFalse;
1.94 + return ETrue;
1.95 + }
1.96 +
1.97 +EXPORT_C TParaBorder::TParaBorder():
1.98 + iLineStyle(ENullLineStyle),
1.99 + iThickness(0),
1.100 + iColor(TLogicalRgb::ESystemForegroundColor),
1.101 + iAutoColor(ETrue)
1.102 +/** The default C++ constructor constructs a TParaBorder, initializing its line
1.103 +style to ENullLineStyle, its line thickness to zero, its colour to KRgbBlack
1.104 +and iAutocolor to ETrue. */
1.105 + {
1.106 + }
1.107 +
1.108 +EXPORT_C TBool TParaBorder::operator==(const TParaBorder& aParaBorder)const
1.109 +/** Compares two paragraph border sides for equality. For two paragraph border
1.110 +sides to be equal, all data members must be equal.
1.111 +
1.112 +@param aBorder The paragraph border to compare with the current border.
1.113 +@return ETrue if the two paragraph border sides are equal, EFalse if not. */
1.114 + {
1.115 + if (iLineStyle!=aParaBorder.iLineStyle)
1.116 + return EFalse;
1.117 + if (iThickness!=aParaBorder.iThickness)
1.118 + return EFalse;
1.119 + if (iColor!=aParaBorder.iColor)
1.120 + return EFalse;
1.121 + if (iAutoColor!=aParaBorder.iAutoColor)
1.122 + return EFalse;
1.123 + return ETrue;
1.124 + }
1.125 +
1.126 +EXPORT_C TBullet::TBullet():
1.127 + iCharacterCode(0x2022),
1.128 + iHeightInTwips(0),
1.129 + iHangingIndent(TRUE),
1.130 + iColor(TLogicalRgb::ESystemForegroundColor),
1.131 + iStyle(EBulletStyle),
1.132 + iStartNumber(1),
1.133 + iAlignment(ELeftAlign)
1.134 +/** The default C++ constructor constructs a TBullet, initializing the
1.135 +character code to 0x2022, the height to zero, the colour to the system's
1.136 +default foreground colour and the hanging indent to ETrue. The typeface
1.137 +is not initialised. */
1.138 + {
1.139 + }
1.140 +
1.141 +EXPORT_C TBool TBullet::operator==(const TBullet& aBullet)const
1.142 +/** Compares two bullet points for equality. For two bullet points to be equal,
1.143 +all data members must be equal.
1.144 +
1.145 +@param aBullet The bullet point to compare.
1.146 +@return ETrue if the two bullet points are equal, EFalse if not. */
1.147 + {
1.148 + return iCharacterCode == aBullet.iCharacterCode &&
1.149 + iHeightInTwips == aBullet.iHeightInTwips &&
1.150 + iHangingIndent == aBullet.iHangingIndent &&
1.151 + iColor == aBullet.iColor &&
1.152 + iStyle == aBullet.iStyle &&
1.153 + iStartNumber == aBullet.iStartNumber &&
1.154 + iAlignment == aBullet.iAlignment &&
1.155 + iTypeface == aBullet.iTypeface;
1.156 + }
1.157 +
1.158 +EXPORT_C CParaFormat* CParaFormat::NewL()
1.159 +/** Allocates and constructs a CParaFormat object. All attributes are
1.160 +initialised with default values.
1.161 +
1.162 +@return The new CParaFormat object. */
1.163 + {
1.164 + return new(ELeave) CParaFormat;
1.165 + }
1.166 +
1.167 +EXPORT_C CParaFormat* CParaFormat::NewLC()
1.168 +/** Allocates and constructs a CParaFormat object. All attributes are
1.169 +initialised with default values. Leaves the object on the cleanup stack.
1.170 +
1.171 +@return The new CParaFormat object. */
1.172 + {
1.173 + CParaFormat* self=new(ELeave) CParaFormat;
1.174 + CleanupStack::PushL(self);
1.175 + return self;
1.176 + }
1.177 +
1.178 +EXPORT_C CParaFormat* CParaFormat::NewL(const CParaFormat& aFormat)
1.179 +/** Allocates and constructs a new CParaFormat. All attributes are initialised
1.180 +to the values contained in the aFormat argument.
1.181 +
1.182 +@param aFormat Paragraph format container whose values are used to initialise
1.183 +the new CParaFormat.
1.184 +@return The new CParaFormat object. */
1.185 + {
1.186 + CParaFormat* self = new(ELeave) CParaFormat(aFormat);
1.187 + CleanupStack::PushL(self);
1.188 + self->CopyL(aFormat);
1.189 + CleanupStack::Pop();
1.190 + return self;
1.191 + }
1.192 +
1.193 +EXPORT_C CParaFormat::CParaFormat():
1.194 + iTabList(NULL),
1.195 + iParaBorderArray(NULL),
1.196 + iFillColor(TLogicalRgb::ESystemBackgroundColor),
1.197 + iLanguage(KParaDefaultLanguage),
1.198 + iLeftMarginInTwips(KParaDefaultLeftMargin),
1.199 + iRightMarginInTwips(KParaDefaultRightMargin),
1.200 + iIndentInTwips(KParaDefaultIndent),
1.201 + iHorizontalAlignment(KParaDefaultHorizAlign),
1.202 + iVerticalAlignment(KParaDefaultVertAlign),
1.203 + iLineSpacingInTwips(KParaDefaultLineSpacing),
1.204 + iLineSpacingControl(KParaDefaultLineSpacingControl),
1.205 + iSpaceBeforeInTwips(KParaDefaultSpaceBefore),
1.206 + iSpaceAfterInTwips(KParaDefaultSpaceAfter),
1.207 + iKeepTogether(KParaDefaultKeepTogether),
1.208 + iKeepWithNext(KParaDefaultKeepWithNext),
1.209 + iStartNewPage(KParaDefaultStartNewPage),
1.210 + iWidowOrphan(KParaDefaultWidowOrphan),
1.211 + iWrap(KParaDefaultWrap),
1.212 + iBorderMarginInTwips(KParaDefaultBorderMargin),
1.213 + iBullet(NULL),
1.214 + iDefaultTabWidthInTwips(KParaDefaultTabWidth)
1.215 +/** The default C++ constructor constructs a new CParaFormat initialising all
1.216 +attributes to the default settings.
1.217 +
1.218 +Note: This function allows a CParaFormat object to be created on the stack. This
1.219 +should only be done if it is known in advance that the object will not be
1.220 +used to store tab stops, bullets or borders. */
1.221 + {
1.222 + }
1.223 +
1.224 +
1.225 +CParaFormat::CParaFormat(const CParaFormat& aFormat):
1.226 + iFillColor(aFormat.iFillColor),
1.227 + iLanguage(aFormat.iLanguage),
1.228 + iLeftMarginInTwips(aFormat.iLeftMarginInTwips),
1.229 + iRightMarginInTwips(aFormat.iRightMarginInTwips),
1.230 + iIndentInTwips(aFormat.iIndentInTwips),
1.231 + iHorizontalAlignment(aFormat.iHorizontalAlignment),
1.232 + iVerticalAlignment(aFormat.iVerticalAlignment),
1.233 + iLineSpacingInTwips(aFormat.iLineSpacingInTwips),
1.234 + iLineSpacingControl(aFormat.iLineSpacingControl),
1.235 + iSpaceBeforeInTwips(aFormat.iSpaceBeforeInTwips),
1.236 + iSpaceAfterInTwips(aFormat.iSpaceAfterInTwips),
1.237 + iKeepTogether(aFormat.iKeepTogether),
1.238 + iKeepWithNext(aFormat.iKeepWithNext),
1.239 + iStartNewPage(aFormat.iStartNewPage),
1.240 + iWidowOrphan(aFormat.iWidowOrphan),
1.241 + iWrap(aFormat.iWrap),
1.242 + iBorderMarginInTwips(aFormat.iBorderMarginInTwips),
1.243 + iDefaultTabWidthInTwips(aFormat.iDefaultTabWidthInTwips)
1.244 + {
1.245 + }
1.246 +
1.247 +void CParaFormat::CreateTabListL()
1.248 + {
1.249 + if (!iTabList)
1.250 + iTabList = new(ELeave) CArrayFixFlat<TTabStop>(ETabStoreGranularity);
1.251 + }
1.252 +
1.253 +EXPORT_C CParaFormat::~CParaFormat()
1.254 +/** The destructor frees all resources owned by the paragraph format container
1.255 +(tabs, borders and bullets), prior to its destruction.
1.256 +
1.257 +Note that Strip() also sets the resource pointers to NULL. This is important
1.258 +in case CParaFormat is on the stack and gets deleted twice: once by the cleanup
1.259 +stack and once by exceptions being unwound. */
1.260 + {
1.261 + Strip();
1.262 + }
1.263 +
1.264 +EXPORT_C void CParaFormat::CopyL(const CParaFormat& aFormat)
1.265 +/** Copies all attribute values from another paragraph format container.
1.266 +
1.267 +@param aFormat Contains the attribute values to copy. */
1.268 + {
1.269 + TParaFormatMask mask;
1.270 + mask.SetAll();
1.271 + CopyL(aFormat,mask);
1.272 + }
1.273 +
1.274 +EXPORT_C void CParaFormat::CopyL(const CParaFormat& aFormat,const TParaFormatMask& aMask)
1.275 +/** Copies selected attribute values from another paragraph format container.
1.276 +Only the attributes which are set in the mask are copied.
1.277 +
1.278 +@param aFormat Contains the attribute values to copy.
1.279 +@param aMask Bitmask specifying the attributes to copy. */
1.280 + {
1.281 + if (aMask.AttribIsSet(EAttParaLanguage))
1.282 + iLanguage=aFormat.iLanguage;
1.283 + if (aMask.AttribIsSet(EAttFillColor))
1.284 + iFillColor=aFormat.iFillColor;
1.285 + if (aMask.AttribIsSet(EAttLeftMargin))
1.286 + iLeftMarginInTwips=aFormat.iLeftMarginInTwips;
1.287 + if (aMask.AttribIsSet(EAttRightMargin))
1.288 + iRightMarginInTwips=aFormat.iRightMarginInTwips;
1.289 + if (aMask.AttribIsSet(EAttIndent))
1.290 + iIndentInTwips=aFormat.iIndentInTwips;
1.291 + if (aMask.AttribIsSet(EAttAlignment))
1.292 + iHorizontalAlignment=aFormat.iHorizontalAlignment;
1.293 + if (aMask.AttribIsSet(EAttVerticalAlignment))
1.294 + iVerticalAlignment=aFormat.iVerticalAlignment;
1.295 + if (aMask.AttribIsSet(EAttLineSpacing))
1.296 + iLineSpacingInTwips=aFormat.iLineSpacingInTwips;
1.297 + if (aMask.AttribIsSet(EAttLineSpacingControl))
1.298 + iLineSpacingControl=aFormat.iLineSpacingControl;
1.299 + if (aMask.AttribIsSet(EAttSpaceBefore))
1.300 + iSpaceBeforeInTwips=aFormat.iSpaceBeforeInTwips;
1.301 + if (aMask.AttribIsSet(EAttSpaceAfter))
1.302 + iSpaceAfterInTwips=aFormat.iSpaceAfterInTwips;
1.303 + if (aMask.AttribIsSet(EAttKeepTogether))
1.304 + iKeepTogether=aFormat.iKeepTogether;
1.305 + if (aMask.AttribIsSet(EAttKeepWithNext))
1.306 + iKeepWithNext=aFormat.iKeepWithNext;
1.307 + if (aMask.AttribIsSet(EAttStartNewPage))
1.308 + iStartNewPage=aFormat.iStartNewPage;
1.309 + if (aMask.AttribIsSet(EAttWidowOrphan))
1.310 + iWidowOrphan=aFormat.iWidowOrphan;
1.311 + if (aMask.AttribIsSet(EAttWrap))
1.312 + iWrap=aFormat.iWrap;
1.313 +
1.314 + // Copy borders; create a border array only if necessary.
1.315 + if (iParaBorderArray || aFormat.iParaBorderArray)
1.316 + {
1.317 + if (!iParaBorderArray)
1.318 + iParaBorderArray = new(ELeave) TParaBorderArray;
1.319 + if (aMask.AttribIsSet(EAttTopBorder))
1.320 + iParaBorderArray->iBorder[EParaBorderTop] = aFormat.ParaBorder(EParaBorderTop);
1.321 + if (aMask.AttribIsSet(EAttBottomBorder))
1.322 + iParaBorderArray->iBorder[EParaBorderBottom] = aFormat.ParaBorder(EParaBorderBottom);
1.323 + if (aMask.AttribIsSet(EAttLeftBorder))
1.324 + iParaBorderArray->iBorder[EParaBorderLeft] = aFormat.ParaBorder(EParaBorderLeft);
1.325 + if (aMask.AttribIsSet(EAttRightBorder))
1.326 + iParaBorderArray->iBorder[EParaBorderRight] = aFormat.ParaBorder(EParaBorderRight);
1.327 + TParaBorder default_border;
1.328 + TBool borders_are_default = TRUE;
1.329 + for (int i = 0; i < 4; i++)
1.330 + if (iParaBorderArray->iBorder[i] != default_border)
1.331 + {
1.332 + borders_are_default = FALSE;
1.333 + break;
1.334 + }
1.335 + if (borders_are_default)
1.336 + RemoveAllBorders();
1.337 + }
1.338 +
1.339 + if (iBullet || aFormat.iBullet)
1.340 + {
1.341 + if (aMask.AttribIsSet(EAttBullet))
1.342 + {
1.343 + if (aFormat.iBullet && aFormat.iBullet->iStyle != TBullet::ENullStyle)
1.344 + {
1.345 + if (!iBullet)
1.346 + iBullet = new(ELeave) TBullet;
1.347 + *iBullet = *aFormat.iBullet;
1.348 + }
1.349 + else
1.350 + {
1.351 + delete iBullet;
1.352 + iBullet = NULL;
1.353 + }
1.354 + }
1.355 + }
1.356 +
1.357 + if (aMask.AttribIsSet(EAttDefaultTabWidth))
1.358 + iDefaultTabWidthInTwips = aFormat.iDefaultTabWidthInTwips;
1.359 +
1.360 + if (iTabList || aFormat.iTabList)
1.361 + {
1.362 + if (aMask.AttribIsSet(EAttTabStop))
1.363 + {
1.364 + RemoveAllTabs();
1.365 + if (aFormat.iTabList && aFormat.iTabList->Count())
1.366 + {
1.367 + CreateTabListL();
1.368 + iTabList->InsertL(0,&(aFormat.iTabList->At(0)),aFormat.iTabList->Count());
1.369 + }
1.370 + }
1.371 + }
1.372 + }
1.373 +
1.374 +EXPORT_C TBool CParaFormat::IsEqual(const CParaFormat& aFormat,const TParaFormatMask& aMask) const
1.375 +/** Compares selected attribute values for equality. Only the attributes
1.376 +specified in the mask are involved in the comparison.
1.377 +
1.378 +@param aFormat Contains the attribute values to compare.
1.379 +@param aMask Bitmask specifying the attributes to compare.
1.380 +@return ETrue if the two format containers have the same values for the
1.381 +attributes specified in the mask, EFalse if not. */
1.382 + {
1.383 + if (aMask.AttribIsSet(EAttParaLanguage))
1.384 + {
1.385 + if (iLanguage!=aFormat.iLanguage)
1.386 + return EFalse;
1.387 + }
1.388 + if (aMask.AttribIsSet(EAttFillColor))
1.389 + {
1.390 + if (iFillColor!=aFormat.iFillColor)
1.391 + return EFalse;
1.392 + }
1.393 + if (aMask.AttribIsSet(EAttLeftMargin))
1.394 + {
1.395 + if (iLeftMarginInTwips!=aFormat.iLeftMarginInTwips)
1.396 + return EFalse;
1.397 + }
1.398 + if (aMask.AttribIsSet(EAttRightMargin))
1.399 + {
1.400 + if (iRightMarginInTwips!=aFormat.iRightMarginInTwips)
1.401 + return EFalse;
1.402 + }
1.403 + if (aMask.AttribIsSet(EAttIndent))
1.404 + {
1.405 + if (iIndentInTwips!=aFormat.iIndentInTwips)
1.406 + return EFalse;
1.407 + }
1.408 + if (aMask.AttribIsSet(EAttAlignment))
1.409 + {
1.410 + if (iHorizontalAlignment!=aFormat.iHorizontalAlignment)
1.411 + return EFalse;
1.412 + }
1.413 + if (aMask.AttribIsSet(EAttVerticalAlignment))
1.414 + {
1.415 + if (iVerticalAlignment!=aFormat.iVerticalAlignment)
1.416 + return EFalse;
1.417 + }
1.418 + if (aMask.AttribIsSet(EAttLineSpacing))
1.419 + {
1.420 + if (iLineSpacingInTwips!=aFormat.iLineSpacingInTwips)
1.421 + return EFalse;
1.422 + }
1.423 + if (aMask.AttribIsSet(EAttLineSpacingControl))
1.424 + {
1.425 + if (iLineSpacingControl!=aFormat.iLineSpacingControl)
1.426 + return EFalse;
1.427 + }
1.428 + if (aMask.AttribIsSet(EAttSpaceBefore))
1.429 + {
1.430 + if (iSpaceBeforeInTwips!=aFormat.iSpaceBeforeInTwips)
1.431 + return EFalse;
1.432 + }
1.433 + if (aMask.AttribIsSet(EAttSpaceAfter))
1.434 + {
1.435 + if (iSpaceAfterInTwips!=aFormat.iSpaceAfterInTwips)
1.436 + return EFalse;
1.437 + }
1.438 + if (aMask.AttribIsSet(EAttKeepTogether))
1.439 + {
1.440 + if (iKeepTogether!=aFormat.iKeepTogether)
1.441 + return EFalse;
1.442 + }
1.443 + if (aMask.AttribIsSet(EAttKeepWithNext))
1.444 + {
1.445 + if (iKeepWithNext!=aFormat.iKeepWithNext)
1.446 + return EFalse;
1.447 + }
1.448 + if (aMask.AttribIsSet(EAttStartNewPage))
1.449 + {
1.450 + if (iStartNewPage!=aFormat.iStartNewPage)
1.451 + return EFalse;
1.452 + }
1.453 + if (aMask.AttribIsSet(EAttWidowOrphan))
1.454 + {
1.455 + if (iWidowOrphan!=aFormat.iWidowOrphan)
1.456 + return EFalse;
1.457 + }
1.458 + if (aMask.AttribIsSet(EAttWrap))
1.459 + {
1.460 + if (iWrap!=aFormat.iWrap)
1.461 + return EFalse;
1.462 + }
1.463 + if (aMask.AttribIsSet(EAttBorderMargin))
1.464 + {
1.465 + if (iBorderMarginInTwips!=aFormat.iBorderMarginInTwips)
1.466 + return EFalse;
1.467 + }
1.468 + if (aMask.AttribIsSet(EAttTopBorder))
1.469 + {
1.470 + if (iParaBorderArray)
1.471 + {
1.472 + if (ParaBorder(EParaBorderTop)!=aFormat.ParaBorder(EParaBorderTop))
1.473 + return EFalse;
1.474 + }
1.475 + else
1.476 + {
1.477 + if (aFormat.ParaBorder(EParaBorderTop).iLineStyle!=TParaBorder::ENullLineStyle)
1.478 + return EFalse;
1.479 + }
1.480 + }
1.481 + if (aMask.AttribIsSet(EAttBottomBorder))
1.482 + {
1.483 + if (iParaBorderArray)
1.484 + {
1.485 + if (ParaBorder(EParaBorderBottom)!=aFormat.ParaBorder(EParaBorderBottom))
1.486 + return EFalse;
1.487 + }
1.488 + else
1.489 + {
1.490 + if (aFormat.ParaBorder(EParaBorderBottom).iLineStyle!=TParaBorder::ENullLineStyle)
1.491 + return EFalse;
1.492 + }
1.493 + }
1.494 + if (aMask.AttribIsSet(EAttLeftBorder))
1.495 + {
1.496 + if (iParaBorderArray)
1.497 + {
1.498 + if (ParaBorder(EParaBorderLeft)!=aFormat.ParaBorder(EParaBorderLeft))
1.499 + return EFalse;
1.500 + }
1.501 + else
1.502 + {
1.503 + if (aFormat.ParaBorder(EParaBorderLeft).iLineStyle!=TParaBorder::ENullLineStyle)
1.504 + return EFalse;
1.505 + }
1.506 + }
1.507 + if (aMask.AttribIsSet(EAttRightBorder))
1.508 + {
1.509 + if (iParaBorderArray)
1.510 + {
1.511 + if (ParaBorder(EParaBorderRight)!=aFormat.ParaBorder(EParaBorderRight))
1.512 + return EFalse;
1.513 + }
1.514 + else
1.515 + {
1.516 + if (aFormat.ParaBorder(EParaBorderRight).iLineStyle!=TParaBorder::ENullLineStyle)
1.517 + return EFalse;
1.518 + }
1.519 + }
1.520 + if (aMask.AttribIsSet(EAttBullet))
1.521 + {
1.522 + if (iBullet)
1.523 + {
1.524 + if (!aFormat.iBullet)
1.525 + return EFalse;
1.526 + if (*iBullet!=*aFormat.iBullet)
1.527 + return EFalse;
1.528 + }
1.529 + else
1.530 + {
1.531 + if (aFormat.iBullet)
1.532 + return EFalse;
1.533 + }
1.534 + }
1.535 + if (aMask.AttribIsSet(EAttDefaultTabWidth))
1.536 + {
1.537 + if (iDefaultTabWidthInTwips!=aFormat.iDefaultTabWidthInTwips)
1.538 + return EFalse;
1.539 + }
1.540 + if (aMask.AttribIsSet(EAttTabStop))
1.541 + {
1.542 + if (TabCount()>0)
1.543 + {// Check the tablists are the same.
1.544 + if (TabCount()!=aFormat.TabCount())
1.545 + return EFalse;
1.546 + TInt tabCount=TabCount();
1.547 + for (TInt index=0;index<tabCount;index++)
1.548 + {// Check each stored tab is the same
1.549 + if (TabStop(index)!=aFormat.TabStop(index))
1.550 + return EFalse;
1.551 + }
1.552 + }
1.553 + else if (aFormat.TabCount()>0)
1.554 + return EFalse;
1.555 + }
1.556 + return ETrue;
1.557 + }
1.558 +
1.559 +EXPORT_C TBool CParaFormat::IsEqual(const CParaFormat& aFormat) const
1.560 +/** Compares all attribute values for equality.
1.561 +
1.562 +@param aFormat Contains the attribute values to compare.
1.563 +@return ETrue if the two format containers have the same values for all
1.564 +attributes, EFalse if not. */
1.565 + {
1.566 + TParaFormatMask mask;
1.567 + mask.SetAll();
1.568 + return IsEqual(aFormat,mask);
1.569 + }
1.570 +
1.571 +EXPORT_C void CParaFormat::Strip()
1.572 +/** Deletes all paragraph borders, bullets and tab stops. No other
1.573 +attributes are affected. */
1.574 + {
1.575 + RemoveAllTabs();
1.576 + RemoveAllBorders();
1.577 + delete iBullet;
1.578 + iBullet = NULL;
1.579 + }
1.580 +
1.581 +EXPORT_C void CParaFormat::Reset()
1.582 +/** Resets all paragraph format attributes to their default values. All tab
1.583 +stops, paragraph borders and bullet points which have been allocated are
1.584 +deleted and set to NULL. */
1.585 + {
1.586 + ResetNonDestructive();
1.587 + Strip();
1.588 + }
1.589 +
1.590 +EXPORT_C void CParaFormat::ResetNonDestructive()
1.591 +/** Resets all paragraph format attributes to their default values, but any
1.592 +allocated tab stops, bullet points and paragraph borders are preserved. */
1.593 + {
1.594 + iLanguage=KParaDefaultLanguage;
1.595 + iFillColor=TLogicalRgb::ESystemBackgroundColor;
1.596 + iLeftMarginInTwips=KParaDefaultLeftMargin;
1.597 + iRightMarginInTwips=KParaDefaultRightMargin;
1.598 + iIndentInTwips=KParaDefaultIndent;
1.599 + iHorizontalAlignment=KParaDefaultHorizAlign;
1.600 + iVerticalAlignment=KParaDefaultVertAlign;
1.601 + iLineSpacingInTwips=KParaDefaultLineSpacing;
1.602 + iLineSpacingControl=KParaDefaultLineSpacingControl;
1.603 + iSpaceBeforeInTwips=KParaDefaultSpaceBefore;
1.604 + iSpaceAfterInTwips=KParaDefaultSpaceAfter;
1.605 + iKeepTogether=KParaDefaultKeepTogether;
1.606 + iKeepWithNext=KParaDefaultKeepWithNext;
1.607 + iStartNewPage=KParaDefaultStartNewPage;
1.608 + iWidowOrphan=KParaDefaultWidowOrphan;
1.609 + iWrap=KParaDefaultWrap;
1.610 + iBorderMarginInTwips=KParaDefaultBorderMargin;
1.611 + iDefaultTabWidthInTwips=KParaDefaultTabWidth;
1.612 + }
1.613 +
1.614 +EXPORT_C void CParaFormat::StoreTabL(const TTabStop& aTabStop)
1.615 +/** Adds a tab stop to the list of tab stops, maintaining the ordering of the
1.616 +list, (ascending order of twips position). Multiple tabs with the same twips
1.617 +position are not allowed, so that if aTabStop shares the same twips position
1.618 +as an existing tab stop, regardless of its alignment, the existing tab stop is
1.619 +replaced by aTabStop.
1.620 +
1.621 +@param aTabStop The tab stop to be stored. */
1.622 + {
1.623 + CreateTabListL();
1.624 + TKeyArrayFix tabKey(_FOFF(TTabStop,iTwipsPosition),ECmpTUint32);
1.625 + TInt tabNumber;
1.626 + CArrayFixFlat<TTabStop>& tabs=*iTabList;
1.627 + if (tabs.FindIsq(aTabStop,tabKey,tabNumber)==0)
1.628 + tabs[tabNumber]=aTabStop; // found one at this position
1.629 + else
1.630 + tabs.InsertL(tabNumber,aTabStop); // add the new one
1.631 + }
1.632 +
1.633 +EXPORT_C void CParaFormat::RemoveTab(TInt aTabPosition)
1.634 +/** Deletes a tab stop identified by its twips position. If the specified
1.635 +tab stop does not exist, the function has no effect.
1.636 +
1.637 +@param aTabTwipsPosition The twips position of the tab stop to remove. */
1.638 +
1.639 + {
1.640 + TInt tabNumber=LocateTab(aTabPosition); // will return KTabNotFound if no tab list present
1.641 + if (tabNumber!=KTabNotFound)
1.642 + {
1.643 + iTabList->Delete(tabNumber);
1.644 + iTabList->Compress();
1.645 + }
1.646 + }
1.647 +
1.648 +EXPORT_C const TTabStop CParaFormat::TabStop(TInt aTabIndex) const
1.649 +/** Gets the tab stop located at the specified index within the tab list
1.650 +(counting from zero). Tab stops are ordered in ascending order of twips
1.651 +position. If the object has no tab list, then a default tab stop is returned.
1.652 +
1.653 +@param aTabIndex The offset of the tab stop in the tab list. Must be less
1.654 +than the total number of tab stops, or a panic occurs. To find the total number
1.655 +of tab stops, use TabCount().
1.656 +@return The tab stop located at the specified index. */
1.657 + {
1.658 + if (aTabIndex>=TabCount())
1.659 + {
1.660 + OstTrace0( TRACE_FATAL, CPARAFORMAT_TABSTOP, "ETabNotFound" );
1.661 + }
1.662 + __ASSERT_ALWAYS(aTabIndex<TabCount(),Panic(ETabNotFound));
1.663 +
1.664 + return (iTabList)
1.665 + ? TTabStop((*iTabList)[aTabIndex])
1.666 + : TTabStop();
1.667 + }
1.668 +
1.669 +EXPORT_C TInt CParaFormat::LocateTab(TInt aTabPosition) const
1.670 +/** Locates the tab stop specified by its twips position, and returns its
1.671 +offset in the tab list.
1.672 +
1.673 +@param aTabPosition The twips position of the tab stop.
1.674 +@return The tab stop's index within the tab list (counting from zero).
1.675 +KTabNotFound indicates that no tab stop has the specified twips
1.676 +position, or that no tab list has been allocated. */
1.677 + {
1.678 + if (!iTabList)
1.679 + return KTabNotFound;
1.680 + TKeyArrayFix tabKey(_FOFF(TTabStop,iTwipsPosition),ECmpTUint32);
1.681 + TInt tabNumber=0;
1.682 + TTabStop tab;
1.683 + tab.iTwipsPosition=aTabPosition;
1.684 + TInt error=iTabList->FindIsq(tab,tabKey,tabNumber);
1.685 + return error ?KTabNotFound :tabNumber;
1.686 + }
1.687 +
1.688 +EXPORT_C void CParaFormat::SetParaBorderL(TParaBorderSide aSide,const TParaBorder& aBorder)
1.689 +/** Sets one side of the object's paragraph border. If a border on the specified
1.690 +side already exists, it is replaced.
1.691 +
1.692 +Note: Setting a single side of the object's paragraph border incurs the overhead
1.693 +of allocating storage for the three other sides, which are assigned default
1.694 +values.
1.695 +
1.696 +@param aSide The side for the paragraph border.
1.697 +@param aBorder Specification for the paragraph border. */
1.698 + {
1.699 + TParaBorderArray* borders=iParaBorderArray;
1.700 + if (!borders)
1.701 + iParaBorderArray=borders=new(ELeave) TParaBorderArray;
1.702 + borders->iBorder[aSide]=aBorder;
1.703 + }
1.704 +
1.705 +EXPORT_C const TParaBorder CParaFormat::ParaBorder(TParaBorderSide aSide)const
1.706 +/** Gets the paragraph border on the side specified. If no paragraph border
1.707 +array has been allocated, returns a default paragraph border.
1.708 +
1.709 +@param aSide The side for the paragraph border.
1.710 +@return The paragraph border on the specified side. */
1.711 + {
1.712 + if (iParaBorderArray)
1.713 + return iParaBorderArray->iBorder[aSide];
1.714 + return TParaBorder();
1.715 + }
1.716 +
1.717 +EXPORT_C void CParaFormat::RemoveAllBorders()
1.718 +/** Deletes all paragraph borders. */
1.719 + {
1.720 + delete iParaBorderArray;
1.721 + iParaBorderArray = NULL;
1.722 + }
1.723 +
1.724 +EXPORT_C TBool CParaFormat::AllBordersEqual(const CParaFormat& aFormat)const
1.725 +/** Tests whether all paragraph borders in the specified paragraph format
1.726 +container are identical to the paragraph borders of this paragraph format
1.727 +container.
1.728 +
1.729 +@param aFormat Contains the set of paragraph borders to compare.
1.730 +@return ETrue if both objects have exactly the same set of paragraph borders.
1.731 +EFalse if not. */
1.732 + {
1.733 + if (aFormat.ParaBorder(EParaBorderTop)!=ParaBorder(EParaBorderTop))
1.734 + return EFalse;
1.735 + if (aFormat.ParaBorder(EParaBorderBottom)!=ParaBorder(EParaBorderBottom))
1.736 + return EFalse;
1.737 + if (aFormat.ParaBorder(EParaBorderLeft)!=ParaBorder(EParaBorderLeft))
1.738 + return EFalse;
1.739 + if (aFormat.ParaBorder(EParaBorderRight)!=ParaBorder(EParaBorderRight))
1.740 + return EFalse;
1.741 + return ETrue;
1.742 + }
1.743 +
1.744 +EXPORT_C TBool CParaFormat::IsBorderEqual(TParaBorderSide aSide,const CParaFormat& aFormat)const
1.745 +/** Tests whether the paragraph border located on the specified side is the same
1.746 +as the border on the corresponding side in this object. For two borders to
1.747 +be equal, they must both either be set or unset, and if set, they must have
1.748 +the same characteristics.
1.749 +
1.750 +@param aSide Indicates which side should be compared.
1.751 +@param aFormat Contains the paragraph border to compare.
1.752 +@return ETrue if the border sides are identical. EFalse if not. */
1.753 + {
1.754 + return aFormat.ParaBorder(aSide)==ParaBorder(aSide);
1.755 + }
1.756 +
1.757 + EXPORT_C void TParaFormatMask::SetAll()
1.758 +/** Sets all attribute flags in the paragraph format mask. */
1.759 + {
1.760 + iGuard = KMaxTUint;
1.761 + }
1.762 +
1.763 +EXPORT_C void TParaFormatMask::ClearAll()
1.764 +/** Clears all attribute flags in the paragraph format mask. */
1.765 + {
1.766 + iGuard=0;
1.767 + }
1.768 +
1.769 +EXPORT_C TBool TParaFormatMask::operator==(const TParaFormatMask& aMask)const
1.770 +/** Compares two paragraph format masks for equality.
1.771 +
1.772 +@param aMask The mask to compare.
1.773 +@return ETrue if all flags are the same in both masks. EFalse if any differ. */
1.774 + {
1.775 + return (iGuard & KParFormatBits) == (aMask.iGuard & KParFormatBits);
1.776 + }
1.777 +
1.778 +EXPORT_C TFontPresentation::TFontPresentation():
1.779 + iTextColor(TLogicalRgb::ESystemForegroundColor),
1.780 + iHighlightColor(TLogicalRgb::ESystemForegroundColor),
1.781 + iHighlightStyle(EFontHighlightNone),
1.782 + iStrikethrough(EStrikethroughOff),
1.783 + iUnderline(EUnderlineOff),
1.784 + iHiddenText(EFalse),
1.785 + iPictureAlignment(EAlignBaseLine)
1.786 +/** The default C++ constructor constructs a TFontPresentation object,
1.787 +initializing all member data to default values. For details of these values,
1.788 +see the table below. */
1.789 + {
1.790 + }
1.791 +
1.792 +EXPORT_C TBool TFontPresentation::IsEqual(const TFontPresentation& aFontPresentation,const TCharFormatMask& aMask) const
1.793 +/** Compares selected attribute values for equality. Only the attributes
1.794 +specified in the mask are involved in the comparison.
1.795 +
1.796 +@param aFontPresentation Contains the attribute values to compare.
1.797 +@param aMask Bitmask specifying the attributes involved in the comparison.
1.798 +@return ETrue if the two objects have the same values for the attributes
1.799 +specified in the mask, EFalse if not. */
1.800 + {
1.801 + // Compare two font presentations, comparing only the attributes selected by the mask.
1.802 + if (aMask.AttribIsSet(EAttColor))
1.803 + {
1.804 + if (iTextColor!=aFontPresentation.iTextColor)
1.805 + return EFalse;
1.806 + }
1.807 + if (aMask.AttribIsSet(EAttFontHighlightColor))
1.808 + {
1.809 + if (iHighlightColor!=aFontPresentation.iHighlightColor)
1.810 + return EFalse;
1.811 + }
1.812 + if (aMask.AttribIsSet(EAttFontHighlightStyle))
1.813 + {
1.814 + if (iHighlightStyle!=aFontPresentation.iHighlightStyle)
1.815 + return EFalse;
1.816 + }
1.817 + if (aMask.AttribIsSet(EAttFontStrikethrough))
1.818 + {
1.819 + if (iStrikethrough!=aFontPresentation.iStrikethrough)
1.820 + return EFalse;
1.821 + }
1.822 + if (aMask.AttribIsSet(EAttFontUnderline))
1.823 + {
1.824 + if (iUnderline!=aFontPresentation.iUnderline)
1.825 + return EFalse;
1.826 + }
1.827 + if (aMask.AttribIsSet(EAttFontHiddenText))
1.828 + {
1.829 + if (iHiddenText!=aFontPresentation.iHiddenText)
1.830 + return EFalse;
1.831 + }
1.832 + if (aMask.AttribIsSet(EAttFontPictureAlignment))
1.833 + {
1.834 + if (iPictureAlignment!=aFontPresentation.iPictureAlignment)
1.835 + return EFalse;
1.836 + }
1.837 + return ETrue;
1.838 + }
1.839 +
1.840 +EXPORT_C TCharFormat::TCharFormat():
1.841 + iLanguage(0)
1.842 +/** Allocates and constructs a TCharFormat object. The font-independent
1.843 +attributes are initialised with default values. The language is initialised
1.844 +to zero. The font (iFontSpec) is set to be proportional and serif and to have
1.845 +a height of 200 twips. The typeface name is not initialised. */
1.846 + {
1.847 + iFontSpec.iTypeface.SetAttributes(TTypeface::EProportional | TTypeface::ESerif);
1.848 + iFontSpec.iHeight = 200;
1.849 + }
1.850 +
1.851 +EXPORT_C TCharFormat::TCharFormat(const TDesC &aTypefaceName,TInt aHeight):
1.852 + iLanguage(0),
1.853 + iFontSpec(aTypefaceName,aHeight)
1.854 +/** The C++ constructor is used to construct the TCharFormat object with a font
1.855 +(typeface name and font height). The font-independent attributes are initialised
1.856 +to default values; for details, see class TFontPresentation. The language
1.857 +is initialised to zero.
1.858 +
1.859 +@param aTypefaceName Specifies the typeface name.
1.860 +@param aHeight Specifies the font height in twips. */
1.861 + {
1.862 + }
1.863 +
1.864 +EXPORT_C TBool TCharFormat::IsEqual(const TCharFormat& aFormat,const TCharFormatMask& aMask) const
1.865 +/** Compares selected attribute values for equality. Only the attributes
1.866 +specified in the mask are involved in the comparison.
1.867 +
1.868 +@param aFormat Contains the attribute values to compare.
1.869 +@param aMask Bitmask specifying the attributes to compare.
1.870 +@return ETrue if the two format containers have the same values for the
1.871 +attributes specified in the mask, EFalse if not. */
1.872 + {
1.873 + if (aMask.AttribIsSet(EAttCharLanguage))
1.874 + {
1.875 + if (iLanguage!=aFormat.iLanguage)
1.876 + return EFalse;
1.877 + }
1.878 + if (!iFontPresentation.IsEqual(aFormat.iFontPresentation,aMask))
1.879 + return EFalse;
1.880 + if (aMask.AttribIsSet(EAttFontHeight))
1.881 + {
1.882 + if (iFontSpec.iHeight!=aFormat.iFontSpec.iHeight)
1.883 + return EFalse;
1.884 + }
1.885 + if (aMask.AttribIsSet(EAttFontTypeface))
1.886 + {
1.887 + if (!(iFontSpec.iTypeface==aFormat.iFontSpec.iTypeface))
1.888 + return EFalse;
1.889 + }
1.890 + if (aMask.AttribIsSet(EAttFontPosture))
1.891 + {
1.892 + if (iFontSpec.iFontStyle.Posture()!=aFormat.iFontSpec.iFontStyle.Posture())
1.893 + return EFalse;
1.894 + }
1.895 + if (aMask.AttribIsSet(EAttFontStrokeWeight))
1.896 + {
1.897 + if (iFontSpec.iFontStyle.StrokeWeight()!=aFormat.iFontSpec.iFontStyle.StrokeWeight())
1.898 + return EFalse;
1.899 + }
1.900 + if (aMask.AttribIsSet(EAttFontPrintPos))
1.901 + {
1.902 + if (iFontSpec.iFontStyle.PrintPosition()!=aFormat.iFontSpec.iFontStyle.PrintPosition())
1.903 + return EFalse;
1.904 + }
1.905 + return ETrue;
1.906 + }
1.907 +
1.908 +
1.909 +EXPORT_C TBool TCharFormat::IsEqual(const TCharFormat& aFormat) const
1.910 +/** Compares all attribute values for equality.
1.911 +
1.912 +@param aFormat Contains the attribute values to compare.
1.913 +@return ETrue if the two format containers have the same values for all
1.914 +attributes, EFalse if not. */
1.915 + {
1.916 + TCharFormatMask mask;
1.917 + mask.SetAll();
1.918 + return IsEqual(aFormat,mask);
1.919 + }
1.920 +
1.921 +EXPORT_C void TCharFormatMask::SetAll()
1.922 +/** Sets all attribute flags in the character format mask. */
1.923 + {
1.924 + iGuard = KMaxTUint;
1.925 + }
1.926 +
1.927 +EXPORT_C void TCharFormatMask::ClearAll()
1.928 +/** Clears all attribute flags in the character format mask. */
1.929 + {
1.930 + iGuard = 0;
1.931 + }
1.932 +
1.933 +EXPORT_C TBool TCharFormatMask::operator==(const TCharFormatMask& aMask)const
1.934 +/** Compares two character format masks for equality.
1.935 +
1.936 +@param aMask The mask to compare.
1.937 +@return ETrue if all flags are the same in both masks. EFalse if any differ. */
1.938 + {
1.939 + return (iGuard & KCharFormatBits) == (aMask.iGuard & KCharFormatBits);
1.940 + }