Replace functions which called once with their bodies
[pidgin-git.git] / pidgin / pixmaps / art-tools / render-pidgin-emotes.rb
blob77f9e539a8dd45736ff6c48d1b984146a908e7bd
1 #!/usr/bin/env ruby
3 require "rexml/document"
4 require "ftools"
5 include REXML
6 INKSCAPE = '/usr/bin/inkscape'
7 SRC = "./svg"
9 def renderit(file)
10   svg = Document.new(File.new("#{SRC}/#{file}", 'r'))
11   svg.root.each_element("//g[contains(@inkscape:label,'plate')]") do |icon|
12      filename = icon.attributes["label"]
13      filename = `echo -n #{filename} | sed -e 's/plate\-//g'`
14      puts "#{file} #{filename}.png"
15      icon.each_element("rect") do |box|
16        if box.attributes['inkscape:label'] == '22x22'
17            dir = "#{box.attributes['width']}x#{box.attributes['height']}/"
18            cmd = "#{INKSCAPE} -i #{box.attributes['id']} -e #{dir}/#{filename}.png #{SRC}/#{file} > /dev/null 2>&1"
19            File.makedirs(dir) unless File.exists?(dir)
20            system(cmd)
21            print "."
22        elsif box.attributes['inkscape:label'] == '24x24'
23            dir = "#{box.attributes['width']}x#{box.attributes['height']}/"
24            cmd = "#{INKSCAPE} -i #{box.attributes['id']} -e #{dir}/#{filename}.png #{SRC}/#{file} > /dev/null 2>&1"
25            File.makedirs(dir) unless File.exists?(dir)
26            system(cmd)
27            print "."
28        end
29      end
30      puts ''
31   end
32 end
34 if (ARGV[0].nil?) #render all SVGs
35   puts "Rendering from SVGs in #{SRC}"
36   Dir.foreach(SRC) do |file|
37     renderit(file) if file.match(/svg$/)
38   end
39   puts "\nrendered all SVGs"
40 else #only render the SVG passed
41   file = "#{ARGV[0]}.svg"
42   if (File.exists?("#{SRC}/#{file}"))
43     renderit(file)
44     puts "\nrendered #{file}"
45   else
46     puts "[E] No such file (#{file})"
47   end
48 end