From 2b30269d11f85fea9f942471193f1d59e7b6d7ac Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Mon, 11 Jan 2016 13:39:10 +0100 Subject: Fix drawing of VectorDrawables that are rotated by 90 or 270 degrees. The SCALE_X / SCALE_Y values of rotated matrices are set to the cosine of the rotation angle, which is 0 for drawables that are rotated by 90 or 270 degrees. Map the matrix onto the bounds rectangle and use the resulting size to determine the scaled size instead. Change-Id: I6cc0f0b5569d43434c829cb5f6e5f848cad995ec --- graphics/java/android/graphics/drawable/VectorDrawable.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'graphics') diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java index 1cfccc4..6d3bf3e 100644 --- a/graphics/java/android/graphics/drawable/VectorDrawable.java +++ b/graphics/java/android/graphics/drawable/VectorDrawable.java @@ -32,6 +32,7 @@ import android.graphics.PathMeasure; import android.graphics.PixelFormat; import android.graphics.PorterDuffColorFilter; import android.graphics.Rect; +import android.graphics.RectF; import android.graphics.PorterDuff.Mode; import android.util.ArrayMap; import android.util.AttributeSet; @@ -225,9 +226,9 @@ public class VectorDrawable extends Drawable { private Insets mDpiScaleInsets = Insets.NONE; // Temp variable, only for saving "new" operation at the draw() time. - private final float[] mTmpFloats = new float[9]; private final Matrix mTmpMatrix = new Matrix(); private final Rect mTmpBounds = new Rect(); + private final RectF mTmpDstBounds = new RectF(); public VectorDrawable() { this(null, null); @@ -288,11 +289,10 @@ public class VectorDrawable extends Drawable { // size first. This bitmap size is determined by the bounds and the // canvas scale. canvas.getMatrix(mTmpMatrix); - mTmpMatrix.getValues(mTmpFloats); - float canvasScaleX = Math.abs(mTmpFloats[Matrix.MSCALE_X]); - float canvasScaleY = Math.abs(mTmpFloats[Matrix.MSCALE_Y]); - int scaledWidth = (int) (mTmpBounds.width() * canvasScaleX); - int scaledHeight = (int) (mTmpBounds.height() * canvasScaleY); + mTmpDstBounds.set(mTmpBounds); + mTmpMatrix.mapRect(mTmpDstBounds); + int scaledWidth = (int) mTmpDstBounds.width(); + int scaledHeight = (int) mTmpDstBounds.height(); scaledWidth = Math.min(MAX_CACHED_BITMAP_SIZE, scaledWidth); scaledHeight = Math.min(MAX_CACHED_BITMAP_SIZE, scaledHeight); -- cgit v1.1