diff options
author | Xavier Ducrohet <xav@android.com> | 2009-11-13 14:10:20 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2009-11-13 16:36:18 -0800 |
commit | 01889503c47aadc9faacf727371f1d23e3a99d97 (patch) | |
tree | 77e374d3089ab85cd211eac04a5ab840059978cf | |
parent | b5046342562aff58af33ae25cfcd1cc3abe27fc8 (diff) | |
download | base-01889503c47aadc9faacf727371f1d23e3a99d97.tar.gz |
Properly implement Paint.breakText for layoutlib. (do not merge)android-sdk-1.6_r2
BUG 2260400
This is integrated from Eclair.
-rw-r--r-- | tools/layoutlib/bridge/src/android/graphics/Paint.java | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint.java b/tools/layoutlib/bridge/src/android/graphics/Paint.java index 4311c2b3262f..fe69df374a03 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Paint.java +++ b/tools/layoutlib/bridge/src/android/graphics/Paint.java @@ -755,13 +755,45 @@ public class Paint extends _Original_Paint { @Override public int breakText(String text, boolean measureForwards, float maxWidth, float[] measuredWidth) { - // NOTE: javadoc doesn't match. Just a guess. return breakText(text, 0 /* start */, text.length() /* end */, measureForwards, maxWidth, measuredWidth); } /** + * Measure the text, stopping early if the measured width exceeds maxWidth. + * Return the number of chars that were measured, and if measuredWidth is + * not null, return in it the actual width measured. + * + * @param text The text to measure + * @param start The offset into text to begin measuring at + * @param end The end of the text slice to measure. + * @param measureForwards If true, measure forwards, starting at start. + * Otherwise, measure backwards, starting with end. + * @param maxWidth The maximum width to accumulate. + * @param measuredWidth Optional. If not null, returns the actual width + * measured. + * @return The number of chars that were measured. Will always be <= + * abs(end - start). + */ + @Override + public int breakText(CharSequence text, int start, int end, boolean measureForwards, + float maxWidth, float[] measuredWidth) { + char[] buf = new char[end - start]; + int result; + + TextUtils.getChars(text, start, end, buf, 0); + + if (measureForwards) { + result = breakText(buf, 0, end - start, maxWidth, measuredWidth); + } else { + result = breakText(buf, 0, -(end - start), maxWidth, measuredWidth); + } + + return result; + } + + /** * Return the advance widths for the characters in the string. * * @param text The text to measure |