summaryrefslogtreecommitdiff
path: root/tex/context/base/supp-eps.tex
blob: ad16fd760e86726840276628fc1d895c004eef14 (plain)
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
%D \module
%D   [       file=supp-eps,
%D        version=1998.05.06,
%D          title=\CONTEXT\ Support Macros,
%D       subtitle=\EPS\ tools,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for 
%C details. 

\ifx \undefined \writestatus \input supp-mis.tex \relax \fi

%D The macros in this module are rather old and were originally
%D part of the figure inclusion macros. When \PDFTEX\ started
%D to support \PDF\ inclusion, where some accompanying macros
%D were put in \type{supp-pdf}, I considered it more suitable
%D to give the \EPS\ macros their own module. 

\writestatus{loading}{Context Support Macros / PDF}

%D \macros
%D   {dogetEPSboundingbox}
%D
%D The predecessors of the following macro's are derived from 
%D Thomas Rockicky's macro's. They are rewritten to a more 
%D compact form, made a bit more robust and also handle the 
%D \type{HiResBoundingBox} and \type{ExactBoundingBox} that 
%D are sometimes present.
%D
%D A bounding box has the form: 
%D
%D \starttypen
%D %%BoundingBox: llx lly urx ury 
%D \stoptypen
%D
%D Before we scan the file, we have to reset special 
%D characters and set some others. The percentage symbol also 
%D needs special treatment. When a bounding box is 
%D encountered, we keep on scanning until no more directives 
%D are found, i.e. a line is found that does not start with a 
%D percentage symbol. We also abort scanning after finding a 
%D high resolution bounding box. 
%D
%D This method also works inside verbatim mode (like when we 
%D are typesetting sources and putting eps coded logos into 
%D a heading. Temporary restoring the \CATCODES\ is done in 
%D the calling routine.  
%D
%D The creator as well as external support for specials are 
%D analyzed as well and their status is available in \type 
%D {\EPScreator} and \type {\EPSshading}. The boundingbox 
%D components are available in \type {\EPSllx} etc. 

\unprotect

\let\EPSllx\!!zeropoint \let\MPllx\EPSllx % just in case these 
\let\EPSlly\!!zeropoint \let\MPlly\EPSlly % are used while running 
\let\EPSurx\!!zeropoint \let\MPurx\EPSurx % in fast mode we set
\let\EPSury\!!zeropoint \let\MPury\EPSury % them to 0pt. 

\chardef\EPSfound=0 \chardef\EPScreator=0 \chardef\EPSspecial=0 

\def\dogetEPSboundingbox#1#2#3#4#5%
  {\bgroup
   \global\chardef\EPSfound=0
   \global\chardef\EPScreator=0 
   \global\chardef\EPSspecial=0
   \uncatcodespecials
   \def\doprocessEPSline%
     {\expandafter\checkEPSboundingbox\fileline:. \end}%
   \doprocessfile\scratchread{#1}\doprocessEPSline
   \egroup
   \ifnum\EPSfound>0
     #2=\EPSllx bp  % Using \EPSllx bp instead of 
     #4=\EPSurx bp  % \dimen0=1bp and \EPSllx\dimen0
     #3=\EPSlly bp  % is more accurate (.005pt). 
     #5=\EPSury bp 
     \scratchdimen=\EPSllx bp \advance#4 -\scratchdimen
     \scratchdimen=\EPSlly bp \advance#5 -\scratchdimen
   \else
     #2=\!!zeropoint
     #3=\!!zeropoint
     #4=\!!zeropoint
     #5=\!!zeropoint
   \fi
   \global\let\MPllx\EPSllx \global\let\MPlly\EPSlly
   \global\let\MPurx\EPSurx \global\let\MPury\EPSury}

\bgroup
\catcode`\%=\@@other
\global\let\EPSpercenttag   =%
\gdef\EPSboundingboxtag     {%BoundingBox}  
\gdef\EPShiresboundingboxtag{%HiResBoundingBox}  
\gdef\EPSexactboundingboxtag{%ExactBoundingBox}  
\gdef\EPScreatortag         {%Creator}  
\gdef\EPSmetaposttag        { MetaPost :. }  
\gdef\EPSmetapostspecialtag {%MetaPostSpecial}  
\egroup  

\long\def\checkEPSboundingbox#1#2:#3\end%
  {\ifx#1\EPSpercenttag
     \def\!!stringa{#2}%
     \ifx\!!stringa\EPScreatortag
       \edef\!!stringa{#3}%
       \global\chardef\EPScreator=\ifx\!!stringa\EPSmetaposttag1 \else0 \fi
     \else\ifx\!!stringa\EPSboundingboxtag
       \expandafter \getEPSboundingbox #3 . . . \end
       \global\chardef\EPSfound=1
     \else\ifx\!!stringa\EPShiresboundingboxtag
       \expandafter \getEPSboundingbox #3 . . . \end
       \global\chardef\EPSfound=2
       \dofinishfile
     \else\ifx\!!stringa\EPSexactboundingboxtag
       \expandafter \getEPSboundingbox #3 . . . \end
       \global\chardef\EPSfound=2
       \dofinishfile
     \else\ifx\!!stringa\EPSmetapostspecialtag % only before finish! 
       \global\chardef\EPSspecial=1
     \fi\fi\fi\fi\fi
   \else\ifnum\EPSfound>0
     \dofinishfile
   \fi\fi}

\def\getEPSboundingbox #1 #2 #3 #4 #5\end%
  {\gdef\EPSllx{#1}%
   \ifx\EPSllx\empty
     \getEPSboundingbox #2 #3 #4 #5 .\end
   \else
     \gdef\EPSlly{#2}%
     \gdef\EPSurx{#3}%
     \gdef\EPSury{#4}%
   \fi}

\protect 

\endinput