Debian Codegraph @

tclpkg/gdtclft/demo/entities.tcl

raw
1 #!/bin/sh
2 # next line is a comment in tcl \
3 exec tclsh "$0" ${1+"$@"}
4
5 package require Gdtclft
6
7 # Create a table of all HTML 4.0 Entities in a PNG image.
8 #
9 # John Ellson <[email protected]>
10
11 #set font symbol
12 set font freesans
13
14 set titlefont times
15 set gd [gd create 1100 850]
16 set white [gd color new $gd 255 255 255]
17 set black [gd color new $gd 0 0 0]
18 set red [gd color new $gd 255 0 0]
19 set green [gd color new $gd 0 255 0]
20
21 proc incr_rowcol {} {
22 upvar 1 row row col col x1 x1 x2 x2 x3 x3 y y
23 if {! ($row % 40)} {
24 set x1 [expr $col * 120 + 10]
25 set x2 [expr $x1 + 30]
26 set x3 [expr $x1 + 60]
27 incr col
28 set y 10
29 }
30 incr row
31 incr y 20
32 }
33
34 # lay down a title on the background
35 gd text $gd $green $titlefont 50. .7 350 500 "HTML 4.0 Entities\r\nfont = $font"
36
37 set row 0
38 set col 0
39
40 # first initialize names for asci characters 32-126 to themselves
41 for {set val 32} {$val < 127} {incr val} {
42 set entity($val) [format {%c} $val]
43 }
44
45 # get other names for html-4.0 characters from:
46 # http://www.w3.org/TR/REC-html40/sgml/entities.html
47 set f [open entities.html r]
48 while {! [eof $f]} {
49 set rec [gets $f]
50 if {[scan $rec {&lt;!ENTITY %s CDATA "&amp;#%d;" --} name val] == 2} {
51 set entity($val) $name
52 }
53 }
54
55 # sort and render
56 foreach val [lsort -integer [array names entity]] {
57 incr_rowcol
58 if {$entity($val) == "hearts" || $entity($val) == "diams"} {
59 # just for fun!
60 set fontcolor $red
61 } {
62 set fontcolor $black
63 }
64 gd text $gd $black $titlefont 8. 0. $x1 $y [format {%5d} $val]
65 gd text $gd $fontcolor $font 16. 0. $x2 $y [format {&#%d;} $val]
66 gd text $gd $black $titlefont 12. 0. $x3 $y $entity($val)
67 }
68 close $f
69
70 set f stdout
71 #set f [open entities.png w]
72 #set f [open "| xv -" w]
73 gd writePNG $gd $f
74 #close $f