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