frameworks/base
Révision | 01889503c47aadc9faacf727371f1d23e3a99d97 (tree) |
---|---|
l'heure | 2009-11-14 09:36:18 |
Auteur | Xavier Ducrohet <xav@andr...> |
Commiter | Xavier Ducrohet |
Properly implement Paint.breakText for layoutlib. (do not merge)
BUG 2260400
This is integrated from Eclair.
@@ -755,13 +755,45 @@ public class Paint extends _Original_Paint { | ||
755 | 755 | @Override |
756 | 756 | public int breakText(String text, boolean measureForwards, |
757 | 757 | float maxWidth, float[] measuredWidth) { |
758 | - // NOTE: javadoc doesn't match. Just a guess. | |
759 | 758 | return breakText(text, |
760 | 759 | 0 /* start */, text.length() /* end */, |
761 | 760 | measureForwards, maxWidth, measuredWidth); |
762 | 761 | } |
763 | 762 | |
764 | 763 | /** |
764 | + * Measure the text, stopping early if the measured width exceeds maxWidth. | |
765 | + * Return the number of chars that were measured, and if measuredWidth is | |
766 | + * not null, return in it the actual width measured. | |
767 | + * | |
768 | + * @param text The text to measure | |
769 | + * @param start The offset into text to begin measuring at | |
770 | + * @param end The end of the text slice to measure. | |
771 | + * @param measureForwards If true, measure forwards, starting at start. | |
772 | + * Otherwise, measure backwards, starting with end. | |
773 | + * @param maxWidth The maximum width to accumulate. | |
774 | + * @param measuredWidth Optional. If not null, returns the actual width | |
775 | + * measured. | |
776 | + * @return The number of chars that were measured. Will always be <= | |
777 | + * abs(end - start). | |
778 | + */ | |
779 | + @Override | |
780 | + public int breakText(CharSequence text, int start, int end, boolean measureForwards, | |
781 | + float maxWidth, float[] measuredWidth) { | |
782 | + char[] buf = new char[end - start]; | |
783 | + int result; | |
784 | + | |
785 | + TextUtils.getChars(text, start, end, buf, 0); | |
786 | + | |
787 | + if (measureForwards) { | |
788 | + result = breakText(buf, 0, end - start, maxWidth, measuredWidth); | |
789 | + } else { | |
790 | + result = breakText(buf, 0, -(end - start), maxWidth, measuredWidth); | |
791 | + } | |
792 | + | |
793 | + return result; | |
794 | + } | |
795 | + | |
796 | + /** | |
765 | 797 | * Return the advance widths for the characters in the string. |
766 | 798 | * |
767 | 799 | * @param text The text to measure |