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 LINEBREAKIMP_H_ sl@0: #define LINEBREAKIMP_H_ sl@0: sl@0: #include sl@0: sl@0: const TText KZeroWidthSpace = 0x200B; sl@0: const TText KWhiteSpace = 0x0020; sl@0: sl@0: // Forward delcarations. sl@0: GLREF_C void Panic(TInt aError); sl@0: class MLineBreaker; sl@0: sl@0: /** sl@0: Rule for which classes may be broken before. sl@0: @internalComponent sl@0: */ sl@0: struct TLineBreakRule sl@0: { sl@0: /** Classes that breaks are illegal before, even after spaces. */ sl@0: TUint iForbid; sl@0: /** Classes that breaks are legal before, even without spaces. */ sl@0: TUint iAllow; sl@0: }; sl@0: sl@0: /** sl@0: Range of characters which have a particular line breaking class. sl@0: @internalComponent sl@0: */ sl@0: struct TLineBreakRange sl@0: { sl@0: TUint iStart; sl@0: TUint iEnd; sl@0: TUint iClass; sl@0: }; sl@0: sl@0: /** sl@0: Single-entry line break cache. Saves asking the MLineBreaker for the classes sl@0: of multiple characters in the same run. sl@0: @internalComponent sl@0: */ sl@0: class TLineBreakClassCache sl@0: { sl@0: public: sl@0: TLineBreakClassCache(const MLineBreaker& aBreaker): iBreaker(aBreaker), iStart(0), iEnd(0), iClass(0) { } sl@0: TUint LineBreakClass(TUint aChar); sl@0: const MLineBreaker& Breaker() const { return iBreaker; } sl@0: sl@0: private: sl@0: const MLineBreaker& iBreaker; sl@0: TUint iStart; sl@0: TUint iEnd; sl@0: TUint iClass; sl@0: }; sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: void TestLineBreakTables(void); sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: class TLineBreakClassIterator sl@0: { sl@0: public: sl@0: void Set(const TText* aFirst, const TText* aText, TLineBreakClassCache& aBreaker); sl@0: void SetNull(); sl@0: /** Returns the pointer to the character that has the class returned by sl@0: Class(). */ sl@0: const TText* Ptr() const { return iCurrent; } sl@0: /** Returns the class of the current character. */ sl@0: TInt Class() const { return iClass; } sl@0: // Will not go beyond maximum of aLimit sl@0: // Should not be called with aLimit == Ptr() sl@0: // Will return EFalse if the limit has been exceeded sl@0: // aOffset must be 1 or -1 sl@0: TBool Move(const TText* aLimit, const TText* aLimitAfterSpaces, sl@0: TInt aOffset, TBool& aHasSpaces, TLineBreakClassCache& aBreaker); sl@0: private: sl@0: /** Addres of first character in the string to iterator through */ sl@0: const TText* iFirst; sl@0: /** Current position within the iteration. */ sl@0: const TText* iCurrent; sl@0: /** Class of the character at the currrent position. */ sl@0: TInt iClass; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TInt MoveTextPtr(const TText*& aPtr, const TText* aLimit, TInt aOffset); sl@0: sl@0: /** sl@0: Class for implementing the Unicode line breaking algorithm sl@0: @internalComponent sl@0: */ sl@0: class TLineBreakIterator sl@0: { sl@0: public: sl@0: TLineBreakIterator(TLineBreakClassCache& aBreaker, sl@0: const TText* aText, TInt aLength, TBool aForwards, sl@0: TInt aMinBreakPos, TInt aMaxBreakPos); sl@0: TBool IsBreak(TBool aForwards); sl@0: // Is one side of the potential line break CB class? sl@0: TBool HasContingentBreak() const; sl@0: // Get class before the break: useful for CB sl@0: TInt PreviousClass() const; sl@0: // Get class after the break: useful for CB sl@0: TInt NextClass() const; sl@0: // Are there spaces between the classes: useful for CB sl@0: TInt HasSpaces() const; sl@0: // go backwards sl@0: TBool Decrement(); sl@0: // go forwards sl@0: TBool Increment(); sl@0: // position of iterator at the break sl@0: TInt BreakPos() const; sl@0: // position of iterator after the break sl@0: TInt AfterBreakPos() const; sl@0: // position of iterator before the break sl@0: TInt BeforeBreakPos() const; sl@0: private: sl@0: TLineBreakClassCache iBreaker; sl@0: const TText* iText; sl@0: TInt iTextLength; sl@0: const TText* iLimit; sl@0: /** The limit that we are allowed to search beyond space characters. For sl@0: forwards this will be up to the end of the text, for backwards we may not sl@0: search beyond the minimum break position because that would mean that the sl@0: break position returned would be below the minimum. */ sl@0: const TText* iLimitAfterSpaces; sl@0: TLineBreakClassIterator iBeforeBreak; sl@0: TLineBreakClassIterator iAfterBreak; sl@0: TBool iHasSpaces; sl@0: /** Holds the address of the lowest point allowed to break at */ sl@0: const TText* iMinBreakPos; sl@0: /** Holds the address of the highest point allowed to break at */ sl@0: const TText* iMaxBreakPos; sl@0: }; sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TBool HasContingentBreak(TLineBreakIterator& aIterator, TBool aForwards, sl@0: MContingentLineBreaker& aCbDelegate); sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TBool HasContingentBreakL(TLineBreakIterator& aIterator, TBool aForwards, sl@0: MContingentLineBreakerL& aCbDelegate); sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TBool FindBreak(TLineBreakIterator& aIterator, TBool aForwards, sl@0: MContingentLineBreaker* aCbDelegate); sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: TBool FindBreakL(TLineBreakIterator& aIterator, TBool aForwards, sl@0: MContingentLineBreakerL* aCbDelegate); sl@0: sl@0: #endif