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 | |
Doug Felt | 4e0c5e5 | 2010-03-15 16:56:02 -0700 | [diff] [blame] | 19 | import com.android.internal.util.ArrayUtils; |
| 20 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 21 | import android.graphics.Bitmap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.graphics.Paint; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.text.style.LeadingMarginSpan; |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 24 | import android.text.style.LeadingMarginSpan.LeadingMarginSpan2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.text.style.LineHeightSpan; |
| 26 | import android.text.style.MetricAffectingSpan; |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 27 | import android.text.style.TabStopSpan; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * StaticLayout is a Layout for text that will not be edited after it |
| 31 | * is laid out. Use {@link DynamicLayout} for text that may change. |
| 32 | * <p>This is used by widgets to control text layout. You should not need |
| 33 | * to use this class directly unless you are implementing your own widget |
| 34 | * or custom display object, or would be tempted to call |
Doug Felt | 4e0c5e5 | 2010-03-15 16:56:02 -0700 | [diff] [blame] | 35 | * {@link android.graphics.Canvas#drawText(java.lang.CharSequence, int, int, |
| 36 | * float, float, android.graphics.Paint) |
| 37 | * Canvas.drawText()} directly.</p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | */ |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 39 | public class StaticLayout extends Layout { |
| 40 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | public StaticLayout(CharSequence source, TextPaint paint, |
| 42 | int width, |
| 43 | Alignment align, float spacingmult, float spacingadd, |
| 44 | boolean includepad) { |
| 45 | this(source, 0, source.length(), paint, width, align, |
| 46 | spacingmult, spacingadd, includepad); |
| 47 | } |
| 48 | |
| 49 | public StaticLayout(CharSequence source, int bufstart, int bufend, |
| 50 | TextPaint paint, int outerwidth, |
| 51 | Alignment align, |
| 52 | float spacingmult, float spacingadd, |
| 53 | boolean includepad) { |
| 54 | this(source, bufstart, bufend, paint, outerwidth, align, |
| 55 | spacingmult, spacingadd, includepad, null, 0); |
| 56 | } |
| 57 | |
| 58 | public StaticLayout(CharSequence source, int bufstart, int bufend, |
| 59 | TextPaint paint, int outerwidth, |
| 60 | Alignment align, |
| 61 | float spacingmult, float spacingadd, |
| 62 | boolean includepad, |
| 63 | TextUtils.TruncateAt ellipsize, int ellipsizedWidth) { |
| 64 | super((ellipsize == null) |
Doug Felt | 4e0c5e5 | 2010-03-15 16:56:02 -0700 | [diff] [blame] | 65 | ? source |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | : (source instanceof Spanned) |
| 67 | ? new SpannedEllipsizer(source) |
| 68 | : new Ellipsizer(source), |
| 69 | paint, outerwidth, align, spacingmult, spacingadd); |
| 70 | |
| 71 | /* |
| 72 | * This is annoying, but we can't refer to the layout until |
| 73 | * superclass construction is finished, and the superclass |
| 74 | * constructor wants the reference to the display text. |
Doug Felt | 4e0c5e5 | 2010-03-15 16:56:02 -0700 | [diff] [blame] | 75 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | * This will break if the superclass constructor ever actually |
| 77 | * cares about the content instead of just holding the reference. |
| 78 | */ |
| 79 | if (ellipsize != null) { |
| 80 | Ellipsizer e = (Ellipsizer) getText(); |
| 81 | |
| 82 | e.mLayout = this; |
| 83 | e.mWidth = ellipsizedWidth; |
| 84 | e.mMethod = ellipsize; |
| 85 | mEllipsizedWidth = ellipsizedWidth; |
| 86 | |
| 87 | mColumns = COLUMNS_ELLIPSIZE; |
| 88 | } else { |
| 89 | mColumns = COLUMNS_NORMAL; |
| 90 | mEllipsizedWidth = outerwidth; |
| 91 | } |
| 92 | |
| 93 | mLines = new int[ArrayUtils.idealIntArraySize(2 * mColumns)]; |
| 94 | mLineDirections = new Directions[ |
| 95 | ArrayUtils.idealIntArraySize(2 * mColumns)]; |
| 96 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 97 | mMeasured = MeasuredText.obtain(); |
| 98 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | generate(source, bufstart, bufend, paint, outerwidth, align, |
| 100 | spacingmult, spacingadd, includepad, includepad, |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 101 | ellipsizedWidth, ellipsize); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 103 | mMeasured = MeasuredText.recycle(mMeasured); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | mFontMetricsInt = null; |
| 105 | } |
| 106 | |
| 107 | /* package */ StaticLayout(boolean ellipsize) { |
| 108 | super(null, null, 0, null, 0, 0); |
| 109 | |
| 110 | mColumns = COLUMNS_ELLIPSIZE; |
| 111 | mLines = new int[ArrayUtils.idealIntArraySize(2 * mColumns)]; |
| 112 | mLineDirections = new Directions[ |
| 113 | ArrayUtils.idealIntArraySize(2 * mColumns)]; |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 114 | mMeasured = MeasuredText.obtain(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 117 | /* package */ void generate(CharSequence source, int bufStart, int bufEnd, |
| 118 | TextPaint paint, int outerWidth, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | Alignment align, |
| 120 | float spacingmult, float spacingadd, |
| 121 | boolean includepad, boolean trackpad, |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 122 | float ellipsizedWidth, TextUtils.TruncateAt ellipsize) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | mLineCount = 0; |
| 124 | |
| 125 | int v = 0; |
| 126 | boolean needMultiply = (spacingmult != 1 || spacingadd != 0); |
| 127 | |
| 128 | Paint.FontMetricsInt fm = mFontMetricsInt; |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 129 | int[] chooseHtv = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 131 | MeasuredText measured = mMeasured; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | Spanned spanned = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | if (source instanceof Spanned) |
| 135 | spanned = (Spanned) source; |
| 136 | |
| 137 | int DEFAULT_DIR = DIR_LEFT_TO_RIGHT; // XXX |
| 138 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 139 | int paraEnd; |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 140 | for (int paraStart = bufStart; paraStart <= bufEnd; paraStart = paraEnd) { |
| 141 | paraEnd = TextUtils.indexOf(source, CHAR_NEW_LINE, paraStart, bufEnd); |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 142 | if (paraEnd < 0) |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 143 | paraEnd = bufEnd; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | else |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 145 | paraEnd++; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 147 | int firstWidthLineLimit = mLineCount + 1; |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 148 | int firstWidth = outerWidth; |
| 149 | int restWidth = outerWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 151 | LineHeightSpan[] chooseHt = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | |
| 153 | if (spanned != null) { |
Eric Fischer | 74d31ef | 2010-08-05 15:29:36 -0700 | [diff] [blame] | 154 | LeadingMarginSpan[] sp = getParagraphSpans(spanned, paraStart, paraEnd, |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 155 | LeadingMarginSpan.class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | for (int i = 0; i < sp.length; i++) { |
Mark Wagner | 7b5676e | 2009-10-16 11:44:23 -0700 | [diff] [blame] | 157 | LeadingMarginSpan lms = sp[i]; |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 158 | firstWidth -= sp[i].getLeadingMargin(true); |
| 159 | restWidth -= sp[i].getLeadingMargin(false); |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 160 | |
| 161 | // LeadingMarginSpan2 is odd. The count affects all |
| 162 | // leading margin spans, not just this particular one, |
| 163 | // and start from the top of the span, not the top of the |
| 164 | // paragraph. |
| 165 | if (lms instanceof LeadingMarginSpan2) { |
| 166 | LeadingMarginSpan2 lms2 = (LeadingMarginSpan2) lms; |
| 167 | int lmsFirstLine = getLineForOffset(spanned.getSpanStart(lms2)); |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 168 | firstWidthLineLimit = lmsFirstLine + lms2.getLeadingMarginLineCount(); |
Mark Wagner | 7b5676e | 2009-10-16 11:44:23 -0700 | [diff] [blame] | 169 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 172 | chooseHt = getParagraphSpans(spanned, paraStart, paraEnd, LineHeightSpan.class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 174 | if (chooseHt.length != 0) { |
| 175 | if (chooseHtv == null || |
| 176 | chooseHtv.length < chooseHt.length) { |
| 177 | chooseHtv = new int[ArrayUtils.idealIntArraySize( |
| 178 | chooseHt.length)]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 181 | for (int i = 0; i < chooseHt.length; i++) { |
| 182 | int o = spanned.getSpanStart(chooseHt[i]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 184 | if (o < paraStart) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | // starts in this layout, before the |
| 186 | // current paragraph |
| 187 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 188 | chooseHtv[i] = getLineTop(getLineForOffset(o)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | } else { |
| 190 | // starts in this paragraph |
| 191 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 192 | chooseHtv[i] = v; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 198 | measured.setPara(source, paraStart, paraEnd, DIR_REQUEST_DEFAULT_LTR); |
| 199 | char[] chs = measured.mChars; |
| 200 | float[] widths = measured.mWidths; |
| 201 | byte[] chdirs = measured.mLevels; |
| 202 | int dir = measured.mDir; |
| 203 | boolean easy = measured.mEasy; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 205 | int width = firstWidth; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | |
| 207 | float w = 0; |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 208 | int here = paraStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 210 | int ok = paraStart; |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 211 | float okWidth = w; |
| 212 | int okAscent = 0, okDescent = 0, okTop = 0, okBottom = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 214 | int fit = paraStart; |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 215 | float fitWidth = w; |
| 216 | int fitAscent = 0, fitDescent = 0, fitTop = 0, fitBottom = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 218 | boolean hasTabOrEmoji = false; |
| 219 | boolean hasTab = false; |
| 220 | TabStops tabStops = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | |
Doug Felt | 2324188 | 2010-06-02 14:41:06 -0700 | [diff] [blame] | 222 | for (int spanStart = paraStart, spanEnd = spanStart, nextSpanStart; |
| 223 | spanStart < paraEnd; spanStart = nextSpanStart) { |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 224 | |
Doug Felt | 2324188 | 2010-06-02 14:41:06 -0700 | [diff] [blame] | 225 | if (spanStart == spanEnd) { |
| 226 | if (spanned == null) |
| 227 | spanEnd = paraEnd; |
| 228 | else |
| 229 | spanEnd = spanned.nextSpanTransition(spanStart, paraEnd, |
| 230 | MetricAffectingSpan.class); |
| 231 | |
| 232 | int spanLen = spanEnd - spanStart; |
| 233 | if (spanned == null) { |
| 234 | measured.addStyleRun(paint, spanLen, fm); |
| 235 | } else { |
| 236 | MetricAffectingSpan[] spans = |
| 237 | spanned.getSpans(spanStart, spanEnd, MetricAffectingSpan.class); |
| 238 | measured.addStyleRun(paint, spans, spanLen, fm); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | nextSpanStart = spanEnd; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 244 | int fmTop = fm.top; |
| 245 | int fmBottom = fm.bottom; |
| 246 | int fmAscent = fm.ascent; |
| 247 | int fmDescent = fm.descent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 249 | for (int j = spanStart; j < spanEnd; j++) { |
| 250 | char c = chs[j - paraStart]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 252 | if (c == CHAR_NEW_LINE) { |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 253 | // intentionally left empty |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 254 | } else if (c == CHAR_TAB) { |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 255 | if (hasTab == false) { |
| 256 | hasTab = true; |
| 257 | hasTabOrEmoji = true; |
Kenny Root | 24ca454 | 2010-06-22 23:46:35 -0700 | [diff] [blame] | 258 | if (spanned != null) { |
| 259 | // First tab this para, check for tabstops |
Eric Fischer | 74d31ef | 2010-08-05 15:29:36 -0700 | [diff] [blame] | 260 | TabStopSpan[] spans = getParagraphSpans(spanned, paraStart, |
Kenny Root | 24ca454 | 2010-06-22 23:46:35 -0700 | [diff] [blame] | 261 | paraEnd, TabStopSpan.class); |
| 262 | if (spans.length > 0) { |
| 263 | tabStops = new TabStops(TAB_INCREMENT, spans); |
| 264 | } |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | if (tabStops != null) { |
| 268 | w = tabStops.nextTab(w); |
| 269 | } else { |
| 270 | w = TabStops.nextDefaultStop(w, TAB_INCREMENT); |
| 271 | } |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 272 | } else if (c >= CHAR_FIRST_HIGH_SURROGATE && c <= CHAR_LAST_LOW_SURROGATE |
| 273 | && j + 1 < spanEnd) { |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 274 | int emoji = Character.codePointAt(chs, j - paraStart); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 276 | if (emoji >= MIN_EMOJI && emoji <= MAX_EMOJI) { |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 277 | Bitmap bm = EMOJI_FACTORY.getBitmapFromAndroidPua(emoji); |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 278 | |
| 279 | if (bm != null) { |
Eric Fischer | 423f0e4 | 2009-03-27 18:04:12 -0700 | [diff] [blame] | 280 | Paint whichPaint; |
| 281 | |
| 282 | if (spanned == null) { |
| 283 | whichPaint = paint; |
| 284 | } else { |
| 285 | whichPaint = mWorkPaint; |
| 286 | } |
| 287 | |
Doug Felt | 4e0c5e5 | 2010-03-15 16:56:02 -0700 | [diff] [blame] | 288 | float wid = bm.getWidth() * |
Eric Fischer | 423f0e4 | 2009-03-27 18:04:12 -0700 | [diff] [blame] | 289 | -whichPaint.ascent() / |
| 290 | bm.getHeight(); |
| 291 | |
| 292 | w += wid; |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 293 | hasTabOrEmoji = true; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 294 | j++; |
| 295 | } else { |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 296 | w += widths[j - paraStart]; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 297 | } |
| 298 | } else { |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 299 | w += widths[j - paraStart]; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 300 | } |
| 301 | } else { |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 302 | w += widths[j - paraStart]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | // Log.e("text", "was " + before + " now " + w + " after " + c + " within " + width); |
| 306 | |
| 307 | if (w <= width) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 308 | fitWidth = w; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | fit = j + 1; |
| 310 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 311 | if (fmTop < fitTop) |
| 312 | fitTop = fmTop; |
| 313 | if (fmAscent < fitAscent) |
| 314 | fitAscent = fmAscent; |
| 315 | if (fmDescent > fitDescent) |
| 316 | fitDescent = fmDescent; |
| 317 | if (fmBottom > fitBottom) |
| 318 | fitBottom = fmBottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | |
| 320 | /* |
| 321 | * From the Unicode Line Breaking Algorithm: |
| 322 | * (at least approximately) |
Doug Felt | 4e0c5e5 | 2010-03-15 16:56:02 -0700 | [diff] [blame] | 323 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | * .,:; are class IS: breakpoints |
| 325 | * except when adjacent to digits |
| 326 | * / is class SY: a breakpoint |
| 327 | * except when followed by a digit. |
| 328 | * - is class HY: a breakpoint |
| 329 | * except when followed by a digit. |
| 330 | * |
Eric Fischer | 549d724 | 2009-03-31 14:19:47 -0700 | [diff] [blame] | 331 | * Ideographs are class ID: breakpoints when adjacent, |
| 332 | * except for NS (non-starters), which can be broken |
| 333 | * after but not before. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | */ |
| 335 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 336 | if (c == CHAR_SPACE || c == CHAR_TAB || |
| 337 | ((c == CHAR_DOT || c == CHAR_COMMA || |
| 338 | c == CHAR_COLON || c == CHAR_SEMICOLON) && |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 339 | (j - 1 < here || !Character.isDigit(chs[j - 1 - paraStart])) && |
| 340 | (j + 1 >= spanEnd || !Character.isDigit(chs[j + 1 - paraStart]))) || |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 341 | ((c == CHAR_SLASH || c == CHAR_HYPHEN) && |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 342 | (j + 1 >= spanEnd || !Character.isDigit(chs[j + 1 - paraStart]))) || |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 343 | (c >= CHAR_FIRST_CJK && isIdeographic(c, true) && |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 344 | j + 1 < spanEnd && isIdeographic(chs[j + 1 - paraStart], false))) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 345 | okWidth = w; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | ok = j + 1; |
| 347 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 348 | if (fitTop < okTop) |
| 349 | okTop = fitTop; |
| 350 | if (fitAscent < okAscent) |
| 351 | okAscent = fitAscent; |
| 352 | if (fitDescent > okDescent) |
| 353 | okDescent = fitDescent; |
| 354 | if (fitBottom > okBottom) |
| 355 | okBottom = fitBottom; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 356 | } |
Gilles Debunne | 4cf435d | 2011-01-04 15:35:29 -0800 | [diff] [blame] | 357 | } else { |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 358 | if (ellipsize != null) { |
| 359 | // Break only at spaces using ok indexes. |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 360 | if (ok != here) { |
| 361 | // Log.e("text", "output ok " + here + " to " +ok); |
Gilles Debunne | 32ea4ff | 2010-12-21 11:28:34 -0800 | [diff] [blame] | 362 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 363 | while (ok < spanEnd && chs[ok - paraStart] == CHAR_SPACE) { |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 364 | ok++; |
| 365 | } |
| 366 | |
| 367 | v = out(source, |
| 368 | here, ok, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 369 | okAscent, okDescent, okTop, okBottom, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 370 | v, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 371 | spacingmult, spacingadd, chooseHt, |
| 372 | chooseHtv, fm, hasTabOrEmoji, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 373 | needMultiply, paraStart, chdirs, dir, easy, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 374 | ok == bufEnd, includepad, trackpad, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 375 | chs, widths, here - paraStart, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 376 | ellipsize, ellipsizedWidth, okWidth, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 377 | paint); |
| 378 | |
| 379 | here = ok; |
| 380 | } else { |
| 381 | // Act like it fit even though it didn't. |
| 382 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 383 | fitWidth = w; |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 384 | here = fit = j + 1; |
| 385 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 386 | if (fmTop < fitTop) |
| 387 | fitTop = fmTop; |
| 388 | if (fmAscent < fitAscent) |
| 389 | fitAscent = fmAscent; |
| 390 | if (fmDescent > fitDescent) |
| 391 | fitDescent = fmDescent; |
| 392 | if (fmBottom > fitBottom) |
| 393 | fitBottom = fmBottom; |
Gilles Debunne | 32ea4ff | 2010-12-21 11:28:34 -0800 | [diff] [blame] | 394 | } |
Gilles Debunne | 4cf435d | 2011-01-04 15:35:29 -0800 | [diff] [blame] | 395 | } else { |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 396 | if (ok != here) { |
| 397 | // Log.e("text", "output ok " + here + " to " +ok); |
Gilles Debunne | 4cf435d | 2011-01-04 15:35:29 -0800 | [diff] [blame] | 398 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 399 | while (ok < spanEnd && chs[ok - paraStart] == CHAR_SPACE) { |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 400 | ok++; |
| 401 | } |
Gilles Debunne | 4cf435d | 2011-01-04 15:35:29 -0800 | [diff] [blame] | 402 | |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 403 | v = out(source, |
| 404 | here, ok, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 405 | okAscent, okDescent, okTop, okBottom, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 406 | v, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 407 | spacingmult, spacingadd, chooseHt, |
| 408 | chooseHtv, fm, hasTabOrEmoji, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 409 | needMultiply, paraStart, chdirs, dir, easy, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 410 | ok == bufEnd, includepad, trackpad, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 411 | chs, widths, here - paraStart, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 412 | ellipsize, ellipsizedWidth, okWidth, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 413 | paint); |
| 414 | |
| 415 | here = ok; |
| 416 | } else if (fit != here) { |
| 417 | // Log.e("text", "output fit " + here + " to " +fit); |
| 418 | v = out(source, |
| 419 | here, fit, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 420 | fitAscent, fitDescent, |
| 421 | fitTop, fitBottom, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 422 | v, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 423 | spacingmult, spacingadd, chooseHt, |
| 424 | chooseHtv, fm, hasTabOrEmoji, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 425 | needMultiply, paraStart, chdirs, dir, easy, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 426 | fit == bufEnd, includepad, trackpad, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 427 | chs, widths, here - paraStart, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 428 | ellipsize, ellipsizedWidth, fitWidth, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 429 | paint); |
| 430 | |
| 431 | here = fit; |
| 432 | } else { |
| 433 | // Log.e("text", "output one " + here + " to " +(here + 1)); |
| 434 | // XXX not sure why the existing fm wasn't ok. |
| 435 | // measureText(paint, mWorkPaint, |
| 436 | // source, here, here + 1, fm, tab, |
| 437 | // null); |
| 438 | |
| 439 | v = out(source, |
| 440 | here, here+1, |
| 441 | fm.ascent, fm.descent, |
| 442 | fm.top, fm.bottom, |
| 443 | v, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 444 | spacingmult, spacingadd, chooseHt, |
| 445 | chooseHtv, fm, hasTabOrEmoji, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 446 | needMultiply, paraStart, chdirs, dir, easy, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 447 | here + 1 == bufEnd, includepad, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 448 | trackpad, |
| 449 | chs, widths, here - paraStart, |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 450 | ellipsize, ellipsizedWidth, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 451 | widths[here - paraStart], paint); |
| 452 | |
| 453 | here = here + 1; |
| 454 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | } |
| 456 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 457 | if (here < spanStart) { |
Doug Felt | 2324188 | 2010-06-02 14:41:06 -0700 | [diff] [blame] | 458 | // didn't output all the text for this span |
| 459 | // we've measured the raw widths, though, so |
| 460 | // just reset the start point |
| 461 | j = nextSpanStart = here; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | } else { |
| 463 | j = here - 1; // continue looping |
| 464 | } |
| 465 | |
| 466 | ok = fit = here; |
| 467 | w = 0; |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 468 | fitAscent = fitDescent = fitTop = fitBottom = 0; |
| 469 | okAscent = okDescent = okTop = okBottom = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 470 | |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 471 | if (--firstWidthLineLimit <= 0) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 472 | width = restWidth; |
Mark Wagner | 7b5676e | 2009-10-16 11:44:23 -0700 | [diff] [blame] | 473 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 478 | if (paraEnd != here) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 479 | if ((fitTop | fitBottom | fitDescent | fitAscent) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | paint.getFontMetricsInt(fm); |
| 481 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 482 | fitTop = fm.top; |
| 483 | fitBottom = fm.bottom; |
| 484 | fitAscent = fm.ascent; |
| 485 | fitDescent = fm.descent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | // Log.e("text", "output rest " + here + " to " + end); |
| 489 | |
| 490 | v = out(source, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 491 | here, paraEnd, fitAscent, fitDescent, |
| 492 | fitTop, fitBottom, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | v, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 494 | spacingmult, spacingadd, chooseHt, |
| 495 | chooseHtv, fm, hasTabOrEmoji, |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 496 | needMultiply, paraStart, chdirs, dir, easy, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 497 | paraEnd == bufEnd, includepad, trackpad, |
Paul Eastham | be46d14 | 2011-02-04 19:17:54 -0800 | [diff] [blame] | 498 | chs, widths, here - paraStart, |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 499 | ellipsize, ellipsizedWidth, w, paint); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | } |
| 501 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 502 | paraStart = paraEnd; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 504 | if (paraEnd == bufEnd) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | break; |
| 506 | } |
| 507 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 508 | if (bufEnd == bufStart || source.charAt(bufEnd - 1) == CHAR_NEW_LINE) { |
| 509 | // Log.e("text", "output last " + bufEnd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 510 | |
| 511 | paint.getFontMetricsInt(fm); |
| 512 | |
| 513 | v = out(source, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 514 | bufEnd, bufEnd, fm.ascent, fm.descent, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | fm.top, fm.bottom, |
| 516 | v, |
| 517 | spacingmult, spacingadd, null, |
| 518 | null, fm, false, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 519 | needMultiply, bufEnd, null, DEFAULT_DIR, true, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | true, includepad, trackpad, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 521 | null, null, bufStart, |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 522 | ellipsize, ellipsizedWidth, 0, paint); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 523 | } |
| 524 | } |
| 525 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | /** |
| 527 | * Returns true if the specified character is one of those specified |
| 528 | * as being Ideographic (class ID) by the Unicode Line Breaking Algorithm |
| 529 | * (http://www.unicode.org/unicode/reports/tr14/), and is therefore OK |
| 530 | * to break between a pair of. |
Eric Fischer | 549d724 | 2009-03-31 14:19:47 -0700 | [diff] [blame] | 531 | * |
| 532 | * @param includeNonStarters also return true for category NS |
| 533 | * (non-starters), which can be broken |
| 534 | * after but not before. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | */ |
Eric Fischer | 549d724 | 2009-03-31 14:19:47 -0700 | [diff] [blame] | 536 | private static final boolean isIdeographic(char c, boolean includeNonStarters) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | if (c >= '\u2E80' && c <= '\u2FFF') { |
| 538 | return true; // CJK, KANGXI RADICALS, DESCRIPTION SYMBOLS |
| 539 | } |
| 540 | if (c == '\u3000') { |
| 541 | return true; // IDEOGRAPHIC SPACE |
| 542 | } |
| 543 | if (c >= '\u3040' && c <= '\u309F') { |
Eric Fischer | 549d724 | 2009-03-31 14:19:47 -0700 | [diff] [blame] | 544 | if (!includeNonStarters) { |
| 545 | switch (c) { |
| 546 | case '\u3041': // # HIRAGANA LETTER SMALL A |
| 547 | case '\u3043': // # HIRAGANA LETTER SMALL I |
| 548 | case '\u3045': // # HIRAGANA LETTER SMALL U |
| 549 | case '\u3047': // # HIRAGANA LETTER SMALL E |
| 550 | case '\u3049': // # HIRAGANA LETTER SMALL O |
| 551 | case '\u3063': // # HIRAGANA LETTER SMALL TU |
| 552 | case '\u3083': // # HIRAGANA LETTER SMALL YA |
| 553 | case '\u3085': // # HIRAGANA LETTER SMALL YU |
| 554 | case '\u3087': // # HIRAGANA LETTER SMALL YO |
| 555 | case '\u308E': // # HIRAGANA LETTER SMALL WA |
| 556 | case '\u3095': // # HIRAGANA LETTER SMALL KA |
| 557 | case '\u3096': // # HIRAGANA LETTER SMALL KE |
| 558 | case '\u309B': // # KATAKANA-HIRAGANA VOICED SOUND MARK |
| 559 | case '\u309C': // # KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK |
| 560 | case '\u309D': // # HIRAGANA ITERATION MARK |
| 561 | case '\u309E': // # HIRAGANA VOICED ITERATION MARK |
| 562 | return false; |
| 563 | } |
| 564 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | return true; // Hiragana (except small characters) |
| 566 | } |
| 567 | if (c >= '\u30A0' && c <= '\u30FF') { |
Eric Fischer | 549d724 | 2009-03-31 14:19:47 -0700 | [diff] [blame] | 568 | if (!includeNonStarters) { |
| 569 | switch (c) { |
| 570 | case '\u30A0': // # KATAKANA-HIRAGANA DOUBLE HYPHEN |
| 571 | case '\u30A1': // # KATAKANA LETTER SMALL A |
| 572 | case '\u30A3': // # KATAKANA LETTER SMALL I |
| 573 | case '\u30A5': // # KATAKANA LETTER SMALL U |
| 574 | case '\u30A7': // # KATAKANA LETTER SMALL E |
| 575 | case '\u30A9': // # KATAKANA LETTER SMALL O |
| 576 | case '\u30C3': // # KATAKANA LETTER SMALL TU |
| 577 | case '\u30E3': // # KATAKANA LETTER SMALL YA |
| 578 | case '\u30E5': // # KATAKANA LETTER SMALL YU |
| 579 | case '\u30E7': // # KATAKANA LETTER SMALL YO |
| 580 | case '\u30EE': // # KATAKANA LETTER SMALL WA |
| 581 | case '\u30F5': // # KATAKANA LETTER SMALL KA |
| 582 | case '\u30F6': // # KATAKANA LETTER SMALL KE |
| 583 | case '\u30FB': // # KATAKANA MIDDLE DOT |
| 584 | case '\u30FC': // # KATAKANA-HIRAGANA PROLONGED SOUND MARK |
| 585 | case '\u30FD': // # KATAKANA ITERATION MARK |
| 586 | case '\u30FE': // # KATAKANA VOICED ITERATION MARK |
| 587 | return false; |
| 588 | } |
| 589 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | return true; // Katakana (except small characters) |
| 591 | } |
| 592 | if (c >= '\u3400' && c <= '\u4DB5') { |
| 593 | return true; // CJK UNIFIED IDEOGRAPHS EXTENSION A |
| 594 | } |
| 595 | if (c >= '\u4E00' && c <= '\u9FBB') { |
| 596 | return true; // CJK UNIFIED IDEOGRAPHS |
| 597 | } |
| 598 | if (c >= '\uF900' && c <= '\uFAD9') { |
| 599 | return true; // CJK COMPATIBILITY IDEOGRAPHS |
| 600 | } |
| 601 | if (c >= '\uA000' && c <= '\uA48F') { |
| 602 | return true; // YI SYLLABLES |
| 603 | } |
| 604 | if (c >= '\uA490' && c <= '\uA4CF') { |
| 605 | return true; // YI RADICALS |
| 606 | } |
| 607 | if (c >= '\uFE62' && c <= '\uFE66') { |
| 608 | return true; // SMALL PLUS SIGN to SMALL EQUALS SIGN |
| 609 | } |
| 610 | if (c >= '\uFF10' && c <= '\uFF19') { |
| 611 | return true; // WIDE DIGITS |
| 612 | } |
| 613 | |
| 614 | return false; |
| 615 | } |
| 616 | |
| 617 | /* |
| 618 | private static void dump(byte[] data, int count, String label) { |
| 619 | if (false) { |
| 620 | System.out.print(label); |
| 621 | |
| 622 | for (int i = 0; i < count; i++) |
| 623 | System.out.print(" " + data[i]); |
| 624 | |
| 625 | System.out.println(); |
| 626 | } |
| 627 | } |
| 628 | */ |
| 629 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | private int out(CharSequence text, int start, int end, |
| 631 | int above, int below, int top, int bottom, int v, |
| 632 | float spacingmult, float spacingadd, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 633 | LineHeightSpan[] chooseHt, int[] chooseHtv, |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 634 | Paint.FontMetricsInt fm, boolean hasTabOrEmoji, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | boolean needMultiply, int pstart, byte[] chdirs, |
| 636 | int dir, boolean easy, boolean last, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 637 | boolean includePad, boolean trackPad, |
| 638 | char[] chs, float[] widths, int widthStart, |
| 639 | TextUtils.TruncateAt ellipsize, float ellipsisWidth, |
| 640 | float textWidth, TextPaint paint) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | int j = mLineCount; |
| 642 | int off = j * mColumns; |
| 643 | int want = off + mColumns + TOP; |
| 644 | int[] lines = mLines; |
| 645 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 646 | if (want >= lines.length) { |
| 647 | int nlen = ArrayUtils.idealIntArraySize(want + 1); |
| 648 | int[] grow = new int[nlen]; |
| 649 | System.arraycopy(lines, 0, grow, 0, lines.length); |
| 650 | mLines = grow; |
| 651 | lines = grow; |
| 652 | |
| 653 | Directions[] grow2 = new Directions[nlen]; |
| 654 | System.arraycopy(mLineDirections, 0, grow2, 0, |
| 655 | mLineDirections.length); |
| 656 | mLineDirections = grow2; |
| 657 | } |
| 658 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 659 | if (chooseHt != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 660 | fm.ascent = above; |
| 661 | fm.descent = below; |
| 662 | fm.top = top; |
| 663 | fm.bottom = bottom; |
| 664 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 665 | for (int i = 0; i < chooseHt.length; i++) { |
| 666 | if (chooseHt[i] instanceof LineHeightSpan.WithDensity) { |
| 667 | ((LineHeightSpan.WithDensity) chooseHt[i]). |
| 668 | chooseHeight(text, start, end, chooseHtv[i], v, fm, paint); |
Eric Fischer | a9f1dd0 | 2009-08-12 15:00:10 -0700 | [diff] [blame] | 669 | |
| 670 | } else { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 671 | chooseHt[i].chooseHeight(text, start, end, chooseHtv[i], v, fm); |
Eric Fischer | a9f1dd0 | 2009-08-12 15:00:10 -0700 | [diff] [blame] | 672 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | above = fm.ascent; |
| 676 | below = fm.descent; |
| 677 | top = fm.top; |
| 678 | bottom = fm.bottom; |
| 679 | } |
| 680 | |
| 681 | if (j == 0) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 682 | if (trackPad) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 683 | mTopPadding = top - above; |
| 684 | } |
| 685 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 686 | if (includePad) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | above = top; |
| 688 | } |
| 689 | } |
| 690 | if (last) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 691 | if (trackPad) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 692 | mBottomPadding = bottom - below; |
| 693 | } |
| 694 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 695 | if (includePad) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 696 | below = bottom; |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | int extra; |
| 701 | |
| 702 | if (needMultiply) { |
Doug Felt | 1065758 | 2010-02-22 11:19:01 -0800 | [diff] [blame] | 703 | double ex = (below - above) * (spacingmult - 1) + spacingadd; |
| 704 | if (ex >= 0) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 705 | extra = (int)(ex + EXTRA_ROUNDING); |
Doug Felt | 1065758 | 2010-02-22 11:19:01 -0800 | [diff] [blame] | 706 | } else { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 707 | extra = -(int)(-ex + EXTRA_ROUNDING); |
Doug Felt | 1065758 | 2010-02-22 11:19:01 -0800 | [diff] [blame] | 708 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 709 | } else { |
| 710 | extra = 0; |
| 711 | } |
| 712 | |
| 713 | lines[off + START] = start; |
| 714 | lines[off + TOP] = v; |
| 715 | lines[off + DESCENT] = below + extra; |
| 716 | |
| 717 | v += (below - above) + extra; |
| 718 | lines[off + mColumns + START] = end; |
| 719 | lines[off + mColumns + TOP] = v; |
| 720 | |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 721 | if (hasTabOrEmoji) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 722 | lines[off + TAB] |= TAB_MASK; |
| 723 | |
Doug Felt | 9f7a444 | 2010-03-01 12:45:56 -0800 | [diff] [blame] | 724 | lines[off + DIR] |= dir << DIR_SHIFT; |
| 725 | Directions linedirs = DIRS_ALL_LEFT_TO_RIGHT; |
| 726 | // easy means all chars < the first RTL, so no emoji, no nothing |
Doug Felt | 4e0c5e5 | 2010-03-15 16:56:02 -0700 | [diff] [blame] | 727 | // XXX a run with no text or all spaces is easy but might be an empty |
Doug Felt | 9f7a444 | 2010-03-01 12:45:56 -0800 | [diff] [blame] | 728 | // RTL paragraph. Make sure easy is false if this is the case. |
| 729 | if (easy) { |
| 730 | mLineDirections[j] = linedirs; |
| 731 | } else { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 732 | mLineDirections[j] = AndroidBidi.directions(dir, chdirs, widthStart, chs, |
| 733 | widthStart, end - start); |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 734 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 735 | |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 736 | // If ellipsize is in marquee mode, do not apply ellipsis on the first line |
| 737 | if (ellipsize != null && (ellipsize != TextUtils.TruncateAt.MARQUEE || j != 0)) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 738 | calculateEllipsis(start, end, widths, widthStart, |
| 739 | ellipsisWidth, ellipsize, j, |
| 740 | textWidth, paint); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | mLineCount++; |
| 744 | return v; |
| 745 | } |
| 746 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 747 | private void calculateEllipsis(int lineStart, int lineEnd, |
| 748 | float[] widths, int widthStart, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 749 | float avail, TextUtils.TruncateAt where, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 750 | int line, float textWidth, TextPaint paint) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 751 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 752 | if (textWidth <= avail) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 753 | // Everything fits! |
| 754 | mLines[mColumns * line + ELLIPSIS_START] = 0; |
| 755 | mLines[mColumns * line + ELLIPSIS_COUNT] = 0; |
| 756 | return; |
| 757 | } |
| 758 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 759 | float ellipsisWidth = paint.measureText(HORIZONTAL_ELLIPSIS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 760 | int ellipsisStart, ellipsisCount; |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 761 | int len = lineEnd - lineStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 762 | |
| 763 | if (where == TextUtils.TruncateAt.START) { |
| 764 | float sum = 0; |
| 765 | int i; |
| 766 | |
| 767 | for (i = len; i >= 0; i--) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 768 | float w = widths[i - 1 + lineStart - widthStart]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 769 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 770 | if (w + sum + ellipsisWidth > avail) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 771 | break; |
| 772 | } |
| 773 | |
| 774 | sum += w; |
| 775 | } |
| 776 | |
| 777 | ellipsisStart = 0; |
| 778 | ellipsisCount = i; |
| 779 | } else if (where == TextUtils.TruncateAt.END || where == TextUtils.TruncateAt.MARQUEE) { |
| 780 | float sum = 0; |
| 781 | int i; |
| 782 | |
| 783 | for (i = 0; i < len; i++) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 784 | float w = widths[i + lineStart - widthStart]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 785 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 786 | if (w + sum + ellipsisWidth > avail) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | break; |
| 788 | } |
| 789 | |
| 790 | sum += w; |
| 791 | } |
| 792 | |
| 793 | ellipsisStart = i; |
| 794 | ellipsisCount = len - i; |
| 795 | } else /* where = TextUtils.TruncateAt.MIDDLE */ { |
| 796 | float lsum = 0, rsum = 0; |
| 797 | int left = 0, right = len; |
| 798 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 799 | float ravail = (avail - ellipsisWidth) / 2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 800 | for (right = len; right >= 0; right--) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 801 | float w = widths[right - 1 + lineStart - widthStart]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 802 | |
| 803 | if (w + rsum > ravail) { |
| 804 | break; |
| 805 | } |
| 806 | |
| 807 | rsum += w; |
| 808 | } |
| 809 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 810 | float lavail = avail - ellipsisWidth - rsum; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 811 | for (left = 0; left < right; left++) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 812 | float w = widths[left + lineStart - widthStart]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 813 | |
| 814 | if (w + lsum > lavail) { |
| 815 | break; |
| 816 | } |
| 817 | |
| 818 | lsum += w; |
| 819 | } |
| 820 | |
| 821 | ellipsisStart = left; |
| 822 | ellipsisCount = right - left; |
| 823 | } |
| 824 | |
| 825 | mLines[mColumns * line + ELLIPSIS_START] = ellipsisStart; |
| 826 | mLines[mColumns * line + ELLIPSIS_COUNT] = ellipsisCount; |
| 827 | } |
| 828 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 829 | // 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] | 830 | // rather than relying on member functions. |
| 831 | // The logic mirrors that of Layout.getLineForVertical |
| 832 | // 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] | 833 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | public int getLineForVertical(int vertical) { |
| 835 | int high = mLineCount; |
| 836 | int low = -1; |
| 837 | int guess; |
| 838 | int[] lines = mLines; |
| 839 | while (high - low > 1) { |
| 840 | guess = (high + low) >> 1; |
| 841 | if (lines[mColumns * guess + TOP] > vertical){ |
| 842 | high = guess; |
| 843 | } else { |
| 844 | low = guess; |
| 845 | } |
| 846 | } |
| 847 | if (low < 0) { |
| 848 | return 0; |
| 849 | } else { |
| 850 | return low; |
| 851 | } |
| 852 | } |
| 853 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 854 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | public int getLineCount() { |
| 856 | return mLineCount; |
| 857 | } |
| 858 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 859 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 860 | public int getLineTop(int line) { |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 861 | int top = mLines[mColumns * line + TOP]; |
| 862 | if (mMaximumVisibleLineCount > 0 && line >= mMaximumVisibleLineCount && |
| 863 | line != mLineCount) { |
| 864 | top += getBottomPadding(); |
| 865 | } |
| 866 | return top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 867 | } |
| 868 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 869 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 870 | public int getLineDescent(int line) { |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 871 | int descent = mLines[mColumns * line + DESCENT]; |
| 872 | if (mMaximumVisibleLineCount > 0 && line >= mMaximumVisibleLineCount - 1 && |
| 873 | line != mLineCount) { |
| 874 | descent += getBottomPadding(); |
| 875 | } |
| 876 | return descent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 877 | } |
| 878 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 879 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 880 | public int getLineStart(int line) { |
| 881 | return mLines[mColumns * line + START] & START_MASK; |
| 882 | } |
| 883 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 884 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 885 | public int getParagraphDirection(int line) { |
| 886 | return mLines[mColumns * line + DIR] >> DIR_SHIFT; |
| 887 | } |
| 888 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 889 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | public boolean getLineContainsTab(int line) { |
| 891 | return (mLines[mColumns * line + TAB] & TAB_MASK) != 0; |
| 892 | } |
| 893 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 894 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 895 | public final Directions getLineDirections(int line) { |
| 896 | return mLineDirections[line]; |
| 897 | } |
| 898 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 899 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 900 | public int getTopPadding() { |
| 901 | return mTopPadding; |
| 902 | } |
| 903 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 904 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 905 | public int getBottomPadding() { |
| 906 | return mBottomPadding; |
| 907 | } |
| 908 | |
| 909 | @Override |
| 910 | public int getEllipsisCount(int line) { |
| 911 | if (mColumns < COLUMNS_ELLIPSIZE) { |
| 912 | return 0; |
| 913 | } |
| 914 | |
| 915 | return mLines[mColumns * line + ELLIPSIS_COUNT]; |
| 916 | } |
| 917 | |
| 918 | @Override |
| 919 | public int getEllipsisStart(int line) { |
| 920 | if (mColumns < COLUMNS_ELLIPSIZE) { |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | return mLines[mColumns * line + ELLIPSIS_START]; |
| 925 | } |
| 926 | |
| 927 | @Override |
| 928 | public int getEllipsizedWidth() { |
| 929 | return mEllipsizedWidth; |
| 930 | } |
| 931 | |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 932 | /** |
| 933 | * @hide |
| 934 | */ |
| 935 | @Override |
| 936 | public void setMaximumVisibleLineCount(int line) { |
| 937 | mMaximumVisibleLineCount = line; |
| 938 | } |
| 939 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 940 | private int mLineCount; |
| 941 | private int mTopPadding, mBottomPadding; |
| 942 | private int mColumns; |
| 943 | private int mEllipsizedWidth; |
| 944 | |
| 945 | private static final int COLUMNS_NORMAL = 3; |
| 946 | private static final int COLUMNS_ELLIPSIZE = 5; |
| 947 | private static final int START = 0; |
| 948 | private static final int DIR = START; |
| 949 | private static final int TAB = START; |
| 950 | private static final int TOP = 1; |
| 951 | private static final int DESCENT = 2; |
| 952 | private static final int ELLIPSIS_START = 3; |
| 953 | private static final int ELLIPSIS_COUNT = 4; |
| 954 | |
| 955 | private int[] mLines; |
| 956 | private Directions[] mLineDirections; |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 957 | private int mMaximumVisibleLineCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 958 | |
| 959 | private static final int START_MASK = 0x1FFFFFFF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 960 | private static final int DIR_SHIFT = 30; |
| 961 | private static final int TAB_MASK = 0x20000000; |
| 962 | |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 963 | 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] | 964 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame^] | 965 | private static final char CHAR_FIRST_CJK = '\u2E80'; |
| 966 | |
| 967 | private static final char CHAR_NEW_LINE = '\n'; |
| 968 | private static final char CHAR_TAB = '\t'; |
| 969 | private static final char CHAR_SPACE = ' '; |
| 970 | private static final char CHAR_DOT = '.'; |
| 971 | private static final char CHAR_COMMA = ','; |
| 972 | private static final char CHAR_COLON = ':'; |
| 973 | private static final char CHAR_SEMICOLON = ';'; |
| 974 | private static final char CHAR_SLASH = '/'; |
| 975 | private static final char CHAR_HYPHEN = '-'; |
| 976 | |
| 977 | private static final double EXTRA_ROUNDING = 0.5; |
| 978 | private static final String HORIZONTAL_ELLIPSIS = "\u2026"; // this is "..." |
| 979 | |
| 980 | private static final int CHAR_FIRST_HIGH_SURROGATE = 0xD800; |
| 981 | private static final int CHAR_LAST_LOW_SURROGATE = 0xDFFF; |
| 982 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 983 | /* |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 984 | * This is reused across calls to generate() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 985 | */ |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 986 | private MeasuredText mMeasured; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 987 | private Paint.FontMetricsInt mFontMetricsInt = new Paint.FontMetricsInt(); |
| 988 | } |