3 * (C) Copyright IBM Corp. 1998-2008 - All Rights Reserved
7 #include "layout/LETypes.h"
8 #include "layout/loengine.h"
9 #include "layout/plruns.h"
11 #include "unicode/locid.h"
13 #include "layout/LayoutEngine.h"
14 #include "layout/RunArrays.h"
18 U_CAPI pl_fontRuns
* U_EXPORT2
19 pl_openFontRuns(const le_font
**fonts
,
20 const le_int32
*limits
,
23 return (pl_fontRuns
*) new FontRuns((const LEFontInstance
**) fonts
, limits
, count
);
26 U_CAPI pl_fontRuns
* U_EXPORT2
27 pl_openEmptyFontRuns(le_int32 initialCapacity
)
29 return (pl_fontRuns
*) new FontRuns(initialCapacity
);
33 pl_closeFontRuns(pl_fontRuns
*fontRuns
)
35 FontRuns
*fr
= (FontRuns
*) fontRuns
;
40 U_CAPI le_int32 U_EXPORT2
41 pl_getFontRunCount(const pl_fontRuns
*fontRuns
)
43 const FontRuns
*fr
= (const FontRuns
*) fontRuns
;
49 return fr
->getCount();
53 pl_resetFontRuns(pl_fontRuns
*fontRuns
)
55 FontRuns
*fr
= (FontRuns
*) fontRuns
;
62 U_CAPI le_int32 U_EXPORT2
63 pl_getFontRunLastLimit(const pl_fontRuns
*fontRuns
)
65 const FontRuns
*fr
= (const FontRuns
*) fontRuns
;
71 return fr
->getLimit();
74 U_CAPI le_int32 U_EXPORT2
75 pl_getFontRunLimit(const pl_fontRuns
*fontRuns
,
78 const FontRuns
*fr
= (const FontRuns
*) fontRuns
;
84 return fr
->getLimit(run
);
87 U_CAPI
const le_font
* U_EXPORT2
88 pl_getFontRunFont(const pl_fontRuns
*fontRuns
,
91 const FontRuns
*fr
= (const FontRuns
*) fontRuns
;
97 return (const le_font
*) fr
->getFont(run
);
100 U_CAPI le_int32 U_EXPORT2
101 pl_addFontRun(pl_fontRuns
*fontRuns
,
105 FontRuns
*fr
= (FontRuns
*) fontRuns
;
111 return fr
->add((const LEFontInstance
*) font
, limit
);
114 U_CAPI pl_valueRuns
* U_EXPORT2
115 pl_openValueRuns(const le_int32
*values
,
116 const le_int32
*limits
,
119 return (pl_valueRuns
*) new ValueRuns(values
, limits
, count
);
122 U_CAPI pl_valueRuns
* U_EXPORT2
123 pl_openEmptyValueRuns(le_int32 initialCapacity
)
125 return (pl_valueRuns
*) new ValueRuns(initialCapacity
);
128 U_CAPI
void U_EXPORT2
129 pl_closeValueRuns(pl_valueRuns
*valueRuns
)
131 ValueRuns
*vr
= (ValueRuns
*) valueRuns
;
136 U_CAPI le_int32 U_EXPORT2
137 pl_getValueRunCount(const pl_valueRuns
*valueRuns
)
139 const ValueRuns
*vr
= (const ValueRuns
*) valueRuns
;
145 return vr
->getCount();
148 U_CAPI
void U_EXPORT2
149 pl_resetValueRuns(pl_valueRuns
*valueRuns
)
151 ValueRuns
*vr
= (ValueRuns
*) valueRuns
;
158 U_CAPI le_int32 U_EXPORT2
159 pl_getValueRunLastLimit(const pl_valueRuns
*valueRuns
)
161 const ValueRuns
*vr
= (const ValueRuns
*) valueRuns
;
167 return vr
->getLimit();
170 U_CAPI le_int32 U_EXPORT2
171 pl_getValueRunLimit(const pl_valueRuns
*valueRuns
,
174 const ValueRuns
*vr
= (const ValueRuns
*) valueRuns
;
180 return vr
->getLimit(run
);
183 U_CAPI le_int32 U_EXPORT2
184 pl_getValueRunValue(const pl_valueRuns
*valueRuns
,
187 const ValueRuns
*vr
= (const ValueRuns
*) valueRuns
;
193 return vr
->getValue(run
);
196 U_CAPI le_int32 U_EXPORT2
197 pl_addValueRun(pl_valueRuns
*valueRuns
,
201 ValueRuns
*vr
= (ValueRuns
*) valueRuns
;
207 return vr
->add(value
, limit
);
211 class ULocRuns
: public LocaleRuns
215 * Construct a <code>LocaleRuns</code> object from pre-existing arrays of locales
218 * @param locales is the address of an array of locale name strings. This array,
219 * and the <code>Locale</code> objects to which it points, must remain valid until
220 * the <code>LocaleRuns</code> object is destroyed.
222 * @param limits is the address of an array of limit indices. This array must remain valid until the
223 * <code>LocaleRuns</code> object is destroyed.
225 * @param count is the number of entries in the two arrays.
229 ULocRuns(const char **locales
, const le_int32
*limits
, le_int32 count
);
232 * Construct an empty <code>LoIDRuns</code> object. Clients can add locale and limit
233 * indices arrays using the <code>add</code> method.
235 * @param initialCapacity is the initial size of the locale and limit indices arrays. If
236 * this value is zero, no arrays will be allocated.
242 ULocRuns(le_int32 initialCapacity
);
245 * The destructor; virtual so that subclass destructors are invoked as well.
252 * Get the name of the locale assoicated with the given run
253 * of text. Use <code>RunArray::getLimit(run)</code> to get the corresponding
256 * @param run is the index into the font and limit indices arrays.
258 * @return the locale name associated with the given text run.
260 * @see RunArray::getLimit
264 const char *getLocaleName(le_int32 run
) const;
267 * Add a <code>Locale</code> and limit index pair to the data arrays and return
268 * the run index where the data was stored. This method calls
269 * <code>RunArray::add(limit)</code> which will create or grow the arrays as needed.
271 * If the <code>ULocRuns</code> object was created with a client-supplied
272 * locale and limit indices arrays, this method will return a run index of -1.
274 * Subclasses should not override this method. Rather they should provide a new <code>add</code>
275 * method which takes a locale name and a limit index along with whatever other data they implement.
276 * The new <code>add</code> method should first call this method to grow the font and limit indices
277 * arrays, and use the returned run index to store data their own arrays.
279 * @param locale is the name of the locale to add. This object must remain valid
280 * until the <code>ULocRuns</code> object is destroyed.
282 * @param limit is the limit index to add
284 * @return the run index where the locale and limit index were stored, or -1 if the data cannot be stored.
288 le_int32
add(const char *locale
, le_int32 limit
);
291 * ICU "poor man's RTTI", returns a UClassID for this class.
295 static inline UClassID
getStaticClassID();
298 * ICU "poor man's RTTI", returns a UClassID for the actual class.
302 virtual inline UClassID
getDynamicClassID() const;
305 virtual void init(le_int32 capacity
);
306 virtual void grow(le_int32 capacity
);
311 inline ULocRuns(const ULocRuns
&other
);
312 inline ULocRuns
&operator=(const ULocRuns
& /*other*/) { return *this; };
313 const char **fLocaleNames
;
314 Locale
**fLocalesCopy
;
317 inline ULocRuns::ULocRuns()
318 : LocaleRuns(0), fLocaleNames(NULL
)
320 // nothing else to do...
323 inline ULocRuns::ULocRuns(const ULocRuns
& /*other*/)
324 : LocaleRuns(0), fLocaleNames(NULL
)
326 // nothing else to do...
329 static const Locale
**getLocales(const char **localeNames
, le_int32 count
)
331 Locale
**locales
= LE_NEW_ARRAY(Locale
*, count
);
333 for (int i
= 0; i
< count
; i
+= 1) {
334 locales
[i
] = new Locale(Locale::createFromName(localeNames
[i
]));
337 return (const Locale
**) locales
;
340 ULocRuns::ULocRuns(const char **locales
, const le_int32
*limits
, le_int32 count
)
341 : LocaleRuns(getLocales(locales
, count
), limits
, count
), fLocaleNames(locales
)
343 // nothing else to do...
346 ULocRuns::ULocRuns(le_int32 initialCapacity
)
347 : LocaleRuns(initialCapacity
), fLocaleNames(NULL
)
349 if(initialCapacity
> 0) {
350 fLocaleNames
= LE_NEW_ARRAY(const char *, initialCapacity
);
354 ULocRuns::~ULocRuns()
356 le_int32 count
= getCount();
358 for(int i
= 0; i
< count
; i
+= 1) {
363 LE_DELETE_ARRAY(fLocales
);
366 LE_DELETE_ARRAY(fLocaleNames
);
371 void ULocRuns::init(le_int32 capacity
)
373 LocaleRuns::init(capacity
);
374 fLocaleNames
= LE_NEW_ARRAY(const char *, capacity
);
377 void ULocRuns::grow(le_int32 capacity
)
379 LocaleRuns::grow(capacity
);
380 fLocaleNames
= (const char **) LE_GROW_ARRAY(fLocaleNames
, capacity
);
383 le_int32
ULocRuns::add(const char *locale
, le_int32 limit
)
385 Locale
*loc
= new Locale(Locale::createFromName(locale
));
386 le_int32 index
= LocaleRuns::add(loc
, limit
);
389 char **localeNames
= (char **) fLocaleNames
;
391 localeNames
[index
] = (char *) locale
;
397 const char *ULocRuns::getLocaleName(le_int32 run
) const
399 if (run
< 0 || run
>= getCount()) {
403 return fLocaleNames
[run
];
405 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ULocRuns
)
408 U_CAPI pl_localeRuns
* U_EXPORT2
409 pl_openLocaleRuns(const char **locales
,
410 const le_int32
*limits
,
413 return (pl_localeRuns
*) new ULocRuns(locales
, limits
, count
);
416 U_CAPI pl_localeRuns
* U_EXPORT2
417 pl_openEmptyLocaleRuns(le_int32 initialCapacity
)
419 return (pl_localeRuns
*) new ULocRuns(initialCapacity
);
422 U_CAPI
void U_EXPORT2
423 pl_closeLocaleRuns(pl_localeRuns
*localeRuns
)
425 ULocRuns
*lr
= (ULocRuns
*) localeRuns
;
430 U_CAPI le_int32 U_EXPORT2
431 pl_getLocaleRunCount(const pl_localeRuns
*localeRuns
)
433 const ULocRuns
*lr
= (const ULocRuns
*) localeRuns
;
439 return lr
->getCount();
442 U_CAPI
void U_EXPORT2
443 pl_resetLocaleRuns(pl_localeRuns
*localeRuns
)
445 ULocRuns
*lr
= (ULocRuns
*) localeRuns
;
452 U_CAPI le_int32 U_EXPORT2
453 pl_getLocaleRunLastLimit(const pl_localeRuns
*localeRuns
)
455 const ULocRuns
*lr
= (const ULocRuns
*) localeRuns
;
461 return lr
->getLimit();
464 U_CAPI le_int32 U_EXPORT2
465 pl_getLocaleRunLimit(const pl_localeRuns
*localeRuns
,
468 const ULocRuns
*lr
= (const ULocRuns
*) localeRuns
;
474 return lr
->getLimit(run
);
477 U_CAPI
const char * U_EXPORT2
478 pl_getLocaleRunLocale(const pl_localeRuns
*localeRuns
,
481 const ULocRuns
*lr
= (const ULocRuns
*) localeRuns
;
487 return lr
->getLocaleName(run
);
490 U_CAPI le_int32 U_EXPORT2
491 pl_addLocaleRun(pl_localeRuns
*localeRuns
,
495 ULocRuns
*lr
= (ULocRuns
*) localeRuns
;
501 return lr
->add(locale
, limit
);