From 00be03dd5f64e71126ee1cf3d0a28c01c2c48520 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Thu, 16 Apr 2015 11:38:29 -0400 Subject: [PATCH] contrib/inkscape_tools: revamp doc of svg_to_png_and_nit MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- contrib/inkscape_tools/src/svg_to_png_and_nit.nit | 31 +++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/contrib/inkscape_tools/src/svg_to_png_and_nit.nit b/contrib/inkscape_tools/src/svg_to_png_and_nit.nit index f718255..5398903 100644 --- a/contrib/inkscape_tools/src/svg_to_png_and_nit.nit +++ b/contrib/inkscape_tools/src/svg_to_png_and_nit.nit @@ -1,6 +1,6 @@ # This file is part of NIT ( http://www.nitlanguage.org ). # -# Copyright 2012-2014 Alexis Laferrière +# Copyright 2012-2015 Alexis Laferrière # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,26 +14,39 @@ # See the License for the specific language governing permissions and # limitations under the License. -# This script extracts pngs from a single svg for all objects with ids -# beginning by 0. Requires Inkscape. +# Extract images of objects from an SVG file using Inkscape module svg_to_png_and_nit import opts import template +# Image info extracted from the SVG file class Image + # Name extracted from the object ID minus the `0` prefix and Nit safe var name: String + + # Left border var x: Int + + # Top border var y: Int + + # Image width var w: Int + + # Image height var h: Int + + # Right border fun right: Int do return x+w + + # Bottom border fun bottom: Int do return y+h redef fun to_s do return name end -# The Nit source file to retreive all images +# Nit module with a single class to retrieve to access the extracted images class ImageSetSrc super Template @@ -45,7 +58,7 @@ class ImageSetSrc redef fun rendering do add """ -# file generated by svg_to_png, do not modify, redef instead +# File generated by svg_to_png_and_nit, do not modify, redef instead import mnit::image_set @@ -68,12 +81,14 @@ end end redef class Int - fun adapt(d: Int, scale: Float): Int + # Magic adaption of this coordinates to the given `margin` and `scale` + fun adapt(margin: Int, scale: Float): Int do - var corrected = self-d + var corrected = self-margin return (corrected.to_f*scale).to_i end + # The first power of to equal or greater than `self` fun next_pow2: Int do var p = 2 @@ -84,7 +99,7 @@ end var opt_out_src = new OptionString("Path to output source file", "--src", "-s") var opt_assets = new OptionString("Path to assert dir where to put PNG files", "--assets", "-a") -var opt_scale = new OptionFloat("Apply scaling to exported images (defaut at 1.0 of 90dpi)", 1.0, "--scale", "-x") +var opt_scale = new OptionFloat("Apply scaling to exported images (default at 1.0 of 90dpi)", 1.0, "--scale", "-x") var opt_help = new OptionBool("Print this help message", "--help", "-h") var opt_context = new OptionContext -- 1.7.9.5