| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
require "rexml/document" |
| 21 |
require "fileutils" |
| 22 |
include REXML |
| 23 |
|
| 24 |
INKSCAPE = '/usr/bin/inkscape' |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
SRC24 = "panel-dark/source-panel-24.svg" |
| 29 |
PREFIX24 = "../Paper-Mono-Dark/24x24" |
| 30 |
|
| 31 |
|
| 32 |
def chopSVG(icon) |
| 33 |
FileUtils.mkdir_p(icon[:dir]) unless File.exists?(icon[:dir]) |
| 34 |
unless (File.exists?(icon[:file]) && !icon[:forcerender]) |
| 35 |
FileUtils.cp(SRC24,icon[:file]) |
| 36 |
puts " >> #{icon[:name]}" |
| 37 |
cmd = "#{INKSCAPE} -f #{icon[:file]} --select #{icon[:id]} --verb=FitCanvasToSelection --verb=EditInvertInAllLayers " |
| 38 |
cmd += "--verb=EditDelete --verb=EditSelectAll --verb=SelectionUnGroup --verb=SelectionUnGroup --verb=SelectionUnGroup --verb=StrokeToPath --verb=FileVacuum " |
| 39 |
cmd += "--verb=FileSave --verb=FileQuit > /dev/null 2>&1" |
| 40 |
system(cmd) |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
svgcrop = Document.new(File.new(icon[:file], 'r')) |
| 45 |
svgcrop.root.each_element("//rect") do |rect| |
| 46 |
w = ((rect.attributes["width"].to_f * 10).round / 10.0).to_i |
| 47 |
h = ((rect.attributes["width"].to_f * 10).round / 10.0).to_i |
| 48 |
if w == 24 && h == 24 |
| 49 |
rect.remove |
| 50 |
end |
| 51 |
end |
| 52 |
icon_f = File.new(icon[:file],'w+') |
| 53 |
icon_f.puts svgcrop |
| 54 |
icon_f.close |
| 55 |
else |
| 56 |
puts " -- #{icon[:name]} already exists" |
| 57 |
end |
| 58 |
end |
| 59 |
|
| 60 |
def get_output_filename(d,n) |
| 61 |
if (/rtl$/.match(n)) |
| 62 |
outfile = "#{d}/#{n.chomp('-rtl')}-rtl.svg" |
| 63 |
else |
| 64 |
outfile = "#{d}/#{n}.svg" |
| 65 |
end |
| 66 |
return outfile |
| 67 |
end |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
svg = Document.new(File.new(SRC24, 'r')) |
| 72 |
|
| 73 |
if (ARGV[0].nil?) |
| 74 |
puts "Rendering from icons in #{SRC24}" |
| 75 |
|
| 76 |
svg.root.each_element("/svg/g[@inkscape:groupmode='layer']") do |context| |
| 77 |
context_name = context.attributes.get_attribute("inkscape:label").value |
| 78 |
puts "Going through layer '" + context_name + "'" |
| 79 |
context.each_element("g") do |icon| |
| 80 |
|
| 81 |
dir = "#{PREFIX24}/#{context_name}" |
| 82 |
icon_name = icon.attributes.get_attribute("inkscape:label").value |
| 83 |
chopSVG({ :name => icon_name, |
| 84 |
:id => icon.attributes.get_attribute("id"), |
| 85 |
:dir => dir, |
| 86 |
:file => get_output_filename(dir, icon_name)}) |
| 87 |
end |
| 88 |
end |
| 89 |
puts "\nrendered all SVGs" |
| 90 |
else |
| 91 |
icons = ARGV |
| 92 |
ARGV.each do |icon_name| |
| 93 |
icon = svg.root.elements["//g[@inkscape:label='#{icon_name}']"] |
| 94 |
dir = "#{PREFIX24}/#{icon.parent.attributes['inkscape:label']}" |
| 95 |
chopSVG({ :name => icon_name, |
| 96 |
:id => icon.attributes["id"], |
| 97 |
:dir => dir, |
| 98 |
:file => get_output_filename(dir, icon_name), |
| 99 |
:forcerender => true}) |
| 100 |
end |
| 101 |
puts "\nrendered #{ARGV.length} icons" |
| 102 |
end |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
SRC22 = "panel-dark/source-panel-22.svg" |
| 107 |
PREFIX22 = "../Paper-Mono-Dark/22x22" |
| 108 |
|
| 109 |
|
| 110 |
def chopSVG(icon) |
| 111 |
FileUtils.mkdir_p(icon[:dir]) unless File.exists?(icon[:dir]) |
| 112 |
unless (File.exists?(icon[:file]) && !icon[:forcerender]) |
| 113 |
FileUtils.cp(SRC22,icon[:file]) |
| 114 |
puts " >> #{icon[:name]}" |
| 115 |
cmd = "#{INKSCAPE} -f #{icon[:file]} --select #{icon[:id]} --verb=FitCanvasToSelection --verb=EditInvertInAllLayers " |
| 116 |
cmd += "--verb=EditDelete --verb=EditSelectAll --verb=SelectionUnGroup --verb=SelectionUnGroup --verb=SelectionUnGroup --verb=StrokeToPath --verb=FileVacuum " |
| 117 |
cmd += "--verb=FileSave --verb=FileQuit > /dev/null 2>&1" |
| 118 |
system(cmd) |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
svgcrop = Document.new(File.new(icon[:file], 'r')) |
| 123 |
svgcrop.root.each_element("//rect") do |rect| |
| 124 |
w = ((rect.attributes["width"].to_f * 10).round / 10.0).to_i |
| 125 |
h = ((rect.attributes["width"].to_f * 10).round / 10.0).to_i |
| 126 |
if w == 24 && h == 24 |
| 127 |
rect.remove |
| 128 |
end |
| 129 |
end |
| 130 |
icon_f = File.new(icon[:file],'w+') |
| 131 |
icon_f.puts svgcrop |
| 132 |
icon_f.close |
| 133 |
else |
| 134 |
puts " -- #{icon[:name]} already exists" |
| 135 |
end |
| 136 |
end |
| 137 |
|
| 138 |
def get_output_filename(d,n) |
| 139 |
if (/rtl$/.match(n)) |
| 140 |
outfile = "#{d}/#{n.chomp('-rtl')}-rtl.svg" |
| 141 |
else |
| 142 |
outfile = "#{d}/#{n}.svg" |
| 143 |
end |
| 144 |
return outfile |
| 145 |
end |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
svg = Document.new(File.new(SRC22, 'r')) |
| 150 |
|
| 151 |
if (ARGV[0].nil?) |
| 152 |
puts "Rendering from icons in #{SRC22}" |
| 153 |
|
| 154 |
svg.root.each_element("/svg/g[@inkscape:groupmode='layer']") do |context| |
| 155 |
context_name = context.attributes.get_attribute("inkscape:label").value |
| 156 |
puts "Going through layer '" + context_name + "'" |
| 157 |
context.each_element("g") do |icon| |
| 158 |
|
| 159 |
dir = "#{PREFIX22}/#{context_name}" |
| 160 |
icon_name = icon.attributes.get_attribute("inkscape:label").value |
| 161 |
chopSVG({ :name => icon_name, |
| 162 |
:id => icon.attributes.get_attribute("id"), |
| 163 |
:dir => dir, |
| 164 |
:file => get_output_filename(dir, icon_name)}) |
| 165 |
end |
| 166 |
end |
| 167 |
puts "\nrendered all SVGs" |
| 168 |
else |
| 169 |
icons = ARGV |
| 170 |
ARGV.each do |icon_name| |
| 171 |
icon = svg.root.elements["//g[@inkscape:label='#{icon_name}']"] |
| 172 |
dir = "#{PREFIX22}/#{icon.parent.attributes['inkscape:label']}" |
| 173 |
chopSVG({ :name => icon_name, |
| 174 |
:id => icon.attributes["id"], |
| 175 |
:dir => dir, |
| 176 |
:file => get_output_filename(dir, icon_name), |
| 177 |
:forcerender => true}) |
| 178 |
end |
| 179 |
puts "\nrendered #{ARGV.length} icons" |
| 180 |
end |