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 | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 358 | if (ok != here) { |
| 359 | // Log.e("text", "output ok " + here + " to " +ok); |
Gilles Debunne | 32ea4ff | 2010-12-21 11:28:34 -0800 | [diff] [blame] | 360 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 361 | while (ok < spanEnd && chs[ok - paraStart] == CHAR_SPACE) { |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 362 | ok++; |
| 363 | } |
| 364 | |
| 365 | v = out(source, |
| 366 | here, ok, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 367 | okAscent, okDescent, okTop, okBottom, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 368 | v, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 369 | spacingmult, spacingadd, chooseHt, |
| 370 | chooseHtv, fm, hasTabOrEmoji, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 371 | needMultiply, paraStart, chdirs, dir, easy, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 372 | ok == bufEnd, includepad, trackpad, |
Gilles Debunne | f3fa0cd | 2011-02-03 14:17:05 -0800 | [diff] [blame] | 373 | chs, widths, paraStart, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 374 | ellipsize, ellipsizedWidth, okWidth, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 375 | paint); |
| 376 | |
| 377 | here = ok; |
| 378 | } else if (fit != here) { |
| 379 | // Log.e("text", "output fit " + here + " to " +fit); |
| 380 | v = out(source, |
| 381 | here, fit, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 382 | fitAscent, fitDescent, |
| 383 | fitTop, fitBottom, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 384 | v, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 385 | spacingmult, spacingadd, chooseHt, |
| 386 | chooseHtv, fm, hasTabOrEmoji, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 387 | needMultiply, paraStart, chdirs, dir, easy, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 388 | fit == bufEnd, includepad, trackpad, |
Gilles Debunne | f3fa0cd | 2011-02-03 14:17:05 -0800 | [diff] [blame] | 389 | chs, widths, paraStart, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 390 | ellipsize, ellipsizedWidth, fitWidth, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 391 | paint); |
| 392 | |
| 393 | here = fit; |
| 394 | } else { |
| 395 | // Log.e("text", "output one " + here + " to " +(here + 1)); |
| 396 | // XXX not sure why the existing fm wasn't ok. |
| 397 | // measureText(paint, mWorkPaint, |
| 398 | // source, here, here + 1, fm, tab, |
| 399 | // null); |
| 400 | |
| 401 | v = out(source, |
| 402 | here, here+1, |
| 403 | fm.ascent, fm.descent, |
| 404 | fm.top, fm.bottom, |
| 405 | v, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 406 | spacingmult, spacingadd, chooseHt, |
| 407 | chooseHtv, fm, hasTabOrEmoji, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 408 | needMultiply, paraStart, chdirs, dir, easy, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 409 | here + 1 == bufEnd, includepad, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 410 | trackpad, |
Gilles Debunne | f3fa0cd | 2011-02-03 14:17:05 -0800 | [diff] [blame] | 411 | chs, widths, paraStart, |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 412 | ellipsize, ellipsizedWidth, |
Gilles Debunne | d434d23 | 2011-01-04 17:15:14 -0800 | [diff] [blame] | 413 | widths[here - paraStart], paint); |
| 414 | |
| 415 | here = here + 1; |
| 416 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 418 | if (here < spanStart) { |
Doug Felt | 2324188 | 2010-06-02 14:41:06 -0700 | [diff] [blame] | 419 | // didn't output all the text for this span |
| 420 | // we've measured the raw widths, though, so |
| 421 | // just reset the start point |
| 422 | j = nextSpanStart = here; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | } else { |
| 424 | j = here - 1; // continue looping |
| 425 | } |
| 426 | |
| 427 | ok = fit = here; |
| 428 | w = 0; |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 429 | fitAscent = fitDescent = fitTop = fitBottom = 0; |
| 430 | okAscent = okDescent = okTop = okBottom = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 431 | |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 432 | if (--firstWidthLineLimit <= 0) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 433 | width = restWidth; |
Mark Wagner | 7b5676e | 2009-10-16 11:44:23 -0700 | [diff] [blame] | 434 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | } |
| 438 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 439 | if (paraEnd != here) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 440 | if ((fitTop | fitBottom | fitDescent | fitAscent) == 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | paint.getFontMetricsInt(fm); |
| 442 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 443 | fitTop = fm.top; |
| 444 | fitBottom = fm.bottom; |
| 445 | fitAscent = fm.ascent; |
| 446 | fitDescent = fm.descent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | // Log.e("text", "output rest " + here + " to " + end); |
| 450 | |
| 451 | v = out(source, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 452 | here, paraEnd, fitAscent, fitDescent, |
| 453 | fitTop, fitBottom, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | v, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 455 | spacingmult, spacingadd, chooseHt, |
| 456 | chooseHtv, fm, hasTabOrEmoji, |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 457 | needMultiply, paraStart, chdirs, dir, easy, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 458 | paraEnd == bufEnd, includepad, trackpad, |
Gilles Debunne | f3fa0cd | 2011-02-03 14:17:05 -0800 | [diff] [blame] | 459 | chs, widths, paraStart, |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 460 | ellipsize, ellipsizedWidth, w, paint); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | } |
| 462 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 463 | paraStart = paraEnd; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 465 | if (paraEnd == bufEnd) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | break; |
| 467 | } |
| 468 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 469 | if (bufEnd == bufStart || source.charAt(bufEnd - 1) == CHAR_NEW_LINE) { |
| 470 | // Log.e("text", "output last " + bufEnd); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 471 | |
| 472 | paint.getFontMetricsInt(fm); |
| 473 | |
| 474 | v = out(source, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 475 | bufEnd, bufEnd, fm.ascent, fm.descent, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | fm.top, fm.bottom, |
| 477 | v, |
| 478 | spacingmult, spacingadd, null, |
| 479 | null, fm, false, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 480 | needMultiply, bufEnd, null, DEFAULT_DIR, true, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 481 | true, includepad, trackpad, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 482 | null, null, bufStart, |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 483 | ellipsize, ellipsizedWidth, 0, paint); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 487 | /** |
| 488 | * Returns true if the specified character is one of those specified |
| 489 | * as being Ideographic (class ID) by the Unicode Line Breaking Algorithm |
| 490 | * (http://www.unicode.org/unicode/reports/tr14/), and is therefore OK |
| 491 | * to break between a pair of. |
Eric Fischer | 549d724 | 2009-03-31 14:19:47 -0700 | [diff] [blame] | 492 | * |
| 493 | * @param includeNonStarters also return true for category NS |
| 494 | * (non-starters), which can be broken |
| 495 | * after but not before. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | */ |
Eric Fischer | 549d724 | 2009-03-31 14:19:47 -0700 | [diff] [blame] | 497 | private static final boolean isIdeographic(char c, boolean includeNonStarters) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | if (c >= '\u2E80' && c <= '\u2FFF') { |
| 499 | return true; // CJK, KANGXI RADICALS, DESCRIPTION SYMBOLS |
| 500 | } |
| 501 | if (c == '\u3000') { |
| 502 | return true; // IDEOGRAPHIC SPACE |
| 503 | } |
| 504 | if (c >= '\u3040' && c <= '\u309F') { |
Eric Fischer | 549d724 | 2009-03-31 14:19:47 -0700 | [diff] [blame] | 505 | if (!includeNonStarters) { |
| 506 | switch (c) { |
| 507 | case '\u3041': // # HIRAGANA LETTER SMALL A |
| 508 | case '\u3043': // # HIRAGANA LETTER SMALL I |
| 509 | case '\u3045': // # HIRAGANA LETTER SMALL U |
| 510 | case '\u3047': // # HIRAGANA LETTER SMALL E |
| 511 | case '\u3049': // # HIRAGANA LETTER SMALL O |
| 512 | case '\u3063': // # HIRAGANA LETTER SMALL TU |
| 513 | case '\u3083': // # HIRAGANA LETTER SMALL YA |
| 514 | case '\u3085': // # HIRAGANA LETTER SMALL YU |
| 515 | case '\u3087': // # HIRAGANA LETTER SMALL YO |
| 516 | case '\u308E': // # HIRAGANA LETTER SMALL WA |
| 517 | case '\u3095': // # HIRAGANA LETTER SMALL KA |
| 518 | case '\u3096': // # HIRAGANA LETTER SMALL KE |
| 519 | case '\u309B': // # KATAKANA-HIRAGANA VOICED SOUND MARK |
| 520 | case '\u309C': // # KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK |
| 521 | case '\u309D': // # HIRAGANA ITERATION MARK |
| 522 | case '\u309E': // # HIRAGANA VOICED ITERATION MARK |
| 523 | return false; |
| 524 | } |
| 525 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 526 | return true; // Hiragana (except small characters) |
| 527 | } |
| 528 | if (c >= '\u30A0' && c <= '\u30FF') { |
Eric Fischer | 549d724 | 2009-03-31 14:19:47 -0700 | [diff] [blame] | 529 | if (!includeNonStarters) { |
| 530 | switch (c) { |
| 531 | case '\u30A0': // # KATAKANA-HIRAGANA DOUBLE HYPHEN |
| 532 | case '\u30A1': // # KATAKANA LETTER SMALL A |
| 533 | case '\u30A3': // # KATAKANA LETTER SMALL I |
| 534 | case '\u30A5': // # KATAKANA LETTER SMALL U |
| 535 | case '\u30A7': // # KATAKANA LETTER SMALL E |
| 536 | case '\u30A9': // # KATAKANA LETTER SMALL O |
| 537 | case '\u30C3': // # KATAKANA LETTER SMALL TU |
| 538 | case '\u30E3': // # KATAKANA LETTER SMALL YA |
| 539 | case '\u30E5': // # KATAKANA LETTER SMALL YU |
| 540 | case '\u30E7': // # KATAKANA LETTER SMALL YO |
| 541 | case '\u30EE': // # KATAKANA LETTER SMALL WA |
| 542 | case '\u30F5': // # KATAKANA LETTER SMALL KA |
| 543 | case '\u30F6': // # KATAKANA LETTER SMALL KE |
| 544 | case '\u30FB': // # KATAKANA MIDDLE DOT |
| 545 | case '\u30FC': // # KATAKANA-HIRAGANA PROLONGED SOUND MARK |
| 546 | case '\u30FD': // # KATAKANA ITERATION MARK |
| 547 | case '\u30FE': // # KATAKANA VOICED ITERATION MARK |
| 548 | return false; |
| 549 | } |
| 550 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 551 | return true; // Katakana (except small characters) |
| 552 | } |
| 553 | if (c >= '\u3400' && c <= '\u4DB5') { |
| 554 | return true; // CJK UNIFIED IDEOGRAPHS EXTENSION A |
| 555 | } |
| 556 | if (c >= '\u4E00' && c <= '\u9FBB') { |
| 557 | return true; // CJK UNIFIED IDEOGRAPHS |
| 558 | } |
| 559 | if (c >= '\uF900' && c <= '\uFAD9') { |
| 560 | return true; // CJK COMPATIBILITY IDEOGRAPHS |
| 561 | } |
| 562 | if (c >= '\uA000' && c <= '\uA48F') { |
| 563 | return true; // YI SYLLABLES |
| 564 | } |
| 565 | if (c >= '\uA490' && c <= '\uA4CF') { |
| 566 | return true; // YI RADICALS |
| 567 | } |
| 568 | if (c >= '\uFE62' && c <= '\uFE66') { |
| 569 | return true; // SMALL PLUS SIGN to SMALL EQUALS SIGN |
| 570 | } |
| 571 | if (c >= '\uFF10' && c <= '\uFF19') { |
| 572 | return true; // WIDE DIGITS |
| 573 | } |
| 574 | |
| 575 | return false; |
| 576 | } |
| 577 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 578 | private int out(CharSequence text, int start, int end, |
| 579 | int above, int below, int top, int bottom, int v, |
| 580 | float spacingmult, float spacingadd, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 581 | LineHeightSpan[] chooseHt, int[] chooseHtv, |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 582 | Paint.FontMetricsInt fm, boolean hasTabOrEmoji, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | boolean needMultiply, int pstart, byte[] chdirs, |
| 584 | int dir, boolean easy, boolean last, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 585 | boolean includePad, boolean trackPad, |
| 586 | char[] chs, float[] widths, int widthStart, |
| 587 | TextUtils.TruncateAt ellipsize, float ellipsisWidth, |
| 588 | float textWidth, TextPaint paint) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | int j = mLineCount; |
| 590 | int off = j * mColumns; |
| 591 | int want = off + mColumns + TOP; |
| 592 | int[] lines = mLines; |
| 593 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | if (want >= lines.length) { |
| 595 | int nlen = ArrayUtils.idealIntArraySize(want + 1); |
| 596 | int[] grow = new int[nlen]; |
| 597 | System.arraycopy(lines, 0, grow, 0, lines.length); |
| 598 | mLines = grow; |
| 599 | lines = grow; |
| 600 | |
| 601 | Directions[] grow2 = new Directions[nlen]; |
| 602 | System.arraycopy(mLineDirections, 0, grow2, 0, |
| 603 | mLineDirections.length); |
| 604 | mLineDirections = grow2; |
| 605 | } |
| 606 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 607 | if (chooseHt != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 608 | fm.ascent = above; |
| 609 | fm.descent = below; |
| 610 | fm.top = top; |
| 611 | fm.bottom = bottom; |
| 612 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 613 | for (int i = 0; i < chooseHt.length; i++) { |
| 614 | if (chooseHt[i] instanceof LineHeightSpan.WithDensity) { |
| 615 | ((LineHeightSpan.WithDensity) chooseHt[i]). |
| 616 | chooseHeight(text, start, end, chooseHtv[i], v, fm, paint); |
Eric Fischer | a9f1dd0 | 2009-08-12 15:00:10 -0700 | [diff] [blame] | 617 | |
| 618 | } else { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 619 | chooseHt[i].chooseHeight(text, start, end, chooseHtv[i], v, fm); |
Eric Fischer | a9f1dd0 | 2009-08-12 15:00:10 -0700 | [diff] [blame] | 620 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | above = fm.ascent; |
| 624 | below = fm.descent; |
| 625 | top = fm.top; |
| 626 | bottom = fm.bottom; |
| 627 | } |
| 628 | |
| 629 | if (j == 0) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 630 | if (trackPad) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | mTopPadding = top - above; |
| 632 | } |
| 633 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 634 | if (includePad) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | above = top; |
| 636 | } |
| 637 | } |
| 638 | if (last) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 639 | if (trackPad) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 640 | mBottomPadding = bottom - below; |
| 641 | } |
| 642 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 643 | if (includePad) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | below = bottom; |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | int extra; |
| 649 | |
| 650 | if (needMultiply) { |
Doug Felt | 1065758 | 2010-02-22 11:19:01 -0800 | [diff] [blame] | 651 | double ex = (below - above) * (spacingmult - 1) + spacingadd; |
| 652 | if (ex >= 0) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 653 | extra = (int)(ex + EXTRA_ROUNDING); |
Doug Felt | 1065758 | 2010-02-22 11:19:01 -0800 | [diff] [blame] | 654 | } else { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 655 | extra = -(int)(-ex + EXTRA_ROUNDING); |
Doug Felt | 1065758 | 2010-02-22 11:19:01 -0800 | [diff] [blame] | 656 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 657 | } else { |
| 658 | extra = 0; |
| 659 | } |
| 660 | |
| 661 | lines[off + START] = start; |
| 662 | lines[off + TOP] = v; |
| 663 | lines[off + DESCENT] = below + extra; |
| 664 | |
| 665 | v += (below - above) + extra; |
| 666 | lines[off + mColumns + START] = end; |
| 667 | lines[off + mColumns + TOP] = v; |
| 668 | |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 669 | if (hasTabOrEmoji) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 670 | lines[off + TAB] |= TAB_MASK; |
| 671 | |
Doug Felt | 9f7a444 | 2010-03-01 12:45:56 -0800 | [diff] [blame] | 672 | lines[off + DIR] |= dir << DIR_SHIFT; |
| 673 | Directions linedirs = DIRS_ALL_LEFT_TO_RIGHT; |
| 674 | // easy means all chars < the first RTL, so no emoji, no nothing |
Doug Felt | 4e0c5e5 | 2010-03-15 16:56:02 -0700 | [diff] [blame] | 675 | // 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] | 676 | // RTL paragraph. Make sure easy is false if this is the case. |
| 677 | if (easy) { |
| 678 | mLineDirections[j] = linedirs; |
| 679 | } else { |
Gilles Debunne | f3fa0cd | 2011-02-03 14:17:05 -0800 | [diff] [blame] | 680 | mLineDirections[j] = AndroidBidi.directions(dir, chdirs, start - widthStart, chs, |
| 681 | start - widthStart, end - start); |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 682 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 683 | |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 684 | // If ellipsize is in marquee mode, do not apply ellipsis on the first line |
| 685 | if (ellipsize != null && (ellipsize != TextUtils.TruncateAt.MARQUEE || j != 0)) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 686 | calculateEllipsis(start, end, widths, widthStart, |
| 687 | ellipsisWidth, ellipsize, j, |
| 688 | textWidth, paint); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | mLineCount++; |
| 692 | return v; |
| 693 | } |
| 694 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 695 | private void calculateEllipsis(int lineStart, int lineEnd, |
| 696 | float[] widths, int widthStart, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 | float avail, TextUtils.TruncateAt where, |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 698 | int line, float textWidth, TextPaint paint) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 699 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 700 | if (textWidth <= avail) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 701 | // Everything fits! |
| 702 | mLines[mColumns * line + ELLIPSIS_START] = 0; |
| 703 | mLines[mColumns * line + ELLIPSIS_COUNT] = 0; |
| 704 | return; |
| 705 | } |
| 706 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 707 | float ellipsisWidth = paint.measureText(HORIZONTAL_ELLIPSIS); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 708 | int ellipsisStart, ellipsisCount; |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 709 | int len = lineEnd - lineStart; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | |
| 711 | if (where == TextUtils.TruncateAt.START) { |
| 712 | float sum = 0; |
| 713 | int i; |
| 714 | |
| 715 | for (i = len; i >= 0; i--) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 716 | float w = widths[i - 1 + lineStart - widthStart]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 717 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 718 | if (w + sum + ellipsisWidth > avail) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 719 | break; |
| 720 | } |
| 721 | |
| 722 | sum += w; |
| 723 | } |
| 724 | |
| 725 | ellipsisStart = 0; |
| 726 | ellipsisCount = i; |
| 727 | } else if (where == TextUtils.TruncateAt.END || where == TextUtils.TruncateAt.MARQUEE) { |
| 728 | float sum = 0; |
| 729 | int i; |
| 730 | |
| 731 | for (i = 0; i < len; i++) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 732 | float w = widths[i + lineStart - widthStart]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 734 | if (w + sum + ellipsisWidth > avail) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 735 | break; |
| 736 | } |
| 737 | |
| 738 | sum += w; |
| 739 | } |
| 740 | |
| 741 | ellipsisStart = i; |
| 742 | ellipsisCount = len - i; |
| 743 | } else /* where = TextUtils.TruncateAt.MIDDLE */ { |
| 744 | float lsum = 0, rsum = 0; |
| 745 | int left = 0, right = len; |
| 746 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 747 | float ravail = (avail - ellipsisWidth) / 2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | for (right = len; right >= 0; right--) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 749 | float w = widths[right - 1 + lineStart - widthStart]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 750 | |
| 751 | if (w + rsum > ravail) { |
| 752 | break; |
| 753 | } |
| 754 | |
| 755 | rsum += w; |
| 756 | } |
| 757 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 758 | float lavail = avail - ellipsisWidth - rsum; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 759 | for (left = 0; left < right; left++) { |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 760 | float w = widths[left + lineStart - widthStart]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 761 | |
| 762 | if (w + lsum > lavail) { |
| 763 | break; |
| 764 | } |
| 765 | |
| 766 | lsum += w; |
| 767 | } |
| 768 | |
| 769 | ellipsisStart = left; |
| 770 | ellipsisCount = right - left; |
| 771 | } |
| 772 | |
| 773 | mLines[mColumns * line + ELLIPSIS_START] = ellipsisStart; |
| 774 | mLines[mColumns * line + ELLIPSIS_COUNT] = ellipsisCount; |
| 775 | } |
| 776 | |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 777 | // 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] | 778 | // rather than relying on member functions. |
| 779 | // The logic mirrors that of Layout.getLineForVertical |
| 780 | // 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] | 781 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 782 | public int getLineForVertical(int vertical) { |
| 783 | int high = mLineCount; |
| 784 | int low = -1; |
| 785 | int guess; |
| 786 | int[] lines = mLines; |
| 787 | while (high - low > 1) { |
| 788 | guess = (high + low) >> 1; |
| 789 | if (lines[mColumns * guess + TOP] > vertical){ |
| 790 | high = guess; |
| 791 | } else { |
| 792 | low = guess; |
| 793 | } |
| 794 | } |
| 795 | if (low < 0) { |
| 796 | return 0; |
| 797 | } else { |
| 798 | return low; |
| 799 | } |
| 800 | } |
| 801 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 802 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 803 | public int getLineCount() { |
| 804 | return mLineCount; |
| 805 | } |
| 806 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 807 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | public int getLineTop(int line) { |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 809 | int top = mLines[mColumns * line + TOP]; |
| 810 | if (mMaximumVisibleLineCount > 0 && line >= mMaximumVisibleLineCount && |
| 811 | line != mLineCount) { |
| 812 | top += getBottomPadding(); |
| 813 | } |
| 814 | return top; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 815 | } |
| 816 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 817 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 818 | public int getLineDescent(int line) { |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 819 | int descent = mLines[mColumns * line + DESCENT]; |
Gilles Debunne | f3fa0cd | 2011-02-03 14:17:05 -0800 | [diff] [blame] | 820 | if (mMaximumVisibleLineCount > 0 && line >= mMaximumVisibleLineCount - 1 && // -1 intended |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 821 | line != mLineCount) { |
| 822 | descent += getBottomPadding(); |
| 823 | } |
| 824 | return descent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 825 | } |
| 826 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 827 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | public int getLineStart(int line) { |
| 829 | return mLines[mColumns * line + START] & START_MASK; |
| 830 | } |
| 831 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 832 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 833 | public int getParagraphDirection(int line) { |
| 834 | return mLines[mColumns * line + DIR] >> DIR_SHIFT; |
| 835 | } |
| 836 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 837 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | public boolean getLineContainsTab(int line) { |
| 839 | return (mLines[mColumns * line + TAB] & TAB_MASK) != 0; |
| 840 | } |
| 841 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 842 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 843 | public final Directions getLineDirections(int line) { |
| 844 | return mLineDirections[line]; |
| 845 | } |
| 846 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 847 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 848 | public int getTopPadding() { |
| 849 | return mTopPadding; |
| 850 | } |
| 851 | |
Gilles Debunne | 6611147 | 2010-11-19 11:04:37 -0800 | [diff] [blame] | 852 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 853 | public int getBottomPadding() { |
| 854 | return mBottomPadding; |
| 855 | } |
| 856 | |
| 857 | @Override |
| 858 | public int getEllipsisCount(int line) { |
| 859 | if (mColumns < COLUMNS_ELLIPSIZE) { |
| 860 | return 0; |
| 861 | } |
| 862 | |
| 863 | return mLines[mColumns * line + ELLIPSIS_COUNT]; |
| 864 | } |
| 865 | |
| 866 | @Override |
| 867 | public int getEllipsisStart(int line) { |
| 868 | if (mColumns < COLUMNS_ELLIPSIZE) { |
| 869 | return 0; |
| 870 | } |
| 871 | |
| 872 | return mLines[mColumns * line + ELLIPSIS_START]; |
| 873 | } |
| 874 | |
| 875 | @Override |
| 876 | public int getEllipsizedWidth() { |
| 877 | return mEllipsizedWidth; |
| 878 | } |
| 879 | |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 880 | /** |
| 881 | * @hide |
| 882 | */ |
| 883 | @Override |
Gilles Debunne | f3fa0cd | 2011-02-03 14:17:05 -0800 | [diff] [blame] | 884 | public void setMaximumVisibleLineCount(int lineCount) { |
| 885 | mMaximumVisibleLineCount = lineCount; |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 886 | } |
| 887 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 888 | private int mLineCount; |
| 889 | private int mTopPadding, mBottomPadding; |
| 890 | private int mColumns; |
| 891 | private int mEllipsizedWidth; |
| 892 | |
| 893 | private static final int COLUMNS_NORMAL = 3; |
| 894 | private static final int COLUMNS_ELLIPSIZE = 5; |
| 895 | private static final int START = 0; |
| 896 | private static final int DIR = START; |
| 897 | private static final int TAB = START; |
| 898 | private static final int TOP = 1; |
| 899 | private static final int DESCENT = 2; |
| 900 | private static final int ELLIPSIS_START = 3; |
| 901 | private static final int ELLIPSIS_COUNT = 4; |
| 902 | |
| 903 | private int[] mLines; |
| 904 | private Directions[] mLineDirections; |
Gilles Debunne | 0a4db3c | 2011-01-14 12:12:04 -0800 | [diff] [blame] | 905 | private int mMaximumVisibleLineCount = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 906 | |
| 907 | private static final int START_MASK = 0x1FFFFFFF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 908 | private static final int DIR_SHIFT = 30; |
| 909 | private static final int TAB_MASK = 0x20000000; |
| 910 | |
Doug Felt | c982f60 | 2010-05-25 11:51:40 -0700 | [diff] [blame] | 911 | 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] | 912 | |
Fabrice Di Meglio | 121c82c | 2011-02-15 15:44:49 -0800 | [diff] [blame] | 913 | private static final char CHAR_FIRST_CJK = '\u2E80'; |
| 914 | |
| 915 | private static final char CHAR_NEW_LINE = '\n'; |
| 916 | private static final char CHAR_TAB = '\t'; |
| 917 | private static final char CHAR_SPACE = ' '; |
| 918 | private static final char CHAR_DOT = '.'; |
| 919 | private static final char CHAR_COMMA = ','; |
| 920 | private static final char CHAR_COLON = ':'; |
| 921 | private static final char CHAR_SEMICOLON = ';'; |
| 922 | private static final char CHAR_SLASH = '/'; |
| 923 | private static final char CHAR_HYPHEN = '-'; |
| 924 | |
| 925 | private static final double EXTRA_ROUNDING = 0.5; |
| 926 | private static final String HORIZONTAL_ELLIPSIS = "\u2026"; // this is "..." |
| 927 | |
| 928 | private static final int CHAR_FIRST_HIGH_SURROGATE = 0xD800; |
| 929 | private static final int CHAR_LAST_LOW_SURROGATE = 0xDFFF; |
| 930 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 931 | /* |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 932 | * This is reused across calls to generate() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | */ |
Doug Felt | e8e45f2 | 2010-03-29 14:58:40 -0700 | [diff] [blame] | 934 | private MeasuredText mMeasured; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 935 | private Paint.FontMetricsInt mFontMetricsInt = new Paint.FontMetricsInt(); |
| 936 | } |