fontservices/textbase/inc/BidiText.h
changeset 45 662fa7de7023
equal deleted inserted replaced
41:ea44a32a96bc 45:662fa7de7023
       
     1 // Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef BIDITEXT_H_
       
    17 #define BIDITEXT_H_
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <gdi.h>	// class CGraphicsContext
       
    21 #include <bidi.h>	// class TBidirectionalState::TRunInfo
       
    22 enum CGraphicsContext::TTextAlign;
       
    23 class MLineBreaker;
       
    24 class RRunInfoArray;
       
    25 class CBidiTextTls;
       
    26 
       
    27 
       
    28 /**
       
    29 This enumeration holds the possible panic codes that may be raised 
       
    30 by the BidiText API on detecting an unrecoverable error.
       
    31 @publishedAll
       
    32 @released
       
    33 */
       
    34 enum TBidiPanic
       
    35 	{
       
    36 	/** The call to RRunInfoArray::OpenL() has not been made prior to this call to TBidiText::SetText()
       
    37 	@see TBidiText::SetText	*/
       
    38 	EBidiPanic_RunArrayNull						= 0,
       
    39 	
       
    40 	/** Maximum number of lines that the text will need to be split into is invalid i.e less than zero or negative.
       
    41 	@see TBidiText::NewL
       
    42 	@see TBidiText::MinimumSize	*/
       
    43 	EBidiPanic_InvalidMaxline					= 1,
       
    44 	
       
    45 	/** Maximum number of characters are invalid i.e less than zero or negative.
       
    46 	@see TBidiText::NewL */
       
    47 	EBidiPanic_InvalidReservedMaxLength			= 2,
       
    48 	
       
    49 	/** Maximum width of the text in pixels is invalid i.e zero or negative.
       
    50 	@see TBidiText::MinimumSize */
       
    51 	EBidiPanic_InvalidWrappingWidth				= 3,
       
    52 	
       
    53 	/** Number of empty pixels between two lines of text are invalid i.e zero or negative.
       
    54 	@see TBidiText::MinimumSize */
       
    55 	EBidiPanic_InvalidLineGap					= 4,
       
    56 	
       
    57 	/** Text length for display is invalid i.e zero or negative.
       
    58 	@see TBidiText::DisplayText
       
    59 	@see TBidiText::LineOfDisplayText */
       
    60 	EBidiPanic_InvalidVisualOrderedTextLength	= 5,
       
    61 	
       
    62 	/** Line number to retrieve is invalid i.e zero or negative. 
       
    63 	@see TBidiText::LineOfDisplayText */
       
    64 	EBidiPanic_InvalidLineNumber				= 6
       
    65 	};
       
    66 
       
    67 /** 
       
    68 This class works as a replacement for HBufC in those cases where a small 
       
    69 amount of text is being formatted simply. The text must be all of one style 
       
    70 and broken into lines of all the same length. The number of lines and the text 
       
    71 itself is specified on construction, and the text may then be re-broken, 
       
    72 re-truncated and re-drawn with non-leaving functions. 
       
    73 @publishedAll
       
    74 @released
       
    75 */
       
    76 class TBidiText
       
    77 	{
       
    78 public:
       
    79 	/** Overall directionality of the text. */
       
    80 	enum TDirectionality
       
    81 		{
       
    82 		/** Text reading begins on the left. */
       
    83 		ELeftToRight = 0,
       
    84 		/** Text reading begins on the right. */
       
    85 		ERightToLeft = 1
       
    86 		};
       
    87 
       
    88 	/** Class specific panic codes 
       
    89 	@deprecated This enum has been replaced by TBidiPanic.
       
    90     */
       
    91 	enum TPanicCodes
       
    92 		{
       
    93 		EPanicRunArrayNull,
       
    94 		};
       
    95 
       
    96 	IMPORT_C static TDirectionality ScriptDirectionality(TLanguage aLanguage);
       
    97 	IMPORT_C static TDirectionality TextDirectionality(
       
    98 		const TDesC& aText, TBool* aFound = 0);
       
    99 protected:
       
   100 	TBidiText();
       
   101 public:
       
   102 	IMPORT_C static TBidiText* NewL(TInt aReservedMaxLength, TInt aMaxLines);
       
   103 	IMPORT_C static TBidiText* NewL(const TDesC& aText, TInt aMaxLines);
       
   104 	IMPORT_C static TBidiText* NewL(const TDesC& aText, TInt aMaxLines,
       
   105 		TDirectionality aDirectionality);
       
   106 	IMPORT_C TInt SetText(const TDesC& aText, RRunInfoArray& aRunInfoArray);
       
   107 	IMPORT_C TInt SetText(const TDesC& aText, TDirectionality aDirectionality, RRunInfoArray& aRunInfoArray);
       
   108 	IMPORT_C void SetTruncationChar(TChar aTruncateWith);
       
   109 	IMPORT_C void WrapText(TInt aWrappingWidth, const CFont& aFont,
       
   110 		const MLineBreaker* aBreaker, TInt aMaxLines);
       
   111 	IMPORT_C void WrapText(TInt aWrappingWidth, const CFont& aFont,
       
   112 		const MLineBreaker* aBreaker = NULL);
       
   113 	IMPORT_C TSize MinimumSize(TInt aWrappingWidth, const CFont& aFont, TInt aLineGap, TInt aMaxLines = -1,
       
   114 		const MLineBreaker* aBreaker = NULL) const;	
       
   115 	IMPORT_C TPtrC Text() const;
       
   116 	IMPORT_C TPtrC DisplayText() const;
       
   117 	IMPORT_C TInt WrappingWidth() const;
       
   118 	IMPORT_C TDirectionality Directionality() const;
       
   119 	IMPORT_C TChar TruncationChar() const;
       
   120 	IMPORT_C TInt NumberOfLinesInDisplayText() const;
       
   121 	IMPORT_C TPtrC LineOfDisplayText(TInt aLine, TInt& aWidthInPixels) const;
       
   122 	IMPORT_C void DrawText(CGraphicsContext& aGc, const TPoint& aLeft) const;
       
   123 	IMPORT_C void DrawText(CGraphicsContext& aGc,
       
   124 		const TPoint& aLeft, TInt aBaseLineSpacing,
       
   125 		CGraphicsContext::TTextAlign aAlignment) const;
       
   126 	IMPORT_C void DrawText(CGraphicsContext& aGc,
       
   127 		const TPoint& aLeft, TInt aBaseLineSpacing) const;
       
   128 private:
       
   129 	TInt DoWrapText(TInt aWrappingWidth, const CFont& aFont, const MLineBreaker* aBreaker, 
       
   130 		TInt aMaxLines, TText*& aOutputText, TInt& aNumLines, TInt16* aLineWidthArray) const;
       
   131 	};
       
   132 
       
   133 
       
   134 /**
       
   135 This class is used to keep track of the shared run info array. 
       
   136 Keep it open for as long as the TBidiText object is used. The same
       
   137 RRunInfoArray object can be used with several different TBidiText objects.
       
   138 @publishedAll
       
   139 @released
       
   140 */
       
   141 class RRunInfoArray
       
   142 	{
       
   143 	friend class TBidiText;
       
   144 
       
   145 public:	
       
   146 	IMPORT_C RRunInfoArray();
       
   147 	IMPORT_C void OpenL();
       
   148 	IMPORT_C void Close();
       
   149 
       
   150 private:
       
   151 	TBidirectionalState::TRunInfo* RunArray() const;
       
   152 
       
   153 private:
       
   154 	CBidiTextTls* iTls;
       
   155 	};
       
   156 
       
   157 #endif