| 1 |
# made in BOP s.c., [email protected]; public domain software |
| 2 |
# history: 20.08.1999: ver. 0.1, pre-release |
| 3 |
# 05.01.2000: ver. 0.2, first release |
| 4 |
BEGIN { |
| 5 |
hd["0"]=0; hd["1"]=1; hd["2"]=2; hd["3"]=3; hd["4"]=4 |
| 6 |
hd["5"]=5; hd["6"]=6; hd["7"]=7; hd["8"]=8; hd["9"]=9 |
| 7 |
hd["a"]=hd["A"]=10; hd["b"]=hd["B"]=11; hd["c"]=hd["C"]=12 |
| 8 |
hd["d"]=hd["D"]=13; hd["e"]=hd["E"]=14; hd["f"]=hd["F"]=15 |
| 9 |
# |
| 10 |
hb["0"]="0000"; hb["1"]="0001"; hb["2"]="0010"; hb["3"]="0011" |
| 11 |
hb["4"]="0100"; hb["5"]="0101"; hb["6"]="0110"; hb["7"]="0111" |
| 12 |
hb["8"]="1000"; hb["9"]="1001"; hb["a"]="1010"; hb["b"]="1011" |
| 13 |
hb["c"]="1100"; hb["d"]="1101"; hb["e"]="1110"; hb["f"]="1111" |
| 14 |
# |
| 15 |
for (i in hb) bh[hb[i]]=i |
| 16 |
# |
| 17 |
hb["A"]="1010"; hb["B"]="1011"; hb["C"]="1100" |
| 18 |
hb["D"]="1101"; hb["E"]="1110"; hb["F"]="1111" |
| 19 |
# |
| 20 |
comments=1 |
| 21 |
} |
| 22 |
|
| 23 |
/^[^%]/ && (comments==1) {comments=0; flush_prolog()} |
| 24 |
|
| 25 |
comments==1 {process_prolog()} |
| 26 |
|
| 27 |
(l==7) {l=0} |
| 28 |
|
| 29 |
(l==6) { |
| 30 |
if ($0~/ *closepath/) {l=7; IncludeEPS(Anum)} else l=-6 |
| 31 |
} |
| 32 |
|
| 33 |
(l==5) { |
| 34 |
if (is_lineto()) {l=6} |
| 35 |
else if (is_curveto()) {l=6} |
| 36 |
else if ($0~/ *closepath/) {l=7; IncludeEPS(Anum)} |
| 37 |
else l=-5 |
| 38 |
} |
| 39 |
|
| 40 |
(l==4) { |
| 41 |
if (is_lineto()) {l=5; Aulx=$1; Auly=$2} |
| 42 |
else if (is_curveto()) {l=5; Aulx=$5; Auly=$6} |
| 43 |
else l=-4 |
| 44 |
} |
| 45 |
|
| 46 |
(l==3) { |
| 47 |
if (is_lineto()) {l=4; Aurx=$1; Aury=$2} |
| 48 |
else if (is_curveto()) {l=4; Aurx=$5; Aury=$6} |
| 49 |
else l=-3 |
| 50 |
} |
| 51 |
|
| 52 |
(l==2) { |
| 53 |
if (is_lineto()) {l=3; Adrx=$1; Adry=$2} |
| 54 |
else if (is_curveto()) {l=3; Adrx=$5; Adry=$6} |
| 55 |
else l=-2 |
| 56 |
} |
| 57 |
|
| 58 |
(l==1) { |
| 59 |
if ($0~/^newpath -?[0-9\.]+ -?[0-9\.]+ moveto$/) { |
| 60 |
l=2 |
| 61 |
Adlx=$2; Adly=$3 |
| 62 |
} else l=-1 |
| 63 |
} |
| 64 |
|
| 65 |
(l<0) { |
| 66 |
print "Something strange in EPS colour (" (-l) ")" > "CON" |
| 67 |
print NR, is_lineto(), is_curveto() > "CON" |
| 68 |
print $0 > "CON" |
| 69 |
exit |
| 70 |
l=0 |
| 71 |
} |
| 72 |
|
| 73 |
/setrgbcolor$/ && (n>0) && (comments==0) { |
| 74 |
for (i in Ename) |
| 75 |
if ((Ecolr[i]==$1) && (Ecolg[i]==$2) && (Ecolb[i]==$3)) { |
| 76 |
Anum=i; l=1 |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
(l==0) && (comments==0) {gsub(/fshow/, "nshow"); print} |
| 81 |
|
| 82 |
function hexval(x) {return hd[substr(x,1,1)]*16+hd[substr(x,2,1)]} |
| 83 |
|
| 84 |
function process_prolog(){ |
| 85 |
if (/^%\*Font:/) { |
| 86 |
f_ch[$2 "\001" $4]=fix_chars(f_ch[$2 "\001" $4],$5) |
| 87 |
} else |
| 88 |
if (/^%EPS/) { |
| 89 |
Ecolr[++n]=$2+0; Ecolg[n]=$3+0; Ecolb[n]=$4+0 |
| 90 |
Ename[n]=$5 "" |
| 91 |
Ebbl[n]=$6+0; Ebbd[n]=$7+0; Ebbr[n]=$8+0; Ebbu[n]=$9+0 |
| 92 |
} else |
| 93 |
prolog[++prolog[0]]=$0 |
| 94 |
} |
| 95 |
|
| 96 |
function flush_prolog( j,l){ |
| 97 |
for (l=1; l<=prolog[0]; ++l) { |
| 98 |
if (prolog[l]~/^%%EndProlog/) j=flush_fonts(); |
| 99 |
print prolog[l] |
| 100 |
} |
| 101 |
if (j>0) print "/nshow {gsave 10 div dup scale 10 fshow grestore} def" |
| 102 |
if (n>0) print "/MEPSDict 50 dict def" |
| 103 |
} |
| 104 |
|
| 105 |
function flush_fonts( i,j) { |
| 106 |
j=0 |
| 107 |
for (i in f_ch) { |
| 108 |
j++ |
| 109 |
split(i,a,"\001") |
| 110 |
printf("%%*Font: %s 10.0 %s %s\n", a[1], a[2], out_chars(f_ch[i])) |
| 111 |
} |
| 112 |
return j |
| 113 |
} |
| 114 |
|
| 115 |
function fix_chars(f,c, a) { |
| 116 |
split(c,a,":") |
| 117 |
return mix_chars((f=="" ? sprintf("%0256d", 0) : f), a[2], hexval(a[1])) |
| 118 |
} |
| 119 |
|
| 120 |
function mix_chars(f,c,x, h,k,l) { |
| 121 |
for (k=1; k<=length(c); k++) { |
| 122 |
h=hb[substr(c,k,1)] |
| 123 |
for (l=1; l<=length(h); l++) |
| 124 |
if (substr(h,l,1)=="1") f=substr(f,1,x+4*k+l-5) "1" substr(f,x+4*k+l-3) |
| 125 |
} |
| 126 |
return f |
| 127 |
} |
| 128 |
|
| 129 |
function out_chars(f, i,j,k,g) { |
| 130 |
while ((i<256) && (substr(f,i,1)=="0")) ++i |
| 131 |
g="" |
| 132 |
for (j=i; j<=length(f); j+=4) { |
| 133 |
k=sprintf("%-4s", substr(f,j,4)); gsub(/ /,"0",k); g=g bh[k] |
| 134 |
} |
| 135 |
sub (/0+$/,"",g) |
| 136 |
return sprintf("%02X", (i-1)) ":" g |
| 137 |
} |
| 138 |
|
| 139 |
function is_lineto() { |
| 140 |
return ($0~/^-?[0-9\.]+ -?[0-9\.]+ lineto$/) |
| 141 |
} |
| 142 |
|
| 143 |
function is_curveto() { |
| 144 |
return ($0~/^-?[0-9\.]+ -?[0-9\.]+ -?[0-9\.]+ -?[0-9\.]+ -?[0-9\.]+ -?[0-9\.]+ curveto$/) |
| 145 |
} |
| 146 |
|
| 147 |
function IncludeEPS(i, comments, s) { |
| 148 |
print "%BeginInclude" |
| 149 |
print "MEPSDict begin /MEPSSave save def gsave" |
| 150 |
print "count /MEPSocount exch def /MEPSdcount countdictstack def" |
| 151 |
print "/showpage {} def /erasepage {} def /copypage {} def" |
| 152 |
print "/letter {} def /note {} def /a4 {} def /legal {} def" |
| 153 |
printf ("[ %f %f %f %f %f %f ] matrix invertmatrix\n", |
| 154 |
Ebbr[i]-Ebbl[i], 0, 0, Ebbu[i]-Ebbd[i], Ebbl[i], Ebbd[i]) |
| 155 |
printf ("[ %f %f %f %f %f %f ] matrix concatmatrix\n", |
| 156 |
Adrx-Adlx, Adry-Adly, Aulx-Adlx, Auly-Adly, Adlx, Adly) |
| 157 |
print "concat" |
| 158 |
print "0 setlinecap 0 setlinejoin 10 setmiterlimit [] 0 setdash" |
| 159 |
print "1 setlinewidth 0 setgray newpath" |
| 160 |
print "%StartInclude" |
| 161 |
# |
| 162 |
comments=1 |
| 163 |
while (getline s < Ename[i] >0) |
| 164 |
if ((s!~/^%[%!\*]/) || (comments==0)) { |
| 165 |
comments=0; gsub(/fshow/, "nshow", s); print s |
| 166 |
} |
| 167 |
close(Ename[i]) |
| 168 |
# |
| 169 |
print "%StopInclude" |
| 170 |
print "count MEPSocount sub {pop} repeat" |
| 171 |
print "countdictstack MEPSdcount sub {end} repeat" |
| 172 |
print "grestore MEPSSave restore end" |
| 173 |
print "%EndInclude" |
| 174 |
} |
| 175 |
|
| 176 |
|