]>
Commit | Line | Data |
---|---|---|
374ca955 A |
1 | /* |
2 | ********************************************************************** | |
3 | * Copyright (C) 1998-2004, International Business Machines | |
4 | * Corporation and others. All Rights Reserved. | |
5 | ********************************************************************** | |
6 | */ | |
7 | ||
8 | #ifndef __LEGLYPHSTORAGE_H | |
9 | #define __LEGLYPHSTORAGE_H | |
10 | ||
11 | #include "LETypes.h" | |
12 | #include "LEInsertionList.h" | |
13 | ||
14 | U_NAMESPACE_BEGIN | |
15 | ||
16 | /** | |
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 | |
20 | * pointer. | |
21 | * | |
22 | * The storage is growable using the <code>LEInsertionList</code> class. | |
23 | * | |
24 | * | |
25 | * @see LEInsertionList.h | |
26 | * | |
27 | * @draft ICU 3.0 | |
28 | */ | |
29 | class U_LAYOUT_API LEGlyphStorage : public UObject, protected LEInsertionCallback | |
30 | { | |
31 | private: | |
32 | /** | |
33 | * The number of entries in the per-glyph arrays. | |
34 | * | |
35 | * @internal | |
36 | */ | |
37 | le_int32 fGlyphCount; | |
38 | ||
39 | /** | |
40 | * The glyph ID array. | |
41 | * | |
42 | * @internal | |
43 | */ | |
44 | LEGlyphID *fGlyphs; | |
45 | ||
46 | /** | |
47 | * The char indices array. | |
48 | * | |
49 | * @internal | |
50 | */ | |
51 | le_int32 *fCharIndices; | |
52 | ||
53 | /** | |
54 | * The glyph positions array. | |
55 | * | |
56 | * @internal | |
57 | */ | |
58 | float *fPositions; | |
59 | ||
60 | /** | |
61 | * The auxillary data array. | |
62 | * | |
63 | * @internal | |
64 | */ | |
65 | void **fAuxData; | |
66 | ||
67 | ||
68 | /** | |
69 | * The insertion list, used to grow the above arrays. | |
70 | * | |
71 | * @internal | |
72 | */ | |
73 | LEInsertionList *fInsertionList; | |
74 | ||
75 | /** | |
76 | * The source index while growing the data arrays. | |
77 | * | |
78 | * @internal | |
79 | */ | |
80 | le_int32 fSrcIndex; | |
81 | ||
82 | /** | |
83 | * The destination index used while growing the data arrays. | |
84 | * | |
85 | * @internal | |
86 | */ | |
87 | le_int32 fDestIndex; | |
88 | ||
89 | protected: | |
90 | /** | |
91 | * This implements <code>LEInsertionCallback</code>. The <code>LEInsertionList</code> | |
92 | * will call this method once for each insertion. | |
93 | * | |
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 | |
97 | * | |
98 | * @return <code>true</code> if <code>LEInsertionList</code> should stop | |
99 | * processing the insertion list after this insertion. | |
100 | * | |
101 | * @see LEInsertionList.h | |
102 | * | |
103 | * @draft ICU 3.0 | |
104 | */ | |
105 | virtual le_bool applyInsertion(le_int32 atPosition, le_int32 count, LEGlyphID newGlyphs[]); | |
106 | ||
107 | public: | |
108 | ||
109 | /** | |
110 | * Allocates an empty <code>LEGlyphStorage</code> object. You must call | |
111 | * <code>allocateGlyphArray, allocatePositions and allocateAuxData</code> | |
112 | * to allocate the data. | |
113 | */ | |
114 | LEGlyphStorage(); | |
115 | ||
116 | /** | |
117 | * The destructor. This will deallocate all of the arrays. | |
118 | */ | |
119 | ~LEGlyphStorage(); | |
120 | ||
121 | /** | |
122 | * This method returns the number of glyphs in the glyph array. | |
123 | * | |
124 | * @return the number of glyphs in the glyph array | |
125 | * | |
126 | * @draft ICU 3.0 | |
127 | */ | |
128 | le_int32 getGlyphCount() const | |
129 | { | |
130 | return fGlyphCount; | |
131 | }; | |
132 | ||
133 | /** | |
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 | |
136 | * the glyphs. | |
137 | * | |
138 | * @param glyphs - the destiniation glyph array | |
139 | * @param success - set to an error code if the operation fails | |
140 | * | |
141 | * @draft ICU 3.0 | |
142 | */ | |
143 | void getGlyphs(LEGlyphID glyphs[], LEErrorCode &success) const; | |
144 | ||
145 | /** | |
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) | |
150 | * | |
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 | |
154 | * | |
155 | * @draft ICU 3.0 | |
156 | */ | |
157 | void getGlyphs(le_uint32 glyphs[], le_uint32 extraBits, LEErrorCode &success) const; | |
158 | ||
159 | /** | |
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. | |
163 | * | |
164 | * @param charIndices - the destiniation character index array | |
165 | * @param success - set to an error code if the operation fails | |
166 | * | |
167 | * @draft ICU 3.0 | |
168 | */ | |
169 | void getCharIndices(le_int32 charIndices[], LEErrorCode &success) const; | |
170 | ||
171 | /** | |
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. | |
175 | * | |
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 | |
179 | * | |
180 | * @draft ICU 3.0 | |
181 | */ | |
182 | void getCharIndices(le_int32 charIndices[], le_int32 indexBase, LEErrorCode &success) const; | |
183 | ||
184 | /** | |
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. | |
189 | * | |
190 | * @param positions - the destiniation position array | |
191 | * @param success - set to an error code if the operation fails | |
192 | * | |
193 | * @draft ICU 3.0 | |
194 | */ | |
195 | void getGlyphPositions(float positions[], LEErrorCode &success) const; | |
196 | ||
197 | /** | |
198 | * This method returns the X and Y position of the glyph at | |
199 | * the given index. | |
200 | * | |
201 | * Input parameters: | |
202 | * @param glyphIndex - the index of the glyph | |
203 | * | |
204 | * Output parameters: | |
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 | |
208 | * | |
209 | * @draft ICU 3.0 | |
210 | */ | |
211 | void getGlyphPosition(le_int32 glyphIndex, float &x, float &y, LEErrorCode &success) const; | |
212 | ||
213 | /** | |
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 | |
216 | * array. | |
217 | * | |
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. | |
222 | * | |
223 | * @draft ICU 3.0 | |
224 | */ | |
225 | void allocateGlyphArray(le_int32 initialGlyphCount, le_bool rightToLeft, LEErrorCode &success); | |
226 | ||
227 | /** | |
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. | |
230 | * | |
231 | * @param success set to an error code if the positions array cannot be allocated. | |
232 | * | |
233 | * @return the number of X, Y position pairs allocated. | |
234 | * | |
235 | * @draft ICU 3.0 | |
236 | */ | |
237 | le_int32 allocatePositions(LEErrorCode &success); | |
238 | ||
239 | /** | |
240 | * This method allocates the storage for the auxillary glyph data. | |
241 | * | |
242 | * @param success set to an error code if the aulillary data array cannot be allocated. | |
243 | * | |
244 | * @return the size of the auxillary data array. | |
245 | * | |
246 | * @draft ICU 3.0 | |
247 | */ | |
248 | le_int32 allocateAuxData(LEErrorCode &success); | |
249 | ||
250 | /** | |
251 | * Copy the entire auxillary data array. | |
252 | * | |
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 | |
255 | * | |
256 | * @draft ICU 3.0 | |
257 | */ | |
258 | void getAuxData(void *auxData[], LEErrorCode &success) const; | |
259 | ||
260 | /** | |
261 | * Get the glyph ID for a particular glyph. | |
262 | * | |
263 | * @param glyphIndex the index into the glyph array | |
264 | * @param success set to an error code if the glyph ID cannot be retrieved. | |
265 | * | |
266 | * @return the glyph ID | |
267 | * | |
268 | * @draft ICU 3.0 | |
269 | */ | |
270 | LEGlyphID getGlyphID(le_int32 glyphIndex, LEErrorCode &success) const; | |
271 | ||
272 | /** | |
273 | * Get the char index for a particular glyph. | |
274 | * | |
275 | * @param glyphIndex the index into the glyph array | |
276 | * @param success set to an error code if the char index cannot be retrieved. | |
277 | * | |
278 | * @return the character index | |
279 | * | |
280 | * @draft ICU 3.0 | |
281 | */ | |
282 | le_int32 getCharIndex(le_int32 glyphIndex, LEErrorCode &success) const; | |
283 | ||
284 | ||
285 | /** | |
286 | * Get the auxillary data for a particular glyph. | |
287 | * | |
288 | * @param glyphIndex the index into the glyph array | |
289 | * @param success set to an error code if the auxillary data cannot be retrieved. | |
290 | * | |
291 | * @return the auxillary data | |
292 | * | |
293 | * @draft ICU 3.0 | |
294 | */ | |
295 | void *getAuxData(le_int32 glyphIndex, LEErrorCode &success) const; | |
296 | ||
297 | /** | |
298 | * This operator allows direct access to the glyph array | |
299 | * using the index operator. | |
300 | * | |
301 | * @param glyphIndex the index into the glyph array | |
302 | * | |
303 | * @return a reference to the given location in the glyph array | |
304 | * | |
305 | * @draft ICU 3.0 | |
306 | */ | |
307 | LEGlyphID &operator[](le_int32 glyphIndex) const; | |
308 | ||
309 | /** | |
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. | |
315 | * | |
316 | * @param atIndex the index of the glyph to be replaced | |
317 | * @param insertCount the number of glyphs to replace it with | |
318 | * | |
319 | * @return the address at which to store the replacement glyphs. | |
320 | * | |
321 | * @see LEInsetionList.h | |
322 | * | |
323 | * @draft ICU 3.0 | |
324 | */ | |
325 | LEGlyphID *insertGlyphs(le_int32 atIndex, le_int32 insertCount); | |
326 | ||
327 | /** | |
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. | |
332 | * | |
333 | * @return the new size of the glyph array | |
334 | * | |
335 | * @see LEInsertionList.h | |
336 | * | |
337 | * @draft ICU 3.0 | |
338 | */ | |
339 | le_int32 applyInsertions(); | |
340 | ||
341 | /** | |
342 | * Set the glyph ID for a particular glyph. | |
343 | * | |
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. | |
347 | * | |
348 | * @draft ICU 3.0 | |
349 | */ | |
350 | void setGlyphID(le_int32 glyphIndex, LEGlyphID glyphID, LEErrorCode &success); | |
351 | ||
352 | /** | |
353 | * Set the char index for a particular glyph. | |
354 | * | |
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. | |
358 | * | |
359 | * @draft ICU 3.0 | |
360 | */ | |
361 | void setCharIndex(le_int32 glyphIndex, le_int32 charIndex, LEErrorCode &success); | |
362 | ||
363 | /** | |
364 | * Set the X, Y position for a particular glyph. | |
365 | * | |
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. | |
370 | * | |
371 | * @draft ICU 3.0 | |
372 | */ | |
373 | void setPosition(le_int32 glyphIndex, float x, float y, LEErrorCode &success); | |
374 | ||
375 | /** | |
376 | * Adjust the X, Y position for a particular glyph. | |
377 | * | |
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. | |
382 | * | |
383 | * @draft ICU 3.0 | |
384 | */ | |
385 | void adjustPosition(le_int32 glyphIndex, float xAdjust, float yAdjust, LEErrorCode &success); | |
386 | ||
387 | /** | |
388 | * Set the auxillary data for a particular glyph. | |
389 | * | |
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. | |
393 | * | |
394 | * @draft ICU 3.0 | |
395 | */ | |
396 | void setAuxData(le_int32 glyphIndex, void *auxData, LEErrorCode &success); | |
397 | ||
398 | /** | |
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>. | |
402 | * | |
403 | * @param from the <code>LEGlyphStorage</code> object from which | |
404 | * to get the new glyph array. | |
405 | * | |
406 | * @draft ICU 3.0 | |
407 | */ | |
408 | void adoptGlyphArray(LEGlyphStorage &from); | |
409 | ||
410 | /** | |
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>. | |
414 | * | |
415 | * @param from the <code>LEGlyphStorage</code> object from which | |
416 | * to get the new char indices array. | |
417 | * | |
418 | * @draft ICU 3.0 | |
419 | */ | |
420 | void adoptCharIndicesArray(LEGlyphStorage &from); | |
421 | ||
422 | /** | |
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>. | |
426 | * | |
427 | * @param from the <code>LEGlyphStorage</code> object from which | |
428 | * to get the new position array. | |
429 | * | |
430 | * @draft ICU 3.0 | |
431 | */ | |
432 | void adoptPositionArray(LEGlyphStorage &from); | |
433 | ||
434 | /** | |
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>. | |
438 | * | |
439 | * @param from the <code>LEGlyphStorage</code> object from which | |
440 | * to get the new auxillary data array. | |
441 | * | |
442 | * @draft ICU 3.0 | |
443 | */ | |
444 | void adoptAuxDataArray(LEGlyphStorage &from); | |
445 | ||
446 | /** | |
447 | * Change the glyph count of this object to be the same | |
448 | * as the one in <code>from</code>. | |
449 | * | |
450 | * @param from the <code>LEGlyphStorage</code> object from which | |
451 | * to get the new glyph count. | |
452 | * | |
453 | * @draft ICU 3.0 | |
454 | */ | |
455 | void adoptGlyphCount(LEGlyphStorage &from); | |
456 | ||
457 | /** | |
458 | * Change the glyph count of this object to the given value. | |
459 | * | |
460 | * @param newGlyphCount the new glyph count. | |
461 | * | |
462 | * @draft ICU 3.0 | |
463 | */ | |
464 | void adoptGlyphCount(le_int32 newGlyphCount); | |
465 | ||
466 | /** | |
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 | |
470 | * by the destructor) | |
471 | * | |
472 | * @draft ICU 3.0 | |
473 | */ | |
474 | void reset(); | |
475 | ||
476 | /** | |
477 | * ICU "poor man's RTTI", returns a UClassID for the actual class. | |
478 | * | |
479 | * @draft ICU 3.0 | |
480 | */ | |
481 | virtual UClassID getDynamicClassID() const; | |
482 | ||
483 | /** | |
484 | * ICU "poor man's RTTI", returns a UClassID for this class. | |
485 | * | |
486 | * @draft ICU 3.0 | |
487 | */ | |
488 | static UClassID getStaticClassID(); | |
489 | }; | |
490 | ||
491 | inline LEGlyphID &LEGlyphStorage::operator[](le_int32 glyphIndex) const | |
492 | { | |
493 | return fGlyphs[glyphIndex]; | |
494 | } | |
495 | ||
496 | ||
497 | U_NAMESPACE_END | |
498 | #endif | |
499 |