1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/fontservices/textbase/sgdi/LineBreakImp.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,181 @@
1.4 +// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#ifndef LINEBREAKIMP_H_
1.20 +#define LINEBREAKIMP_H_
1.21 +
1.22 +#include <e32def.h>
1.23 +
1.24 +const TText KZeroWidthSpace = 0x200B;
1.25 +const TText KWhiteSpace = 0x0020;
1.26 +
1.27 +// Forward delcarations.
1.28 +GLREF_C void Panic(TInt aError);
1.29 +class MLineBreaker;
1.30 +
1.31 +/**
1.32 + Rule for which classes may be broken before.
1.33 +@internalComponent
1.34 + */
1.35 +struct TLineBreakRule
1.36 + {
1.37 + /** Classes that breaks are illegal before, even after spaces. */
1.38 + TUint iForbid;
1.39 + /** Classes that breaks are legal before, even without spaces. */
1.40 + TUint iAllow;
1.41 + };
1.42 +
1.43 +/**
1.44 + Range of characters which have a particular line breaking class.
1.45 +@internalComponent
1.46 + */
1.47 +struct TLineBreakRange
1.48 + {
1.49 + TUint iStart;
1.50 + TUint iEnd;
1.51 + TUint iClass;
1.52 + };
1.53 +
1.54 +/**
1.55 + Single-entry line break cache. Saves asking the MLineBreaker for the classes
1.56 + of multiple characters in the same run.
1.57 +@internalComponent
1.58 + */
1.59 +class TLineBreakClassCache
1.60 + {
1.61 +public:
1.62 + TLineBreakClassCache(const MLineBreaker& aBreaker): iBreaker(aBreaker), iStart(0), iEnd(0), iClass(0) { }
1.63 + TUint LineBreakClass(TUint aChar);
1.64 + const MLineBreaker& Breaker() const { return iBreaker; }
1.65 +
1.66 +private:
1.67 + const MLineBreaker& iBreaker;
1.68 + TUint iStart;
1.69 + TUint iEnd;
1.70 + TUint iClass;
1.71 + };
1.72 +
1.73 +/**
1.74 +@internalComponent
1.75 + */
1.76 +void TestLineBreakTables(void);
1.77 +
1.78 +/**
1.79 +@internalComponent
1.80 + */
1.81 +class TLineBreakClassIterator
1.82 + {
1.83 +public:
1.84 + void Set(const TText* aFirst, const TText* aText, TLineBreakClassCache& aBreaker);
1.85 + void SetNull();
1.86 + /** Returns the pointer to the character that has the class returned by
1.87 + Class(). */
1.88 + const TText* Ptr() const { return iCurrent; }
1.89 + /** Returns the class of the current character. */
1.90 + TInt Class() const { return iClass; }
1.91 + // Will not go beyond maximum of aLimit
1.92 + // Should not be called with aLimit == Ptr()
1.93 + // Will return EFalse if the limit has been exceeded
1.94 + // aOffset must be 1 or -1
1.95 + TBool Move(const TText* aLimit, const TText* aLimitAfterSpaces,
1.96 + TInt aOffset, TBool& aHasSpaces, TLineBreakClassCache& aBreaker);
1.97 +private:
1.98 + /** Addres of first character in the string to iterator through */
1.99 + const TText* iFirst;
1.100 + /** Current position within the iteration. */
1.101 + const TText* iCurrent;
1.102 + /** Class of the character at the currrent position. */
1.103 + TInt iClass;
1.104 + };
1.105 +
1.106 +
1.107 +/**
1.108 +@internalComponent
1.109 + */
1.110 +TInt MoveTextPtr(const TText*& aPtr, const TText* aLimit, TInt aOffset);
1.111 +
1.112 +/**
1.113 + Class for implementing the Unicode line breaking algorithm
1.114 +@internalComponent
1.115 + */
1.116 +class TLineBreakIterator
1.117 + {
1.118 +public:
1.119 + TLineBreakIterator(TLineBreakClassCache& aBreaker,
1.120 + const TText* aText, TInt aLength, TBool aForwards,
1.121 + TInt aMinBreakPos, TInt aMaxBreakPos);
1.122 + TBool IsBreak(TBool aForwards);
1.123 + // Is one side of the potential line break CB class?
1.124 + TBool HasContingentBreak() const;
1.125 + // Get class before the break: useful for CB
1.126 + TInt PreviousClass() const;
1.127 + // Get class after the break: useful for CB
1.128 + TInt NextClass() const;
1.129 + // Are there spaces between the classes: useful for CB
1.130 + TInt HasSpaces() const;
1.131 + // go backwards
1.132 + TBool Decrement();
1.133 + // go forwards
1.134 + TBool Increment();
1.135 + // position of iterator at the break
1.136 + TInt BreakPos() const;
1.137 + // position of iterator after the break
1.138 + TInt AfterBreakPos() const;
1.139 + // position of iterator before the break
1.140 + TInt BeforeBreakPos() const;
1.141 +private:
1.142 + TLineBreakClassCache iBreaker;
1.143 + const TText* iText;
1.144 + TInt iTextLength;
1.145 + const TText* iLimit;
1.146 + /** The limit that we are allowed to search beyond space characters. For
1.147 + forwards this will be up to the end of the text, for backwards we may not
1.148 + search beyond the minimum break position because that would mean that the
1.149 + break position returned would be below the minimum. */
1.150 + const TText* iLimitAfterSpaces;
1.151 + TLineBreakClassIterator iBeforeBreak;
1.152 + TLineBreakClassIterator iAfterBreak;
1.153 + TBool iHasSpaces;
1.154 + /** Holds the address of the lowest point allowed to break at */
1.155 + const TText* iMinBreakPos;
1.156 + /** Holds the address of the highest point allowed to break at */
1.157 + const TText* iMaxBreakPos;
1.158 + };
1.159 +
1.160 +/**
1.161 +@internalComponent
1.162 +*/
1.163 +TBool HasContingentBreak(TLineBreakIterator& aIterator, TBool aForwards,
1.164 + MContingentLineBreaker& aCbDelegate);
1.165 +
1.166 +/**
1.167 +@internalComponent
1.168 +*/
1.169 +TBool HasContingentBreakL(TLineBreakIterator& aIterator, TBool aForwards,
1.170 + MContingentLineBreakerL& aCbDelegate);
1.171 +
1.172 +/**
1.173 +@internalComponent
1.174 +*/
1.175 +TBool FindBreak(TLineBreakIterator& aIterator, TBool aForwards,
1.176 + MContingentLineBreaker* aCbDelegate);
1.177 +
1.178 +/**
1.179 +@internalComponent
1.180 +*/
1.181 +TBool FindBreakL(TLineBreakIterator& aIterator, TBool aForwards,
1.182 + MContingentLineBreakerL* aCbDelegate);
1.183 +
1.184 +#endif