blob: cf6987c6d123d777fb3aba0d3ea7ace60b5cad5c [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.text;
18
Mathew Inwoodefeab842018-08-14 15:21:30 +010019import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.graphics.Canvas;
21import android.graphics.Paint;
22import android.graphics.Path;
Eric Fischer86fcef82009-08-17 17:16:44 -070023import android.text.style.ParagraphStyle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
25/**
26 * A BoringLayout is a very simple Layout implementation for text that
27 * fits on a single line and is all left-to-right characters.
28 * You will probably never want to make one of these yourself;
29 * if you do, be sure to call {@link #isBoring} first to make sure
30 * the text meets the criteria.
31 * <p>This class is used by widgets to control text layout. You should not need
32 * to use this class directly unless you are implementing your own widget
33 * or custom display object, in which case
34 * you are encouraged to use a Layout instead of calling
35 * {@link android.graphics.Canvas#drawText(java.lang.CharSequence, int, int, float, float, android.graphics.Paint)
36 * Canvas.drawText()} directly.</p>
37 */
38public class BoringLayout extends Layout implements TextUtils.EllipsizeCallback {
Siyamed Sinir08fac622017-07-19 18:23:11 -070039
40 /**
41 * Utility function to construct a BoringLayout instance.
42 *
43 * @param source the text to render
44 * @param paint the default paint for the layout
45 * @param outerWidth the wrapping width for the text
46 * @param align whether to left, right, or center the text
47 * @param spacingMult this value is no longer used by BoringLayout
48 * @param spacingAdd this value is no longer used by BoringLayout
49 * @param metrics {@code #Metrics} instance that contains information about FontMetrics and
50 * line width
51 * @param includePad set whether to include extra space beyond font ascent and descent which is
52 * needed to avoid clipping in some scripts
53 */
54 public static BoringLayout make(CharSequence source, TextPaint paint, int outerWidth,
55 Alignment align, float spacingMult, float spacingAdd, BoringLayout.Metrics metrics,
56 boolean includePad) {
57 return new BoringLayout(source, paint, outerWidth, align, spacingMult, spacingAdd, metrics,
58 includePad);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 }
60
Siyamed Sinir08fac622017-07-19 18:23:11 -070061 /**
62 * Utility function to construct a BoringLayout instance.
63 *
64 * @param source the text to render
65 * @param paint the default paint for the layout
66 * @param outerWidth the wrapping width for the text
67 * @param align whether to left, right, or center the text
68 * @param spacingmult this value is no longer used by BoringLayout
69 * @param spacingadd this value is no longer used by BoringLayout
70 * @param metrics {@code #Metrics} instance that contains information about FontMetrics and
71 * line width
72 * @param includePad set whether to include extra space beyond font ascent and descent which is
73 * needed to avoid clipping in some scripts
74 * @param ellipsize whether to ellipsize the text if width of the text is longer than the
75 * requested width
76 * @param ellipsizedWidth the width to which this Layout is ellipsizing. If {@code ellipsize} is
77 * {@code null}, or is {@link TextUtils.TruncateAt#MARQUEE} this value is
78 * not used, {@code outerWidth} is used instead
79 */
80 public static BoringLayout make(CharSequence source, TextPaint paint, int outerWidth,
81 Alignment align, float spacingmult, float spacingadd, BoringLayout.Metrics metrics,
82 boolean includePad, TextUtils.TruncateAt ellipsize, int ellipsizedWidth) {
83 return new BoringLayout(source, paint, outerWidth, align, spacingmult, spacingadd, metrics,
84 includePad, ellipsize, ellipsizedWidth);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 }
86
87 /**
88 * Returns a BoringLayout for the specified text, potentially reusing
89 * this one if it is already suitable. The caller must make sure that
90 * no one is still using this Layout.
Siyamed Sinir08fac622017-07-19 18:23:11 -070091 *
92 * @param source the text to render
93 * @param paint the default paint for the layout
94 * @param outerwidth the wrapping width for the text
95 * @param align whether to left, right, or center the text
96 * @param spacingMult this value is no longer used by BoringLayout
97 * @param spacingAdd this value is no longer used by BoringLayout
98 * @param metrics {@code #Metrics} instance that contains information about FontMetrics and
99 * line width
100 * @param includePad set whether to include extra space beyond font ascent and descent which is
101 * needed to avoid clipping in some scripts
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 */
Siyamed Sinir08fac622017-07-19 18:23:11 -0700103 public BoringLayout replaceOrMake(CharSequence source, TextPaint paint, int outerwidth,
104 Alignment align, float spacingMult, float spacingAdd, BoringLayout.Metrics metrics,
105 boolean includePad) {
106 replaceWith(source, paint, outerwidth, align, spacingMult, spacingAdd);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107
108 mEllipsizedWidth = outerwidth;
109 mEllipsizedStart = 0;
110 mEllipsizedCount = 0;
111
Siyamed Sinir08fac622017-07-19 18:23:11 -0700112 init(source, paint, align, metrics, includePad, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 return this;
114 }
115
116 /**
117 * Returns a BoringLayout for the specified text, potentially reusing
118 * this one if it is already suitable. The caller must make sure that
119 * no one is still using this Layout.
Siyamed Sinir08fac622017-07-19 18:23:11 -0700120 *
121 * @param source the text to render
122 * @param paint the default paint for the layout
123 * @param outerWidth the wrapping width for the text
124 * @param align whether to left, right, or center the text
125 * @param spacingMult this value is no longer used by BoringLayout
126 * @param spacingAdd this value is no longer used by BoringLayout
127 * @param metrics {@code #Metrics} instance that contains information about FontMetrics and
128 * line width
129 * @param includePad set whether to include extra space beyond font ascent and descent which is
130 * needed to avoid clipping in some scripts
131 * @param ellipsize whether to ellipsize the text if width of the text is longer than the
132 * requested width
133 * @param ellipsizedWidth the width to which this Layout is ellipsizing. If {@code ellipsize} is
134 * {@code null}, or is {@link TextUtils.TruncateAt#MARQUEE} this value is
135 * not used, {@code outerwidth} is used instead
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800136 */
Siyamed Sinir08fac622017-07-19 18:23:11 -0700137 public BoringLayout replaceOrMake(CharSequence source, TextPaint paint, int outerWidth,
138 Alignment align, float spacingMult, float spacingAdd, BoringLayout.Metrics metrics,
139 boolean includePad, TextUtils.TruncateAt ellipsize, int ellipsizedWidth) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 boolean trust;
141
142 if (ellipsize == null || ellipsize == TextUtils.TruncateAt.MARQUEE) {
Siyamed Sinir08fac622017-07-19 18:23:11 -0700143 replaceWith(source, paint, outerWidth, align, spacingMult, spacingAdd);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144
Siyamed Sinir08fac622017-07-19 18:23:11 -0700145 mEllipsizedWidth = outerWidth;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 mEllipsizedStart = 0;
147 mEllipsizedCount = 0;
148 trust = true;
149 } else {
Siyamed Sinir08fac622017-07-19 18:23:11 -0700150 replaceWith(TextUtils.ellipsize(source, paint, ellipsizedWidth, ellipsize, true, this),
151 paint, outerWidth, align, spacingMult, spacingAdd);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152
153 mEllipsizedWidth = ellipsizedWidth;
154 trust = false;
155 }
156
Siyamed Sinir08fac622017-07-19 18:23:11 -0700157 init(getText(), paint, align, metrics, includePad, trust);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 return this;
159 }
160
Siyamed Sinir08fac622017-07-19 18:23:11 -0700161 /**
162 * @param source the text to render
163 * @param paint the default paint for the layout
164 * @param outerwidth the wrapping width for the text
165 * @param align whether to left, right, or center the text
166 * @param spacingMult this value is no longer used by BoringLayout
167 * @param spacingAdd this value is no longer used by BoringLayout
168 * @param metrics {@code #Metrics} instance that contains information about FontMetrics and
169 * line width
170 * @param includePad set whether to include extra space beyond font ascent and descent which is
171 * needed to avoid clipping in some scripts
172 */
173 public BoringLayout(CharSequence source, TextPaint paint, int outerwidth, Alignment align,
174 float spacingMult, float spacingAdd, BoringLayout.Metrics metrics, boolean includePad) {
175 super(source, paint, outerwidth, align, spacingMult, spacingAdd);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176
177 mEllipsizedWidth = outerwidth;
178 mEllipsizedStart = 0;
179 mEllipsizedCount = 0;
180
Siyamed Sinir08fac622017-07-19 18:23:11 -0700181 init(source, paint, align, metrics, includePad, true);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 }
183
Siyamed Sinir08fac622017-07-19 18:23:11 -0700184 /**
185 *
186 * @param source the text to render
187 * @param paint the default paint for the layout
188 * @param outerWidth the wrapping width for the text
189 * @param align whether to left, right, or center the text
190 * @param spacingMult this value is no longer used by BoringLayout
191 * @param spacingAdd this value is no longer used by BoringLayout
192 * @param metrics {@code #Metrics} instance that contains information about FontMetrics and
193 * line width
194 * @param includePad set whether to include extra space beyond font ascent and descent which is
195 * needed to avoid clipping in some scripts
196 * @param ellipsize whether to ellipsize the text if width of the text is longer than the
197 * requested {@code outerwidth}
198 * @param ellipsizedWidth the width to which this Layout is ellipsizing. If {@code ellipsize} is
199 * {@code null}, or is {@link TextUtils.TruncateAt#MARQUEE} this value is
200 * not used, {@code outerwidth} is used instead
201 */
202 public BoringLayout(CharSequence source, TextPaint paint, int outerWidth, Alignment align,
203 float spacingMult, float spacingAdd, BoringLayout.Metrics metrics, boolean includePad,
204 TextUtils.TruncateAt ellipsize, int ellipsizedWidth) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 /*
206 * It is silly to have to call super() and then replaceWith(),
207 * but we can't use "this" for the callback until the call to
208 * super() finishes.
209 */
Siyamed Sinir08fac622017-07-19 18:23:11 -0700210 super(source, paint, outerWidth, align, spacingMult, spacingAdd);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211
212 boolean trust;
213
214 if (ellipsize == null || ellipsize == TextUtils.TruncateAt.MARQUEE) {
Siyamed Sinir08fac622017-07-19 18:23:11 -0700215 mEllipsizedWidth = outerWidth;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 mEllipsizedStart = 0;
217 mEllipsizedCount = 0;
218 trust = true;
219 } else {
Siyamed Sinir08fac622017-07-19 18:23:11 -0700220 replaceWith(TextUtils.ellipsize(source, paint, ellipsizedWidth, ellipsize, true, this),
221 paint, outerWidth, align, spacingMult, spacingAdd);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222
223 mEllipsizedWidth = ellipsizedWidth;
224 trust = false;
225 }
226
Siyamed Sinir08fac622017-07-19 18:23:11 -0700227 init(getText(), paint, align, metrics, includePad, trust);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 }
229
Siyamed Sinir08fac622017-07-19 18:23:11 -0700230 /* package */ void init(CharSequence source, TextPaint paint, Alignment align,
231 BoringLayout.Metrics metrics, boolean includePad, boolean trustWidth) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 int spacing;
233
234 if (source instanceof String && align == Layout.Alignment.ALIGN_NORMAL) {
235 mDirect = source.toString();
236 } else {
237 mDirect = null;
238 }
239
240 mPaint = paint;
241
Siyamed Sinir08fac622017-07-19 18:23:11 -0700242 if (includePad) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800243 spacing = metrics.bottom - metrics.top;
Raph Levien07e6c232016-04-04 12:34:06 -0700244 mDesc = metrics.bottom;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800245 } else {
246 spacing = metrics.descent - metrics.ascent;
Raph Levien07e6c232016-04-04 12:34:06 -0700247 mDesc = metrics.descent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 }
249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 mBottom = spacing;
251
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 if (trustWidth) {
253 mMax = metrics.width;
254 } else {
255 /*
256 * If we have ellipsized, we have to actually calculate the
257 * width because the width that was passed in was for the
258 * full text, not the ellipsized form.
259 */
Doug Felte8e45f22010-03-29 14:58:40 -0700260 TextLine line = TextLine.obtain();
261 line.set(paint, source, 0, source.length(), Layout.DIR_LEFT_TO_RIGHT,
Mihai Popace642dc2018-05-24 14:25:11 +0100262 Layout.DIRS_ALL_LEFT_TO_RIGHT, false, null,
263 mEllipsizedStart, mEllipsizedStart + mEllipsizedCount);
Neil Fuller33253a42014-10-01 11:55:10 +0100264 mMax = (int) Math.ceil(line.metrics(null));
Doug Felte8e45f22010-03-29 14:58:40 -0700265 TextLine.recycle(line);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 }
267
Siyamed Sinir08fac622017-07-19 18:23:11 -0700268 if (includePad) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800269 mTopPadding = metrics.top - metrics.ascent;
270 mBottomPadding = metrics.bottom - metrics.descent;
271 }
272 }
273
274 /**
Seigo Nonakabd959fb2019-01-11 17:13:16 -0800275 * Determine and compute metrics if given text can be handled by BoringLayout.
276 *
277 * @param text a text
278 * @param paint a paint
279 * @return layout metric for the given text. null if given text is unable to be handled by
280 * BoringLayout.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 */
Siyamed Sinir08fac622017-07-19 18:23:11 -0700282 public static Metrics isBoring(CharSequence text, TextPaint paint) {
Doug Feltcb3791202011-07-07 11:57:48 -0700283 return isBoring(text, paint, TextDirectionHeuristics.FIRSTSTRONG_LTR, null);
284 }
285
286 /**
Seigo Nonakabd959fb2019-01-11 17:13:16 -0800287 * Determine and compute metrics if given text can be handled by BoringLayout.
288 *
289 * @param text a text
290 * @param paint a paint
291 * @param metrics a metrics object to be recycled. If null is passed, this function creat new
292 * object.
293 * @return layout metric for the given text. If metrics is not null, this method fills values
294 * to given metrics object instead of allocating new metrics object. null if given text
295 * is unable to be handled by BoringLayout.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 */
Gilles Debunnef483e512011-04-28 15:08:54 -0700297 public static Metrics isBoring(CharSequence text, TextPaint paint, Metrics metrics) {
Doug Feltcb3791202011-07-07 11:57:48 -0700298 return isBoring(text, paint, TextDirectionHeuristics.FIRSTSTRONG_LTR, metrics);
299 }
300
301 /**
Roozbeh Pournader5536c4f2016-06-01 16:49:27 -0700302 * Returns true if the text contains any RTL characters, bidi format characters, or surrogate
303 * code units.
304 */
305 private static boolean hasAnyInterestingChars(CharSequence text, int textLength) {
306 final int MAX_BUF_LEN = 500;
307 final char[] buffer = TextUtils.obtain(MAX_BUF_LEN);
308 try {
309 for (int start = 0; start < textLength; start += MAX_BUF_LEN) {
310 final int end = Math.min(start + MAX_BUF_LEN, textLength);
311
312 // No need to worry about getting half codepoints, since we consider surrogate code
313 // units "interesting" as soon we see one.
314 TextUtils.getChars(text, start, end, buffer, 0);
315
316 final int len = end - start;
317 for (int i = 0; i < len; i++) {
318 final char c = buffer[i];
Roozbeh Pournader8823c852016-06-09 18:36:47 -0700319 if (c == '\n' || c == '\t' || TextUtils.couldAffectRtl(c)) {
Roozbeh Pournader5536c4f2016-06-01 16:49:27 -0700320 return true;
321 }
322 }
323 }
324 return false;
325 } finally {
326 TextUtils.recycle(buffer);
327 }
328 }
329
330 /**
Doug Feltcb3791202011-07-07 11:57:48 -0700331 * Returns null if not boring; the width, ascent, and descent in the
332 * provided Metrics object (or a new one if the provided one was null)
333 * if boring.
334 * @hide
335 */
Mathew Inwoodefeab842018-08-14 15:21:30 +0100336 @UnsupportedAppUsage
Doug Feltcb3791202011-07-07 11:57:48 -0700337 public static Metrics isBoring(CharSequence text, TextPaint paint,
338 TextDirectionHeuristic textDir, Metrics metrics) {
Roozbeh Pournader3cf82082016-03-16 14:33:51 -0700339 final int textLength = text.length();
Roozbeh Pournader5536c4f2016-06-01 16:49:27 -0700340 if (hasAnyInterestingChars(text, textLength)) {
341 return null; // There are some interesting characters. Not boring.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800342 }
Roozbeh Pournader5536c4f2016-06-01 16:49:27 -0700343 if (textDir != null && textDir.isRtl(text, 0, textLength)) {
344 return null; // The heuristic considers the whole text RTL. Not boring.
345 }
346 if (text instanceof Spanned) {
Eric Fischer86fcef82009-08-17 17:16:44 -0700347 Spanned sp = (Spanned) text;
Roozbeh Pournader3cf82082016-03-16 14:33:51 -0700348 Object[] styles = sp.getSpans(0, textLength, ParagraphStyle.class);
Eric Fischer86fcef82009-08-17 17:16:44 -0700349 if (styles.length > 0) {
Mihai Popace642dc2018-05-24 14:25:11 +0100350 return null; // There are some ParagraphStyle spans. Not boring.
Eric Fischer86fcef82009-08-17 17:16:44 -0700351 }
352 }
353
Roozbeh Pournader5536c4f2016-06-01 16:49:27 -0700354 Metrics fm = metrics;
355 if (fm == null) {
356 fm = new Metrics();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 } else {
Roozbeh Pournader5536c4f2016-06-01 16:49:27 -0700358 fm.reset();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800359 }
Roozbeh Pournader5536c4f2016-06-01 16:49:27 -0700360
Seigo Nonaka4e90fa22018-02-13 21:40:01 +0000361 TextLine line = TextLine.obtain();
362 line.set(paint, text, 0, textLength, Layout.DIR_LEFT_TO_RIGHT,
Mihai Popace642dc2018-05-24 14:25:11 +0100363 Layout.DIRS_ALL_LEFT_TO_RIGHT, false, null,
364 0 /* ellipsisStart, 0 since text has not been ellipsized at this point */,
365 0 /* ellipsisEnd, 0 since text has not been ellipsized at this point */);
Seigo Nonaka53145632018-03-23 17:22:54 -0700366 fm.width = (int) Math.ceil(line.metrics(fm));
Seigo Nonaka4e90fa22018-02-13 21:40:01 +0000367 TextLine.recycle(line);
Roozbeh Pournader5536c4f2016-06-01 16:49:27 -0700368
369 return fm;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800370 }
371
Gilles Debunnef483e512011-04-28 15:08:54 -0700372 @Override
373 public int getHeight() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 return mBottom;
375 }
376
Gilles Debunnef483e512011-04-28 15:08:54 -0700377 @Override
378 public int getLineCount() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 return 1;
380 }
381
Gilles Debunnef483e512011-04-28 15:08:54 -0700382 @Override
383 public int getLineTop(int line) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384 if (line == 0)
385 return 0;
386 else
387 return mBottom;
388 }
389
Gilles Debunnef483e512011-04-28 15:08:54 -0700390 @Override
391 public int getLineDescent(int line) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 return mDesc;
393 }
394
Gilles Debunnef483e512011-04-28 15:08:54 -0700395 @Override
396 public int getLineStart(int line) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800397 if (line == 0)
398 return 0;
399 else
400 return getText().length();
401 }
402
Gilles Debunnef483e512011-04-28 15:08:54 -0700403 @Override
404 public int getParagraphDirection(int line) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 return DIR_LEFT_TO_RIGHT;
406 }
407
Gilles Debunnef483e512011-04-28 15:08:54 -0700408 @Override
409 public boolean getLineContainsTab(int line) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800410 return false;
411 }
412
Gilles Debunnef483e512011-04-28 15:08:54 -0700413 @Override
414 public float getLineMax(int line) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 return mMax;
416 }
417
Gilles Debunnef483e512011-04-28 15:08:54 -0700418 @Override
John Reck44e8d602015-10-05 15:44:04 -0700419 public float getLineWidth(int line) {
420 return (line == 0 ? mMax : 0);
421 }
422
423 @Override
Gilles Debunnef483e512011-04-28 15:08:54 -0700424 public final Directions getLineDirections(int line) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800425 return Layout.DIRS_ALL_LEFT_TO_RIGHT;
426 }
427
Gilles Debunnef483e512011-04-28 15:08:54 -0700428 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800429 public int getTopPadding() {
430 return mTopPadding;
431 }
432
Gilles Debunnef483e512011-04-28 15:08:54 -0700433 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 public int getBottomPadding() {
435 return mBottomPadding;
436 }
437
438 @Override
439 public int getEllipsisCount(int line) {
440 return mEllipsizedCount;
441 }
442
443 @Override
444 public int getEllipsisStart(int line) {
445 return mEllipsizedStart;
446 }
447
448 @Override
449 public int getEllipsizedWidth() {
450 return mEllipsizedWidth;
451 }
452
453 // Override draw so it will be faster.
454 @Override
455 public void draw(Canvas c, Path highlight, Paint highlightpaint,
456 int cursorOffset) {
457 if (mDirect != null && highlight == null) {
458 c.drawText(mDirect, 0, mBottom - mDesc, mPaint);
459 } else {
460 super.draw(c, highlight, highlightpaint, cursorOffset);
461 }
462 }
463
464 /**
465 * Callback for the ellipsizer to report what region it ellipsized.
466 */
467 public void ellipsized(int start, int end) {
468 mEllipsizedStart = start;
469 mEllipsizedCount = end - start;
470 }
471
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800472 private String mDirect;
473 private Paint mPaint;
474
475 /* package */ int mBottom, mDesc; // for Direct
476 private int mTopPadding, mBottomPadding;
477 private float mMax;
478 private int mEllipsizedWidth, mEllipsizedStart, mEllipsizedCount;
479
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480 public static class Metrics extends Paint.FontMetricsInt {
481 public int width;
Doug Felte8e45f22010-03-29 14:58:40 -0700482
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483 @Override public String toString() {
484 return super.toString() + " width=" + width;
485 }
Siyamed Sinir70f660f2016-03-29 11:56:53 -0700486
487 private void reset() {
488 top = 0;
489 bottom = 0;
490 ascent = 0;
491 descent = 0;
492 width = 0;
493 leading = 0;
494 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800495 }
496}