[
  {
    "path": ".classpath",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<classpath>\n\t<classpathentry kind=\"src\" path=\"src\"/>\n\t<classpathentry kind=\"con\" path=\"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6\"/>\n\t<classpathentry kind=\"output\" path=\"bin\"/>\n</classpath>\n"
  },
  {
    "path": ".gitignore",
    "content": "*.class\n\n# Mobile Tools for Java (J2ME)\n.mtj.tmp/\n\n# Package Files #\n*.war\n*.ear\n\n# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml\nhs_err_pid*\n/bin\n"
  },
  {
    "path": ".project",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<projectDescription>\n\t<name>SVGtoDrawable</name>\n\t<comment></comment>\n\t<projects>\n\t</projects>\n\t<buildSpec>\n\t\t<buildCommand>\n\t\t\t<name>org.eclipse.jdt.core.javabuilder</name>\n\t\t\t<arguments>\n\t\t\t</arguments>\n\t\t</buildCommand>\n\t</buildSpec>\n\t<natures>\n\t\t<nature>org.eclipse.jdt.core.javanature</nature>\n\t</natures>\n</projectDescription>\n"
  },
  {
    "path": ".settings/org.eclipse.jdt.core.prefs",
    "content": "eclipse.preferences.version=1\norg.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\norg.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6\norg.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve\norg.eclipse.jdt.core.compiler.compliance=1.6\norg.eclipse.jdt.core.compiler.debug.lineNumber=generate\norg.eclipse.jdt.core.compiler.debug.localVariable=generate\norg.eclipse.jdt.core.compiler.debug.sourceFile=generate\norg.eclipse.jdt.core.compiler.problem.assertIdentifier=error\norg.eclipse.jdt.core.compiler.problem.enumIdentifier=error\norg.eclipse.jdt.core.compiler.source=1.6\n"
  },
  {
    "path": "LICENSE",
    "content": "Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"{}\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright {yyyy} {name of copyright owner}\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n\n"
  },
  {
    "path": "README.md",
    "content": "SVG2Drawable\n============\n\nUse a jar executable to create a Drawable class to display a SVG on Android.\n\nThis is a standalone library, not a Runtime Android library. You need to use it BEFORE your Android compilation (and only once per SVG file).\n\n## Why?\n\nI want to use a scalable image format.\n\nA SVG sounds really good but it's a bit long to load (mainly the time to parse the XML) and I didn't find any library that support the Hardware acceleration.\n\n## How does it work?\n\nMy main goal is to have a [Drawable](http://developer.android.com/reference/android/graphics/drawable/Drawable.html) class:\n\n* Made a fork of the [svg-android](https://code.google.com/p/svg-android/) library.\n* Replaced any instructions to create a [Picture](http://developer.android.com/reference/android/graphics/Picture.html) to collect them into a Logger.\n* Print this Logger.\n* Save it to a Drawable java class.\n\n## How to use it?\n\nYou can read the code but I'm not proud of it. I started to do a POC for a basic usage and now I need to transform the code to make it more readable and robust.\n\nYou can simply use the [jar provided into this repo](https://github.com/StanKocken/SVG2Drawable/blob/master/svg_converter.jar) by specify:\n\n* the SVG file\n* the package where you want to put the Drawable\n* the drawable name\n\nYou can also specify the output of the script to create a file. By adding \"> filename.java\".\n\n\n    java -jar svg_converter.jar example.svg com.skocken.svg.example.drawable ExampleDrawable > ExampleDrawable.java\n\nNow, copy this \"ExampleDrawable.java\" into your Android project, into the package \"com.skocken.svg.example.drawable\" (from this example), and add it to your ImageView into your code with:\n\n    imageview.setImageDrawable(new ExampleDrawable());\n\n![diagram](https://raw.githubusercontent.com/StanKocken/SVG2Drawable/master/svg_to_drawable.png)\n\n## License\n\n* [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)\n\n## Contributing\n\nIf you found a SVG with a problem, you can open an issue. Please, if possible, let me know if this same SVG work with the library [svg-android](https://code.google.com/p/svg-android/).\n\nPlease fork this repository and contribute back using\n[pull requests](https://github.com/StanKocken/SVG2Drawable/pulls).\n\nAny contributions, large or small, major features, bug fixes, additional\nlanguage translations, unit/integration tests are welcomed and appreciated\nbut will be thoroughly reviewed and discussed.\n"
  },
  {
    "path": "build.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<project default=\"create_run_jar\" name=\"Create Runnable Jar for Project SVGtoDrawable\">\n    <!--this file was created by Eclipse Runnable JAR Export Wizard-->\n    <!--ANT 1.7 is required                                        -->\n    <target name=\"create_run_jar\">\n        <jar destfile=\"./svg_converter.jar\" filesetmanifest=\"mergewithoutmain\">\n            <manifest>\n                <attribute name=\"Main-Class\" value=\"com.skocken.svgconverter.Unparse\"/>\n                <attribute name=\"Class-Path\" value=\"./\"/>\n            </manifest>\n            <fileset dir=\"./bin\"/>\n        </jar>\n    </target>\n</project>\n"
  },
  {
    "path": "src/com/skocken/svgconverter/Unparse.java",
    "content": "package com.skocken.svgconverter;\n\nimport java.io.FileInputStream;\n\nimport com.skocken.svgconverter.svg.SVGParser;\n\npublic class Unparse {\n\n    public static void main(String[] args) {\n\n        if (args.length == 3) {\n            try {\n                SVGParser.getSVGFromInputStream(args[1], args[2], new FileInputStream(args[0]));\n            } catch (Exception e) {\n                e.printStackTrace();\n            }\n        } else {\n            System.out.println(\"Some paramaters are missing. Should be 'path', 'package name' and 'class name'.\");\n        }\n    }\n}\n"
  },
  {
    "path": "src/com/skocken/svgconverter/svg/Element.java",
    "content": "package com.skocken.svgconverter.svg;\n\npublic class Element {\n    private String name;\n    private boolean canvasSave;\n\n    public Element(String name) {\n        this.name = name;\n    }\n\n    public String getName() {\n        return name;\n    }\n\n    public boolean hasCanvasSave() {\n        return canvasSave;\n    }\n\n    public void setHasCanvasSave() {\n        this.canvasSave = true;\n    }\n\n}\n"
  },
  {
    "path": "src/com/skocken/svgconverter/svg/Gradient.java",
    "content": "package com.skocken.svgconverter.svg;\n\n// import android.graphics.Matrix;\n\nimport java.util.ArrayList;\n\npublic class Gradient {\n    String id;\n    String xlink;\n    boolean isLinear;\n    float x1, y1, x2, y2;\n    float x, y, radius;\n    ArrayList<Float> positions = new ArrayList<Float>();\n    ArrayList<Integer> colors = new ArrayList<Integer>();\n\n    InstructionRecorder matrixInstructions = new InstructionRecorder();\n\n    public Gradient createChild(Gradient g) {\n        Gradient child = new Gradient();\n        child.id = g.id;\n        child.xlink = id;\n        child.isLinear = g.isLinear;\n        child.x1 = g.x1;\n        child.x2 = g.x2;\n        child.y1 = g.y1;\n        child.y2 = g.y2;\n        child.x = g.x;\n        child.y = g.y;\n        child.radius = g.radius;\n        child.positions = positions;\n        child.colors = colors;\n        child.matrixInstructions = matrixInstructions;\n        if (g.matrixInstructions != null) {\n            if (matrixInstructions == null) {\n                child.matrixInstructions = g.matrixInstructions;\n            } else {\n                // Matrix m = new Matrix(matrixInstructions);\n                // m.preConcat(g.matrixInstructions);\n                // child.matrixInstructions = m;\n                child.matrixInstructions = g.matrixInstructions;\n            }\n        }\n        return child;\n    }\n}"
  },
  {
    "path": "src/com/skocken/svgconverter/svg/InstructionRecorder.java",
    "content": "package com.skocken.svgconverter.svg;\n\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Locale;\n\npublic class InstructionRecorder {\n\n    private static final int MAX_LENGTH_LOG = 3800;\n\n    private List<String> listInstructions = new ArrayList<String>();\n\n    public void addBegin(String instructions, Object... args) {\n        listInstructions.add(0, format(instructions, args));\n    }\n\n    public void add(String instructions, Object... args) {\n        listInstructions.add(format(instructions, args));\n    }\n\n    public List<String> getListInstructions() {\n        return listInstructions;\n    }\n\n    public boolean isEmpty() {\n        return listInstructions.isEmpty();\n    }\n\n    public void print() {\n        StringBuffer sb = new StringBuffer();\n        for (String instruction : listInstructions) {\n            if (sb.length() + instruction.length() > MAX_LENGTH_LOG) {\n                System.out.println(sb.toString());\n                sb.setLength(0);\n            }\n            sb.append(instruction);\n            sb.append(\"\\r\\n\");\n        }\n        System.out.println(sb.toString());\n    }\n\n    private String format(String instructions, Object[] args) {\n        return String.format(Locale.ENGLISH, instructions, args);\n    }\n\n    public void add(InstructionRecorder instructions) {\n        if (instructions == null || instructions.isEmpty()) {\n            return;\n        }\n        listInstructions.addAll(instructions.listInstructions);\n    }\n}\n"
  },
  {
    "path": "src/com/skocken/svgconverter/svg/LinearGradient.java",
    "content": "package com.skocken.svgconverter.svg;\n\npublic class LinearGradient extends Shader {\n\n    private float mX0;\n    private float mY0;\n    private float mX1;\n    private float mY1;\n    private int[] mColors;\n    private float[] mPositions;\n\n    private String mTileMode;\n\n    public LinearGradient(float x0, float y0, float x1, float y1, int[] colors, float[] positions, String tileMode) {\n        super();\n        mX0 = x0;\n        mY0 = y0;\n        mX1 = x1;\n        mY1 = y1;\n        mColors = colors;\n        mPositions = positions;\n        mTileMode = tileMode;\n    }\n\n    @Override\n    public void printTo(InstructionRecorder drawInstructions) {\n        drawInstructions.add(\"{\");\n        StringBuffer sb = new StringBuffer(\"int[] colors = \");\n        if (mColors == null) {\n            sb.append(\"null;\");\n        } else {\n            sb.append(\" { \");\n            int startIterationLength = sb.length();\n            for (int color : mColors) {\n                if (sb.length() > startIterationLength) {\n                    sb.append(\", \");\n                }\n                sb.append(color);\n            }\n            sb.append(\" }; \");\n        }\n        drawInstructions.add(sb.toString());\n        sb = new StringBuffer(\"float[] positions = \");\n        if (mPositions == null) {\n            sb.append(\"null;\");\n        } else {\n            sb.append(\" { \");\n            int startIterationLength = sb.length();\n            for (float position : mPositions) {\n                if (sb.length() > startIterationLength) {\n                    sb.append(\", \");\n                }\n                sb.append(position);\n                sb.append(\"f\");\n            }\n            sb.append(\" }; \");\n        }\n        drawInstructions.add(sb.toString());\n        drawInstructions.add(\"shader = new LinearGradient(%ff, %ff, %ff, %ff, colors, positions, %s);\", mX0, mY0, mX1, mY1, mTileMode);\n        drawInstructions.add(\"}\");\n        printMatrixTo(drawInstructions);\n    }\n\n}\n"
  },
  {
    "path": "src/com/skocken/svgconverter/svg/NumberParse.java",
    "content": "package com.skocken.svgconverter.svg;\n\nimport java.util.ArrayList;\n\npublic class NumberParse {\n\n    private ArrayList<Float> numbers;\n\n    private int nextCmd;\n\n    public NumberParse(ArrayList<Float> numbers, int nextCmd) {\n        this.numbers = numbers;\n        this.nextCmd = nextCmd;\n    }\n\n    public int getNextCmd() {\n        return nextCmd;\n    }\n\n    public int size() {\n        return numbers.size();\n    }\n\n    public float getNumber(int index) {\n        return numbers.get(index);\n    }\n\n}\n"
  },
  {
    "path": "src/com/skocken/svgconverter/svg/ParserHelper.java",
    "content": "package com.skocken.svgconverter.svg;\n\n/*\n\n   Licensed to the Apache Software Foundation (ASF) under one or more\n   contributor license agreements.  See the NOTICE file distributed with\n   this work for additional information regarding copyright ownership.\n   The ASF licenses this file to You under the Apache License, Version 2.0\n   (the \"License\"); you may not use this file except in compliance with\n   the License.  You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n\n*/\n/**\n * Parses numbers from SVG text. Based on the Batik Number Parser (Apache 2 License).\n *\n * @author Apache Software Foundation, Larva Labs LLC\n */\npublic class ParserHelper {\n\n    private char current;\n    private CharSequence s;\n    public int pos;\n    private int n;\n\n    public ParserHelper(CharSequence s, int pos) {\n        this.s = s;\n        this.pos = pos;\n        n = s.length();\n        current = s.charAt(pos);\n    }\n\n    private char read() {\n        if (pos < n) {\n            pos++;\n        }\n        if (pos == n) {\n            return '\\0';\n        } else {\n            return s.charAt(pos);\n        }\n    }\n\n    public void skipWhitespace() {\n        while (pos < n) {\n            if (Character.isWhitespace(s.charAt(pos))) {\n                advance();\n            } else {\n                break;\n            }\n        }\n    }\n\n    public void skipNumberSeparator() {\n        while (pos < n) {\n            char c = s.charAt(pos);\n            switch (c) {\n                case ' ':\n                case ',':\n                case '\\n':\n                case '\\t':\n                    advance();\n                    break;\n                default:\n                    return;\n            }\n        }\n    }\n\n    public void advance() {\n        current = read();\n    }\n\n    /**\n     * Parses the content of the buffer and converts it to a float.\n     */\n    public float parseFloat() {\n        int     mant     = 0;\n        int     mantDig  = 0;\n        boolean mantPos  = true;\n        boolean mantRead = false;\n\n        int     exp      = 0;\n        int     expDig   = 0;\n        int     expAdj   = 0;\n        boolean expPos   = true;\n\n        switch (current) {\n        case '-':\n            mantPos = false;\n            // fallthrough\n        case '+':\n            current = read();\n        }\n\n        m1: switch (current) {\n        default:\n            return Float.NaN;\n\n        case '.':\n            break;\n\n        case '0':\n            mantRead = true;\n            l: for (;;) {\n                current = read();\n                switch (current) {\n                case '1': case '2': case '3': case '4':\n                case '5': case '6': case '7': case '8': case '9':\n                    break l;\n                case '.': case 'e': case 'E':\n                    break m1;\n                default:\n                    return 0.0f;\n                case '0':\n                }\n            }\n\n        case '1': case '2': case '3': case '4':\n        case '5': case '6': case '7': case '8': case '9':\n            mantRead = true;\n            l: for (;;) {\n                if (mantDig < 9) {\n                    mantDig++;\n                    mant = mant * 10 + (current - '0');\n                } else {\n                    expAdj++;\n                }\n                current = read();\n                switch (current) {\n                default:\n                    break l;\n                case '0': case '1': case '2': case '3': case '4':\n                case '5': case '6': case '7': case '8': case '9':\n                }\n            }\n        }\n\n        if (current == '.') {\n            current = read();\n            m2: switch (current) {\n            default:\n            case 'e': case 'E':\n                if (!mantRead) {\n                    reportUnexpectedCharacterError( current );\n                    return 0.0f;\n                }\n                break;\n\n            case '0':\n                if (mantDig == 0) {\n                    l: for (;;) {\n                        current = read();\n                        expAdj--;\n                        switch (current) {\n                        case '1': case '2': case '3': case '4':\n                        case '5': case '6': case '7': case '8': case '9':\n                            break l;\n                        default:\n                            if (!mantRead) {\n                                return 0.0f;\n                            }\n                            break m2;\n                        case '0':\n                        }\n                    }\n                }\n            case '1': case '2': case '3': case '4':\n            case '5': case '6': case '7': case '8': case '9':\n                l: for (;;) {\n                    if (mantDig < 9) {\n                        mantDig++;\n                        mant = mant * 10 + (current - '0');\n                        expAdj--;\n                    }\n                    current = read();\n                    switch (current) {\n                    default:\n                        break l;\n                    case '0': case '1': case '2': case '3': case '4':\n                    case '5': case '6': case '7': case '8': case '9':\n                    }\n                }\n            }\n        }\n\n        switch (current) {\n        case 'e': case 'E':\n            current = read();\n            switch (current) {\n            default:\n                reportUnexpectedCharacterError( current );\n                return 0f;\n            case '-':\n                expPos = false;\n            case '+':\n                current = read();\n                switch (current) {\n                default:\n                    reportUnexpectedCharacterError( current );\n                    return 0f;\n                case '0': case '1': case '2': case '3': case '4':\n                case '5': case '6': case '7': case '8': case '9':\n                }\n            case '0': case '1': case '2': case '3': case '4':\n            case '5': case '6': case '7': case '8': case '9':\n            }\n\n            en: switch (current) {\n            case '0':\n                l: for (;;) {\n                    current = read();\n                    switch (current) {\n                    case '1': case '2': case '3': case '4':\n                    case '5': case '6': case '7': case '8': case '9':\n                        break l;\n                    default:\n                        break en;\n                    case '0':\n                    }\n                }\n\n            case '1': case '2': case '3': case '4':\n            case '5': case '6': case '7': case '8': case '9':\n                l: for (;;) {\n                    if (expDig < 3) {\n                        expDig++;\n                        exp = exp * 10 + (current - '0');\n                    }\n                    current = read();\n                    switch (current) {\n                    default:\n                        break l;\n                    case '0': case '1': case '2': case '3': case '4':\n                    case '5': case '6': case '7': case '8': case '9':\n                    }\n                }\n            }\n        default:\n        }\n\n        if (!expPos) {\n            exp = -exp;\n        }\n        exp += expAdj;\n        if (!mantPos) {\n            mant = -mant;\n        }\n\n        return buildFloat(mant, exp);\n    }\n\n    private void reportUnexpectedCharacterError(char c) {\n        throw new RuntimeException(\"Unexpected char '\" + c + \"'.\");\n    }\n\n    /**\n     * Computes a float from mantissa and exponent.\n     */\n    public static float buildFloat(int mant, int exp) {\n        if (exp < -125 || mant == 0) {\n            return 0.0f;\n        }\n\n        if (exp >=  128) {\n            return (mant > 0)\n                ? Float.POSITIVE_INFINITY\n                : Float.NEGATIVE_INFINITY;\n        }\n\n        if (exp == 0) {\n            return mant;\n        }\n\n        if (mant >= (1 << 26)) {\n            mant++;  // round up trailing bits if they will be dropped.\n        }\n\n        return (float) ((exp > 0) ? mant * pow10[exp] : mant / pow10[-exp]);\n    }\n\n    /**\n     * Array of powers of ten. Using double instead of float gives a tiny bit more precision.\n     */\n    private static final double[] pow10 = new double[128];\n\n    static {\n        for (int i = 0; i < pow10.length; i++) {\n            pow10[i] = Math.pow(10, i);\n        }\n    }\n\n    public float nextFloat() {\n        skipWhitespace();\n        float f = parseFloat();\n        skipNumberSeparator();\n        return f;\n    }\n}\n"
  },
  {
    "path": "src/com/skocken/svgconverter/svg/Properties.java",
    "content": "package com.skocken.svgconverter.svg;\n\nimport static com.skocken.svgconverter.svg.SVGParsingMethods.getStringAttr;\n\nimport org.xml.sax.Attributes;\n\npublic class Properties {\n\n    StyleSet styles = null;\n\n    Attributes atts;\n\n    Properties(Attributes atts) {\n        this.atts = atts;\n        String styleAttr = getStringAttr(\"style\", atts);\n        if (styleAttr != null) {\n            styles = new StyleSet(styleAttr);\n        }\n    }\n\n    public String getAttr(String name) {\n        String v = null;\n        if (styles != null) {\n            v = styles.getStyle(name);\n        }\n        if (v == null) {\n            v = getStringAttr(name, atts);\n        }\n        return v;\n    }\n\n    public String getString(String name) {\n        return getAttr(name);\n    }\n\n    public Integer getHex(String name) {\n        String v = getAttr(name);\n        if (v == null || !v.startsWith(\"#\")) {\n            return null;\n        } else {\n            try {\n                return Integer.parseInt(v.substring(1), 16);\n            } catch (NumberFormatException nfe) {\n                // todo - parse word-based color here\n                return null;\n            }\n        }\n    }\n\n    public Float getFloat(String name, float defaultValue) {\n        Float v = getFloat(name);\n        if (v == null) {\n            return defaultValue;\n        } else {\n            return v;\n        }\n    }\n\n    public Float getFloat(String name) {\n        String v = getAttr(name);\n        if (v == null) {\n            return null;\n        } else {\n            try {\n                return Float.parseFloat(v);\n            } catch (NumberFormatException nfe) {\n                return null;\n            }\n        }\n    }\n}"
  },
  {
    "path": "src/com/skocken/svgconverter/svg/RadialGradient.java",
    "content": "package com.skocken.svgconverter.svg;\n\npublic class RadialGradient extends Shader {\n\n    private float mX;\n    private float mY;\n    private float mRadius;\n    private int[] mColors;\n    private float[] mPositions;\n\n    private String mTileMode;\n\n    public RadialGradient(float x, float y, float radius, int[] colors, float[] positions, String tileMode) {\n        super();\n        mX = x;\n        mY = y;\n        mRadius = radius;\n        mColors = colors;\n        mPositions = positions;\n        mTileMode = tileMode;\n    }\n\n    @Override\n    public void printTo(InstructionRecorder drawInstructions) {\n        drawInstructions.add(\"{\");\n        StringBuffer sb = new StringBuffer(\"int[] colors = \");\n        if (mColors == null) {\n            sb.append(\"null;\");\n        } else {\n            sb.append(\" { \");\n            int startIterationLength = sb.length();\n            for (int color : mColors) {\n                if (sb.length() > startIterationLength) {\n                    sb.append(\", \");\n                }\n                sb.append(color);\n            }\n            sb.append(\" }; \");\n        }\n        drawInstructions.add(sb.toString());\n        sb = new StringBuffer(\"float[] positions = \");\n        if (mPositions == null) {\n            sb.append(\"null;\");\n        } else {\n            sb.append(\" { \");\n            int startIterationLength = sb.length();\n            for (float position : mPositions) {\n                if (sb.length() > startIterationLength) {\n                    sb.append(\", \");\n                }\n                sb.append(position);\n                sb.append(\"f\");\n            }\n            sb.append(\" }; \");\n        }\n        drawInstructions.add(sb.toString());\n        drawInstructions.add(\"shader = new RadialGradient(%ff, %ff, %ff, colors, positions, %s);\", mX, mY, mRadius, mTileMode);\n        drawInstructions.add(\"}\");\n        printMatrixTo(drawInstructions);\n    }\n}\n"
  },
  {
    "path": "src/com/skocken/svgconverter/svg/SVGHandler.java",
    "content": "package com.skocken.svgconverter.svg;\n\nimport static com.skocken.svgconverter.svg.SVGParsingMethods.doPath;\nimport static com.skocken.svgconverter.svg.SVGParsingMethods.getFloatAttr;\nimport static com.skocken.svgconverter.svg.SVGParsingMethods.getNumberParseAttr;\nimport static com.skocken.svgconverter.svg.SVGParsingMethods.getStringAttr;\nimport static com.skocken.svgconverter.svg.SVGParsingMethods.parseTransform;\n\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.List;\n\nimport org.xml.sax.Attributes;\nimport org.xml.sax.SAXException;\nimport org.xml.sax.helpers.DefaultHandler;\n\npublic class SVGHandler extends DefaultHandler {\n\n    List<Element> elements = new ArrayList<Element>();\n\n    HashMap<String, Shader> gradientMap = new HashMap<String, Shader>();\n\n    HashMap<String, Gradient> gradientRefMap = new HashMap<String, Gradient>();\n\n    Gradient gradient = null;\n\n    int height, width;\n\n    float viewBox[];\n\n    InstructionRecorder drawInstructions = new InstructionRecorder();\n\n    String packageName, className;\n\n    SVGHandler(String packageName, String className) {\n        this.packageName = packageName;\n        this.className = className;\n\n        drawInstructions.add(\"private RectF rect = new RectF();\");\n        drawInstructions.add(\"private Matrix matrix = new Matrix();\");\n        drawInstructions.add(\"private Shader shader;\");\n        drawInstructions.add(\"private Path p = new Path();\");\n        drawInstructions.add(\"private Paint paint = new Paint();\");\n        drawInstructions.add(\"@Override\");\n        drawInstructions.add(\"public void draw(Canvas canvas) {\");\n        drawInstructions.add(\"paint.setAntiAlias(true);\");\n\n        drawInstructions.add(\"float viewBoxWidth = VIEW_BOX[2];\");\n        drawInstructions.add(\"float viewBoxHeight = VIEW_BOX[3];\");\n        drawInstructions.add(\"Rect bounds = getBounds();\");\n        drawInstructions.add(\"if (viewBoxHeight <= 0 || viewBoxWidth <= 0 || bounds.width() <= 0 || bounds.height() <= 0) {\");\n        drawInstructions.add(\"return;\");\n        drawInstructions.add(\"}\");\n        drawInstructions.add(\"canvas.save();\");\n        drawInstructions.add(\"float viewBoxRatio = viewBoxWidth / viewBoxHeight;\");\n        drawInstructions.add(\"float boundsRatio = bounds.width() / (float) bounds.height();\");\n        drawInstructions.add(\"float factorScale;\");\n        drawInstructions.add(\"if (boundsRatio > viewBoxRatio) {\");\n        drawInstructions.add(\" // canvas larger than viewbox\");\n        drawInstructions.add(\" factorScale = bounds.height() / viewBoxHeight;\");\n        drawInstructions.add(\"} else {\");\n        drawInstructions.add(\" // canvas higher (or equals) than viewbox\");\n        drawInstructions.add(\" factorScale = bounds.width() / viewBoxWidth;\");\n        drawInstructions.add(\"}\");\n        drawInstructions.add(\"int newViewBoxHeight = Math.round(factorScale * viewBoxHeight);\");\n        drawInstructions.add(\"int newViewBoxWidth = Math.round(factorScale * viewBoxWidth);\");\n        drawInstructions.add(\"int marginX = bounds.width() - newViewBoxWidth;\");\n        drawInstructions.add(\"int marginY = bounds.height() - newViewBoxHeight;\");\n        drawInstructions.add(\"canvas.translate(bounds.left, bounds.top);\");\n        drawInstructions.add(\"canvas.translate(Math.round(marginX / 2f), Math.round(marginY / 2f));\");\n        drawInstructions.add(\"canvas.clipRect(0, 0, newViewBoxWidth, newViewBoxHeight);\");\n        drawInstructions.add(\"canvas.translate(-Math.round(factorScale * VIEW_BOX[0]), -Math.round(factorScale * VIEW_BOX[1]));\");\n    }\n\n    public List<String> getDrawInstructions() {\n        return drawInstructions.getListInstructions();\n    }\n\n    @Override\n    public void startDocument() throws SAXException {\n        // Set up prior to parsing a doc\n    }\n\n    @Override\n    public void endDocument() throws SAXException {\n        // Clean up after parsing a doc\n        if (viewBox == null) {\n            viewBox = new float[4];\n            viewBox[0] = 0;\n            viewBox[1] = 0;\n            viewBox[2] = width;\n            viewBox[3] = height;\n        }\n\n        float width = viewBox[2];\n        float height = viewBox[3];\n\n        float factorMin = Math.min(width / 10, height / 10);\n        int minWidth = Math.round(width / factorMin);\n        int minHeight = Math.round(height / (width / minWidth));\n\n        drawInstructions.addBegin(\"private static final float[] VIEW_BOX = { %ff, %ff, %ff, %ff };\", viewBox[0], viewBox[1], viewBox[2], viewBox[3]);\n        drawInstructions.add(\"canvas.restore();\");\n        drawInstructions.add(\"}\");\n\n        drawInstructions.add(\"@Override public void setAlpha(int alpha) { }\");\n        drawInstructions.add(\"@Override public void setColorFilter(ColorFilter cf) { }\");\n        drawInstructions.add(\"@Override public int getOpacity() { return 0; }\");\n        drawInstructions.add(\"@Override public int getMinimumHeight() { return %d; }\", minHeight);\n        drawInstructions.add(\"@Override public int getMinimumWidth() { return %d; }\", minWidth);\n        drawInstructions.add(\"}\");\n\n        drawInstructions.addBegin(\"public class %s extends Drawable {\", className);\n        drawInstructions.addBegin(\"import android.graphics.Canvas;\");\n        drawInstructions.addBegin(\"import android.graphics.ColorFilter;\");\n        drawInstructions.addBegin(\"import android.graphics.Matrix;\");\n        drawInstructions.addBegin(\"import android.graphics.Paint;\");\n        drawInstructions.addBegin(\"import android.graphics.Path;\");\n        drawInstructions.addBegin(\"import android.graphics.Rect;\");\n        drawInstructions.addBegin(\"import android.graphics.RectF;\");\n        drawInstructions.addBegin(\"import android.graphics.LinearGradient;\");\n        drawInstructions.addBegin(\"import android.graphics.RadialGradient;\");\n        drawInstructions.addBegin(\"import android.graphics.Shader;\");\n        drawInstructions.addBegin(\"import android.graphics.drawable.Drawable;\");\n        drawInstructions.addBegin(\"package %s;\", packageName);\n\n    }\n\n    private boolean doFill(Properties atts, HashMap<String, Shader> gradients) {\n        if (\"none\".equals(atts.getString(\"display\"))) {\n            return false;\n        }\n        String fillString = atts.getString(\"fill\");\n        if (fillString != null && fillString.startsWith(\"url(#\")) {\n            // It's a gradient fill, look it up in our map\n            String id = fillString.substring(\"url(#\".length(), fillString.length() - 1);\n            Shader shader = gradients.get(id);\n            if (shader != null) {\n                // Util.debug(\"Found shader!\");\n                shader.printTo(drawInstructions);\n                drawInstructions.add(\"paint.setShader(shader);\");\n                drawInstructions.add(\"paint.setStyle(Paint.Style.FILL);\");\n                return true;\n            } else {\n                // Util.debug(\"Didn't find shader!\");\n                return false;\n            }\n        } else {\n            drawInstructions.add(\"paint.setShader(null);\");\n            Integer color = atts.getHex(\"fill\");\n            if (color != null) {\n                doColor(atts, color, true);\n                drawInstructions.add(\"paint.setStyle(Paint.Style.FILL);\");\n                return true;\n            } else if (atts.getString(\"fill\") == null && atts.getString(\"stroke\") == null) {\n                // Default is black fill\n                drawInstructions.add(\"paint.setStyle(Paint.Style.FILL);\");\n                drawInstructions.add(\"paint.setColor(0xFF000000);\");\n                return true;\n            }\n        }\n        return false;\n    }\n\n    private boolean doStroke(Properties atts) {\n        if (\"none\".equals(atts.getString(\"display\"))) {\n            return false;\n        }\n        Integer color = atts.getHex(\"stroke\");\n        if (color != null) {\n            doColor(atts, color, false);\n            // Check for other stroke attributes\n            Float width = atts.getFloat(\"stroke-width\");\n            // Set defaults\n\n            if (width != null) {\n                drawInstructions.add(\"paint.setStrokeWidth(%ff);\", width);\n            }\n            String linecap = atts.getString(\"stroke-linecap\");\n            if (\"round\".equals(linecap)) {\n                drawInstructions.add(\"paint.setStrokeCap(Paint.Cap.ROUND);\");\n            } else if (\"square\".equals(linecap)) {\n                drawInstructions.add(\"paint.setStrokeCap(Paint.Cap.SQUARE);\");\n            } else if (\"butt\".equals(linecap)) {\n                drawInstructions.add(\"paint.setStrokeCap(Paint.Cap.BUTT);\");\n            }\n            String linejoin = atts.getString(\"stroke-linejoin\");\n            if (\"miter\".equals(linejoin)) {\n                drawInstructions.add(\"paint.setStrokeCap(Paint.Cap.MITER);\");\n            } else if (\"round\".equals(linejoin)) {\n                drawInstructions.add(\"paint.setStrokeCap(Paint.Cap.ROUND);\");\n            } else if (\"bevel\".equals(linejoin)) {\n                drawInstructions.add(\"paint.setStrokeCap(Paint.Cap.BEVEL);\");\n            }\n            drawInstructions.add(\"paint.setStyle(Paint.Style.STROKE);\");\n            return true;\n        }\n        return false;\n    }\n\n    private Gradient doGradient(boolean isLinear, Attributes atts) {\n        Gradient gradient = new Gradient();\n        gradient.id = getStringAttr(\"id\", atts);\n        gradient.isLinear = isLinear;\n        if (isLinear) {\n            gradient.x1 = getFloatAttr(\"x1\", atts, 0f);\n            gradient.x2 = getFloatAttr(\"x2\", atts, 0f);\n            gradient.y1 = getFloatAttr(\"y1\", atts, 0f);\n            gradient.y2 = getFloatAttr(\"y2\", atts, 0f);\n        } else {\n            gradient.x = getFloatAttr(\"cx\", atts, 0f);\n            gradient.y = getFloatAttr(\"cy\", atts, 0f);\n            gradient.radius = getFloatAttr(\"r\", atts, 0f);\n        }\n        String transform = getStringAttr(\"gradientTransform\", atts);\n        if (transform != null) {\n            gradient.matrixInstructions = parseTransform(new InstructionRecorder(), transform);\n        }\n        String xlink = getStringAttr(\"href\", atts);\n        if (xlink != null) {\n            if (xlink.startsWith(\"#\")) {\n                xlink = xlink.substring(1);\n            }\n            gradient.xlink = xlink;\n        }\n        return gradient;\n    }\n\n    private void doColor(Properties atts, Integer color, boolean fillMode) {\n        int c = (0xFFFFFF & color) | 0xFF000000;\n        drawInstructions.add(\"paint.setColor(%d);\", c);\n        Float opacity = atts.getFloat(\"opacity\");\n        if (opacity == null) {\n            opacity = atts.getFloat(fillMode ? \"fill-opacity\" : \"stroke-opacity\");\n        }\n        if (opacity == null) {\n            drawInstructions.add(\"paint.setAlpha(255);\");\n        } else {\n            drawInstructions.add(\"paint.setAlpha(%d);\", (int) (255 * opacity));\n        }\n    }\n\n    private boolean hidden = false;\n\n    private int hiddenLevel = 0;\n\n    private boolean boundsMode = false;\n\n    private boolean defsMode = false;\n\n    private boolean pushTransform(Attributes atts) {\n        final String transform = getStringAttr(\"transform\", atts);\n        if (transform != null) {\n            parseTransform(drawInstructions, transform);\n            drawInstructions.add(\"canvas.save();\");\n            drawInstructions.add(\"canvas.concat(matrix);\");\n            return true;\n        } else {\n            return false;\n        }\n    }\n\n    private void popTransform() {\n        drawInstructions.add(\"canvas.restore();\");\n    }\n\n    @Override\n    public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {\n        // Reset paint opacity\n        drawInstructions.add(\"paint.setAlpha(255);\");\n        if (localName == null || localName.length() == 0) {\n            localName = qName;\n        }\n\n        Element element = new Element(localName);\n        elements.add(0, element);\n\n        // Ignore everything but rectangles in bounds mode\n        if (boundsMode) {\n            return;\n        }\n        // Ignore defs\n        if (defsMode) {\n            return;\n        }\n        if (localName.equals(\"svg\")) {\n            width = (int) Math.ceil(getFloatAttr(\"width\", atts, 0f));\n            height = (int) Math.ceil(getFloatAttr(\"height\", atts, 0f));\n            String viewBoxStr = getStringAttr(\"viewBox\", atts);\n            if (viewBoxStr != null) {\n                String[] split = viewBoxStr.split(\" \");\n                if (split.length == 4) {\n                    viewBox = new float[4];\n                    viewBox[0] = Float.parseFloat(split[0]);\n                    viewBox[1] = Float.parseFloat(split[1]);\n                    viewBox[2] = Float.parseFloat(split[2]);\n                    viewBox[3] = Float.parseFloat(split[3]);\n                }\n            }\n        } else if (localName.equals(\"defs\")) {\n            // Ignore\n            defsMode = true;\n        } else if (localName.equals(\"linearGradient\")) {\n            gradient = doGradient(true, atts);\n        } else if (localName.equals(\"radialGradient\")) {\n            gradient = doGradient(false, atts);\n        } else if (localName.equals(\"stop\")) {\n            if (gradient != null) {\n                float offset = getFloatAttr(\"offset\", atts);\n                String styles = getStringAttr(\"style\", atts);\n                StyleSet styleSet = new StyleSet(styles);\n                String colorStyle = styleSet.getStyle(\"stop-color\");\n                int color = 0xFF000000;\n                if (colorStyle != null) {\n                    if (colorStyle.startsWith(\"#\")) {\n                        color = Integer.parseInt(colorStyle.substring(1), 16);\n                    } else {\n                        color = Integer.parseInt(colorStyle, 16);\n                    }\n                }\n                String opacityStyle = styleSet.getStyle(\"stop-opacity\");\n                if (opacityStyle != null) {\n                    float alpha = Float.parseFloat(opacityStyle);\n                    int alphaInt = Math.round(255 * alpha);\n                    color |= (alphaInt << 24);\n                } else {\n                    color |= 0xFF000000;\n                }\n                gradient.positions.add(offset);\n                gradient.colors.add(color);\n            }\n        } else if (localName.equals(\"g\")) {\n            // Check to see if this is the \"bounds\" layer\n            if (\"bounds\".equalsIgnoreCase(getStringAttr(\"id\", atts))) {\n                boundsMode = true;\n            }\n            if (hidden) {\n                hiddenLevel++;\n                // Util.debug(\"Hidden up: \" + hiddenLevel);\n            }\n            // Go in to hidden mode if display is \"none\"\n            if (\"none\".equals(getStringAttr(\"display\", atts))) {\n                if (!hidden) {\n                    hidden = true;\n                    hiddenLevel = 1;\n                    // Util.debug(\"Hidden up: \" + hiddenLevel);\n                }\n            }\n            if (pushTransform(atts)) {\n                element.setHasCanvasSave();\n            }\n        } else if (!hidden && localName.equals(\"rect\")) {\n            Float x = getFloatAttr(\"x\", atts);\n            if (x == null) {\n                x = 0f;\n            }\n            Float y = getFloatAttr(\"y\", atts);\n            if (y == null) {\n                y = 0f;\n            }\n            Float width = getFloatAttr(\"width\", atts);\n            Float height = getFloatAttr(\"height\", atts);\n            if (pushTransform(atts)) {\n                element.setHasCanvasSave();\n            }\n            Properties props = new Properties(atts);\n            if (doFill(props, gradientMap)) {\n                drawInstructions.add(\"canvas.drawRect(factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff, paint);\", x, y, x + width, y + height);\n            }\n            if (doStroke(props)) {\n                drawInstructions.add(\"canvas.drawRect(factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff, paint);\", x, y, x + width, y + height);\n            }\n        } else if (!hidden && localName.equals(\"line\")) {\n            Float x1 = getFloatAttr(\"x1\", atts);\n            Float x2 = getFloatAttr(\"x2\", atts);\n            Float y1 = getFloatAttr(\"y1\", atts);\n            Float y2 = getFloatAttr(\"y2\", atts);\n            Properties props = new Properties(atts);\n            if (doStroke(props)) {\n                if (pushTransform(atts)) {\n                    element.setHasCanvasSave();\n                }\n                drawInstructions.add(\"canvas.drawLine(factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff, paint);\", x1, y1, x2, y2);\n            }\n        } else if (!hidden && localName.equals(\"circle\")) {\n            Float centerX = getFloatAttr(\"cx\", atts);\n            Float centerY = getFloatAttr(\"cy\", atts);\n            Float radius = getFloatAttr(\"r\", atts);\n            if (centerX != null && centerY != null && radius != null) {\n                if (pushTransform(atts)) {\n                    element.setHasCanvasSave();\n                }\n                Properties props = new Properties(atts);\n                if (doFill(props, gradientMap)) {\n                    drawInstructions.add(\"canvas.drawCircle(factorScale * %ff, factorScale * %ff, factorScale * %ff, paint);\", centerX, centerY, radius);\n                }\n                if (doStroke(props)) {\n                    drawInstructions.add(\"canvas.drawCircle(factorScale * %ff, factorScale * %ff, factorScale * %ff, paint);\", centerX, centerY, radius);\n                }\n            }\n        } else if (!hidden && localName.equals(\"ellipse\")) {\n            Float centerX = getFloatAttr(\"cx\", atts);\n            Float centerY = getFloatAttr(\"cy\", atts);\n            Float radiusX = getFloatAttr(\"rx\", atts);\n            Float radiusY = getFloatAttr(\"ry\", atts);\n            if (centerX != null && centerY != null && radiusX != null && radiusY != null) {\n                if (pushTransform(atts)) {\n                    element.setHasCanvasSave();\n                }\n                Properties props = new Properties(atts);\n                drawInstructions.add(\"rect.set(factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff);\", centerX - radiusX, centerY - radiusY, centerX + radiusX, centerY + radiusY);\n                if (doFill(props, gradientMap)) {\n                    drawInstructions.add(\"canvas.drawOval(rect, paint);\");\n                }\n                if (doStroke(props)) {\n                    drawInstructions.add(\"canvas.drawOval(rect, paint);\");\n                }\n            }\n        } else if (!hidden && (localName.equals(\"polygon\") || localName.equals(\"polyline\"))) {\n            NumberParse numbers = getNumberParseAttr(\"points\", atts);\n            if (numbers != null) {\n                drawInstructions.add(\"p.reset();\");\n                if (numbers.size() > 1) {\n                    if (pushTransform(atts)) {\n                        element.setHasCanvasSave();\n                    }\n                    Properties props = new Properties(atts);\n                    drawInstructions.add(\"p.moveTo(factorScale * %ff, factorScale * %ff);\", numbers.getNumber(0), numbers.getNumber(1));\n                    for (int i = 2; i < numbers.size(); i += 2) {\n                        float x = numbers.getNumber(i);\n                        float y = numbers.getNumber(i + 1);\n                        drawInstructions.add(\"p.lineTo(factorScale * %ff, factorScale * %ff);\", x, y);\n                    }\n                    // Don't close a polyline\n                    if (localName.equals(\"polygon\")) {\n                        drawInstructions.add(\"p.close();\");\n                    }\n                    if (doFill(props, gradientMap)) {\n                        drawInstructions.add(\"canvas.drawPath(p, paint);\");\n                    }\n                    if (doStroke(props)) {\n                        drawInstructions.add(\"canvas.drawPath(p, paint);\");\n                    }\n                }\n            }\n        } else if (!hidden && localName.equals(\"path\")) {\n            doPath(drawInstructions, getStringAttr(\"d\", atts));\n            if (pushTransform(atts)) {\n                element.setHasCanvasSave();\n            }\n            Properties props = new Properties(atts);\n            if (doFill(props, gradientMap)) {\n                // doLimits(p);\n                drawInstructions.add(\"canvas.drawPath(p, paint);\");\n            }\n            if (doStroke(props)) {\n                drawInstructions.add(\"canvas.drawPath(p, paint);\");\n            }\n        } else if (!hidden) {\n        }\n    }\n\n    @Override\n    public void characters(char ch[], int start, int length) {\n        // no-op\n    }\n\n    @Override\n    public void endElement(String namespaceURI, String localName, String qName) throws SAXException {\n        if (localName == null || localName.length() == 0) {\n            localName = qName;\n        }\n\n        if (localName.equals(\"svg\")) {\n        } else if (localName.equals(\"linearGradient\")) {\n            if (gradient.id != null) {\n                if (gradient.xlink != null) {\n                    Gradient parent = gradientRefMap.get(gradient.xlink);\n                    if (parent != null) {\n                        gradient = parent.createChild(gradient);\n                    }\n                }\n                int[] colors = new int[gradient.colors.size()];\n                for (int i = 0; i < colors.length; i++) {\n                    colors[i] = gradient.colors.get(i);\n                }\n                float[] positions = new float[gradient.positions.size()];\n                for (int i = 0; i < positions.length; i++) {\n                    positions[i] = gradient.positions.get(i);\n                }\n                if (colors.length == 0) {\n                }\n                LinearGradient g = new LinearGradient(gradient.x1, gradient.y1, gradient.x2, gradient.y2, colors, positions, \"Shader.TileMode.CLAMP\");\n                g.setLocalMatrix(gradient.matrixInstructions);\n                gradientMap.put(gradient.id, g);\n                gradientRefMap.put(gradient.id, gradient);\n            }\n        } else if (localName.equals(\"radialGradient\")) {\n            if (gradient.id != null) {\n                if (gradient.xlink != null) {\n                    Gradient parent = gradientRefMap.get(gradient.xlink);\n                    if (parent != null) {\n                        gradient = parent.createChild(gradient);\n                    }\n                }\n                int[] colors = new int[gradient.colors.size()];\n                for (int i = 0; i < colors.length; i++) {\n                    colors[i] = gradient.colors.get(i);\n                }\n                float[] positions = new float[gradient.positions.size()];\n                for (int i = 0; i < positions.length; i++) {\n                    positions[i] = gradient.positions.get(i);\n                }\n                if (gradient.xlink != null) {\n                    Gradient parent = gradientRefMap.get(gradient.xlink);\n                    if (parent != null) {\n                        gradient = parent.createChild(gradient);\n                    }\n                }\n                RadialGradient g = new RadialGradient(gradient.x, gradient.y, gradient.radius, colors, positions, \"Shader.TileMode.CLAMP\");\n                g.setLocalMatrix(gradient.matrixInstructions);\n                gradientMap.put(gradient.id, g);\n                gradientRefMap.put(gradient.id, gradient);\n            }\n        } else if (localName.equals(\"g\")) {\n            if (boundsMode) {\n                boundsMode = false;\n            }\n            // Break out of hidden mode\n            if (hidden) {\n                hiddenLevel--;\n                // Util.debug(\"Hidden down: \" + hiddenLevel);\n                if (hiddenLevel == 0) {\n                    hidden = false;\n                }\n            }\n            // Clear gradient map\n            gradientMap.clear();\n        } else if (localName.equals(\"defs\")) {\n            defsMode = false;\n        }\n\n        Element element = pollLastElement(localName);\n        if (element != null && element.hasCanvasSave()) {\n            popTransform();\n        }\n    }\n\n    private Element pollLastElement(String name) {\n        if (elements.size() == 0) {\n            return null;\n        }\n        Element element = elements.get(0);\n        if (element != null && name != null && name.equals(element.getName())) {\n            elements.remove(0);\n            return element;\n        } else {\n            return null;\n        }\n    }\n}\n"
  },
  {
    "path": "src/com/skocken/svgconverter/svg/SVGParser.java",
    "content": "package com.skocken.svgconverter.svg;\n\nimport java.io.InputStream;\n\nimport javax.xml.parsers.SAXParser;\nimport javax.xml.parsers.SAXParserFactory;\n\nimport org.xml.sax.InputSource;\nimport org.xml.sax.XMLReader;\n\n/*\n * \n * Licensed to the Apache Software Foundation (ASF) under one or more\n * contributor license agreements. See the NOTICE file distributed with\n * this work for additional information regarding copyright ownership.\n * The ASF licenses this file to You under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compliance with\n * the License. You may obtain a copy of the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npublic class SVGParser {\n\n    public static void getSVGFromInputStream(String packageName, String className, InputStream svgData) throws Exception {\n\n        SAXParserFactory spf = SAXParserFactory.newInstance();\n        SAXParser sp = spf.newSAXParser();\n        XMLReader xr = sp.getXMLReader();\n        SVGHandler handler = new SVGHandler(packageName, className);\n        xr.setContentHandler(handler);\n        xr.parse(new InputSource(svgData));\n        handler.drawInstructions.print();\n    }\n\n}\n"
  },
  {
    "path": "src/com/skocken/svgconverter/svg/SVGParsingMethods.java",
    "content": "package com.skocken.svgconverter.svg;\n\nimport java.util.ArrayList;\n\nimport org.xml.sax.Attributes;\n\npublic class SVGParsingMethods {\n\n    static NumberParse parseNumbers(String s) {\n        // Util.debug(\"Parsing numbers from: '\" + s + \"'\");\n        int n = s.length();\n        int p = 0;\n        ArrayList<Float> numbers = new ArrayList<Float>();\n        boolean skipChar = false;\n        for (int i = 1; i < n; i++) {\n            if (skipChar) {\n                skipChar = false;\n                continue;\n            }\n            char c = s.charAt(i);\n            switch (c) {\n            // This ends the parsing, as we are on the next element\n                case 'M':\n                case 'm':\n                case 'Z':\n                case 'z':\n                case 'L':\n                case 'l':\n                case 'H':\n                case 'h':\n                case 'V':\n                case 'v':\n                case 'C':\n                case 'c':\n                case 'S':\n                case 's':\n                case 'Q':\n                case 'q':\n                case 'T':\n                case 't':\n                case 'a':\n                case 'A':\n                case ')': {\n                    String str = s.substring(p, i);\n                    if (str.trim().length() > 0) {\n                        // Util.debug(\"  Last: \" + str);\n                        Float f = Float.parseFloat(str);\n                        numbers.add(f);\n                    }\n                    p = i;\n                    return new NumberParse(numbers, p);\n                }\n                case '\\n':\n                case '\\t':\n                case ' ':\n                case ',':\n                case '-': {\n                    String str = s.substring(p, i);\n                    // Just keep moving if multiple whitespace\n                    if (str.trim().length() > 0) {\n                        // Util.debug(\"  Next: \" + str);\n                        Float f = Float.parseFloat(str);\n                        numbers.add(f);\n                        if (c == '-') {\n                            p = i;\n                        } else {\n                            p = i + 1;\n                            skipChar = true;\n                        }\n                    } else {\n                        p++;\n                    }\n                    break;\n                }\n            }\n        }\n        String last = s.substring(p);\n        if (last.length() > 0) {\n            // Util.debug(\"  Last: \" + last);\n            try {\n                numbers.add(Float.parseFloat(last));\n            } catch (NumberFormatException nfe) {\n                // Just white-space, forget it\n            }\n            p = s.length();\n        }\n        return new NumberParse(numbers, p);\n    }\n\n    static InstructionRecorder parseTransform(InstructionRecorder drawInstructions, String s) {\n        drawInstructions.add(\"matrix.reset();\");\n        return parseTransformInternal(drawInstructions, s);\n    }\n\n    static InstructionRecorder parseTransformInternal(InstructionRecorder drawInstructions, String s) {\n        int lastP = s.lastIndexOf(\"(\");\n        if (lastP > -1) {\n            String left = s.substring(0, lastP).trim();\n            NumberParse np = parseNumbers(s.substring(lastP + 1));\n\n            if (left.endsWith(\"matrix\") && np.size() == 6) {\n                // matrix\n                drawInstructions.add(\"matrix.setValues(new float[]{ factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff, 0, 0, factorScale});\",\n                // Row 1\n                np.getNumber(0), np.getNumber(2), np.getNumber(4),\n                // Row 2\n                np.getNumber(1), np.getNumber(3), np.getNumber(5));\n            } else if (left.endsWith(\"translate\") && np.size() > 0) {\n                // translate\n                float tx = np.getNumber(0);\n                float ty = 0;\n                if (np.size() > 1) {\n                    ty = np.getNumber(1);\n                }\n                drawInstructions.add(\"matrix.postTranslate(factorScale * %ff, factorScale * %ff);\", tx, ty);\n            } else if (left.endsWith(\"scale\") && np.size() > 0) {\n                float sx = np.getNumber(0);\n                float sy = 0;\n                if (np.size() > 1) {\n                    sy = np.getNumber(1);\n                }\n                drawInstructions.add(\"matrix.postScale(%ff, %ff);\", sx, sy);\n            } else if (left.endsWith(\"skewX\") && np.size() > 0) {\n                float angle = np.getNumber(0);\n                drawInstructions.add(\"matrix.postSkew(%ff, 0);\", (float) Math.tan(angle));\n            } else if (left.endsWith(\"skewY\") && np.size() > 0) {\n                float angle = np.getNumber(0);\n                drawInstructions.add(\"matrix.postSkew(0, %ff);\", (float) Math.tan(angle));\n            } else if (left.endsWith(\"rotate\") && np.size() > 0) {\n                float angle = np.getNumber(0);\n                float cx = 0;\n                float cy = 0;\n                if (np.size() > 2) {\n                    cx = np.getNumber(1);\n                    cy = np.getNumber(2);\n                }\n                if (cx != 0 || cy != 0) {\n                    drawInstructions.add(\"matrix.postTranslate(factorScale * %ff, factorScale * %ff);\", cx, cy);\n                }\n                drawInstructions.add(\"matrix.postRotate(%ff);\", angle);\n                if (cx != 0 || cy != 0) {\n                    drawInstructions.add(\"matrix.postTranslate(factorScale * %ff, factorScale * %ff);\", -cx, -cy);\n                }\n            }\n\n            parseTransformInternal(drawInstructions, left);\n        }\n        return drawInstructions;\n    }\n\n    /**\n     * This is where the hard-to-parse paths are handled.\n     * Uppercase rules are absolute positions, lowercase are relative.\n     * Types of path rules:\n     * <p/>\n     * <ol>\n     * <li>M/m - (x y)+ - Move to (without drawing)\n     * <li>Z/z - (no params) - Close path (back to starting point)\n     * <li>L/l - (x y)+ - Line to\n     * <li>H/h - x+ - Horizontal ine to\n     * <li>V/v - y+ - Vertical line to\n     * <li>C/c - (x1 y1 x2 y2 x y)+ - Cubic bezier to\n     * <li>S/s - (x2 y2 x y)+ - Smooth cubic bezier to (shorthand that assumes the x2, y2 from previous C/S is the x1, y1 of this bezier)\n     * <li>Q/q - (x1 y1 x y)+ - Quadratic bezier to\n     * <li>T/t - (x y)+ - Smooth quadratic bezier to (assumes previous control point is \"reflection\" of last one w.r.t. to current point)\n     * </ol>\n     * <p/>\n     * Numbers are separate by whitespace, comma or nothing at all (!) if they are self-delimiting, (ie. begin with a - sign)\n     * \n     * @param s\n     *            the path string from the XML\n     */\n    static void doPath(InstructionRecorder drawInstructions, String s) {\n        int n = s.length();\n        ParserHelper ph = new ParserHelper(s, 0);\n        ph.skipWhitespace();\n        drawInstructions.add(\"p.reset();\");\n        float lastX = 0;\n        float lastY = 0;\n        float lastX1 = 0;\n        float lastY1 = 0;\n        float subPathStartX = 0;\n        float subPathStartY = 0;\n        int nbMove = 0;\n        char prevCmd = 0;\n        while (ph.pos < n) {\n            char cmd = s.charAt(ph.pos);\n            switch (cmd) {\n                case '-':\n                case '+':\n                case '0':\n                case '1':\n                case '2':\n                case '3':\n                case '4':\n                case '5':\n                case '6':\n                case '7':\n                case '8':\n                case '9':\n                    if (prevCmd == 'm' || prevCmd == 'M') {\n                        cmd = (char) (((int) prevCmd) - 1);\n                        break;\n                    } else if (prevCmd == 'c' || prevCmd == 'C') {\n                        cmd = prevCmd;\n                        break;\n                    } else if (prevCmd == 'l' || prevCmd == 'L') {\n                        cmd = prevCmd;\n                        break;\n                    }\n                default: {\n                    ph.advance();\n                    prevCmd = cmd;\n                }\n            }\n\n            boolean wasCurve = false;\n            switch (cmd) {\n                case 'M':\n                case 'm': {\n                    nbMove++;\n                    float x = ph.nextFloat();\n                    float y = ph.nextFloat();\n                    if (cmd == 'm') {\n                        subPathStartX += x;\n                        subPathStartY += y;\n                        drawInstructions.add(\"p.rMoveTo(factorScale * %ff, factorScale * %ff);\", x, y);\n                        lastX += x;\n                        lastY += y;\n                    } else {\n                        subPathStartX = x;\n                        subPathStartY = y;\n                        drawInstructions.add(\"p.moveTo(factorScale * %ff, factorScale * %ff);\", x, y);\n                        lastX = x;\n                        lastY = y;\n                    }\n                    break;\n                }\n                case 'Z':\n                case 'z': {\n                    drawInstructions.add(\"p.close();\");\n                    drawInstructions.add(\"p.moveTo(factorScale * %ff, factorScale * %ff);\", subPathStartX, subPathStartY);\n                    lastX = subPathStartX;\n                    lastY = subPathStartY;\n                    lastX1 = subPathStartX;\n                    lastY1 = subPathStartY;\n                    wasCurve = true;\n                    break;\n                }\n                case 'L':\n                case 'l': {\n                    float x = ph.nextFloat();\n                    float y = ph.nextFloat();\n                    if (cmd == 'l') {\n                        drawInstructions.add(\"p.rLineTo(factorScale * %ff, factorScale * %ff);\", x, y);\n                        lastX += x;\n                        lastY += y;\n                    } else {\n                        drawInstructions.add(\"p.lineTo(factorScale * %ff, factorScale * %ff);\", x, y);\n                        lastX = x;\n                        lastY = y;\n                    }\n                    break;\n                }\n                case 'H':\n                case 'h': {\n                    float x = ph.nextFloat();\n                    if (cmd == 'h') {\n                        drawInstructions.add(\"p.rLineTo(factorScale * %ff, 0);\", x);\n                        lastX += x;\n                    } else {\n                        drawInstructions.add(\"p.lineTo(factorScale * %ff, factorScale * %ff);\", x, lastY);\n                        lastX = x;\n                    }\n                    break;\n                }\n                case 'V':\n                case 'v': {\n                    float y = ph.nextFloat();\n                    if (cmd == 'v') {\n                        drawInstructions.add(\"p.rLineTo(0, factorScale * %ff);\", y);\n                        lastY += y;\n                    } else {\n                        drawInstructions.add(\"p.lineTo(factorScale * %ff, factorScale * %ff);\", lastX, y);\n                        lastY = y;\n                    }\n                    break;\n                }\n                case 'C':\n                case 'c': {\n                    wasCurve = true;\n                    float x1 = ph.nextFloat();\n                    float y1 = ph.nextFloat();\n                    float x2 = ph.nextFloat();\n                    float y2 = ph.nextFloat();\n                    float x = ph.nextFloat();\n                    float y = ph.nextFloat();\n                    if (cmd == 'c') {\n                        drawInstructions.add(\"p.rCubicTo(factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff);\", x1, y1, x2, y2, x, y);\n                        lastX1 += x2;\n                        lastY1 += y2;\n                        lastX += x;\n                        lastY += y;\n                    } else {\n                        drawInstructions.add(\"p.cubicTo(factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff);\", x1, y1, x2, y2, x, y);\n                        lastX1 = x2;\n                        lastY1 = y2;\n                        lastX = x;\n                        lastY = y;\n\n                    }\n                    break;\n                }\n                case 'S':\n                case 's': {\n                    wasCurve = true;\n                    float x2 = ph.nextFloat();\n                    float y2 = ph.nextFloat();\n                    float x = ph.nextFloat();\n                    float y = ph.nextFloat();\n                    if (cmd == 's') {\n                        x2 += lastX;\n                        x += lastX;\n                        y2 += lastY;\n                        y += lastY;\n                    }\n                    float x1 = 2 * lastX - lastX1;\n                    float y1 = 2 * lastY - lastY1;\n                    drawInstructions.add(\"p.cubicTo(factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff, factorScale * %ff);\", x1, y1, x2, y2, x, y);\n                    lastX1 = x2;\n                    lastY1 = y2;\n                    lastX = x;\n                    lastY = y;\n                    break;\n                }\n                case 'A':\n                case 'a': {\n                    float rx = ph.nextFloat();\n                    float ry = ph.nextFloat();\n                    float theta = ph.nextFloat();\n                    int largeArc = (int) ph.nextFloat();\n                    int sweepArc = (int) ph.nextFloat();\n                    float x = ph.nextFloat();\n                    float y = ph.nextFloat();\n                    drawArc(drawInstructions, lastX, lastY, x, y, rx, ry, theta, largeArc, sweepArc);\n                    lastX = x;\n                    lastY = y;\n                    break;\n                }\n            }\n            if (!wasCurve) {\n                lastX1 = lastX;\n                lastY1 = lastY;\n            }\n            ph.skipWhitespace();\n        }\n        if (nbMove > 1) {\n            drawInstructions.add(\"p.setFillType(Path.FillType.EVEN_ODD);\");\n        }\n    }\n\n    static void drawArc(InstructionRecorder drawInstructions, float lastX, float lastY, float x, float y, float rx, float ry, float theta, int largeArc, int sweepArc) {\n        // todo - not implemented yet, may be very hard to do using Android drawing facilities.\n    }\n\n    static NumberParse getNumberParseAttr(String name, Attributes attributes) {\n        int n = attributes.getLength();\n        for (int i = 0; i < n; i++) {\n            if (attributes.getLocalName(i).equals(name)) {\n                return parseNumbers(attributes.getValue(i));\n            }\n        }\n        return null;\n    }\n\n    static String getStringAttr(String name, Attributes attributes) {\n        int n = attributes.getLength();\n        for (int i = 0; i < n; i++) {\n            if (attributes.getLocalName(i).equals(name)) {\n                return attributes.getValue(i);\n            }\n        }\n        return null;\n    }\n\n    static Float getFloatAttr(String name, Attributes attributes) {\n        return getFloatAttr(name, attributes, null);\n    }\n\n    static Float getFloatAttr(String name, Attributes attributes, Float defaultValue) {\n        String v = getStringAttr(name, attributes);\n        if (v == null) {\n            return defaultValue;\n        } else {\n            if (v.endsWith(\"px\")) {\n                v = v.substring(0, v.length() - 2);\n            }\n            // Log.d(TAG, \"Float parsing '\" + name + \"=\" + v + \"'\");\n            return Float.parseFloat(v);\n        }\n    }\n\n    static Integer getHexAttr(String name, Attributes attributes) {\n        String v = getStringAttr(name, attributes);\n        // Util.debug(\"Hex parsing '\" + name + \"=\" + v + \"'\");\n        if (v == null) {\n            return null;\n        } else {\n            try {\n                return Integer.parseInt(v.substring(1), 16);\n            } catch (NumberFormatException nfe) {\n                // todo - parse word-based color here\n                return null;\n            }\n        }\n    }\n}\n"
  },
  {
    "path": "src/com/skocken/svgconverter/svg/Shader.java",
    "content": "package com.skocken.svgconverter.svg;\n\npublic abstract class Shader {\n\n    private InstructionRecorder matrixInstructions;\n\n    public abstract void printTo(InstructionRecorder drawInstructions);\n\n    protected void printMatrixTo(InstructionRecorder drawInstructions) {\n        if (matrixInstructions == null || matrixInstructions.isEmpty()) {\n            return;\n        }\n        drawInstructions.add(matrixInstructions);\n        drawInstructions.add(\"shader.setLocalMatrix(matrix);\");\n    }\n\n    public void setLocalMatrix(InstructionRecorder matrixInstructions) {\n        this.matrixInstructions = matrixInstructions;\n    }\n}\n"
  },
  {
    "path": "src/com/skocken/svgconverter/svg/StyleSet.java",
    "content": "package com.skocken.svgconverter.svg;\n\nimport java.util.HashMap;\n\npublic class StyleSet {\n\n    HashMap<String, String> styleMap = new HashMap<String, String>();\n\n    StyleSet(String string) {\n        String[] styles = string.split(\";\");\n        for (String s : styles) {\n            String[] style = s.split(\":\");\n            if (style.length == 2) {\n                styleMap.put(style[0], style[1]);\n            }\n        }\n    }\n\n    public String getStyle(String name) {\n        return styleMap.get(name);\n    }\n}"
  }
]