graphicsdeviceinterface/gdi/sgdi/LineBreakImp.h
changeset 183 6a1564a2f3e6
parent 168 2bd88482bfe5
child 194 18f84489a694
equal deleted inserted replaced
168:2bd88482bfe5 183:6a1564a2f3e6
     1 // Copyright (c) 2002-2009 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 LINEBREAKIMP_H_
       
    17 #define LINEBREAKIMP_H_
       
    18 
       
    19 #include <e32def.h>
       
    20 
       
    21 const TText KZeroWidthSpace = 0x200B;
       
    22 const TText KWhiteSpace = 0x0020;
       
    23 
       
    24 // Forward delcarations.
       
    25 GLREF_C void Panic(TInt aError);
       
    26 class MLineBreaker;
       
    27 
       
    28 /**
       
    29  Rule for which classes may be broken before.
       
    30 @internalComponent
       
    31  */
       
    32 struct TLineBreakRule
       
    33 	{
       
    34 	/** Classes that breaks are illegal before, even after spaces. */
       
    35 	TUint iForbid;
       
    36 	/** Classes that breaks are legal before, even without spaces. */
       
    37 	TUint iAllow;
       
    38 	};
       
    39 
       
    40 /**
       
    41  Range of characters which have a particular line breaking class.
       
    42 @internalComponent
       
    43  */
       
    44 struct TLineBreakRange
       
    45 	{
       
    46 	TUint iStart;
       
    47 	TUint iEnd;
       
    48 	TUint iClass;
       
    49 	};
       
    50 
       
    51 /**
       
    52  Single-entry line break cache. Saves asking the MLineBreaker for the classes
       
    53  of multiple characters in the same run.
       
    54 @internalComponent
       
    55  */
       
    56 class TLineBreakClassCache
       
    57 	{
       
    58 public:
       
    59 	TLineBreakClassCache(const MLineBreaker& aBreaker): iBreaker(aBreaker), iStart(0), iEnd(0), iClass(0) { }
       
    60 	TUint LineBreakClass(TUint aChar);
       
    61 	const MLineBreaker& Breaker() const { return iBreaker; }
       
    62 
       
    63 private:
       
    64 	const MLineBreaker& iBreaker;
       
    65 	TUint iStart;
       
    66 	TUint iEnd;
       
    67 	TUint iClass;
       
    68 	};
       
    69 
       
    70 /**
       
    71 @internalComponent
       
    72  */
       
    73 void TestLineBreakTables(void);
       
    74 
       
    75 /**
       
    76 @internalComponent
       
    77  */
       
    78 class TLineBreakClassIterator
       
    79 	{
       
    80 public:
       
    81 	void Set(const TText* aFirst, const TText* aText, TLineBreakClassCache& aBreaker);
       
    82 	void SetNull();
       
    83 	/** Returns the pointer to the character that has the class returned by
       
    84 	Class(). */
       
    85 	const TText* Ptr() const { return iCurrent; }
       
    86 	/** Returns the class of the current character. */
       
    87 	TInt Class() const { return iClass; }
       
    88 	// Will not go beyond maximum of aLimit
       
    89 	// Should not be called with aLimit == Ptr()
       
    90 	// Will return EFalse if the limit has been exceeded
       
    91 	// aOffset must be 1 or -1
       
    92 	TBool Move(const TText* aLimit, const TText* aLimitAfterSpaces,
       
    93 		TInt aOffset, TBool& aHasSpaces, TLineBreakClassCache& aBreaker);
       
    94 private:
       
    95     /** Addres of first character in the string to iterator through */
       
    96     const TText* iFirst;
       
    97 	/** Current position within the iteration. */
       
    98 	const TText* iCurrent;
       
    99 	/** Class of the character at the currrent position. */
       
   100 	TInt iClass;
       
   101 	};
       
   102 
       
   103 
       
   104 /**
       
   105 @internalComponent
       
   106  */
       
   107 TInt MoveTextPtr(const TText*& aPtr, const TText* aLimit, TInt aOffset);
       
   108 
       
   109 /**
       
   110  Class for implementing the Unicode line breaking algorithm
       
   111 @internalComponent
       
   112  */
       
   113 class TLineBreakIterator
       
   114 	{
       
   115 public:
       
   116 	TLineBreakIterator(TLineBreakClassCache& aBreaker,
       
   117 		const TText* aText, TInt aLength, TBool aForwards,
       
   118 		TInt aMinBreakPos, TInt aMaxBreakPos);
       
   119 	TBool IsBreak(TBool aForwards);
       
   120 	// Is one side of the potential line break CB class?
       
   121 	TBool HasContingentBreak() const;
       
   122 	// Get class before the break: useful for CB
       
   123 	TInt PreviousClass() const;
       
   124 	// Get class after the break: useful for CB
       
   125 	TInt NextClass() const;
       
   126 	// Are there spaces between the classes: useful for CB
       
   127 	TInt HasSpaces() const;
       
   128 	// go backwards
       
   129 	TBool Decrement();
       
   130 	// go forwards
       
   131 	TBool Increment();
       
   132 	// position of iterator at the break
       
   133 	TInt BreakPos() const;
       
   134 	// position of iterator after the break
       
   135 	TInt AfterBreakPos() const;
       
   136 	// position of iterator before the break
       
   137 	TInt BeforeBreakPos() const;
       
   138 private:
       
   139 	TLineBreakClassCache iBreaker;
       
   140 	const TText* iText;
       
   141 	TInt iTextLength;
       
   142 	const TText* iLimit;
       
   143 	/** The limit that we are allowed to search beyond space characters. For
       
   144 	forwards this will be up to the end of the text, for backwards we may not
       
   145 	search beyond the minimum break position because that would mean that the
       
   146 	break position returned would be below the minimum. */
       
   147 	const TText* iLimitAfterSpaces;
       
   148 	TLineBreakClassIterator iBeforeBreak;
       
   149 	TLineBreakClassIterator iAfterBreak;
       
   150 	TBool iHasSpaces;
       
   151 	/** Holds the address of the lowest point allowed to break at */
       
   152 	const TText* iMinBreakPos;
       
   153 	/** Holds the address of the highest point allowed to break at */
       
   154 	const TText* iMaxBreakPos;
       
   155 	};
       
   156 
       
   157 /** 
       
   158 @internalComponent 
       
   159 */
       
   160 TBool HasContingentBreak(TLineBreakIterator& aIterator, TBool aForwards,
       
   161 	MContingentLineBreaker& aCbDelegate);
       
   162 
       
   163 /** 
       
   164 @internalComponent 
       
   165 */
       
   166 TBool HasContingentBreakL(TLineBreakIterator& aIterator, TBool aForwards,
       
   167 	MContingentLineBreakerL& aCbDelegate);
       
   168 
       
   169 /** 
       
   170 @internalComponent 
       
   171 */
       
   172 TBool FindBreak(TLineBreakIterator& aIterator, TBool aForwards,
       
   173 	MContingentLineBreaker* aCbDelegate);
       
   174 
       
   175 /** 
       
   176 @internalComponent 
       
   177 */
       
   178 TBool FindBreakL(TLineBreakIterator& aIterator, TBool aForwards,
       
   179 	MContingentLineBreakerL* aCbDelegate);
       
   180 
       
   181 #endif