| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
require "rexml/document" |
| 22 |
require "fileutils" |
| 23 |
include REXML |
| 24 |
|
| 25 |
INKSCAPE = 'flatpak run org.inkscape.Inkscape' |
| 26 |
|
| 27 |
SRC = "./source-symbolic.svg" |
| 28 |
PREFIX = "../../Paper/scalable" |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
SVGO = '/usr/bin/svgo' |
| 34 |
|
| 35 |
def chopSVG(icon) |
| 36 |
FileUtils.mkdir_p(icon[:dir]) unless File.exists?(icon[:dir]) |
| 37 |
unless (File.exists?(icon[:file]) && !icon[:forcerender]) |
| 38 |
FileUtils.cp(SRC,icon[:file]) |
| 39 |
puts " >> #{icon[:name]}" |
| 40 |
|
| 41 |
cmd = "#{INKSCAPE} -f #{icon[:file]} " |
| 42 |
cmd += "--select #{icon[:id]} --verb=FitCanvasToSelection --verb=EditInvertInAllLayers --verb=EditDelete " |
| 43 |
cmd += "--verb=FileVacuum --verb=FileSave --verb=FileQuit > /dev/null 2>&1" |
| 44 |
system(cmd) |
| 45 |
|
| 46 |
svgcrop = Document.new(File.new(icon[:file], 'r')) |
| 47 |
svgcrop.root.each_element("//rect") do |rect| |
| 48 |
w = ((rect.attributes["width"].to_f * 10).round / 10.0).to_i |
| 49 |
h = ((rect.attributes["width"].to_f * 10).round / 10.0).to_i |
| 50 |
if w == 16 && h == 16 |
| 51 |
rect.remove |
| 52 |
end |
| 53 |
end |
| 54 |
icon_f = File.new(icon[:file],'w+') |
| 55 |
icon_f.puts svgcrop |
| 56 |
icon_f.close |
| 57 |
|
| 58 |
cmd = "#{INKSCAPE} -f #{icon[:file]} --verb=EditSelectAll --verb=SelectionUnGroup --verb=SelectionUnGroup --verb=SelectionUnGroup --verb=ObjectToPath --verb=StrokeToPath " |
| 59 |
cmd += "--verb=FileSave --verb=FileQuit > /dev/null 2>&1" |
| 60 |
system(cmd) |
| 61 |
|
| 62 |
cmd = "#{INKSCAPE} -f #{icon[:file]} -z --vacuum-defs --export-plain-svg=#{icon[:file]} > /dev/null 2>&1" |
| 63 |
system(cmd) |
| 64 |
|
| 65 |
cmd = "#{SVGO} --pretty --disable=convertShapeToPath --disable=convertPathData --enable=removeStyleElement -i #{icon[:file]} -o #{icon[:file]} > /dev/null 2>&1" |
| 66 |
system(cmd) |
| 67 |
else |
| 68 |
puts " -- #{icon[:name]} already exists" |
| 69 |
end |
| 70 |
end |
| 71 |
|
| 72 |
def get_output_filename(d,n) |
| 73 |
if (/rtl$/.match(n)) |
| 74 |
outfile = "#{d}/#{n.chomp('-rtl')}-symbolic-rtl.svg" |
| 75 |
else |
| 76 |
outfile = "#{d}/#{n}-symbolic.svg" |
| 77 |
end |
| 78 |
return outfile |
| 79 |
end |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
svg = Document.new(File.new(SRC, 'r')) |
| 84 |
|
| 85 |
if (ARGV[0].nil?) |
| 86 |
puts "Rendering from icons in #{SRC}" |
| 87 |
|
| 88 |
svg.root.each_element("/svg/g[@inkscape:groupmode='layer']") do |context| |
| 89 |
context_name = context.attributes.get_attribute("inkscape:label").value |
| 90 |
puts "Going through layer '" + context_name + "'" |
| 91 |
context.each_element("g") do |icon| |
| 92 |
|
| 93 |
dir = "#{PREFIX}/#{context_name}" |
| 94 |
icon_name = icon.attributes.get_attribute("inkscape:label").value |
| 95 |
|
| 96 |
if icon_name.end_with?("-alt", "-old", "-template", "-source", "-ltr", "-working") |
| 97 |
puts " ++ skipping icon '" + icon_name + "'" |
| 98 |
elsif icon_name =~ /\d$/ |
| 99 |
puts " ++ skipping icon '" + icon_name + "'" |
| 100 |
else |
| 101 |
chopSVG({ :name => icon_name, |
| 102 |
:id => icon.attributes.get_attribute("id"), |
| 103 |
:dir => dir, |
| 104 |
:file => get_output_filename(dir, icon_name)}) |
| 105 |
end |
| 106 |
end |
| 107 |
end |
| 108 |
puts "\nrendered all SVGs" |
| 109 |
else |
| 110 |
icons = ARGV |
| 111 |
ARGV.each do |icon_name| |
| 112 |
icon = svg.root.elements["//g[@inkscape:label='#{icon_name}']"] |
| 113 |
if icon_name == "process-working" |
| 114 |
dir = "#{PREFIX32}/#{icon.parent.attributes['inkscape:label']}" |
| 115 |
else |
| 116 |
dir = "#{PREFIX}/#{icon.parent.attributes['inkscape:label']}" |
| 117 |
end |
| 118 |
chopSVG({ :name => icon_name, |
| 119 |
:id => icon.attributes["id"], |
| 120 |
:dir => dir, |
| 121 |
:file => get_output_filename(dir, icon_name), |
| 122 |
:forcerender => true}) |
| 123 |
end |
| 124 |
puts "\nrendered #{ARGV.length} icons" |
| 125 |
end |