3 require "rexml/document"
6 INKSCAPE = '/usr/bin/inkscape'
11 File.makedirs("moblin") unless File.exists?("moblin")
14 svg = Document.new(File.new("#{SRC}/#{file}", 'r'))
16 # Go through every layer.
17 svg.root.each_element("/svg/g[@inkscape:groupmode='layer']") do |type|
19 type_name = type.attributes.get_attribute("inkscape:label").value
21 puts "Going through layer '" + type_name + "'"
23 svg.root.each_element("/svg/g[@inkscape:label='#{type_name}']/g") do |icon|
25 icon_node = icon.attributes.get_attribute("inkscape:label")
28 icon_name = icon_node.value
29 puts " Found icon '" + icon_name + "'"
30 svg.root.each_element("/svg/g[@inkscape:label='#{type_name}']/g[@inkscape:label='#{icon_name}']/rect']") do |rect|
31 rect_node = rect.attributes.get_attribute("id")
34 rect_name = rect_node.value
35 rect_width = rect.attributes.get_attribute("width").value
36 rect_height = rect.attributes.get_attribute("height").value
38 if (rect_width == '48' and rect_height == '48')
39 dir = "moblin/48x48/#{type_name}/"
40 puts " Exporting #{dir}/#{icon_name}.png"
41 File.makedirs(dir) unless File.exists?(dir)
42 cmd = "#{INKSCAPE} -i #{rect_name} -e #{dir}/#{icon_name}.png #{SRC}/#{file} > /dev/null 2>&1"
46 if (rect_width == '24' and rect_height == '24')
47 dir = "moblin/24x24/#{type_name}/"
48 puts " Exporting #{dir}/#{icon_name}.png"
49 File.makedirs(dir) unless File.exists?(dir)
50 cmd = "#{INKSCAPE} -i #{rect_name} -e #{dir}/#{icon_name}.png #{SRC}/#{file} > /dev/null 2>&1"
54 if (rect_width == '16' and rect_height == '16')
55 dir = "moblin/16x16/#{type_name}/"
56 puts " Exporting #{dir}/#{icon_name}.png"
57 File.makedirs(dir) unless File.exists?(dir)
58 cmd = "#{INKSCAPE} -i #{rect_name} -e #{dir}/#{icon_name}.png #{SRC}/#{file} > /dev/null 2>&1"
75 end # End of function.
78 if (ARGV[0].nil?) #render all SVGs
79 puts "Rendering from SVGs in #{SRC}"
80 Dir.foreach(SRC) do |file|
81 renderit(file) if file.match(/svg$/)
83 puts "\nrendered all SVGs"
84 else #only render the SVG passed
85 file = "#{ARGV[0]}.svg"
86 if (File.exists?("#{SRC}/#{file}"))
88 puts "\nrendered #{file}"
90 puts "[E] No such file (#{file})"