Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 63cfd85b authored by ztenghui's avatar ztenghui
Browse files

Move the rotation information from path to group.

Also update the 3rd test to correctly testing clipping.

Removing some naive tests which rotate 360 or 0.

bug:15288554

Change-Id: I436e8e494cb78fc665a3890171a1af87367db419
parent 69170a56
Loading
Loading
Loading
Loading
+12 −6
Original line number Original line Diff line number Diff line
@@ -4780,6 +4780,18 @@
        <attr name="height" />
        <attr name="height" />
    </declare-styleable>
    </declare-styleable>


    <!-- Defines the group used in Vector Drawables. -->
    <declare-styleable name="VectorDrawableGroup">
        <!-- The Name of this group -->
        <attr name="name" />
        <!-- The amount to rotate the group -->
        <attr name="rotation" />
        <!-- The X coordinate of the center of rotation of a group -->
        <attr name="pivotX" />
        <!-- The Y coordinate of the center of rotation of a group -->
        <attr name="pivotY" />
    </declare-styleable>

    <!-- Defines the path used in Vector Drawables. -->
    <!-- Defines the path used in Vector Drawables. -->
    <declare-styleable name="VectorDrawablePath">
    <declare-styleable name="VectorDrawablePath">
        <!-- The Name of this path -->
        <!-- The Name of this path -->
@@ -4788,12 +4800,6 @@
        <attr name="strokeWidth" format="float" />
        <attr name="strokeWidth" format="float" />
        <!-- The opacity of a path stroke -->
        <!-- The opacity of a path stroke -->
        <attr name="strokeOpacity" format="float" />
        <attr name="strokeOpacity" format="float" />
        <!-- The amount to rotate the path stroke -->
        <attr name="rotation" />
        <!-- The X coordinate of the center of rotation of a path -->
        <attr name="pivotX" />
        <!-- The Y coordinate of the center of rotation of a path -->
        <attr name="pivotY" />
        <!-- The color to stroke the path if not defined implies no stroke-->
        <!-- The color to stroke the path if not defined implies no stroke-->
        <attr name="stroke" format="color" />
        <attr name="stroke" format="color" />
        <!-- The color to fill the path if not defined implies no fill-->
        <!-- The color to fill the path if not defined implies no fill-->
+116 −139
Original line number Original line Diff line number Diff line
@@ -39,7 +39,6 @@ import org.xmlpull.v1.XmlPullParserFactory;
import java.io.IOException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashMap;


/**
/**
@@ -289,6 +288,7 @@ public class VectorDrawable extends Drawable {
                    noViewportTag = false;
                    noViewportTag = false;
                } else if (SHAPE_GROUP.equals(tagName)) {
                } else if (SHAPE_GROUP.equals(tagName)) {
                    currentGroup = new VGroup();
                    currentGroup = new VGroup();
                    currentGroup.inflate(res, attrs, theme);
                    pathRenderer.mGroupList.add(currentGroup);
                    pathRenderer.mGroupList.add(currentGroup);
                    noGroupTag = false;
                    noGroupTag = false;
                }
                }
@@ -325,8 +325,6 @@ public class VectorDrawable extends Drawable {
            throw new XmlPullParserException("no " + tag + " defined");
            throw new XmlPullParserException("no " + tag + " defined");
        }
        }


        // post parse cleanup
        pathRenderer.parseFinish();
        return pathRenderer;
        return pathRenderer;
    }
    }


@@ -373,7 +371,6 @@ public class VectorDrawable extends Drawable {
        private final Path mRenderPath = new Path();
        private final Path mRenderPath = new Path();
        private final Matrix mMatrix = new Matrix();
        private final Matrix mMatrix = new Matrix();


        private VPath[] mCurrentPaths;
        private Paint mStrokePaint;
        private Paint mStrokePaint;
        private Paint mFillPaint;
        private Paint mFillPaint;
        private ColorFilter mColorFilter;
        private ColorFilter mColorFilter;
@@ -391,12 +388,6 @@ public class VectorDrawable extends Drawable {


        public VPathRenderer(VPathRenderer copy) {
        public VPathRenderer(VPathRenderer copy) {
            mGroupList.addAll(copy.mGroupList);
            mGroupList.addAll(copy.mGroupList);
            if (copy.mCurrentPaths != null) {
                mCurrentPaths = new VPath[copy.mCurrentPaths.length];
                for (int i = 0; i < mCurrentPaths.length; i++) {
                    mCurrentPaths[i] = new VPath(copy.mCurrentPaths[i]);
                }
            }


            mBaseWidth = copy.mBaseWidth;
            mBaseWidth = copy.mBaseWidth;
            mBaseHeight = copy.mBaseHeight;
            mBaseHeight = copy.mBaseHeight;
@@ -422,7 +413,9 @@ public class VectorDrawable extends Drawable {
        public void applyTheme(Theme t) {
        public void applyTheme(Theme t) {
            final ArrayList<VGroup> groups = mGroupList;
            final ArrayList<VGroup> groups = mGroupList;
            for (int i = groups.size() - 1; i >= 0; i--) {
            for (int i = groups.size() - 1; i >= 0; i--) {
                final ArrayList<VPath> paths = groups.get(i).mVGList;
                VGroup currentGroup = groups.get(i);
                currentGroup.applyTheme(t);
                final ArrayList<VPath> paths = currentGroup.mVGList;
                for (int j = paths.size() - 1; j >= 0; j--) {
                for (int j = paths.size() - 1; j >= 0; j--) {
                    final VPath path = paths.get(j);
                    final VPath path = paths.get(j);
                    if (path.canApplyTheme()) {
                    if (path.canApplyTheme()) {
@@ -446,21 +439,31 @@ public class VectorDrawable extends Drawable {
        }
        }


        public void draw(Canvas canvas, int w, int h) {
        public void draw(Canvas canvas, int w, int h) {
            if (mCurrentPaths == null) {
            if (mGroupList == null || mGroupList.size() == 0) {
                Log.e(LOGTAG,"mCurrentPaths == null");
                Log.e(LOGTAG,"There is no group to draw");
                return;
                return;
            }
            }


            for (int i = 0; i < mCurrentPaths.length; i++) {
            for (int i = 0; i < mGroupList.size(); i++) {
                if (mCurrentPaths[i] != null) {
                VGroup currentGroup = mGroupList.get(i);
                    drawPath(mCurrentPaths[i], canvas, w, h);
                if (currentGroup != null) {
                    drawPath(currentGroup, canvas, w, h);
                }
                }
            }
            }
        }
        }


        private void drawPath(VPath vPath, Canvas canvas, int w, int h) {
        private void drawPath(VGroup vGroup, Canvas canvas, int w, int h) {
            final float scale = Math.min(h / mViewportHeight, w / mViewportWidth);
            final float scale = Math.min(h / mViewportHeight, w / mViewportWidth);


            mMatrix.reset();

            mMatrix.postRotate(vGroup.mRotate, vGroup.mPivotX, vGroup.mPivotY);
            mMatrix.postScale(scale, scale, mViewportWidth / 2f, mViewportHeight / 2f);
            mMatrix.postTranslate(w / 2f - mViewportWidth / 2f, h / 2f - mViewportHeight / 2f);

            ArrayList<VPath> paths = vGroup.getPaths();
            for (int i = 0; i < paths.size(); i++) {
                VPath vPath = paths.get(i);
                vPath.toPath(mPath);
                vPath.toPath(mPath);
                final Path path = mPath;
                final Path path = mPath;


@@ -487,11 +490,6 @@ public class VectorDrawable extends Drawable {
                }
                }


                mRenderPath.reset();
                mRenderPath.reset();
            mMatrix.reset();

            mMatrix.postRotate(vPath.mRotate, vPath.mPivotX, vPath.mPivotY);
            mMatrix.postScale(scale, scale, mViewportWidth / 2f, mViewportHeight / 2f);
            mMatrix.postTranslate(w / 2f - mViewportWidth / 2f, h / 2f - mViewportHeight / 2f);


                mRenderPath.addPath(path, mMatrix);
                mRenderPath.addPath(path, mMatrix);


@@ -534,17 +532,6 @@ public class VectorDrawable extends Drawable {
                    canvas.drawPath(mRenderPath, strokePaint);
                    canvas.drawPath(mRenderPath, strokePaint);
                }
                }
            }
            }

        /**
         * Build the "current" path based on the current group
         * TODO: improve memory use & performance or move to C++
         */
        public void parseFinish() {
            final Collection<VPath> paths = mGroupList.get(0).getPaths();
            mCurrentPaths = paths.toArray(new VPath[paths.size()]);
            for (int i = 0; i < mCurrentPaths.length; i++) {
                mCurrentPaths[i] = new VPath(mCurrentPaths[i]);
            }
        }
        }


        private void parseViewport(Resources r, AttributeSet attrs)
        private void parseViewport(Resources r, AttributeSet attrs)
@@ -587,17 +574,60 @@ public class VectorDrawable extends Drawable {
        private final HashMap<String, VPath> mVGPathMap = new HashMap<String, VPath>();
        private final HashMap<String, VPath> mVGPathMap = new HashMap<String, VPath>();
        private final ArrayList<VPath> mVGList = new ArrayList<VPath>();
        private final ArrayList<VPath> mVGList = new ArrayList<VPath>();


        private float mRotate = 0;
        private float mPivotX = 0;
        private float mPivotY = 0;

        private int[] mThemeAttrs;

        public void add(VPath path) {
        public void add(VPath path) {
            String id = path.getID();
            String id = path.getID();
            mVGPathMap.put(id, path);
            mVGPathMap.put(id, path);
            mVGList.add(path);
            mVGList.add(path);
         }
         }


        public void applyTheme(Theme t) {
            if (mThemeAttrs == null) {
                return;
            }

            final TypedArray a = t.resolveAttributes(
                    mThemeAttrs, R.styleable.VectorDrawablePath);

            mRotate = a.getFloat(R.styleable.VectorDrawableGroup_rotation, mRotate);
            mPivotX = a.getFloat(R.styleable.VectorDrawableGroup_pivotX, mPivotX);
            mPivotY = a.getFloat(R.styleable.VectorDrawableGroup_pivotY, mPivotY);
            a.recycle();
        }

        public void inflate(Resources res, AttributeSet attrs, Theme theme) {
            final TypedArray a = obtainAttributes(res, theme, attrs, R.styleable.VectorDrawableGroup);
            final int[] themeAttrs = a.extractThemeAttrs();

            mThemeAttrs = themeAttrs;
            // NOTE: The set of attributes loaded here MUST match the
            // set of attributes loaded in applyTheme.

            if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawableGroup_rotation] == 0) {
                mRotate = a.getFloat(R.styleable.VectorDrawableGroup_rotation, mRotate);
            }

            if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawableGroup_pivotX] == 0) {
                mPivotX = a.getFloat(R.styleable.VectorDrawableGroup_pivotX, mPivotX);
            }

            if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawableGroup_pivotY] == 0) {
                mPivotY = a.getFloat(R.styleable.VectorDrawableGroup_pivotY, mPivotY);
            }

            a.recycle();
        }

        /**
        /**
         * Must return in order of adding
         * Must return in order of adding
         * @return ordered list of paths
         * @return ordered list of paths
         */
         */
        public Collection<VPath> getPaths() {
        public ArrayList<VPath> getPaths() {
            return mVGList;
            return mVGList;
        }
        }


@@ -616,10 +646,6 @@ public class VectorDrawable extends Drawable {
        int mFillRule;
        int mFillRule;
        float mFillOpacity = Float.NaN;
        float mFillOpacity = Float.NaN;


        float mRotate = 0;
        float mPivotX = 0;
        float mPivotY = 0;

        float mTrimPathStart = 0;
        float mTrimPathStart = 0;
        float mTrimPathEnd = 1;
        float mTrimPathEnd = 1;
        float mTrimPathOffset = 0;
        float mTrimPathOffset = 0;
@@ -631,18 +657,11 @@ public class VectorDrawable extends Drawable {


        private VNode[] mNode = null;
        private VNode[] mNode = null;
        private String mId;
        private String mId;
        private int[] mCheckState = new int[MAX_STATES];
        private boolean[] mCheckValue = new boolean[MAX_STATES];
        private int mNumberOfStates = 0;


        public VPath() {
        public VPath() {
            // Empty constructor.
            // Empty constructor.
        }
        }


        public VPath(VPath p) {
            copyFrom(p);
        }

        public void toPath(Path path) {
        public void toPath(Path path) {
            path.reset();
            path.reset();
            if (mNode != null) {
            if (mNode != null) {
@@ -707,18 +726,6 @@ public class VectorDrawable extends Drawable {
                mFillOpacity = a.getFloat(R.styleable.VectorDrawablePath_fillOpacity, mFillOpacity);
                mFillOpacity = a.getFloat(R.styleable.VectorDrawablePath_fillOpacity, mFillOpacity);
            }
            }


            if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawablePath_rotation] == 0) {
                mRotate = a.getFloat(R.styleable.VectorDrawablePath_rotation, mRotate);
            }

            if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawablePath_pivotX] == 0) {
                mPivotX = a.getFloat(R.styleable.VectorDrawablePath_pivotX, mPivotX);
            }

            if (themeAttrs == null || themeAttrs[R.styleable.VectorDrawablePath_pivotY] == 0) {
                mPivotY = a.getFloat(R.styleable.VectorDrawablePath_pivotY, mPivotY);
            }

            if (themeAttrs == null
            if (themeAttrs == null
                    || themeAttrs[R.styleable.VectorDrawablePath_strokeLineCap] == 0) {
                    || themeAttrs[R.styleable.VectorDrawablePath_strokeLineCap] == 0) {
                mStrokeLineCap = getStrokeLineCap(
                mStrokeLineCap = getStrokeLineCap(
@@ -797,10 +804,6 @@ public class VectorDrawable extends Drawable {
            mFillColor = a.getColor(R.styleable.VectorDrawablePath_fill, mFillColor);
            mFillColor = a.getColor(R.styleable.VectorDrawablePath_fill, mFillColor);
            mFillOpacity = a.getFloat(R.styleable.VectorDrawablePath_fillOpacity, mFillOpacity);
            mFillOpacity = a.getFloat(R.styleable.VectorDrawablePath_fillOpacity, mFillOpacity);


            mRotate = a.getFloat(R.styleable.VectorDrawablePath_rotation, mRotate);
            mPivotX = a.getFloat(R.styleable.VectorDrawablePath_pivotX, mPivotX);
            mPivotY = a.getFloat(R.styleable.VectorDrawablePath_pivotY, mPivotY);

            mStrokeLineCap = getStrokeLineCap(a.getInt(
            mStrokeLineCap = getStrokeLineCap(a.getInt(
                    R.styleable.VectorDrawablePath_strokeLineCap, -1), mStrokeLineCap);
                    R.styleable.VectorDrawablePath_strokeLineCap, -1), mStrokeLineCap);
            mStrokeLineJoin = getStrokeLineJoin(a.getInt(
            mStrokeLineJoin = getStrokeLineJoin(a.getInt(
@@ -819,6 +822,7 @@ public class VectorDrawable extends Drawable {
                    R.styleable.VectorDrawablePath_trimPathStart, mTrimPathStart);
                    R.styleable.VectorDrawablePath_trimPathStart, mTrimPathStart);


            updateColorAlphas();
            updateColorAlphas();
            a.recycle();
        }
        }


        private void updateColorAlphas() {
        private void updateColorAlphas() {
@@ -921,33 +925,6 @@ public class VectorDrawable extends Drawable {
            }
            }
            return list.toArray(new VectorDrawable.VNode[list.size()]);
            return list.toArray(new VectorDrawable.VNode[list.size()]);
        }
        }

        public void copyFrom(VPath p1) {
            mNode = new VNode[p1.mNode.length];
            for (int i = 0; i < mNode.length; i++) {
                mNode[i] = new VNode(p1.mNode[i]);
            }
            mId = p1.mId;
            mStrokeColor = p1.mStrokeColor;
            mFillColor = p1.mFillColor;
            mStrokeWidth = p1.mStrokeWidth;
            mRotate = p1.mRotate;
            mPivotX = p1.mPivotX;
            mPivotY = p1.mPivotY;
            mTrimPathStart = p1.mTrimPathStart;
            mTrimPathEnd = p1.mTrimPathEnd;
            mTrimPathOffset = p1.mTrimPathOffset;
            mStrokeLineCap = p1.mStrokeLineCap;
            mStrokeLineJoin = p1.mStrokeLineJoin;
            mStrokeMiterlimit = p1.mStrokeMiterlimit;
            mNumberOfStates = p1.mNumberOfStates;
            for (int i = 0; i < mNumberOfStates; i++) {
                mCheckState[i] = p1.mCheckState[i];
                mCheckValue[i] = p1.mCheckValue[i];
            }

            mFillRule = p1.mFillRule;
        }
    }
    }


    private static class VNode {
    private static class VNode {
+8 −7
Original line number Original line Diff line number Diff line
@@ -20,16 +20,17 @@


    <viewport android:viewportWidth="320"
    <viewport android:viewportWidth="320"
          android:viewportHeight="320"/>
          android:viewportHeight="320"/>

    <group
        android:rotation="180"
        android:pivotX="70"
        android:pivotY="120">
        <path
        <path
            android:name="house"
            android:name="house"
            android:pathData="M 130,225 L 130,115 L 130,115 L 70,15 L 10,115 L 10,115 L 10,225 z"
            android:pathData="M 130,225 L 130,115 L 130,115 L 70,15 L 10,115 L 10,115 L 10,225 z"
            android:fill="#ff440000"
            android:fill="#ff440000"
            android:stroke="#FF00FF00"
            android:stroke="#FF00FF00"
            android:strokeWidth="10"
            android:strokeWidth="10"
            android:rotation="180"
            android:pivotX="70"
            android:pivotY="120"
            android:trimPathStart=".1"
            android:trimPathStart=".1"
            android:trimPathEnd=".9"/>
            android:trimPathEnd=".9"/>
    </group>
</vector>
</vector>
+50 −44
Original line number Original line Diff line number Diff line
<!-- Copyright (C) 2014 The Android Open Source Project
<!--
 Copyright (C) 2014 The Android Open Source Project


     Licensed under the Apache License, Version 2.0 (the "License");
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     you may not use this file except in compliance with the License.
@@ -15,48 +16,53 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" >
<vector xmlns:android="http://schemas.android.com/apk/res/android" >


    <size
    <size
            android:width="64dp"
        android:height="64dp"
            android:height="64dp"/>
        android:width="64dp" />


    <viewport
    <viewport
            android:viewportWidth="7.30625"
        android:viewportHeight="12.25"
            android:viewportHeight="12.25"/>
        android:viewportWidth="7.30625" />


    <group
        android:pivotX="3.65"
        android:pivotY="6.125"
        android:rotation="-30" >
        <path
        <path
            android:name="clip1"
            android:name="clip1"
            android:clipToPath="true"
            android:pathData="
            android:pathData="
            M 0, 0
                M 0, 6.125
                l 7.3, 0
                l 7.3, 0
            l 0, 0
                l 0, 12.25
                l -7.3, 0
                l -7.3, 0
            z"
                z" />
            android:clipToPath="true"
    </group>
            android:rotation="-30"
    <group>
            android:pivotX="3.65"
            android:pivotY="6.125"
            />
        <path
        <path
            android:name="one"
            android:name="one"
            android:fill="#ff88ff"
            android:pathData="M 1.215625,9.5l 1.9375,0.0 0.0,-6.671875 -2.109375,0.421875 0.0,-1.078125
            android:pathData="M 1.215625,9.5l 1.9375,0.0 0.0,-6.671875 -2.109375,0.421875 0.0,-1.078125
                l 2.09375,-0.421875 1.1874998,0.0 0.0,7.75 1.9375,0.0 0.0,1.0
                l 2.09375,-0.421875 1.1874998,0.0 0.0,7.75 1.9375,0.0 0.0,1.0
            l -5.046875,0.0 0.0,-1.0Z"
                l -5.046875,0.0 0.0,-1.0Z" />
            android:fill="#ff88ff"
    </group>
            />
    <group
        android:pivotX="3.65"
        android:pivotY="6.125"
        android:rotation="-30" >
        <path
        <path
            android:name="clip2"
            android:name="clip2"
            android:clipToPath="true"
            android:pathData="
            android:pathData="
                M 0, 0
                M 0, 0
                l 7.3, 0
                l 7.3, 0
            l 0, 12.25
                l 0, 6.125
                l -7.3, 0
                l -7.3, 0
            z"
                z" />
            android:clipToPath="true"
    </group>
            android:rotation="-30"
    <group>
            android:pivotX="3.65"
            android:pivotY="6.125"
            />
        <path
        <path
            android:name="two"
            android:name="two"
            android:fill="#ff88ff"
            android:pathData="M 2.534375,9.6875l 4.140625,0.0 0.0,1.0 -5.5625,0.0 0.0,-1.0q 0.671875,-0.6875 1.828125,-1.859375
            android:pathData="M 2.534375,9.6875l 4.140625,0.0 0.0,1.0 -5.5625,0.0 0.0,-1.0q 0.671875,-0.6875 1.828125,-1.859375
                        q 1.1718752,-1.1875 1.4687502,-1.53125 0.578125,-0.625 0.796875,-1.0625
                        q 1.1718752,-1.1875 1.4687502,-1.53125 0.578125,-0.625 0.796875,-1.0625
                        q 0.234375,-0.453125 0.234375,-0.875 0.0,-0.703125 -0.5,-1.140625
                        q 0.234375,-0.453125 0.234375,-0.875 0.0,-0.703125 -0.5,-1.140625
@@ -65,7 +71,7 @@
                        q 0.625,-0.15625 1.140625,-0.15625 1.3593752,0.0 2.1718752,0.6875
                        q 0.625,-0.15625 1.140625,-0.15625 1.3593752,0.0 2.1718752,0.6875
                        q 0.8125,0.671875 0.8125,1.8125 0.0,0.53125 -0.203125,1.015625
                        q 0.8125,0.671875 0.8125,1.8125 0.0,0.53125 -0.203125,1.015625
                        q -0.203125,0.484375 -0.734375,1.140625 -0.15625,0.171875 -0.9375,0.984375
                        q -0.203125,0.484375 -0.734375,1.140625 -0.15625,0.171875 -0.9375,0.984375
                    q -0.78125024,0.8125 -2.2187502,2.265625Z"
                        q -0.78125024,0.8125 -2.2187502,2.265625Z" />
            android:fill="#ff88ff"
    </group>
            />

</vector>
</vector>
 No newline at end of file
+5 −5
Original line number Original line Diff line number Diff line
@@ -23,14 +23,14 @@
        android:viewportHeight="200"
        android:viewportHeight="200"
        android:viewportWidth="200" />
        android:viewportWidth="200" />


    <group>
    <group
        android:pivotX="100"
        android:pivotY="100"
        android:rotation="90">
        <path
        <path
            android:name="house"
            android:name="house"
            android:fill="#ffffffff"
            android:fill="#ffffffff"
            android:pathData="M 100,20 l 0,0 0,140 -80,0 z M 100,20 l 0,0 80,140 -80,0 z"
            android:pathData="M 100,20 l 0,0 0,140 -80,0 z M 100,20 l 0,0 80,140 -80,0 z"/>
            android:pivotX="100"
            android:pivotY="100"
            android:rotation="90" />
    </group>
    </group>


</vector>
</vector>
 No newline at end of file
Loading