2 * Copyright (c) 1999-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.
15 * The main header file for TAGMA, the low-level text formatting engine for EPOC.
16 * 'Tm' stands for 'TAGMA' and is the standard prefix for TAGMA classes, after
17 * the C, T, or whatever.
29 #include <linebreak.h>
31 // forward declarations
36 class RParagraphStyleInfo;
40 class TCursorSelection;
41 class TTmHighlightExtensions;
42 class TBidirectionalContext;
47 A character format; all dimensions are in twips. A character format object
48 stores all text style attributes that can differ from any one character to the
49 next. Attributes that affect an entire paragraph only are kept in RTmParFormat
51 The class should only be used internally by FORM component.
57 /** Bit assignments for effects */
60 EBackground = 1, ///< Text background is drawn in the background colour
61 ERounded = 2, ///< Text background (if any) has rounded corners
62 EUnderline = 4, ///< Text is underlined
63 EStrikethrough = 8, ///< Text is struck through with a horizontal line.
64 EShadow = 16, ///< Text has a drop shadow.
65 /** Bits 24-31 are reserved for styles defined by the custom drawer. */
66 EUserDefinedMask = 0xFF000000,
67 /** Shift TCharFormat highlight styles left by this to get the
68 TTmCharFormat effects portion. */
69 EUserDefinedShift = 24,
70 /** For custom drawers: draw whatever is wanted for "no matches" in the FEP. */
71 ENoMatchesIndicator = 0x4000000,
72 /** Reset if the effect in bits 24-30 is defined defined by Symbian,
73 set if it is defined externally. */
74 ECustomDrawEffectIsExternallyDefined = 0x80000000
77 /** Picture alignment */
78 enum TPictureAlignment
80 EPictureAlignBaseline,
86 IMPORT_C TTmCharFormat();
87 IMPORT_C TTmCharFormat(const TDesC& aFontName,TInt aFontHeight);
88 IMPORT_C void operator=(const TCharFormat& aFormat);
89 inline TTmCharFormat(const TCharFormat& aFormat);
90 IMPORT_C void GetTCharFormat(TCharFormat& aFormat) const;
91 IMPORT_C TBool operator==(const TTmCharFormat& aFormat) const;
92 inline TBool operator!=(const TTmCharFormat& aFormat) const;
94 TOpenFontSpec iFontSpec;
95 TLogicalRgb iTextColor;
96 TLogicalRgb iBackgroundColor; // used only when EBackground flag is set in iEffects
97 TUint iEffects; // bit flags as defined above;
98 // note that effects NEVER change character metrics and so can
99 // be ignored when measuring text
100 TUint iLanguage; // language used for proofing
101 TPictureAlignment iPictureAlignment;// vertical alignment of embedded objects
102 TUint iTag; // tag for use by URL parsers, etc.; a way of marking a range of
103 // text without using any typographic attributes
107 The text customization interface. You can customize the colors, word
108 spacing, line breaking, line height calculation, background drawing, and text
109 appearance, of a text object by supplying an implementation of the MTmCustom
110 class, either directly (as in CTmText::CustomizeL, which takes a pointer to
111 MTmCustom) or indirectly, making use of the fact that MTmSource is derived from
112 MTmCustom (as in CTmTextLayout::SetTextL, which takes a reference to
118 : public MLineBreaker
122 TLineHeightParam structure is used in MTmCustom::SetLineHeight() method to set
123 text line height related parameters such as max character height, max ascent and descent,
124 height and depth of the tallest pictures (top-aligned, bottom-aligned or centered).
125 @see MTmCustom::SetLineHeight()
129 class TLineHeightParam
132 inline TLineHeightParam();
133 /** Height of the highest character in the line. */
135 /** Depth of the deepest character in the line. */
137 /** Height plus depth of the tallest top-aligned picture. */
138 TInt iMaxTopPictureHeight;
139 /** Height plus depth of the tallest bottom-aligned picture. */
140 TInt iMaxBottomPictureHeight;
141 /** Height plus depth of the tallest centred picture. */
142 TInt iMaxCenterPictureHeight;
143 /** Height of the tallest character of any in the fonts in the line. */
144 TInt iFontMaxCharHeight;
145 /** Depth of the deepest character of any in the fonts in the line. */
146 TInt iFontMaxCharDepth;
147 /** Maximum ascent of the fonts in the line. */
149 /** Maximum descent of the fonts in the line. */
150 TInt iFontMaxDescent;
151 /** Desired precise or minimum line height. */
152 TInt iDesiredLineHeight;
153 /** True if the line height must be precise. */
154 TBool iExactLineHeight;
157 /** The Unicode line breaking classes; see Unicode Technical Report 14.
158 Not a named enumerated type, so that overriding applications can add new
159 line breaking classes freely.
160 The description of each constant gives the name of the line-breaking
161 class, an example and a brief, imprecise description of the default
162 behaviour of characters of that class.
166 /** Opening Punctuation (e.g. '['). Breaking after prohibited. */
168 /** Closing Punctuation (e.g. ']'). Breaking before prohibited. */
170 /** Ambiguous Quotes (e.g. '"'). Breaking before and after prohibited. */
172 /** Glue (e.g. Non-breaking space). Breaking before and after prohibited
173 unless spaces are present. */
175 /** Non-Starter (e.g. small Japanese kana). Breaking before prohibited
176 if no spaces present. */
178 /** Exclamation or Interrogation (e.g. '?'). Like closing punctuation
179 except before Postfix or Non-starter. */
181 /** Symbol (e.g. '/'. Like Alphabetic, but allows breaking before
184 /** Numeric Infix Separator (e.g. ','). Forbids breaking after any and before
187 /** Numeric Prefix (e.g. '$'). Forbids breaking before Numeric. */
189 /** Numeric Postfix (e.g. '%'). Forbids breaking after Numeric. */
191 /** Numeric (e.g. '1'). */
193 /** Alphabetic (e.g. 'a'). */
195 /** Ideographic (e.g. Japanese Kanji). Generally break before or after */
197 /** Inseparable (e.g. ellipsis). Forbid breaks between Inseparables. */
199 /** Hyphen (e.g. '-'). Allows a break after except before Numeric. */
201 /** Break After. Generally allow a break after. Breaking between Break
202 Afters not separated by spaces is prohibited. */
204 /** Break Before. Generally allow a break before. Breaking between Break
205 Befores not separated by spaces is prohibited. */
207 /** Break Before and After. Generally allow a break before or after.
208 Breaking between Break Before and Afters is prohibited, even if spaces
211 /** Zero-Width Space. Allow a break. */
213 /** Combining Mark. Takes on the class of its base class. */
215 /** Mandatory Break. */
217 /** Carriage Return. Break after unless part of a CRLF pair. */
219 /** Line Feed. Break after. */
221 /** Surrogate. Half of a surrogate pair. */
223 /** Contingent Break (e.g. embedded pictures). Uses external
227 /** Space. Intervening characters of class Space are indicated by
228 aHaveSpaces in LineBreakPossible. */
231 /** Complex Context (e.g. Thai). Runs of Complex Context are passed to
232 GetLineBreakInContext. */
235 /** Ambiguous. Characters of ambiguous East Asian width are treated
236 as Alphabetic, unless they are resolved as being "Wide", in which case
237 they are treated as Ideographic. */
240 /** The Xx class is used when the class is unknown; e.g.; outside the provided context. */
243 /** The number of Unicode line break classes. */
247 IMPORT_C virtual TRgb SystemColor(TUint aColorIndex,TRgb aDefaultColor) const;
248 IMPORT_C virtual TInt Stretch(TUint aChar) const;
249 IMPORT_C virtual TUint Map(TUint aChar) const;
250 IMPORT_C virtual void SetLineHeight(const TLineHeightParam& aParam,TInt& aAscent,TInt& aDescent) const;
251 IMPORT_C virtual void DrawBackground(CGraphicsContext& aGc,const TPoint& aTextLayoutTopLeft,const TRect& aRect,
252 const TLogicalRgb& aBackground,TRect& aRectDrawn) const;
253 IMPORT_C virtual void DrawLineGraphics(CGraphicsContext& aGc,const TPoint& aTextLayoutTopLeft,const TRect& aRect,
254 const TTmLineInfo& aLineInfo) const;
255 IMPORT_C virtual void DrawText(CGraphicsContext& aGc,const TPoint& aTopLeft,const TRect& aRect,
256 const TTmLineInfo& aLineInfo,const TTmCharFormat& aFormat,
257 const TDesC& aText,const TPoint& aTextOrigin,TInt aExtraPixels) const;
258 IMPORT_C virtual void DrawPicture(CGraphicsContext& aGc,
259 const TPoint& aTextLayoutTopLeft, const TRect& aRect,
260 MGraphicsDeviceMap& aDevice, const CPicture& aPicture) const;
261 IMPORT_C virtual TUint LineBreakClass(TUint aCode,TUint& aRangeStart,TUint& aRangeEnd) const;
262 IMPORT_C virtual TBool LineBreakPossible(TUint aPrevClass,TUint aNextClass,TBool aHaveSpaces) const;
263 IMPORT_C virtual TBool GetLineBreakInContext(const TDesC& aText,TInt aMinBreakPos,TInt aMaxBreakPos,
264 TBool aForwards,TInt& aBreakPos) const;
265 IMPORT_C virtual TBool IsHangingCharacter(TUint aChar) const;
268 IMPORT_C void SetPenColor(CGraphicsContext& aGc,TLogicalRgb aColor) const;
269 IMPORT_C void SetBrushColor(CGraphicsContext& aGc,TLogicalRgb aColor) const;
270 IMPORT_C TRgb SystemColor(TLogicalRgb aColor) const;
273 /* MTmSource extension interface****************************************************/
276 const TUid KTmCustomExtensionUid = {0x10285BB5};
278 /** MTmSource Extension Interface abstract base class to enable further customisation of the source.
280 MTmSource derivers should also derive from this interface to enable drawing text in context
282 This interface should be returned by the overridden
283 MTmSource::GetExtendedInterface function when KUidMTmSourceExtension is
287 @see KUidMTmSourceExtension
291 class MTmCustomExtension
294 IMPORT_C virtual TRgb SystemColor(TUint aColorIndex,TRgb aDefaultColor) const;
295 IMPORT_C virtual void DrawText(CGraphicsContext& aGc,const TPoint& aTopLeft,const TRect& aRect,
296 const TTmLineInfo& aLineInfo,const TTmCharFormat& aFormat,
297 const TDesC& aText, const TInt aStart, const TInt aEnd,const TPoint& aTextOrigin,TInt aExtraPixels) const;
299 IMPORT_C void SetPenColor(CGraphicsContext& aGc,TLogicalRgb aColor) const;
300 IMPORT_C void SetBrushColor(CGraphicsContext& aGc,TLogicalRgb aColor) const;
301 IMPORT_C TRgb SystemColor(TLogicalRgb aColor) const;
305 A structure for returning information about a line. One of these is
306 returned by all hit-detection functions. Typically, after finding the position
307 in the document that corresponds to given x-y coordinates, you will want some
308 more information like the line's bounding rectangle. When you call, for
309 example, CTmTextLayout::FindXyPos you will receive a TTmLineInfo object that
310 will tell you this, and much more.
318 // bit values for iFlags
324 ELineEndsInForcedLineBreak = 8,
325 EPictureButtsLowerEdge = 16, /**< @deprecated - no effect, present for compatibility only */
326 EPictureButtsUpperEdge = 32 /**< @deprecated - no effect, present for compatibility only */
329 inline TTmLineInfo();
331 /** Outer enclosing rectangle including margins */
334 /** Inner enclosing rectangle: the text only */
337 /** y coordinate of the baseline */
340 /** Start document position */
343 /** End document position */
349 /** Paragraph number */
352 /** Line number in the paragraph */
355 /** y coordinate of the top of the paragraph */
358 /** Start of paragraph, end of paragraph, etc. */
363 A structure to hold a logical document position that can be converted to a raw
364 document position or an x-y position.
366 A document position can specify a leading or trailing edge or a text
367 directionality so that bidirectional hit testing can use both these
370 The leading edge at position N is the position before character N in logical
371 order, and the trailing edge is the position after character in logical order.
373 Specification by directionality works differently. Character N in left-to-right
374 text is preceded by position N (left-to-right) and followed by position N+1
375 (left-to-right). Character N in right-to-left text is preceded (in display
376 order) by position N+1 (right-to-left) and followed by position N
403 inline TTmDocPosSpec();
404 inline TTmDocPosSpec(TInt aPos,TType aType);
405 inline TTmDocPosSpec(const TTmDocPos& aRawDocPos);
407 /** the edge position in the document; 0 ... document length */
409 /** the type as specified above */
414 A structure for holding a raw document position that can be converted to or
415 from an x-y position and compared ordinally, which cannot be done with the more
416 abstract TTmDocPosSpec class. Leading edges are distinguished from trailing
417 edges so that bidirectional hit testing and cursor positioning can distinguish
418 between 'after character N', and 'before character N + 1', which may be some
419 distance apart if N and N + 1 are in runs of opposite directionality.
428 inline TTmDocPos(TInt aPos,TBool aLeadingEdge);
429 IMPORT_C TBool operator==(const TTmDocPos& aPos) const;
430 inline TBool operator!=(const TTmDocPos& aPos) const;
431 IMPORT_C TBool operator>(const TTmDocPos& aPos) const;
432 IMPORT_C TBool operator>=(const TTmDocPos& aPos) const;
433 inline TBool operator<(const TTmDocPos& aPos) const;
434 inline TBool operator<=(const TTmDocPos& aPos) const;
436 /** the edge position in the document; 0 ... document length */
438 /** true if the position is a leading edge */
443 Holds information about a position in a document.
451 /** Document position. */
453 /** True if the position is attatched to text flowing right-to-left. */
455 /** Intersection of the character edge with the baseline. */
460 A structure for returning information about a position in a line.
461 The class should only be used internally by FORM component.
470 TTmPosInfo(const TTmPosInfo2& a) : iDocPos(a.iDocPos), iEdge(a.iEdge) {}
471 TTmDocPos iDocPos; // the document position
472 TPoint iEdge; // intersection of the character edge at iDocPos with the baseline
477 Cursor placement. Used as an argument to CTextView::SetCursorPlacement().
478 @see CTextView::SetCursorPlacement()
482 enum TTmCursorPlacement
484 /** The text cursor is a vertical line at the insertion position, with its height
485 and depth based on the metrics of the previous character in the paragraph
486 or if none, the next character. */
488 /** The text cursor is an underline below the character logically after the insertion
490 ECursorUnderlineNext,
491 /** The text cursor is an underline below the character logically before the insertion
499 A mixin class to make it easy for higher-level classes that own a CTmTextLayout
500 object to have enquiry functions without it being necessary to implement them
501 all as forwarding functions. The owner class just implements TextLayout and
502 overrides GetOrigin if necessary.
504 Non-const CTmTextLayout functions like Clear are not included because allowing
505 them to be called on owner classes would probably put the owner class into an
508 The word Layout is prefixed, suffixed or infixed to functions with names that
509 would usually conflict with owner class names. For example, we have DrawLayout,
510 not Draw, and GetMinimumLayoutSizeL, not GetMinimumSizeL.
512 The class should only be used internally by FORM component.
515 class MTmTextLayoutForwarder
519 IMPORT_C void DrawLayout(CGraphicsContext& aGc,const TPoint& aTopLeft,const TRect& aClipRect,
520 const TLogicalRgb* aDocBackground,TBool aDrawParBackground) const;
521 IMPORT_C void DrawBackground(CGraphicsContext& aGc,const TPoint& aTopLeft,const TRect& aClipRect,
522 const TLogicalRgb& aBackground) const;
523 IMPORT_C void InvertLayout(CGraphicsContext& aGc,const TPoint& aTopLeft,TInt aStartDocPos,TInt aEndDocPos);
524 IMPORT_C TBool FindDocPos(const TTmDocPosSpec& aDocPos,TTmPosInfo2& aPosInfo,TTmLineInfo& aLineInfo) const;
525 IMPORT_C TBool FindXyPos(const TPoint& aXyPos,TTmPosInfo2& aPosInfo,TTmLineInfo& aLineInfo) const;
526 IMPORT_C TBool FindXyPosWithDisambiguation(const TPoint& aXyPos,
527 TTmPosInfo2& aPosLeft, TTmPosInfo2& aPosRight,
528 TTmLineInfo& aLineInfo) const;
529 IMPORT_C TBool DocPosToLine(const TTmDocPosSpec& aDocPos,TTmLineInfo& aLineInfo) const;
530 IMPORT_C TBool LineNumberToLine(TInt aLineNumber,TTmLineInfo& aLineInfo) const;
531 IMPORT_C TBool ParNumberToLine(TInt aParNumber,TInt aLineInPar,TTmLineInfo& aLineInfo) const;
532 IMPORT_C TBool YPosToLine(TInt aYPos,TTmLineInfo& aLineInfo) const;
533 IMPORT_C TInt WidthOfWidestLine(TInt aTop = 0,TInt aBottom = KMaxTInt) const;
534 IMPORT_C void HorizontalExtremes(TInt &aLeft, TInt &aRight,
535 TInt aTopY = 0, TInt aBottomY = KMaxTInt) const;
536 IMPORT_C TBool GetNextVisualCursorPos(const TTmDocPosSpec& aDocPos,TTmPosInfo2& aInfo,TBool aToLeft) const;
537 IMPORT_C TBool GetNextPosLeftWithDisambiguation(const TTmDocPosSpec& aDocPos,
538 TTmPosInfo2& aPosLeft, TTmPosInfo2& aPosRight) const;
539 IMPORT_C TBool GetNextPosRightWithDisambiguation(const TTmDocPosSpec& aDocPos,
540 TTmPosInfo2& aPosLeft, TTmPosInfo2& aPosRight) const;
541 IMPORT_C TBool GetCursor(const TTmDocPosSpec& aDocPos,TTmCursorPlacement aPlacement,
542 TTmLineInfo& aLineInfo,TPoint& aOrigin,TInt& aWidth,TInt& aAscent,TInt& aDescent) const;
544 IMPORT_C TInt Lines() const;
545 IMPORT_C TInt Paragraphs() const;
546 IMPORT_C TBool GetDisplayedText(TInt aLineNumber,TDes& aText,TInt& aNeeded) const;
547 IMPORT_C void GetMinimumLayoutSizeL(TInt aWrapWidth,TSize& aSize) const;
548 IMPORT_C void GetMinimumLayoutSizeL(TInt aWrapWidth,TBool aAllowLegalLineBreaksOnly,TSize& aSize) const;
549 IMPORT_C TInt StartChar() const;
550 IMPORT_C TInt EndChar() const;
551 IMPORT_C TInt LayoutWidth() const;
552 IMPORT_C TInt LayoutHeight() const;
554 // deprecated functions
556 IMPORT_C TBool FindDocPos(const TTmDocPos& aDocPos,TTmPosInfo& aPosInfo,TTmLineInfo& aLineInfo) const;
558 IMPORT_C TBool FindXyPos(const TPoint& aXyPos,TTmPosInfo& aPosInfo,TTmLineInfo& aLineInfo) const;
560 IMPORT_C TBool DocPosToLine(const TTmDocPos& aDocPos,TTmLineInfo& aLineInfo) const;
562 IMPORT_C TBool GetNextVisualCursorPos(const TTmDocPos& aDocPos,TTmPosInfo& aInfo,TBool aToLeft) const;
564 IMPORT_C TBool GetCursor(const TTmDocPos& aDocPos,
565 TTmCursorPlacement aPlacement, TTmLineInfo& aLineInfo,
566 TPoint& aOrigin, TInt& aWidth, TInt& aAscent, TInt& aDescent) const;
568 /** Returns a reference to the CTmTextLayoutObject this
569 MTmTextLayoutForwarder forwards inquiries to. */
570 virtual const CTmTextLayout& TextLayout() const = 0;
572 /** The origin is subtracted from coordinates passed in and added to those
574 IMPORT_C virtual void GetOrigin(TPoint& aPoint) const;
576 void FixUpLineInfo(TTmLineInfo& aInfo,const TPoint* aOrigin = NULL) const;
579 /** Constructs a TTmLineInfo object, setting all data members to 0. */
580 TTmLineInfo::TTmLineInfo()
582 Mem::FillZ(this,sizeof(*this));
585 /** Constructs a TTmDocPos object, setting iPos to 0 and iLeadingEdge to false.
586 This is the lowest legal value for a TTmDocPos object. A trailing edge comes
587 before a leading edge because it is the trailing edge of the character before
588 the position, while the leading edge is that of the character after the
589 position. ('Leading' means the first to be encountered when traversing the
590 document in logical order). */
591 TTmDocPos::TTmDocPos():
597 /** Constructs a TTmDocPos object, setting iPos to aPos and iLeadingEdge to
600 TTmDocPos::TTmDocPos(TInt aPos,TBool aLeadingEdge):
602 iLeadingEdge(aLeadingEdge)
606 /** Constructs a TTmDocPosSpec, setting the position to 0 and the type to
608 TTmDocPosSpec::TTmDocPosSpec():
616 The not equal operator.
617 @return True if both sides have different values.
619 TBool TTmDocPos::operator!=(const TTmDocPos& aPos) const { return !((*this)==aPos); }
622 Smaller than operator.
624 True if the right side of the operator is further on in the document than
627 TBool TTmDocPos::operator<(const TTmDocPos& aPos) const { return !((*this)>=aPos); }
630 Smaller than or equal to operator.
632 True if the right side of the operator is further on in the document than
633 the left hand side or if both sides are identical.
635 TBool TTmDocPos::operator<=(const TTmDocPos& aPos) const { return !((*this)>aPos); }
637 /** Constructs a TTmDocPosSpec, setting the position to aPos and the type to
640 TTmDocPosSpec::TTmDocPosSpec(TInt aPos,TType aType):
646 /** Constructs a TTmDocPosSpec from a TTmDocPos. */
647 TTmDocPosSpec::TTmDocPosSpec(const TTmDocPos& aDocPos):
649 iType(aDocPos.iLeadingEdge ? ELeading : ETrailing)
653 /** Constructs a TTmCharFormat by converting the information in a TCharFormat. */
654 TTmCharFormat::TTmCharFormat(const TCharFormat& aFormat)
659 /** The inequality operator. Return TRUE if this object and aFormat differ in any way. */
660 TBool TTmCharFormat::operator!=(const TTmCharFormat& aFormat) const
662 return !operator==(aFormat);
665 /** Constructs a line height parameter structure, setting all the data members
667 MTmCustom::TLineHeightParam::TLineHeightParam()
669 Mem::FillZ(this,sizeof(*this));
672 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
673 #include <tagma_internal.h>
674 #include <tagmalayoutandsource.h>
677 #endif // __TAGMA_H__