From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- jni/ruby/ext/tk/sample/tkextlib/tkHTML/hv.rb | 313 +++++++++++++++++++++++++++ 1 file changed, 313 insertions(+) create mode 100644 jni/ruby/ext/tk/sample/tkextlib/tkHTML/hv.rb (limited to 'jni/ruby/ext/tk/sample/tkextlib/tkHTML/hv.rb') diff --git a/jni/ruby/ext/tk/sample/tkextlib/tkHTML/hv.rb b/jni/ruby/ext/tk/sample/tkextlib/tkHTML/hv.rb new file mode 100644 index 0000000..920eb15 --- /dev/null +++ b/jni/ruby/ext/tk/sample/tkextlib/tkHTML/hv.rb @@ -0,0 +1,313 @@ +#!/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