92 |
} |
} |
93 |
} |
} |
94 |
|
|
95 |
|
/** Get the ith line start/end-- counting |
96 |
|
* the beginning and end of the chain. |
97 |
|
*/ |
98 |
|
protected int getLineDivision(int i) { |
99 |
|
if(i == 0) |
100 |
|
return 0; |
101 |
|
else if(i <= length) |
102 |
|
return breaks[i-1]; |
103 |
|
else |
104 |
|
return chain.length(); |
105 |
|
} |
106 |
|
|
107 |
public float getHeight() { |
public float getHeight() { |
108 |
|
return getLineOffset(length); |
109 |
|
} |
110 |
|
|
111 |
|
/** Get the Y position under a given line. |
112 |
|
* If line < 0, return 0. |
113 |
|
*/ |
114 |
|
public float getLineOffset(int line) { |
115 |
|
if(line < 0) return 0; |
116 |
|
|
117 |
float h = 0; |
float h = 0; |
118 |
if(length > 0) { |
if(line > length) throw new IndexOutOfBoundsException(""+line); |
119 |
h += chain.getHeight(0, breaks[0], scale); |
|
120 |
for(int i=1; i<length; i++) |
for(int i=0; i<=line; i++) |
121 |
h += chain.getHeight(breaks[i-1], breaks[i], scale); |
h += chain.getHeight(getLineDivision(i), |
122 |
h += chain.getHeight(breaks[length-1], chain.length(), scale); |
getLineDivision(i+1), scale); |
|
} else { |
|
|
h = chain.getHeight(0, chain.length(), scale); |
|
|
} |
|
123 |
|
|
124 |
return h; |
return h; |
125 |
} |
} |
126 |
|
|
127 |
|
/** Get the number of lines. |
128 |
|
*/ |
129 |
|
public int getLineCount() { |
130 |
|
return length+1; |
131 |
|
} |
132 |
|
|
133 |
|
public float getLineWidth(int line) { |
134 |
|
if(line >= (length+1)) |
135 |
|
throw new IndexOutOfBoundsException(line+"; line count is "+ |
136 |
|
(length+1)); |
137 |
|
|
138 |
|
float result = 0; |
139 |
|
int start = getLineDivision(line), |
140 |
|
end = getLineDivision(line+1); |
141 |
|
|
142 |
|
for(int i=start; i<end; i++) |
143 |
|
result += chain.getBox(i).getWidth(scale); |
144 |
|
|
145 |
|
return result; |
146 |
|
} |
147 |
|
|
148 |
|
/** Get the line a given character is at. |
149 |
|
* Additionally, if passed an array |
150 |
|
* as the second parameter, return |
151 |
|
* the x offset before the character. |
152 |
|
* Passing a pos one more than the last |
153 |
|
* character is valid. |
154 |
|
*/ |
155 |
|
public int getLine(int pos, float[] xoffs) { |
156 |
|
int i=0, n=0; |
157 |
|
while(true) { |
158 |
|
if(i >= chain.length()) { |
159 |
|
if(xoffs != null) { |
160 |
|
xoffs[0] = getLineWidth(length); |
161 |
|
} |
162 |
|
return length; |
163 |
|
} |
164 |
|
|
165 |
|
int l = chain.getBox(i).getLength(); |
166 |
|
if(n+l > pos) break; |
167 |
|
n += l; |
168 |
|
i++; |
169 |
|
} |
170 |
|
|
171 |
|
int line=0; |
172 |
|
while(getLineDivision(line+1) <= i) line++; |
173 |
|
|
174 |
|
if(xoffs != null) { |
175 |
|
xoffs[0] = 0; |
176 |
|
for(int j=getLineDivision(line); j<i; j++) |
177 |
|
xoffs[0] += chain.getBox(j).getWidth(scale); |
178 |
|
|
179 |
|
xoffs[0] += chain.getBox(i).getX(pos-n, scale); |
180 |
|
} |
181 |
|
|
182 |
|
return line; |
183 |
|
} |
184 |
} |
} |