Debian Codegraph @

cmd/dot/cmap_tester.tcl

raw
1 #!/usr/bin/tclsh
2
3 # cmap tester - make visible the map areas from a .cmapx or .cmap file onto
4 # a .png or .gif image file
5 #
6 # usage example:
7 #
8 #
9 # ./dot -Tpng -o example.png -Tcmapx -o example.cmapx < example.gv
10 # ./cmap_tester.tcl example | xv -
11
12
13 package require Gdtclft
14
15 if {! $argc} {
16 puts stderr "Usage: $argv0 file"
17 exit
18 }
19
20 set fn [file rootname [lindex $argv 0]]
21
22 if {[file exists $fn.gif]} {
23 set image_type gif
24 } elseif {[file exists $fn.png]} {
25 set image_type png
26 } elseif {[file exists [lindex $argv 0].png]} {
27 set fn [lindex $argv 0]
28 set image_type png
29 } elseif {[file exists [lindex $argv 0].gif]} {
30 set fn [lindex $argv 0]
31 set image_type gif
32 } else {
33 puts stderr "image file $fn.gif or $fn.png does not exist."
34 exit
35 }
36
37 if {[file exists $fn.cmap]} {
38 set map_type cmap
39 } elseif {[file exists $fn.cmapx]} {
40 set map_type cmapx
41 } else {
42 puts stderr "map file $fn.cmap or $fn.cmapx does not exist."
43 exit
44 }
45
46 set f [open $fn.$image_type r]
47 set gd [gd createFrom[string toupper $image_type] $f]
48 close $f
49
50 set turquoise [gd color resolve $gd 0 255 255]
51
52 set f [open $fn.$map_type r]
53 set map [read $f [file size $fn.$map_type]]
54 close $f
55
56 foreach {. coords} [regexp -all -inline {coords="([-0-9, ]*)"} $map] {
57 set coords [split $coords ", "]
58 if {[llength $coords] == 4} {
59 eval gd rectangle $gd $turquoise $coords
60 } {
61 eval gd polygon $gd $turquoise $coords
62 }
63 }
64
65 gd write[string toupper $image_type] $gd stdout