Example usage for android.graphics Matrix preSkew

List of usage examples for android.graphics Matrix preSkew

Introduction

In this page you can find the example usage for android.graphics Matrix preSkew.

Prototype

public boolean preSkew(float kx, float ky) 

Source Link

Document

Preconcats the matrix with the specified skew.

Usage

From source file:com.jiahuan.svgmapview.core.helper.map.SVGParser.java

private static Matrix parseTransformItem(String s, Matrix matrix) {
    if (s.startsWith("matrix(")) {
        NumberParse np = parseNumbers(s.substring("matrix(".length()));
        if (np.numbers.size() == 6) {
            Matrix mat = new Matrix();
            mat.setValues(new float[] {
                    // Row 1
                    np.numbers.get(0), np.numbers.get(2), np.numbers.get(4),
                    // Row 2
                    np.numbers.get(1), np.numbers.get(3), np.numbers.get(5),
                    // Row 3
                    0, 0, 1, });//from w ww .j  a  va 2 s .com
            matrix.preConcat(mat);
        }
    } else if (s.startsWith("translate(")) {
        NumberParse np = parseNumbers(s.substring("translate(".length()));
        if (np.numbers.size() > 0) {
            float tx = np.numbers.get(0);
            float ty = 0;
            if (np.numbers.size() > 1) {
                ty = np.numbers.get(1);
            }
            matrix.preTranslate(tx, ty);
        }
    } else if (s.startsWith("scale(")) {
        NumberParse np = parseNumbers(s.substring("scale(".length()));
        if (np.numbers.size() > 0) {
            float sx = np.numbers.get(0);
            float sy = sx;
            if (np.numbers.size() > 1) {
                sy = np.numbers.get(1);
            }
            matrix.preScale(sx, sy);
        }
    } else if (s.startsWith("skewX(")) {
        NumberParse np = parseNumbers(s.substring("skewX(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            matrix.preSkew((float) Math.tan(angle), 0);
        }
    } else if (s.startsWith("skewY(")) {
        NumberParse np = parseNumbers(s.substring("skewY(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            matrix.preSkew(0, (float) Math.tan(angle));
        }
    } else if (s.startsWith("rotate(")) {
        NumberParse np = parseNumbers(s.substring("rotate(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            float cx = 0;
            float cy = 0;
            if (np.numbers.size() > 2) {
                cx = np.numbers.get(1);
                cy = np.numbers.get(2);
            }
            matrix.preTranslate(-cx, -cy);
            matrix.preRotate(angle);
            matrix.preTranslate(cx, cy);
        }
    } else {
        Log.w(TAG, "Invalid transform (" + s + ")");
    }
    return matrix;
}

From source file:com.larvalabs.svgandroid.SVGParser.java

private static Matrix parseTransformItem(String s, Matrix matrix) {
    if (s.startsWith("matrix(")) {
        NumberParse np = parseNumbers(s.substring("matrix(".length()));
        if (np.numbers.size() == 6) {
            Matrix mat = new Matrix();
            mat.setValues(new float[] {
                    // Row 1
                    np.numbers.get(0), np.numbers.get(2), np.numbers.get(4),
                    // Row 2
                    np.numbers.get(1), np.numbers.get(3), np.numbers.get(5),
                    // Row 3
                    0, 0, 1, });//from  www  .j  a  va2  s . c o  m
            matrix.preConcat(mat);
        }
    } else if (s.startsWith("translate(")) {
        NumberParse np = parseNumbers(s.substring("translate(".length()));
        if (np.numbers.size() > 0) {
            float tx = np.numbers.get(0);
            float ty = 0;
            if (np.numbers.size() > 1) {
                ty = np.numbers.get(1);
            }
            matrix.preTranslate(tx, ty);
        }
    } else if (s.startsWith("scale(")) {
        NumberParse np = parseNumbers(s.substring("scale(".length()));
        if (np.numbers.size() > 0) {
            float sx = np.numbers.get(0);
            float sy = sx;
            if (np.numbers.size() > 1) {
                sy = np.numbers.get(1);
            }
            matrix.preScale(sx, sy);
        }
    } else if (s.startsWith("skewX(")) {
        NumberParse np = parseNumbers(s.substring("skewX(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            matrix.preSkew((float) Math.tan(angle), 0);
        }
    } else if (s.startsWith("skewY(")) {
        NumberParse np = parseNumbers(s.substring("skewY(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            matrix.preSkew(0, (float) Math.tan(angle));
        }
    } else if (s.startsWith("rotate(")) {
        NumberParse np = parseNumbers(s.substring("rotate(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            float cx = 0;
            float cy = 0;
            if (np.numbers.size() > 2) {
                cx = np.numbers.get(1);
                cy = np.numbers.get(2);
            }
            matrix.preTranslate(cx, cy);
            matrix.preRotate(angle);
            matrix.preTranslate(-cx, -cy);
        }
    } else {
        Log.i(TAG, "Invalid transform (" + s + ")");
    }
    return matrix;
}