From ac8a1c931f18b7874453ea0db28c7c4e648371c2 Mon Sep 17 00:00:00 2001 From: nagai Date: Thu, 1 Jul 2004 09:38:48 +0000 Subject: * ext/tk/lib/tcltklib : bug fix * ext/tk/lib/tk : bug fix and add Tcl/Tk extension support libraries git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@6559 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/sample/tkextlib/tkHTML/ss.rb | 404 ++++++++++++++++++++++++++++++++++++ 1 file changed, 404 insertions(+) create mode 100644 ext/tk/sample/tkextlib/tkHTML/ss.rb (limited to 'ext/tk/sample/tkextlib/tkHTML/ss.rb') diff --git a/ext/tk/sample/tkextlib/tkHTML/ss.rb b/ext/tk/sample/tkextlib/tkHTML/ss.rb new file mode 100644 index 000000000..e71c26f7d --- /dev/null +++ b/ext/tk/sample/tkextlib/tkHTML/ss.rb @@ -0,0 +1,404 @@ +#!/usr/bin/env ruby +# +# This script implements the "ss" application. "ss" implements +# a presentation slide-show based on HTML slides. +# +require 'tk' +require 'tkextlib/tkHTML' + +root = TkRoot.new(:title=>'HTML File Viewer', :iconname=>'HV') +fswin = nil + +html = nil +html_fs = nil + +hotkey = {} + +file = ARGV[0] + + +# These are images to use with the actual image specified in a +# "" markup can't be found. +# +biggray = TkPhotoImage.new(:data=><<'EOD') + R0lGODdhPAA+APAAALi4uAAAACwAAAAAPAA+AAACQISPqcvtD6OctNqLs968+w+G4kiW5omm + 6sq27gvH8kzX9o3n+s73/g8MCofEovGITCqXzKbzCY1Kp9Sq9YrNFgsAO/// +EOD + +smgray = TkPhotoImage.new(:data=><<'EOD') + R0lGODdhOAAYAPAAALi4uAAAACwAAAAAOAAYAAACI4SPqcvtD6OctNqLs968+w+G4kiW5omm + 6sq27gvH8kzX9m0VADv/ +EOD + + +# +# 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 to pick fonts for the fullscreen view. +# +baseFontSize = 24 +pick_font_fs = proc{|size, attrs| + # puts "FontCmd: #{size} #{attrs}" + [ ((attrs =~ /fixed/)? 'courier': 'charter'), + (baseFontSize * (1.2**(size.to_f - 4.0))).to_i, + ((attrs =~ /italic/)? 'italic': 'roman'), + ((attrs =~ /bold/)? 'bold': 'normal') ].join(' ') +} + +# +# +hyper_cmd = proc{|*args| + puts "HyperlinkCommand: #{args.inspect}" +} + +# This routine is called to run an applet +# +applet_arg = TkVarAccess.new_hash('AppletArg') +run_applet = proc{|size, w, arglist| + applet_arg.value = Hash[*simplelist(arglist)] + + return unless applet_arg.key?('src') + + src = html.remove(applet_arg['src']) + + applet_arg['window'] = w + applet_arg['fontsize'] = size + + begin + Tk.load_tclscript(src) + rescue => e + puts "Applet error: #{e.message}" + end +} + +# +# +form_cmd = proc{|n, cmd, *args| +} + +# +# +images = {} +old_imgs = {} +big_imgs = {} + +# +# +move_big_image = proc{|b| + return unless big_imgs.key?(b) + b.copy(big_imgs[b]) + big_imgs[b].delete + big_imgs.delete(b) +} + +image_cmd = proc{|hs, *args| + fn = args[0] + + if old_imgs.key?(fn) + return (images[fn] = old_imgs.delete(fn)) + end + + begin + img = TkPhotoImage.new(:file=>fn) + rescue + return ((hs)? smallgray: biggray) + end + + if hs + img2 = TkPhotoImage.new + img2.copy(img, :subsample=>[2,2]) + img.delete + img = img2 + end + + 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 +} + + +# +# This routine is called for every