Debian Codegraph @

texmf-dist/metapost/epsincl/epsincl.mp

raw
1 %%% addto closefrom readfrom
2 % made in BOP s.c., [email protected]; public domain software
3 % history: 20.08.1999: ver. 0.1, pre-release
4 % 05.01.2000: ver. 0.2, first release
5
6 def verify_operator primary x = x if not x: expandafter gobble fi enddef;
7
8 if not verify_operator known closefrom "????????": % tricky, isn't it
9 % |closefrom| primitive is available in MP since ver. 0.64
10 def closefrom expr eps_name =
11 forever: exitif (readfrom eps_name)=EOF; endfor
12 enddef;
13 fi
14
15 % The structure |eps_data| is presumed to be local for a given figure.
16 % If the same outer picture is to be included in several figures, its
17 % header must be examined each time anew. This is necassary if we want
18 % to include EPS files generated by METAPOST; otherwise we would have
19 % to store the information about the fonts used in EPS files being
20 % included. Note that the possibility of multiple reading necessitates
21 % using the |closefrom| operator.
22
23 def ini_eps =
24 % The common construction |save eps_data| must not be used,
25 % because of implicit reference to |ini_eps| in |use_eps|.
26 numeric eps_data.used[\\];
27 string eps_data.name[\\];
28 pair eps_data.ll[\\], eps_data.ur[\\];
29 color eps_data.col[\\];
30 eps_data.num:=0; eps_data.col[eps_data.num]=(0, 1, .5);
31 enddef;
32
33 vardef fix_eps(expr eps_name) =
34 save i_, j_, k_, l_, n_;
35 i_:=0;
36 forever:
37 i_:=i_+1; exitif i_>eps_data.num; exitif eps_data.name[i_]=eps_name;
38 endfor
39 if i_<=eps_data.num: errmessage "EPS " & eps_name & " already fixed";
40 else:
41 forever:
42 string l_; % this improves string memory handling (why?)
43 l_:=readfrom eps_name; exitif l_=EOF;
44 if substring (0,14) of l_="%%BoundingBox:":
45 j_:=14;
46 for k_=1,2,3,4:
47 i_:=j_;
48 forever: % scan spaces
49 exitif (substring (i_,i_+1) of l_) <> " "; i_:=i_+1;
50 endfor
51 j_:=i_;
52 forever: % scan digits
53 exitif ((substring (j_,j_+1) of l_) = " ")
54 or ((substring (j_,j_+1) of l_) = "");
55 j_:=j_+1;
56 endfor
57 n_[k_]:=scantokens substring (i_,j_) of l_;
58 endfor;
59 elseif substring (0,7) of l_="%*Font:": special l_;
60 elseif substring (0,1) of l_<>"%":
61 expandafter exitif expandafter true expandafter; % avoid ``dangling'' fi
62 fi
63 endfor
64 eps_data.num:=eps_data.num+1;
65 eps_data.name[eps_data.num]:=eps_name;
66 if l_=EOF:
67 eps_data.used[eps_data.num]:=-1;
68 message "EPS file " & eps_name & " malformed or not found.";
69 else:
70 eps_data.used[eps_data.num]:=0;
71 eps_data.ll[eps_data.num]:=(n_1, n_2);
72 eps_data.ur[eps_data.num]:=(n_3, n_4);
73 eps_data.col[eps_data.num]:=eps_data.col0+1/1000eps_data.num*(1, -1,0);
74 fi
75 closefrom eps_name;
76 fi
77 enddef;
78
79 vardef use_eps(expr eps_name) =
80 if unknown eps_data.num: ini_eps; fi
81 save currentpicture; picture currentpicture; currentpicture:=nullpicture;
82 save i_; i_:=0;
83 forever:
84 i_:=i_+1;
85 exitif i_>eps_data.num;
86 exitif eps_data.name[i_]=eps_name;
87 endfor
88 if i_>eps_data.num: fix_eps(eps_name); fi
89 % invariant: |(eps_data.name[i_]=eps_name) && known eps_data.used[i_]|
90 if eps_data.used[i_]>=0: % fixing was successful
91 fill unitsquare
92 xscaled xpart(eps_data.ur[i_]-eps_data.ll[i_])
93 yscaled ypart(eps_data.ur[i_]-eps_data.ll[i_])
94 withcolor eps_data.col[i_];
95 if eps_data.used[i_]=0:
96 special "%EPS "
97 & decimal(redpart(eps_data.col[i_])) & " "
98 & decimal(greenpart(eps_data.col[i_])) & " "
99 & decimal(bluepart(eps_data.col[i_])) & " "
100 & eps_name & " "
101 & decimal(xpart(eps_data.ll[i_])) & " "
102 & decimal(ypart(eps_data.ll[i_])) & " "
103 & decimal(xpart(eps_data.ur[i_])) & " "
104 & decimal(ypart(eps_data.ur[i_]));
105 eps_data.used[i_]:=1;
106 fi
107 currentpicture
108 else: % fixing failed (either missing file or bounding box not found)
109 nullpicture
110 fi
111 enddef;
112
113 extra_beginfig:=extra_beginfig & ";ini_eps;";
114
115 endinput;
116 %%\end