summaryrefslogtreecommitdiff
path: root/core/java/android/text/SpannableStringBuilder.java
diff options
context:
space:
mode:
authorDoug Felt <dougfelt@google.com>2010-05-14 10:55:42 -0700
committerKenny Root <kroot@google.com>2010-06-10 14:03:22 -0700
commit0c702b88c5d0d4380930b920f5be6e66dd95a0d8 (patch)
tree69bce2976a8f21b6a13c6dfd53941326166dbef9 /core/java/android/text/SpannableStringBuilder.java
parenta9aaf8ffcecf294c8da9785b5c5e1f055ee4d245 (diff)
Move shaping to native.
Add internal API (getTextRunAdvances) to Paint, use when measuring. Add internal API (getTextRunCursor) to Paint, use when determining valid cursor positions. Remove java-level shaping code. Remove 'prep' code in TextLine (except for replacement text) since shaping now is done on the fly as needed in native. Provide explicit shaping context bounds to internal text measuring, cursor movement, and rendering APIs. Update for to changes in external API in ushape.h. Change-Id: I146958b624802ce8553125e5c3c6c03031bc9608
Diffstat (limited to 'core/java/android/text/SpannableStringBuilder.java')
-rw-r--r--core/java/android/text/SpannableStringBuilder.java86
1 files changed, 65 insertions, 21 deletions
diff --git a/core/java/android/text/SpannableStringBuilder.java b/core/java/android/text/SpannableStringBuilder.java
index 756317932d06..56f130284464 100644
--- a/core/java/android/text/SpannableStringBuilder.java
+++ b/core/java/android/text/SpannableStringBuilder.java
@@ -1055,35 +1055,27 @@ 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) {
+ int contextStart, int contextEnd,
+ 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);
+ int contextLen = contextEnd - contextStart;
+ int len = end - start;
+ if (contextEnd <= mGapStart) {
+ c.drawTextRun(mText, start, len, contextStart, contextLen, x, y, flags, p);
+ } else if (contextStart >= mGapStart) {
+ c.drawTextRun(mText, start + mGapLength, len, contextStart + mGapLength,
+ contextLen, 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);
+ char[] buf = TextUtils.obtain(contextLen);
+ getChars(contextStart, contextEnd, buf, 0);
+ c.drawTextRun(buf, start - contextStart, len, 0, contextLen, x, y, flags, p);
TextUtils.recycle(buf);
}
}
@@ -1137,6 +1129,58 @@ implements CharSequence, GetChars, Spannable, Editable, Appendable,
return ret;
}
+ /**
+ * Don't call this yourself -- exists for Paint to use internally.
+ * {@hide}
+ */
+ public float getTextRunAdvances(int start, int end, int contextStart, int contextEnd, int flags,
+ float[] advances, int advancesPos, Paint p) {
+
+ float ret;
+
+ int contextLen = contextEnd - contextStart;
+ int len = end - start;
+
+ if (end <= mGapStart) {
+ ret = p.getTextRunAdvances(mText, start, len, contextStart, contextLen,
+ flags, advances, advancesPos);
+ } else if (start >= mGapStart) {
+ ret = p.getTextRunAdvances(mText, start + mGapLength, len,
+ contextStart + mGapLength, contextLen, flags, advances, advancesPos);
+ } else {
+ char[] buf = TextUtils.obtain(contextLen);
+ getChars(contextStart, contextEnd, buf, 0);
+ ret = p.getTextRunAdvances(buf, start - contextStart, len,
+ 0, contextLen, flags, advances, advancesPos);
+ TextUtils.recycle(buf);
+ }
+
+ return ret;
+ }
+
+ public int getTextRunCursor(int contextStart, int contextEnd, int flags, int offset,
+ int cursorOpt, Paint p) {
+
+ int ret;
+
+ int contextLen = contextEnd - contextStart;
+ if (contextEnd <= mGapStart) {
+ ret = p.getTextRunCursor(mText, contextStart, contextLen,
+ flags, offset, cursorOpt);
+ } else if (contextStart >= mGapStart) {
+ ret = p.getTextRunCursor(mText, contextStart + mGapLength, contextLen,
+ flags, offset + mGapLength, cursorOpt);
+ } else {
+ char[] buf = TextUtils.obtain(contextLen);
+ getChars(contextStart, contextEnd, buf, 0);
+ ret = p.getTextRunCursor(buf, 0, contextLen,
+ flags, offset - contextStart, cursorOpt) + contextStart;
+ TextUtils.recycle(buf);
+ }
+
+ return ret;
+ }
+
// Documentation from interface
public void setFilters(InputFilter[] filters) {
if (filters == null) {