-
Notifications
You must be signed in to change notification settings - Fork 0
/
epsbox.sty
360 lines (316 loc) · 8.49 KB
/
epsbox.sty
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
%
% epsbox.sty
%
% These are the macros to include EPS file, based on NTT's "epsf.sty".
% Porting is made by Yuki Kusumi (Matsushita Electric Industrial Co., Ltd.),
% and now the facility of "epsf.sty" is available on ASCII JTeX/jdvi2kps v.2.1
% too. Note that specification of these macros are not completely compatible
% with that of "epsf.sty". One reason of this incompatibility is difference
% between the specification of dvi2ps and that of jdvi2kps, and the other is
% that we need to keep the compatibility with Neil Hunt's "postscript.sty".
%
% Oct. 1990
%
%
% EPSF macros by Kazuhiro Kazama and modified by Hideki ISOZAKI
% based on Trevor J. Darrell's psfig.tex
%
% pstex/postscript.sty are Copyright(c) 1989 Teleos Research, Inc 1989.
%
% All software, documentation, and related files in this distribution of
% psfig/tex are Copyright (c) 1987 Trevor J. Darrell
%
% Permission is granted for use and non-profit distribution of psfig/tex
% providing that this notice be clearly maintained, but the right to
% distribute any portion of psfig/tex for profit or as part of any commercial
% product is specifically reserved for the author.
%
\endlinechar=-1
\typeout{EPSbox version 1.7b for LaTeX/jdvi2kps2.1-3.0 (May 26, 1992)}
\typeout{Based on EPSF macro package. version 1.2 - Released July 16, 1990}
\newif\if@psdraft
\@ifundefined{eps@dummybox}{
\let\psdraft=\@psdrafttrue
\let\psfull=\@psdraftfalse
\psfull
\def\eps@dummybox#1#2#3{
\hbox{\offinterlineskip
\vrule
\vbox to #2{
\hrule
\vss
\hbox to #1{\hss #3\hss}
\vss
\hrule}
\vrule}}
}{}
\newdimen\@darg
\newdimen\eps@xdim
\newdimen\eps@ydim
\newdimen\eps@width
\newdimen\eps@height
\newdimen\eps@tempdima
\newdimen\eps@tempdimb
\newcount\eps@cnta
\newcount\eps@cntb
\newcount\eps@cntc
\newcount\eps@cntd
\newif\if@height
\newif\if@width
\newif\if@aspect
\newif\ifno@bb
\newif\ifno@psfile
\def\@setpsfile#1{
\def\@psfile{#1}
}
\def\@setpsheight#1{
\@heighttrue
\eps@height=#1\relax
}
\def\@setpswidth#1{
\@widthtrue
\eps@width=#1\relax
}
\def\@setpsscale#1{
\edef\@pshscale{#1}
\edef\@psvscale{#1}
}
\def\@setpshscale#1{
\edef\@pshscale{#1}
}
\def\@setpsvscale#1{
\edef\@psvscale{#1}
}
\def\@setpsaspect#1{
\@aspecttrue
\edef\@psaspect{#1}
}
\def\@setparms#1=#2,{\@nameuse{@setps#1}{#2}}
%
% initialize
%
\def\ps@init@parms{
\@heightfalse
\@widthfalse
\@aspectfalse
\no@bbfalse
\def\@psbbllx{}\def\@psbblly{}
\def\@psbburx{}\def\@psbbury{}
\def\@psheight{}\def\@pswidth{}
\def\@pshscale{1}\def\@psvscale{1}
\def\@psfile{}
\def\@sc{}
}
%
% Go through the options setting things up.
%
\def\parse@ps@parms#1{
\@for\@epsfile:=#1\do
{\expandafter\@setparms\@epsfile,}}
%
% Compute %%BoundingBox height and width
%
\newif\ifnot@eof
\newread\ps@stream
\def\bb@search{
\openin\ps@stream=\@psfile
\no@bbtrue
\not@eoftrue
\catcode`\%=12\relax
\ifeof\ps@stream
\def\eps@errmsg{EPS File \@psfile\space not found}
\no@psfiletrue
\else
\no@psfilefalse
\loop
\read\ps@stream to \line@in
\global\toks200=\expandafter{\line@in}\relax
\ifeof\ps@stream \not@eoffalse \fi
\@bbtest{\toks200}\relax
\if@bbmatch\expandafter\@bbatendtest\the\toks200\relax
\if@bbvalue\not@eoffalse\expandafter\bb@cull\the\toks200\fi
\fi
\ifnot@eof \repeat
\fi
\catcode`\%=14
}
\catcode`\%=12
\newif\if@bbmatch
\newif\if@bbvalue
\def\@bbtest#1{\expandafter\@a@\the#1%%BoundingBox:\@bbtest\@a@}
\long\def\@a@#1%%BoundingBox:#2#3\@a@{
\ifx\@bbtest#2\@bbmatchfalse\else\@bbmatchtrue\fi}
\def\bb@cull %%BoundingBox:{
\@ifnextchar\space{\@latexbug}{\bb@extract}}
\def\bb@extract #1 #2 #3 #4 {
\@darg=#1 bp\edef\@psbbllx{\number\@darg}
\@darg=#2 bp\edef\@psbblly{\number\@darg}
\@darg=#3 bp\edef\@psbburx{\number\@darg}
\@darg=#4 bp\edef\@psbbury{\number\@darg}
\no@bbfalse
}
\def\bb@atend{(atend)}
\def\@bbatendtest %%BoundingBox:{
\@ifnextchar\space{\@latexbug}{\bb@atextract}}
\def\bb@atextract #1 #2\relax{
\def\bb@tempa{#1}
\ifx\bb@tempa\bb@atend\@bbvaluefalse\else\@bbvaluetrue\fi}
\catcode`\%=14
\def\compute@bb{
\edef\@conflicttexfile{\@psfile.tex}
\immediate\openin\ps@stream=\@conflicttexfile\relax
% Caution! never remove \relax on the above line.
\edef\@psfile@root{\@psfile}
\ifeof\ps@stream\else
\global\edef\@psfile{\@[email protected]}
\fi
\bb@search
\ifno@bb% try .ps
\global\edef\@psfile{\@[email protected]}
\bb@search
\ifno@bb% try .eps
\global\edef\@psfile{\@[email protected]}
\bb@search
\ifno@bb% try .epsf
\global\edef\@psfile{\@[email protected]}
\bb@search
\fi
\fi
\fi
\ifno@bb
\ifno@psfile\else
\def\eps@errmsg{No BoundingBox on \@psfile}
\fi
\typeout{epsbox: \eps@errmsg}
\else
\eps@xdim=\@psbburx sp
\advance\eps@xdim by -\@psbbllx sp
\eps@ydim=\@psbbury sp
\advance\eps@ydim by -\@psbblly sp
\fi
}
\def\get@quotient#1#2{
\eps@cnta=#1\eps@cntb=#2\eps@cntc=\eps@cnta
\divide\eps@cntc by\eps@cntb
\edef\eps@quotient{\the\eps@cntc.}
\eps@cntd=5
\loop
\multiply\eps@cntc\eps@cntb
\advance\eps@cnta -\eps@cntc
\multiply\eps@cnta by 10
\eps@cntc\eps@cnta
\divide\eps@cntc by \eps@cntb
\edef\eps@quotient{\eps@quotient\the\eps@cntc}
\advance\eps@cntd by -1
\ifnum\eps@cntd>0
\repeat}
\def\compute@wfromh{
% computing : width = height * (bbw / bbh)
\if@aspect
\eps@width=\@psaspect\eps@height
\@aspectfalse
\else
\get@quotient{\number\eps@xdim}{\number\eps@ydim}
\eps@width=\eps@quotient\eps@height
\fi
}
\def\compute@hfromw{
% computing : height = width * (bbh / bbw)
\if@aspect
\eps@tempdima=1pt
\eps@tempdimb=\@psaspect pt\relax
\get@quotient{\number\eps@tempdima}{\number\eps@tempdimb}
\@aspectfalse
\else
\get@quotient{\number\eps@ydim}{\number\eps@xdim}
\fi
\eps@height=\eps@quotient\eps@width
}
\def\compute@handw{
\if@height
\if@width\else
\compute@wfromh
\fi
\else
\if@width
\compute@hfromw
\else
\eps@width=\eps@xdim
\eps@height=\eps@ydim
\fi
\fi
\eps@width=\@pshscale\eps@width
\eps@height=\@psvscale\eps@height
}
{\catcode`\p=12\catcode`\t=12
\gdef\remove@dim#1.#2pt{#1}}
% Compute any missing values
\def\compute@sizes{
\compute@bb
\ifno@bb\else
\compute@handw
\fi
}
%
%
% \postscriptbox{width}{height}{filename}
% \postscriptbox(width,height){filename}
%
\def\postscriptbox{\@ifnextchar ({\@postscriptpicbox}{\@postscriptbox}}
\def\@postscriptpicbox(#1,#2)#3{%
\@postscriptbox{#1\unitlength}{#2\unitlength}{#3}}
\def\@postscriptbox#1#2#3{% <width> <height> <file>
\eps@tempdima=\mag sp\relax
\eps@tempdimb=1000sp
\get@quotient{\number\eps@tempdima}{\number\eps@tempdimb}
\eps@xdim=#1\eps@ydim=#2
\eps@width=\eps@quotient\eps@xdim
\eps@height=\eps@quotient\eps@ydim
\leavevmode
\if@psdraft
\xdef\@@psfname{#3}
\eps@dummybox{\eps@xdim}{\eps@ydim}
{\vbox{\hbox{\viiipt\tt\expandafter\@psstringout
\meaning\@@psfname\relax}
\hbox{\viiipt\rm will be pasted}}}
\else
\vbox to \eps@ydim{\vss\hbox to \eps@xdim{%
\special{postscriptbox{\the\eps@width}{\the\eps@height}{#3}}%
\hss}}
\fi}
\def\@psstringout #1>#2\relax{#2}
%
%
% \epsfile{file=filename}
%
%
\def\epsfile#1{
\ps@init@parms
\parse@ps@parms{#1}
\compute@sizes
\ifno@bb\@epserrbox\else
\message{<\@psfile(\the\eps@width,\the\eps@height)>}
\if@aspect
\typeout{epsbox: Option "aspect" ignored.}
\fi
\@postscriptbox{\eps@width}{\eps@height}{\@psfile}\fi
}
\def\@epserrbox{
\fbox{\vbox to 1in{
\hsize=2in
\vfil
\hbox to 2in{
\vbox {\leftskip\z@\rightskip\z@
\centering\normalsize\sf\eps@errmsg}
}
\vfil}}
}
%
%
% \psbox[option list]{filename}
%
%
\def\@psbox[#1]#2{\epsfile{file=#2,#1}}
\def\psbox{\@ifnextchar[ {\@psbox}{\@psbox[scale=1]}}
\endlinechar=13\relax
\endinput