entities.tcl 1.7 KB

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