summaryrefslogtreecommitdiff
path: root/tex/context/base/mkii/spec-ps.mkii
blob: 02ec16453cb7f274b4075a3e1618cb9566aa2461 (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
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
%D \module
%D   [       file=spec-ps,
%D        version=1996.01.25,
%D          title=\CONTEXT\ Special Macros,
%D       subtitle=Adobe PostScript,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

%D \macros
%D   {dostartgraymode,dostopgraymode,
%D    dostartrgbcolormode,dostartcmykcolormode,dostartgraycolormode,dostopcolormode,
%D    dostartrotation,dostoprotation,
%D    dostartscaling,dostopscaling,
%D    dostartmirroring,dostopmirroring,
%D    dostartnegative,dostopnegative,
%D    dostartoverprint,dostopoverprint,
%D    doselectfirstpaperbin,
%D    doselectsecondpaperbin}
%D
%D This implementation is straightforward and can be used as
%D a default with postscript||drivers. We use \type{ps:} as
%D opening, because most drivers support this.

\startspecials[postscript]

\def\@@insertpostscriptliteral {ps: }
\def\@@insertpostscriptretain  {" }

\definespecial\dostartgraymode#1%
  {\special
     {\@@insertpostscriptliteral
        #1\space setgray}}

\definespecial\dostopgraymode
  {\special
     {\@@insertpostscriptliteral
        0 setgray}}

\definespecial\dostartrgbcolormode#1#2#3%
  {\special
     {\@@insertpostscriptliteral
        #1\space #2\space #3\space setrgbcolor}}

\definespecial\dostartcmykcolormode#1#2#3#4%
  {\special
     {\@@insertpostscriptliteral
        #1\space #2\space #3\space #4\space setcmykcolor}}

\definespecial\dostartgraycolormode#1%
  {\special
     {\@@insertpostscriptliteral
        #1\space setgray}}

\definespecial\dostopcolormode
  {\special
     {\@@insertpostscriptliteral
        0 setgray}}

\definespecial\doselectfirstpaperbin
  {\special
     {\@@insertpostscriptliteral
        statusdict begin 1 setpapertray end}}  % checken

\definespecial\doselectsecondpaperbin
  {\special
     {\@@insertpostscriptliteral
        statusdict begin 0 setpapertray end}}  % checken

\definespecial\dostartrotation#1% straight from the YandY manual
  {\special
     {\@@insertpostscriptliteral
        gsave currentpoint currentpoint translate
        \number#1\space\space rotate neg exch neg exch translate}}

\definespecial\dostoprotation
  {\special
     {\@@insertpostscriptliteral
        currentfont currentpoint grestore moveto setfont}}

\definespecial\dostartscaling#1#2% conforming the YandY manual
  {\special
     {\@@insertpostscriptliteral
        gsave currentpoint currentpoint translate
        #1\space #2\space scale neg exch neg exch translate}}

\definespecial\dostopscaling
  {\special
     {\@@insertpostscriptliteral
        currentfont currentpoint grestore moveto setfont}}

\definespecial\dostartmirroring % some translate and exch stuff from YandY
  {\special
     {\@@insertpostscriptliteral
        gsave currentpoint currentpoint translate
        [-1 0 0 1 0 0] concat neg exch neg exch translate}}

\definespecial\dostopmirroring
  {\special
     {\@@insertpostscriptliteral
        currentfont currentpoint grestore moveto setfont}}

\definespecial\dostartnegative
  {\special{\@@insertpostscriptliteral gsave {1 exch sub} settransfer}}

\definespecial\dostopnegative
  {\special{\@@insertpostscriptliteral grestore}}

\definespecial\dostartoverprint
  {\special{\@@insertpostscriptliteral true setoverprint}}

\definespecial\dostopoverprint
  {\special{\@@insertpostscriptliteral false setoverprint}}

\definespecial\dostartgraphicgroup
  {\special{\@@insertpostscriptliteral gsave}}

\definespecial\dostopgraphicgroup
  {\special{\@@insertpostscriptliteral grestore}}

%D \macros
%D   {doovalbox}
%D
%D This implementation is a mixture of several possible
%D implementations. We use some constants that may not be
%D changed. It took some time to find them, but these values
%D offer quite accurate results. The macro calls for
%D \type{\forgetall}, which resets indentation, skips and
%D \type{\everypar}.
%D
%D Because a stroke follows the line, we correct for half of
%D the linewidth. Furthermore we use scaling to overcome some
%D limitations in the precision ($<1$~sp) and to prevent
%D rounding errors. We also do some correction for large
%D values. We let PostScript compare some arguments with
%D \type{a b eq {action} fi}.
%D
%D The path is based on a macro of J.~Hefferon cs. We also
%D tried the D.~Salomon implementation, but this did not work
%D well, just like some other alternatives.

% #1 = width            #2 = height           #3 = depth
% #4 = linewidth        #5 = radius
% #5 = stroke (ja,nee)  #7 = fill (ja,nee)

\def\@@insertpostscriptliteral {ps: }
\def\@@insertpostscriptretain  {postscript } % unknown

\def\dosomeovalcalc#1#2#3%
  {\dimen2=#1%
   \advance\dimen2 #2%
   \PointsToBigPoints{\dimen2}#3}

\def\dosomeovalbox#1#2#3#4#5#6#7#8% variant not yet supported
  {\bgroup
   \dimen0=#4\divide\dimen0 2
   \dosomeovalcalc{0pt}{+\dimen0}\xmin
   \dosomeovalcalc{#1}{-\dimen0}\xmax
   \dosomeovalcalc{#2}{-\dimen0}\ymax
   \dosomeovalcalc{-#3}{+\dimen0}\ymin
   \dosomeovalcalc{#4}{0pt}\stroke
   \dosomeovalcalc{#5}{0pt}\radius
   \edef\dostroke{#6}%
   \edef\dofill{#7}%
   \setbox\nextbox\hbox
     {\ifnum\dostroke\dofill>0
        \special
          {\@@insertpostscriptretain
             gsave
               newpath
               \xmin\space \radius\space add \ymin\space moveto
               \xmax\space \ymin\space \xmax\space \ymax\space \radius\space arcto
               \xmax\space \ymax\space \xmin\space \ymax\space \radius\space arcto
               \xmin\space \ymax\space \xmin\space \ymin\space \radius\space arcto
               \xmin\space \ymin\space \xmax\space \ymin\space \radius\space arcto
               \xmin\space \radius\space add \ymin\space moveto
               16 {pop} repeat
               closepath
               (\dostroke) (1) eq
                 {\stroke\space 0 ne
                   {gsave
                     \stroke\space setlinewidth
                      stroke
                    grestore} if} if
               (\dofill) (1) eq
                 {fill} if
             grestore}%
      \fi}%
   \nextboxwd#1%
   \nextboxht#2%
   \nextboxdp#3%
   \flushnextbox
   \egroup}

%D The indirect call permits a (rather) dirty hack, needed
%D for \DVIPS\ support.

\definespecial\doovalbox
  {\dosomeovalbox}

%D \macros
%D   {dostartclipping,dostopclipping}
%D
%D These two specials are not yet working as expected.

\definespecial\dostartclipping#1#2#3%
  {\PointsToBigPoints{#2}\width
   \PointsToBigPoints{#3}\height
   \grabMPclippath{#1}{0}{\width}{\height}
     {0 0 moveto \width 0 lineto \width \height lineto 0 \height\space lineto}%
   \special
     {\@@insertpostscriptliteral\space
      save newpath \MPclippath\space closepath clip}}

\definespecial\dostopclipping
  {\special{\@@insertpostscriptliteral\space restore}}

%D Some MP stuff:

\definespecial\doinsertMPfile#1%
  {\doiffileelse{./#1}{\includeMPasEPS{./#1}}{\message{[MP #1]}}}

\stopspecials

\endinput