Adjust hornsey thater icons a bit
[moblin-icon-theme.git] / render.rb
blobe022f7fd7033a8ac678af8d602546f013a6d3428
1 #!/usr/bin/env ruby
3 require "rexml/document"
4 require "ftools"
5 include REXML
6 INKSCAPE = '/usr/bin/inkscape'
7 SRC = "."
9 def renderit(file)
11     File.makedirs("moblin") unless File.exists?("moblin")
13         # Open SVG file.
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")
27                         if (icon_node) 
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")
33                                         if (rect_node) 
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"
43                             system(cmd)
44                                                 end
45                                                 
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"
51                             system(cmd)
52                                                 end
53                                                 
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"
59                             system(cmd)
60                                                 end
61                                                 
62                                         end
64                                 end
67                         end
69                 end
72         end
73     
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$/)
82   end
83   puts "\nrendered all SVGs"
84 else #only render the SVG passed
85   file = "#{ARGV[0]}.svg"
86   if (File.exists?("#{SRC}/#{file}"))
87     renderit(file)
88     puts "\nrendered #{file}"
89   else
90     puts "[E] No such file (#{file})"
91   end
92 end