File: cmap_tester.tcl

package info (click to toggle)
graphviz 14.0.5-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 139,388 kB
  • sloc: ansic: 141,938; cpp: 11,957; python: 7,766; makefile: 4,043; yacc: 3,030; xml: 2,972; tcl: 2,495; sh: 1,388; objc: 1,159; java: 560; lex: 423; perl: 243; awk: 156; pascal: 139; php: 58; ruby: 49; cs: 31; sed: 1
file content (65 lines) | stat: -rwxr-xr-x 1,439 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/tclsh

# cmap tester - make visible the map areas from a .cmapx or .cmap file onto 
# a .png or .gif image file
#
# usage example:
#
#
# ./dot -Tpng -o example.png -Tcmapx -o example.cmapx < example.gv
# ./cmap_tester.tcl example | xv -


package require Gdtclft

if {! $argc} {
	puts stderr "Usage: $argv0 file"
	exit
}

set fn [file rootname [lindex $argv 0]]

if {[file exists $fn.gif]} {
	set image_type gif
} elseif {[file exists $fn.png]} {
	set image_type png
} elseif {[file exists [lindex $argv 0].png]} {
	set fn [lindex $argv 0]
	set image_type png
} elseif {[file exists [lindex $argv 0].gif]} {
	set fn [lindex $argv 0]
	set image_type gif
} else {
	puts stderr "image file $fn.gif or $fn.png does not exist."
	exit
}

if {[file exists $fn.cmap]} {
	set map_type cmap
} elseif {[file exists $fn.cmapx]} {
	set map_type cmapx
} else {
	puts stderr "map file $fn.cmap or $fn.cmapx does not exist."
	exit
}

set f [open $fn.$image_type r]
set gd [gd createFrom[string toupper $image_type] $f]
close $f

set turquoise [gd color resolve $gd 0 255 255]

set f [open $fn.$map_type r]
set map [read $f [file size $fn.$map_type]]
close $f

foreach {. coords} [regexp -all -inline {coords="([-0-9, ]*)"} $map] {
	set coords [split $coords ", "]
	if {[llength $coords] == 4} {
	    eval gd rectangle $gd $turquoise $coords
	} {
	    eval gd polygon $gd $turquoise $coords
	}
}

gd write[string toupper $image_type] $gd stdout