sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef BIDITEXT_H_ sl@0: #define BIDITEXT_H_ sl@0: sl@0: #include sl@0: #include sl@0: #include // class TBidirectionalState::TRunInfo sl@0: enum CGraphicsContext::TTextAlign; sl@0: class MLineBreaker; sl@0: class RRunInfoArray; sl@0: class CBidiTextTls; sl@0: sl@0: sl@0: /** sl@0: This enumeration holds the possible panic codes that may be raised sl@0: by the BidiText API on detecting an unrecoverable error. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: enum TBidiPanic sl@0: { sl@0: /** The call to RRunInfoArray::OpenL() has not been made prior to this call to TBidiText::SetText() sl@0: @see TBidiText::SetText */ sl@0: EBidiPanic_RunArrayNull = 0, sl@0: sl@0: /** Maximum number of lines that the text will need to be split into is invalid i.e less than zero or negative. sl@0: @see TBidiText::NewL sl@0: @see TBidiText::MinimumSize */ sl@0: EBidiPanic_InvalidMaxline = 1, sl@0: sl@0: /** Maximum number of characters are invalid i.e less than zero or negative. sl@0: @see TBidiText::NewL */ sl@0: EBidiPanic_InvalidReservedMaxLength = 2, sl@0: sl@0: /** Maximum width of the text in pixels is invalid i.e zero or negative. sl@0: @see TBidiText::MinimumSize */ sl@0: EBidiPanic_InvalidWrappingWidth = 3, sl@0: sl@0: /** Number of empty pixels between two lines of text are invalid i.e zero or negative. sl@0: @see TBidiText::MinimumSize */ sl@0: EBidiPanic_InvalidLineGap = 4, sl@0: sl@0: /** Text length for display is invalid i.e zero or negative. sl@0: @see TBidiText::DisplayText sl@0: @see TBidiText::LineOfDisplayText */ sl@0: EBidiPanic_InvalidVisualOrderedTextLength = 5, sl@0: sl@0: /** Line number to retrieve is invalid i.e zero or negative. sl@0: @see TBidiText::LineOfDisplayText */ sl@0: EBidiPanic_InvalidLineNumber = 6 sl@0: }; sl@0: sl@0: /** sl@0: This class works as a replacement for HBufC in those cases where a small sl@0: amount of text is being formatted simply. The text must be all of one style sl@0: and broken into lines of all the same length. The number of lines and the text sl@0: itself is specified on construction, and the text may then be re-broken, sl@0: re-truncated and re-drawn with non-leaving functions. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class TBidiText sl@0: { sl@0: public: sl@0: /** Overall directionality of the text. */ sl@0: enum TDirectionality sl@0: { sl@0: /** Text reading begins on the left. */ sl@0: ELeftToRight = 0, sl@0: /** Text reading begins on the right. */ sl@0: ERightToLeft = 1 sl@0: }; sl@0: sl@0: /** Class specific panic codes sl@0: @deprecated This enum has been replaced by TBidiPanic. sl@0: */ sl@0: enum TPanicCodes sl@0: { sl@0: EPanicRunArrayNull, sl@0: }; sl@0: sl@0: IMPORT_C static TDirectionality ScriptDirectionality(TLanguage aLanguage); sl@0: IMPORT_C static TDirectionality TextDirectionality( sl@0: const TDesC& aText, TBool* aFound = 0); sl@0: protected: sl@0: TBidiText(); sl@0: public: sl@0: IMPORT_C static TBidiText* NewL(TInt aReservedMaxLength, TInt aMaxLines); sl@0: IMPORT_C static TBidiText* NewL(const TDesC& aText, TInt aMaxLines); sl@0: IMPORT_C static TBidiText* NewL(const TDesC& aText, TInt aMaxLines, sl@0: TDirectionality aDirectionality); sl@0: IMPORT_C TInt SetText(const TDesC& aText, RRunInfoArray& aRunInfoArray); sl@0: IMPORT_C TInt SetText(const TDesC& aText, TDirectionality aDirectionality, RRunInfoArray& aRunInfoArray); sl@0: IMPORT_C void SetTruncationChar(TChar aTruncateWith); sl@0: IMPORT_C void WrapText(TInt aWrappingWidth, const CFont& aFont, sl@0: const MLineBreaker* aBreaker, TInt aMaxLines); sl@0: IMPORT_C void WrapText(TInt aWrappingWidth, const CFont& aFont, sl@0: const MLineBreaker* aBreaker = NULL); sl@0: IMPORT_C TSize MinimumSize(TInt aWrappingWidth, const CFont& aFont, TInt aLineGap, TInt aMaxLines = -1, sl@0: const MLineBreaker* aBreaker = NULL) const; sl@0: IMPORT_C TPtrC Text() const; sl@0: IMPORT_C TPtrC DisplayText() const; sl@0: IMPORT_C TInt WrappingWidth() const; sl@0: IMPORT_C TDirectionality Directionality() const; sl@0: IMPORT_C TChar TruncationChar() const; sl@0: IMPORT_C TInt NumberOfLinesInDisplayText() const; sl@0: IMPORT_C TPtrC LineOfDisplayText(TInt aLine, TInt& aWidthInPixels) const; sl@0: IMPORT_C void DrawText(CGraphicsContext& aGc, const TPoint& aLeft) const; sl@0: IMPORT_C void DrawText(CGraphicsContext& aGc, sl@0: const TPoint& aLeft, TInt aBaseLineSpacing, sl@0: CGraphicsContext::TTextAlign aAlignment) const; sl@0: IMPORT_C void DrawText(CGraphicsContext& aGc, sl@0: const TPoint& aLeft, TInt aBaseLineSpacing) const; sl@0: private: sl@0: TInt DoWrapText(TInt aWrappingWidth, const CFont& aFont, const MLineBreaker* aBreaker, sl@0: TInt aMaxLines, TText*& aOutputText, TInt& aNumLines, TInt16* aLineWidthArray) const; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: This class is used to keep track of the shared run info array. sl@0: Keep it open for as long as the TBidiText object is used. The same sl@0: RRunInfoArray object can be used with several different TBidiText objects. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class RRunInfoArray sl@0: { sl@0: friend class TBidiText; sl@0: sl@0: public: sl@0: IMPORT_C RRunInfoArray(); sl@0: IMPORT_C void OpenL(); sl@0: IMPORT_C void Close(); sl@0: sl@0: private: sl@0: TBidirectionalState::TRunInfo* RunArray() const; sl@0: sl@0: private: sl@0: CBidiTextTls* iTls; sl@0: }; sl@0: sl@0: #endif