1 /* 2 ********************************************************************** 3 * Copyright (C) 2003, International Business Machines 4 * Corporation and others. All Rights Reserved. 5 ********************************************************************** 6 */ 7 8 #include "layout/LETypes.h" 9 #include "layout/LEFontInstance.h" 10 11 #include "unicode/locid.h" 12 13 #include "layout/RunArrays.h" 14 15 U_NAMESPACE_BEGIN 16 17 const char RunArray::fgClassID = 0; 18 19 RunArray::RunArray(le_int32 initialCapacity) 20 : fClientArrays(FALSE), fLimits(NULL), fCount(0), fCapacity(initialCapacity) 21 { 22 if (initialCapacity > 0) { 23 fLimits = LE_NEW_ARRAY(le_int32, fCapacity); 24 } 25 } 26 27 RunArray::~RunArray() 28 { 29 if (! fClientArrays) { 30 LE_DELETE_ARRAY(fLimits); 31 fLimits = NULL; 32 } 33 } 34 35 le_int32 RunArray::ensureCapacity() 36 { 37 if (fCount >= fCapacity) { 38 if (fCapacity == 0) { 39 fCapacity = INITIAL_CAPACITY; 40 init(fCapacity); 41 } else { 42 fCapacity += (fCapacity < CAPACITY_GROW_LIMIT ? fCapacity : CAPACITY_GROW_LIMIT); 43 grow(fCapacity); 44 } 45 } 46 47 return fCount++; 48 } 49 50 void RunArray::init(le_int32 capacity) 51 { 52 fLimits = LE_NEW_ARRAY(le_int32, capacity); 53 } 54 55 void RunArray::grow(le_int32 newCapacity) 56 { 57 fLimits = (le_int32 *) LE_GROW_ARRAY(fLimits, newCapacity); 58 } 59 60 le_int32 RunArray::add(le_int32 limit) 61 { 62 if (fClientArrays) { 63 return -1; 64 } 65 66 le_int32 index = ensureCapacity(); 67 le_int32 *limits = (le_int32 *) fLimits; 68 69 limits[index] = limit; 70 71 return index; 72 } 73 74 const char FontRuns::fgClassID = 0; 75 76 FontRuns::FontRuns(le_int32 initialCapacity) 77 : RunArray(initialCapacity), fFonts(NULL) 78 { 79 if (initialCapacity > 0) { 80 fFonts = LE_NEW_ARRAY(const LEFontInstance *, initialCapacity); 81 } 82 } 83 84 FontRuns::~FontRuns() 85 { 86 if (! fClientArrays) { 87 LE_DELETE_ARRAY(fFonts); 88 fFonts = NULL; 89 } 90 } 91 92 void FontRuns::init(le_int32 capacity) 93 { 94 RunArray::init(capacity); 95 fFonts = LE_NEW_ARRAY(const LEFontInstance *, capacity); 96 } 97 98 void FontRuns::grow(le_int32 capacity) 99 { 100 RunArray::grow(capacity); 101 fFonts = (const LEFontInstance **) LE_GROW_ARRAY(fFonts, capacity); 102 } 103 104 le_int32 FontRuns::add(const LEFontInstance *font, le_int32 limit) 105 { 106 le_int32 index = RunArray::add(limit); 107 108 if (index >= 0) { 109 LEFontInstance **fonts = (LEFontInstance **) fFonts; 110 111 fonts[index] = (LEFontInstance *) font; 112 } 113 114 return index; 115 } 116 117 const LEFontInstance *FontRuns::getFont(le_int32 run) const 118 { 119 if (run < 0 || run >= getCount()) { 120 return NULL; 121 } 122 123 return fFonts[run]; 124 } 125 126 const char LocaleRuns::fgClassID = 0; 127 128 LocaleRuns::LocaleRuns(le_int32 initialCapacity) 129 : RunArray(initialCapacity), fLocales(NULL) 130 { 131 if (initialCapacity > 0) { 132 fLocales = LE_NEW_ARRAY(const Locale *, initialCapacity); 133 } 134 } 135 136 LocaleRuns::~LocaleRuns() 137 { 138 if (! fClientArrays) { 139 LE_DELETE_ARRAY(fLocales); 140 fLocales = NULL; 141 } 142 } 143 144 void LocaleRuns::init(le_int32 capacity) 145 { 146 RunArray::init(capacity); 147 fLocales = LE_NEW_ARRAY(const Locale *, capacity); 148 } 149 150 void LocaleRuns::grow(le_int32 capacity) 151 { 152 RunArray::grow(capacity); 153 fLocales = (const Locale **) LE_GROW_ARRAY(fLocales, capacity); 154 } 155 156 le_int32 LocaleRuns::add(const Locale *locale, le_int32 limit) 157 { 158 le_int32 index = RunArray::add(limit); 159 160 if (index >= 0) { 161 Locale **locales = (Locale **) fLocales; 162 163 locales[index] = (Locale *) locale; 164 } 165 166 return index; 167 } 168 169 const Locale *LocaleRuns::getLocale(le_int32 run) const 170 { 171 if (run < 0 || run >= getCount()) { 172 return NULL; 173 } 174 175 return fLocales[run]; 176 } 177 178 const char ValueRuns::fgClassID = 0; 179 180 ValueRuns::ValueRuns(le_int32 initialCapacity) 181 : RunArray(initialCapacity), fValues(NULL) 182 { 183 if (initialCapacity > 0) { 184 fValues = LE_NEW_ARRAY(le_int32, initialCapacity); 185 } 186 } 187 188 ValueRuns::~ValueRuns() 189 { 190 if (! fClientArrays) { 191 LE_DELETE_ARRAY(fValues); 192 fValues = NULL; 193 } 194 } 195 196 void ValueRuns::init(le_int32 capacity) 197 { 198 RunArray::init(capacity); 199 fValues = LE_NEW_ARRAY(le_int32, capacity); 200 } 201 202 void ValueRuns::grow(le_int32 capacity) 203 { 204 RunArray::grow(capacity); 205 fValues = (const le_int32 *) LE_GROW_ARRAY(fValues, capacity); 206 } 207 208 le_int32 ValueRuns::add(le_int32 value, le_int32 limit) 209 { 210 le_int32 index = RunArray::add(limit); 211 212 if (index >= 0) { 213 le_int32 *values = (le_int32 *) fValues; 214 215 values[index] = value; 216 } 217 218 return index; 219 } 220 221 le_int32 ValueRuns::getValue(le_int32 run) const 222 { 223 if (run < 0 || run >= getCount()) { 224 return -1; 225 } 226 227 return fValues[run]; 228 } 229 230 U_NAMESPACE_END 231