]> git.saurik.com Git - apple/icu.git/blame - icuSources/layoutex/RunArrays.cpp
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / layoutex / RunArrays.cpp
CommitLineData
b75a7d8f
A
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
15U_NAMESPACE_BEGIN
16
17const char RunArray::fgClassID = 0;
18
19le_int32 RunArray::ensureCapacity()
20{
21 if (fCount >= fCapacity) {
22 if (fCapacity == 0) {
23 fCapacity = INITIAL_CAPACITY;
24 init(fCapacity);
25 } else {
26 fCapacity += (fCapacity < CAPACITY_GROW_LIMIT ? fCapacity : CAPACITY_GROW_LIMIT);
27 grow(fCapacity);
28 }
29 }
30
31 return fCount++;
32}
33
34void RunArray::init(le_int32 capacity)
35{
36 fLimits = LE_NEW_ARRAY(le_int32, capacity);
37}
38
39void RunArray::grow(le_int32 newCapacity)
40{
41 fLimits = (le_int32 *) LE_GROW_ARRAY(fLimits, newCapacity);
42}
43
44le_int32 RunArray::add(le_int32 limit)
45{
46 if (fClientArrays) {
47 return -1;
48 }
49
50 le_int32 index = ensureCapacity();
51 le_int32 *limits = (le_int32 *) fLimits;
52
53 limits[index] = limit;
54
55 return index;
56}
57
58const char FontRuns::fgClassID = 0;
59
60void FontRuns::init(le_int32 capacity)
61{
62 RunArray::init(capacity);
63 fFonts = LE_NEW_ARRAY(const LEFontInstance *, capacity);
64}
65
66void FontRuns::grow(le_int32 capacity)
67{
68 RunArray::grow(capacity);
69 fFonts = (const LEFontInstance **) LE_GROW_ARRAY(fFonts, capacity);
70}
71
72le_int32 FontRuns::add(const LEFontInstance *font, le_int32 limit)
73{
74 le_int32 index = RunArray::add(limit);
75
76 if (index >= 0) {
77 LEFontInstance **fonts = (LEFontInstance **) fFonts;
78
79 fonts[index] = (LEFontInstance *) font;
80 }
81
82 return index;
83}
84
85const LEFontInstance *FontRuns::getFont(le_int32 run) const
86{
87 if (run < 0 || run >= getCount()) {
88 return NULL;
89 }
90
91 return fFonts[run];
92}
93
94const char LocaleRuns::fgClassID = 0;
95
96void LocaleRuns::init(le_int32 capacity)
97{
98 RunArray::init(capacity);
99 fLocales = LE_NEW_ARRAY(const Locale *, capacity);
100}
101
102void LocaleRuns::grow(le_int32 capacity)
103{
104 RunArray::grow(capacity);
105 fLocales = (const Locale **) LE_GROW_ARRAY(fLocales, capacity);
106}
107
108le_int32 LocaleRuns::add(const Locale *locale, le_int32 limit)
109{
110 le_int32 index = RunArray::add(limit);
111
112 if (index >= 0) {
113 Locale **locales = (Locale **) fLocales;
114
115 locales[index] = (Locale *) locale;
116 }
117
118 return index;
119}
120
121const Locale *LocaleRuns::getLocale(le_int32 run) const
122{
123 if (run < 0 || run >= getCount()) {
124 return NULL;
125 }
126
127 return fLocales[run];
128}
129
130const char ValueRuns::fgClassID = 0;
131
132void ValueRuns::init(le_int32 capacity)
133{
134 RunArray::init(capacity);
135 fValues = LE_NEW_ARRAY(le_int32, capacity);
136}
137
138void ValueRuns::grow(le_int32 capacity)
139{
140 RunArray::grow(capacity);
141 fValues = (const le_int32 *) LE_GROW_ARRAY(fValues, capacity);
142}
143
144le_int32 ValueRuns::add(le_int32 value, le_int32 limit)
145{
146 le_int32 index = RunArray::add(limit);
147
148 if (index >= 0) {
149 le_int32 *values = (le_int32 *) fValues;
150
151 values[index] = value;
152 }
153
154 return index;
155}
156
157le_int32 ValueRuns::getValue(le_int32 run) const
158{
159 if (run < 0 || run >= getCount()) {
160 return -1;
161 }
162
163 return fValues[run];
164}
165
166U_NAMESPACE_END