3 require "rexml/document"
7 INKSCAPE = '/usr/bin/inkscape'
8 SRC = "gnome-osd-icons.svg"
9 PREFIX = "gnome-osd-icons/16x16"
12 FileUtils.mkdir_p(icon[:dir]) unless File.exists?(icon[:dir])
13 unless (File.exists?(icon[:file]) && !icon[:forcerender])
14 FileUtils.cp(SRC,icon[:file])
15 puts " >> #{icon[:name]}"
16 cmd = "#{INKSCAPE} -f #{icon[:file]} --select #{icon[:id]} --verb=FitCanvasToSelection --verb=EditInvertInAllLayers "
17 cmd += "--verb=EditDelete --verb=EditSelectAll --verb=SelectionUnGroup --verb=StrokeToPath --verb=FileVacuum "
18 cmd += "--verb=FileSave --verb=FileClose > /dev/null 2>&1"
20 cmd = "#{INKSCAPE} -f #{icon[:file]} -z --vacuum-defs -l #{icon[:file]} > /dev/null 2>&1"
22 system cmd unless (!icon[:dir].match(/app/))
24 puts " -- #{icon[:name]} already exists"
31 svg = Document.new(File.new(SRC, 'r'))
33 if (ARGV[0].nil?) #render all SVGs
34 puts "Rendering from icons in #{SRC}"
35 # Go through every layer.
36 svg.root.each_element("/svg/g[@inkscape:groupmode='layer']") do |context|
37 context_name = context.attributes.get_attribute("inkscape:label").value
38 puts "Going through layer '" + context_name + "'"
39 context.each_element("g") do |icon|
40 #puts "DEBUG #{icon.attributes.get_attribute('id')}"
41 dir = "#{PREFIX}/#{context_name}"
42 icon_name = icon.attributes.get_attribute("inkscape:label").value
43 chopSVG({ :name => icon_name,
44 :id => icon.attributes.get_attribute("id"),
46 :file => "#{dir}/#{icon_name}.svg"})
49 puts "\nrendered all SVGs"
50 else #only render the icons passed
52 ARGV.each do |icon_name|
53 icon = svg.root.elements["//g[@inkscape:label='#{icon_name}']"]
54 dir = "#{PREFIX}/#{icon.parent.attributes['inkscape:label']}"
55 chopSVG({ :name => icon_name,
56 :id => icon.attributes["id"],
58 :file => "#{dir}/#{icon_name}.svg",
59 :forcerender => true})
61 puts "\nrendered #{ARGV.length} icons"