2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #ifndef __TXTFRMAT_H__
20 #define __TXTFRMAT_H__
27 // Classes declared in this file:
31 class TParaBorderArray;
33 class TParaFormatMask;
34 class TFontPresentation;
36 class TCharFormatMask;
39 Provides support for system colours, in addition to literal colours, in
42 The base class TRgb stores the 24-bit literal colour value using a TUint32.
43 TLogicalRgb uses the MSB from iValue2 data member as an 8-bit index. The
44 purpose of the index is to allow applications to use logical colours. If the
45 index is zero, the value is not a logical colour; it is treated as an ordinary
46 TRgb value. If the index is non zero (1-255), the colour should be translated by the
47 application into a system colour. Indices 254 and 255 are reserved for the
48 system foreground and background colours, respectively and should be translated
49 into them. Translation from index to RGB colour occurs in the implementation of
50 MFormParam::SystemColor().
52 All colours in the Text and Text Attributes API are stored using TLogicalRgb
53 values and are initialised to either TLogicalRgb::ESystemForegroundColor or
54 TLogicalRgb::ESystemBackgroundColor.
56 This system allows an application to set its text colours once, perhaps using
57 the system-wide colour scheme, rather than having to set the colours each
58 time a text object is created. It is also compatible with legacy code which
59 expects TRgb rather than TLogicalRgb values: for example, the logical
60 foreground and background colours have their bottom three bytes filled with
61 black and white respectively so that code which expects TRgb values can still
66 class TLogicalRgb : public TRgb
71 Reserved colour indices for default foreground and background colours,
72 and colours for the selection highlight. The top 128 indices (128-255)
73 are reserved for future expansion, but the first 126 non-zero indices
74 (1-127) can be used by the GUI as convenient.
78 ESystemSelectionForegroundIndex = 252,
79 ESystemSelectionBackgroundIndex = 253,
80 /** Index reserved for the system foreground colour (=254). */
81 ESystemForegroundIndex = 254,
82 /** Index reserved for the system background colour (=255). */
83 ESystemBackgroundIndex = 255
88 /** Used to construct TLogicalRgb objects which should use either the
89 system foreground or background colour. */
92 ESystemSelectionForegroundColor = ESystemSelectionForegroundIndex << 24,
93 ESystemSelectionBackgroundColor = ESystemSelectionBackgroundIndex << 24,
94 /** The system foreground colour. */
95 ESystemForegroundColor = ESystemForegroundIndex << 24,
96 /** The system background colour. */
97 ESystemBackgroundColor = (ESystemBackgroundIndex << 24) | 0xFFFFFF
100 /** Constructs a new TLogicalRgb object. */
106 /** Constructs the object with a 32-bit integer. The index is stored in the
107 MSB of iValue2 data member. A TRgb value may be stored in the base TRgb class.
108 @param aValue Integer holding the logical colour index. */
109 TLogicalRgb(TUint32 aValue):
110 iValue2(aValue & 0xFF000000)
112 SetInternal((TUint32)aValue | 0xFF000000);
115 /** Constructs the object with a TSystemColor value.
116 @param aValue Identifies whether the colour is the system foreground or
117 system background colour. */
118 TLogicalRgb(TSystemColor aValue) :
119 iValue2((TUint32)aValue & 0xFF000000)
121 SetInternal((TUint32)aValue | 0xFF000000);
124 /** Constructs a new TLogicalRgb object from an existing one. */
125 TLogicalRgb(const TRgb& aRgb) :
131 /** Returns the logical colour's index value. Zero indicates that the value
132 is not a logical colour; it is an ordinary TRgb value. 254 and 255 indicate
133 the system foreground and background colours, respectively.
134 @return The index: between zero and 255 inclusive. */
135 TUint SystemColorIndex() const
137 return iValue2 >> 24;
140 /** Sets the logical colour's index value.
141 @param aIndex The new index value (between 1 and 253 inclusive). */
142 void SetSystemColorIndex(TUint aIndex)
144 iValue2 = aIndex << 24;
153 Indicates which format attributes are relevant when setting or sensing text
158 enum TTextFormatAttribute
160 // Paragraph format attributes.
161 /** Language of the paragraph for proofing. */
163 /** Background colour of the paragraph. */
165 /** Leading text margin. */
167 /** Trailing text margin. */
169 /** First line leading indent. */
171 /** Horizontal alignment of paragraph. */
173 /** Vertical paragraph alignment. */
174 EAttVerticalAlignment,
175 /** Inter-line spacing. */
177 /** Control for EAttLineSpacing. */
178 EAttLineSpacingControl,
179 /** Space above paragraph. */
181 /** Space below paragraph. */
183 /** Whether a page break can occur within the paragraph. */
185 /** Whether a page break can occur between this and the next paragraph. */
187 /** Whether a page break should be inserted before this paragraph. */
189 /** Whether the last line of a paragraph can appear by itself at the top of a new
190 page, (widow), or the first line of a paragraph can appear by itself at the
191 bottom of the page, (orphan). */
193 /** Whether the paragraph should line wrap at the right margin. */
195 /** Distance between paragraph border and enclosed text. */
197 /** Top of paragraph border. */
199 /** Bottom of paragraph border. */
201 /** Left-hand side of paragraph border. */
203 /** Right-hand side of paragraph border. */
205 /** Bullet point associated with paragraph. */
207 /** Spacing between default tab stops. */
212 // Character format attributes.
213 /** Language of individual characters within a paragraph for proofing. */
217 /** Text highlight colour. */
218 EAttFontHighlightColor,
219 /** Text highlight style. */
220 EAttFontHighlightStyle,
223 /** Font posture (i.e. italics). */
225 /** Font stroke weight (i.e. bold). */
226 EAttFontStrokeWeight,
227 /** Subscript, superscript or normal print position. */
231 /** Strikethrough. */
232 EAttFontStrikethrough,
233 /** The typeface name. */
235 /** Vertical picture alignment. */
236 EAttFontPictureAlignment,
240 /** Used internally to indicate the count of all attributes. */
241 ETextFormatAttributeCount
245 Following enum and variable should not be used by external developers.
247 enum {EVariableLengthValue = 0};
249 const TInt KMaxStyleName = 0x20;
250 const TInt KMaxParaAttributes = EAttTabStop;
251 const TInt KMaxCharAttributes = EAttFontHiddenText - KMaxParaAttributes;
252 const TInt KTabNotFound = -1;
257 This is a position on a page used to align columns of text. It has a twips
258 position and an alignment. The twips position is the width in twips (1/1440th
259 of an inch) of the tab stop, i.e. the number of twips from the start of the
260 line at which text can be inserted. It uniquely identifies the tab stop. The
261 alignment (left, right, or centre) indicates how text inserted at the tab
262 stop should be aligned.
264 Tab stops are paragraph format attributes. They are owned by the CParaFormat
265 class, through which tab stops can be added and removed.
272 /** Text alignment at the tab stop. */
277 /** Text is aligned to the tab stop's leading edge (left for
278 left-to-right paragraphs, right for right-to-left paragraphs). */
280 /** Text is aligned to the tab stop's trailing edge (right for
281 left-to-right paragraphs, left for right-to-left paragraphs). */
283 /** Text is right aligned at the tab stop. */
288 IMPORT_C TTabStop(const TTabStop& aTabStop);
289 IMPORT_C TTabStop& operator=(const TTabStop& aTabStop);
290 IMPORT_C TBool operator==(const TTabStop& aTabStop) const;
291 inline TBool operator!=(const TTabStop& aTabStop) const;
293 /** The twips position. This is the width in twips of the tab stop, i.e.
294 the number of twips from the start of the line at which text can be
296 TUint32 iTwipsPosition;
297 /** Text alignment at the tab stop. */
302 Defines the characteristics of one of the four sides of a paragraph border.
304 These are the line style, thickness and colour. Paragraph borders are paragraph
305 format attributes. They are owned by the CParaFormat class which allows
306 paragraph borders to be added and removed. The CParaFormat::TParaBorderSide
307 enumeration identifies which side of the paragraph the object applies to.
318 /** No line style. */
322 /** Double solid line. */
328 /** Alternating dots and dashes. */
330 /** Alternating sequence of two dots and a dash. */
334 IMPORT_C TParaBorder();
335 IMPORT_C TBool operator==(const TParaBorder& aParaBorder) const;
336 inline TBool operator!=(const TParaBorder& aParaBorder) const;
338 /** The line style. By default, ENullLineStyle. */
339 TLineStyle iLineStyle;
340 /** The line thickness in twips. By default, zero. */
342 /** The line colour. By default, the system's default foreground colour. */
344 /** ETrue indicates that the line colour is set to the default or current
345 text colour, overriding iColor. EFalse indicates that the iColor value is
346 used. By default, ETrue. */
351 Stores the four sides of a paragraph border.
353 Paragraph borders sides are set individually using functions provided by class
358 class TParaBorderArray
361 TParaBorder iBorder[4];
367 This is a paragraph format attribute, stored as the iBullet member of class
370 Bullet points have a typeface, height, colour and a character code (defines
371 the symbol displayed). Single level bullets only are supported. Bullets may
372 also have a hanging indent. If set, this means that the rest of the paragraph
373 following the line containing the bullet point is indented.
381 IMPORT_C TBool operator ==(const TBullet& aBullet) const;
382 inline TBool operator !=(const TBullet& aBullet) const;
385 Identifies the bullet style.
387 Note: Styles other than ENullStyle and EBulletStyle are not currently supported.
388 They have the same effect as the EBulletStyle.
393 No bullet. Used for style layers that override a bullet with the absence of a bullet.
397 A bullet point. Character with code 0x2022 is used by default.
401 ESmallRomanNumberStyle,
402 ECapitalRomanNumberStyle,
407 /** Paragraph alignment */
410 /** Paragraph left aligned. */
412 /** Paragraph centre aligned. */
414 /** Paragraph right aligned. */
418 /** The Unicode character used to represent the bullet point. By default
420 TChar iCharacterCode; // the bullet or other symbol used if iStyle is EBulletStyle
421 /** The height in twips of the font used for the bullet point character.
423 TUint iHeightInTwips;
424 /** The typeface used for the bullet point character. */
426 /** ETrue to indent the rest of the paragraph from the bullet point.
427 EFalse to align the bullet point character with the rest of the paragraph. */
428 TBool iHangingIndent;
429 /** The colour of the bullet point character. By default, the system's
430 default foreground colour. */
432 TStyle iStyle; // is this a bullet or a number or a letter?
433 TInt iStartNumber; // the number of the first paragraph in a run of paragraphs in this style
434 TAlignment iAlignment; // alignment of the bullet or number within the margin
438 A transient container of paragraph format attributes, including tab stops,
439 bullet points and paragraph borders.
441 Rich and global text objects store paragraph formatting using paragraph format
442 layers (see class CParaFormatLayer). The CParaFormat class is used to store
443 the relevant attribute values when setting or sensing a CParaFormatLayer.
444 It is normally used in combination with a TParaFormatMask, to specify which
445 attributes are relevant to the function concerned.
447 On construction, all CParaFormat member data is initialised. The attributes
448 which are not explicitly set are assigned default values.
452 class CParaFormat: public CBase
455 /** Miscellaneous constants. */
458 /** The maximum number of paragraph borders (= 4). */
462 /** Paragraph border sides */
465 /** The border at the top of the paragraph. */
467 /** The border at the bottom of the paragraph. */
469 /** The border on the left hand side. */
471 /** The border on the right hand side. */
475 /** Line spacing control */
476 enum TLineSpacingControl
478 /** Twips line spacing must be at least as wide as the
479 iLineSpacingInTwips value. */
480 ELineSpacingAtLeastInTwips,
481 /** Twips line spacing must be exactly the iLineSpacingInTwips value. */
482 ELineSpacingExactlyInTwips,
483 /** Pixels line spacing must be at least as wide as the line spacing
485 ELineSpacingAtLeastInPixels,
486 /** Pixels line spacing must be exactly the same as the line spacing
488 ELineSpacingExactlyInPixels
491 /** Paragraph alignment */
494 /** Paragraph aligned to the leading margin (left for left-to-right
495 paragraphs, right for right-to-left paragraphs). */
497 /** Paragraph top aligned. */
498 ETopAlign = ELeftAlign,
499 /** Paragraph centre aligned. */
501 /** Paragraph aligned to the trailing margin (right for left-to-right
502 paragraphs, left for right-to-left paragraphs). */
504 /** Paragraph bottom aligned. */
505 EBottomAlign = ERightAlign,
506 /** Paragraph justified. */
508 /** Used by the spreadsheet application. Unlike ETopAlign and
509 EBottomAlign, provides no default implementation. */
511 /** User-defined paragraph alignment. */
513 /** Absolute left alignment */
515 /** Absolute right alignment */
519 /** Attribute sense mode */
520 enum TParaFormatGetMode
522 /** Indicates that all paragraph format attributes are written to the
523 result when sensing paragraph format attributes. */
525 /** Indicates that tabs, bullets and borders are not sensed. */
529 IMPORT_C static CParaFormat* NewL();
530 IMPORT_C static CParaFormat* NewLC();
531 IMPORT_C static CParaFormat* NewL(const CParaFormat& aFormat);
532 IMPORT_C CParaFormat();
533 IMPORT_C ~CParaFormat();
534 IMPORT_C void ResetNonDestructive(); // preserves any allocated tabs, bullets or borders.
535 IMPORT_C void Reset(); // full reset, deletes and nulls any allocated tabs, bullets or borders.
536 IMPORT_C void CopyL(const CParaFormat& aFormat, const TParaFormatMask& aMask);
537 IMPORT_C void CopyL(const CParaFormat& aFormat);
538 IMPORT_C void Strip(); // Cleans up this paragraph format.
539 IMPORT_C TBool IsEqual(const CParaFormat& aFormat, const TParaFormatMask& aMask) const;
540 IMPORT_C TBool IsEqual(const CParaFormat& aFormat) const;
541 IMPORT_C void StoreTabL(const TTabStop& aTabStop);
542 IMPORT_C void RemoveTab(TInt aTabTwipsPosition);
543 inline void RemoveAllTabs();
544 IMPORT_C const TTabStop TabStop(TInt aTabIndex) const;
545 inline TInt TabCount() const;
546 IMPORT_C TInt LocateTab(TInt aTabTwipsPosition) const;
547 IMPORT_C void SetParaBorderL(TParaBorderSide aSide, const TParaBorder& aBorder); // Overwrites any existing border for that side
548 IMPORT_C void RemoveAllBorders();
549 IMPORT_C const TParaBorder ParaBorder(TParaBorderSide aSide) const;
551 /** Tests whether any paragraph borders have been set.
553 @return ETrue if any paragraph borders have been set, EFalse if not. */
554 inline TBool BordersPresent() const { return iParaBorderArray != NULL;}
556 inline TParaBorder* ParaBorderPtr(TParaBorderSide aSide)
558 /** Gets a pointer to the paragraph border on the side specified. If no
559 paragraph border array has been allocated, returns NULL.
561 @param aSide The side for the paragraph border.
562 @return Pointer to the paragraph border on the specified side. */
563 { return iParaBorderArray ? &iParaBorderArray->iBorder[aSide] : NULL; }
564 IMPORT_C TBool AllBordersEqual(const CParaFormat& aFormat) const;
565 IMPORT_C TBool IsBorderEqual(TParaBorderSide aSide, const CParaFormat& aFormat) const;
567 CParaFormat(const CParaFormat& aFormat);
568 void CreateTabListL();
571 ETabStoreGranularity = 2
574 CParaFormat& operator=(const CParaFormat& aParaFormat); // intentionally unimplemented
576 CArrayFixFlat<TTabStop>* iTabList; // ordered list of tab stops; null if none
577 TParaBorderArray* iParaBorderArray; // array of paragraph borders; null if none
579 /** The background colour of the paragraph. By default the default system
580 background colour. This colour applies to the area bounded by the paragraph
581 border, if one exists. */
582 TLogicalRgb iFillColor;
583 /** The language of the paragraph for proofing. By default
584 KParaDefaultLanguage. Used for example when spell checking a document
585 which contains text in more than one language, so that the program
586 recognises the text as being in another language. */
588 /** The width in twips of the leading margin (left for left-to-right
589 paragraphs, right for right-to-left paragraphs). By default
590 KParaDefaultLeftMargin (zero). */
591 TInt32 iLeftMarginInTwips;
592 /** The width in twips of the trailing margin (right for left-to-right
593 paragraphs, left for right-to-left paragraphs). By default
594 KParaDefaultRightMargin (zero). */
595 TInt32 iRightMarginInTwips;
596 /** An indent for the first line in the paragraph, relative to the leading
597 margin (left for left-to-right paragraphs, right for right-to-left
598 paragraphs). By default KParaDefaultIndent (zero). */
599 TInt32 iIndentInTwips;
600 /** Horizontal alignment of paragraph. By default KParaDefaultHorizAlign
602 TAlignment iHorizontalAlignment;
603 /** Vertical alignment of paragraph, (intended for use by spreadsheet
604 applications). By default KParaDefaultVertAlign (unspecified). */
605 TAlignment iVerticalAlignment;
606 /** Inter-line spacing within the paragraph, in twips. By default
607 KParaDefaultLineSpacing (200 twips). */
608 TInt32 iLineSpacingInTwips; // distance between successive baselines
609 /** Control for the iLineSpacingInTwips value. By default,
610 KParaDefaultLineSpacingControl (ELineSpacingAtLeastInTwips). */
611 TLineSpacingControl iLineSpacingControl; // whether iLineSpacingInTwips means 'at least' or 'exactly'
612 /** Space above paragraph. By default KParaDefaultSpaceBefore (zero). */
613 TInt32 iSpaceBeforeInTwips;
614 /** Space below paragraph. By default KParaDefaultSpaceAfter (zero). */
615 TInt32 iSpaceAfterInTwips;
616 /** Prevents a page break within paragraph if ETrue. By default
617 KParaDefaultKeepTogether (EFalse). */
619 /** Prevents a page break between this paragraph and the following
620 paragraph if ETrue. By default, KParaDefaultKeepWithNext (EFalse). */
622 /** Inserts a page break immediately before this paragraph if ETrue.
623 By default, KParaDefaultStartNewPage (EFalse). */
625 /** Prevents the printing of the last line of a paragraph at the top
626 of the page (referred to as a widow), or the first line of a paragraph
627 at the bottom of the page, (referred to as an orphan). By default,
628 KParaDefaultWidowOrphan (EFalse). */
630 /** Specifies whether the paragraph should line wrap at the right margin.
631 By default KParaDefaultWrap (ETrue). */
633 /** Distance in twips between the paragraph border and the enclosed text.
634 By default KParaDefaultBorderMargin (zero). */
635 TInt32 iBorderMarginInTwips;
636 /** The bullet point associated with the paragraph. A NULL value indicates
637 no bullet point. By default NULL. */
639 /** Specifies the default tab stop width. By default KParaDefaultTabWidth
641 TUint32 iDefaultTabWidthInTwips;
645 Masks the paragraph format attributes which are involved when setting and
646 sensing paragraph formatting.
648 Used in conjunction with an object of class CParaFormat. When setting formatting,
649 only the attributes which are set in the mask will participate in the relevant
650 function. When sensing formatting, on return, the mask indicates which attributes
651 were sensed from the format layer, and were not taken from the default values.
655 class TParaFormatMask
658 inline TParaFormatMask();
659 inline void SetAttrib(TTextFormatAttribute aAttribute);
660 inline void ClearAttrib(TTextFormatAttribute aAttribute);
661 IMPORT_C void SetAll();
662 IMPORT_C void ClearAll();
663 inline TBool AttribIsSet(TTextFormatAttribute aAttribute) const;
664 inline TBool IsNull() const;
665 IMPORT_C TBool operator==(const TParaFormatMask& aMask) const;
666 inline TBool operator!=(const TParaFormatMask& aMask) const;
673 Specifies the font-independent character format attributes, including bold,
674 italics and underlining.
676 An instance of this class is owned by the character formatting container (class
681 class TFontPresentation
685 /** Highlight style */
686 enum TFontHighlightStyle
688 /** No highlighting used. */
690 /** Normal (square cornered) highlighting used. */
691 EFontHighlightNormal,
692 /** Rounded corner highlighting used. */
693 EFontHighlightRounded,
694 /** Text is drawn offset towards the bottom-right in the highlight
695 colour, (iHighlightColor) before being drawn again in the text colour,
696 (iTextColor) creating a shadow effect. */
697 EFontHighlightShadow,
698 /** Placeholder for "unrecognised word" highlighting style for FEPs */
699 EFontHighlightNoMatchesIndicator,
700 /** First custom highlighting style is used.
701 @see MFormCustomDraw::DrawText(). */
702 EFontHighlightFirstCustomStyle = 128,
703 /** Second custom highlighting style is used.
704 @see MFormCustomDraw::DrawText(). */
705 EFontHighlightLastCustomStyle = 255
709 /** Vertical picture alignment */
712 /** The top of the picture is aligned flush with the top of the font's
713 ascent, so that the picture may descend below the line. */
715 /** The bottom of the picture is aligned flush with the bottom of the
716 font's descent so that the picture may extend above the line. */
718 /** The picture is aligned so that its centre is positioned at the
719 baseline of the line. */
721 /** The bottom of the picture is aligned with the baseline of the font.
722 This is the default. */
726 IMPORT_C TFontPresentation();
729 IMPORT_C TBool IsEqual(const TFontPresentation& aFontPresentation, const TCharFormatMask& aMask) const;
731 /** The text colour. By default, the default system foreground colour. */
732 TLogicalRgb iTextColor;
733 /** The highlight colour for selected text. Only takes effect if
734 iHighlightStyle is not EFontHighlightNone. By default, the default system
735 foreground colour. */
736 TLogicalRgb iHighlightColor; // Background color
737 /** Style for character highlighting. By default EFontHighlightNone. */
738 TFontHighlightStyle iHighlightStyle;
739 /** The value of the strikethrough attribute. By default EStrikethroughOff. */
740 TFontStrikethrough iStrikethrough;
741 /** The value of the underline attribute. By default EUnderlineOff. */
742 TFontUnderline iUnderline;
743 /** Specifies whether or not text is hidden. Note that hidden text is not
744 currently supported by the text layout engine. This attribute is provided
745 to preserve information when copying from and to devices which support
746 hidden text. By default EFalse. */
748 /** The vertical alignment of a picture character. By default
750 TAlignment iPictureAlignment;
754 A transient container of character format attributes, including
755 font-dependent and font-independent attributes.
757 The font-independent attributes are stored in a TFontPresentation object.
758 Rich and global text objects store character formatting using character format
759 layers (see class CCharFormatLayer). The TCharFormat class is used to store
760 the relevant attribute values when setting or sensing a CCharFormatLayer.
761 It is normally used in combination with a TCharFormatMask, to specify which
762 attributes are relevant to the function concerned.
769 IMPORT_C TCharFormat();
770 IMPORT_C TCharFormat(const TDesC &aTypefaceName, TInt aHeight);
773 IMPORT_C TBool IsEqual(const TCharFormat& aFormat, const TCharFormatMask& aMask) const;
774 IMPORT_C TBool IsEqual(const TCharFormat& aFormat) const;
776 /** Specifies the language of individual characters for proofing. Used for
777 example when spell checking a document which contains text in more than one
778 language, so that the program recognises the text as being in another
779 language. Language is also a paragraph format attribute. If the language
780 setting of a character is different from the language setting of the
781 containing paragraph, the character's setting takes precedence. */
783 /** Font independent character format attributes. */
784 TFontPresentation iFontPresentation;
785 /** Device independent font specification. */
790 Masks the character format attributes which are involved when setting and
791 sensing character formatting.
793 Used in conjunction with an object of class TCharFormat.
795 When setting formatting, only the attributes which are set in the mask should
796 participate in the relevant function. When sensing formatting, on return,
797 the mask indicates which attributes were sensed from the format layer, and
798 were not taken from the default values.
802 class TCharFormatMask
805 inline TCharFormatMask();
806 inline void SetAttrib(TTextFormatAttribute aAttribute);
807 inline void ClearAttrib(TTextFormatAttribute aAttribute);
808 inline TBool AttribIsSet(TTextFormatAttribute aAttribute) const;
809 IMPORT_C void SetAll();
810 IMPORT_C void ClearAll();
811 inline TBool IsNull()const;
812 IMPORT_C TBool operator==(const TCharFormatMask& aMask) const;
813 inline TBool operator!=(const TCharFormatMask& aMask) const;
819 #include <txtfrmat.inl>