summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Raph Levien <raph@google.com> 2015-04-27 22:50:33 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2015-04-27 22:50:34 +0000
commita589368a78f946976f1ac45feb47fb9611b0e64b (patch)
tree983197b103bbe141255c7c5b5f7b9a5ab52a657e
parentd0922ed723c3199de5a45e01fc9f4d56178cc577 (diff)
parentc6abf5bff6bbfafa1f133644f02a5d50d5269b7f (diff)
Merge "Expose drawTextRun publicly" into mnc-dev
-rw-r--r--api/current.txt2
-rw-r--r--api/system-current.txt2
-rw-r--r--graphics/java/android/graphics/Canvas.java58
-rw-r--r--graphics/java/android/graphics/Paint.java16
-rw-r--r--tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java2
5 files changed, 49 insertions, 31 deletions
diff --git a/api/current.txt b/api/current.txt
index df77416c2b73..8246144cf87a 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -11184,6 +11184,8 @@ package android.graphics {
method public void drawText(java.lang.CharSequence, int, int, float, float, android.graphics.Paint);
method public void drawTextOnPath(char[], int, int, android.graphics.Path, float, float, android.graphics.Paint);
method public void drawTextOnPath(java.lang.String, android.graphics.Path, float, float, android.graphics.Paint);
+ method public void drawTextRun(char[], int, int, int, int, float, float, boolean, android.graphics.Paint);
+ method public void drawTextRun(java.lang.CharSequence, int, int, int, int, float, float, boolean, android.graphics.Paint);
method public void drawVertices(android.graphics.Canvas.VertexMode, int, float[], int, float[], int, int[], int, short[], int, int, android.graphics.Paint);
method public boolean getClipBounds(android.graphics.Rect);
method public final android.graphics.Rect getClipBounds();
diff --git a/api/system-current.txt b/api/system-current.txt
index e10a8b2548da..b0740829122c 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -11479,6 +11479,8 @@ package android.graphics {
method public void drawText(java.lang.CharSequence, int, int, float, float, android.graphics.Paint);
method public void drawTextOnPath(char[], int, int, android.graphics.Path, float, float, android.graphics.Paint);
method public void drawTextOnPath(java.lang.String, android.graphics.Path, float, float, android.graphics.Paint);
+ method public void drawTextRun(char[], int, int, int, int, float, float, boolean, android.graphics.Paint);
+ method public void drawTextRun(java.lang.CharSequence, int, int, int, int, float, float, boolean, android.graphics.Paint);
method public void drawVertices(android.graphics.Canvas.VertexMode, int, float[], int, float[], int, int[], int, short[], int, int, android.graphics.Paint);
method public boolean getClipBounds(android.graphics.Rect);
method public final android.graphics.Rect getClipBounds();
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java
index 2acb8baaaa06..9fe8e0cd9b16 100644
--- a/graphics/java/android/graphics/Canvas.java
+++ b/graphics/java/android/graphics/Canvas.java
@@ -81,17 +81,9 @@ public class Canvas {
*/
protected int mScreenDensity = Bitmap.DENSITY_NONE;
- /**
- * Flag for drawTextRun indicating left-to-right run direction.
- * @hide
- */
- public static final int DIRECTION_LTR = 0;
-
- /**
- * Flag for drawTextRun indicating right-to-left run direction.
- * @hide
- */
- public static final int DIRECTION_RTL = 1;
+ // Used by native code
+ @SuppressWarnings("UnusedDeclaration")
+ private int mSurfaceFormat;
// Maximum bitmap size as defined in Skia's native code
// (see SkCanvas.cpp, SkDraw.cpp)
@@ -1724,10 +1716,15 @@ public class Canvas {
}
/**
- * Render a run of all LTR or all RTL text, with shaping. This does not run
- * bidi on the provided text, but renders it as a uniform right-to-left or
- * left-to-right run, as indicated by dir. Alignment of the text is as
- * determined by the Paint's TextAlign value.
+ * Draw a run of text, all in a single direction, with optional context for complex text
+ * shaping.
+ *
+ * <p>See {@link #drawTextRun(CharSequence, int, int, int, int, float, float, boolean, Paint)}
+ * for more details. This method uses a character array rather than CharSequence to
+ * represent the string. Also, to be consistent with the pattern established in
+ * {@link #drawText}, in this method {@code count} and {@code contextCount} are used rather
+ * than offsets of the end position; {@code count = end - start, contextCount = contextEnd -
+ * contextStart}.
*
* @param text the text to render
* @param index the start of the text to render
@@ -1735,13 +1732,12 @@ public class Canvas {
* @param contextIndex the start of the context for shaping. Must be
* no greater than index.
* @param contextCount the number of characters in the context for shaping.
- * ContexIndex + contextCount must be no less than index
+ * contexIndex + contextCount must be no less than index
* + count.
* @param x the x position at which to draw the text
* @param y the y position at which to draw the text
* @param isRtl whether the run is in RTL direction
* @param paint the paint
- * @hide
*/
public void drawTextRun(@NonNull char[] text, int index, int count, int contextIndex,
int contextCount, float x, float y, boolean isRtl, @NonNull Paint paint) {
@@ -1761,21 +1757,39 @@ public class Canvas {
}
/**
- * Render a run of all LTR or all RTL text, with shaping. This does not run
- * bidi on the provided text, but renders it as a uniform right-to-left or
- * left-to-right run, as indicated by dir. Alignment of the text is as
- * determined by the Paint's TextAlign value.
+ * Draw a run of text, all in a single direction, with optional context for complex text
+ * shaping.
+ *
+ * <p>The run of text includes the characters from {@code start} to {@code end} in the text. In
+ * addition, the range {@code contextStart} to {@code contextEnd} is used as context for the
+ * purpose of complex text shaping, such as Arabic text potentially shaped differently based on
+ * the text next to it.
+ *
+ * <p>All text outside the range {@code contextStart..contextEnd} is ignored. The text between
+ * {@code start} and {@code end} will be laid out and drawn.
+ *
+ * <p>The direction of the run is explicitly specified by {@code isRtl}. Thus, this method is
+ * suitable only for runs of a single direction. Alignment of the text is as determined by the
+ * Paint's TextAlign value. Further, {@code 0 <= contextStart <= start <= end <= contextEnd
+ * <= text.length} must hold on entry.
+ *
+ * <p>Also see {@link android.graphics.Paint#getRunAdvance} for a corresponding method to
+ * measure the text; the advance width of the text drawn matches the value obtained from that
+ * method.
*
* @param text the text to render
* @param start the start of the text to render. Data before this position
* can be used for shaping context.
* @param end the end of the text to render. Data at or after this
* position can be used for shaping context.
+ * @param contextStart the index of the start of the shaping context
+ * @param contextEnd the index of the end of the shaping context
* @param x the x position at which to draw the text
* @param y the y position at which to draw the text
* @param isRtl whether the run is in RTL direction
* @param paint the paint
- * @hide
+ *
+ * @see #drawTextRun(char[], int, int, int, int, float, float, boolean, Paint)
*/
public void drawTextRun(@NonNull CharSequence text, int start, int end, int contextStart,
int contextEnd, float x, float y, boolean isRtl, @NonNull Paint paint) {
diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java
index ce2448fa9eab..20cd9b19c5d0 100644
--- a/graphics/java/android/graphics/Paint.java
+++ b/graphics/java/android/graphics/Paint.java
@@ -2263,10 +2263,10 @@ public class Paint {
* the input is a pair of regional indicator symbols, determine whether there is an emoji flag
* for the pair.
*
- * Finally, if the string contains a variation selector, the method only returns true if
+ * <p>Finally, if the string contains a variation selector, the method only returns true if
* the fonts contains a glyph specific to that variation.
*
- * Checking is done on the entire fallback chain, not just the immediate font referenced.
+ * <p>Checking is done on the entire fallback chain, not just the immediate font referenced.
*
* @param string the string to test whether there is glyph support
* @return true if the typeface has a glyph for the string
@@ -2283,20 +2283,20 @@ public class Paint {
* purpose of complex text shaping, such as Arabic text potentially shaped differently based on
* the text next to it.
*
- * All text outside the range {@code contextStart..contextEnd} is ignored. The text between
+ * <p>All text outside the range {@code contextStart..contextEnd} is ignored. The text between
* {@code start} and {@code end} will be laid out to be measured.
*
- * The returned width measurement is the advance from {@code start} to {@code offset}. It is
+ * <p>The returned width measurement is the advance from {@code start} to {@code offset}. It is
* generally a positive value, no matter the direction of the run. If {@code offset == end},
* the return value is simply the width of the whole run from {@code start} to {@code end}.
*
- * Ligatures are formed for characters in the range {@code start..end} (but not for
+ * <p>Ligatures are formed for characters in the range {@code start..end} (but not for
* {@code start..contextStart} or {@code end..contextEnd}). If {@code offset} points to a
* character in the middle of such a formed ligature, but at a grapheme cluster boundary, the
* return value will also reflect an advance in the middle of the ligature. See
* {@link #getOffsetForAdvance} for more discussion of grapheme cluster boundaries.
*
- * The direction of the run is explicitly specified by {@code isRtl}. Thus, this method is
+ * <p>The direction of the run is explicitly specified by {@code isRtl}. Thus, this method is
* suitable only for runs of a single direction.
*
* <p>All indices are relative to the start of {@code text}. Further, {@code 0 <= contextStart
@@ -2306,7 +2306,7 @@ public class Paint {
* @param start the index of the start of the range to measure
* @param end the index + 1 of the end of the range to measure
* @param contextStart the index of the start of the shaping context
- * @param contextEnd the index + 1 of the end of the range to measure
+ * @param contextEnd the index + 1 of the end of the shaping context
* @param isRtl whether the run is in RTL direction
* @param offset index of caret position
* @return width measurement between start and offset
@@ -2336,7 +2336,7 @@ public class Paint {
* @param start the index of the start of the range to measure
* @param end the index + 1 of the end of the range to measure
* @param contextStart the index of the start of the shaping context
- * @param contextEnd the index + 1 of the end of the range to measure
+ * @param contextEnd the index + 1 of the end of the shaping context
* @param isRtl whether the run is in RTL direction
* @param offset index of caret position
* @return width measurement between start and offset
diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
index 4d2d1000c5eb..9f5ad845670a 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
@@ -844,7 +844,7 @@ public final class Canvas_Delegate {
@LayoutlibDelegate
/*package*/ static void native_drawText(long nativeCanvas, char[] text, int index, int count,
float startX, float startY, int flags, long paint, long typeface) {
- drawText(nativeCanvas, text, index, count, startX, startY, flags == Canvas.DIRECTION_RTL,
+ drawText(nativeCanvas, text, index, count, startX, startY, (flags & 1) != 0,
paint, typeface);
}