The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.text; |
| 18 | |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 19 | import android.annotation.FloatRange; |
| 20 | import android.annotation.IntRange; |
| 21 | import android.annotation.NonNull; |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 22 | import android.annotation.Nullable; |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 23 | import android.annotation.UnsupportedAppUsage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.graphics.Paint; |
Seigo Nonaka | 70200b0 | 2018-10-01 16:04:11 -0700 | [diff] [blame] | 25 | import android.graphics.text.LineBreaker; |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 26 | import android.os.Build; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.text.style.LeadingMarginSpan; |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 28 | import android.text.style.LeadingMarginSpan.LeadingMarginSpan2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.text.style.LineHeightSpan; |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 30 | import android.text.style.TabStopSpan; |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 31 | import android.util.Log; |
Raph Levien | 39b4db7 | 2015-03-25 13:18:20 -0700 | [diff] [blame] | 32 | import android.util.Pools.SynchronizedPool; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 34 | import com.android.internal.util.ArrayUtils; |
Adam Lesinski | 776abc2 | 2014-03-07 11:30:59 -0500 | [diff] [blame] | 35 | import com.android.internal.util.GrowingArrayUtils; |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 36 | |
Anish Athalye | c8f9e62 | 2014-07-21 15:26:34 -0700 | [diff] [blame] | 37 | import java.util.Arrays; |
| 38 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | /** |
| 40 | * StaticLayout is a Layout for text that will not be edited after it |
| 41 | * is laid out. Use {@link DynamicLayout} for text that may change. |
| 42 | * <p>This is used by widgets to control text layout. You should not need |
| 43 | * to use this class directly unless you are implementing your own widget |
| 44 | * or custom display object, or would be tempted to call |
Doug Felt | 4e0c5e5 | 2010-03-15 16:56:02 -0700 | [diff] [blame] | 45 | * {@link android.graphics.Canvas#drawText(java.lang.CharSequence, int, int, |
| 46 | * float, float, android.graphics.Paint) |
| 47 | * Canvas.drawText()} directly.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | */ |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 49 | public class StaticLayout extends Layout { |
Seigo Nonaka | 6f1868b | 2017-12-01 16:24:19 -0800 | [diff] [blame] | 50 | /* |
| 51 | * The break iteration is done in native code. The protocol for using the native code is as |
| 52 | * follows. |
| 53 | * |
| 54 | * First, call nInit to setup native line breaker object. Then, for each paragraph, do the |
| 55 | * following: |
| 56 | * |
Seigo Nonaka | 9d3bd08 | 2018-01-11 10:02:12 -0800 | [diff] [blame] | 57 | * - Create MeasuredParagraph by MeasuredParagraph.buildForStaticLayout which measures in |
| 58 | * native. |
Seigo Nonaka | 70200b0 | 2018-10-01 16:04:11 -0700 | [diff] [blame] | 59 | * - Run LineBreaker.computeLineBreaks() to obtain line breaks for the paragraph. |
Seigo Nonaka | 6f1868b | 2017-12-01 16:24:19 -0800 | [diff] [blame] | 60 | * |
| 61 | * After all paragraphs, call finish() to release expensive buffers. |
| 62 | */ |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 63 | |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 64 | static final String TAG = "StaticLayout"; |
| 65 | |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 66 | /** |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 67 | * Builder for static layouts. The builder is the preferred pattern for constructing |
| 68 | * StaticLayout objects and should be preferred over the constructors, particularly to access |
| 69 | * newer features. To build a static layout, first call {@link #obtain} with the required |
| 70 | * arguments (text, paint, and width), then call setters for optional parameters, and finally |
| 71 | * {@link #build} to build the StaticLayout object. Parameters not explicitly set will get |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 72 | * default values. |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 73 | */ |
| 74 | public final static class Builder { |
Seigo Nonaka | b90e08f | 2017-10-20 15:23:51 -0700 | [diff] [blame] | 75 | private Builder() {} |
Raph Levien | 4c1f12e | 2015-03-02 16:29:23 -0800 | [diff] [blame] | 76 | |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 77 | /** |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 78 | * Obtain a builder for constructing StaticLayout objects. |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 79 | * |
| 80 | * @param source The text to be laid out, optionally with spans |
| 81 | * @param start The index of the start of the text |
| 82 | * @param end The index + 1 of the end of the text |
| 83 | * @param paint The base paint used for layout |
| 84 | * @param width The width in pixels |
| 85 | * @return a builder object used for constructing the StaticLayout |
| 86 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 87 | @NonNull |
| 88 | public static Builder obtain(@NonNull CharSequence source, @IntRange(from = 0) int start, |
| 89 | @IntRange(from = 0) int end, @NonNull TextPaint paint, |
| 90 | @IntRange(from = 0) int width) { |
Raph Levien | 39b4db7 | 2015-03-25 13:18:20 -0700 | [diff] [blame] | 91 | Builder b = sPool.acquire(); |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 92 | if (b == null) { |
| 93 | b = new Builder(); |
| 94 | } |
| 95 | |
| 96 | // set default initial values |
Raph Levien | 39b4db7 | 2015-03-25 13:18:20 -0700 | [diff] [blame] | 97 | b.mText = source; |
| 98 | b.mStart = start; |
| 99 | b.mEnd = end; |
Raph Levien | ebd66ca | 2015-04-30 15:27:57 -0700 | [diff] [blame] | 100 | b.mPaint = paint; |
Raph Levien | 39b4db7 | 2015-03-25 13:18:20 -0700 | [diff] [blame] | 101 | b.mWidth = width; |
| 102 | b.mAlignment = Alignment.ALIGN_NORMAL; |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 103 | b.mTextDir = TextDirectionHeuristics.FIRSTSTRONG_LTR; |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 104 | b.mSpacingMult = DEFAULT_LINESPACING_MULTIPLIER; |
| 105 | b.mSpacingAdd = DEFAULT_LINESPACING_ADDITION; |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 106 | b.mIncludePad = true; |
Roozbeh Pournader | 737dfea | 2017-08-10 11:32:24 -0700 | [diff] [blame] | 107 | b.mFallbackLineSpacing = false; |
Raph Levien | 39b4db7 | 2015-03-25 13:18:20 -0700 | [diff] [blame] | 108 | b.mEllipsizedWidth = width; |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 109 | b.mEllipsize = null; |
| 110 | b.mMaxLines = Integer.MAX_VALUE; |
Raph Levien | 3bd60c7 | 2015-05-06 14:26:35 -0700 | [diff] [blame] | 111 | b.mBreakStrategy = Layout.BREAK_STRATEGY_SIMPLE; |
Roozbeh Pournader | 95c7a13 | 2015-05-12 12:01:06 -0700 | [diff] [blame] | 112 | b.mHyphenationFrequency = Layout.HYPHENATION_FREQUENCY_NONE; |
Seigo Nonaka | 4b4730d | 2017-03-31 09:42:16 -0700 | [diff] [blame] | 113 | b.mJustificationMode = Layout.JUSTIFICATION_MODE_NONE; |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 114 | return b; |
| 115 | } |
| 116 | |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 117 | /** |
| 118 | * This method should be called after the layout is finished getting constructed and the |
| 119 | * builder needs to be cleaned up and returned to the pool. |
| 120 | */ |
| 121 | private static void recycle(@NonNull Builder b) { |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 122 | b.mPaint = null; |
| 123 | b.mText = null; |
Raph Levien | 2ea5290 | 2015-07-01 14:39:31 -0700 | [diff] [blame] | 124 | b.mLeftIndents = null; |
| 125 | b.mRightIndents = null; |
Raph Levien | 39b4db7 | 2015-03-25 13:18:20 -0700 | [diff] [blame] | 126 | sPool.release(b); |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | // release any expensive state |
| 130 | /* package */ void finish() { |
Raph Levien | 22ba786 | 2015-07-29 12:34:13 -0700 | [diff] [blame] | 131 | mText = null; |
| 132 | mPaint = null; |
| 133 | mLeftIndents = null; |
| 134 | mRightIndents = null; |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | public Builder setText(CharSequence source) { |
| 138 | return setText(source, 0, source.length()); |
| 139 | } |
| 140 | |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 141 | /** |
| 142 | * Set the text. Only useful when re-using the builder, which is done for |
| 143 | * the internal implementation of {@link DynamicLayout} but not as part |
| 144 | * of normal {@link StaticLayout} usage. |
| 145 | * |
| 146 | * @param source The text to be laid out, optionally with spans |
| 147 | * @param start The index of the start of the text |
| 148 | * @param end The index + 1 of the end of the text |
| 149 | * @return this builder, useful for chaining |
| 150 | * |
| 151 | * @hide |
| 152 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 153 | @NonNull |
| 154 | public Builder setText(@NonNull CharSequence source, int start, int end) { |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 155 | mText = source; |
| 156 | mStart = start; |
| 157 | mEnd = end; |
| 158 | return this; |
| 159 | } |
| 160 | |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 161 | /** |
| 162 | * Set the paint. Internal for reuse cases only. |
| 163 | * |
| 164 | * @param paint The base paint used for layout |
| 165 | * @return this builder, useful for chaining |
| 166 | * |
| 167 | * @hide |
| 168 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 169 | @NonNull |
| 170 | public Builder setPaint(@NonNull TextPaint paint) { |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 171 | mPaint = paint; |
| 172 | return this; |
| 173 | } |
| 174 | |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 175 | /** |
| 176 | * Set the width. Internal for reuse cases only. |
| 177 | * |
| 178 | * @param width The width in pixels |
| 179 | * @return this builder, useful for chaining |
| 180 | * |
| 181 | * @hide |
| 182 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 183 | @NonNull |
| 184 | public Builder setWidth(@IntRange(from = 0) int width) { |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 185 | mWidth = width; |
| 186 | if (mEllipsize == null) { |
| 187 | mEllipsizedWidth = width; |
| 188 | } |
| 189 | return this; |
| 190 | } |
| 191 | |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 192 | /** |
| 193 | * Set the alignment. The default is {@link Layout.Alignment#ALIGN_NORMAL}. |
| 194 | * |
| 195 | * @param alignment Alignment for the resulting {@link StaticLayout} |
| 196 | * @return this builder, useful for chaining |
| 197 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 198 | @NonNull |
| 199 | public Builder setAlignment(@NonNull Alignment alignment) { |
Raph Levien | 39b4db7 | 2015-03-25 13:18:20 -0700 | [diff] [blame] | 200 | mAlignment = alignment; |
| 201 | return this; |
| 202 | } |
| 203 | |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 204 | /** |
| 205 | * Set the text direction heuristic. The text direction heuristic is used to |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 206 | * resolve text direction per-paragraph based on the input text. The default is |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 207 | * {@link TextDirectionHeuristics#FIRSTSTRONG_LTR}. |
| 208 | * |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 209 | * @param textDir text direction heuristic for resolving bidi behavior. |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 210 | * @return this builder, useful for chaining |
| 211 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 212 | @NonNull |
| 213 | public Builder setTextDirection(@NonNull TextDirectionHeuristic textDir) { |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 214 | mTextDir = textDir; |
| 215 | return this; |
| 216 | } |
| 217 | |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 218 | /** |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 219 | * Set line spacing parameters. Each line will have its line spacing multiplied by |
| 220 | * {@code spacingMult} and then increased by {@code spacingAdd}. The default is 0.0 for |
| 221 | * {@code spacingAdd} and 1.0 for {@code spacingMult}. |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 222 | * |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 223 | * @param spacingAdd the amount of line spacing addition |
| 224 | * @param spacingMult the line spacing multiplier |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 225 | * @return this builder, useful for chaining |
| 226 | * @see android.widget.TextView#setLineSpacing |
| 227 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 228 | @NonNull |
| 229 | public Builder setLineSpacing(float spacingAdd, @FloatRange(from = 0.0) float spacingMult) { |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 230 | mSpacingAdd = spacingAdd; |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 231 | mSpacingMult = spacingMult; |
| 232 | return this; |
| 233 | } |
| 234 | |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 235 | /** |
| 236 | * Set whether to include extra space beyond font ascent and descent (which is |
| 237 | * needed to avoid clipping in some languages, such as Arabic and Kannada). The |
| 238 | * default is {@code true}. |
| 239 | * |
| 240 | * @param includePad whether to include padding |
| 241 | * @return this builder, useful for chaining |
| 242 | * @see android.widget.TextView#setIncludeFontPadding |
| 243 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 244 | @NonNull |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 245 | public Builder setIncludePad(boolean includePad) { |
| 246 | mIncludePad = includePad; |
| 247 | return this; |
| 248 | } |
| 249 | |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 250 | /** |
Roozbeh Pournader | 737dfea | 2017-08-10 11:32:24 -0700 | [diff] [blame] | 251 | * Set whether to respect the ascent and descent of the fallback fonts that are used in |
| 252 | * displaying the text (which is needed to avoid text from consecutive lines running into |
| 253 | * each other). If set, fallback fonts that end up getting used can increase the ascent |
| 254 | * and descent of the lines that they are used on. |
| 255 | * |
| 256 | * <p>For backward compatibility reasons, the default is {@code false}, but setting this to |
| 257 | * true is strongly recommended. It is required to be true if text could be in languages |
| 258 | * like Burmese or Tibetan where text is typically much taller or deeper than Latin text. |
| 259 | * |
| 260 | * @param useLineSpacingFromFallbacks whether to expand linespacing based on fallback fonts |
| 261 | * @return this builder, useful for chaining |
| 262 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 263 | @NonNull |
Roozbeh Pournader | 737dfea | 2017-08-10 11:32:24 -0700 | [diff] [blame] | 264 | public Builder setUseLineSpacingFromFallbacks(boolean useLineSpacingFromFallbacks) { |
| 265 | mFallbackLineSpacing = useLineSpacingFromFallbacks; |
| 266 | return this; |
| 267 | } |
| 268 | |
| 269 | /** |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 270 | * Set the width as used for ellipsizing purposes, if it differs from the |
| 271 | * normal layout width. The default is the {@code width} |
| 272 | * passed to {@link #obtain}. |
| 273 | * |
| 274 | * @param ellipsizedWidth width used for ellipsizing, in pixels |
| 275 | * @return this builder, useful for chaining |
| 276 | * @see android.widget.TextView#setEllipsize |
| 277 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 278 | @NonNull |
| 279 | public Builder setEllipsizedWidth(@IntRange(from = 0) int ellipsizedWidth) { |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 280 | mEllipsizedWidth = ellipsizedWidth; |
| 281 | return this; |
| 282 | } |
| 283 | |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 284 | /** |
| 285 | * Set ellipsizing on the layout. Causes words that are longer than the view |
| 286 | * is wide, or exceeding the number of lines (see #setMaxLines) in the case |
| 287 | * of {@link android.text.TextUtils.TruncateAt#END} or |
| 288 | * {@link android.text.TextUtils.TruncateAt#MARQUEE}, to be ellipsized instead |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 289 | * of broken. The default is {@code null}, indicating no ellipsis is to be applied. |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 290 | * |
| 291 | * @param ellipsize type of ellipsis behavior |
| 292 | * @return this builder, useful for chaining |
| 293 | * @see android.widget.TextView#setEllipsize |
| 294 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 295 | @NonNull |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 296 | public Builder setEllipsize(@Nullable TextUtils.TruncateAt ellipsize) { |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 297 | mEllipsize = ellipsize; |
| 298 | return this; |
| 299 | } |
| 300 | |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 301 | /** |
| 302 | * Set maximum number of lines. This is particularly useful in the case of |
| 303 | * ellipsizing, where it changes the layout of the last line. The default is |
| 304 | * unlimited. |
| 305 | * |
| 306 | * @param maxLines maximum number of lines in the layout |
| 307 | * @return this builder, useful for chaining |
| 308 | * @see android.widget.TextView#setMaxLines |
| 309 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 310 | @NonNull |
| 311 | public Builder setMaxLines(@IntRange(from = 0) int maxLines) { |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 312 | mMaxLines = maxLines; |
| 313 | return this; |
| 314 | } |
| 315 | |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 316 | /** |
| 317 | * Set break strategy, useful for selecting high quality or balanced paragraph |
| 318 | * layout options. The default is {@link Layout#BREAK_STRATEGY_SIMPLE}. |
Siyamed Sinir | c0dab36 | 2018-07-22 13:48:51 -0700 | [diff] [blame] | 319 | * <p/> |
| 320 | * Enabling hyphenation with either using {@link Layout#HYPHENATION_FREQUENCY_NORMAL} or |
| 321 | * {@link Layout#HYPHENATION_FREQUENCY_FULL} while line breaking is set to one of |
| 322 | * {@link Layout#BREAK_STRATEGY_BALANCED}, {@link Layout#BREAK_STRATEGY_HIGH_QUALITY} |
| 323 | * improves the structure of text layout however has performance impact and requires more |
| 324 | * time to do the text layout. |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 325 | * |
| 326 | * @param breakStrategy break strategy for paragraph layout |
| 327 | * @return this builder, useful for chaining |
| 328 | * @see android.widget.TextView#setBreakStrategy |
Siyamed Sinir | c0dab36 | 2018-07-22 13:48:51 -0700 | [diff] [blame] | 329 | * @see #setHyphenationFrequency(int) |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 330 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 331 | @NonNull |
Raph Levien | 39b4db7 | 2015-03-25 13:18:20 -0700 | [diff] [blame] | 332 | public Builder setBreakStrategy(@BreakStrategy int breakStrategy) { |
| 333 | mBreakStrategy = breakStrategy; |
| 334 | return this; |
| 335 | } |
| 336 | |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 337 | /** |
Roozbeh Pournader | 95c7a13 | 2015-05-12 12:01:06 -0700 | [diff] [blame] | 338 | * Set hyphenation frequency, to control the amount of automatic hyphenation used. The |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 339 | * possible values are defined in {@link Layout}, by constants named with the pattern |
| 340 | * {@code HYPHENATION_FREQUENCY_*}. The default is |
| 341 | * {@link Layout#HYPHENATION_FREQUENCY_NONE}. |
Siyamed Sinir | c0dab36 | 2018-07-22 13:48:51 -0700 | [diff] [blame] | 342 | * <p/> |
| 343 | * Enabling hyphenation with either using {@link Layout#HYPHENATION_FREQUENCY_NORMAL} or |
| 344 | * {@link Layout#HYPHENATION_FREQUENCY_FULL} while line breaking is set to one of |
| 345 | * {@link Layout#BREAK_STRATEGY_BALANCED}, {@link Layout#BREAK_STRATEGY_HIGH_QUALITY} |
| 346 | * improves the structure of text layout however has performance impact and requires more |
| 347 | * time to do the text layout. |
Roozbeh Pournader | 95c7a13 | 2015-05-12 12:01:06 -0700 | [diff] [blame] | 348 | * |
| 349 | * @param hyphenationFrequency hyphenation frequency for the paragraph |
| 350 | * @return this builder, useful for chaining |
| 351 | * @see android.widget.TextView#setHyphenationFrequency |
Siyamed Sinir | c0dab36 | 2018-07-22 13:48:51 -0700 | [diff] [blame] | 352 | * @see #setBreakStrategy(int) |
Roozbeh Pournader | 95c7a13 | 2015-05-12 12:01:06 -0700 | [diff] [blame] | 353 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 354 | @NonNull |
Roozbeh Pournader | 95c7a13 | 2015-05-12 12:01:06 -0700 | [diff] [blame] | 355 | public Builder setHyphenationFrequency(@HyphenationFrequency int hyphenationFrequency) { |
| 356 | mHyphenationFrequency = hyphenationFrequency; |
| 357 | return this; |
| 358 | } |
| 359 | |
| 360 | /** |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 361 | * Set indents. Arguments are arrays holding an indent amount, one per line, measured in |
| 362 | * pixels. For lines past the last element in the array, the last element repeats. |
| 363 | * |
| 364 | * @param leftIndents array of indent values for left margin, in pixels |
| 365 | * @param rightIndents array of indent values for right margin, in pixels |
| 366 | * @return this builder, useful for chaining |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 367 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 368 | @NonNull |
| 369 | public Builder setIndents(@Nullable int[] leftIndents, @Nullable int[] rightIndents) { |
Raph Levien | 2ea5290 | 2015-07-01 14:39:31 -0700 | [diff] [blame] | 370 | mLeftIndents = leftIndents; |
| 371 | mRightIndents = rightIndents; |
Raph Levien | e319d5a | 2015-04-14 23:51:07 -0700 | [diff] [blame] | 372 | return this; |
| 373 | } |
| 374 | |
Raph Levien | 70616ec | 2015-03-04 10:41:30 -0800 | [diff] [blame] | 375 | /** |
Seigo Nonaka | 4b4730d | 2017-03-31 09:42:16 -0700 | [diff] [blame] | 376 | * Set paragraph justification mode. The default value is |
| 377 | * {@link Layout#JUSTIFICATION_MODE_NONE}. If the last line is too short for justification, |
| 378 | * the last line will be displayed with the alignment set by {@link #setAlignment}. |
Haoyu Zhang | eccdc6b | 2019-01-07 15:11:46 -0800 | [diff] [blame] | 379 | * When Justification mode is JUSTIFICATION_MODE_INTER_WORD, wordSpacing on the given |
| 380 | * {@link Paint} will be ignored. This behavior also affects Spans which change the |
| 381 | * wordSpacing. |
Seigo Nonaka | 09da71a | 2016-11-28 16:24:14 +0900 | [diff] [blame] | 382 | * |
Seigo Nonaka | 4b4730d | 2017-03-31 09:42:16 -0700 | [diff] [blame] | 383 | * @param justificationMode justification mode for the paragraph. |
Seigo Nonaka | 09da71a | 2016-11-28 16:24:14 +0900 | [diff] [blame] | 384 | * @return this builder, useful for chaining. |
Haoyu Zhang | eccdc6b | 2019-01-07 15:11:46 -0800 | [diff] [blame] | 385 | * @see Paint#setWordSpacing(float) |
Seigo Nonaka | 09da71a | 2016-11-28 16:24:14 +0900 | [diff] [blame] | 386 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 387 | @NonNull |
Seigo Nonaka | 4b4730d | 2017-03-31 09:42:16 -0700 | [diff] [blame] | 388 | public Builder setJustificationMode(@JustificationMode int justificationMode) { |
| 389 | mJustificationMode = justificationMode; |
Seigo Nonaka | 09da71a | 2016-11-28 16:24:14 +0900 | [diff] [blame] | 390 | return this; |
| 391 | } |
| 392 | |
Siyamed Sinir | 442c151 | 2017-07-24 12:18:27 -0700 | [diff] [blame] | 393 | /** |
| 394 | * Sets whether the line spacing should be applied for the last line. Default value is |
| 395 | * {@code false}. |
| 396 | * |
| 397 | * @hide |
| 398 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 399 | @NonNull |
Siyamed Sinir | 442c151 | 2017-07-24 12:18:27 -0700 | [diff] [blame] | 400 | /* package */ Builder setAddLastLineLineSpacing(boolean value) { |
| 401 | mAddLastLineLineSpacing = value; |
| 402 | return this; |
| 403 | } |
| 404 | |
Seigo Nonaka | 09da71a | 2016-11-28 16:24:14 +0900 | [diff] [blame] | 405 | /** |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 406 | * Build the {@link StaticLayout} after options have been set. |
| 407 | * |
| 408 | * <p>Note: the builder object must not be reused in any way after calling this |
| 409 | * method. Setting parameters after calling this method, or calling it a second |
| 410 | * time on the same builder object, will likely lead to unexpected results. |
| 411 | * |
| 412 | * @return the newly constructed {@link StaticLayout} object |
| 413 | */ |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 414 | @NonNull |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 415 | public StaticLayout build() { |
Raph Levien | 39b4db7 | 2015-03-25 13:18:20 -0700 | [diff] [blame] | 416 | StaticLayout result = new StaticLayout(this); |
| 417 | Builder.recycle(this); |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 418 | return result; |
| 419 | } |
| 420 | |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 421 | private CharSequence mText; |
| 422 | private int mStart; |
| 423 | private int mEnd; |
| 424 | private TextPaint mPaint; |
| 425 | private int mWidth; |
| 426 | private Alignment mAlignment; |
| 427 | private TextDirectionHeuristic mTextDir; |
| 428 | private float mSpacingMult; |
| 429 | private float mSpacingAdd; |
| 430 | private boolean mIncludePad; |
| 431 | private boolean mFallbackLineSpacing; |
| 432 | private int mEllipsizedWidth; |
| 433 | private TextUtils.TruncateAt mEllipsize; |
| 434 | private int mMaxLines; |
| 435 | private int mBreakStrategy; |
| 436 | private int mHyphenationFrequency; |
Seigo Nonaka | bafe197 | 2017-08-24 15:30:29 -0700 | [diff] [blame] | 437 | @Nullable private int[] mLeftIndents; |
| 438 | @Nullable private int[] mRightIndents; |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 439 | private int mJustificationMode; |
| 440 | private boolean mAddLastLineLineSpacing; |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 441 | |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 442 | private final Paint.FontMetricsInt mFontMetricsInt = new Paint.FontMetricsInt(); |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 443 | |
Siyamed Sinir | a273a70 | 2017-10-05 11:22:12 -0700 | [diff] [blame] | 444 | private static final SynchronizedPool<Builder> sPool = new SynchronizedPool<>(3); |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 445 | } |
| 446 | |
Clara Bayarri | 81a4f2e | 2017-12-19 16:46:56 +0000 | [diff] [blame] | 447 | /** |
| 448 | * @deprecated Use {@link Builder} instead. |
| 449 | */ |
| 450 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | public StaticLayout(CharSequence source, TextPaint paint, |
| 452 | int width, |
| 453 | Alignment align, float spacingmult, float spacingadd, |
| 454 | boolean includepad) { |
| 455 | this(source, 0, source.length(), paint, width, align, |
| 456 | spacingmult, spacingadd, includepad); |
| 457 | } |
| 458 | |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 459 | /** |
Clara Bayarri | 81a4f2e | 2017-12-19 16:46:56 +0000 | [diff] [blame] | 460 | * @deprecated Use {@link Builder} instead. |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 461 | */ |
Clara Bayarri | 81a4f2e | 2017-12-19 16:46:56 +0000 | [diff] [blame] | 462 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | public StaticLayout(CharSequence source, int bufstart, int bufend, |
| 464 | TextPaint paint, int outerwidth, |
| 465 | Alignment align, |
| 466 | float spacingmult, float spacingadd, |
| 467 | boolean includepad) { |
| 468 | this(source, bufstart, bufend, paint, outerwidth, align, |
| 469 | spacingmult, spacingadd, includepad, null, 0); |
| 470 | } |
| 471 | |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 472 | /** |
Clara Bayarri | 81a4f2e | 2017-12-19 16:46:56 +0000 | [diff] [blame] | 473 | * @deprecated Use {@link Builder} instead. |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 474 | */ |
Clara Bayarri | 81a4f2e | 2017-12-19 16:46:56 +0000 | [diff] [blame] | 475 | @Deprecated |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 476 | public StaticLayout(CharSequence source, int bufstart, int bufend, |
| 477 | TextPaint paint, int outerwidth, |
| 478 | Alignment align, |
| 479 | float spacingmult, float spacingadd, |
| 480 | boolean includepad, |
| 481 | TextUtils.TruncateAt ellipsize, int ellipsizedWidth) { |
Seigo Nonaka | 4e90fa2 | 2018-02-13 21:40:01 +0000 | [diff] [blame] | 482 | this(source, bufstart, bufend, paint, outerwidth, align, |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 483 | TextDirectionHeuristics.FIRSTSTRONG_LTR, |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 484 | spacingmult, spacingadd, includepad, ellipsize, ellipsizedWidth, Integer.MAX_VALUE); |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | /** |
| 488 | * @hide |
Clara Bayarri | 81a4f2e | 2017-12-19 16:46:56 +0000 | [diff] [blame] | 489 | * @deprecated Use {@link Builder} instead. |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 490 | */ |
Clara Bayarri | 81a4f2e | 2017-12-19 16:46:56 +0000 | [diff] [blame] | 491 | @Deprecated |
Siyamed Sinir | 00589be | 2018-11-27 12:46:14 -0800 | [diff] [blame] | 492 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 117521430) |
Seigo Nonaka | 4e90fa2 | 2018-02-13 21:40:01 +0000 | [diff] [blame] | 493 | public StaticLayout(CharSequence source, int bufstart, int bufend, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | TextPaint paint, int outerwidth, |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 495 | Alignment align, TextDirectionHeuristic textDir, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | float spacingmult, float spacingadd, |
| 497 | boolean includepad, |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 498 | TextUtils.TruncateAt ellipsize, int ellipsizedWidth, int maxLines) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 499 | super((ellipsize == null) |
Doug Felt | 4e0c5e5 | 2010-03-15 16:56:02 -0700 | [diff] [blame] | 500 | ? source |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | : (source instanceof Spanned) |
| 502 | ? new SpannedEllipsizer(source) |
| 503 | : new Ellipsizer(source), |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 504 | paint, outerwidth, align, textDir, spacingmult, spacingadd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | |
Raph Levien | ebd66ca | 2015-04-30 15:27:57 -0700 | [diff] [blame] | 506 | Builder b = Builder.obtain(source, bufstart, bufend, paint, outerwidth) |
Raph Levien | 39b4db7 | 2015-03-25 13:18:20 -0700 | [diff] [blame] | 507 | .setAlignment(align) |
Raph Levien | a6a0828 | 2015-06-03 13:20:45 -0700 | [diff] [blame] | 508 | .setTextDirection(textDir) |
Raph Levien | 531c30c | 2015-04-30 16:29:59 -0700 | [diff] [blame] | 509 | .setLineSpacing(spacingadd, spacingmult) |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 510 | .setIncludePad(includepad) |
| 511 | .setEllipsizedWidth(ellipsizedWidth) |
| 512 | .setEllipsize(ellipsize) |
| 513 | .setMaxLines(maxLines); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | /* |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 515 | * This is annoying, but we can't refer to the layout until superclass construction is |
| 516 | * finished, and the superclass constructor wants the reference to the display text. |
Doug Felt | 4e0c5e5 | 2010-03-15 16:56:02 -0700 | [diff] [blame] | 517 | * |
Roozbeh Pournader | 22a167c | 2017-08-21 12:53:44 -0700 | [diff] [blame] | 518 | * In other words, the two Ellipsizer classes in Layout.java need a (Dynamic|Static)Layout |
| 519 | * as a parameter to do their calculations, but the Ellipsizers also need to be the input |
| 520 | * to the superclass's constructor (Layout). In order to go around the circular |
| 521 | * dependency, we construct the Ellipsizer with only one of the parameters, the text. And |
| 522 | * we fill in the rest of the needed information (layout, width, and method) later, here. |
| 523 | * |
| 524 | * This will break if the superclass constructor ever actually cares about the content |
| 525 | * instead of just holding the reference. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | */ |
| 527 | if (ellipsize != null) { |
| 528 | Ellipsizer e = (Ellipsizer) getText(); |
| 529 | |
| 530 | e.mLayout = this; |
| 531 | e.mWidth = ellipsizedWidth; |
| 532 | e.mMethod = ellipsize; |
| 533 | mEllipsizedWidth = ellipsizedWidth; |
| 534 | |
| 535 | mColumns = COLUMNS_ELLIPSIZE; |
| 536 | } else { |
| 537 | mColumns = COLUMNS_NORMAL; |
| 538 | mEllipsizedWidth = outerwidth; |
| 539 | } |
| 540 | |
Siyamed Sinir | af39851 | 2017-07-25 19:08:42 -0700 | [diff] [blame] | 541 | mLineDirections = ArrayUtils.newUnpaddedArray(Directions.class, 2); |
| 542 | mLines = ArrayUtils.newUnpaddedIntArray(2 * mColumns); |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 543 | mMaximumVisibleLineCount = maxLines; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | |
Raph Levien | 70616ec | 2015-03-04 10:41:30 -0800 | [diff] [blame] | 545 | generate(b, b.mIncludePad, b.mIncludePad); |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 546 | |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 547 | Builder.recycle(b); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 548 | } |
| 549 | |
Clara Bayarri | 81a4f2e | 2017-12-19 16:46:56 +0000 | [diff] [blame] | 550 | /** |
| 551 | * Used by DynamicLayout. |
| 552 | */ |
Roozbeh Pournader | e88b5df | 2017-07-25 13:52:57 -0700 | [diff] [blame] | 553 | /* package */ StaticLayout(@Nullable CharSequence text) { |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 554 | super(text, null, 0, null, 0, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | |
| 556 | mColumns = COLUMNS_ELLIPSIZE; |
Siyamed Sinir | af39851 | 2017-07-25 19:08:42 -0700 | [diff] [blame] | 557 | mLineDirections = ArrayUtils.newUnpaddedArray(Directions.class, 2); |
| 558 | mLines = ArrayUtils.newUnpaddedIntArray(2 * mColumns); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 559 | } |
| 560 | |
Raph Levien | 39b4db7 | 2015-03-25 13:18:20 -0700 | [diff] [blame] | 561 | private StaticLayout(Builder b) { |
| 562 | super((b.mEllipsize == null) |
| 563 | ? b.mText |
| 564 | : (b.mText instanceof Spanned) |
| 565 | ? new SpannedEllipsizer(b.mText) |
| 566 | : new Ellipsizer(b.mText), |
Roozbeh Pournader | 158dfaf | 2017-09-21 13:23:50 -0700 | [diff] [blame] | 567 | b.mPaint, b.mWidth, b.mAlignment, b.mTextDir, b.mSpacingMult, b.mSpacingAdd); |
Raph Levien | 39b4db7 | 2015-03-25 13:18:20 -0700 | [diff] [blame] | 568 | |
| 569 | if (b.mEllipsize != null) { |
| 570 | Ellipsizer e = (Ellipsizer) getText(); |
| 571 | |
| 572 | e.mLayout = this; |
| 573 | e.mWidth = b.mEllipsizedWidth; |
| 574 | e.mMethod = b.mEllipsize; |
| 575 | mEllipsizedWidth = b.mEllipsizedWidth; |
| 576 | |
| 577 | mColumns = COLUMNS_ELLIPSIZE; |
| 578 | } else { |
| 579 | mColumns = COLUMNS_NORMAL; |
| 580 | mEllipsizedWidth = b.mWidth; |
| 581 | } |
| 582 | |
Siyamed Sinir | af39851 | 2017-07-25 19:08:42 -0700 | [diff] [blame] | 583 | mLineDirections = ArrayUtils.newUnpaddedArray(Directions.class, 2); |
| 584 | mLines = ArrayUtils.newUnpaddedIntArray(2 * mColumns); |
Raph Levien | 39b4db7 | 2015-03-25 13:18:20 -0700 | [diff] [blame] | 585 | mMaximumVisibleLineCount = b.mMaxLines; |
| 586 | |
Raph Levien | 2ea5290 | 2015-07-01 14:39:31 -0700 | [diff] [blame] | 587 | mLeftIndents = b.mLeftIndents; |
| 588 | mRightIndents = b.mRightIndents; |
Seigo Nonaka | 4b4730d | 2017-03-31 09:42:16 -0700 | [diff] [blame] | 589 | setJustificationMode(b.mJustificationMode); |
Raph Levien | 2ea5290 | 2015-07-01 14:39:31 -0700 | [diff] [blame] | 590 | |
Raph Levien | 39b4db7 | 2015-03-25 13:18:20 -0700 | [diff] [blame] | 591 | generate(b, b.mIncludePad, b.mIncludePad); |
| 592 | } |
| 593 | |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 594 | /* package */ void generate(Builder b, boolean includepad, boolean trackpad) { |
Roozbeh Pournader | e88b5df | 2017-07-25 13:52:57 -0700 | [diff] [blame] | 595 | final CharSequence source = b.mText; |
Seigo Nonaka | fbe63bd | 2017-12-02 19:28:05 -0800 | [diff] [blame] | 596 | final int bufStart = b.mStart; |
| 597 | final int bufEnd = b.mEnd; |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 598 | TextPaint paint = b.mPaint; |
| 599 | int outerWidth = b.mWidth; |
| 600 | TextDirectionHeuristic textDir = b.mTextDir; |
Roozbeh Pournader | 737dfea | 2017-08-10 11:32:24 -0700 | [diff] [blame] | 601 | final boolean fallbackLineSpacing = b.mFallbackLineSpacing; |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 602 | float spacingmult = b.mSpacingMult; |
| 603 | float spacingadd = b.mSpacingAdd; |
| 604 | float ellipsizedWidth = b.mEllipsizedWidth; |
| 605 | TextUtils.TruncateAt ellipsize = b.mEllipsize; |
Siyamed Sinir | 442c151 | 2017-07-24 12:18:27 -0700 | [diff] [blame] | 606 | final boolean addLastLineSpacing = b.mAddLastLineLineSpacing; |
Seigo Nonaka | ab9b479 | 2018-09-24 17:37:15 -0700 | [diff] [blame] | 607 | |
| 608 | int lineBreakCapacity = 0; |
| 609 | int[] breaks = null; |
| 610 | float[] lineWidths = null; |
| 611 | float[] ascents = null; |
| 612 | float[] descents = null; |
| 613 | boolean[] hasTabs = null; |
| 614 | int[] hyphenEdits = null; |
Anish Athalye | 88b5b0b | 2014-06-24 14:39:43 -0700 | [diff] [blame] | 615 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | mLineCount = 0; |
Siyamed Sinir | a19cd51 | 2017-08-03 22:01:56 -0700 | [diff] [blame] | 617 | mEllipsized = false; |
Siyamed Sinir | a8d982d | 2017-08-21 13:27:47 -0700 | [diff] [blame] | 618 | mMaxLineHeight = mMaximumVisibleLineCount < 1 ? 0 : DEFAULT_MAX_LINE_HEIGHT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 619 | |
| 620 | int v = 0; |
| 621 | boolean needMultiply = (spacingmult != 1 || spacingadd != 0); |
| 622 | |
Raph Levien | d3ab692 | 2015-03-02 14:30:53 -0800 | [diff] [blame] | 623 | Paint.FontMetricsInt fm = b.mFontMetricsInt; |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 624 | int[] chooseHtv = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | |
Seigo Nonaka | bafe197 | 2017-08-24 15:30:29 -0700 | [diff] [blame] | 626 | final int[] indents; |
| 627 | if (mLeftIndents != null || mRightIndents != null) { |
| 628 | final int leftLen = mLeftIndents == null ? 0 : mLeftIndents.length; |
| 629 | final int rightLen = mRightIndents == null ? 0 : mRightIndents.length; |
| 630 | final int indentsLen = Math.max(leftLen, rightLen); |
| 631 | indents = new int[indentsLen]; |
| 632 | for (int i = 0; i < leftLen; i++) { |
| 633 | indents[i] = mLeftIndents[i]; |
| 634 | } |
| 635 | for (int i = 0; i < rightLen; i++) { |
| 636 | indents[i] += mRightIndents[i]; |
| 637 | } |
| 638 | } else { |
| 639 | indents = null; |
| 640 | } |
| 641 | |
Seigo Nonaka | 70200b0 | 2018-10-01 16:04:11 -0700 | [diff] [blame] | 642 | final LineBreaker lineBreaker = new LineBreaker.Builder() |
Seigo Nonaka | 41bb4fa | 2018-08-07 15:15:42 -0700 | [diff] [blame] | 643 | .setBreakStrategy(b.mBreakStrategy) |
| 644 | .setHyphenationFrequency(b.mHyphenationFrequency) |
Seigo Nonaka | b90e08f | 2017-10-20 15:23:51 -0700 | [diff] [blame] | 645 | // TODO: Support more justification mode, e.g. letter spacing, stretching. |
Seigo Nonaka | de41eea | 2019-03-07 16:19:05 -0800 | [diff] [blame] | 646 | .setJustificationMode(b.mJustificationMode) |
Seigo Nonaka | 41bb4fa | 2018-08-07 15:15:42 -0700 | [diff] [blame] | 647 | .setIndents(indents) |
| 648 | .build(); |
| 649 | |
Seigo Nonaka | 70200b0 | 2018-10-01 16:04:11 -0700 | [diff] [blame] | 650 | LineBreaker.ParagraphConstraints constraints = |
| 651 | new LineBreaker.ParagraphConstraints(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 652 | |
Seigo Nonaka | c3328d6 | 2018-03-20 15:18:59 -0700 | [diff] [blame] | 653 | PrecomputedText.ParagraphInfo[] paragraphInfo = null; |
| 654 | final Spanned spanned = (source instanceof Spanned) ? (Spanned) source : null; |
Seigo Nonaka | beafa1f | 2018-02-01 21:39:24 -0800 | [diff] [blame] | 655 | if (source instanceof PrecomputedText) { |
Seigo Nonaka | c3328d6 | 2018-03-20 15:18:59 -0700 | [diff] [blame] | 656 | PrecomputedText precomputed = (PrecomputedText) source; |
Seigo Nonaka | 291ef05 | 2018-11-16 10:41:32 -0800 | [diff] [blame] | 657 | final @PrecomputedText.Params.CheckResultUsableResult int checkResult = |
| 658 | precomputed.checkResultUsable(bufStart, bufEnd, textDir, paint, |
| 659 | b.mBreakStrategy, b.mHyphenationFrequency); |
| 660 | switch (checkResult) { |
| 661 | case PrecomputedText.Params.UNUSABLE: |
| 662 | break; |
| 663 | case PrecomputedText.Params.NEED_RECOMPUTE: |
| 664 | final PrecomputedText.Params newParams = |
| 665 | new PrecomputedText.Params.Builder(paint) |
| 666 | .setBreakStrategy(b.mBreakStrategy) |
| 667 | .setHyphenationFrequency(b.mHyphenationFrequency) |
| 668 | .setTextDirection(textDir) |
| 669 | .build(); |
| 670 | precomputed = PrecomputedText.create(precomputed, newParams); |
| 671 | paragraphInfo = precomputed.getParagraphInfo(); |
| 672 | break; |
| 673 | case PrecomputedText.Params.USABLE: |
| 674 | // Some parameters are different from the ones when measured text is created. |
| 675 | paragraphInfo = precomputed.getParagraphInfo(); |
| 676 | break; |
Seigo Nonaka | fbe63bd | 2017-12-02 19:28:05 -0800 | [diff] [blame] | 677 | } |
Seigo Nonaka | 87b1547 | 2018-01-12 14:06:29 -0800 | [diff] [blame] | 678 | } |
| 679 | |
Seigo Nonaka | c3328d6 | 2018-03-20 15:18:59 -0700 | [diff] [blame] | 680 | if (paragraphInfo == null) { |
Seigo Nonaka | beafa1f | 2018-02-01 21:39:24 -0800 | [diff] [blame] | 681 | final PrecomputedText.Params param = new PrecomputedText.Params(paint, textDir, |
| 682 | b.mBreakStrategy, b.mHyphenationFrequency); |
Seigo Nonaka | c3328d6 | 2018-03-20 15:18:59 -0700 | [diff] [blame] | 683 | paragraphInfo = PrecomputedText.createMeasuredParagraphs(source, param, bufStart, |
| 684 | bufEnd, false /* computeLayout */); |
Seigo Nonaka | 4e90fa2 | 2018-02-13 21:40:01 +0000 | [diff] [blame] | 685 | } |
Seigo Nonaka | fbe63bd | 2017-12-02 19:28:05 -0800 | [diff] [blame] | 686 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 687 | for (int paraIndex = 0; paraIndex < paragraphInfo.length; paraIndex++) { |
| 688 | final int paraStart = paraIndex == 0 |
| 689 | ? bufStart : paragraphInfo[paraIndex - 1].paragraphEnd; |
| 690 | final int paraEnd = paragraphInfo[paraIndex].paragraphEnd; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 691 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 692 | int firstWidthLineCount = 1; |
| 693 | int firstWidth = outerWidth; |
| 694 | int restWidth = outerWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 695 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 696 | LineHeightSpan[] chooseHt = null; |
| 697 | if (spanned != null) { |
| 698 | LeadingMarginSpan[] sp = getParagraphSpans(spanned, paraStart, paraEnd, |
| 699 | LeadingMarginSpan.class); |
| 700 | for (int i = 0; i < sp.length; i++) { |
| 701 | LeadingMarginSpan lms = sp[i]; |
| 702 | firstWidth -= sp[i].getLeadingMargin(true); |
| 703 | restWidth -= sp[i].getLeadingMargin(false); |
Doug Felt | cb379120 | 2011-07-07 11:57:48 -0700 | [diff] [blame] | 704 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 705 | // LeadingMarginSpan2 is odd. The count affects all |
| 706 | // leading margin spans, not just this particular one |
| 707 | if (lms instanceof LeadingMarginSpan2) { |
| 708 | LeadingMarginSpan2 lms2 = (LeadingMarginSpan2) lms; |
| 709 | firstWidthLineCount = Math.max(firstWidthLineCount, |
| 710 | lms2.getLeadingMarginLineCount()); |
| 711 | } |
| 712 | } |
Seigo Nonaka | b90e08f | 2017-10-20 15:23:51 -0700 | [diff] [blame] | 713 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 714 | chooseHt = getParagraphSpans(spanned, paraStart, paraEnd, LineHeightSpan.class); |
| 715 | |
| 716 | if (chooseHt.length == 0) { |
| 717 | chooseHt = null; // So that out() would not assume it has any contents |
| 718 | } else { |
| 719 | if (chooseHtv == null || chooseHtv.length < chooseHt.length) { |
| 720 | chooseHtv = ArrayUtils.newUnpaddedIntArray(chooseHt.length); |
Seigo Nonaka | b90e08f | 2017-10-20 15:23:51 -0700 | [diff] [blame] | 721 | } |
| 722 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 723 | for (int i = 0; i < chooseHt.length; i++) { |
| 724 | int o = spanned.getSpanStart(chooseHt[i]); |
Seigo Nonaka | b90e08f | 2017-10-20 15:23:51 -0700 | [diff] [blame] | 725 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 726 | if (o < paraStart) { |
| 727 | // starts in this layout, before the |
| 728 | // current paragraph |
| 729 | |
| 730 | chooseHtv[i] = getLineTop(getLineForOffset(o)); |
| 731 | } else { |
| 732 | // starts in this paragraph |
| 733 | |
| 734 | chooseHtv[i] = v; |
| 735 | } |
| 736 | } |
| 737 | } |
| 738 | } |
| 739 | // tab stop locations |
| 740 | int[] variableTabStops = null; |
| 741 | if (spanned != null) { |
| 742 | TabStopSpan[] spans = getParagraphSpans(spanned, paraStart, |
| 743 | paraEnd, TabStopSpan.class); |
| 744 | if (spans.length > 0) { |
| 745 | int[] stops = new int[spans.length]; |
| 746 | for (int i = 0; i < spans.length; i++) { |
| 747 | stops[i] = spans[i].getTabStop(); |
| 748 | } |
| 749 | Arrays.sort(stops, 0, stops.length); |
| 750 | variableTabStops = stops; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | final MeasuredParagraph measuredPara = paragraphInfo[paraIndex].measured; |
| 755 | final char[] chs = measuredPara.getChars(); |
| 756 | final int[] spanEndCache = measuredPara.getSpanEndCache().getRawArray(); |
| 757 | final int[] fmCache = measuredPara.getFontMetrics().getRawArray(); |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 758 | |
Seigo Nonaka | 41bb4fa | 2018-08-07 15:15:42 -0700 | [diff] [blame] | 759 | constraints.setWidth(restWidth); |
| 760 | constraints.setIndent(firstWidth, firstWidthLineCount); |
| 761 | constraints.setTabStops(variableTabStops, TAB_INCREMENT); |
| 762 | |
Seigo Nonaka | 70200b0 | 2018-10-01 16:04:11 -0700 | [diff] [blame] | 763 | LineBreaker.Result res = lineBreaker.computeLineBreaks( |
| 764 | measuredPara.getMeasuredText(), constraints, mLineCount); |
Seigo Nonaka | ab9b479 | 2018-09-24 17:37:15 -0700 | [diff] [blame] | 765 | int breakCount = res.getLineCount(); |
| 766 | if (lineBreakCapacity < breakCount) { |
| 767 | lineBreakCapacity = breakCount; |
| 768 | breaks = new int[lineBreakCapacity]; |
| 769 | lineWidths = new float[lineBreakCapacity]; |
| 770 | ascents = new float[lineBreakCapacity]; |
| 771 | descents = new float[lineBreakCapacity]; |
| 772 | hasTabs = new boolean[lineBreakCapacity]; |
| 773 | hyphenEdits = new int[lineBreakCapacity]; |
| 774 | } |
| 775 | |
| 776 | for (int i = 0; i < breakCount; ++i) { |
| 777 | breaks[i] = res.getLineBreakOffset(i); |
| 778 | lineWidths[i] = res.getLineWidth(i); |
| 779 | ascents[i] = res.getLineAscent(i); |
| 780 | descents[i] = res.getLineDescent(i); |
| 781 | hasTabs[i] = res.hasLineTab(i); |
Seigo Nonaka | fb1b479 | 2019-03-08 14:05:08 -0800 | [diff] [blame^] | 782 | hyphenEdits[i] = |
| 783 | packHyphenEdit(res.getStartLineHyphenEdit(i), res.getEndLineHyphenEdit(i)); |
Seigo Nonaka | ab9b479 | 2018-09-24 17:37:15 -0700 | [diff] [blame] | 784 | } |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 785 | |
| 786 | final int remainingLineCount = mMaximumVisibleLineCount - mLineCount; |
| 787 | final boolean ellipsisMayBeApplied = ellipsize != null |
| 788 | && (ellipsize == TextUtils.TruncateAt.END |
| 789 | || (mMaximumVisibleLineCount == 1 |
| 790 | && ellipsize != TextUtils.TruncateAt.MARQUEE)); |
| 791 | if (0 < remainingLineCount && remainingLineCount < breakCount |
| 792 | && ellipsisMayBeApplied) { |
| 793 | // Calculate width |
| 794 | float width = 0; |
Seigo Nonaka | ab9b479 | 2018-09-24 17:37:15 -0700 | [diff] [blame] | 795 | boolean hasTab = false; // XXX May need to also have starting hyphen edit |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 796 | for (int i = remainingLineCount - 1; i < breakCount; i++) { |
| 797 | if (i == breakCount - 1) { |
| 798 | width += lineWidths[i]; |
Seigo Nonaka | b90e08f | 2017-10-20 15:23:51 -0700 | [diff] [blame] | 799 | } else { |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 800 | for (int j = (i == 0 ? 0 : breaks[i - 1]); j < breaks[i]; j++) { |
Seigo Nonaka | 5783c13 | 2018-10-15 17:35:56 -0700 | [diff] [blame] | 801 | width += measuredPara.getCharWidthAt(j); |
Seigo Nonaka | b90e08f | 2017-10-20 15:23:51 -0700 | [diff] [blame] | 802 | } |
Mark Wagner | 7b5676e | 2009-10-16 11:44:23 -0700 | [diff] [blame] | 803 | } |
Seigo Nonaka | ab9b479 | 2018-09-24 17:37:15 -0700 | [diff] [blame] | 804 | hasTab |= hasTabs[i]; |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 805 | } |
| 806 | // Treat the last line and overflowed lines as a single line. |
| 807 | breaks[remainingLineCount - 1] = breaks[breakCount - 1]; |
| 808 | lineWidths[remainingLineCount - 1] = width; |
Seigo Nonaka | ab9b479 | 2018-09-24 17:37:15 -0700 | [diff] [blame] | 809 | hasTabs[remainingLineCount - 1] = hasTab; |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 810 | |
| 811 | breakCount = remainingLineCount; |
| 812 | } |
| 813 | |
| 814 | // here is the offset of the starting character of the line we are currently |
| 815 | // measuring |
| 816 | int here = paraStart; |
| 817 | |
| 818 | int fmTop = 0, fmBottom = 0, fmAscent = 0, fmDescent = 0; |
| 819 | int fmCacheIndex = 0; |
| 820 | int spanEndCacheIndex = 0; |
| 821 | int breakIndex = 0; |
| 822 | for (int spanStart = paraStart, spanEnd; spanStart < paraEnd; spanStart = spanEnd) { |
| 823 | // retrieve end of span |
| 824 | spanEnd = spanEndCache[spanEndCacheIndex++]; |
| 825 | |
| 826 | // retrieve cached metrics, order matches above |
| 827 | fm.top = fmCache[fmCacheIndex * 4 + 0]; |
| 828 | fm.bottom = fmCache[fmCacheIndex * 4 + 1]; |
| 829 | fm.ascent = fmCache[fmCacheIndex * 4 + 2]; |
| 830 | fm.descent = fmCache[fmCacheIndex * 4 + 3]; |
| 831 | fmCacheIndex++; |
| 832 | |
| 833 | if (fm.top < fmTop) { |
| 834 | fmTop = fm.top; |
| 835 | } |
| 836 | if (fm.ascent < fmAscent) { |
| 837 | fmAscent = fm.ascent; |
| 838 | } |
| 839 | if (fm.descent > fmDescent) { |
| 840 | fmDescent = fm.descent; |
| 841 | } |
| 842 | if (fm.bottom > fmBottom) { |
| 843 | fmBottom = fm.bottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | } |
| 845 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 846 | // skip breaks ending before current span range |
| 847 | while (breakIndex < breakCount && paraStart + breaks[breakIndex] < spanStart) { |
| 848 | breakIndex++; |
Seigo Nonaka | b90e08f | 2017-10-20 15:23:51 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 851 | while (breakIndex < breakCount && paraStart + breaks[breakIndex] <= spanEnd) { |
| 852 | int endPos = paraStart + breaks[breakIndex]; |
Seigo Nonaka | f1644f7 | 2017-11-27 22:09:49 -0800 | [diff] [blame] | 853 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 854 | boolean moreChars = (endPos < bufEnd); |
Seigo Nonaka | b90e08f | 2017-10-20 15:23:51 -0700 | [diff] [blame] | 855 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 856 | final int ascent = fallbackLineSpacing |
| 857 | ? Math.min(fmAscent, Math.round(ascents[breakIndex])) |
| 858 | : fmAscent; |
| 859 | final int descent = fallbackLineSpacing |
| 860 | ? Math.max(fmDescent, Math.round(descents[breakIndex])) |
| 861 | : fmDescent; |
Seigo Nonaka | b90e08f | 2017-10-20 15:23:51 -0700 | [diff] [blame] | 862 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 863 | v = out(source, here, endPos, |
| 864 | ascent, descent, fmTop, fmBottom, |
| 865 | v, spacingmult, spacingadd, chooseHt, chooseHtv, fm, |
Seigo Nonaka | ab9b479 | 2018-09-24 17:37:15 -0700 | [diff] [blame] | 866 | hasTabs[breakIndex], hyphenEdits[breakIndex], needMultiply, |
| 867 | measuredPara, bufEnd, includepad, trackpad, addLastLineSpacing, chs, |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 868 | paraStart, ellipsize, ellipsizedWidth, lineWidths[breakIndex], |
| 869 | paint, moreChars); |
Seigo Nonaka | b90e08f | 2017-10-20 15:23:51 -0700 | [diff] [blame] | 870 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 871 | if (endPos < spanEnd) { |
| 872 | // preserve metrics for current span |
Anish Athalye | c8f9e62 | 2014-07-21 15:26:34 -0700 | [diff] [blame] | 873 | fmTop = fm.top; |
Seigo Nonaka | b90e08f | 2017-10-20 15:23:51 -0700 | [diff] [blame] | 874 | fmBottom = fm.bottom; |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 875 | fmAscent = fm.ascent; |
| 876 | fmDescent = fm.descent; |
| 877 | } else { |
| 878 | fmTop = fmBottom = fmAscent = fmDescent = 0; |
Anish Athalye | c8f9e62 | 2014-07-21 15:26:34 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 881 | here = endPos; |
| 882 | breakIndex++; |
| 883 | |
| 884 | if (mLineCount >= mMaximumVisibleLineCount && mEllipsized) { |
| 885 | return; |
Anish Athalye | c8f9e62 | 2014-07-21 15:26:34 -0700 | [diff] [blame] | 886 | } |
| 887 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 888 | } |
| 889 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 890 | if (paraEnd == bufEnd) { |
| 891 | break; |
Seigo Nonaka | b90e08f | 2017-10-20 15:23:51 -0700 | [diff] [blame] | 892 | } |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | if ((bufEnd == bufStart || source.charAt(bufEnd - 1) == CHAR_NEW_LINE) |
| 896 | && mLineCount < mMaximumVisibleLineCount) { |
| 897 | final MeasuredParagraph measuredPara = |
| 898 | MeasuredParagraph.buildForBidi(source, bufEnd, bufEnd, textDir, null); |
| 899 | paint.getFontMetricsInt(fm); |
| 900 | v = out(source, |
| 901 | bufEnd, bufEnd, fm.ascent, fm.descent, |
| 902 | fm.top, fm.bottom, |
| 903 | v, |
| 904 | spacingmult, spacingadd, null, |
Seigo Nonaka | ab9b479 | 2018-09-24 17:37:15 -0700 | [diff] [blame] | 905 | null, fm, false, 0, |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 906 | needMultiply, measuredPara, bufEnd, |
| 907 | includepad, trackpad, addLastLineSpacing, null, |
| 908 | bufStart, ellipsize, |
| 909 | ellipsizedWidth, 0, paint, false); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 910 | } |
| 911 | } |
| 912 | |
Roozbeh Pournader | e88b5df | 2017-07-25 13:52:57 -0700 | [diff] [blame] | 913 | private int out(final CharSequence text, final int start, final int end, int above, int below, |
| 914 | int top, int bottom, int v, final float spacingmult, final float spacingadd, |
| 915 | final LineHeightSpan[] chooseHt, final int[] chooseHtv, final Paint.FontMetricsInt fm, |
Seigo Nonaka | ab9b479 | 2018-09-24 17:37:15 -0700 | [diff] [blame] | 916 | final boolean hasTab, final int hyphenEdit, final boolean needMultiply, |
| 917 | @NonNull final MeasuredParagraph measured, |
Seigo Nonaka | f1644f7 | 2017-11-27 22:09:49 -0800 | [diff] [blame] | 918 | final int bufEnd, final boolean includePad, final boolean trackPad, |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 919 | final boolean addLastLineLineSpacing, final char[] chs, |
Roozbeh Pournader | e88b5df | 2017-07-25 13:52:57 -0700 | [diff] [blame] | 920 | final int widthStart, final TextUtils.TruncateAt ellipsize, final float ellipsisWidth, |
| 921 | final float textWidth, final TextPaint paint, final boolean moreChars) { |
Siyamed Sinir | af39851 | 2017-07-25 19:08:42 -0700 | [diff] [blame] | 922 | final int j = mLineCount; |
| 923 | final int off = j * mColumns; |
| 924 | final int want = off + mColumns + TOP; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | int[] lines = mLines; |
Seigo Nonaka | 4b6bcee | 2017-12-11 11:39:51 -0800 | [diff] [blame] | 926 | final int dir = measured.getParagraphDir(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 927 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | if (want >= lines.length) { |
Siyamed Sinir | af39851 | 2017-07-25 19:08:42 -0700 | [diff] [blame] | 929 | final int[] grow = ArrayUtils.newUnpaddedIntArray(GrowingArrayUtils.growSize(want)); |
Adam Lesinski | 776abc2 | 2014-03-07 11:30:59 -0500 | [diff] [blame] | 930 | System.arraycopy(lines, 0, grow, 0, lines.length); |
| 931 | mLines = grow; |
| 932 | lines = grow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | } |
| 934 | |
Siyamed Sinir | af39851 | 2017-07-25 19:08:42 -0700 | [diff] [blame] | 935 | if (j >= mLineDirections.length) { |
| 936 | final Directions[] grow = ArrayUtils.newUnpaddedArray(Directions.class, |
| 937 | GrowingArrayUtils.growSize(j)); |
| 938 | System.arraycopy(mLineDirections, 0, grow, 0, mLineDirections.length); |
| 939 | mLineDirections = grow; |
| 940 | } |
| 941 | |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 942 | if (chooseHt != null) { |
| 943 | fm.ascent = above; |
| 944 | fm.descent = below; |
| 945 | fm.top = top; |
| 946 | fm.bottom = bottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 947 | |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 948 | for (int i = 0; i < chooseHt.length; i++) { |
| 949 | if (chooseHt[i] instanceof LineHeightSpan.WithDensity) { |
| 950 | ((LineHeightSpan.WithDensity) chooseHt[i]) |
| 951 | .chooseHeight(text, start, end, chooseHtv[i], v, fm, paint); |
| 952 | } else { |
| 953 | chooseHt[i].chooseHeight(text, start, end, chooseHtv[i], v, fm); |
| 954 | } |
| 955 | } |
Eric Fischer | a9f1dd0 | 2009-08-12 15:00:10 -0700 | [diff] [blame] | 956 | |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 957 | above = fm.ascent; |
| 958 | below = fm.descent; |
| 959 | top = fm.top; |
| 960 | bottom = fm.bottom; |
| 961 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 963 | boolean firstLine = (j == 0); |
| 964 | boolean currentLineIsTheLastVisibleOne = (j + 1 == mMaximumVisibleLineCount); |
Siyamed Sinir | 0745c72 | 2016-05-31 20:39:33 -0700 | [diff] [blame] | 965 | |
| 966 | if (ellipsize != null) { |
| 967 | // If there is only one line, then do any type of ellipsis except when it is MARQUEE |
| 968 | // if there are multiple lines, just allow END ellipsis on the last line |
| 969 | boolean forceEllipsis = moreChars && (mLineCount + 1 == mMaximumVisibleLineCount); |
| 970 | |
| 971 | boolean doEllipsis = |
| 972 | (((mMaximumVisibleLineCount == 1 && moreChars) || (firstLine && !moreChars)) && |
| 973 | ellipsize != TextUtils.TruncateAt.MARQUEE) || |
| 974 | (!firstLine && (currentLineIsTheLastVisibleOne || !moreChars) && |
| 975 | ellipsize == TextUtils.TruncateAt.END); |
| 976 | if (doEllipsis) { |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 977 | calculateEllipsis(start, end, measured, widthStart, |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 978 | ellipsisWidth, ellipsize, j, |
| 979 | textWidth, paint, forceEllipsis); |
Siyamed Sinir | 0745c72 | 2016-05-31 20:39:33 -0700 | [diff] [blame] | 980 | } |
| 981 | } |
| 982 | |
Siyamed Sinir | fb0b2dc | 2017-07-26 22:08:24 -0700 | [diff] [blame] | 983 | final boolean lastLine; |
| 984 | if (mEllipsized) { |
| 985 | lastLine = true; |
| 986 | } else { |
| 987 | final boolean lastCharIsNewLine = widthStart != bufEnd && bufEnd > 0 |
| 988 | && text.charAt(bufEnd - 1) == CHAR_NEW_LINE; |
| 989 | if (end == bufEnd && !lastCharIsNewLine) { |
| 990 | lastLine = true; |
| 991 | } else if (start == bufEnd && lastCharIsNewLine) { |
| 992 | lastLine = true; |
| 993 | } else { |
| 994 | lastLine = false; |
| 995 | } |
| 996 | } |
Raph Levien | d97b097 | 2014-04-24 12:51:35 -0700 | [diff] [blame] | 997 | |
| 998 | if (firstLine) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 999 | if (trackPad) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1000 | mTopPadding = top - above; |
| 1001 | } |
| 1002 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 1003 | if (includePad) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | above = top; |
| 1005 | } |
| 1006 | } |
Raph Levien | d97b097 | 2014-04-24 12:51:35 -0700 | [diff] [blame] | 1007 | |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1008 | int extra; |
| 1009 | |
Raph Levien | d97b097 | 2014-04-24 12:51:35 -0700 | [diff] [blame] | 1010 | if (lastLine) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 1011 | if (trackPad) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1012 | mBottomPadding = bottom - below; |
| 1013 | } |
| 1014 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 1015 | if (includePad) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1016 | below = bottom; |
| 1017 | } |
| 1018 | } |
| 1019 | |
Siyamed Sinir | 442c151 | 2017-07-24 12:18:27 -0700 | [diff] [blame] | 1020 | if (needMultiply && (addLastLineLineSpacing || !lastLine)) { |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1021 | double ex = (below - above) * (spacingmult - 1) + spacingadd; |
Doug Felt | 1065758 | 2010-02-22 11:19:01 -0800 | [diff] [blame] | 1022 | if (ex >= 0) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 1023 | extra = (int)(ex + EXTRA_ROUNDING); |
Doug Felt | 1065758 | 2010-02-22 11:19:01 -0800 | [diff] [blame] | 1024 | } else { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 1025 | extra = -(int)(-ex + EXTRA_ROUNDING); |
Doug Felt | 1065758 | 2010-02-22 11:19:01 -0800 | [diff] [blame] | 1026 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1027 | } else { |
| 1028 | extra = 0; |
| 1029 | } |
| 1030 | |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1031 | lines[off + START] = start; |
| 1032 | lines[off + TOP] = v; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | lines[off + DESCENT] = below + extra; |
Siyamed Sinir | 0fa89d6 | 2017-07-24 20:46:41 -0700 | [diff] [blame] | 1034 | lines[off + EXTRA] = extra; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | |
Siyamed Sinir | 0745c72 | 2016-05-31 20:39:33 -0700 | [diff] [blame] | 1036 | // special case for non-ellipsized last visible line when maxLines is set |
| 1037 | // store the height as if it was ellipsized |
| 1038 | if (!mEllipsized && currentLineIsTheLastVisibleOne) { |
| 1039 | // below calculation as if it was the last line |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1040 | int maxLineBelow = includePad ? bottom : below; |
Siyamed Sinir | 0745c72 | 2016-05-31 20:39:33 -0700 | [diff] [blame] | 1041 | // similar to the calculation of v below, without the extra. |
| 1042 | mMaxLineHeight = v + (maxLineBelow - above); |
| 1043 | } |
| 1044 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1045 | v += (below - above) + extra; |
| 1046 | lines[off + mColumns + START] = end; |
| 1047 | lines[off + mColumns + TOP] = v; |
| 1048 | |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1049 | // TODO: could move TAB to share same column as HYPHEN, simplifying this code and gaining |
| 1050 | // one bit for start field |
Seigo Nonaka | ab9b479 | 2018-09-24 17:37:15 -0700 | [diff] [blame] | 1051 | lines[off + TAB] |= hasTab ? TAB_MASK : 0; |
| 1052 | lines[off + HYPHEN] = hyphenEdit; |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1053 | lines[off + DIR] |= dir << DIR_SHIFT; |
| 1054 | mLineDirections[j] = measured.getDirections(start - widthStart, end - widthStart); |
| 1055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | mLineCount++; |
| 1057 | return v; |
| 1058 | } |
| 1059 | |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1060 | private void calculateEllipsis(int lineStart, int lineEnd, |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 1061 | MeasuredParagraph measured, int widthStart, |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1062 | float avail, TextUtils.TruncateAt where, |
| 1063 | int line, float textWidth, TextPaint paint, |
| 1064 | boolean forceEllipsis) { |
| 1065 | avail -= getTotalInsets(line); |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1066 | if (textWidth <= avail && !forceEllipsis) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1067 | // Everything fits! |
| 1068 | mLines[mColumns * line + ELLIPSIS_START] = 0; |
| 1069 | mLines[mColumns * line + ELLIPSIS_COUNT] = 0; |
| 1070 | return; |
| 1071 | } |
| 1072 | |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1073 | float ellipsisWidth = paint.measureText(TextUtils.getEllipsisString(where)); |
| 1074 | int ellipsisStart = 0; |
| 1075 | int ellipsisCount = 0; |
| 1076 | int len = lineEnd - lineStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1077 | |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1078 | // We only support start ellipsis on a single line |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1079 | if (where == TextUtils.TruncateAt.START) { |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1080 | if (mMaximumVisibleLineCount == 1) { |
| 1081 | float sum = 0; |
| 1082 | int i; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | |
Keisuke Kuroyanagi | ed2eea1 | 2015-04-14 18:18:35 +0900 | [diff] [blame] | 1084 | for (i = len; i > 0; i--) { |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 1085 | float w = measured.getCharWidthAt(i - 1 + lineStart - widthStart); |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1086 | if (w + sum + ellipsisWidth > avail) { |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 1087 | while (i < len |
| 1088 | && measured.getCharWidthAt(i + lineStart - widthStart) == 0.0f) { |
Keisuke Kuroyanagi | 82d1c44 | 2016-09-14 14:30:14 +0900 | [diff] [blame] | 1089 | i++; |
| 1090 | } |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1091 | break; |
| 1092 | } |
| 1093 | |
| 1094 | sum += w; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | } |
| 1096 | |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1097 | ellipsisStart = 0; |
| 1098 | ellipsisCount = i; |
| 1099 | } else { |
| 1100 | if (Log.isLoggable(TAG, Log.WARN)) { |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1101 | Log.w(TAG, "Start Ellipsis only supported with one line"); |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1102 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | } |
Fabrice Di Meglio | cb33264 | 2011-09-23 19:08:04 -0700 | [diff] [blame] | 1104 | } else if (where == TextUtils.TruncateAt.END || where == TextUtils.TruncateAt.MARQUEE || |
| 1105 | where == TextUtils.TruncateAt.END_SMALL) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | float sum = 0; |
| 1107 | int i; |
| 1108 | |
| 1109 | for (i = 0; i < len; i++) { |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 1110 | float w = measured.getCharWidthAt(i + lineStart - widthStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 1112 | if (w + sum + ellipsisWidth > avail) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1113 | break; |
| 1114 | } |
| 1115 | |
| 1116 | sum += w; |
| 1117 | } |
| 1118 | |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1119 | ellipsisStart = i; |
| 1120 | ellipsisCount = len - i; |
| 1121 | if (forceEllipsis && ellipsisCount == 0 && len > 0) { |
Fabrice Di Meglio | aef455f | 2011-08-29 15:39:11 -0700 | [diff] [blame] | 1122 | ellipsisStart = len - 1; |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1123 | ellipsisCount = 1; |
| 1124 | } |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1125 | } else { |
| 1126 | // where = TextUtils.TruncateAt.MIDDLE We only support middle ellipsis on a single line |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1127 | if (mMaximumVisibleLineCount == 1) { |
| 1128 | float lsum = 0, rsum = 0; |
| 1129 | int left = 0, right = len; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1131 | float ravail = (avail - ellipsisWidth) / 2; |
Raph Levien | 0e3c5e8 | 2014-12-04 13:26:07 -0800 | [diff] [blame] | 1132 | for (right = len; right > 0; right--) { |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 1133 | float w = measured.getCharWidthAt(right - 1 + lineStart - widthStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1135 | if (w + rsum > ravail) { |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 1136 | while (right < len |
| 1137 | && measured.getCharWidthAt(right + lineStart - widthStart) |
| 1138 | == 0.0f) { |
Keisuke Kuroyanagi | 82d1c44 | 2016-09-14 14:30:14 +0900 | [diff] [blame] | 1139 | right++; |
| 1140 | } |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1141 | break; |
| 1142 | } |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1143 | rsum += w; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1144 | } |
| 1145 | |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1146 | float lavail = avail - ellipsisWidth - rsum; |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1147 | for (left = 0; left < right; left++) { |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 1148 | float w = measured.getCharWidthAt(left + lineStart - widthStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1149 | |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1150 | if (w + lsum > lavail) { |
| 1151 | break; |
| 1152 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1154 | lsum += w; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | } |
| 1156 | |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1157 | ellipsisStart = left; |
| 1158 | ellipsisCount = right - left; |
| 1159 | } else { |
| 1160 | if (Log.isLoggable(TAG, Log.WARN)) { |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1161 | Log.w(TAG, "Middle Ellipsis only supported with one line"); |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1162 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1164 | } |
Siyamed Sinir | 1a5648a | 2018-01-23 16:40:06 -0800 | [diff] [blame] | 1165 | mEllipsized = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | mLines[mColumns * line + ELLIPSIS_START] = ellipsisStart; |
| 1167 | mLines[mColumns * line + ELLIPSIS_COUNT] = ellipsisCount; |
| 1168 | } |
| 1169 | |
Selim Cinek | 365ec09 | 2017-03-09 00:10:52 -0800 | [diff] [blame] | 1170 | private float getTotalInsets(int line) { |
| 1171 | int totalIndent = 0; |
| 1172 | if (mLeftIndents != null) { |
| 1173 | totalIndent = mLeftIndents[Math.min(line, mLeftIndents.length - 1)]; |
| 1174 | } |
| 1175 | if (mRightIndents != null) { |
| 1176 | totalIndent += mRightIndents[Math.min(line, mRightIndents.length - 1)]; |
| 1177 | } |
| 1178 | return totalIndent; |
| 1179 | } |
| 1180 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 1181 | // Override the base class so we can directly access our members, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | // rather than relying on member functions. |
| 1183 | // The logic mirrors that of Layout.getLineForVertical |
| 1184 | // FIXME: It may be faster to do a linear search for layouts without many lines. |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 1185 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | public int getLineForVertical(int vertical) { |
| 1187 | int high = mLineCount; |
| 1188 | int low = -1; |
| 1189 | int guess; |
| 1190 | int[] lines = mLines; |
| 1191 | while (high - low > 1) { |
| 1192 | guess = (high + low) >> 1; |
| 1193 | if (lines[mColumns * guess + TOP] > vertical){ |
| 1194 | high = guess; |
| 1195 | } else { |
| 1196 | low = guess; |
| 1197 | } |
| 1198 | } |
| 1199 | if (low < 0) { |
| 1200 | return 0; |
| 1201 | } else { |
| 1202 | return low; |
| 1203 | } |
| 1204 | } |
| 1205 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 1206 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1207 | public int getLineCount() { |
| 1208 | return mLineCount; |
| 1209 | } |
| 1210 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 1211 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1212 | public int getLineTop(int line) { |
Raph Levien | 07e6c23 | 2016-04-04 12:34:06 -0700 | [diff] [blame] | 1213 | return mLines[mColumns * line + TOP]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1214 | } |
| 1215 | |
Siyamed Sinir | 0fa89d6 | 2017-07-24 20:46:41 -0700 | [diff] [blame] | 1216 | /** |
| 1217 | * @hide |
| 1218 | */ |
| 1219 | @Override |
| 1220 | public int getLineExtra(int line) { |
| 1221 | return mLines[mColumns * line + EXTRA]; |
| 1222 | } |
| 1223 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 1224 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1225 | public int getLineDescent(int line) { |
Raph Levien | 07e6c23 | 2016-04-04 12:34:06 -0700 | [diff] [blame] | 1226 | return mLines[mColumns * line + DESCENT]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | } |
| 1228 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 1229 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1230 | public int getLineStart(int line) { |
| 1231 | return mLines[mColumns * line + START] & START_MASK; |
| 1232 | } |
| 1233 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 1234 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | public int getParagraphDirection(int line) { |
| 1236 | return mLines[mColumns * line + DIR] >> DIR_SHIFT; |
| 1237 | } |
| 1238 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 1239 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1240 | public boolean getLineContainsTab(int line) { |
| 1241 | return (mLines[mColumns * line + TAB] & TAB_MASK) != 0; |
| 1242 | } |
| 1243 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 1244 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1245 | public final Directions getLineDirections(int line) { |
Siyamed Sinir | 0fa89d6 | 2017-07-24 20:46:41 -0700 | [diff] [blame] | 1246 | if (line > getLineCount()) { |
| 1247 | throw new ArrayIndexOutOfBoundsException(); |
| 1248 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | return mLineDirections[line]; |
| 1250 | } |
| 1251 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 1252 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1253 | public int getTopPadding() { |
| 1254 | return mTopPadding; |
| 1255 | } |
| 1256 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 1257 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1258 | public int getBottomPadding() { |
| 1259 | return mBottomPadding; |
| 1260 | } |
| 1261 | |
Seigo Nonaka | fb1b479 | 2019-03-08 14:05:08 -0800 | [diff] [blame^] | 1262 | // To store into single int field, pack the pair of start and end hyphen edit. |
| 1263 | static int packHyphenEdit( |
| 1264 | @Paint.StartHyphenEdit int start, @Paint.EndHyphenEdit int end) { |
| 1265 | return start << START_HYPHEN_BITS_SHIFT | end; |
| 1266 | } |
| 1267 | |
| 1268 | static int unpackStartHyphenEdit(int packedHyphenEdit) { |
| 1269 | return (packedHyphenEdit & START_HYPHEN_MASK) >> START_HYPHEN_BITS_SHIFT; |
| 1270 | } |
| 1271 | |
| 1272 | static int unpackEndHyphenEdit(int packedHyphenEdit) { |
| 1273 | return packedHyphenEdit & END_HYPHEN_MASK; |
| 1274 | } |
| 1275 | |
Raph Levien | 26d443a | 2015-03-30 14:18:32 -0700 | [diff] [blame] | 1276 | /** |
Seigo Nonaka | fb1b479 | 2019-03-08 14:05:08 -0800 | [diff] [blame^] | 1277 | * Returns the start hyphen edit value for this line. |
Seigo Nonaka | 9033e0c | 2018-09-06 18:42:10 -0700 | [diff] [blame] | 1278 | * |
| 1279 | * @param lineNumber a line number |
Seigo Nonaka | fb1b479 | 2019-03-08 14:05:08 -0800 | [diff] [blame^] | 1280 | * @return A start hyphen edit value. |
Raph Levien | 26d443a | 2015-03-30 14:18:32 -0700 | [diff] [blame] | 1281 | * @hide |
| 1282 | */ |
| 1283 | @Override |
Seigo Nonaka | fb1b479 | 2019-03-08 14:05:08 -0800 | [diff] [blame^] | 1284 | public @Paint.StartHyphenEdit int getStartHyphenEdit(int lineNumber) { |
| 1285 | return unpackStartHyphenEdit(mLines[mColumns * lineNumber + HYPHEN] & HYPHEN_MASK); |
| 1286 | } |
| 1287 | |
| 1288 | /** |
| 1289 | * Returns the packed hyphen edit value for this line. |
| 1290 | * |
| 1291 | * @param lineNumber a line number |
| 1292 | * @return An end hyphen edit value. |
| 1293 | * @hide |
| 1294 | */ |
| 1295 | @Override |
| 1296 | public @Paint.EndHyphenEdit int getEndHyphenEdit(int lineNumber) { |
| 1297 | return unpackEndHyphenEdit(mLines[mColumns * lineNumber + HYPHEN] & HYPHEN_MASK); |
Raph Levien | 26d443a | 2015-03-30 14:18:32 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
Raph Levien | 2ea5290 | 2015-07-01 14:39:31 -0700 | [diff] [blame] | 1300 | /** |
| 1301 | * @hide |
| 1302 | */ |
| 1303 | @Override |
| 1304 | public int getIndentAdjust(int line, Alignment align) { |
| 1305 | if (align == Alignment.ALIGN_LEFT) { |
| 1306 | if (mLeftIndents == null) { |
| 1307 | return 0; |
| 1308 | } else { |
| 1309 | return mLeftIndents[Math.min(line, mLeftIndents.length - 1)]; |
| 1310 | } |
| 1311 | } else if (align == Alignment.ALIGN_RIGHT) { |
| 1312 | if (mRightIndents == null) { |
| 1313 | return 0; |
| 1314 | } else { |
| 1315 | return -mRightIndents[Math.min(line, mRightIndents.length - 1)]; |
| 1316 | } |
| 1317 | } else if (align == Alignment.ALIGN_CENTER) { |
| 1318 | int left = 0; |
| 1319 | if (mLeftIndents != null) { |
| 1320 | left = mLeftIndents[Math.min(line, mLeftIndents.length - 1)]; |
| 1321 | } |
| 1322 | int right = 0; |
| 1323 | if (mRightIndents != null) { |
| 1324 | right = mRightIndents[Math.min(line, mRightIndents.length - 1)]; |
| 1325 | } |
| 1326 | return (left - right) >> 1; |
| 1327 | } else { |
| 1328 | throw new AssertionError("unhandled alignment " + align); |
| 1329 | } |
| 1330 | } |
| 1331 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1332 | @Override |
| 1333 | public int getEllipsisCount(int line) { |
| 1334 | if (mColumns < COLUMNS_ELLIPSIZE) { |
| 1335 | return 0; |
| 1336 | } |
| 1337 | |
| 1338 | return mLines[mColumns * line + ELLIPSIS_COUNT]; |
| 1339 | } |
| 1340 | |
| 1341 | @Override |
| 1342 | public int getEllipsisStart(int line) { |
| 1343 | if (mColumns < COLUMNS_ELLIPSIZE) { |
| 1344 | return 0; |
| 1345 | } |
| 1346 | |
| 1347 | return mLines[mColumns * line + ELLIPSIS_START]; |
| 1348 | } |
| 1349 | |
| 1350 | @Override |
| 1351 | public int getEllipsizedWidth() { |
| 1352 | return mEllipsizedWidth; |
| 1353 | } |
| 1354 | |
Siyamed Sinir | 0745c72 | 2016-05-31 20:39:33 -0700 | [diff] [blame] | 1355 | /** |
| 1356 | * Return the total height of this layout. |
| 1357 | * |
| 1358 | * @param cap if true and max lines is set, returns the height of the layout at the max lines. |
| 1359 | * |
| 1360 | * @hide |
| 1361 | */ |
Mathew Inwood | 8c854f8 | 2018-09-14 12:35:36 +0100 | [diff] [blame] | 1362 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
Siyamed Sinir | 0745c72 | 2016-05-31 20:39:33 -0700 | [diff] [blame] | 1363 | public int getHeight(boolean cap) { |
Siyamed Sinir | 70ffd28 | 2018-03-08 17:19:46 -0800 | [diff] [blame] | 1364 | if (cap && mLineCount > mMaximumVisibleLineCount && mMaxLineHeight == -1 |
| 1365 | && Log.isLoggable(TAG, Log.WARN)) { |
Siyamed Sinir | 0745c72 | 2016-05-31 20:39:33 -0700 | [diff] [blame] | 1366 | Log.w(TAG, "maxLineHeight should not be -1. " |
| 1367 | + " maxLines:" + mMaximumVisibleLineCount |
| 1368 | + " lineCount:" + mLineCount); |
| 1369 | } |
| 1370 | |
Siyamed Sinir | 70ffd28 | 2018-03-08 17:19:46 -0800 | [diff] [blame] | 1371 | return cap && mLineCount > mMaximumVisibleLineCount && mMaxLineHeight != -1 |
| 1372 | ? mMaxLineHeight : super.getHeight(); |
Siyamed Sinir | 0745c72 | 2016-05-31 20:39:33 -0700 | [diff] [blame] | 1373 | } |
| 1374 | |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 1375 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1376 | private int mLineCount; |
| 1377 | private int mTopPadding, mBottomPadding; |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 1378 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1379 | private int mColumns; |
| 1380 | private int mEllipsizedWidth; |
| 1381 | |
Siyamed Sinir | 0745c72 | 2016-05-31 20:39:33 -0700 | [diff] [blame] | 1382 | /** |
| 1383 | * Keeps track if ellipsize is applied to the text. |
| 1384 | */ |
| 1385 | private boolean mEllipsized; |
| 1386 | |
| 1387 | /** |
| 1388 | * If maxLines is set, ellipsize is not set, and the actual line count of text is greater than |
| 1389 | * or equal to maxLine, this variable holds the ideal visual height of the maxLine'th line |
| 1390 | * starting from the top of the layout. If maxLines is not set its value will be -1. |
| 1391 | * |
| 1392 | * The value is the same as getLineTop(maxLines) for ellipsized version where structurally no |
| 1393 | * more than maxLines is contained. |
| 1394 | */ |
Siyamed Sinir | a19cd51 | 2017-08-03 22:01:56 -0700 | [diff] [blame] | 1395 | private int mMaxLineHeight = DEFAULT_MAX_LINE_HEIGHT; |
Siyamed Sinir | 0745c72 | 2016-05-31 20:39:33 -0700 | [diff] [blame] | 1396 | |
Siyamed Sinir | 0fa89d6 | 2017-07-24 20:46:41 -0700 | [diff] [blame] | 1397 | private static final int COLUMNS_NORMAL = 5; |
| 1398 | private static final int COLUMNS_ELLIPSIZE = 7; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1399 | private static final int START = 0; |
| 1400 | private static final int DIR = START; |
| 1401 | private static final int TAB = START; |
| 1402 | private static final int TOP = 1; |
| 1403 | private static final int DESCENT = 2; |
Siyamed Sinir | 0fa89d6 | 2017-07-24 20:46:41 -0700 | [diff] [blame] | 1404 | private static final int EXTRA = 3; |
| 1405 | private static final int HYPHEN = 4; |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 1406 | @UnsupportedAppUsage |
Siyamed Sinir | 0fa89d6 | 2017-07-24 20:46:41 -0700 | [diff] [blame] | 1407 | private static final int ELLIPSIS_START = 5; |
| 1408 | private static final int ELLIPSIS_COUNT = 6; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1409 | |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 1410 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1411 | private int[] mLines; |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 1412 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1413 | private Directions[] mLineDirections; |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 1414 | @UnsupportedAppUsage |
Fabrice Di Meglio | 8059e090 | 2011-08-10 16:31:58 -0700 | [diff] [blame] | 1415 | private int mMaximumVisibleLineCount = Integer.MAX_VALUE; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1416 | |
| 1417 | private static final int START_MASK = 0x1FFFFFFF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1418 | private static final int DIR_SHIFT = 30; |
| 1419 | private static final int TAB_MASK = 0x20000000; |
Keisuke Kuroyanagi | f5af4a3 | 2016-08-31 21:40:53 +0900 | [diff] [blame] | 1420 | private static final int HYPHEN_MASK = 0xFF; |
Seigo Nonaka | fb1b479 | 2019-03-08 14:05:08 -0800 | [diff] [blame^] | 1421 | private static final int START_HYPHEN_BITS_SHIFT = 3; |
| 1422 | private static final int START_HYPHEN_MASK = 0x18; // 0b11000 |
| 1423 | private static final int END_HYPHEN_MASK = 0x7; // 0b00111 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1424 | |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 1425 | private static final int TAB_INCREMENT = 20; // same as Layout, but that's private |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1426 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 1427 | private static final char CHAR_NEW_LINE = '\n'; |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 1428 | |
| 1429 | private static final double EXTRA_ROUNDING = 0.5; |
Fabrice Di Meglio | cb33264 | 2011-09-23 19:08:04 -0700 | [diff] [blame] | 1430 | |
Siyamed Sinir | a19cd51 | 2017-08-03 22:01:56 -0700 | [diff] [blame] | 1431 | private static final int DEFAULT_MAX_LINE_HEIGHT = -1; |
| 1432 | |
Seigo Nonaka | 6f11c6e | 2018-07-24 11:26:18 -0700 | [diff] [blame] | 1433 | // Unused, here because of gray list private API accesses. |
Deepanshu Gupta | 7053919 | 2014-10-15 15:57:40 -0700 | [diff] [blame] | 1434 | /*package*/ static class LineBreaks { |
Anish Athalye | c8f9e62 | 2014-07-21 15:26:34 -0700 | [diff] [blame] | 1435 | private static final int INITIAL_SIZE = 16; |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 1436 | @UnsupportedAppUsage |
Anish Athalye | c8f9e62 | 2014-07-21 15:26:34 -0700 | [diff] [blame] | 1437 | public int[] breaks = new int[INITIAL_SIZE]; |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 1438 | @UnsupportedAppUsage |
Anish Athalye | c8f9e62 | 2014-07-21 15:26:34 -0700 | [diff] [blame] | 1439 | public float[] widths = new float[INITIAL_SIZE]; |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 1440 | @UnsupportedAppUsage |
Roozbeh Pournader | 737dfea | 2017-08-10 11:32:24 -0700 | [diff] [blame] | 1441 | public float[] ascents = new float[INITIAL_SIZE]; |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 1442 | @UnsupportedAppUsage |
Roozbeh Pournader | 737dfea | 2017-08-10 11:32:24 -0700 | [diff] [blame] | 1443 | public float[] descents = new float[INITIAL_SIZE]; |
Mathew Inwood | efeab84 | 2018-08-14 15:21:30 +0100 | [diff] [blame] | 1444 | @UnsupportedAppUsage |
Roozbeh Pournader | 112d9c7 | 2015-08-07 12:44:41 -0700 | [diff] [blame] | 1445 | public int[] flags = new int[INITIAL_SIZE]; // hasTab |
Anish Athalye | c8f9e62 | 2014-07-21 15:26:34 -0700 | [diff] [blame] | 1446 | // breaks, widths, and flags should all have the same length |
| 1447 | } |
| 1448 | |
Seigo Nonaka | bafe197 | 2017-08-24 15:30:29 -0700 | [diff] [blame] | 1449 | @Nullable private int[] mLeftIndents; |
| 1450 | @Nullable private int[] mRightIndents; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | } |