| •1 |
#!/usr/bin/tclsh8.6 |
| 2 |
|
| 3 |
array set page " |
| 4 |
rows 2 |
| 5 |
columns 2 |
| 6 |
padx 0.5 |
| 7 |
pady 0.5 |
| 8 |
width 8.5 |
| 9 |
height 11 |
| 10 |
gutter 0.25 |
| 11 |
" |
| 12 |
|
| 13 |
proc Pica { dist } { |
| 14 |
expr $dist * 72.0 |
| 15 |
} |
| 16 |
|
| 17 |
# ------------------------------------------------------------------ |
| 18 |
# |
| 19 |
# TileFiles |
| 20 |
# |
| 21 |
# Tiles graph postscript files together in a pre-defined |
| 22 |
# grid. |
| 23 |
# |
| 24 |
# Arguments: |
| 25 |
# outFile -- Resulting tiled PostScript output file. |
| 26 |
# args -- Names of input graph PostScript files. |
| 27 |
# |
| 28 |
# ------------------------------------------------------------------ |
| 29 |
|
| 30 |
proc TileFiles { outFile args } { |
| 31 |
global page |
| 32 |
|
| 33 |
set row 0 |
| 34 |
set column 0 |
| 35 |
|
| 36 |
|
| 37 |
set padx [Pica $page(padx)] |
| 38 |
set pady [Pica $page(padx)] |
| 39 |
set width [Pica $page(width)] |
| 40 |
set height [Pica $page(height)] |
| 41 |
set gutter [Pica $page(gutter)] |
| 42 |
|
| 43 |
set totalGutters [expr $gutter * ($page(columns) - 1)] |
| 44 |
set w [expr $width - (2 * $padx) - $totalGutters] |
| 45 |
set totalGutters [expr $gutter * ($page(rows) - 1)] |
| 46 |
set h [expr $height - (2 * $pady) - $totalGutters] |
| 47 |
|
| 48 |
set cellWidth [expr double($w) / $page(columns)] |
| 49 |
set cellHeight [expr double($h) / $page(rows)] |
| 50 |
|
| 51 |
set out [open $outFile "w"] |
| 52 |
|
| 53 |
puts $out "%!PS-Adobe-3.0 EPSF-3.0" |
| 54 |
puts $out "%%Pages: 1" |
| 55 |
puts $out "%%Title: (Graph tiler)" |
| 56 |
puts $out "%%DocumentNeededResources: font Helvetica Courier" |
| 57 |
puts $out "%%CreationDate: [clock format [clock seconds]]" |
| 58 |
puts $out "%%EndComments" |
| 59 |
|
| 60 |
puts $out "/showsheet { showpage } bind def" |
| 61 |
puts $out "/showpage { } def" |
| 62 |
puts $out "$padx $pady translate" |
| 63 |
|
| 64 |
set first {} |
| 65 |
foreach inFile $args { |
| 66 |
set in [open $inFile "r"] |
| 67 |
|
| 68 |
# Warning, this is assuming that the BoundingBox is in the first |
| 69 |
# twenty lines of the graph's PostScript. |
| 70 |
|
| 71 |
for { set count 0 } { $count < 20 } { incr count } { |
| 72 |
gets $in line |
| 73 |
if { [string match "%%BoundingBox:*" $line] } { |
| 74 |
set bbox $line |
| 75 |
break; |
| 76 |
} |
| 77 |
append first "$line\n" |
| 78 |
if { [eof $in] } { |
| 79 |
break |
| 80 |
} |
| 81 |
} |
| 82 |
if { ![info exists bbox] } { |
| 83 |
error "can't find \"%%BoundingBox:\" line" |
| 84 |
} |
| 85 |
set n [scan $bbox "%%%%BoundingBox: %d %d %d %d" x1 y1 x2 y2] |
| 86 |
if { $n != 4} { |
| 87 |
error "Bad bounding box line \"$bbox\"" |
| 88 |
} |
| 89 |
|
| 90 |
set rest [read $in] |
| 91 |
close $in |
| 92 |
|
| 93 |
set x [expr ($cellWidth + $gutter) * $column] |
| 94 |
set y [expr ($cellHeight + $gutter) * $row] |
| 95 |
|
| 96 |
set w [expr abs($x2 - $x1)] |
| 97 |
set h [expr abs($y2 - $y1)] |
| 98 |
|
| 99 |
set scaleX [expr $cellWidth / $w] |
| 100 |
set scaleY [expr $cellHeight / $h] |
| 101 |
if { $scaleX > $scaleY } { |
| 102 |
set scale $scaleY |
| 103 |
} else { |
| 104 |
set scale $scaleX |
| 105 |
} |
| 106 |
puts $out "% " |
| 107 |
puts $out "% Tiling \"$inFile\" at ($row,$column)" |
| 108 |
puts $out "% " |
| 109 |
puts $out "gsave" |
| 110 |
puts $out "$x $y translate" |
| 111 |
puts $out "$scale $scale scale" |
| 112 |
puts $out "-$x1 -$y1 translate" |
| 113 |
puts $out $first |
| 114 |
puts $out $rest |
| 115 |
puts $out "grestore" |
| 116 |
incr column |
| 117 |
if { $column >= $page(columns) } { |
| 118 |
set column 0 |
| 119 |
incr row |
| 120 |
} |
| 121 |
} |
| 122 |
puts $out "showsheet" |
| 123 |
close $out |
| 124 |
} |
| 125 |
|
| 126 |
eval TileFiles $argv |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|