diff options
author | Karl Berry <karl@freefriends.org> | 2006-11-16 01:02:47 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2006-11-16 01:02:47 +0000 |
commit | 3c85b55e2f245fb7edac7e445f107e6d0bb423ae (patch) | |
tree | c62b7f80edafe0455310d08e09f4218127bf9e87 /Master/texmf-dist/scripts/context/ruby/rlxtools.rb | |
parent | e5ecff27a26ef59e1dbe9702677687fd7107be3a (diff) |
context update
git-svn-id: svn://tug.org/texlive/trunk@2444 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/context/ruby/rlxtools.rb')
-rw-r--r-- | Master/texmf-dist/scripts/context/ruby/rlxtools.rb | 83 |
1 files changed, 78 insertions, 5 deletions
diff --git a/Master/texmf-dist/scripts/context/ruby/rlxtools.rb b/Master/texmf-dist/scripts/context/ruby/rlxtools.rb index 7962474eb10..1225dedb301 100644 --- a/Master/texmf-dist/scripts/context/ruby/rlxtools.rb +++ b/Master/texmf-dist/scripts/context/ruby/rlxtools.rb @@ -97,20 +97,20 @@ class Commands report("processing record #{nofrecords} (#{variables['file'] || 'noname'}: #{variables.size} entries)") if conversion = variables['conversion'] then report("testing for conversion #{conversion}") - if suffix = variables['suffix'] then + if suffix = variables['suffix'].downcase then if file = variables['file'] then report("conversion #{conversion} for suffix #{suffix} for file #{file}") else report("conversion #{conversion} for suffix #{suffix}") end - pattern = "@name='#{conversion}' and @suffix='#{suffix}'" + pattern = "@name='#{conversion}' and @suffix='#{suffix.downcase}'" if steps = REXML::XPath.first(proc.root,"/rl:manipulators/rl:manipulator[#{pattern}]") then localsteps = steps.deep_clone ['rl:old','rl:new'].each do |tag| REXML::XPath.each(localsteps,tag) do |extras| REXML::XPath.each(extras,"rl:value") do |value| if name = value.attributes['name'] then - substititute(value,variables[name.to_s]) + substititute(value,variables[name.to_s] || '') end end end @@ -176,7 +176,7 @@ class Commands end end rescue - report('error in manipulating files') + report("error in manipulating files: #{$!}") end begin logname = "#{filename}.log" @@ -202,7 +202,7 @@ class Commands return str.strip end - def substititute(value,str) + def substititute(value,str='') if str then begin if value.attributes.key?('method') then @@ -247,10 +247,83 @@ class Commands end +class Commands + + include CommandBase + + def identify + @commandline.arguments.each do |filename| + if state = do_identify(filename) then + begin + File.open(filename+'.rli','w') do |f| + f << state + end + rescue + report("error in identifying #{filename}") + else + report("#{filename} is identified") + end + end + end + end + + private + + def do_identify(filename) + begin + str = nil + if FileTest.file?(filename) then + result = `identify -format \"x=%x,y=%y,w=%w,h=%h,b=%b\" #{filename}`.chomp.split(',') + tags = Hash.new + result.each do |r| + if rr = r.split("=") then + tags[rr[0]] = rr[1] + end + end + size = (tags['b']||0).to_i + width = unified(tags['w']||0,tags['x']||'1') + height = unified(tags['h']||0,tags['y']||'1') + if size > 0 then + str = '' + str << "<?xml version='1.0' standalone='yes'?>\n" + str << "<rl:identify name='#{File.basename(filename)}'>\n" + str << " <rl:size>#{size}</rl:size>\n" + str << " <rl:path>#{File.dirname(filename).sub(/\\/o,'/')}</rl:path>\n" + str << " <rl:width>#{width}</rl:width>\n" + str << " <rl:height>#{height}</rl:height>\n" + str << "</rl:identify>\n" + end + else + str = nil + end + rescue + str = nil + end + return str + end + + def unified(dim,res) + case res + when /([\d\.]+)\s*PixelsPerInch/io then + sprintf("%.4fin",dim.to_f/$1.to_f) + when /([\d\.]+)\s*PixelsPerCentimeter/io then + sprintf("%.4fcm",dim.to_f/$1.to_f) + when /([\d\.]+)\s*PixelsPerMillimeter/io then + sprintf("%.4fmm",dim.to_f/$1.to_f) + when /([\d\.]+)\s*PixelsPerPoint/io then + sprintf("%.4fbp",dim.to_f/$1.to_f) + else + sprintf("%.4fbp",dim.to_f) + end + end + +end + logger = Logger.new(banner.shift) commandline = CommandLine.new commandline.registeraction('manipulate', ' [--test] manipulatorfile resourselog') +commandline.registeraction('identify', 'filename') commandline.registeraction('help') commandline.registeraction('version') |