contrib/inkscape_tools: add iOS target format
authorAlexis Laferrière <alexis.laf@xymus.net>
Sat, 13 Feb 2016 03:23:48 +0000 (22:23 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Tue, 16 Feb 2016 01:10:29 +0000 (20:10 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/inkscape_tools/src/svg_to_icons.nit
contrib/inkscape_tools/src/xcode_assets.nit [new file with mode: 0644]

index 917c197..bae4f7d 100644 (file)
@@ -19,9 +19,11 @@ module svg_to_icons
 
 import opts
 
+import xcode_assets
+
 redef class Int
        # Android name for this resolution
-       fun resolution_name: String
+       fun android_name: String
        do
                if self == 36 then return "ldpi"
                if self == 48 then return "mdpi"
@@ -36,18 +38,22 @@ end
 var opt_out = new OptionString("Where to output PNG files", "--out", "-o")
 var opt_id = new OptionString("Extract only object with given ID", "--id", "-i")
 var opt_android = new OptionBool("Generate in the file structure for Android", "--android", "-a")
+var opt_ios = new OptionBool("Generate in the file structure for iOS", "--ios")
 var opt_android_name = new OptionString("Name of the resource for Android", "--name", "-n")
 var opt_large = new OptionBool("Generate large icons (512 and 1024 px)", "--large", "-l")
 var opt_help = new OptionBool("Print this help message", "--help", "-h")
 
 var opt_context = new OptionContext
-opt_context.add_option(opt_out, opt_id, opt_android, opt_android_name, opt_large, opt_help)
+opt_context.add_option(opt_out, opt_id, opt_android, opt_ios, opt_android_name, opt_large, opt_help)
 
 opt_context.parse(args)
 var rest = opt_context.rest
 var errors = opt_context.errors
 if rest.length != 1 and not opt_help.value then errors.add "You must specify one source drawing file"
-if opt_android.value == opt_large.value then errors.add "You must specify a single format (--android or --large)"
+if [opt_android.value, opt_ios.value, opt_large.value].count(true) > 1 then
+       errors.add "You must specify a single format (--android, --ios or --large)"
+end
+
 if not errors.is_empty or opt_help.value then
        print errors.join("\n")
        print "Usage: svg_to_icons [Options] drawing.svg"
@@ -79,20 +85,29 @@ var id = opt_id.value
 var resolutions
 if opt_android.value then
        resolutions = [36, 48, 72, 96, 144, 192]
+else if opt_ios.value then
+       resolutions = [29, 57, 58, 80, 87, 114, 120, 180]
 else if opt_large.value then
        resolutions = [512, 1024]
 else abort
 
 var android_res_name = opt_android_name.value or else "icon"
 
+if opt_ios.value then
+       var contents_path = out_path / "Contents.json"
+       appiconset_contents_json.write_to_file contents_path
+end
+
 for wh in resolutions do
        var png_path
        if opt_android.value then
-               png_path = out_path / "drawable-" + wh.resolution_name / android_res_name + ".png"
+               png_path = out_path / "drawable-" + wh.android_name / android_res_name + ".png"
                var dir = png_path.dirname
                if not dir.file_exists then dir.mkdir
+       else if opt_ios.value then
+               png_path = out_path / "{wh}.png"
        else
-               png_path = "{out_path}/{wh}.png"
+               png_path = out_path / "{wh}.png"
        end
 
        var prog = "inkscape"
diff --git a/contrib/inkscape_tools/src/xcode_assets.nit b/contrib/inkscape_tools/src/xcode_assets.nit
new file mode 100644 (file)
index 0000000..f1f30e8
--- /dev/null
@@ -0,0 +1,78 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Content of the file to describe iOS icons, usually at `AppIcon.appiconset/Contents.json`
+fun appiconset_contents_json: String do return """
+{
+  "images" : [
+    {
+      "idiom" : "iphone",
+      "size" : "29x29",
+      "filename" : "29.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "iphone",
+      "size" : "29x29",
+      "filename" : "58.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "iphone",
+      "size" : "29x29",
+      "filename" : "87.png",
+      "scale" : "3x"
+    },
+    {
+      "idiom" : "iphone",
+      "size" : "40x40",
+      "filename" : "80.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "iphone",
+      "size" : "40x40",
+      "filename" : "120.png",
+      "scale" : "3x"
+    },
+    {
+      "idiom" : "iphone",
+      "size" : "57x57",
+      "filename" : "57.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "iphone",
+      "size" : "57x57",
+      "filename" : "114.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "iphone",
+      "size" : "60x60",
+      "filename" : "120.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "iphone",
+      "size" : "60x60",
+      "filename" : "180.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "svg_to_icons"
+  }
+}"""