Merge "Clean up dirFlags / bidiFlags confusion"

This commit is contained in:
Raph Levien
2014-06-16 22:24:32 +00:00
committed by Android (Google) Code Review
11 changed files with 300 additions and 317 deletions

View File

@@ -38,7 +38,7 @@ extends CharSequence
* {@hide}
*/
void drawTextRun(Canvas c, int start, int end, int contextStart, int contextEnd,
float x, float y, int flags, Paint p);
float x, float y, boolean isRtl, Paint p);
/**
* Just like {@link Paint#measureText}.
@@ -55,12 +55,12 @@ extends CharSequence
* @hide
*/
float getTextRunAdvances(int start, int end, int contextStart, int contextEnd,
int flags, float[] advances, int advancesIndex, Paint paint);
boolean isRtl, float[] advances, int advancesIndex, Paint paint);
/**
* Just like {@link Paint#getTextRunCursor}.
* @hide
*/
int getTextRunCursor(int contextStart, int contextEnd, int flags, int offset,
int getTextRunCursor(int contextStart, int contextEnd, int dir, int offset,
int cursorOpt, Paint p);
}

View File

@@ -159,18 +159,17 @@ class MeasuredText {
mPos = p + len;
if (mEasy) {
int flags = mDir == Layout.DIR_LEFT_TO_RIGHT
? Canvas.DIRECTION_LTR : Canvas.DIRECTION_RTL;
return paint.getTextRunAdvances(mChars, p, len, p, len, flags, mWidths, p);
boolean isRtl = mDir != Layout.DIR_LEFT_TO_RIGHT;
return paint.getTextRunAdvances(mChars, p, len, p, len, isRtl, mWidths, p);
}
float totalAdvance = 0;
int level = mLevels[p];
for (int q = p, i = p + 1, e = p + len;; ++i) {
if (i == e || mLevels[i] != level) {
int flags = (level & 0x1) == 0 ? Canvas.DIRECTION_LTR : Canvas.DIRECTION_RTL;
boolean isRtl = (level & 0x1) != 0;
totalAdvance +=
paint.getTextRunAdvances(mChars, q, i - q, q, i - q, flags, mWidths, q);
paint.getTextRunAdvances(mChars, q, i - q, q, i - q, isRtl, mWidths, q);
if (i == e) {
break;
}

View File

@@ -503,7 +503,7 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
// Span watchers need to be called after text watchers, which may update the layout
sendToSpanWatchers(start, end, newLen - origLen);
return this;
return this;
}
private static boolean hasNonExclusiveExclusiveSpanAt(CharSequence text, int offset) {
@@ -745,7 +745,7 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
}
}
return 0;
return 0;
}
/**
@@ -1117,20 +1117,20 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
* {@hide}
*/
public void drawTextRun(Canvas c, int start, int end, int contextStart, int contextEnd,
float x, float y, int flags, Paint p) {
float x, float y, boolean isRtl, Paint p) {
checkRange("drawTextRun", start, end);
int contextLen = contextEnd - contextStart;
int len = end - start;
if (contextEnd <= mGapStart) {
c.drawTextRun(mText, start, len, contextStart, contextLen, x, y, flags, p);
c.drawTextRun(mText, start, len, contextStart, contextLen, x, y, isRtl, p);
} else if (contextStart >= mGapStart) {
c.drawTextRun(mText, start + mGapLength, len, contextStart + mGapLength,
contextLen, x, y, flags, p);
contextLen, x, y, isRtl, p);
} else {
char[] buf = TextUtils.obtain(contextLen);
getChars(contextStart, contextEnd, buf, 0);
c.drawTextRun(buf, start - contextStart, len, 0, contextLen, x, y, flags, p);
c.drawTextRun(buf, start - contextStart, len, 0, contextLen, x, y, isRtl, p);
TextUtils.recycle(buf);
}
}
@@ -1187,7 +1187,7 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
* 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,
public float getTextRunAdvances(int start, int end, int contextStart, int contextEnd, boolean isRtl,
float[] advances, int advancesPos, Paint p) {
float ret;
@@ -1197,15 +1197,15 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
if (end <= mGapStart) {
ret = p.getTextRunAdvances(mText, start, len, contextStart, contextLen,
flags, advances, advancesPos);
isRtl, advances, advancesPos);
} else if (start >= mGapStart) {
ret = p.getTextRunAdvances(mText, start + mGapLength, len,
contextStart + mGapLength, contextLen, flags, advances, advancesPos);
contextStart + mGapLength, contextLen, isRtl, 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);
0, contextLen, isRtl, advances, advancesPos);
TextUtils.recycle(buf);
}
@@ -1228,7 +1228,7 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
*
* @param contextStart the start index of the context
* @param contextEnd the (non-inclusive) end index of the context
* @param flags either DIRECTION_RTL or DIRECTION_LTR
* @param dir either DIRECTION_RTL or DIRECTION_LTR
* @param offset the cursor position to move from
* @param cursorOpt how to move the cursor, one of CURSOR_AFTER,
* CURSOR_AT_OR_AFTER, CURSOR_BEFORE,
@@ -1238,7 +1238,7 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
* @deprecated This is an internal method, refrain from using it in your code
*/
@Deprecated
public int getTextRunCursor(int contextStart, int contextEnd, int flags, int offset,
public int getTextRunCursor(int contextStart, int contextEnd, int dir, int offset,
int cursorOpt, Paint p) {
int ret;
@@ -1246,15 +1246,15 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
int contextLen = contextEnd - contextStart;
if (contextEnd <= mGapStart) {
ret = p.getTextRunCursor(mText, contextStart, contextLen,
flags, offset, cursorOpt);
dir, offset, cursorOpt);
} else if (contextStart >= mGapStart) {
ret = p.getTextRunCursor(mText, contextStart + mGapLength, contextLen,
flags, offset + mGapLength, cursorOpt) - mGapLength;
dir, offset + mGapLength, cursorOpt) - mGapLength;
} else {
char[] buf = TextUtils.obtain(contextLen);
getChars(contextStart, contextEnd, buf, 0);
ret = p.getTextRunCursor(buf, 0, contextLen,
flags, offset - contextStart, cursorOpt) + contextStart;
dir, offset - contextStart, cursorOpt) + contextStart;
TextUtils.recycle(buf);
}

View File

@@ -664,14 +664,14 @@ class TextLine {
}
}
int flags = runIsRtl ? Paint.DIRECTION_RTL : Paint.DIRECTION_LTR;
int dir = runIsRtl ? Paint.DIRECTION_RTL : Paint.DIRECTION_LTR;
int cursorOpt = after ? Paint.CURSOR_AFTER : Paint.CURSOR_BEFORE;
if (mCharsValid) {
return wp.getTextRunCursor(mChars, spanStart, spanLimit - spanStart,
flags, offset, cursorOpt);
dir, offset, cursorOpt);
} else {
return wp.getTextRunCursor(mText, mStart + spanStart,
mStart + spanLimit, flags, mStart + offset, cursorOpt) - mStart;
mStart + spanLimit, dir, mStart + offset, cursorOpt) - mStart;
}
}
@@ -738,15 +738,14 @@ class TextLine {
int contextLen = contextEnd - contextStart;
if (needWidth || (c != null && (wp.bgColor != 0 || wp.underlineColor != 0 || runIsRtl))) {
int flags = runIsRtl ? Paint.DIRECTION_RTL : Paint.DIRECTION_LTR;
if (mCharsValid) {
ret = wp.getTextRunAdvances(mChars, start, runLen,
contextStart, contextLen, flags, null, 0);
contextStart, contextLen, runIsRtl, null, 0);
} else {
int delta = mStart;
ret = wp.getTextRunAdvances(mText, delta + start,
delta + end, delta + contextStart, delta + contextEnd,
flags, null, 0);
runIsRtl, null, 0);
}
}
@@ -977,16 +976,15 @@ class TextLine {
private void drawTextRun(Canvas c, TextPaint wp, int start, int end,
int contextStart, int contextEnd, boolean runIsRtl, float x, int y) {
int flags = runIsRtl ? Canvas.DIRECTION_RTL : Canvas.DIRECTION_LTR;
if (mCharsValid) {
int count = end - start;
int contextCount = contextEnd - contextStart;
c.drawTextRun(mChars, start, count, contextStart, contextCount,
x, y, flags, wp);
x, y, runIsRtl, wp);
} else {
int delta = mStart;
c.drawTextRun(mText, delta + start, delta + end,
delta + contextStart, delta + contextEnd, x, y, flags, wp);
delta + contextStart, delta + contextEnd, x, y, runIsRtl, wp);
}
}

View File

@@ -51,10 +51,10 @@ class GLES20Canvas extends HardwareCanvas {
private int mWidth;
private int mHeight;
private float[] mPoint;
private float[] mLine;
private Rect mClipBounds;
private RectF mPathBounds;
@@ -167,7 +167,7 @@ class GLES20Canvas extends HardwareCanvas {
nSetViewport(mRenderer, width, height);
}
private static native void nSetViewport(long renderer, int width, int height);
@Override
@@ -208,22 +208,22 @@ class GLES20Canvas extends HardwareCanvas {
/**
* Must match Caches::FlushMode values
*
* @see #flushCaches(int)
*
* @see #flushCaches(int)
*/
static final int FLUSH_CACHES_LAYERS = 0;
/**
* Must match Caches::FlushMode values
*
* @see #flushCaches(int)
*
* @see #flushCaches(int)
*/
static final int FLUSH_CACHES_MODERATE = 1;
/**
* Must match Caches::FlushMode values
*
* @see #flushCaches(int)
*
* @see #flushCaches(int)
*/
static final int FLUSH_CACHES_FULL = 2;
@@ -245,7 +245,7 @@ class GLES20Canvas extends HardwareCanvas {
///////////////////////////////////////////////////////////////////////////
// Hardware layer
///////////////////////////////////////////////////////////////////////////
void drawHardwareLayer(HardwareLayer layer, float x, float y, Paint paint) {
layer.setLayerPaint(paint);
nDrawLayer(mRenderer, layer.getLayer(), x, y);
@@ -298,7 +298,7 @@ class GLES20Canvas extends HardwareCanvas {
public boolean clipRect(float left, float top, float right, float bottom) {
return nClipRect(mRenderer, left, top, right, bottom, Region.Op.INTERSECT.nativeInt);
}
private static native boolean nClipRect(long renderer, float left, float top,
float right, float bottom, int op);
@@ -311,14 +311,14 @@ class GLES20Canvas extends HardwareCanvas {
public boolean clipRect(int left, int top, int right, int bottom) {
return nClipRect(mRenderer, left, top, right, bottom, Region.Op.INTERSECT.nativeInt);
}
private static native boolean nClipRect(long renderer, int left, int top,
int right, int bottom, int op);
@Override
public boolean clipRect(Rect rect) {
return nClipRect(mRenderer, rect.left, rect.top, rect.right, rect.bottom,
Region.Op.INTERSECT.nativeInt);
Region.Op.INTERSECT.nativeInt);
}
@Override
@@ -360,7 +360,7 @@ class GLES20Canvas extends HardwareCanvas {
public boolean quickReject(float left, float top, float right, float bottom, EdgeType type) {
return nQuickReject(mRenderer, left, top, right, bottom);
}
private static native boolean nQuickReject(long renderer, float left, float top,
float right, float bottom);
@@ -385,7 +385,7 @@ class GLES20Canvas extends HardwareCanvas {
public void translate(float dx, float dy) {
if (dx != 0.0f || dy != 0.0f) nTranslate(mRenderer, dx, dy);
}
private static native void nTranslate(long renderer, float dx, float dy);
@Override
@@ -399,21 +399,21 @@ class GLES20Canvas extends HardwareCanvas {
public void rotate(float degrees) {
nRotate(mRenderer, degrees);
}
private static native void nRotate(long renderer, float degrees);
@Override
public void scale(float sx, float sy) {
nScale(mRenderer, sx, sy);
}
private static native void nScale(long renderer, float sx, float sy);
@Override
public void setMatrix(Matrix matrix) {
nSetMatrix(mRenderer, matrix == null ? 0 : matrix.native_instance);
}
private static native void nSetMatrix(long renderer, long matrix);
@SuppressWarnings("deprecation")
@@ -421,16 +421,16 @@ class GLES20Canvas extends HardwareCanvas {
public void getMatrix(Matrix matrix) {
nGetMatrix(mRenderer, matrix.native_instance);
}
private static native void nGetMatrix(long renderer, long matrix);
@Override
public void concat(Matrix matrix) {
if (matrix != null) nConcatMatrix(mRenderer, matrix.native_instance);
}
private static native void nConcatMatrix(long renderer, long matrix);
///////////////////////////////////////////////////////////////////////////
// State management
///////////////////////////////////////////////////////////////////////////
@@ -439,14 +439,14 @@ class GLES20Canvas extends HardwareCanvas {
public int save() {
return nSave(mRenderer, Canvas.CLIP_SAVE_FLAG | Canvas.MATRIX_SAVE_FLAG);
}
@Override
public int save(int saveFlags) {
return nSave(mRenderer, saveFlags);
}
private static native int nSave(long renderer, int flags);
@Override
public int saveLayer(RectF bounds, Paint paint, int saveFlags) {
if (bounds != null) {
@@ -494,12 +494,12 @@ class GLES20Canvas extends HardwareCanvas {
private static native int nSaveLayerAlpha(long renderer, float left, float top, float right,
float bottom, int alpha, int saveFlags);
@Override
public void restore() {
nRestore(mRenderer);
}
private static native void nRestore(long renderer);
@Override
@@ -508,12 +508,12 @@ class GLES20Canvas extends HardwareCanvas {
}
private static native void nRestoreToCount(long renderer, int saveCount);
@Override
public int getSaveCount() {
return nGetSaveCount(mRenderer);
}
private static native int nGetSaveCount(long renderer);
///////////////////////////////////////////////////////////////////////////
@@ -739,7 +739,7 @@ class GLES20Canvas extends HardwareCanvas {
public void drawColor(int color, PorterDuff.Mode mode) {
nDrawColor(mRenderer, color, mode.nativeInt);
}
private static native void nDrawColor(long renderer, int color, int mode);
@Override
@@ -930,7 +930,7 @@ class GLES20Canvas extends HardwareCanvas {
nDrawText(mRenderer, text, index, count, x, y,
paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
}
private static native void nDrawText(long renderer, char[] text, int index, int count,
float x, float y, int bidiFlags, long paint, long typeface);
@@ -997,49 +997,45 @@ class GLES20Canvas extends HardwareCanvas {
@Override
public void drawTextRun(char[] text, int index, int count, int contextIndex, int contextCount,
float x, float y, int dir, Paint paint) {
float x, float y, boolean isRtl, Paint paint) {
if ((index | count | text.length - index - count) < 0) {
throw new IndexOutOfBoundsException();
}
if (dir != DIRECTION_LTR && dir != DIRECTION_RTL) {
throw new IllegalArgumentException("Unknown direction: " + dir);
}
nDrawTextRun(mRenderer, text, index, count, contextIndex, contextCount, x, y, dir,
nDrawTextRun(mRenderer, text, index, count, contextIndex, contextCount, x, y, isRtl,
paint.mNativePaint, paint.mNativeTypeface);
}
private static native void nDrawTextRun(long renderer, char[] text, int index, int count,
int contextIndex, int contextCount, float x, float y, int dir, long nativePaint, long nativeTypeface);
int contextIndex, int contextCount, float x, float y, boolean isRtl, long nativePaint, long nativeTypeface);
@Override
public void drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd,
float x, float y, int dir, Paint paint) {
float x, float y, boolean isRtl, Paint paint) {
if ((start | end | end - start | text.length() - end) < 0) {
throw new IndexOutOfBoundsException();
}
int flags = dir == 0 ? 0 : 1;
if (text instanceof String || text instanceof SpannedString ||
text instanceof SpannableString) {
nDrawTextRun(mRenderer, text.toString(), start, end, contextStart,
contextEnd, x, y, flags, paint.mNativePaint, paint.mNativeTypeface);
contextEnd, x, y, isRtl, paint.mNativePaint, paint.mNativeTypeface);
} else if (text instanceof GraphicsOperations) {
((GraphicsOperations) text).drawTextRun(this, start, end,
contextStart, contextEnd, x, y, flags, paint);
contextStart, contextEnd, x, y, isRtl, paint);
} else {
int contextLen = contextEnd - contextStart;
int len = end - start;
char[] buf = TemporaryBuffer.obtain(contextLen);
TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
nDrawTextRun(mRenderer, buf, start - contextStart, len, 0, contextLen,
x, y, flags, paint.mNativePaint, paint.mNativeTypeface);
x, y, isRtl, paint.mNativePaint, paint.mNativeTypeface);
TemporaryBuffer.recycle(buf);
}
}
private static native void nDrawTextRun(long renderer, String text, int start, int end,
int contextStart, int contextEnd, float x, float y, int flags, long nativePaint, long nativeTypeface);
int contextStart, int contextEnd, float x, float y, boolean isRtl, long nativePaint, long nativeTypeface);
@Override
public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset,

View File

@@ -9060,11 +9060,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
public void drawTextRun(Canvas c, int start, int end,
int contextStart, int contextEnd, float x, float y, int flags, Paint p) {
int contextStart, int contextEnd, float x, float y, boolean isRtl, Paint p) {
int count = end - start;
int contextCount = contextEnd - contextStart;
c.drawTextRun(mChars, start + mStart, count, contextStart + mStart,
contextCount, x, y, flags, p);
contextCount, x, y, isRtl, p);
}
public float measureText(int start, int end, Paint p) {
@@ -9076,20 +9076,20 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
public float getTextRunAdvances(int start, int end, int contextStart,
int contextEnd, int flags, float[] advances, int advancesIndex,
int contextEnd, boolean isRtl, float[] advances, int advancesIndex,
Paint p) {
int count = end - start;
int contextCount = contextEnd - contextStart;
return p.getTextRunAdvances(mChars, start + mStart, count,
contextStart + mStart, contextCount, flags, advances,
contextStart + mStart, contextCount, isRtl, advances,
advancesIndex);
}
public int getTextRunCursor(int contextStart, int contextEnd, int flags,
public int getTextRunCursor(int contextStart, int contextEnd, int dir,
int offset, int cursorOpt, Paint p) {
int contextCount = contextEnd - contextStart;
return p.getTextRunCursor(mChars, contextStart + mStart,
contextCount, flags, offset + mStart, cursorOpt);
contextCount, dir, offset + mStart, cursorOpt);
}
}