blob: cdff395a3fa91a8f9a1acb5488c7387c6735f37e [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.text;
18
Raph Levien531c30c2015-04-30 16:29:59 -070019import android.annotation.Nullable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.graphics.Paint;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.text.style.LeadingMarginSpan;
Gilles Debunne66111472010-11-19 11:04:37 -080022import android.text.style.LeadingMarginSpan.LeadingMarginSpan2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.text.style.LineHeightSpan;
24import android.text.style.MetricAffectingSpan;
Doug Feltc982f602010-05-25 11:51:40 -070025import android.text.style.TabStopSpan;
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -070026import android.util.Log;
Raph Levien39b4db72015-03-25 13:18:20 -070027import android.util.Pools.SynchronizedPool;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028
Doug Feltcb3791202011-07-07 11:57:48 -070029import com.android.internal.util.ArrayUtils;
Adam Lesinski776abc22014-03-07 11:30:59 -050030import com.android.internal.util.GrowingArrayUtils;
Doug Feltcb3791202011-07-07 11:57:48 -070031
Anish Athalyec8f9e622014-07-21 15:26:34 -070032import java.util.Arrays;
Raph Levien4c1f12e2015-03-02 16:29:23 -080033import java.util.Locale;
Anish Athalyec8f9e622014-07-21 15:26:34 -070034
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035/**
36 * StaticLayout is a Layout for text that will not be edited after it
37 * is laid out. Use {@link DynamicLayout} for text that may change.
38 * <p>This is used by widgets to control text layout. You should not need
39 * to use this class directly unless you are implementing your own widget
40 * or custom display object, or would be tempted to call
Doug Felt4e0c5e52010-03-15 16:56:02 -070041 * {@link android.graphics.Canvas#drawText(java.lang.CharSequence, int, int,
42 * float, float, android.graphics.Paint)
43 * Canvas.drawText()} directly.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 */
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -080045public class StaticLayout extends Layout {
46
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -070047 static final String TAG = "StaticLayout";
48
Raph Leviend3ab6922015-03-02 14:30:53 -080049 /**
Raph Levien531c30c2015-04-30 16:29:59 -070050 * Builder for static layouts. The builder is a newer pattern for constructing
51 * StaticLayout objects and should be preferred over the constructors,
52 * particularly to access newer features. To build a static layout, first
53 * call {@link #obtain} with the required arguments (text, paint, and width),
54 * then call setters for optional parameters, and finally {@link #build}
55 * to build the StaticLayout object. Parameters not explicitly set will get
56 * default values.
Raph Leviend3ab6922015-03-02 14:30:53 -080057 */
58 public final static class Builder {
Raph Levien4c1f12e2015-03-02 16:29:23 -080059 private Builder() {
60 mNativePtr = nNewBuilder();
61 }
62
Raph Levien531c30c2015-04-30 16:29:59 -070063 /**
64 * Obtain a builder for constructing StaticLayout objects
65 *
66 * @param source The text to be laid out, optionally with spans
67 * @param start The index of the start of the text
68 * @param end The index + 1 of the end of the text
69 * @param paint The base paint used for layout
70 * @param width The width in pixels
71 * @return a builder object used for constructing the StaticLayout
72 */
Raph Levienebd66ca2015-04-30 15:27:57 -070073 public static Builder obtain(CharSequence source, int start, int end, TextPaint paint,
74 int width) {
Raph Levien39b4db72015-03-25 13:18:20 -070075 Builder b = sPool.acquire();
Raph Leviend3ab6922015-03-02 14:30:53 -080076 if (b == null) {
77 b = new Builder();
78 }
79
80 // set default initial values
Raph Levien39b4db72015-03-25 13:18:20 -070081 b.mText = source;
82 b.mStart = start;
83 b.mEnd = end;
Raph Levienebd66ca2015-04-30 15:27:57 -070084 b.mPaint = paint;
Raph Levien39b4db72015-03-25 13:18:20 -070085 b.mWidth = width;
86 b.mAlignment = Alignment.ALIGN_NORMAL;
Raph Leviend3ab6922015-03-02 14:30:53 -080087 b.mTextDir = TextDirectionHeuristics.FIRSTSTRONG_LTR;
88 b.mSpacingMult = 1.0f;
89 b.mSpacingAdd = 0.0f;
90 b.mIncludePad = true;
Raph Levien39b4db72015-03-25 13:18:20 -070091 b.mEllipsizedWidth = width;
Raph Leviend3ab6922015-03-02 14:30:53 -080092 b.mEllipsize = null;
93 b.mMaxLines = Integer.MAX_VALUE;
Raph Levien3bd60c72015-05-06 14:26:35 -070094 b.mBreakStrategy = Layout.BREAK_STRATEGY_SIMPLE;
Roozbeh Pournader95c7a132015-05-12 12:01:06 -070095 b.mHyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE;
Raph Leviend3ab6922015-03-02 14:30:53 -080096
97 b.mMeasuredText = MeasuredText.obtain();
98 return b;
99 }
100
Raph Levien39b4db72015-03-25 13:18:20 -0700101 private static void recycle(Builder b) {
Raph Leviend3ab6922015-03-02 14:30:53 -0800102 b.mPaint = null;
103 b.mText = null;
104 MeasuredText.recycle(b.mMeasuredText);
Raph Levien3bd60c72015-05-06 14:26:35 -0700105 b.mMeasuredText = null;
Raph Levien2ea52902015-07-01 14:39:31 -0700106 b.mLeftIndents = null;
107 b.mRightIndents = null;
Raph Levien3bd60c72015-05-06 14:26:35 -0700108 nFinishBuilder(b.mNativePtr);
Raph Levien39b4db72015-03-25 13:18:20 -0700109 sPool.release(b);
Raph Leviend3ab6922015-03-02 14:30:53 -0800110 }
111
112 // release any expensive state
113 /* package */ void finish() {
Raph Levien4c1f12e2015-03-02 16:29:23 -0800114 nFinishBuilder(mNativePtr);
Raph Leviend3ab6922015-03-02 14:30:53 -0800115 mMeasuredText.finish();
116 }
117
118 public Builder setText(CharSequence source) {
119 return setText(source, 0, source.length());
120 }
121
Raph Levien531c30c2015-04-30 16:29:59 -0700122 /**
123 * Set the text. Only useful when re-using the builder, which is done for
124 * the internal implementation of {@link DynamicLayout} but not as part
125 * of normal {@link StaticLayout} usage.
126 *
127 * @param source The text to be laid out, optionally with spans
128 * @param start The index of the start of the text
129 * @param end The index + 1 of the end of the text
130 * @return this builder, useful for chaining
131 *
132 * @hide
133 */
Raph Leviend3ab6922015-03-02 14:30:53 -0800134 public Builder setText(CharSequence source, int start, int end) {
135 mText = source;
136 mStart = start;
137 mEnd = end;
138 return this;
139 }
140
Raph Levien531c30c2015-04-30 16:29:59 -0700141 /**
142 * Set the paint. Internal for reuse cases only.
143 *
144 * @param paint The base paint used for layout
145 * @return this builder, useful for chaining
146 *
147 * @hide
148 */
Raph Leviend3ab6922015-03-02 14:30:53 -0800149 public Builder setPaint(TextPaint paint) {
150 mPaint = paint;
151 return this;
152 }
153
Raph Levien531c30c2015-04-30 16:29:59 -0700154 /**
155 * Set the width. Internal for reuse cases only.
156 *
157 * @param width The width in pixels
158 * @return this builder, useful for chaining
159 *
160 * @hide
161 */
Raph Leviend3ab6922015-03-02 14:30:53 -0800162 public Builder setWidth(int width) {
163 mWidth = width;
164 if (mEllipsize == null) {
165 mEllipsizedWidth = width;
166 }
167 return this;
168 }
169
Raph Levien531c30c2015-04-30 16:29:59 -0700170 /**
171 * Set the alignment. The default is {@link Layout.Alignment#ALIGN_NORMAL}.
172 *
173 * @param alignment Alignment for the resulting {@link StaticLayout}
174 * @return this builder, useful for chaining
175 */
Raph Levien39b4db72015-03-25 13:18:20 -0700176 public Builder setAlignment(Alignment alignment) {
177 mAlignment = alignment;
178 return this;
179 }
180
Raph Levien531c30c2015-04-30 16:29:59 -0700181 /**
182 * Set the text direction heuristic. The text direction heuristic is used to
183 * resolve text direction based per-paragraph based on the input text. The default is
184 * {@link TextDirectionHeuristics#FIRSTSTRONG_LTR}.
185 *
186 * @param textDir text direction heuristic for resolving BiDi behavior.
187 * @return this builder, useful for chaining
188 */
Raph Leviena6a08282015-06-03 13:20:45 -0700189 public Builder setTextDirection(TextDirectionHeuristic textDir) {
Raph Leviend3ab6922015-03-02 14:30:53 -0800190 mTextDir = textDir;
191 return this;
192 }
193
Raph Levien531c30c2015-04-30 16:29:59 -0700194 /**
195 * Set line spacing parameters. The default is 0.0 for {@code spacingAdd}
196 * and 1.0 for {@code spacingMult}.
197 *
198 * @param spacingAdd line spacing add
199 * @param spacingMult line spacing multiplier
200 * @return this builder, useful for chaining
201 * @see android.widget.TextView#setLineSpacing
202 */
203 public Builder setLineSpacing(float spacingAdd, float spacingMult) {
204 mSpacingAdd = spacingAdd;
Raph Leviend3ab6922015-03-02 14:30:53 -0800205 mSpacingMult = spacingMult;
206 return this;
207 }
208
Raph Levien531c30c2015-04-30 16:29:59 -0700209 /**
210 * Set whether to include extra space beyond font ascent and descent (which is
211 * needed to avoid clipping in some languages, such as Arabic and Kannada). The
212 * default is {@code true}.
213 *
214 * @param includePad whether to include padding
215 * @return this builder, useful for chaining
216 * @see android.widget.TextView#setIncludeFontPadding
217 */
Raph Leviend3ab6922015-03-02 14:30:53 -0800218 public Builder setIncludePad(boolean includePad) {
219 mIncludePad = includePad;
220 return this;
221 }
222
Raph Levien531c30c2015-04-30 16:29:59 -0700223 /**
224 * Set the width as used for ellipsizing purposes, if it differs from the
225 * normal layout width. The default is the {@code width}
226 * passed to {@link #obtain}.
227 *
228 * @param ellipsizedWidth width used for ellipsizing, in pixels
229 * @return this builder, useful for chaining
230 * @see android.widget.TextView#setEllipsize
231 */
Raph Leviend3ab6922015-03-02 14:30:53 -0800232 public Builder setEllipsizedWidth(int ellipsizedWidth) {
233 mEllipsizedWidth = ellipsizedWidth;
234 return this;
235 }
236
Raph Levien531c30c2015-04-30 16:29:59 -0700237 /**
238 * Set ellipsizing on the layout. Causes words that are longer than the view
239 * is wide, or exceeding the number of lines (see #setMaxLines) in the case
240 * of {@link android.text.TextUtils.TruncateAt#END} or
241 * {@link android.text.TextUtils.TruncateAt#MARQUEE}, to be ellipsized instead
242 * of broken. The default is
243 * {@code null}, indicating no ellipsis is to be applied.
244 *
245 * @param ellipsize type of ellipsis behavior
246 * @return this builder, useful for chaining
247 * @see android.widget.TextView#setEllipsize
248 */
249 public Builder setEllipsize(@Nullable TextUtils.TruncateAt ellipsize) {
Raph Leviend3ab6922015-03-02 14:30:53 -0800250 mEllipsize = ellipsize;
251 return this;
252 }
253
Raph Levien531c30c2015-04-30 16:29:59 -0700254 /**
255 * Set maximum number of lines. This is particularly useful in the case of
256 * ellipsizing, where it changes the layout of the last line. The default is
257 * unlimited.
258 *
259 * @param maxLines maximum number of lines in the layout
260 * @return this builder, useful for chaining
261 * @see android.widget.TextView#setMaxLines
262 */
Raph Leviend3ab6922015-03-02 14:30:53 -0800263 public Builder setMaxLines(int maxLines) {
264 mMaxLines = maxLines;
265 return this;
266 }
267
Raph Levien531c30c2015-04-30 16:29:59 -0700268 /**
269 * Set break strategy, useful for selecting high quality or balanced paragraph
270 * layout options. The default is {@link Layout#BREAK_STRATEGY_SIMPLE}.
271 *
272 * @param breakStrategy break strategy for paragraph layout
273 * @return this builder, useful for chaining
274 * @see android.widget.TextView#setBreakStrategy
275 */
Raph Levien39b4db72015-03-25 13:18:20 -0700276 public Builder setBreakStrategy(@BreakStrategy int breakStrategy) {
277 mBreakStrategy = breakStrategy;
278 return this;
279 }
280
Raph Levien531c30c2015-04-30 16:29:59 -0700281 /**
Roozbeh Pournader95c7a132015-05-12 12:01:06 -0700282 * Set hyphenation frequency, to control the amount of automatic hyphenation used. The
283 * default is {@link Layout#HYPHENATION_FREQUENCY_NONE}.
284 *
285 * @param hyphenationFrequency hyphenation frequency for the paragraph
286 * @return this builder, useful for chaining
287 * @see android.widget.TextView#setHyphenationFrequency
288 */
289 public Builder setHyphenationFrequency(@HyphenationFrequency int hyphenationFrequency) {
290 mHyphenationFrequency = hyphenationFrequency;
291 return this;
292 }
293
294 /**
Raph Levien531c30c2015-04-30 16:29:59 -0700295 * Set indents. Arguments are arrays holding an indent amount, one per line, measured in
296 * pixels. For lines past the last element in the array, the last element repeats.
297 *
298 * @param leftIndents array of indent values for left margin, in pixels
299 * @param rightIndents array of indent values for right margin, in pixels
300 * @return this builder, useful for chaining
Raph Levien531c30c2015-04-30 16:29:59 -0700301 */
Raph Leviene319d5a2015-04-14 23:51:07 -0700302 public Builder setIndents(int[] leftIndents, int[] rightIndents) {
Raph Levien2ea52902015-07-01 14:39:31 -0700303 mLeftIndents = leftIndents;
304 mRightIndents = rightIndents;
Raph Leviene319d5a2015-04-14 23:51:07 -0700305 int leftLen = leftIndents == null ? 0 : leftIndents.length;
306 int rightLen = rightIndents == null ? 0 : rightIndents.length;
307 int[] indents = new int[Math.max(leftLen, rightLen)];
308 for (int i = 0; i < indents.length; i++) {
309 int leftMargin = i < leftLen ? leftIndents[i] : 0;
310 int rightMargin = i < rightLen ? rightIndents[i] : 0;
311 indents[i] = leftMargin + rightMargin;
312 }
313 nSetIndents(mNativePtr, indents);
314 return this;
315 }
316
Raph Levien70616ec2015-03-04 10:41:30 -0800317 /**
318 * Measurement and break iteration is done in native code. The protocol for using
319 * the native code is as follows.
320 *
Raph Levien26d443a2015-03-30 14:18:32 -0700321 * For each paragraph, do a nSetupParagraph, which sets paragraph text, line width, tab
Roozbeh Pournader95c7a132015-05-12 12:01:06 -0700322 * stops, break strategy, and hyphenation frequency (and possibly other parameters in the
323 * future).
Raph Levienc94f7422015-03-06 19:19:48 -0800324 *
325 * Then, for each run within the paragraph:
Raph Levien70616ec2015-03-04 10:41:30 -0800326 * - setLocale (this must be done at least for the first run, optional afterwards)
327 * - one of the following, depending on the type of run:
328 * + addStyleRun (a text run, to be measured in native code)
329 * + addMeasuredRun (a run already measured in Java, passed into native code)
330 * + addReplacementRun (a replacement run, width is given)
331 *
332 * After measurement, nGetWidths() is valid if the widths are needed (eg for ellipsis).
333 * Run nComputeLineBreaks() to obtain line breaks for the paragraph.
334 *
335 * After all paragraphs, call finish() to release expensive buffers.
336 */
337
338 private void setLocale(Locale locale) {
Raph Levien4c1f12e2015-03-02 16:29:23 -0800339 if (!locale.equals(mLocale)) {
Raph Levien26d443a2015-03-30 14:18:32 -0700340 nSetLocale(mNativePtr, locale.toLanguageTag(), Hyphenator.get(locale));
Raph Levien4c1f12e2015-03-02 16:29:23 -0800341 mLocale = locale;
342 }
343 }
344
Raph Levien70616ec2015-03-04 10:41:30 -0800345 /* package */ float addStyleRun(TextPaint paint, int start, int end, boolean isRtl) {
346 return nAddStyleRun(mNativePtr, paint.getNativeInstance(), paint.mNativeTypeface,
347 start, end, isRtl);
348 }
349
350 /* package */ void addMeasuredRun(int start, int end, float[] widths) {
351 nAddMeasuredRun(mNativePtr, start, end, widths);
352 }
353
354 /* package */ void addReplacementRun(int start, int end, float width) {
355 nAddReplacementRun(mNativePtr, start, end, width);
356 }
357
Raph Levien531c30c2015-04-30 16:29:59 -0700358 /**
359 * Build the {@link StaticLayout} after options have been set.
360 *
361 * <p>Note: the builder object must not be reused in any way after calling this
362 * method. Setting parameters after calling this method, or calling it a second
363 * time on the same builder object, will likely lead to unexpected results.
364 *
365 * @return the newly constructed {@link StaticLayout} object
366 */
Raph Leviend3ab6922015-03-02 14:30:53 -0800367 public StaticLayout build() {
Raph Levien39b4db72015-03-25 13:18:20 -0700368 StaticLayout result = new StaticLayout(this);
369 Builder.recycle(this);
Raph Leviend3ab6922015-03-02 14:30:53 -0800370 return result;
371 }
372
Raph Levien4c1f12e2015-03-02 16:29:23 -0800373 @Override
374 protected void finalize() throws Throwable {
375 try {
376 nFreeBuilder(mNativePtr);
377 } finally {
378 super.finalize();
379 }
380 }
381
382 /* package */ long mNativePtr;
383
Raph Leviend3ab6922015-03-02 14:30:53 -0800384 CharSequence mText;
385 int mStart;
386 int mEnd;
387 TextPaint mPaint;
388 int mWidth;
Raph Levien39b4db72015-03-25 13:18:20 -0700389 Alignment mAlignment;
Raph Leviend3ab6922015-03-02 14:30:53 -0800390 TextDirectionHeuristic mTextDir;
391 float mSpacingMult;
392 float mSpacingAdd;
393 boolean mIncludePad;
394 int mEllipsizedWidth;
395 TextUtils.TruncateAt mEllipsize;
396 int mMaxLines;
Raph Levien39b4db72015-03-25 13:18:20 -0700397 int mBreakStrategy;
Roozbeh Pournader95c7a132015-05-12 12:01:06 -0700398 int mHyphenationFrequency;
Raph Levien2ea52902015-07-01 14:39:31 -0700399 int[] mLeftIndents;
400 int[] mRightIndents;
Raph Leviend3ab6922015-03-02 14:30:53 -0800401
402 Paint.FontMetricsInt mFontMetricsInt = new Paint.FontMetricsInt();
403
404 // This will go away and be subsumed by native builder code
405 MeasuredText mMeasuredText;
406
Raph Levien4c1f12e2015-03-02 16:29:23 -0800407 Locale mLocale;
408
Raph Levien39b4db72015-03-25 13:18:20 -0700409 private static final SynchronizedPool<Builder> sPool = new SynchronizedPool<Builder>(3);
Raph Leviend3ab6922015-03-02 14:30:53 -0800410 }
411
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412 public StaticLayout(CharSequence source, TextPaint paint,
413 int width,
414 Alignment align, float spacingmult, float spacingadd,
415 boolean includepad) {
416 this(source, 0, source.length(), paint, width, align,
417 spacingmult, spacingadd, includepad);
418 }
419
Doug Feltcb3791202011-07-07 11:57:48 -0700420 /**
421 * @hide
422 */
423 public StaticLayout(CharSequence source, TextPaint paint,
424 int width, Alignment align, TextDirectionHeuristic textDir,
425 float spacingmult, float spacingadd,
426 boolean includepad) {
427 this(source, 0, source.length(), paint, width, align, textDir,
428 spacingmult, spacingadd, includepad);
429 }
430
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 public StaticLayout(CharSequence source, int bufstart, int bufend,
432 TextPaint paint, int outerwidth,
433 Alignment align,
434 float spacingmult, float spacingadd,
435 boolean includepad) {
436 this(source, bufstart, bufend, paint, outerwidth, align,
437 spacingmult, spacingadd, includepad, null, 0);
438 }
439
Doug Feltcb3791202011-07-07 11:57:48 -0700440 /**
441 * @hide
442 */
443 public StaticLayout(CharSequence source, int bufstart, int bufend,
444 TextPaint paint, int outerwidth,
445 Alignment align, TextDirectionHeuristic textDir,
446 float spacingmult, float spacingadd,
447 boolean includepad) {
448 this(source, bufstart, bufend, paint, outerwidth, align, textDir,
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -0700449 spacingmult, spacingadd, includepad, null, 0, Integer.MAX_VALUE);
Doug Feltcb3791202011-07-07 11:57:48 -0700450}
451
452 public StaticLayout(CharSequence source, int bufstart, int bufend,
453 TextPaint paint, int outerwidth,
454 Alignment align,
455 float spacingmult, float spacingadd,
456 boolean includepad,
457 TextUtils.TruncateAt ellipsize, int ellipsizedWidth) {
458 this(source, bufstart, bufend, paint, outerwidth, align,
459 TextDirectionHeuristics.FIRSTSTRONG_LTR,
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -0700460 spacingmult, spacingadd, includepad, ellipsize, ellipsizedWidth, Integer.MAX_VALUE);
Doug Feltcb3791202011-07-07 11:57:48 -0700461 }
462
463 /**
464 * @hide
465 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800466 public StaticLayout(CharSequence source, int bufstart, int bufend,
467 TextPaint paint, int outerwidth,
Doug Feltcb3791202011-07-07 11:57:48 -0700468 Alignment align, TextDirectionHeuristic textDir,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 float spacingmult, float spacingadd,
470 boolean includepad,
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -0700471 TextUtils.TruncateAt ellipsize, int ellipsizedWidth, int maxLines) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 super((ellipsize == null)
Doug Felt4e0c5e52010-03-15 16:56:02 -0700473 ? source
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474 : (source instanceof Spanned)
475 ? new SpannedEllipsizer(source)
476 : new Ellipsizer(source),
Doug Feltcb3791202011-07-07 11:57:48 -0700477 paint, outerwidth, align, textDir, spacingmult, spacingadd);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478
Raph Levienebd66ca2015-04-30 15:27:57 -0700479 Builder b = Builder.obtain(source, bufstart, bufend, paint, outerwidth)
Raph Levien39b4db72015-03-25 13:18:20 -0700480 .setAlignment(align)
Raph Leviena6a08282015-06-03 13:20:45 -0700481 .setTextDirection(textDir)
Raph Levien531c30c2015-04-30 16:29:59 -0700482 .setLineSpacing(spacingadd, spacingmult)
Raph Leviend3ab6922015-03-02 14:30:53 -0800483 .setIncludePad(includepad)
484 .setEllipsizedWidth(ellipsizedWidth)
485 .setEllipsize(ellipsize)
486 .setMaxLines(maxLines);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 /*
488 * This is annoying, but we can't refer to the layout until
489 * superclass construction is finished, and the superclass
490 * constructor wants the reference to the display text.
Doug Felt4e0c5e52010-03-15 16:56:02 -0700491 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 * This will break if the superclass constructor ever actually
493 * cares about the content instead of just holding the reference.
494 */
495 if (ellipsize != null) {
496 Ellipsizer e = (Ellipsizer) getText();
497
498 e.mLayout = this;
499 e.mWidth = ellipsizedWidth;
500 e.mMethod = ellipsize;
501 mEllipsizedWidth = ellipsizedWidth;
502
503 mColumns = COLUMNS_ELLIPSIZE;
504 } else {
505 mColumns = COLUMNS_NORMAL;
506 mEllipsizedWidth = outerwidth;
507 }
508
Adam Lesinski776abc22014-03-07 11:30:59 -0500509 mLineDirections = ArrayUtils.newUnpaddedArray(Directions.class, 2 * mColumns);
510 mLines = new int[mLineDirections.length];
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -0700511 mMaximumVisibleLineCount = maxLines;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512
Raph Levien70616ec2015-03-04 10:41:30 -0800513 generate(b, b.mIncludePad, b.mIncludePad);
Doug Felte8e45f22010-03-29 14:58:40 -0700514
Raph Leviend3ab6922015-03-02 14:30:53 -0800515 Builder.recycle(b);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 }
517
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -0700518 /* package */ StaticLayout(CharSequence text) {
519 super(text, null, 0, null, 0, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520
521 mColumns = COLUMNS_ELLIPSIZE;
Adam Lesinski776abc22014-03-07 11:30:59 -0500522 mLineDirections = ArrayUtils.newUnpaddedArray(Directions.class, 2 * mColumns);
523 mLines = new int[mLineDirections.length];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800524 }
525
Raph Levien39b4db72015-03-25 13:18:20 -0700526 private StaticLayout(Builder b) {
527 super((b.mEllipsize == null)
528 ? b.mText
529 : (b.mText instanceof Spanned)
530 ? new SpannedEllipsizer(b.mText)
531 : new Ellipsizer(b.mText),
532 b.mPaint, b.mWidth, b.mAlignment, b.mSpacingMult, b.mSpacingAdd);
533
534 if (b.mEllipsize != null) {
535 Ellipsizer e = (Ellipsizer) getText();
536
537 e.mLayout = this;
538 e.mWidth = b.mEllipsizedWidth;
539 e.mMethod = b.mEllipsize;
540 mEllipsizedWidth = b.mEllipsizedWidth;
541
542 mColumns = COLUMNS_ELLIPSIZE;
543 } else {
544 mColumns = COLUMNS_NORMAL;
545 mEllipsizedWidth = b.mWidth;
546 }
547
548 mLineDirections = ArrayUtils.newUnpaddedArray(Directions.class, 2 * mColumns);
549 mLines = new int[mLineDirections.length];
550 mMaximumVisibleLineCount = b.mMaxLines;
551
Raph Levien2ea52902015-07-01 14:39:31 -0700552 mLeftIndents = b.mLeftIndents;
553 mRightIndents = b.mRightIndents;
554
Raph Levien39b4db72015-03-25 13:18:20 -0700555 generate(b, b.mIncludePad, b.mIncludePad);
556 }
557
Raph Leviend3ab6922015-03-02 14:30:53 -0800558 /* package */ void generate(Builder b, boolean includepad, boolean trackpad) {
559 CharSequence source = b.mText;
560 int bufStart = b.mStart;
561 int bufEnd = b.mEnd;
562 TextPaint paint = b.mPaint;
563 int outerWidth = b.mWidth;
564 TextDirectionHeuristic textDir = b.mTextDir;
565 float spacingmult = b.mSpacingMult;
566 float spacingadd = b.mSpacingAdd;
567 float ellipsizedWidth = b.mEllipsizedWidth;
568 TextUtils.TruncateAt ellipsize = b.mEllipsize;
Raph Levien4c1f12e2015-03-02 16:29:23 -0800569 LineBreaks lineBreaks = new LineBreaks(); // TODO: move to builder to avoid allocation costs
Anish Athalyec8f9e622014-07-21 15:26:34 -0700570 // store span end locations
571 int[] spanEndCache = new int[4];
572 // store fontMetrics per span range
573 // must be a multiple of 4 (and > 0) (store top, bottom, ascent, and descent per range)
574 int[] fmCache = new int[4 * 4];
Raph Levien4c1f12e2015-03-02 16:29:23 -0800575 b.setLocale(paint.getTextLocale()); // TODO: also respect LocaleSpan within the text
Anish Athalye88b5b0b2014-06-24 14:39:43 -0700576
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 mLineCount = 0;
578
579 int v = 0;
580 boolean needMultiply = (spacingmult != 1 || spacingadd != 0);
581
Raph Leviend3ab6922015-03-02 14:30:53 -0800582 Paint.FontMetricsInt fm = b.mFontMetricsInt;
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800583 int[] chooseHtv = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584
Raph Leviend3ab6922015-03-02 14:30:53 -0800585 MeasuredText measured = b.mMeasuredText;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 Spanned spanned = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 if (source instanceof Spanned)
589 spanned = (Spanned) source;
590
Doug Felte8e45f22010-03-29 14:58:40 -0700591 int paraEnd;
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800592 for (int paraStart = bufStart; paraStart <= bufEnd; paraStart = paraEnd) {
593 paraEnd = TextUtils.indexOf(source, CHAR_NEW_LINE, paraStart, bufEnd);
Doug Felte8e45f22010-03-29 14:58:40 -0700594 if (paraEnd < 0)
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800595 paraEnd = bufEnd;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596 else
Doug Felte8e45f22010-03-29 14:58:40 -0700597 paraEnd++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800598
Anish Athalyec8f9e622014-07-21 15:26:34 -0700599 int firstWidthLineCount = 1;
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800600 int firstWidth = outerWidth;
601 int restWidth = outerWidth;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800602
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800603 LineHeightSpan[] chooseHt = null;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800604
605 if (spanned != null) {
Eric Fischer74d31ef2010-08-05 15:29:36 -0700606 LeadingMarginSpan[] sp = getParagraphSpans(spanned, paraStart, paraEnd,
Doug Felte8e45f22010-03-29 14:58:40 -0700607 LeadingMarginSpan.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 for (int i = 0; i < sp.length; i++) {
Mark Wagner7b5676e2009-10-16 11:44:23 -0700609 LeadingMarginSpan lms = sp[i];
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800610 firstWidth -= sp[i].getLeadingMargin(true);
611 restWidth -= sp[i].getLeadingMargin(false);
Doug Feltcb3791202011-07-07 11:57:48 -0700612
Doug Feltc982f602010-05-25 11:51:40 -0700613 // LeadingMarginSpan2 is odd. The count affects all
Anish Athalyeab08c6d2014-08-08 12:09:58 -0700614 // leading margin spans, not just this particular one
Doug Feltc982f602010-05-25 11:51:40 -0700615 if (lms instanceof LeadingMarginSpan2) {
616 LeadingMarginSpan2 lms2 = (LeadingMarginSpan2) lms;
Anish Athalyec8f9e622014-07-21 15:26:34 -0700617 firstWidthLineCount = Math.max(firstWidthLineCount,
618 lms2.getLeadingMarginLineCount());
Mark Wagner7b5676e2009-10-16 11:44:23 -0700619 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620 }
621
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800622 chooseHt = getParagraphSpans(spanned, paraStart, paraEnd, LineHeightSpan.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800624 if (chooseHt.length != 0) {
625 if (chooseHtv == null ||
626 chooseHtv.length < chooseHt.length) {
Adam Lesinski776abc22014-03-07 11:30:59 -0500627 chooseHtv = ArrayUtils.newUnpaddedIntArray(chooseHt.length);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628 }
629
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800630 for (int i = 0; i < chooseHt.length; i++) {
631 int o = spanned.getSpanStart(chooseHt[i]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632
Doug Felte8e45f22010-03-29 14:58:40 -0700633 if (o < paraStart) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800634 // starts in this layout, before the
635 // current paragraph
636
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800637 chooseHtv[i] = getLineTop(getLineForOffset(o));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800638 } else {
639 // starts in this paragraph
640
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800641 chooseHtv[i] = v;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 }
643 }
644 }
645 }
646
Raph Levien70616ec2015-03-04 10:41:30 -0800647 measured.setPara(source, paraStart, paraEnd, textDir, b);
Doug Felte8e45f22010-03-29 14:58:40 -0700648 char[] chs = measured.mChars;
649 float[] widths = measured.mWidths;
650 byte[] chdirs = measured.mLevels;
651 int dir = measured.mDir;
652 boolean easy = measured.mEasy;
Raph Levienc94f7422015-03-06 19:19:48 -0800653
654 // tab stop locations
655 int[] variableTabStops = null;
656 if (spanned != null) {
657 TabStopSpan[] spans = getParagraphSpans(spanned, paraStart,
658 paraEnd, TabStopSpan.class);
659 if (spans.length > 0) {
660 int[] stops = new int[spans.length];
661 for (int i = 0; i < spans.length; i++) {
662 stops[i] = spans[i].getTabStop();
663 }
664 Arrays.sort(stops, 0, stops.length);
665 variableTabStops = stops;
666 }
667 }
668
Raph Levienc94f7422015-03-06 19:19:48 -0800669 nSetupParagraph(b.mNativePtr, chs, paraEnd - paraStart,
670 firstWidth, firstWidthLineCount, restWidth,
Roozbeh Pournader95c7a132015-05-12 12:01:06 -0700671 variableTabStops, TAB_INCREMENT, b.mBreakStrategy, b.mHyphenationFrequency);
Raph Levien2ea52902015-07-01 14:39:31 -0700672 if (mLeftIndents != null || mRightIndents != null) {
673 // TODO(raph) performance: it would be better to do this once per layout rather
674 // than once per paragraph, but that would require a change to the native
675 // interface.
676 int leftLen = mLeftIndents == null ? 0 : mLeftIndents.length;
677 int rightLen = mRightIndents == null ? 0 : mRightIndents.length;
678 int indentsLen = Math.max(1, Math.min(leftLen, rightLen) - mLineCount);
679 int[] indents = new int[indentsLen];
680 for (int i = 0; i < indentsLen; i++) {
681 int leftMargin = mLeftIndents == null ? 0 :
682 mLeftIndents[Math.min(i + mLineCount, leftLen - 1)];
683 int rightMargin = mRightIndents == null ? 0 :
684 mRightIndents[Math.min(i + mLineCount, rightLen - 1)];
685 indents[i] = leftMargin + rightMargin;
686 }
687 nSetIndents(b.mNativePtr, indents);
688 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800689
Anish Athalyec8f9e622014-07-21 15:26:34 -0700690 // measurement has to be done before performing line breaking
691 // but we don't want to recompute fontmetrics or span ranges the
692 // second time, so we cache those and then use those stored values
693 int fmCacheCount = 0;
694 int spanEndCacheCount = 0;
Gilles Debunnecd943a72012-06-07 17:54:47 -0700695 for (int spanStart = paraStart, spanEnd; spanStart < paraEnd; spanStart = spanEnd) {
Anish Athalyec8f9e622014-07-21 15:26:34 -0700696 if (fmCacheCount * 4 >= fmCache.length) {
697 int[] grow = new int[fmCacheCount * 4 * 2];
698 System.arraycopy(fmCache, 0, grow, 0, fmCacheCount * 4);
699 fmCache = grow;
700 }
701
702 if (spanEndCacheCount >= spanEndCache.length) {
703 int[] grow = new int[spanEndCacheCount * 2];
704 System.arraycopy(spanEndCache, 0, grow, 0, spanEndCacheCount);
705 spanEndCache = grow;
706 }
Doug Felte8e45f22010-03-29 14:58:40 -0700707
Gilles Debunnecd943a72012-06-07 17:54:47 -0700708 if (spanned == null) {
709 spanEnd = paraEnd;
Doug Felt23241882010-06-02 14:41:06 -0700710 int spanLen = spanEnd - spanStart;
Gilles Debunnecd943a72012-06-07 17:54:47 -0700711 measured.addStyleRun(paint, spanLen, fm);
712 } else {
713 spanEnd = spanned.nextSpanTransition(spanStart, paraEnd,
714 MetricAffectingSpan.class);
715 int spanLen = spanEnd - spanStart;
716 MetricAffectingSpan[] spans =
Doug Felt23241882010-06-02 14:41:06 -0700717 spanned.getSpans(spanStart, spanEnd, MetricAffectingSpan.class);
Gilles Debunnecd943a72012-06-07 17:54:47 -0700718 spans = TextUtils.removeEmptySpans(spans, spanned, MetricAffectingSpan.class);
719 measured.addStyleRun(paint, spans, spanLen, fm);
Doug Felt23241882010-06-02 14:41:06 -0700720 }
721
Anish Athalyec8f9e622014-07-21 15:26:34 -0700722 // the order of storage here (top, bottom, ascent, descent) has to match the code below
723 // where these values are retrieved
724 fmCache[fmCacheCount * 4 + 0] = fm.top;
725 fmCache[fmCacheCount * 4 + 1] = fm.bottom;
726 fmCache[fmCacheCount * 4 + 2] = fm.ascent;
727 fmCache[fmCacheCount * 4 + 3] = fm.descent;
728 fmCacheCount++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800729
Anish Athalyec8f9e622014-07-21 15:26:34 -0700730 spanEndCache[spanEndCacheCount] = spanEnd;
731 spanEndCacheCount++;
732 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800733
Raph Levien70616ec2015-03-04 10:41:30 -0800734 nGetWidths(b.mNativePtr, widths);
Raph Levienc94f7422015-03-06 19:19:48 -0800735 int breakCount = nComputeLineBreaks(b.mNativePtr, lineBreaks, lineBreaks.breaks,
736 lineBreaks.widths, lineBreaks.flags, lineBreaks.breaks.length);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800737
Anish Athalyec8f9e622014-07-21 15:26:34 -0700738 int[] breaks = lineBreaks.breaks;
739 float[] lineWidths = lineBreaks.widths;
Raph Levien26d443a2015-03-30 14:18:32 -0700740 int[] flags = lineBreaks.flags;
Anish Athalyec8f9e622014-07-21 15:26:34 -0700741
Keisuke Kuroyanagif4a3f3a2015-06-10 09:37:32 +0900742 final int remainingLineCount = mMaximumVisibleLineCount - mLineCount;
743 final boolean ellipsisMayBeApplied = ellipsize != null
744 && (ellipsize == TextUtils.TruncateAt.END
745 || (mMaximumVisibleLineCount == 1
746 && ellipsize != TextUtils.TruncateAt.MARQUEE));
747 if (remainingLineCount < breakCount && ellipsisMayBeApplied) {
748 // Treat the last line and overflowed lines as a single line.
749 breaks[remainingLineCount - 1] = breaks[breakCount - 1];
750 // Calculate width and flag.
751 float width = 0;
752 int flag = 0;
753 for (int i = remainingLineCount - 1; i < breakCount; i++) {
754 width += lineWidths[i];
755 flag |= flags[i] & TAB_MASK;
756 }
757 lineWidths[remainingLineCount - 1] = width;
758 flags[remainingLineCount - 1] = flag;
759
760 breakCount = remainingLineCount;
761 }
762
Anish Athalyec8f9e622014-07-21 15:26:34 -0700763 // here is the offset of the starting character of the line we are currently measuring
764 int here = paraStart;
765
766 int fmTop = 0, fmBottom = 0, fmAscent = 0, fmDescent = 0;
767 int fmCacheIndex = 0;
768 int spanEndCacheIndex = 0;
769 int breakIndex = 0;
770 for (int spanStart = paraStart, spanEnd; spanStart < paraEnd; spanStart = spanEnd) {
771 // retrieve end of span
772 spanEnd = spanEndCache[spanEndCacheIndex++];
773
774 // retrieve cached metrics, order matches above
775 fm.top = fmCache[fmCacheIndex * 4 + 0];
776 fm.bottom = fmCache[fmCacheIndex * 4 + 1];
777 fm.ascent = fmCache[fmCacheIndex * 4 + 2];
778 fm.descent = fmCache[fmCacheIndex * 4 + 3];
779 fmCacheIndex++;
780
781 if (fm.top < fmTop) {
782 fmTop = fm.top;
783 }
784 if (fm.ascent < fmAscent) {
785 fmAscent = fm.ascent;
786 }
787 if (fm.descent > fmDescent) {
788 fmDescent = fm.descent;
789 }
790 if (fm.bottom > fmBottom) {
791 fmBottom = fm.bottom;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800792 }
793
Anish Athalyec8f9e622014-07-21 15:26:34 -0700794 // skip breaks ending before current span range
795 while (breakIndex < breakCount && paraStart + breaks[breakIndex] < spanStart) {
796 breakIndex++;
797 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798
Anish Athalyec8f9e622014-07-21 15:26:34 -0700799 while (breakIndex < breakCount && paraStart + breaks[breakIndex] <= spanEnd) {
800 int endPos = paraStart + breaks[breakIndex];
801
Raph Levience4155a2015-03-11 11:02:33 -0700802 boolean moreChars = (endPos < bufEnd);
Raph Levien4c02e832014-12-12 11:17:01 -0800803
Anish Athalyec8f9e622014-07-21 15:26:34 -0700804 v = out(source, here, endPos,
805 fmAscent, fmDescent, fmTop, fmBottom,
806 v, spacingmult, spacingadd, chooseHt,chooseHtv, fm, flags[breakIndex],
807 needMultiply, chdirs, dir, easy, bufEnd, includepad, trackpad,
808 chs, widths, paraStart, ellipsize, ellipsizedWidth,
Raph Levien4c02e832014-12-12 11:17:01 -0800809 lineWidths[breakIndex], paint, moreChars);
Anish Athalyec8f9e622014-07-21 15:26:34 -0700810
811 if (endPos < spanEnd) {
812 // preserve metrics for current span
813 fmTop = fm.top;
814 fmBottom = fm.bottom;
815 fmAscent = fm.ascent;
816 fmDescent = fm.descent;
817 } else {
818 fmTop = fmBottom = fmAscent = fmDescent = 0;
819 }
820
821 here = endPos;
822 breakIndex++;
823
824 if (mLineCount >= mMaximumVisibleLineCount) {
825 return;
826 }
827 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 }
829
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800830 if (paraEnd == bufEnd)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 break;
832 }
833
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -0700834 if ((bufEnd == bufStart || source.charAt(bufEnd - 1) == CHAR_NEW_LINE) &&
Fabrice Di Meglioad0b0512011-10-04 17:21:26 -0700835 mLineCount < mMaximumVisibleLineCount) {
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800836 // Log.e("text", "output last " + bufEnd);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800837
Raph Levien70616ec2015-03-04 10:41:30 -0800838 measured.setPara(source, bufEnd, bufEnd, textDir, b);
Fabrice Di Meglioe6318892013-06-18 20:03:41 -0700839
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800840 paint.getFontMetricsInt(fm);
841
842 v = out(source,
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800843 bufEnd, bufEnd, fm.ascent, fm.descent,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 fm.top, fm.bottom,
845 v,
846 spacingmult, spacingadd, null,
Raph Levien26d443a2015-03-30 14:18:32 -0700847 null, fm, 0,
Fabrice Di Meglioe6318892013-06-18 20:03:41 -0700848 needMultiply, measured.mLevels, measured.mDir, measured.mEasy, bufEnd,
Gilles Debunned300e752011-10-17 13:37:36 -0700849 includepad, trackpad, null,
850 null, bufStart, ellipsize,
851 ellipsizedWidth, 0, paint, false);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800852 }
853 }
854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 private int out(CharSequence text, int start, int end,
856 int above, int below, int top, int bottom, int v,
857 float spacingmult, float spacingadd,
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800858 LineHeightSpan[] chooseHt, int[] chooseHtv,
Raph Levien26d443a2015-03-30 14:18:32 -0700859 Paint.FontMetricsInt fm, int flags,
Gilles Debunned300e752011-10-17 13:37:36 -0700860 boolean needMultiply, byte[] chdirs, int dir,
861 boolean easy, int bufEnd, boolean includePad,
862 boolean trackPad, char[] chs,
863 float[] widths, int widthStart, TextUtils.TruncateAt ellipsize,
864 float ellipsisWidth, float textWidth,
865 TextPaint paint, boolean moreChars) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800866 int j = mLineCount;
867 int off = j * mColumns;
868 int want = off + mColumns + TOP;
869 int[] lines = mLines;
870
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800871 if (want >= lines.length) {
Adam Lesinski776abc22014-03-07 11:30:59 -0500872 Directions[] grow2 = ArrayUtils.newUnpaddedArray(
873 Directions.class, GrowingArrayUtils.growSize(want));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800874 System.arraycopy(mLineDirections, 0, grow2, 0,
875 mLineDirections.length);
876 mLineDirections = grow2;
Adam Lesinski776abc22014-03-07 11:30:59 -0500877
878 int[] grow = new int[grow2.length];
879 System.arraycopy(lines, 0, grow, 0, lines.length);
880 mLines = grow;
881 lines = grow;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882 }
883
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800884 if (chooseHt != null) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800885 fm.ascent = above;
886 fm.descent = below;
887 fm.top = top;
888 fm.bottom = bottom;
889
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800890 for (int i = 0; i < chooseHt.length; i++) {
891 if (chooseHt[i] instanceof LineHeightSpan.WithDensity) {
892 ((LineHeightSpan.WithDensity) chooseHt[i]).
893 chooseHeight(text, start, end, chooseHtv[i], v, fm, paint);
Eric Fischera9f1dd02009-08-12 15:00:10 -0700894
895 } else {
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800896 chooseHt[i].chooseHeight(text, start, end, chooseHtv[i], v, fm);
Eric Fischera9f1dd02009-08-12 15:00:10 -0700897 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800898 }
899
900 above = fm.ascent;
901 below = fm.descent;
902 top = fm.top;
903 bottom = fm.bottom;
904 }
905
Raph Leviend97b0972014-04-24 12:51:35 -0700906 boolean firstLine = (j == 0);
907 boolean currentLineIsTheLastVisibleOne = (j + 1 == mMaximumVisibleLineCount);
908 boolean lastLine = currentLineIsTheLastVisibleOne || (end == bufEnd);
909
910 if (firstLine) {
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800911 if (trackPad) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 mTopPadding = top - above;
913 }
914
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800915 if (includePad) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800916 above = top;
917 }
918 }
Raph Leviend97b0972014-04-24 12:51:35 -0700919
920 int extra;
921
922 if (lastLine) {
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800923 if (trackPad) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800924 mBottomPadding = bottom - below;
925 }
926
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800927 if (includePad) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 below = bottom;
929 }
930 }
931
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800932
Raph Leviend97b0972014-04-24 12:51:35 -0700933 if (needMultiply && !lastLine) {
Doug Felt10657582010-02-22 11:19:01 -0800934 double ex = (below - above) * (spacingmult - 1) + spacingadd;
935 if (ex >= 0) {
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800936 extra = (int)(ex + EXTRA_ROUNDING);
Doug Felt10657582010-02-22 11:19:01 -0800937 } else {
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800938 extra = -(int)(-ex + EXTRA_ROUNDING);
Doug Felt10657582010-02-22 11:19:01 -0800939 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800940 } else {
941 extra = 0;
942 }
943
944 lines[off + START] = start;
945 lines[off + TOP] = v;
946 lines[off + DESCENT] = below + extra;
947
948 v += (below - above) + extra;
949 lines[off + mColumns + START] = end;
950 lines[off + mColumns + TOP] = v;
951
Raph Levien26d443a2015-03-30 14:18:32 -0700952 // TODO: could move TAB to share same column as HYPHEN, simplifying this code and gaining
953 // one bit for start field
954 lines[off + TAB] |= flags & TAB_MASK;
955 lines[off + HYPHEN] = flags;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800956
Doug Felt9f7a4442010-03-01 12:45:56 -0800957 lines[off + DIR] |= dir << DIR_SHIFT;
958 Directions linedirs = DIRS_ALL_LEFT_TO_RIGHT;
959 // easy means all chars < the first RTL, so no emoji, no nothing
Doug Felt4e0c5e52010-03-15 16:56:02 -0700960 // XXX a run with no text or all spaces is easy but might be an empty
Doug Felt9f7a4442010-03-01 12:45:56 -0800961 // RTL paragraph. Make sure easy is false if this is the case.
962 if (easy) {
963 mLineDirections[j] = linedirs;
964 } else {
Gilles Debunnef3fa0cd2011-02-03 14:17:05 -0800965 mLineDirections[j] = AndroidBidi.directions(dir, chdirs, start - widthStart, chs,
966 start - widthStart, end - start);
Gilles Debunne0a4db3c2011-01-14 12:12:04 -0800967 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968
Fabrice Di Meglioaef455f2011-08-29 15:39:11 -0700969 if (ellipsize != null) {
970 // If there is only one line, then do any type of ellipsis except when it is MARQUEE
971 // if there are multiple lines, just allow END ellipsis on the last line
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -0700972 boolean forceEllipsis = moreChars && (mLineCount + 1 == mMaximumVisibleLineCount);
Fabrice Di Meglioaef455f2011-08-29 15:39:11 -0700973
Fabrice Di Meglio34a126e2012-02-29 18:43:14 -0800974 boolean doEllipsis =
975 (((mMaximumVisibleLineCount == 1 && moreChars) || (firstLine && !moreChars)) &&
Fabrice Di Meglioaef455f2011-08-29 15:39:11 -0700976 ellipsize != TextUtils.TruncateAt.MARQUEE) ||
977 (!firstLine && (currentLineIsTheLastVisibleOne || !moreChars) &&
978 ellipsize == TextUtils.TruncateAt.END);
979 if (doEllipsis) {
980 calculateEllipsis(start, end, widths, widthStart,
981 ellipsisWidth, ellipsize, j,
982 textWidth, paint, forceEllipsis);
983 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800984 }
985
986 mLineCount++;
987 return v;
988 }
989
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -0800990 private void calculateEllipsis(int lineStart, int lineEnd,
991 float[] widths, int widthStart,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992 float avail, TextUtils.TruncateAt where,
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -0700993 int line, float textWidth, TextPaint paint,
994 boolean forceEllipsis) {
995 if (textWidth <= avail && !forceEllipsis) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800996 // Everything fits!
997 mLines[mColumns * line + ELLIPSIS_START] = 0;
998 mLines[mColumns * line + ELLIPSIS_COUNT] = 0;
999 return;
1000 }
1001
Fabrice Di Megliocb332642011-09-23 19:08:04 -07001002 float ellipsisWidth = paint.measureText(
Fabrice Di Meglio8d44fff2012-06-13 15:45:38 -07001003 (where == TextUtils.TruncateAt.END_SMALL) ?
Neil Fullerd29bdb22015-02-06 10:03:08 +00001004 TextUtils.ELLIPSIS_TWO_DOTS : TextUtils.ELLIPSIS_NORMAL, 0, 1);
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001005 int ellipsisStart = 0;
1006 int ellipsisCount = 0;
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -08001007 int len = lineEnd - lineStart;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001009 // We only support start ellipsis on a single line
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 if (where == TextUtils.TruncateAt.START) {
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001011 if (mMaximumVisibleLineCount == 1) {
1012 float sum = 0;
1013 int i;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014
Keisuke Kuroyanagied2eea12015-04-14 18:18:35 +09001015 for (i = len; i > 0; i--) {
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001016 float w = widths[i - 1 + lineStart - widthStart];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001018 if (w + sum + ellipsisWidth > avail) {
1019 break;
1020 }
1021
1022 sum += w;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001023 }
1024
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001025 ellipsisStart = 0;
1026 ellipsisCount = i;
1027 } else {
1028 if (Log.isLoggable(TAG, Log.WARN)) {
1029 Log.w(TAG, "Start Ellipsis only supported with one line");
1030 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001031 }
Fabrice Di Megliocb332642011-09-23 19:08:04 -07001032 } else if (where == TextUtils.TruncateAt.END || where == TextUtils.TruncateAt.MARQUEE ||
1033 where == TextUtils.TruncateAt.END_SMALL) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001034 float sum = 0;
1035 int i;
1036
1037 for (i = 0; i < len; i++) {
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -08001038 float w = widths[i + lineStart - widthStart];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -08001040 if (w + sum + ellipsisWidth > avail) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 break;
1042 }
1043
1044 sum += w;
1045 }
1046
1047 ellipsisStart = i;
1048 ellipsisCount = len - i;
Fabrice Di Meglioaef455f2011-08-29 15:39:11 -07001049 if (forceEllipsis && ellipsisCount == 0 && len > 0) {
1050 ellipsisStart = len - 1;
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001051 ellipsisCount = 1;
1052 }
1053 } else {
1054 // where = TextUtils.TruncateAt.MIDDLE We only support middle ellipsis on a single line
1055 if (mMaximumVisibleLineCount == 1) {
1056 float lsum = 0, rsum = 0;
1057 int left = 0, right = len;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001058
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001059 float ravail = (avail - ellipsisWidth) / 2;
Raph Levien0e3c5e82014-12-04 13:26:07 -08001060 for (right = len; right > 0; right--) {
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001061 float w = widths[right - 1 + lineStart - widthStart];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001062
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001063 if (w + rsum > ravail) {
1064 break;
1065 }
1066
1067 rsum += w;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001068 }
1069
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001070 float lavail = avail - ellipsisWidth - rsum;
1071 for (left = 0; left < right; left++) {
1072 float w = widths[left + lineStart - widthStart];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001073
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001074 if (w + lsum > lavail) {
1075 break;
1076 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001077
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001078 lsum += w;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001079 }
1080
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001081 ellipsisStart = left;
1082 ellipsisCount = right - left;
1083 } else {
1084 if (Log.isLoggable(TAG, Log.WARN)) {
1085 Log.w(TAG, "Middle Ellipsis only supported with one line");
1086 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001087 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001088 }
1089
1090 mLines[mColumns * line + ELLIPSIS_START] = ellipsisStart;
1091 mLines[mColumns * line + ELLIPSIS_COUNT] = ellipsisCount;
1092 }
1093
Doug Felte8e45f22010-03-29 14:58:40 -07001094 // Override the base class so we can directly access our members,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001095 // rather than relying on member functions.
1096 // The logic mirrors that of Layout.getLineForVertical
1097 // FIXME: It may be faster to do a linear search for layouts without many lines.
Gilles Debunne66111472010-11-19 11:04:37 -08001098 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 public int getLineForVertical(int vertical) {
1100 int high = mLineCount;
1101 int low = -1;
1102 int guess;
1103 int[] lines = mLines;
1104 while (high - low > 1) {
1105 guess = (high + low) >> 1;
1106 if (lines[mColumns * guess + TOP] > vertical){
1107 high = guess;
1108 } else {
1109 low = guess;
1110 }
1111 }
1112 if (low < 0) {
1113 return 0;
1114 } else {
1115 return low;
1116 }
1117 }
1118
Gilles Debunne66111472010-11-19 11:04:37 -08001119 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001120 public int getLineCount() {
1121 return mLineCount;
1122 }
1123
Gilles Debunne66111472010-11-19 11:04:37 -08001124 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 public int getLineTop(int line) {
Gilles Debunne0a4db3c2011-01-14 12:12:04 -08001126 int top = mLines[mColumns * line + TOP];
1127 if (mMaximumVisibleLineCount > 0 && line >= mMaximumVisibleLineCount &&
1128 line != mLineCount) {
1129 top += getBottomPadding();
1130 }
1131 return top;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 }
1133
Gilles Debunne66111472010-11-19 11:04:37 -08001134 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 public int getLineDescent(int line) {
Gilles Debunne0a4db3c2011-01-14 12:12:04 -08001136 int descent = mLines[mColumns * line + DESCENT];
Gilles Debunnef3fa0cd2011-02-03 14:17:05 -08001137 if (mMaximumVisibleLineCount > 0 && line >= mMaximumVisibleLineCount - 1 && // -1 intended
Gilles Debunne0a4db3c2011-01-14 12:12:04 -08001138 line != mLineCount) {
1139 descent += getBottomPadding();
1140 }
1141 return descent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 }
1143
Gilles Debunne66111472010-11-19 11:04:37 -08001144 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001145 public int getLineStart(int line) {
1146 return mLines[mColumns * line + START] & START_MASK;
1147 }
1148
Gilles Debunne66111472010-11-19 11:04:37 -08001149 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 public int getParagraphDirection(int line) {
1151 return mLines[mColumns * line + DIR] >> DIR_SHIFT;
1152 }
1153
Gilles Debunne66111472010-11-19 11:04:37 -08001154 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001155 public boolean getLineContainsTab(int line) {
1156 return (mLines[mColumns * line + TAB] & TAB_MASK) != 0;
1157 }
1158
Gilles Debunne66111472010-11-19 11:04:37 -08001159 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 public final Directions getLineDirections(int line) {
1161 return mLineDirections[line];
1162 }
1163
Gilles Debunne66111472010-11-19 11:04:37 -08001164 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001165 public int getTopPadding() {
1166 return mTopPadding;
1167 }
1168
Gilles Debunne66111472010-11-19 11:04:37 -08001169 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001170 public int getBottomPadding() {
1171 return mBottomPadding;
1172 }
1173
Raph Levien26d443a2015-03-30 14:18:32 -07001174 /**
1175 * @hide
1176 */
1177 @Override
1178 public int getHyphen(int line) {
1179 return mLines[mColumns * line + HYPHEN] & 0xff;
1180 }
1181
Raph Levien2ea52902015-07-01 14:39:31 -07001182 /**
1183 * @hide
1184 */
1185 @Override
1186 public int getIndentAdjust(int line, Alignment align) {
1187 if (align == Alignment.ALIGN_LEFT) {
1188 if (mLeftIndents == null) {
1189 return 0;
1190 } else {
1191 return mLeftIndents[Math.min(line, mLeftIndents.length - 1)];
1192 }
1193 } else if (align == Alignment.ALIGN_RIGHT) {
1194 if (mRightIndents == null) {
1195 return 0;
1196 } else {
1197 return -mRightIndents[Math.min(line, mRightIndents.length - 1)];
1198 }
1199 } else if (align == Alignment.ALIGN_CENTER) {
1200 int left = 0;
1201 if (mLeftIndents != null) {
1202 left = mLeftIndents[Math.min(line, mLeftIndents.length - 1)];
1203 }
1204 int right = 0;
1205 if (mRightIndents != null) {
1206 right = mRightIndents[Math.min(line, mRightIndents.length - 1)];
1207 }
1208 return (left - right) >> 1;
1209 } else {
1210 throw new AssertionError("unhandled alignment " + align);
1211 }
1212 }
1213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001214 @Override
1215 public int getEllipsisCount(int line) {
1216 if (mColumns < COLUMNS_ELLIPSIZE) {
1217 return 0;
1218 }
1219
1220 return mLines[mColumns * line + ELLIPSIS_COUNT];
1221 }
1222
1223 @Override
1224 public int getEllipsisStart(int line) {
1225 if (mColumns < COLUMNS_ELLIPSIZE) {
1226 return 0;
1227 }
1228
1229 return mLines[mColumns * line + ELLIPSIS_START];
1230 }
1231
1232 @Override
1233 public int getEllipsizedWidth() {
1234 return mEllipsizedWidth;
1235 }
1236
Raph Levien70616ec2015-03-04 10:41:30 -08001237 private static native long nNewBuilder();
1238 private static native void nFreeBuilder(long nativePtr);
1239 private static native void nFinishBuilder(long nativePtr);
Raph Levien26d443a2015-03-30 14:18:32 -07001240
1241 /* package */ static native long nLoadHyphenator(String patternData);
1242
1243 private static native void nSetLocale(long nativePtr, String locale, long nativeHyphenator);
Raph Levien70616ec2015-03-04 10:41:30 -08001244
Raph Leviene319d5a2015-04-14 23:51:07 -07001245 private static native void nSetIndents(long nativePtr, int[] indents);
1246
Raph Levienc94f7422015-03-06 19:19:48 -08001247 // Set up paragraph text and settings; done as one big method to minimize jni crossings
1248 private static native void nSetupParagraph(long nativePtr, char[] text, int length,
1249 float firstWidth, int firstWidthLineCount, float restWidth,
Roozbeh Pournader95c7a132015-05-12 12:01:06 -07001250 int[] variableTabStops, int defaultTabStop, int breakStrategy, int hyphenationFrequency);
Raph Levien70616ec2015-03-04 10:41:30 -08001251
1252 private static native float nAddStyleRun(long nativePtr, long nativePaint,
1253 long nativeTypeface, int start, int end, boolean isRtl);
1254
1255 private static native void nAddMeasuredRun(long nativePtr,
1256 int start, int end, float[] widths);
1257
1258 private static native void nAddReplacementRun(long nativePtr, int start, int end, float width);
1259
1260 private static native void nGetWidths(long nativePtr, float[] widths);
1261
Anish Athalyec8f9e622014-07-21 15:26:34 -07001262 // populates LineBreaks and returns the number of breaks found
1263 //
1264 // the arrays inside the LineBreaks objects are passed in as well
1265 // to reduce the number of JNI calls in the common case where the
1266 // arrays do not have to be resized
Raph Levienc94f7422015-03-06 19:19:48 -08001267 private static native int nComputeLineBreaks(long nativePtr, LineBreaks recycle,
Raph Levien26d443a2015-03-30 14:18:32 -07001268 int[] recycleBreaks, float[] recycleWidths, int[] recycleFlags, int recycleLength);
Anish Athalye88b5b0b2014-06-24 14:39:43 -07001269
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001270 private int mLineCount;
1271 private int mTopPadding, mBottomPadding;
1272 private int mColumns;
1273 private int mEllipsizedWidth;
1274
Raph Levien26d443a2015-03-30 14:18:32 -07001275 private static final int COLUMNS_NORMAL = 4;
1276 private static final int COLUMNS_ELLIPSIZE = 6;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 private static final int START = 0;
1278 private static final int DIR = START;
1279 private static final int TAB = START;
1280 private static final int TOP = 1;
1281 private static final int DESCENT = 2;
Raph Levien26d443a2015-03-30 14:18:32 -07001282 private static final int HYPHEN = 3;
1283 private static final int ELLIPSIS_START = 4;
1284 private static final int ELLIPSIS_COUNT = 5;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001285
1286 private int[] mLines;
1287 private Directions[] mLineDirections;
Fabrice Di Meglio8059e0902011-08-10 16:31:58 -07001288 private int mMaximumVisibleLineCount = Integer.MAX_VALUE;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001289
1290 private static final int START_MASK = 0x1FFFFFFF;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 private static final int DIR_SHIFT = 30;
1292 private static final int TAB_MASK = 0x20000000;
1293
Doug Feltc982f602010-05-25 11:51:40 -07001294 private static final int TAB_INCREMENT = 20; // same as Layout, but that's private
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001295
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -08001296 private static final char CHAR_NEW_LINE = '\n';
Fabrice Di Meglio121c82c2011-02-15 15:44:49 -08001297
1298 private static final double EXTRA_ROUNDING = 0.5;
Fabrice Di Megliocb332642011-09-23 19:08:04 -07001299
Anish Athalyec8f9e622014-07-21 15:26:34 -07001300 // This is used to return three arrays from a single JNI call when
1301 // performing line breaking
Deepanshu Gupta70539192014-10-15 15:57:40 -07001302 /*package*/ static class LineBreaks {
Anish Athalyec8f9e622014-07-21 15:26:34 -07001303 private static final int INITIAL_SIZE = 16;
1304 public int[] breaks = new int[INITIAL_SIZE];
1305 public float[] widths = new float[INITIAL_SIZE];
Raph Levien26d443a2015-03-30 14:18:32 -07001306 public int[] flags = new int[INITIAL_SIZE]; // hasTabOrEmoji
Anish Athalyec8f9e622014-07-21 15:26:34 -07001307 // breaks, widths, and flags should all have the same length
1308 }
1309
Raph Levien2ea52902015-07-01 14:39:31 -07001310 private int[] mLeftIndents;
1311 private int[] mRightIndents;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312}