2 **********************************************************************
3 * Copyright (C) 2003-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
12 #include "layout/LETypes.h"
13 #include "layout/LEFontInstance.h"
15 #include "unicode/utypes.h"
16 #include "unicode/locid.h"
21 * The initial size of an array if it is unspecified.
25 #define INITIAL_CAPACITY 16
28 * When an array needs to grow, it will double in size until
29 * it becomes this large, then it will grow by this amount.
33 #define CAPACITY_GROW_LIMIT 128
36 * The <code>RunArray</code> class is a base class for building classes
37 * which represent data that is associated with runs of text. This class
38 * maintains an array of limit indices into the text, subclasses
39 * provide one or more arrays of data.
43 class U_LAYOUTEX_API RunArray
: public UObject
47 * Construct a <code>RunArray</code> object from a pre-existing
48 * array of limit indices.
50 * @param limits is an array of limit indices. This array must remain
51 * valid until the <code>RunArray</code> object is destroyed.
53 * @param count is the number of entries in the limit array.
57 RunArray(const le_int32
*limits
, le_int32 count
);
60 * Construct an empty <code>RunArray</code> object. Clients can add limit
61 * indices array using the <code>add</code> method.
63 * @param initialCapacity is the initial size of the limit indices array. If
64 * this value is zero, no array will be allocated.
70 RunArray(le_int32 initialCapacity
);
73 * The destructor; virtual so that subclass destructors are invoked as well.
80 * Get the number of entries in the limit indices array.
82 * @return the number of entries in the limit indices array.
86 le_int32
getCount() const;
89 * Get the last limit index. This is the number of characters in
92 * @return the last limit index.
96 le_int32
getLimit() const;
99 * Get the limit index for a particular run of text.
101 * @param run is the run. This is an index into the limit index array.
103 * @return the limit index for the run, or -1 if <code>run</code> is out of bounds.
107 le_int32
getLimit(le_int32 run
) const;
110 * Add a limit index to the limit indices array and return the run index
111 * where it was stored. If the array does not exist, it will be created by
112 * calling the <code>init</code> method. If it is full, it will be grown by
113 * calling the <code>grow</code> method.
115 * If the <code>RunArray</code> object was created with a client-supplied
116 * limit indices array, this method will return a run index of -1.
118 * Subclasses should not override this method. Rather they should provide
119 * a new <code>add</code> method which takes a limit index along with whatever
120 * other data they implement. The new <code>add</code> method should
121 * first call this method to grow the data arrays, and use the return value
122 * to store the data in their own arrays.
124 * @param limit is the limit index to add to the array.
126 * @return the run index where the limit index was stored, or -1 if the limit index cannt be stored.
133 le_int32
add(le_int32 limit
);
136 * ICU "poor man's RTTI", returns a UClassID for the actual class.
140 virtual inline UClassID
getDynamicClassID() const { return getStaticClassID(); }
143 * ICU "poor man's RTTI", returns a UClassID for this class.
147 static inline UClassID
getStaticClassID() { return (UClassID
)&fgClassID
; }
151 * Create a data array with the given initial size. This method will be
152 * called by the <code>add</code> method if there is no limit indices
153 * array. Subclasses which override this method must also call it from
154 * the overriding method to create the limit indices array.
156 * @param capacity is the initial size of the data array.
162 virtual void init(le_int32 capacity
);
165 * Grow a data array to the given initial size. This method will be
166 * called by the <code>add</code> method if the limit indices
167 * array is full. Subclasses which override this method must also call it from
168 * the overriding method to grow the limit indices array.
170 * @param capacity is the initial size of the data array.
176 virtual void grow(le_int32 capacity
);
179 * Set by the constructors to indicate whether
180 * or not the client supplied the data arrays.
181 * If they were supplied by the client, the
182 * <code>add</code> method won't change the arrays
183 * and the destructor won't delete them.
187 le_bool fClientArrays
;
191 * The address of this static class variable serves as this class's ID
192 * for ICU "poor man's RTTI".
194 static const char fgClassID
;
196 le_int32
ensureCapacity();
199 RunArray(const RunArray
& /*other*/);
200 RunArray
&operator=(const RunArray
& /*other*/) { return *this; };
202 const le_int32
*fLimits
;
207 inline RunArray::RunArray()
208 : UObject(), fClientArrays(FALSE
), fLimits(NULL
), fCount(0), fCapacity(0)
210 // nothing else to do...
213 inline RunArray::RunArray(const RunArray
& /*other*/)
214 : UObject(), fClientArrays(FALSE
), fLimits(NULL
), fCount(0), fCapacity(0)
216 // nothing else to do...
219 inline RunArray::RunArray(const le_int32
*limits
, le_int32 count
)
220 : UObject(), fClientArrays(TRUE
), fLimits(limits
), fCount(count
), fCapacity(count
)
222 // nothing else to do...
225 inline le_int32
RunArray::getCount() const
230 inline le_int32
RunArray::getLimit(le_int32 run
) const
232 if (run
< 0 || run
>= fCount
) {
239 inline le_int32
RunArray::getLimit() const
241 return getLimit(fCount
- 1);
245 * The <code>FontRuns</code> class associates pointers to <code>LEFontInstance</code>
246 * objects with runs of text.
250 class U_LAYOUTEX_API FontRuns
: public RunArray
254 * Construct a <code>FontRuns</code> object from pre-existing arrays of fonts
257 * @param fonts is the address of an array of pointers to <code>LEFontInstance</code> objects. This
258 * array, and the <code>LEFontInstance</code> objects to which it points must remain
259 * valid until the <code>FontRuns</code> object is destroyed.
261 * @param limits is the address of an array of limit indices. This array must remain valid until
262 * the <code>FontRuns</code> object is destroyed.
264 * @param count is the number of entries in the two arrays.
268 FontRuns(const LEFontInstance
**fonts
, const le_int32
*limits
, le_int32 count
);
271 * Construct an empty <code>FontRuns</code> object. Clients can add font and limit
272 * indices arrays using the <code>add</code> method.
274 * @param initialCapacity is the initial size of the font and limit indices arrays. If
275 * this value is zero, no arrays will be allocated.
281 FontRuns(le_int32 initialCapacity
);
284 * The destructor; virtual so that subclass destructors are invoked as well.
291 * Get the <code>LEFontInstance</code> object assoicated with the given run
292 * of text. Use <code>RunArray::getLimit(run)</code> to get the corresponding
295 * @param run is the index into the font and limit indices arrays.
297 * @return the <code>LEFontInstance</code> associated with the given text run.
299 * @see RunArray::getLimit
303 const LEFontInstance
*getFont(le_int32 run
) const;
307 * Add an <code>LEFontInstance</code> and limit index pair to the data arrays and return
308 * the run index where the data was stored. This method calls
309 * <code>RunArray::add(limit)</code> which will create or grow the arrays as needed.
311 * If the <code>FontRuns</code> object was created with a client-supplied
312 * font and limit indices arrays, this method will return a run index of -1.
314 * Subclasses should not override this method. Rather they should provide a new <code>add</code>
315 * method which takes a font and a limit index along with whatever other data they implement.
316 * The new <code>add</code> method should first call this method to grow the font and limit indices
317 * arrays, and use the returned run index to store data their own arrays.
319 * @param font is the address of the <code>LEFontInstance</code> to add. This object must
320 * remain valid until the <code>FontRuns</code> object is destroyed.
322 * @param limit is the limit index to add
324 * @return the run index where the font and limit index were stored, or -1 if the data cannot be stored.
328 le_int32
add(const LEFontInstance
*font
, le_int32 limit
);
331 * ICU "poor man's RTTI", returns a UClassID for the actual class.
335 virtual inline UClassID
getDynamicClassID() const { return getStaticClassID(); }
338 * ICU "poor man's RTTI", returns a UClassID for this class.
342 static inline UClassID
getStaticClassID() { return (UClassID
)&fgClassID
; }
345 virtual void init(le_int32 capacity
);
346 virtual void grow(le_int32 capacity
);
351 FontRuns(const FontRuns
&other
);
352 FontRuns
&operator=(const FontRuns
& /*other*/) { return *this; };
355 * The address of this static class variable serves as this class's ID
356 * for ICU "poor man's RTTI".
358 static const char fgClassID
;
360 const LEFontInstance
**fFonts
;
363 inline FontRuns::FontRuns()
364 : RunArray(0), fFonts(NULL
)
366 // nothing else to do...
369 inline FontRuns::FontRuns(const FontRuns
& /*other*/)
370 : RunArray(0), fFonts(NULL
)
372 // nothing else to do...
375 inline FontRuns::FontRuns(const LEFontInstance
**fonts
, const le_int32
*limits
, le_int32 count
)
376 : RunArray(limits
, count
), fFonts(fonts
)
378 // nothing else to do...
382 * The <code>LocaleRuns</code> class associates pointers to <code>Locale</code>
383 * objects with runs of text.
387 class U_LAYOUTEX_API LocaleRuns
: public RunArray
391 * Construct a <code>LocaleRuns</code> object from pre-existing arrays of locales
394 * @param locales is the address of an array of pointers to <code>Locale</code> objects. This array,
395 * and the <code>Locale</code> objects to which it points, must remain valid until
396 * the <code>LocaleRuns</code> object is destroyed.
398 * @param limits is the address of an array of limit indices. This array must remain valid until the
399 * <code>LocaleRuns</code> object is destroyed.
401 * @param count is the number of entries in the two arrays.
405 LocaleRuns(const Locale
**locales
, const le_int32
*limits
, le_int32 count
);
408 * Construct an empty <code>LocaleRuns</code> object. Clients can add locale and limit
409 * indices arrays using the <code>add</code> method.
411 * @param initialCapacity is the initial size of the locale and limit indices arrays. If
412 * this value is zero, no arrays will be allocated.
418 LocaleRuns(le_int32 initialCapacity
);
421 * The destructor; virtual so that subclass destructors are invoked as well.
425 virtual ~LocaleRuns();
428 * Get the <code>Locale</code> object assoicated with the given run
429 * of text. Use <code>RunArray::getLimit(run)</code> to get the corresponding
432 * @param run is the index into the font and limit indices arrays.
434 * @return the <code>Locale</code> associated with the given text run.
436 * @see RunArray::getLimit
440 const Locale
*getLocale(le_int32 run
) const;
444 * Add a <code>Locale</code> and limit index pair to the data arrays and return
445 * the run index where the data was stored. This method calls
446 * <code>RunArray::add(limit)</code> which will create or grow the arrays as needed.
448 * If the <code>LocaleRuns</code> object was created with a client-supplied
449 * locale and limit indices arrays, this method will return a run index of -1.
451 * Subclasses should not override this method. Rather they should provide a new <code>add</code>
452 * method which takes a locale and a limit index along with whatever other data they implement.
453 * The new <code>add</code> method should first call this method to grow the font and limit indices
454 * arrays, and use the returned run index to store data their own arrays.
456 * @param locale is the address of the <code>Locale</code> to add. This object must remain valid
457 * until the <code>LocaleRuns</code> object is destroyed.
459 * @param limit is the limit index to add
461 * @return the run index where the locale and limit index were stored, or -1 if the data cannot be stored.
465 le_int32
add(const Locale
*locale
, le_int32 limit
);
468 * ICU "poor man's RTTI", returns a UClassID for the actual class.
472 virtual inline UClassID
getDynamicClassID() const { return getStaticClassID(); }
475 * ICU "poor man's RTTI", returns a UClassID for this class.
479 static inline UClassID
getStaticClassID() { return (UClassID
)&fgClassID
; }
482 virtual void init(le_int32 capacity
);
483 virtual void grow(le_int32 capacity
);
488 LocaleRuns(const LocaleRuns
&other
);
489 LocaleRuns
&operator=(const LocaleRuns
& /*other*/) { return *this; };
492 * The address of this static class variable serves as this class's ID
493 * for ICU "poor man's RTTI".
495 static const char fgClassID
;
497 const Locale
**fLocales
;
500 inline LocaleRuns::LocaleRuns()
501 : RunArray(0), fLocales(NULL
)
503 // nothing else to do...
506 inline LocaleRuns::LocaleRuns(const LocaleRuns
& /*other*/)
507 : RunArray(0), fLocales(NULL
)
509 // nothing else to do...
512 inline LocaleRuns::LocaleRuns(const Locale
**locales
, const le_int32
*limits
, le_int32 count
)
513 : RunArray(limits
, count
), fLocales(locales
)
515 // nothing else to do...
519 * The <code>ValueRuns</code> class associates integer values with runs of text.
523 class U_LAYOUTEX_API ValueRuns
: public RunArray
527 * Construct a <code>ValueRuns</code> object from pre-existing arrays of values
530 * @param values is the address of an array of integer. This array must remain valid until
531 * the <code>ValueRuns</code> object is destroyed.
533 * @param limits is the address of an array of limit indices. This array must remain valid until
534 * the <code>ValueRuns</code> object is destroyed.
536 * @param count is the number of entries in the two arrays.
540 ValueRuns(const le_int32
*values
, const le_int32
*limits
, le_int32 count
);
543 * Construct an empty <code>ValueRuns</code> object. Clients can add value and limit
544 * indices arrays using the <code>add</code> method.
546 * @param initialCapacity is the initial size of the value and limit indices arrays. If
547 * this value is zero, no arrays will be allocated.
553 ValueRuns(le_int32 initialCapacity
);
556 * The destructor; virtual so that subclass destructors are invoked as well.
560 virtual ~ValueRuns();
563 * Get the integer value assoicated with the given run
564 * of text. Use <code>RunArray::getLimit(run)</code> to get the corresponding
567 * @param run is the index into the font and limit indices arrays.
569 * @return the integer value associated with the given text run.
571 * @see RunArray::getLimit
575 le_int32
getValue(le_int32 run
) const;
579 * Add an integer value and limit index pair to the data arrays and return
580 * the run index where the data was stored. This method calls
581 * <code>RunArray::add(limit)</code> which will create or grow the arrays as needed.
583 * If the <code>ValueRuns</code> object was created with a client-supplied
584 * font and limit indices arrays, this method will return a run index of -1.
586 * Subclasses should not override this method. Rather they should provide a new <code>add</code>
587 * method which takes an integer value and a limit index along with whatever other data they implement.
588 * The new <code>add</code> method should first call this method to grow the font and limit indices
589 * arrays, and use the returned run index to store data their own arrays.
591 * @param value is the integer value to add
593 * @param limit is the limit index to add
595 * @return the run index where the value and limit index were stored, or -1 if the data cannot be stored.
599 le_int32
add(le_int32 value
, le_int32 limit
);
602 * ICU "poor man's RTTI", returns a UClassID for the actual class.
606 virtual inline UClassID
getDynamicClassID() const { return getStaticClassID(); }
609 * ICU "poor man's RTTI", returns a UClassID for this class.
613 static inline UClassID
getStaticClassID() { return (UClassID
)&fgClassID
; }
616 virtual void init(le_int32 capacity
);
617 virtual void grow(le_int32 capacity
);
622 ValueRuns(const ValueRuns
&other
);
623 ValueRuns
&operator=(const ValueRuns
& /*other*/) { return *this; };
626 * The address of this static class variable serves as this class's ID
627 * for ICU "poor man's RTTI".
629 static const char fgClassID
;
631 const le_int32
*fValues
;
634 inline ValueRuns::ValueRuns()
635 : RunArray(0), fValues(NULL
)
637 // nothing else to do...
640 inline ValueRuns::ValueRuns(const ValueRuns
& /*other*/)
641 : RunArray(0), fValues(NULL
)
643 // nothing else to do...
646 inline ValueRuns::ValueRuns(const le_int32
*values
, const le_int32
*limits
, le_int32 count
)
647 : RunArray(limits
, count
), fValues(values
)
649 // nothing else to do...