3 * (C) Copyright IBM Corp. 1998-2004 - All Rights Reserved
10 #include "unicode/utypes.h"
11 #include "unicode/uobject.h"
12 #include "unicode/uscript.h"
13 #include "unicode/unistr.h"
15 #include "layout/LETypes.h"
16 #include "layout/LayoutEngine.h"
21 * This is a wrapper class designed to allow ICU clients to
22 * use LayoutEngine in a way that is consistent with the rest
25 * (LayoutEngine was developed seperately from ICU and
26 * the same source is used in non-ICU environments, so it cannot
27 * be changed to match ICU coding conventions).
29 * This class is designed for clients who wish to use LayoutEngine
30 * to layout complex text. If you need to subclass LayoutEngine,
31 * you'll need to use the LayoutEngine interfaces directly.
33 * Basically, it creates an instance of LayoutEngine, stashes
34 * it in fLayoutEngine, and uses it to implement the layout
37 * Use the createInstance method to create an ICULayoutEngine. Use
38 * delete to destroy it. The layoutChars method computes the glyphs
39 * and positions, and saves them in the ICULayoutEngine object.
40 * Use getGlyphs, getPositions and getCharIndices to retreive this
43 * You'll also need an implementation of LEFontInstance for your platform.
46 * @see LEFontInstance.h
48 * @obsolete ICU 3.0. Use LayoutEngine.h instead since this API will be removed in that release.
50 #ifndef U_HIDE_OBSOLETE_API
51 class U_LAYOUT_API ICULayoutEngine
: public UObject
{
54 * This holds the instance of LayoutEngine that does all
57 LayoutEngine
*fLayoutEngine
;
60 * This no argument constructor is private so that clients
61 * can't envoke it. Clients should use createInstance.
68 * The main constructor. It is defined as private to
69 * stop clients from invoking it. Clients should use
72 * @param layoutEngine - the LayoutEngine that this instance wraps.
76 ICULayoutEngine(LayoutEngine
*layoutEngine
);
81 * The destructor. At least on Windows it needs to be
82 * virtual to ensure that it deletes the object from the
83 * same heap that createInstance will allocate it from. We
84 * don't know why this is...
88 * @obsolete ICU 3.0. Use LayoutEngine.h instead since this API will be removed in that release.
90 virtual ~ICULayoutEngine();
93 * This method computes the glyph, character index and position arrays
94 * for the input characters.
96 * @param chars - the input character context
97 * @param startOffset - the starting offset of the characters to process
98 * @param endOffset - the ending offset of the characters to process
99 * @param maxOffset - the number of characters in the input context
100 * @param rightToLeft - TRUE if the characers are in a right to left directional run
101 * @param x - the initial X position
102 * @param y - the initial Y position
103 * @param success - output parameter set to an error code if the operation fails
105 * @return the number of glyphs in the glyph array
107 * Note; the glyph, character index and position array can be accessed
108 * using the getter method below.
110 * @obsolete ICU 3.0. Use LayoutEngine.h instead since this API will be removed in that release.
112 int32_t layoutChars(const UChar chars
[],
118 UErrorCode
&success
);
122 * This method computes the glyph, character index and position arrays
123 * for the input characters.
125 * @param str - the input character context
126 * @param startOffset - the starting offset of the characters to process
127 * @param endOffset - the ending offset of the characters to process
128 * @param rightToLeft - TRUE if the characers are in a right to left directional run
129 * @param x - the initial X position
130 * @param y - the initial Y position
131 * @param success - output parameter set to an error code if the operation fails
133 * @return the number of glyphs in the glyph array
135 * Note; the glyph, character index and position array can be accessed
136 * using the getter method below.
138 * @obsolete ICU 3.0. Use LayoutEngine.h instead since this API will be removed in that release.
140 int32_t layoutString(const UnicodeString
&str
,
145 UErrorCode
&success
);
148 * This method returns the number of glyphs in the glyph array. Note
149 * that the number of glyphs will be greater than or equal to the number
150 * of characters used to create the LayoutEngine.
152 * @return the number of glyphs in the glyph array
154 * @obsolete ICU 3.0. Use LayoutEngine.h instead since this API will be removed in that release.
156 int32_t countGlyphs() const;
159 * This method copies the glyph array into a caller supplied array.
160 * The caller must ensure that the array is large enough to hold all
163 * @param glyphs - the destiniation glyph array
164 * @param success - output parameter set to an error code if the operation fails
166 * @obsolete ICU 3.0. Use LayoutEngine.h instead since this API will be removed in that release.
168 void getGlyphs(uint32_t glyphs
[], UErrorCode
&success
);
171 * This method copies the character index array into a caller supplied array.
172 * The caller must ensure that the array is large enough to hold a character
173 * index for each glyph.
175 * @param charIndices - the destiniation character index array
176 * @param success - output parameter set to an error code if the operation fails
178 * @obsolete ICU 3.0. Use LayoutEngine.h instead since this API will be removed in that release.
180 void getCharIndices(int32_t charIndices
[], UErrorCode
&success
);
183 * This method copies the character index array into a caller supplied array.
184 * The caller must ensure that the array is large enough to hold a character
185 * index for each glyph.
187 * @param charIndices - the destiniation character index array
188 * @param indexBase - an offset which will be added to each index
189 * @param success - output parameter set to an error code if the operation fails
191 * @obsolete ICU 3.0. Use LayoutEngine.h instead since this API will be removed in that release.
193 void getCharIndices(int32_t charIndices
[], int32_t indexBase
, UErrorCode
&success
);
196 * This method copies the position array into a caller supplied array.
197 * The caller must ensure that the array is large enough to hold an
198 * X and Y position for each glyph, plus an extra X and Y for the
199 * advance of the last glyph.
201 * @param positions - the destiniation position array
202 * @param success - output parameter set to an error code if the operation fails
204 * @obsolete ICU 3.0. Use LayoutEngine.h instead since this API will be removed in that release.
206 void getGlyphPositions(float positions
[], UErrorCode
&success
);
209 * This method returns the X and Y position of the glyph at the
213 * @param glyphIndex - the index of the glyph
216 * @param x - the glyph's X position
217 * @param y - the glyph's Y position
218 * @param success - output parameter set to an error code if the operation fails
220 * @obsolete ICU 3.0. Use LayoutEngine.h instead since this API will be removed in that release.
222 void getGlyphPosition(int32_t glyphIndex
, float &x
, float &y
, UErrorCode
&success
);
225 * This method returns an ICULayoutEngine capable of laying out text
226 * in the given font, script and langauge.
228 * @param fontInstance - the font of the text
229 * @param scriptCode - the script of the text
230 * @param locale - used to determine the language of the text
231 * @param success - output parameter set to an error code if the operation fails
233 * @return an ICULayoutEngine which can layout text in the given font.
235 * NOTE: currently, locale is ignored...
237 * @see LEFontInstance
239 * @obsolete ICU 3.0. Use LayoutEngine.h instead since this API will be removed in that release.
241 static ICULayoutEngine
*createInstance(const LEFontInstance
*fontInstance
,
242 UScriptCode scriptCode
, Locale
&locale
,
243 UErrorCode
&success
);
246 * ICU "poor man's RTTI", returns a UClassID for the actual class.
248 * @obsolete ICU 3.0. Use LayoutEngine.h instead since this API will be removed in that release.
250 virtual UClassID
getDynamicClassID() const;
253 * ICU "poor man's RTTI", returns a UClassID for this class.
255 * @obsolete ICU 3.0. Use LayoutEngine.h instead since this API will be removed in that release.
257 static UClassID
getStaticClassID();
260 inline ICULayoutEngine::ICULayoutEngine()
265 inline ICULayoutEngine::ICULayoutEngine(LayoutEngine
*layoutEngine
)
266 : fLayoutEngine(layoutEngine
)
268 // nothing else to do
271 inline ICULayoutEngine::~ICULayoutEngine()
273 delete fLayoutEngine
;
277 inline int32_t ICULayoutEngine::layoutChars(const UChar chars
[],
285 // NOTE: call reset() so that clients can safely reuse
286 fLayoutEngine
->reset();
287 return fLayoutEngine
->layoutChars(chars
,
289 endOffset
- startOffset
,
293 (LEErrorCode
&) success
);
296 inline int32_t ICULayoutEngine::layoutString(const UnicodeString
&str
,
303 // NOTE: call reset() so that clients can safely reuse
304 fLayoutEngine
->reset();
305 return fLayoutEngine
->layoutChars(str
.getBuffer(),
307 endOffset
- startOffset
,
311 (LEErrorCode
&) success
);
314 inline int32_t ICULayoutEngine::countGlyphs() const
316 return fLayoutEngine
->getGlyphCount();
319 inline void ICULayoutEngine::getGlyphs(uint32_t glyphs
[], UErrorCode
&success
)
321 fLayoutEngine
->getGlyphs(glyphs
, (LEErrorCode
&) success
);
324 inline void ICULayoutEngine::getCharIndices(int32_t charIndices
[], UErrorCode
&success
)
326 fLayoutEngine
->getCharIndices(charIndices
, (LEErrorCode
&) success
);
329 inline void ICULayoutEngine::getCharIndices(int32_t charIndices
[], int32_t indexBase
, UErrorCode
&success
)
331 fLayoutEngine
->getCharIndices(charIndices
, indexBase
, (LEErrorCode
&) success
);
334 inline void ICULayoutEngine::getGlyphPositions(float positions
[], UErrorCode
&success
)
336 fLayoutEngine
->getGlyphPositions(positions
, (LEErrorCode
&) success
);
339 inline void ICULayoutEngine::getGlyphPosition(int32_t glyphIndex
, float &x
, float &y
, UErrorCode
&success
)
341 fLayoutEngine
->getGlyphPosition(glyphIndex
, x
, y
, (LEErrorCode
&) success
);
344 inline ICULayoutEngine
*ICULayoutEngine::createInstance(const LEFontInstance
*fontInstance
,
345 UScriptCode scriptCode
,
346 Locale
&locale
, UErrorCode
&success
)
348 LayoutEngine
*engine
= LayoutEngine::layoutEngineFactory(fontInstance
,
349 (le_int32
) scriptCode
,
351 (LEErrorCode
&) success
);
353 return new ICULayoutEngine(engine
);
355 #endif // U_HIDE_OBSOLETE_API