Update contrib.
2 **********************************************************************
3 * Copyright (C) 1998-2005, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
8 #ifndef __LEGLYPHSTORAGE_H
9 #define __LEGLYPHSTORAGE_H
12 #include "LEInsertionList.h"
16 * \brief C++ API: This class encapsulates the per-glyph storage used by the ICU LayoutEngine.
22 * This class encapsulates the per-glyph storage used by the ICU LayoutEngine.
23 * For each glyph it holds the glyph ID, the index of the backing store character
24 * which produced the glyph, the X and Y position of the glyph and an auxillary data
27 * The storage is growable using the <code>LEInsertionList</code> class.
30 * @see LEInsertionList.h
34 class U_LAYOUT_API LEGlyphStorage : public UObject, protected LEInsertionCallback
38 * The number of entries in the per-glyph arrays.
52 * The char indices array.
56 le_int32 *fCharIndices;
59 * The glyph positions array.
66 * The auxillary data array.
74 * The insertion list, used to grow the above arrays.
78 LEInsertionList *fInsertionList;
81 * The source index while growing the data arrays.
88 * The destination index used while growing the data arrays.
96 * This implements <code>LEInsertionCallback</code>. The <code>LEInsertionList</code>
97 * will call this method once for each insertion.
99 * @param atPosition the position of the insertion
100 * @param count the number of glyphs being inserted
101 * @param newGlyphs the address of the new glyph IDs
103 * @return <code>true</code> if <code>LEInsertionList</code> should stop
104 * processing the insertion list after this insertion.
106 * @see LEInsertionList.h
110 virtual le_bool applyInsertion(le_int32 atPosition, le_int32 count, LEGlyphID newGlyphs[]);
115 * Allocates an empty <code>LEGlyphStorage</code> object. You must call
116 * <code>allocateGlyphArray, allocatePositions and allocateAuxData</code>
117 * to allocate the data.
122 * The destructor. This will deallocate all of the arrays.
127 * This method returns the number of glyphs in the glyph array.
129 * @return the number of glyphs in the glyph array
133 inline le_int32 getGlyphCount() const;
136 * This method copies the glyph array into a caller supplied array.
137 * The caller must ensure that the array is large enough to hold all
140 * @param glyphs - the destiniation glyph array
141 * @param success - set to an error code if the operation fails
145 void getGlyphs(LEGlyphID glyphs[], LEErrorCode &success) const;
148 * This method copies the glyph array into a caller supplied array,
149 * ORing in extra bits. (This functionality is needed by the JDK,
150 * which uses 32 bits pre glyph idex, with the high 16 bits encoding
151 * the composite font slot number)
153 * @param glyphs - the destination (32 bit) glyph array
154 * @param extraBits - this value will be ORed with each glyph index
155 * @param success - set to an error code if the operation fails
159 void getGlyphs(le_uint32 glyphs[], le_uint32 extraBits, LEErrorCode &success) const;
162 * This method copies the character index array into a caller supplied array.
163 * The caller must ensure that the array is large enough to hold a
164 * character index for each glyph.
166 * @param charIndices - the destiniation character index array
167 * @param success - set to an error code if the operation fails
171 void getCharIndices(le_int32 charIndices[], LEErrorCode &success) const;
174 * This method copies the character index array into a caller supplied array.
175 * The caller must ensure that the array is large enough to hold a
176 * character index for each glyph.
178 * @param charIndices - the destiniation character index array
179 * @param indexBase - an offset which will be added to each index
180 * @param success - set to an error code if the operation fails
184 void getCharIndices(le_int32 charIndices[], le_int32 indexBase, LEErrorCode &success) const;
187 * This method copies the position array into a caller supplied array.
188 * The caller must ensure that the array is large enough to hold an
189 * X and Y position for each glyph, plus an extra X and Y for the
190 * advance of the last glyph.
192 * @param positions - the destiniation position array
193 * @param success - set to an error code if the operation fails
197 void getGlyphPositions(float positions[], LEErrorCode &success) const;
200 * This method returns the X and Y position of the glyph at
204 * @param glyphIndex - the index of the glyph
207 * @param x - the glyph's X position
208 * @param y - the glyph's Y position
209 * @param success - set to an error code if the operation fails
213 void getGlyphPosition(le_int32 glyphIndex, float &x, float &y, LEErrorCode &success) const;
216 * This method allocates the glyph array, the char indices array and the insertion list. You
217 * must call this method before using the object. This method also initializes the char indices
220 * @param initialGlyphCount the initial size of the glyph and char indices arrays.
221 * @param rightToLeft <code>true</code> if the original input text is right to left.
222 * @param success set to an error code if the storage cannot be allocated of if the initial
223 * glyph count is not positive.
227 void allocateGlyphArray(le_int32 initialGlyphCount, le_bool rightToLeft, LEErrorCode &success);
230 * This method allocates the storage for the glyph positions. It allocates one extra X, Y
231 * position pair for the position just after the last glyph.
233 * @param success set to an error code if the positions array cannot be allocated.
235 * @return the number of X, Y position pairs allocated.
239 le_int32 allocatePositions(LEErrorCode &success);
242 * This method allocates the storage for the auxillary glyph data.
244 * @param success set to an error code if the aulillary data array cannot be allocated.
246 * @return the size of the auxillary data array.
250 le_int32 allocateAuxData(LEErrorCode &success);
253 * Copy the entire auxillary data array.
255 * @param auxData the auxillary data array will be copied to this address
256 * @param success set to an error code if the data cannot be copied
260 void getAuxData(void *auxData[], LEErrorCode &success) const;
263 * Get the glyph ID for a particular glyph.
265 * @param glyphIndex the index into the glyph array
266 * @param success set to an error code if the glyph ID cannot be retrieved.
268 * @return the glyph ID
272 LEGlyphID getGlyphID(le_int32 glyphIndex, LEErrorCode &success) const;
275 * Get the char index for a particular glyph.
277 * @param glyphIndex the index into the glyph array
278 * @param success set to an error code if the char index cannot be retrieved.
280 * @return the character index
284 le_int32 getCharIndex(le_int32 glyphIndex, LEErrorCode &success) const;
288 * Get the auxillary data for a particular glyph.
290 * @param glyphIndex the index into the glyph array
291 * @param success set to an error code if the auxillary data cannot be retrieved.
293 * @return the auxillary data
297 void *getAuxData(le_int32 glyphIndex, LEErrorCode &success) const;
300 * This operator allows direct access to the glyph array
301 * using the index operator.
303 * @param glyphIndex the index into the glyph array
305 * @return a reference to the given location in the glyph array
309 inline LEGlyphID &operator[](le_int32 glyphIndex) const;
312 * Call this method to replace a single glyph in the glyph array
313 * with multiple glyphs. This method uses the <code>LEInsertionList</code>
314 * to do the insertion. It returns the address of storage where the new
315 * glyph IDs can be stored. They will not actually be inserted into the
316 * glyph array until <code>applyInsertions</code> is called.
318 * @param atIndex the index of the glyph to be replaced
319 * @param insertCount the number of glyphs to replace it with
320 * @param success set to an error code if the auxillary data cannot be retrieved.
322 * @return the address at which to store the replacement glyphs.
324 * @see LEInsetionList.h
328 LEGlyphID *insertGlyphs(le_int32 atIndex, le_int32 insertCount,
329 LEErrorCode& success);
332 * This method causes all of the glyph insertions recorded by
333 * <code>insertGlyphs</code> to be applied to the glyph array. The
334 * new slots in the char indices and the auxillary data arrays
335 * will be filled in with the values for the glyph being replaced.
337 * @return the new size of the glyph array
339 * @see LEInsertionList.h
343 le_int32 applyInsertions();
346 * Set the glyph ID for a particular glyph.
348 * @param glyphIndex the index of the glyph
349 * @param glyphID the new glyph ID
350 * @param success will be set to an error code if the glyph ID cannot be set.
354 void setGlyphID(le_int32 glyphIndex, LEGlyphID glyphID, LEErrorCode &success);
357 * Set the char index for a particular glyph.
359 * @param glyphIndex the index of the glyph
360 * @param charIndex the new char index
361 * @param success will be set to an error code if the char index cannot be set.
365 void setCharIndex(le_int32 glyphIndex, le_int32 charIndex, LEErrorCode &success);
368 * Set the X, Y position for a particular glyph.
370 * @param glyphIndex the index of the glyph
371 * @param x the new X position
372 * @param y the new Y position
373 * @param success will be set to an error code if the position cannot be set.
377 void setPosition(le_int32 glyphIndex, float x, float y, LEErrorCode &success);
380 * Adjust the X, Y position for a particular glyph.
382 * @param glyphIndex the index of the glyph
383 * @param xAdjust the adjustment to the glyph's X position
384 * @param yAdjust the adjustment to the glyph's Y position
385 * @param success will be set to an error code if the glyph's position cannot be adjusted.
389 void adjustPosition(le_int32 glyphIndex, float xAdjust, float yAdjust, LEErrorCode &success);
392 * Set the auxillary data for a particular glyph.
394 * @param glyphIndex the index of the glyph
395 * @param auxData the new auxillary data
396 * @param success will be set to an error code if the auxillary data cannot be set.
400 void setAuxData(le_int32 glyphIndex, void *auxData, LEErrorCode &success);
403 * Delete the glyph array and replace it with the one
404 * in <code>from</code>. Set the glyph array pointer
405 * in <code>from</code> to <code>NULL</code>.
407 * @param from the <code>LEGlyphStorage</code> object from which
408 * to get the new glyph array.
412 void adoptGlyphArray(LEGlyphStorage &from);
415 * Delete the char indices array and replace it with the one
416 * in <code>from</code>. Set the char indices array pointer
417 * in <code>from</code> to <code>NULL</code>.
419 * @param from the <code>LEGlyphStorage</code> object from which
420 * to get the new char indices array.
424 void adoptCharIndicesArray(LEGlyphStorage &from);
427 * Delete the position array and replace it with the one
428 * in <code>from</code>. Set the position array pointer
429 * in <code>from</code> to <code>NULL</code>.
431 * @param from the <code>LEGlyphStorage</code> object from which
432 * to get the new position array.
436 void adoptPositionArray(LEGlyphStorage &from);
439 * Delete the auxillary data array and replace it with the one
440 * in <code>from</code>. Set the auxillary data array pointer
441 * in <code>from</code> to <code>NULL</code>.
443 * @param from the <code>LEGlyphStorage</code> object from which
444 * to get the new auxillary data array.
448 void adoptAuxDataArray(LEGlyphStorage &from);
451 * Change the glyph count of this object to be the same
452 * as the one in <code>from</code>.
454 * @param from the <code>LEGlyphStorage</code> object from which
455 * to get the new glyph count.
459 void adoptGlyphCount(LEGlyphStorage &from);
462 * Change the glyph count of this object to the given value.
464 * @param newGlyphCount the new glyph count.
468 void adoptGlyphCount(le_int32 newGlyphCount);
471 * This method frees the glyph, character index, position and
472 * auxillary data arrays so that the LayoutEngine can be reused
473 * to layout a different characer array. (This method is also called
481 * This method move glyph of Malayalam RAKAR to the left of the preceding
484 * @param aGlyphID the <code>LEGlyphID</code> of RAKAR
486 * @draft Added by Nokia
488 void forMlylRakar(LEGlyphID aGlyphID);
491 * ICU "poor man's RTTI", returns a UClassID for the actual class.
495 virtual UClassID getDynamicClassID() const;
498 * ICU "poor man's RTTI", returns a UClassID for this class.
502 static UClassID getStaticClassID();
505 inline le_int32 LEGlyphStorage::getGlyphCount() const
510 inline LEGlyphID &LEGlyphStorage::operator[](le_int32 glyphIndex) const
512 return fGlyphs[glyphIndex];