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

@@ -65,11 +65,11 @@ public class Canvas {
/**
* Used to determine when compatibility scaling is in effect.
*
*
* @hide
*/
protected int mScreenDensity = Bitmap.DENSITY_NONE;
// Used by native code
@SuppressWarnings("UnusedDeclaration")
private int mSurfaceFormat;
@@ -79,7 +79,7 @@ public class Canvas {
* @hide
*/
public static final int DIRECTION_LTR = 0;
/**
* Flag for drawTextRun indicating right-to-left run direction.
* @hide
@@ -136,7 +136,7 @@ public class Canvas {
/**
* Construct a canvas with the specified bitmap to draw into. The bitmap
* must be mutable.
*
*
* <p>The initial target density of the canvas is the same as the given
* bitmap's density.
*
@@ -177,10 +177,10 @@ public class Canvas {
/**
* Indicates whether this Canvas uses hardware acceleration.
*
*
* Note that this method does not define what type of hardware acceleration
* may or may not be used.
*
*
* @return True if drawing operations are hardware accelerated,
* false otherwise.
*/
@@ -189,7 +189,7 @@ public class Canvas {
}
/**
* Specify a bitmap for the canvas to draw into. All canvas state such as
* Specify a bitmap for the canvas to draw into. All canvas state such as
* layers, filters, and the save/restore stack are reset with the exception
* of the current matrix and clip stack. Additionally, as a side-effect
* the canvas' target density is updated to match that of the bitmap.
@@ -279,7 +279,7 @@ public class Canvas {
* to determine the scaling factor when drawing a bitmap into it.
*
* @see #setDensity(int)
* @see Bitmap#getDensity()
* @see Bitmap#getDensity()
*/
public int getDensity() {
return mDensity;
@@ -295,7 +295,7 @@ public class Canvas {
* {@link Bitmap#DENSITY_NONE} to disable bitmap scaling.
*
* @see #getDensity()
* @see Bitmap#setDensity(int)
* @see Bitmap#setDensity(int)
*/
public void setDensity(int density) {
if (mBitmap != null) {
@@ -313,19 +313,19 @@ public class Canvas {
* Returns the maximum allowed width for bitmaps drawn with this canvas.
* Attempting to draw with a bitmap wider than this value will result
* in an error.
*
* @see #getMaximumBitmapHeight()
*
* @see #getMaximumBitmapHeight()
*/
public int getMaximumBitmapWidth() {
return MAXMIMUM_BITMAP_SIZE;
}
/**
* Returns the maximum allowed height for bitmaps drawn with this canvas.
* Attempting to draw with a bitmap taller than this value will result
* in an error.
*
* @see #getMaximumBitmapWidth()
*
* @see #getMaximumBitmapWidth()
*/
public int getMaximumBitmapHeight() {
return MAXMIMUM_BITMAP_SIZE;
@@ -357,8 +357,8 @@ public class Canvas {
/** clip against the layer's bounds */
public static final int CLIP_TO_LAYER_SAVE_FLAG = 0x10;
/** restore everything when restore() is called */
public static final int ALL_SAVE_FLAG = 0x1F;
public static final int ALL_SAVE_FLAG = 0x1F;
/**
* Saves the current matrix and clip onto a private stack. Subsequent
* calls to translate,scale,rotate,skew,concat or clipRect,clipPath
@@ -371,7 +371,7 @@ public class Canvas {
public int save() {
return native_save(mNativeCanvasWrapper, MATRIX_SAVE_FLAG | CLIP_SAVE_FLAG);
}
/**
* Based on saveFlags, can save the current matrix and clip onto a private
* stack. Subsequent calls to translate,scale,rotate,skew,concat or
@@ -589,25 +589,25 @@ public class Canvas {
public void concat(@Nullable Matrix matrix) {
if (matrix != null) native_concat(mNativeCanvasWrapper, matrix.native_instance);
}
/**
* Completely replace the current matrix with the specified matrix. If the
* matrix parameter is null, then the current matrix is reset to identity.
*
*
* <strong>Note:</strong> it is recommended to use {@link #concat(Matrix)},
* {@link #scale(float, float)}, {@link #translate(float, float)} and
* {@link #rotate(float)} instead of this method.
*
* @param matrix The matrix to replace the current matrix with. If it is
* null, set the current matrix to identity.
*
* @see #concat(Matrix)
*
* @see #concat(Matrix)
*/
public void setMatrix(@Nullable Matrix matrix) {
native_setMatrix(mNativeCanvasWrapper,
matrix == null ? 0 : matrix.native_instance);
}
/**
* Return, in ctm, the current transformation matrix. This does not alter
* the matrix in the canvas, but just returns a copy of it.
@@ -628,7 +628,7 @@ public class Canvas {
getMatrix(m);
return m;
}
/**
* Modify the current clip with the specified rectangle.
*
@@ -677,7 +677,7 @@ public class Canvas {
return native_clipRect(mNativeCanvasWrapper, rect.left, rect.top, rect.right, rect.bottom,
Region.Op.INTERSECT.nativeInt);
}
/**
* Modify the current clip with the specified rectangle, which is
* expressed in local coordinates.
@@ -744,7 +744,7 @@ public class Canvas {
public boolean clipPath(@NonNull Path path, @NonNull Region.Op op) {
return native_clipPath(mNativeCanvasWrapper, path.ni(), op.nativeInt);
}
/**
* Intersect the current clip with the specified path.
*
@@ -754,7 +754,7 @@ public class Canvas {
public boolean clipPath(@NonNull Path path) {
return clipPath(path, Region.Op.INTERSECT);
}
/**
* Modify the current clip with the specified region. Note that unlike
* clipRect() and clipPath() which transform their arguments by the
@@ -789,11 +789,11 @@ public class Canvas {
public boolean clipRegion(@NonNull Region region) {
return clipRegion(region, Region.Op.INTERSECT);
}
public @Nullable DrawFilter getDrawFilter() {
return mDrawFilter;
}
public void setDrawFilter(@Nullable DrawFilter filter) {
long nativeFilter = 0;
if (filter != null) {
@@ -814,7 +814,7 @@ public class Canvas {
* Antialiased: Treat edges by rounding-out, since they may be antialiased
*/
AA(1);
EdgeType(int nativeInt) {
this.nativeInt = nativeInt;
}
@@ -900,7 +900,7 @@ public class Canvas {
public boolean getClipBounds(@Nullable Rect bounds) {
return native_getClipBounds(mNativeCanvasWrapper, bounds);
}
/**
* Retrieve the bounds of the current clip (in local coordinates).
*
@@ -911,7 +911,7 @@ public class Canvas {
getClipBounds(r);
return r;
}
/**
* Fill the entire canvas' bitmap (restricted to the current clip) with the
* specified RGB color, using srcover porterduff mode.
@@ -968,7 +968,7 @@ public class Canvas {
public void drawPaint(@NonNull Paint paint) {
native_drawPaint(mNativeCanvasWrapper, paint.mNativePaint);
}
/**
* Draw a series of points. Each point is centered at the coordinate
* specified by pts[], and its diameter is specified by the paint's stroke
@@ -1065,7 +1065,7 @@ public class Canvas {
public void drawRect(@NonNull Rect r, @NonNull Paint paint) {
drawRect(r.left, r.top, r.right, r.bottom, paint);
}
/**
* Draw the specified Rect using the specified paint. The rectangle will
@@ -1111,15 +1111,15 @@ public class Canvas {
/**
* <p>Draw the specified arc, which will be scaled to fit inside the
* specified oval.</p>
*
*
* <p>If the start angle is negative or >= 360, the start angle is treated
* as start angle modulo 360.</p>
*
*
* <p>If the sweep angle is >= 360, then the oval is drawn
* completely. Note that this differs slightly from SkPath::arcTo, which
* treats the sweep angle modulo 360. If the sweep angle is negative,
* the sweep angle is treated as sweep angle modulo 360</p>
*
*
* <p>The arc is drawn clockwise. An angle of 0 degrees correspond to the
* geometric angle of 0 degrees (3 o'clock on a watch.)</p>
*
@@ -1197,7 +1197,7 @@ public class Canvas {
* @param patch The ninepatch object to render
* @param dst The destination rectangle.
* @param paint The paint to draw the bitmap with. may be null
*
*
* @hide
*/
public void drawPatch(@NonNull NinePatch patch, @NonNull Rect dst, @Nullable Paint paint) {
@@ -1220,7 +1220,7 @@ public class Canvas {
/**
* Draw the specified bitmap, with its top/left corner at (x,y), using
* the specified paint, transformed by the current matrix.
*
*
* <p>Note: if the paint contains a maskfilter that generates a mask which
* extends beyond the bitmap's original width/height (e.g. BlurMaskFilter),
* then the bitmap will be drawn as if it were in a Shader with CLAMP mode.
@@ -1230,7 +1230,7 @@ public class Canvas {
* <p>If the bitmap and canvas have different densities, this function
* will take care of automatically scaling the bitmap to draw at the
* same density as the canvas.
*
*
* @param bitmap The bitmap to be drawn
* @param left The position of the left side of the bitmap being drawn
* @param top The position of the top side of the bitmap being drawn
@@ -1246,7 +1246,7 @@ public class Canvas {
* Draw the specified bitmap, scaling/translating automatically to fill
* the destination rectangle. If the source rectangle is not null, it
* specifies the subset of the bitmap to draw.
*
*
* <p>Note: if the paint contains a maskfilter that generates a mask which
* extends beyond the bitmap's original width/height (e.g. BlurMaskFilter),
* then the bitmap will be drawn as if it were in a Shader with CLAMP mode.
@@ -1257,7 +1257,7 @@ public class Canvas {
* This is because the source and destination rectangle coordinate
* spaces are in their respective densities, so must already have the
* appropriate scaling factor applied.
*
*
* @param bitmap The bitmap to be drawn
* @param src May be null. The subset of the bitmap to be drawn
* @param dst The rectangle that the bitmap will be scaled/translated
@@ -1278,7 +1278,7 @@ public class Canvas {
* Draw the specified bitmap, scaling/translating automatically to fill
* the destination rectangle. If the source rectangle is not null, it
* specifies the subset of the bitmap to draw.
*
*
* <p>Note: if the paint contains a maskfilter that generates a mask which
* extends beyond the bitmap's original width/height (e.g. BlurMaskFilter),
* then the bitmap will be drawn as if it were in a Shader with CLAMP mode.
@@ -1289,7 +1289,7 @@ public class Canvas {
* This is because the source and destination rectangle coordinate
* spaces are in their respective densities, so must already have the
* appropriate scaling factor applied.
*
*
* @param bitmap The bitmap to be drawn
* @param src May be null. The subset of the bitmap to be drawn
* @param dst The rectangle that the bitmap will be scaled/translated
@@ -1305,7 +1305,7 @@ public class Canvas {
native_drawBitmap(mNativeCanvasWrapper, bitmap.ni(), src, dst,
paint != null ? paint.mNativePaint : 0, mScreenDensity, bitmap.mDensity);
}
/**
* Treat the specified array of colors as a bitmap, and draw it. This gives
* the same result as first creating a bitmap from the array, and then
@@ -1394,7 +1394,7 @@ public class Canvas {
throw new ArrayIndexOutOfBoundsException();
}
}
/**
* Draw the bitmap through the mesh, where mesh vertices are evenly
* distributed across the bitmap. There are meshWidth+1 vertices across, and
@@ -1446,7 +1446,7 @@ public class Canvas {
TRIANGLES(0),
TRIANGLE_STRIP(1),
TRIANGLE_FAN(2);
VertexMode(int nativeInt) {
this.nativeInt = nativeInt;
}
@@ -1456,7 +1456,7 @@ public class Canvas {
*/
public final int nativeInt;
}
/**
* Draw the array of vertices, interpreted as triangles (based on mode). The
* verts array is required, and specifies the x,y pairs for each vertex. If
@@ -1485,7 +1485,7 @@ public class Canvas {
* @param indices If not null, array of indices to reference into the
* vertex (texs, colors) array.
* @param indexCount number of entries in the indices array (if not null).
* @param paint Specifies the shader to use if the texs array is non-null.
* @param paint Specifies the shader to use if the texs array is non-null.
*/
public void drawVertices(@NonNull VertexMode mode, int vertexCount, @NonNull float[] verts,
int vertOffset, @Nullable float[] texs, int texOffset, @Nullable int[] colors,
@@ -1595,7 +1595,7 @@ public class Canvas {
* 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.
*
*
* @param text the text to render
* @param index the start of the text to render
* @param count the count of chars to render
@@ -1606,13 +1606,12 @@ public class Canvas {
* + count.
* @param x the x position at which to draw the text
* @param y the y position at which to draw the text
* @param dir the run direction, either {@link #DIRECTION_LTR} or
* {@link #DIRECTION_RTL}.
* @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, int dir, @NonNull Paint paint) {
int contextCount, float x, float y, boolean isRtl, @NonNull Paint paint) {
if (text == null) {
throw new NullPointerException("text is null");
@@ -1623,12 +1622,9 @@ public class Canvas {
if ((index | count | text.length - index - count) < 0) {
throw new IndexOutOfBoundsException();
}
if (dir != DIRECTION_LTR && dir != DIRECTION_RTL) {
throw new IllegalArgumentException("unknown dir: " + dir);
}
native_drawTextRun(mNativeCanvasWrapper, text, index, count,
contextIndex, contextCount, x, y, dir, paint.mNativePaint, paint.mNativeTypeface);
contextIndex, contextCount, x, y, isRtl, paint.mNativePaint, paint.mNativeTypeface);
}
/**
@@ -1644,12 +1640,12 @@ public class Canvas {
* position can be used for 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 dir the run direction, either 0 for LTR or 1 for RTL.
* @param isRtl whether the run is in RTL direction
* @param paint the paint
* @hide
*/
public void drawTextRun(@NonNull CharSequence text, int start, int end, int contextStart,
int contextEnd, float x, float y, int dir, @NonNull Paint paint) {
int contextEnd, float x, float y, boolean isRtl, @NonNull Paint paint) {
if (text == null) {
throw new NullPointerException("text is null");
@@ -1661,22 +1657,20 @@ public class Canvas {
throw new IndexOutOfBoundsException();
}
int flags = dir == 0 ? 0 : 1;
if (text instanceof String || text instanceof SpannedString ||
text instanceof SpannableString) {
native_drawTextRun(mNativeCanvasWrapper, text.toString(), start, end,
contextStart, contextEnd, x, y, flags, paint.mNativePaint, paint.mNativeTypeface);
contextStart, 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);
native_drawTextRun(mNativeCanvasWrapper, buf, start - contextStart, len,
0, contextLen, x, y, flags, paint.mNativePaint, paint.mNativeTypeface);
0, contextLen, x, y, isRtl, paint.mNativePaint, paint.mNativeTypeface);
TemporaryBuffer.recycle(buf);
}
}
@@ -1684,7 +1678,7 @@ public class Canvas {
/**
* Draw the text in the array, with each character's origin specified by
* the pos array.
*
*
* This method does not support glyph composition and decomposition and
* should therefore not be used to render complex scripts.
*
@@ -1708,7 +1702,7 @@ public class Canvas {
/**
* Draw the text in the array, with each character's origin specified by
* the pos array.
*
*
* This method does not support glyph composition and decomposition and
* should therefore not be used to render complex scripts.
*
@@ -1776,7 +1770,7 @@ public class Canvas {
* <p>
* <strong>Note:</strong> This forces the picture to internally call
* {@link Picture#endRecording} in order to prepare for playback.
*
*
* @param picture The picture to be drawn
*/
public void drawPicture(@NonNull Picture picture) {
@@ -1785,7 +1779,7 @@ public class Canvas {
picture.draw(this);
restoreToCount(restoreCount);
}
/**
* Draw the picture, stretched to fit into the dst rectangle.
*/
@@ -1798,7 +1792,7 @@ public class Canvas {
drawPicture(picture);
restore();
}
/**
* Draw the picture, stretched to fit into the dst rectangle.
*/
@@ -1977,11 +1971,11 @@ public class Canvas {
private static native void native_drawTextRun(long nativeCanvas, String text,
int start, int end, int contextStart, int contextEnd,
float x, float y, int flags, long nativePaint, long nativeTypeface);
float x, float y, boolean isRtl, long nativePaint, long nativeTypeface);
private static native void native_drawTextRun(long nativeCanvas, char[] text,
int start, int count, int contextStart, int contextCount,
float x, float y, int flags, long nativePaint, long nativeTypeface);
float x, float y, boolean isRtl, long nativePaint, long nativeTypeface);
private static native void native_drawPosText(long nativeCanvas,
char[] text, int index,

View File

@@ -56,7 +56,7 @@ public class Paint {
* @hide
*/
public int mBidiFlags = BIDI_DEFAULT_LTR;
static final Style[] sStyleArray = {
Style.FILL, Style.STROKE, Style.FILL_AND_STROKE
};
@@ -202,14 +202,14 @@ public class Paint {
/**
* Bidi flag to set LTR paragraph direction.
*
*
* @hide
*/
public static final int BIDI_LTR = 0x0;
/**
* Bidi flag to set RTL paragraph direction.
*
*
* @hide
*/
public static final int BIDI_RTL = 0x1;
@@ -217,7 +217,7 @@ public class Paint {
/**
* Bidi flag to detect paragraph direction via heuristics, defaulting to
* LTR.
*
*
* @hide
*/
public static final int BIDI_DEFAULT_LTR = 0x2;
@@ -225,21 +225,21 @@ public class Paint {
/**
* Bidi flag to detect paragraph direction via heuristics, defaulting to
* RTL.
*
*
* @hide
*/
public static final int BIDI_DEFAULT_RTL = 0x3;
/**
* Bidi flag to override direction to all LTR (ignore bidi).
*
*
* @hide
*/
public static final int BIDI_FORCE_LTR = 0x4;
/**
* Bidi flag to override direction to all RTL (ignore bidi).
*
*
* @hide
*/
public static final int BIDI_FORCE_RTL = 0x5;
@@ -331,7 +331,7 @@ public class Paint {
* either FILL or STROKE.
*/
FILL_AND_STROKE (2);
Style(int nativeInt) {
this.nativeInt = nativeInt;
}
@@ -357,7 +357,7 @@ public class Paint {
* of the path.
*/
SQUARE (2);
private Cap(int nativeInt) {
this.nativeInt = nativeInt;
}
@@ -381,7 +381,7 @@ public class Paint {
* The outer edges of a join meet with a straight line
*/
BEVEL (2);
private Join(int nativeInt) {
this.nativeInt = nativeInt;
}
@@ -405,7 +405,7 @@ public class Paint {
* The text is drawn to the left of the x,y origin
*/
RIGHT (2);
private Align(int nativeInt) {
this.nativeInt = nativeInt;
}
@@ -418,7 +418,7 @@ public class Paint {
public Paint() {
this(0);
}
/**
* Create a new paint with the specified flags. Use setFlags() to change
* these after the paint is created.
@@ -475,7 +475,7 @@ public class Paint {
setTextLocale(Locale.getDefault());
setElegantTextHeight(false);
}
/**
* Copy the fields from src into this paint. This is equivalent to calling
* get() on all of the src fields, and calling the corresponding set()
@@ -529,7 +529,7 @@ public class Paint {
/**
* Return the bidi flags on the paint.
*
*
* @return the bidi flags on the paint
* @hide
*/
@@ -552,7 +552,7 @@ public class Paint {
/**
* Return the paint's flags. Use the Flag enum to test flag values.
*
*
* @return the paint's flags (see enums ending in _Flag for bit masks)
*/
public native int getFlags();
@@ -587,7 +587,7 @@ public class Paint {
public final boolean isAntiAlias() {
return (getFlags() & ANTI_ALIAS_FLAG) != 0;
}
/**
* Helper for setFlags(), setting or clearing the ANTI_ALIAS_FLAG bit
* AntiAliasing smooths out the edges of what is being drawn, but is has
@@ -597,7 +597,7 @@ public class Paint {
* @param aa true to set the antialias bit in the flags, false to clear it
*/
public native void setAntiAlias(boolean aa);
/**
* Helper for getFlags(), returning true if DITHER_FLAG bit is set
* Dithering affects how colors that are higher precision than the device
@@ -611,7 +611,7 @@ public class Paint {
public final boolean isDither() {
return (getFlags() & DITHER_FLAG) != 0;
}
/**
* Helper for setFlags(), setting or clearing the DITHER_FLAG bit
* Dithering affects how colors that are higher precision than the device
@@ -623,7 +623,7 @@ public class Paint {
* @param dither true to set the dithering bit in flags, false to clear it
*/
public native void setDither(boolean dither);
/**
* Helper for getFlags(), returning true if LINEAR_TEXT_FLAG bit is set
*
@@ -649,7 +649,7 @@ public class Paint {
public final boolean isSubpixelText() {
return (getFlags() & SUBPIXEL_TEXT_FLAG) != 0;
}
/**
* Helper for setFlags(), setting or clearing the SUBPIXEL_TEXT_FLAG bit
*
@@ -657,7 +657,7 @@ public class Paint {
* flags, false to clear it.
*/
public native void setSubpixelText(boolean subpixelText);
/**
* Helper for getFlags(), returning true if UNDERLINE_TEXT_FLAG bit is set
*
@@ -708,7 +708,7 @@ public class Paint {
* flags, false to clear it.
*/
public native void setFakeBoldText(boolean fakeBoldText);
/**
* Whether or not the bitmap filter is activated.
* Filtering affects the sampling of bitmaps when they are transformed.
@@ -720,13 +720,13 @@ public class Paint {
public final boolean isFilterBitmap() {
return (getFlags() & FILTER_BITMAP_FLAG) != 0;
}
/**
* Helper for setFlags(), setting or clearing the FILTER_BITMAP_FLAG bit.
* Filtering affects the sampling of bitmaps when they are transformed.
* Filtering does not affect how the colors in the bitmap are converted into
* device pixels. That is dependent on dithering and xfermodes.
*
*
* @param filter true to set the FILTER_BITMAP_FLAG bit in the paint's
* flags, false to clear it.
*/
@@ -773,7 +773,7 @@ public class Paint {
* @param color The new color (including alpha) to set in the paint.
*/
public native void setColor(int color);
/**
* Helper to getColor() that just returns the color's alpha value. This is
* the same as calling getColor() >>> 24. It always returns a value between
@@ -1285,7 +1285,7 @@ public class Paint {
*/
public static class FontMetrics {
/**
* The maximum distance above the baseline for the tallest glyph in
* The maximum distance above the baseline for the tallest glyph in
* the font at a given text size.
*/
public float top;
@@ -1298,7 +1298,7 @@ public class Paint {
*/
public float descent;
/**
* The maximum distance below the baseline for the lowest glyph in
* The maximum distance below the baseline for the lowest glyph in
* the font at a given text size.
*/
public float bottom;
@@ -1307,7 +1307,7 @@ public class Paint {
*/
public float leading;
}
/**
* Return the font's recommended interline spacing, given the Paint's
* settings for typeface, textSize, etc. If metrics is not null, return the
@@ -1318,7 +1318,7 @@ public class Paint {
* @return the font's recommended interline spacing.
*/
public native float getFontMetrics(FontMetrics metrics);
/**
* Allocates a new FontMetrics object, and then calls getFontMetrics(fm)
* with it, returning the object.
@@ -1328,7 +1328,7 @@ public class Paint {
getFontMetrics(fm);
return fm;
}
/**
* Convenience method for callers that want to have FontMetrics values as
* integers.
@@ -1339,7 +1339,7 @@ public class Paint {
public int descent;
public int bottom;
public int leading;
@Override public String toString() {
return "FontMetricsInt: top=" + top + " ascent=" + ascent +
" descent=" + descent + " bottom=" + bottom +
@@ -1364,7 +1364,7 @@ public class Paint {
getFontMetricsInt(fm);
return fm;
}
/**
* Return the recommend line spacing based on the current typeface and
* text size.
@@ -1407,7 +1407,7 @@ public class Paint {
}
private native float native_measureText(char[] text, int index, int count, int bidiFlags);
/**
* Return the width of the text.
*
@@ -1439,7 +1439,7 @@ public class Paint {
}
private native float native_measureText(String text, int start, int end, int bidiFlags);
/**
* Return the width of the text.
*
@@ -1466,7 +1466,7 @@ public class Paint {
}
private native float native_measureText(String text, int bidiFlags);
/**
* Return the width of the text.
*
@@ -1503,7 +1503,7 @@ public class Paint {
TemporaryBuffer.recycle(buf);
return result;
}
/**
* Measure the text, stopping early if the measured width exceeds maxWidth.
* Return the number of chars that were measured, and if measuredWidth is
@@ -1738,7 +1738,7 @@ public class Paint {
if (end - start > widths.length) {
throw new ArrayIndexOutOfBoundsException();
}
if (text.length() == 0 || start == end) {
return 0;
}
@@ -1755,7 +1755,7 @@ public class Paint {
}
return res;
}
/**
* Return the advance widths for the characters in the string.
*
@@ -1816,15 +1816,12 @@ public class Paint {
* @hide
*/
public float getTextRunAdvances(char[] chars, int index, int count,
int contextIndex, int contextCount, int flags, float[] advances,
int contextIndex, int contextCount, boolean isRtl, float[] advances,
int advancesIndex) {
if (chars == null) {
throw new IllegalArgumentException("text cannot be null");
}
if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) {
throw new IllegalArgumentException("unknown flags value: " + flags);
}
if ((index | count | contextIndex | contextCount | advancesIndex
| (index - contextIndex) | (contextCount - count)
| ((contextIndex + contextCount) - (index + count))
@@ -1839,13 +1836,13 @@ public class Paint {
}
if (!mHasCompatScaling) {
return native_getTextRunAdvances(mNativePaint, mNativeTypeface, chars, index, count,
contextIndex, contextCount, flags, advances, advancesIndex);
contextIndex, contextCount, isRtl, advances, advancesIndex);
}
final float oldSize = getTextSize();
setTextSize(oldSize * mCompatScaling);
float res = native_getTextRunAdvances(mNativePaint, mNativeTypeface, chars, index, count,
contextIndex, contextCount, flags, advances, advancesIndex);
contextIndex, contextCount, isRtl, advances, advancesIndex);
setTextSize(oldSize);
if (advances != null) {
@@ -1864,7 +1861,7 @@ public class Paint {
* @hide
*/
public float getTextRunAdvances(CharSequence text, int start, int end,
int contextStart, int contextEnd, int flags, float[] advances,
int contextStart, int contextEnd, boolean isRtl, float[] advances,
int advancesIndex) {
if (text == null) {
@@ -1880,16 +1877,16 @@ public class Paint {
if (text instanceof String) {
return getTextRunAdvances((String) text, start, end,
contextStart, contextEnd, flags, advances, advancesIndex);
contextStart, contextEnd, isRtl, advances, advancesIndex);
}
if (text instanceof SpannedString ||
text instanceof SpannableString) {
return getTextRunAdvances(text.toString(), start, end,
contextStart, contextEnd, flags, advances, advancesIndex);
contextStart, contextEnd, isRtl, advances, advancesIndex);
}
if (text instanceof GraphicsOperations) {
return ((GraphicsOperations) text).getTextRunAdvances(start, end,
contextStart, contextEnd, flags, advances, advancesIndex, this);
contextStart, contextEnd, isRtl, advances, advancesIndex, this);
}
if (text.length() == 0 || end == start) {
return 0f;
@@ -1900,7 +1897,7 @@ public class Paint {
char[] buf = TemporaryBuffer.obtain(contextLen);
TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
float result = getTextRunAdvances(buf, start - contextStart, len,
0, contextLen, flags, advances, advancesIndex);
0, contextLen, isRtl, advances, advancesIndex);
TemporaryBuffer.recycle(buf);
return result;
}
@@ -1937,8 +1934,7 @@ public class Paint {
* must be <= start
* @param contextEnd the index past the last character to use for shaping context,
* must be >= end
* @param flags the flags to control the advances, either {@link #DIRECTION_LTR}
* or {@link #DIRECTION_RTL}
* @param isRtl whether the run is in RTL direction
* @param advances array to receive the advances, must have room for all advances,
* can be null if only total advance is needed
* @param advancesIndex the position in advances at which to put the
@@ -1948,14 +1944,11 @@ public class Paint {
* @hide
*/
public float getTextRunAdvances(String text, int start, int end, int contextStart,
int contextEnd, int flags, float[] advances, int advancesIndex) {
int contextEnd, boolean isRtl, float[] advances, int advancesIndex) {
if (text == null) {
throw new IllegalArgumentException("text cannot be null");
}
if (flags != DIRECTION_LTR && flags != DIRECTION_RTL) {
throw new IllegalArgumentException("unknown flags value: " + flags);
}
if ((start | end | contextStart | contextEnd | advancesIndex | (end - start)
| (start - contextStart) | (contextEnd - end)
| (text.length() - contextEnd)
@@ -1970,13 +1963,13 @@ public class Paint {
if (!mHasCompatScaling) {
return native_getTextRunAdvances(mNativePaint, mNativeTypeface, text, start, end,
contextStart, contextEnd, flags, advances, advancesIndex);
contextStart, contextEnd, isRtl, advances, advancesIndex);
}
final float oldSize = getTextSize();
setTextSize(oldSize * mCompatScaling);
float totalAdvance = native_getTextRunAdvances(mNativePaint, mNativeTypeface, text, start, end,
contextStart, contextEnd, flags, advances, advancesIndex);
contextStart, contextEnd, isRtl, advances, advancesIndex);
setTextSize(oldSize);
if (advances != null) {
@@ -2005,7 +1998,7 @@ public class Paint {
* @param text the text
* @param contextStart the start of the context
* @param contextLength the length of the context
* @param flags either {@link #DIRECTION_RTL} or {@link #DIRECTION_LTR}
* @param dir either {@link #DIRECTION_RTL} or {@link #DIRECTION_LTR}
* @param offset the cursor position to move from
* @param cursorOpt how to move the cursor, one of {@link #CURSOR_AFTER},
* {@link #CURSOR_AT_OR_AFTER}, {@link #CURSOR_BEFORE},
@@ -2014,7 +2007,7 @@ public class Paint {
* @hide
*/
public int getTextRunCursor(char[] text, int contextStart, int contextLength,
int flags, int offset, int cursorOpt) {
int dir, int offset, int cursorOpt) {
int contextEnd = contextStart + contextLength;
if (((contextStart | contextEnd | offset | (contextEnd - contextStart)
| (offset - contextStart) | (contextEnd - offset)
@@ -2024,7 +2017,7 @@ public class Paint {
}
return native_getTextRunCursor(mNativePaint, text,
contextStart, contextLength, flags, offset, cursorOpt);
contextStart, contextLength, dir, offset, cursorOpt);
}
/**
@@ -2045,7 +2038,7 @@ public class Paint {
* @param text the text
* @param contextStart the start of the context
* @param contextEnd the end of the context
* @param flags either {@link #DIRECTION_RTL} or {@link #DIRECTION_LTR}
* @param dir either {@link #DIRECTION_RTL} or {@link #DIRECTION_LTR}
* @param offset the cursor position to move from
* @param cursorOpt how to move the cursor, one of {@link #CURSOR_AFTER},
* {@link #CURSOR_AT_OR_AFTER}, {@link #CURSOR_BEFORE},
@@ -2054,22 +2047,22 @@ public class Paint {
* @hide
*/
public int getTextRunCursor(CharSequence text, int contextStart,
int contextEnd, int flags, int offset, int cursorOpt) {
int contextEnd, int dir, int offset, int cursorOpt) {
if (text instanceof String || text instanceof SpannedString ||
text instanceof SpannableString) {
return getTextRunCursor(text.toString(), contextStart, contextEnd,
flags, offset, cursorOpt);
dir, offset, cursorOpt);
}
if (text instanceof GraphicsOperations) {
return ((GraphicsOperations) text).getTextRunCursor(
contextStart, contextEnd, flags, offset, cursorOpt, this);
contextStart, contextEnd, dir, offset, cursorOpt, this);
}
int contextLen = contextEnd - contextStart;
char[] buf = TemporaryBuffer.obtain(contextLen);
TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
int result = getTextRunCursor(buf, 0, contextLen, flags, offset - contextStart, cursorOpt);
int result = getTextRunCursor(buf, 0, contextLen, dir, offset - contextStart, cursorOpt);
TemporaryBuffer.recycle(buf);
return result;
}
@@ -2092,7 +2085,7 @@ public class Paint {
* @param text the text
* @param contextStart the start of the context
* @param contextEnd the end of the context
* @param flags either {@link #DIRECTION_RTL} or {@link #DIRECTION_LTR}
* @param dir either {@link #DIRECTION_RTL} or {@link #DIRECTION_LTR}
* @param offset the cursor position to move from
* @param cursorOpt how to move the cursor, one of {@link #CURSOR_AFTER},
* {@link #CURSOR_AT_OR_AFTER}, {@link #CURSOR_BEFORE},
@@ -2101,7 +2094,7 @@ public class Paint {
* @hide
*/
public int getTextRunCursor(String text, int contextStart, int contextEnd,
int flags, int offset, int cursorOpt) {
int dir, int offset, int cursorOpt) {
if (((contextStart | contextEnd | offset | (contextEnd - contextStart)
| (offset - contextStart) | (contextEnd - offset)
| (text.length() - contextEnd) | cursorOpt) < 0)
@@ -2110,7 +2103,7 @@ public class Paint {
}
return native_getTextRunCursor(mNativePaint, text,
contextStart, contextEnd, flags, offset, cursorOpt);
contextStart, contextEnd, dir, offset, cursorOpt);
}
/**
@@ -2156,7 +2149,7 @@ public class Paint {
native_getTextPath(mNativePaint, mNativeTypeface, mBidiFlags, text, start, end, x, y,
path.ni());
}
/**
* Return in bounds (allocated by the caller) the smallest rectangle that
* encloses all of the characters, with an implied origin at (0,0).
@@ -2176,7 +2169,7 @@ public class Paint {
}
nativeGetStringBounds(mNativePaint, mNativeTypeface, text, start, end, mBidiFlags, bounds);
}
/**
* Return in bounds (allocated by the caller) the smallest rectangle that
* encloses all of the characters, with an implied origin at (0,0).
@@ -2197,7 +2190,7 @@ public class Paint {
nativeGetCharArrayBounds(mNativePaint, mNativeTypeface, text, index, count, mBidiFlags,
bounds);
}
@Override
protected void finalize() throws Throwable {
try {
@@ -2252,15 +2245,15 @@ public class Paint {
private static native float native_getTextRunAdvances(long native_object, long native_typeface,
char[] text, int index, int count, int contextIndex, int contextCount,
int flags, float[] advances, int advancesIndex);
boolean isRtl, float[] advances, int advancesIndex);
private static native float native_getTextRunAdvances(long native_object, long native_typeface,
String text, int start, int end, int contextStart, int contextEnd,
int flags, float[] advances, int advancesIndex);
boolean isRtl, float[] advances, int advancesIndex);
private native int native_getTextRunCursor(long native_object, char[] text,
int contextStart, int contextLength, int flags, int offset, int cursorOpt);
int contextStart, int contextLength, int dir, int offset, int cursorOpt);
private native int native_getTextRunCursor(long native_object, String text,
int contextStart, int contextEnd, int flags, int offset, int cursorOpt);
int contextStart, int contextEnd, int dir, int offset, int cursorOpt);
private static native void native_getTextPath(long native_object, long native_typeface,
int bidiFlags, char[] text, int index, int count, float x, float y, long path);