diff options
author | Steve Kondik <shade@chemlab.org> | 2010-06-22 13:02:13 -0400 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2010-06-22 13:02:13 -0400 |
commit | 3a5bfe958ded4041f69831c9f6e48c2973372c0e (patch) | |
tree | ec3038b5db83feff314643128adeb3ef3ad88dcc | |
parent | 4c4d50909f1b65a0c4b1580c523dbb27d9aa0ba7 (diff) | |
download | android_frameworks_base-eclair.tar.gz android_frameworks_base-eclair.tar.bz2 android_frameworks_base-eclair.zip |
Fix garbled text rendering.eclair
Thanks to Dudy Kohen for the quick fix.
-rw-r--r-- | graphics/java/android/graphics/Canvas.java | 132 |
1 files changed, 66 insertions, 66 deletions
diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index ff52c15385d..82e2eaf9d9b 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -36,7 +36,7 @@ public class Canvas { final int mNativeCanvas; private static final char FIRST_RIGHT_TO_LEFT = '\u0590'; private static final char LAST_RIGHT_TO_LEFT = '\u07b1'; - + /* Our native canvas can be either a raster, gl, or picture canvas. If we are raster, then mGL will be null, and mBitmap may or may not be present (our default constructor creates a raster canvas but no @@ -46,7 +46,7 @@ public class Canvas { */ private Bitmap mBitmap; // if not null, mGL must be null private GL mGL; // if not null, mBitmap must be null - + // optional field set by the caller private DrawFilter mDrawFilter; @@ -55,7 +55,7 @@ public class Canvas { // Used to determine when compatibility scaling is in effect. private int mScreenDensity = Bitmap.DENSITY_NONE; - + // Used by native code @SuppressWarnings({"UnusedDeclaration"}) private int mSurfaceFormat; @@ -74,7 +74,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. * @@ -90,7 +90,7 @@ public class Canvas { mBitmap = bitmap; mDensity = bitmap.mDensity; } - + /*package*/ Canvas(int nativeCanvas) { if (nativeCanvas == 0) { throw new IllegalStateException(); @@ -98,14 +98,14 @@ public class Canvas { mNativeCanvas = nativeCanvas; mDensity = Bitmap.getDefaultDensity(); } - + /** * Construct a canvas with the specified gl context. All drawing through * this canvas will be redirected to OpenGL. Note: some features may not * be supported in this mode (e.g. some GL implementations may not support * antialiasing or certain effects like ColorMatrix or certain Xfermodes). * However, no exception will be thrown in those cases. - * + * * <p>The initial target density of the canvas is the same as the initial * density of bitmaps as per {@link Bitmap#getDensity() Bitmap.getDensity()}. */ @@ -114,7 +114,7 @@ public class Canvas { mGL = gl; mDensity = Bitmap.getDefaultDensity(); } - + /** * Return the GL object associated with this canvas, or null if it is not * backed by GL. @@ -122,7 +122,7 @@ public class Canvas { public GL getGL() { return mGL; } - + /** * Call this to free up OpenGL resources that may be cached or allocated * on behalf of the Canvas. Any subsequent drawing with a GL-backed Canvas @@ -131,13 +131,13 @@ public class Canvas { public static void freeGlCaches() { freeCaches(); } - + /** * Specify a bitmap for the canvas to draw into. As a side-effect, also * updates the canvas's target density to match that of the bitmap. * * @param bitmap Specifies a mutable bitmap for the canvas to draw into. - * + * * @see #setDensity(int) * @see #getDensity() */ @@ -154,7 +154,7 @@ public class Canvas { mBitmap = bitmap; mDensity = bitmap.mDensity; } - + /** * Set the viewport dimensions if this canvas is GL based. If it is not, * this method is ignored and no exception is thrown. @@ -199,7 +199,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; @@ -215,7 +215,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) { @@ -228,7 +228,7 @@ public class Canvas { public void setScreenDensity(int density) { mScreenDensity = density; } - + // the SAVE_FLAG constants must match their native equivalents /** restore the current matrix when restore() is called */ @@ -242,8 +242,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 @@ -254,7 +254,7 @@ public class Canvas { * @return The value to pass to restoreToCount() to balance this save() */ public native int save(); - + /** * Based on saveFlags, can save the current matrix and clip onto a private * stack. Subsequent calls to translate,scale,rotate,skew,concat or @@ -289,7 +289,7 @@ public class Canvas { paint != null ? paint.mNativePaint : 0, saveFlags); } - + /** * Helper version of saveLayer() that takes 4 values rather than a RectF. */ @@ -320,7 +320,7 @@ public class Canvas { alpha = Math.min(255, Math.max(0, alpha)); return native_saveLayerAlpha(mNativeCanvas, bounds, alpha, saveFlags); } - + /** * Helper for saveLayerAlpha() that takes 4 values instead of a RectF. */ @@ -424,7 +424,7 @@ public class Canvas { public void concat(Matrix matrix) { native_concat(mNativeCanvas, 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. @@ -436,7 +436,7 @@ public class Canvas { native_setMatrix(mNativeCanvas, 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. @@ -444,7 +444,7 @@ public class Canvas { public void getMatrix(Matrix ctm) { native_getCTM(mNativeCanvas, ctm.native_instance); } - + /** * Return a new matrix with a copy of the canvas' current transformation * matrix. @@ -454,7 +454,7 @@ public class Canvas { getMatrix(m); return m; } - + /** * Modify the current clip with the specified rectangle. * @@ -490,7 +490,7 @@ public class Canvas { * @return true if the resulting clip is non-empty */ public native boolean clipRect(RectF rect); - + /** * Intersect the current clip with the specified rectangle, which is * expressed in local coordinates. @@ -499,7 +499,7 @@ public class Canvas { * @return true if the resulting clip is non-empty */ public native boolean clipRect(Rect rect); - + /** * Modify the current clip with the specified rectangle, which is * expressed in local coordinates. @@ -536,7 +536,7 @@ public class Canvas { */ public native boolean clipRect(float left, float top, float right, float bottom); - + /** * Intersect the current clip with the specified rectangle, which is * expressed in local coordinates. @@ -552,7 +552,7 @@ public class Canvas { */ public native boolean clipRect(int left, int top, int right, int bottom); - + /** * Modify the current clip with the specified path. * @@ -563,7 +563,7 @@ public class Canvas { public boolean clipPath(Path path, Region.Op op) { return native_clipPath(mNativeCanvas, path.ni(), op.nativeInt); } - + /** * Intersect the current clip with the specified path. * @@ -573,7 +573,7 @@ public class Canvas { public boolean clipPath(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 @@ -602,11 +602,11 @@ public class Canvas { public boolean clipRegion(Region region) { return clipRegion(region, Region.Op.INTERSECT); } - + public DrawFilter getDrawFilter() { return mDrawFilter; } - + public void setDrawFilter(DrawFilter filter) { int nativeFilter = 0; if (filter != null) { @@ -619,7 +619,7 @@ public class Canvas { public enum EdgeType { BW(0), //!< treat edges by just rounding to nearest pixel boundary AA(1); //!< treat edges by rounding-out, since they may be antialiased - + EdgeType(int nativeInt) { this.nativeInt = nativeInt; } @@ -697,7 +697,7 @@ public class Canvas { public boolean getClipBounds(Rect bounds) { return native_getClipBounds(mNativeCanvas, bounds); } - + /** * Retrieve the clip bounds. * @@ -708,7 +708,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. @@ -765,7 +765,7 @@ public class Canvas { public void drawPaint(Paint paint) { native_drawPaint(mNativeCanvas, 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 @@ -855,7 +855,7 @@ public class Canvas { public void drawRect(Rect r, Paint paint) { drawRect(r.left, r.top, r.right, r.bottom, paint); } - + /** * Draw the specified Rect using the specified paint. The rectangle will @@ -951,7 +951,7 @@ public class Canvas { public void drawPath(Path path, Paint paint) { native_drawPath(mNativeCanvas, path.ni(), paint.mNativePaint); } - + private static void throwIfRecycled(Bitmap bitmap) { if (bitmap.isRecycled()) { throw new RuntimeException( @@ -962,7 +962,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. @@ -972,7 +972,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 @@ -989,7 +989,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. @@ -1000,7 +1000,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 @@ -1021,7 +1021,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. @@ -1032,7 +1032,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 @@ -1048,7 +1048,7 @@ public class Canvas { 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 @@ -1095,7 +1095,7 @@ public class Canvas { native_drawBitmap(mNativeCanvas, colors, offset, stride, x, y, width, height, hasAlpha, paint != null ? paint.mNativePaint : 0); } - + /** Legacy version of drawBitmap(int[] colors, ...) that took ints for x,y */ public void drawBitmap(int[] colors, int offset, int stride, int x, int y, @@ -1105,7 +1105,7 @@ public class Canvas { drawBitmap(colors, offset, stride, (float)x, (float)y, width, height, hasAlpha, paint); } - + /** * Draw the bitmap using the specified matrix. * @@ -1117,13 +1117,13 @@ public class Canvas { nativeDrawBitmapMatrix(mNativeCanvas, bitmap.ni(), matrix.ni(), paint != null ? paint.mNativePaint : 0); } - + private static void checkRange(int length, int offset, int count) { if ((offset | count) < 0 || offset + count > length) { 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 @@ -1170,18 +1170,18 @@ public class Canvas { verts, vertOffset, colors, colorOffset, paint != null ? paint.mNativePaint : 0); } - + public enum VertexMode { TRIANGLES(0), TRIANGLE_STRIP(1), TRIANGLE_FAN(2); - + VertexMode(int nativeInt) { this.nativeInt = nativeInt; } 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 @@ -1210,7 +1210,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(VertexMode mode, int vertexCount, float[] verts, int vertOffset, @@ -1337,7 +1337,7 @@ public class Canvas { return str.toCharArray(); } - + /** @hide **/ public void drawText(char[] text, int index, int count, float x, float y, Paint paint,boolean bidi) { @@ -1349,14 +1349,14 @@ public class Canvas { if (bidi) { char[] bidiText; bidiText=bidiProcess(text,index,count); - native_drawText(mNativeCanvas, bidiText, index, count, x, y, + native_drawText(mNativeCanvas, bidiText, 0, count, x, y, paint.mNativePaint); } else { native_drawText(mNativeCanvas, text, index, count, x, y, paint.mNativePaint); } } - + /** * Draw the text, with origin at (x,y), using the specified paint. The * origin is interpreted based on the Align setting in the paint. @@ -1372,10 +1372,10 @@ public class Canvas { (text.length - index - count)) < 0) { throw new IndexOutOfBoundsException(); } - + char[] bidiText; bidiText=bidiProcess(text,index,count); - native_drawText(mNativeCanvas, bidiText, index, count, x, y, + native_drawText(mNativeCanvas, bidiText, 0, count, x, y, paint.mNativePaint); } @@ -1462,7 +1462,7 @@ public class Canvas { TemporaryBuffer.recycle(buf); } } - + /** @hide */ public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint,boolean bidi) { @@ -1506,7 +1506,7 @@ public class Canvas { if (index < 0 || index + count > text.length || count*2 > pos.length) { throw new IndexOutOfBoundsException(); } - + char[] bidiText; bidiText=bidiProcess(text,index,count); native_drawPosText(mNativeCanvas, bidiText, 0, count, pos, @@ -1526,7 +1526,7 @@ public class Canvas { if (text.length()*2 > pos.length) { throw new ArrayIndexOutOfBoundsException(); } - + String bidiText; bidiText=new String(bidiProcess(text.toCharArray(),0,text.length())); native_drawPosText(mNativeCanvas, bidiText, pos, paint.mNativePaint); @@ -1586,14 +1586,14 @@ public class Canvas { * Save the canvas state, draw the picture, and restore the canvas state. * This differs from picture.draw(canvas), which does not perform any * save/restore. - * + * * @param picture The picture to be drawn */ public void drawPicture(Picture picture) { picture.endRecording(); native_drawPicture(mNativeCanvas, picture.ni()); } - + /** * Draw the picture, stretched to fit into the dst rectangle. */ @@ -1607,7 +1607,7 @@ public class Canvas { drawPicture(picture); restore(); } - + /** * Draw the picture, stretched to fit into the dst rectangle. */ @@ -1621,7 +1621,7 @@ public class Canvas { drawPicture(picture); restore(); } - + protected void finalize() throws Throwable { super.finalize(); // If the constructor threw an exception before setting mNativeCanvas, the native finalizer @@ -1742,7 +1742,7 @@ public class Canvas { float[] verts, int vertOffset, float[] texs, int texOffset, int[] colors, int colorOffset, short[] indices, int indexOffset, int indexCount, int nPaint); - + private static native void native_drawText(int nativeCanvas, char[] text, int index, int count, float x, float y, int paint); |