Mercurial > pidgin.yaz
annotate pidgin/pixmaps/art-tools/render-pidgin-emotes.rb @ 32827:4a34689eeb33 default tip
merged from im.pidgin.pidgin
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sat, 19 Nov 2011 14:42:54 +0900 |
parents | 209da0d52824 |
children |
rev | line source |
---|---|
23877
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env ruby |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
2 |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
3 require "rexml/document" |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
4 require "ftools" |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
5 include REXML |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
6 INKSCAPE = '/usr/bin/inkscape' |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
7 SRC = "./svg" |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
8 |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
9 def renderit(file) |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
10 svg = Document.new(File.new("#{SRC}/#{file}", 'r')) |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
11 svg.root.each_element("//g[contains(@inkscape:label,'plate')]") do |icon| |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
12 filename = icon.attributes["label"] |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
13 filename = `echo -n #{filename} | sed -e 's/plate\-//g'` |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
14 puts "#{file} #{filename}.png" |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
15 icon.each_element("rect") do |box| |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
16 if box.attributes['inkscape:label'] == '22x22' |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
17 dir = "#{box.attributes['width']}x#{box.attributes['height']}/" |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
18 cmd = "#{INKSCAPE} -i #{box.attributes['id']} -e #{dir}/#{filename}.png #{SRC}/#{file} > /dev/null 2>&1" |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
19 File.makedirs(dir) unless File.exists?(dir) |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
20 system(cmd) |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
21 print "." |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
22 elsif box.attributes['inkscape:label'] == '24x24' |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
23 dir = "#{box.attributes['width']}x#{box.attributes['height']}/" |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
24 cmd = "#{INKSCAPE} -i #{box.attributes['id']} -e #{dir}/#{filename}.png #{SRC}/#{file} > /dev/null 2>&1" |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
25 File.makedirs(dir) unless File.exists?(dir) |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
26 system(cmd) |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
27 print "." |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
28 end |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
29 end |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
30 puts '' |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
31 end |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
32 end |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
33 |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
34 if (ARGV[0].nil?) #render all SVGs |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
35 puts "Rendering from SVGs in #{SRC}" |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
36 Dir.foreach(SRC) do |file| |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
37 renderit(file) if file.match(/svg$/) |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
38 end |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
39 puts "\nrendered all SVGs" |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
40 else #only render the SVG passed |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
41 file = "#{ARGV[0]}.svg" |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
42 if (File.exists?("#{SRC}/#{file}")) |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
43 renderit(file) |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
44 puts "\nrendered #{file}" |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
45 else |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
46 puts "[E] No such file (#{file})" |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
47 end |
209da0d52824
First steps to one-canvas workflow.
Hylke Bons <hylkebons@gmail.com>
parents:
diff
changeset
|
48 end |