-
Notifications
You must be signed in to change notification settings - Fork 2
/
picify
executable file
·175 lines (134 loc) · 3.47 KB
/
picify
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/perl
$chars = 0;
@twobit = ( "00", "01", "10", "11" );
@threebit = ( "000", "001", "010", "011", "100", "101", "110", "111" );
@fourbit = ( "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
"1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111" );
while (<>)
{
chop;
$char[$chars] = $_;
$chars++;
}
print ".ie t \\{.\n";
print ".PS\n";
#print ".sp -1\n";
$rows = 16;
$cols = $chars / $rows;
$captionwid = 0.25;
#$bitwidth = 0.4;
$wid = (3 - $captionwid) / ($cols);
$ht = 1/6;
$ht = 10/72; # was 1/6, then 1/8, ...
#print ".ft H\n";
print "boxwid = $wid\n";
print "boxht = $ht\n";
print "linethick = 0\n";
for ($y = 0; $y < $rows; $y++) {
print ".ps 7\n";
printf ("move to %0.5f, -%0.5f; left\n", 0, $y * $ht);
printf ("box invis width $captionwid \"");
print "$y\" rjust\n";
# printf ("move to %0.5f, -%0.5f; right\n", $cols * $wid, $y * $ht);
# printf ("box invis width $bitwidth \"\\&...\\fC%s\\fP\"\n",
# $fourbit[$y]);
}
for ($x = 0; $x < $cols; $x++) {
print ".ps 7\n";
printf ("move to %0.5f, -%0.5f; up\n", $x * $wid + $wid/2, -$ht/2);
printf ("box invis \"", $wid, $ht);
print "$x\"\n";
# printf ("move to %0.5f, -%0.5f; down\n", $x * $wid + $wid/2,
# $rows * $ht - $ht/2);
# if ($cols == 4) {
# printf ("box invis \"\\fC%s\\fP...\"\n", $twobit[$x]);
# } else {
# printf ("box invis \"\\fC%s\\fP...\"\n", $threebit[$x]);
# }
}
print ".ps 8\n";
for ($y = 0; $y < $rows; $y++) {
for ($x = 0; $x < $cols; $x++) {
$cell = $x * $rows + $y;
$arrows = 0;
$text = $char[$cell];
if ($text =~ /\*\*\*/) {
$text =~ s/\s*\*\*\*//;
$arrows = 1;
}
# $text =~ s/\s*$//;
$text =~ s/"/\\"/g;
printf ("move to %0.5f, -%0.5f; right\n", $x * $wid, $y * $ht);
if ($arrows) {
print "linethick = 1\n";
}
if ($text =~ /^(.*)\t(.*)$/) {
print "box invis width boxwid/2";
print "\"", $1, "\"\n";
print "box invis width boxwid/2";
print "\"", $2, "\"\n";
print "left; box\n";
if ($arrows) {
print "linethick = 0\n";
}
print "move right boxwid/2 + boxht/8\n";
print "move up boxht/2\n";
print "line down boxht left boxht/4\n";
} else {
printf ("box ");
print "\"";
print "$text\"\n";
}
if ($arrows) {
print "linethick = 0\n";
}
}
}
print ".ps 10\n";
print ".PE\n";
#print ".vs 12\n"; # so double-spaced picture captions aren't so huge
print ".\\}\n";
print ".el \\{.\n";
print "<table align=\"center\" width=\"75%\">\n";
print "<tr><td></td>\n";
for ($x = 0; $x < $cols; $x++) {
print "<td colspan=2 align=\"center\"><font size=-2>$x</font></td>\n";
}
print "</tr>\n";
for ($y = 0; $y < $rows; $y++) {
print "<tr>\n";
print "<td align=\"right\"><font size=-2>$y</font></td>\n";
for ($x = 0; $x < $cols; $x++) {
$text = $char[$x * $rows + $y];
$bold = "bgcolor=\"#bbbbbb\"";
if ($text =~ /\*\*\*$/) {
$text =~ s/\s*\*\*\*$//;
$bold = "bgcolor=\"#ff8888\"";
}
$whole = int (100 / ($cols + 1));
$half = int ($whole / 2);
$whole = $half * 2;
if ($text =~ /(.*)\t(.*)/) {
print "<td $bold align=center width=$half%>";
print "<font size=-1>";
print "$1";
print "</font>";
print "</td> ";
print "<td $bold align=center width=$half%>";
print "<font size=-1>";
print "$2";
print "</font>";
print "</td> ";
} else {
print "<td $bold align=center width=$whole%";
print " colspan=2>";
print "<font size=-1>";
print "$text";
print "</font>";
print "</td> ";
}
}
print "</tr>\n";
}
print "</table>\n";
print ".\\}\n";