diff options
Diffstat (limited to 'scripts/context/ruby/xmltools.rb')
-rw-r--r-- | scripts/context/ruby/xmltools.rb | 81 |
1 files changed, 79 insertions, 2 deletions
diff --git a/scripts/context/ruby/xmltools.rb b/scripts/context/ruby/xmltools.rb index e1803daf6..0c2367068 100644 --- a/scripts/context/ruby/xmltools.rb +++ b/scripts/context/ruby/xmltools.rb @@ -11,7 +11,7 @@ banner = ['XMLTools', 'version 1.0', '2002/2004', 'PRAGMA ADE/POD'] unless defined? ownpath - ownpath = $0.sub(/[\\\/]\w*?\.rb/i,'') + ownpath = $0.sub(/[\\\/][a-z0-9\-]*?\.rb/i,'') $: << ownpath end @@ -114,12 +114,84 @@ class Commands alias ls :dir + def mmlpages + + file = @commandline.argument('first') + eps = @commandline.option('eps') + png = @commandline.option('png') + style = @commandline.option('style') + modes = @commandline.option('modes') + + file = file.sub(/\.xml/io, '') + long = "#{file}-mmlpages" + if FileTest.file?(file+'.xml') then + style = "--arg=\"style=#{style}\"" unless style.empty? + modes = "--mode=#{modes}" unless modes.empty? + if system("texmfstart texexec.pl --batch --pdf --once --result=#{long} --use=mmlpag #{style} #{modes} #{file}.xml") then + if f = open("#{file}-mmlpages.txt") then + while line = f.gets do + data = Hash.new + if fields = line.split then + fields.each do |fld| + key, value = fld.split('=') + data[key] = value if key && value + end + if data.key?('p') then + page = data['p'] + name = "#{long}-#{page}" + if eps then + report("generating eps file #{name}") + if system("pdftops -eps -f #{page} -l #{page} #{long}.pdf #{name}.eps") then + if data.key?('d') then + if epsfile = IO.read("#{name}.eps") then + epsfile.sub!(/^(\%\%BoundingBox:.*?$)/i) do + newline = $1 + "\n%%Baseline: #{data['d']}\n" + if data.key?('w') && data.key?('h') then + newline += "%%PositionWidth: #{data['w']}\n" + newline += "%%PositionHeight: #{data['h']}\n" + newline += "%%PositionDepth: #{data['d']}" + end + newline + end + if g = File.open("#{name}.eps",'wb') then + g.write(epsfile) + g.close + end + end + end + else + report("error in generating eps from #{name}") + end + end + if png then + report("generating png file #{name}") + system("imagemagick #{name}.eps #{name}.png") + end + end + end + end + f.close + else + report("missing data log file #{filename}") + end + else + report("error in processing file #{filename}") + end + system("texmfstart texutil --purge") + else + report("error in processing file #{filename}") + end + + end + end logger = EXA::ExaLogger.new(banner.shift) commandline = CommandLine.new -commandline.registeraction('dir','generate directory listing') +commandline.registeraction('dir', 'generate directory listing') +commandline.registeraction('mmlpages','generate graphic from mathml') + commandline.registeraction('ls') commandline.registeraction('help') @@ -133,6 +205,11 @@ commandline.registervalue('url') commandline.registervalue('output') commandline.registervalue('root') +commandline.registerflag('eps') +commandline.registerflag('png') +commandline.registervalue('style') +commandline.registervalue('modes') + commandline.expand Commands.new(commandline,logger,banner).send(commandline.action || 'help')
\ No newline at end of file |