From f47d7405bbcb25d7cdf89ebb059f41520fe9ab87 Mon Sep 17 00:00:00 2001 From: Doug Felt Date: Wed, 21 Apr 2010 16:01:52 -0700 Subject: Modify Canvas drawText to run bidi and shape. Adds drawTextRun as internal API on Canvas and GraphicsOperations. Adds implementation to implementors of GraphicsOperations. Adds state and API on Paint to control the bidi algorithm when used by Canvas. This API is currently hidden. The drawText changes are incomplete since shaping is not yet available in the native code. Change-Id: I4368048aef9545df0953a349381771603e04b619 --- core/java/android/text/SpannableStringBuilder.java | 38 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'core/java/android/text/SpannableStringBuilder.java') diff --git a/core/java/android/text/SpannableStringBuilder.java b/core/java/android/text/SpannableStringBuilder.java index caaafa147397..756317932d06 100644 --- a/core/java/android/text/SpannableStringBuilder.java +++ b/core/java/android/text/SpannableStringBuilder.java @@ -17,8 +17,9 @@ package android.text; import com.android.internal.util.ArrayUtils; -import android.graphics.Paint; + import android.graphics.Canvas; +import android.graphics.Paint; import java.lang.reflect.Array; @@ -780,7 +781,7 @@ implements CharSequence, GetChars, Spannable, Editable, Appendable, } if (count == 0) { - return (T[]) ArrayUtils.emptyArray(kind); + return ArrayUtils.emptyArray(kind); } if (count == 1) { ret = (Object[]) Array.newInstance(kind, 1); @@ -1055,6 +1056,39 @@ implements CharSequence, GetChars, Spannable, Editable, Appendable, } /** + * Don't call this yourself -- exists for Canvas to use internally. + * {@hide} + */ + public void drawTextRun(Canvas c, int start, int end, + float x, float y, int flags, Paint p) { + checkRange("drawTextRun", start, end); + + // Assume context requires no more than 8 chars on either side. + // This is ample, only decomposed U+FDFA falls into this + // category, and no one should put a style break within it + // anyway. + int cstart = start - 8; + if (cstart < 0) { + cstart = 0; + } + int cend = end + 8; + int max = length(); + if (cend > max) { + cend = max; + } + if (cend <= mGapStart) { + c.drawTextRun(mText, start, end - start, x, y, flags, p); + } else if (cstart >= mGapStart) { + c.drawTextRun(mText, start + mGapLength, end - start, x, y, flags, p); + } else { + char[] buf = TextUtils.obtain(cend - cstart); + getChars(cstart, cend, buf, 0); + c.drawTextRun(buf, start - cstart, end - start, x, y, flags, p); + TextUtils.recycle(buf); + } + } + + /** * Don't call this yourself -- exists for Paint to use internally. * {@hide} */ -- cgit v1.2.3