# This file is part of NIT ( http://www.nitlanguage.org ).
#
-# Copyright 2012-2014 Alexis Laferrière <alexis.laf@xymus.net>
+# Copyright 2012-2015 Alexis Laferrière <alexis.laf@xymus.net>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# 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
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
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
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