2 **********************************************************************
3 * Copyright (C) 1998-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
8 #ifndef __LEGLYPHSTORAGE_H
9 #define __LEGLYPHSTORAGE_H
12 #include "LEInsertionList.h"
17 * This class encapsulates the per-glyph storage used by the ICU LayoutEngine.
18 * For each glyph it holds the glyph ID, the index of the backing store character
19 * which produced the glyph, the X and Y position of the glyph and an auxillary data
22 * The storage is growable using the <code>LEInsertionList</code> class.
25 * @see LEInsertionList.h
29 class U_LAYOUT_API LEGlyphStorage
: public UObject
, protected LEInsertionCallback
33 * The number of entries in the per-glyph arrays.
47 * The char indices array.
51 le_int32
*fCharIndices
;
54 * The glyph positions array.
61 * The auxillary data array.
69 * The insertion list, used to grow the above arrays.
73 LEInsertionList
*fInsertionList
;
76 * The source index while growing the data arrays.
83 * The destination index used while growing the data arrays.
91 * This implements <code>LEInsertionCallback</code>. The <code>LEInsertionList</code>
92 * will call this method once for each insertion.
94 * @param atPosition the position of the insertion
95 * @param count the number of glyphs being inserted
96 * @param newGlyphs the address of the new glyph IDs
98 * @return <code>true</code> if <code>LEInsertionList</code> should stop
99 * processing the insertion list after this insertion.
101 * @see LEInsertionList.h
105 virtual le_bool
applyInsertion(le_int32 atPosition
, le_int32 count
, LEGlyphID newGlyphs
[]);
110 * Allocates an empty <code>LEGlyphStorage</code> object. You must call
111 * <code>allocateGlyphArray, allocatePositions and allocateAuxData</code>
112 * to allocate the data.
117 * The destructor. This will deallocate all of the arrays.
122 * This method returns the number of glyphs in the glyph array.
124 * @return the number of glyphs in the glyph array
128 le_int32
getGlyphCount() const
134 * This method copies the glyph array into a caller supplied array.
135 * The caller must ensure that the array is large enough to hold all
138 * @param glyphs - the destiniation glyph array
139 * @param success - set to an error code if the operation fails
143 void getGlyphs(LEGlyphID glyphs
[], LEErrorCode
&success
) const;
146 * This method copies the glyph array into a caller supplied array,
147 * ORing in extra bits. (This functionality is needed by the JDK,
148 * which uses 32 bits pre glyph idex, with the high 16 bits encoding
149 * the composite font slot number)
151 * @param glyphs - the destination (32 bit) glyph array
152 * @param extraBits - this value will be ORed with each glyph index
153 * @param success - set to an error code if the operation fails
157 void getGlyphs(le_uint32 glyphs
[], le_uint32 extraBits
, LEErrorCode
&success
) const;
160 * This method copies the character index array into a caller supplied array.
161 * The caller must ensure that the array is large enough to hold a
162 * character index for each glyph.
164 * @param charIndices - the destiniation character index array
165 * @param success - set to an error code if the operation fails
169 void getCharIndices(le_int32 charIndices
[], LEErrorCode
&success
) const;
172 * This method copies the character index array into a caller supplied array.
173 * The caller must ensure that the array is large enough to hold a
174 * character index for each glyph.
176 * @param charIndices - the destiniation character index array
177 * @param indexBase - an offset which will be added to each index
178 * @param success - set to an error code if the operation fails
182 void getCharIndices(le_int32 charIndices
[], le_int32 indexBase
, LEErrorCode
&success
) const;
185 * This method copies the position array into a caller supplied array.
186 * The caller must ensure that the array is large enough to hold an
187 * X and Y position for each glyph, plus an extra X and Y for the
188 * advance of the last glyph.
190 * @param positions - the destiniation position array
191 * @param success - set to an error code if the operation fails
195 void getGlyphPositions(float positions
[], LEErrorCode
&success
) const;
198 * This method returns the X and Y position of the glyph at
202 * @param glyphIndex - the index of the glyph
205 * @param x - the glyph's X position
206 * @param y - the glyph's Y position
207 * @param success - set to an error code if the operation fails
211 void getGlyphPosition(le_int32 glyphIndex
, float &x
, float &y
, LEErrorCode
&success
) const;
214 * This method allocates the glyph array, the char indices array and the insertion list. You
215 * must call this method before using the object. This method also initializes the char indices
218 * @param initialGlyphCount the initial size of the glyph and char indices arrays.
219 * @param rightToLeft <code>true</code> if the original input text is right to left.
220 * @param success set to an error code if the storage cannot be allocated of if the initial
221 * glyph count is not positive.
225 void allocateGlyphArray(le_int32 initialGlyphCount
, le_bool rightToLeft
, LEErrorCode
&success
);
228 * This method allocates the storage for the glyph positions. It allocates one extra X, Y
229 * position pair for the position just after the last glyph.
231 * @param success set to an error code if the positions array cannot be allocated.
233 * @return the number of X, Y position pairs allocated.
237 le_int32
allocatePositions(LEErrorCode
&success
);
240 * This method allocates the storage for the auxillary glyph data.
242 * @param success set to an error code if the aulillary data array cannot be allocated.
244 * @return the size of the auxillary data array.
248 le_int32
allocateAuxData(LEErrorCode
&success
);
251 * Copy the entire auxillary data array.
253 * @param auxData the auxillary data array will be copied to this address
254 * @param success set to an error code if the data cannot be copied
258 void getAuxData(void *auxData
[], LEErrorCode
&success
) const;
261 * Get the glyph ID for a particular glyph.
263 * @param glyphIndex the index into the glyph array
264 * @param success set to an error code if the glyph ID cannot be retrieved.
266 * @return the glyph ID
270 LEGlyphID
getGlyphID(le_int32 glyphIndex
, LEErrorCode
&success
) const;
273 * Get the char index for a particular glyph.
275 * @param glyphIndex the index into the glyph array
276 * @param success set to an error code if the char index cannot be retrieved.
278 * @return the character index
282 le_int32
getCharIndex(le_int32 glyphIndex
, LEErrorCode
&success
) const;
286 * Get the auxillary data for a particular glyph.
288 * @param glyphIndex the index into the glyph array
289 * @param success set to an error code if the auxillary data cannot be retrieved.
291 * @return the auxillary data
295 void *getAuxData(le_int32 glyphIndex
, LEErrorCode
&success
) const;
298 * This operator allows direct access to the glyph array
299 * using the index operator.
301 * @param glyphIndex the index into the glyph array
303 * @return a reference to the given location in the glyph array
307 LEGlyphID
&operator[](le_int32 glyphIndex
) const;
310 * Call this method to replace a single glyph in the glyph array
311 * with multiple glyphs. This method uses the <code>LEInsertionList</code>
312 * to do the insertion. It returns the address of storage where the new
313 * glyph IDs can be stored. They will not actually be inserted into the
314 * glyph array until <code>applyInsertions</code> is called.
316 * @param atIndex the index of the glyph to be replaced
317 * @param insertCount the number of glyphs to replace it with
319 * @return the address at which to store the replacement glyphs.
321 * @see LEInsetionList.h
325 LEGlyphID
*insertGlyphs(le_int32 atIndex
, le_int32 insertCount
);
328 * This method causes all of the glyph insertions recorded by
329 * <code>insertGlyphs</code> to be applied to the glyph array. The
330 * new slots in the char indices and the auxillary data arrays
331 * will be filled in with the values for the glyph being replaced.
333 * @return the new size of the glyph array
335 * @see LEInsertionList.h
339 le_int32
applyInsertions();
342 * Set the glyph ID for a particular glyph.
344 * @param glyphIndex the index of the glyph
345 * @param glyphID the new glyph ID
346 * @param success will be set to an error code if the glyph ID cannot be set.
350 void setGlyphID(le_int32 glyphIndex
, LEGlyphID glyphID
, LEErrorCode
&success
);
353 * Set the char index for a particular glyph.
355 * @param glyphIndex the index of the glyph
356 * @param charIndex the new char index
357 * @param success will be set to an error code if the char index cannot be set.
361 void setCharIndex(le_int32 glyphIndex
, le_int32 charIndex
, LEErrorCode
&success
);
364 * Set the X, Y position for a particular glyph.
366 * @param glyphIndex the index of the glyph
367 * @param x the new X position
368 * @param y the new Y position
369 * @param success will be set to an error code if the position cannot be set.
373 void setPosition(le_int32 glyphIndex
, float x
, float y
, LEErrorCode
&success
);
376 * Adjust the X, Y position for a particular glyph.
378 * @param glyphIndex the index of the glyph
379 * @param xAdjust the adjustment to the glyph's X position
380 * @param yAdjust the adjustment to the glyph's Y position
381 * @param success will be set to an error code if the glyph's position cannot be adjusted.
385 void adjustPosition(le_int32 glyphIndex
, float xAdjust
, float yAdjust
, LEErrorCode
&success
);
388 * Set the auxillary data for a particular glyph.
390 * @param glyphIndex the index of the glyph
391 * @param auxData the new auxillary data
392 * @param success will be set to an error code if the auxillary data cannot be set.
396 void setAuxData(le_int32 glyphIndex
, void *auxData
, LEErrorCode
&success
);
399 * Delete the glyph array and replace it with the one
400 * in <code>from</code>. Set the glyph array pointer
401 * in <code>from</code> to <code>NULL</code>.
403 * @param from the <code>LEGlyphStorage</code> object from which
404 * to get the new glyph array.
408 void adoptGlyphArray(LEGlyphStorage
&from
);
411 * Delete the char indices array and replace it with the one
412 * in <code>from</code>. Set the char indices array pointer
413 * in <code>from</code> to <code>NULL</code>.
415 * @param from the <code>LEGlyphStorage</code> object from which
416 * to get the new char indices array.
420 void adoptCharIndicesArray(LEGlyphStorage
&from
);
423 * Delete the position array and replace it with the one
424 * in <code>from</code>. Set the position array pointer
425 * in <code>from</code> to <code>NULL</code>.
427 * @param from the <code>LEGlyphStorage</code> object from which
428 * to get the new position array.
432 void adoptPositionArray(LEGlyphStorage
&from
);
435 * Delete the auxillary data array and replace it with the one
436 * in <code>from</code>. Set the auxillary data array pointer
437 * in <code>from</code> to <code>NULL</code>.
439 * @param from the <code>LEGlyphStorage</code> object from which
440 * to get the new auxillary data array.
444 void adoptAuxDataArray(LEGlyphStorage
&from
);
447 * Change the glyph count of this object to be the same
448 * as the one in <code>from</code>.
450 * @param from the <code>LEGlyphStorage</code> object from which
451 * to get the new glyph count.
455 void adoptGlyphCount(LEGlyphStorage
&from
);
458 * Change the glyph count of this object to the given value.
460 * @param newGlyphCount the new glyph count.
464 void adoptGlyphCount(le_int32 newGlyphCount
);
467 * This method frees the glyph, character index, position and
468 * auxillary data arrays so that the LayoutEngine can be reused
469 * to layout a different characer array. (This method is also called
477 * ICU "poor man's RTTI", returns a UClassID for the actual class.
481 virtual UClassID
getDynamicClassID() const;
484 * ICU "poor man's RTTI", returns a UClassID for this class.
488 static UClassID
getStaticClassID();
491 inline LEGlyphID
&LEGlyphStorage::operator[](le_int32 glyphIndex
) const
493 return fGlyphs
[glyphIndex
];