1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (C) 2003, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
10 #include "layout/LETypes.h"
11 #include "layout/LEFontInstance.h"
13 #include "unicode/locid.h"
15 #include "layout/RunArrays.h"
19 const char RunArray::fgClassID = 0;
21 RunArray::RunArray(le_int32 initialCapacity)
22 : fClientArrays(FALSE), fLimits(NULL), fCount(0), fCapacity(initialCapacity)
24 if (initialCapacity > 0) {
25 fLimits = LE_NEW_ARRAY(le_int32, fCapacity);
31 if (! fClientArrays) {
32 LE_DELETE_ARRAY(fLimits);
37 le_int32 RunArray::ensureCapacity()
39 if (fCount >= fCapacity) {
41 fCapacity = INITIAL_CAPACITY;
44 fCapacity += (fCapacity < CAPACITY_GROW_LIMIT ? fCapacity : CAPACITY_GROW_LIMIT);
52 void RunArray::init(le_int32 capacity)
54 fLimits = LE_NEW_ARRAY(le_int32, capacity);
57 void RunArray::grow(le_int32 newCapacity)
59 fLimits = (le_int32 *) LE_GROW_ARRAY(fLimits, newCapacity);
62 le_int32 RunArray::add(le_int32 limit)
68 le_int32 index = ensureCapacity();
69 le_int32 *limits = (le_int32 *) fLimits;
71 limits[index] = limit;
76 const char FontRuns::fgClassID = 0;
78 FontRuns::FontRuns(le_int32 initialCapacity)
79 : RunArray(initialCapacity), fFonts(NULL)
81 if (initialCapacity > 0) {
82 fFonts = LE_NEW_ARRAY(const LEFontInstance *, initialCapacity);
88 if (! fClientArrays) {
89 LE_DELETE_ARRAY(fFonts);
94 void FontRuns::init(le_int32 capacity)
96 RunArray::init(capacity);
97 fFonts = LE_NEW_ARRAY(const LEFontInstance *, capacity);
100 void FontRuns::grow(le_int32 capacity)
102 RunArray::grow(capacity);
103 fFonts = (const LEFontInstance **) LE_GROW_ARRAY(fFonts, capacity);
106 le_int32 FontRuns::add(const LEFontInstance *font, le_int32 limit)
108 le_int32 index = RunArray::add(limit);
111 LEFontInstance **fonts = (LEFontInstance **) fFonts;
113 fonts[index] = (LEFontInstance *) font;
119 const LEFontInstance *FontRuns::getFont(le_int32 run) const
121 if (run < 0 || run >= getCount()) {
128 const char LocaleRuns::fgClassID = 0;
130 LocaleRuns::LocaleRuns(le_int32 initialCapacity)
131 : RunArray(initialCapacity), fLocales(NULL)
133 if (initialCapacity > 0) {
134 fLocales = LE_NEW_ARRAY(const Locale *, initialCapacity);
138 LocaleRuns::~LocaleRuns()
140 if (! fClientArrays) {
141 LE_DELETE_ARRAY(fLocales);
146 void LocaleRuns::init(le_int32 capacity)
148 RunArray::init(capacity);
149 fLocales = LE_NEW_ARRAY(const Locale *, capacity);
152 void LocaleRuns::grow(le_int32 capacity)
154 RunArray::grow(capacity);
155 fLocales = (const Locale **) LE_GROW_ARRAY(fLocales, capacity);
158 le_int32 LocaleRuns::add(const Locale *locale, le_int32 limit)
160 le_int32 index = RunArray::add(limit);
163 Locale **locales = (Locale **) fLocales;
165 locales[index] = (Locale *) locale;
171 const Locale *LocaleRuns::getLocale(le_int32 run) const
173 if (run < 0 || run >= getCount()) {
177 return fLocales[run];
180 const char ValueRuns::fgClassID = 0;
182 ValueRuns::ValueRuns(le_int32 initialCapacity)
183 : RunArray(initialCapacity), fValues(NULL)
185 if (initialCapacity > 0) {
186 fValues = LE_NEW_ARRAY(le_int32, initialCapacity);
190 ValueRuns::~ValueRuns()
192 if (! fClientArrays) {
193 LE_DELETE_ARRAY(fValues);
198 void ValueRuns::init(le_int32 capacity)
200 RunArray::init(capacity);
201 fValues = LE_NEW_ARRAY(le_int32, capacity);
204 void ValueRuns::grow(le_int32 capacity)
206 RunArray::grow(capacity);
207 fValues = (const le_int32 *) LE_GROW_ARRAY(fValues, capacity);
210 le_int32 ValueRuns::add(le_int32 value, le_int32 limit)
212 le_int32 index = RunArray::add(limit);
215 le_int32 *values = (le_int32 *) fValues;
217 values[index] = value;
223 le_int32 ValueRuns::getValue(le_int32 run) const
225 if (run < 0 || run >= getCount()) {