3 * (C) Copyright IBM Corp. 1998-2013 - 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
;
316 inline ULocRuns::ULocRuns()
317 : LocaleRuns(0), fLocaleNames(NULL
)
319 // nothing else to do...
322 inline ULocRuns::ULocRuns(const ULocRuns
& /*other*/)
323 : LocaleRuns(0), fLocaleNames(NULL
)
325 // nothing else to do...
328 static const Locale
**getLocales(const char **localeNames
, le_int32 count
)
330 Locale
**locales
= LE_NEW_ARRAY(Locale
*, count
);
332 for (int i
= 0; i
< count
; i
+= 1) {
333 locales
[i
] = new Locale(Locale::createFromName(localeNames
[i
]));
336 return (const Locale
**) locales
;
339 ULocRuns::ULocRuns(const char **locales
, const le_int32
*limits
, le_int32 count
)
340 : LocaleRuns(getLocales(locales
, count
), limits
, count
), fLocaleNames(locales
)
342 // nothing else to do...
345 ULocRuns::ULocRuns(le_int32 initialCapacity
)
346 : LocaleRuns(initialCapacity
), fLocaleNames(NULL
)
348 if(initialCapacity
> 0) {
349 fLocaleNames
= LE_NEW_ARRAY(const char *, initialCapacity
);
353 ULocRuns::~ULocRuns()
355 le_int32 count
= getCount();
357 for(int i
= 0; i
< count
; i
+= 1) {
362 LE_DELETE_ARRAY(fLocales
);
365 LE_DELETE_ARRAY(fLocaleNames
);
370 void ULocRuns::init(le_int32 capacity
)
372 LocaleRuns::init(capacity
);
373 fLocaleNames
= LE_NEW_ARRAY(const char *, capacity
);
376 void ULocRuns::grow(le_int32 capacity
)
378 LocaleRuns::grow(capacity
);
379 fLocaleNames
= (const char **) LE_GROW_ARRAY(fLocaleNames
, capacity
);
382 le_int32
ULocRuns::add(const char *locale
, le_int32 limit
)
384 Locale
*loc
= new Locale(Locale::createFromName(locale
));
385 le_int32 index
= LocaleRuns::add(loc
, limit
);
388 char **localeNames
= (char **) fLocaleNames
;
390 localeNames
[index
] = (char *) locale
;
396 const char *ULocRuns::getLocaleName(le_int32 run
) const
398 if (run
< 0 || run
>= getCount()) {
402 return fLocaleNames
[run
];
404 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ULocRuns
)
407 U_CAPI pl_localeRuns
* U_EXPORT2
408 pl_openLocaleRuns(const char **locales
,
409 const le_int32
*limits
,
412 return (pl_localeRuns
*) new ULocRuns(locales
, limits
, count
);
415 U_CAPI pl_localeRuns
* U_EXPORT2
416 pl_openEmptyLocaleRuns(le_int32 initialCapacity
)
418 return (pl_localeRuns
*) new ULocRuns(initialCapacity
);
421 U_CAPI
void U_EXPORT2
422 pl_closeLocaleRuns(pl_localeRuns
*localeRuns
)
424 ULocRuns
*lr
= (ULocRuns
*) localeRuns
;
429 U_CAPI le_int32 U_EXPORT2
430 pl_getLocaleRunCount(const pl_localeRuns
*localeRuns
)
432 const ULocRuns
*lr
= (const ULocRuns
*) localeRuns
;
438 return lr
->getCount();
441 U_CAPI
void U_EXPORT2
442 pl_resetLocaleRuns(pl_localeRuns
*localeRuns
)
444 ULocRuns
*lr
= (ULocRuns
*) localeRuns
;
451 U_CAPI le_int32 U_EXPORT2
452 pl_getLocaleRunLastLimit(const pl_localeRuns
*localeRuns
)
454 const ULocRuns
*lr
= (const ULocRuns
*) localeRuns
;
460 return lr
->getLimit();
463 U_CAPI le_int32 U_EXPORT2
464 pl_getLocaleRunLimit(const pl_localeRuns
*localeRuns
,
467 const ULocRuns
*lr
= (const ULocRuns
*) localeRuns
;
473 return lr
->getLimit(run
);
476 U_CAPI
const char * U_EXPORT2
477 pl_getLocaleRunLocale(const pl_localeRuns
*localeRuns
,
480 const ULocRuns
*lr
= (const ULocRuns
*) localeRuns
;
486 return lr
->getLocaleName(run
);
489 U_CAPI le_int32 U_EXPORT2
490 pl_addLocaleRun(pl_localeRuns
*localeRuns
,
494 ULocRuns
*lr
= (ULocRuns
*) localeRuns
;
500 return lr
->add(locale
, limit
);