#!/usr/bin/env ruby
#
# This script implements the "hv" application. Type "hv FILE" to
# view FILE as HTML.
#
# This application is used for testing the HTML widget. It can
# also server as an example of how to use the HTML widget.
#
require 'tk'
require 'tkextlib/tkHTML'
root = TkRoot.new(:title=>'HTML File Viewer', :iconname=>'HV')
file = ARGV[0]
#
# These images are used in place of GIFs or of form elements
#
biggray = TkPhotoImage.new(:data=><<'EOD')
R0lGODdhPAA+APAAALi4uAAAACwAAAAAPAA+AAACQISPqcvtD6OctNqLs968+w+G4kiW5omm
6sq27gvH8kzX9o3n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNFgsAO///
EOD
smgray = TkPhotoImage.new(:data=><<'EOD')
R0lGODdhOAAYAPAAALi4uAAAACwAAAAAOAAYAAACI4SPqcvtD6OctNqLs968+w+G4kiW5omm
6sq27gvH8kzX9m0VADv/
EOD
nogifbig = TkPhotoImage.new(:data=><<'EOD')
R0lGODdhJAAkAPEAAACQkADQ0PgAAAAAACwAAAAAJAAkAAACmISPqcsQD6OcdJqKM71PeK15
AsSJH0iZY1CqqKSurfsGsex08XuTuU7L9HywHWZILAaVJssvgoREk5PolFo1XrHZ29IZ8oo0
HKEYVDYbyc/jFhz2otvdcyZdF68qeKh2DZd3AtS0QWcDSDgWKJXY+MXS9qY4+JA2+Vho+YPp
FzSjiTIEWslDQ1rDhPOY2sXVOgeb2kBbu1AAADv/
EOD
nogifsm = TkPhotoImage.new(:data=><<'EOD')
R0lGODdhEAAQAPEAAACQkADQ0PgAAAAAACwAAAAAEAAQAAACNISPacHtD4IQz80QJ60as25d
3idKZdR0IIOm2ta0Lhw/Lz2S1JqvK8ozbTKlEIVYceWSjwIAO///
EOD
#
# define variables
#
ul_hyper = TkVariable.new(0)
show_tbl = TkVariable.new(0)
show_img = TkVariable.new(1)
#
# A font chooser routine.
#
# html[:fontcommand] = pick_font
pick_font = proc{|size, attrs|
puts "FontCmd: #{size} #{attrs}"
[ ((attrs =~ /fixed/)? 'courier': 'charter'),
(12 * (1.2**(size.to_f - 4.0))).to_i,
((attrs =~ /italic/)? 'italic': 'roman'),
((attrs =~ /bold/)? 'bold': 'normal') ].join(' ')
}
#
# This routine is called for each form element
#
form_cmd = proc{|n, cmd, style, *args|
# puts "FormCmd: $n $cmd $args"
case cmd
when 'select', 'textarea', 'input'
TkLabel.new(:widgetname=>args[0], :image=>nogifsm)
end
}
#
# This routine is called for every markup
#
images = {}
old_imgs = {}
big_imgs = {}
hotkey = {}
move_big_image = proc{|b|
if big_imgs.key?(b)
b.copy(big_imgs[b])
big_imgs[b].delete
big_imgs.delete(b)
Tk.update
end
}
image_cmd = proc{|*args|
if show_img.bool
smgray
else
fn = args[0]
if old_imgs.key?(fn)
images[fn] = old_imgs[fn]
old_imgs.delete(fn)
images[fn]
else
begin
img = TkPhotoImage.new(:file=>fn)
rescue
smgray
else
if img.width * img.height > 20000
b = TkPhotoImage.new(:width=>img.width, :height=>img.height)
big_imgs[b] = img
img = b
Tk.after_idle(proc{ move_big_image.call(b) })
end
images[fn] = img
img
end
end
end
}
#
# This routine is called for every