Debian Codegraph @

texmf-dist/tex/generic/pgf/utilities/pgfutil-context.def

raw
1 % Copyright 2019 by Till Tantau
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Public License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9 %
10 % Adapted for colors and pdf resources by Hans Hagen. There can be a few more
11 % optimizations but they are not critital.
12
13 \pgfutil@format@is@contexttrue
14
15
16 % The aux files, needed for reading back coordinates
17 \def\pgfutil@aux@read@hook{%
18 \pgfutil@IfFileExists{\jobname.pgf}{\input \jobname.pgf\relax}{}
19 \csname newwrite\endcsname\pgfutil@auxout
20 \immediate\csname openout\endcsname\pgfutil@auxout\jobname.pgf\relax
21 }
22 \def\pgfutil@writetoaux#1{\write\pgfutil@auxout{#1}}
23
24 % XColor-like support for ConTeXt
25
26 \def\pgfutil@definecolor#1#2#3{\csname pgfutil@emu@#2\endcsname{#1}#3\@nil}
27
28 \def\pgfutil@emu@rgb#1#2,#3,#4\@nil{\expandafter\def\csname\string\color@#1\endcsname{\xcolor@{}{}{rgb}{#2,#3,#4}}}
29 \def\pgfutil@emu@gray#1#2\@nil{\expandafter\def\csname\string\color@#1\endcsname{\xcolor@{}{}{gray}{#2}}}
30 \def\pgfutil@emu@cmyk#1#2,#3,#4,#5\@nil{\expandafter\def\csname\string\color@#1\endcsname{\xcolor@{}{}{cmyk}{#2,#3,#4,#5}}}
31 \def\pgfutil@emu@RGB#1#2,#3,#4\@nil{%
32 \begingroup
33 \pgfmathdivide@{#2}{255}\let\pgfutil@emu@RGB@r\pgfmathresult
34 \pgfmathdivide@{#3}{255}\let\pgfutil@emu@RGB@g\pgfmathresult
35 \pgfmathdivide@{#4}{255}\let\pgfutil@emu@RGB@b\pgfmathresult
36 \edef\pgf@marshal{\def\expandafter\noexpand\csname\string\color@#1\endcsname{%
37 \noexpand\xcolor@{}{}{rgb}{\pgfutil@emu@RGB@r,\pgfutil@emu@RGB@g,\pgfutil@emu@RGB@b}}}%
38 \expandafter\endgroup\pgf@marshal
39 }
40
41
42 % no need for x colors (users can load it if needed)
43 %\pgfutil@definecolor{white}{gray}{1}
44 %\pgfutil@definecolor{black}{gray}{0}
45 %\pgfutil@definecolor{gray}{gray}{0.5}
46 %\pgfutil@definecolor{red}{rgb}{1,0,0}
47 %\pgfutil@definecolor{green}{rgb}{0,1,0}
48 %\pgfutil@definecolor{blue}{rgb}{0,0,1}
49 %\pgfutil@definecolor{cyan}{rgb}{0,1,1}
50 %\pgfutil@definecolor{magenta}{rgb}{1,0,1}
51 %\pgfutil@definecolor{yellow}{rgb}{1,1,0}
52 %\pgfutil@definecolor{orange}{rgb}{1,0.5,0}
53 %\pgfutil@definecolor{violet}{rgb}{0.5,0,0.5}
54 %\pgfutil@definecolor{purple}{rgb}{0.75,0,0.25}
55 %\pgfutil@definecolor{brown}{rgb}{0.75,0.5,0.25}
56
57 \def\pgfutil@color#1{%
58 \pgfutil@colorlet{.}{#1}%
59 \pgfsysprotocol@getcurrentprotocol\pgfutil@emu@temp%
60 {%
61 \pgfsysprotocol@setcurrentprotocol\pgfutil@empty%
62 \pgfsysprotocol@bufferedtrue%
63 \pgfsetcolor{.}%
64 \expandafter\pgfsys@outerinvoke\expandafter{\pgfsysprotocol@currentprotocol}%
65 }%
66 \pgfsysprotocol@setcurrentprotocol\pgfutil@emu@temp%
67 \aftergroup\pgfutil@reset@color%
68 }
69
70 \def\pgfutil@extractcolorspec#1#2{%
71 \def#2{{#1}}%
72 }
73
74 \def\pgfutil@convertcolorspec#1#2#3{%
75 \edef#3{\expandafter\expandafter\expandafter\pgfutil@emu@select\csname\string\color@#1\endcsname}%
76 }
77
78 \def\pgfutil@doifcolorelse#1#2#3{%
79 \expandafter\ifx\csname\string\color@#1\endcsname\relax%
80 \doifcolorelse{#1}{\let\pgf@next=\pgfutil@firstoftwo}{\let\pgf@next=\pgfutil@secondoftwo}%
81 \else
82 \let\pgf@next=\pgfutil@firstoftwo%
83 \fi%
84 \pgf@next{#2}{#3}%
85 }
86
87 \def\pgfutil@reset@color{%
88 \pgfsysprotocol@getcurrentprotocol\pgfutil@emu@temp%
89 {%
90 \pgfsysprotocol@setcurrentprotocol\pgfutil@empty%
91 \pgfsysprotocol@bufferedtrue%
92 \pgfsetcolor{.}%
93 \expandafter\pgfsys@outerinvoke\expandafter{\pgfsysprotocol@currentprotocol}%
94 }%
95 \pgfsysprotocol@setcurrentprotocol\pgfutil@emu@temp%
96 }
97
98 \expandafter\def\csname\string\color@.\endcsname{\xcolor@{}{}{rgb}{0,0,0}}
99
100 \def\pgfutil@colorlet#1#2{%
101 \edef\pgf@marshal{#2}%
102 \expandafter\pgfutil@in@\expandafter!\expandafter{\pgf@marshal}%
103 \ifpgfutil@in@%
104 % compute mixture
105 {%
106 \expandafter\pgfutil@emu@mix\pgf@marshal!white!\@nil%
107 \xdef\pgf@marshal{\noexpand\def\expandafter\noexpand\csname\string\color@#1\endcsname{%
108 \noexpand\xcolor@{}{}{rgb}{\pgf@sys@tonumber\pgf@xa,\pgf@sys@tonumber\pgf@xb,\pgf@sys@tonumber\pgf@xc}}}%
109 }%
110 \pgf@marshal%
111 \else%
112 \expandafter\ifx\csname\string\color@#2\endcsname\relax%
113 \pgfutil@registercolor{#2}%
114 \fi%
115 \edef\pgf@marshal{\noexpand\let\expandafter\noexpand\csname\string\color@#1\endcsname=%
116 \expandafter\noexpand\csname\string\color@#2\endcsname}%
117 \pgf@marshal%
118 \fi%
119 }
120
121 \def\pgfutil@emu@mix#1!#2!#3!#4\@nil{%
122 \expandafter\ifx\csname\string\color@#1\endcsname\relax%
123 \pgfutil@registerrgb{#1}%
124 \fi%
125 \expandafter\ifx\csname\string\color@#3\endcsname\relax%
126 \pgfutil@registerrgb{#3}%
127 \fi%
128 \expandafter\expandafter\expandafter\pgfutil@emu@unpack\csname\string\color@#1\endcsname%
129 \pgf@ya=\pgf@xa%
130 \pgf@yb=\pgf@xb%
131 \pgf@yc=\pgf@xc%
132 \expandafter\expandafter\expandafter\pgfutil@emu@unpack\csname\string\color@#3\endcsname%
133 \c@pgf@counta=#2\relax%
134 \c@pgf@countb=100\relax%
135 \advance\c@pgf@countb by-\c@pgf@counta\relax%
136 \pgf@xa=\c@pgf@countb\pgf@xa%
137 \advance\pgf@xa by\c@pgf@counta\pgf@ya%
138 \divide\pgf@xa by 100\relax%
139 \pgf@xb=\c@pgf@countb\pgf@xb%
140 \advance\pgf@xb by\c@pgf@counta\pgf@yb%
141 \divide\pgf@xb by 100\relax%
142 \pgf@xc=\c@pgf@countb\pgf@xc%
143 \advance\pgf@xc by\c@pgf@counta\pgf@yc%
144 \divide\pgf@xc by 100\relax%
145 }
146
147 \def\pgfutil@emu@unpack#1#2#3#4#5{%
148 \pgfutil@emu@@unpack#5\@nil%
149 }
150
151 \def\pgfutil@emu@@unpack#1,#2,#3\@nil{%
152 \pgf@xa=#1pt%
153 \pgf@xb=#2pt%
154 \pgf@xc=#3pt%
155 }
156
157 \def\pgfutil@emu@select#1#2#3#4#5{#5}
158
159 \def\XC@tgt@mod#1{#1}
160 \def\XC@sdef#1#2{\edef#1{#2}}
161 \def\XC@mod@cmyk{cmyk}
162 \def\XC@mod@rgb{rgb}
163
164 % goody
165
166 \let\colorlet=\pgfutil@colorlet
167
168 % latex stuff
169
170 \newskip\pgfutil@flushglue
171 \pgfutil@flushglue=0pt plus 1fil
172
173
174 % pgfutil@minipage
175
176 \def\pgfutil@minipage[#1]#2{%
177 \hbox to#2\bgroup
178 \hsize=#2\relax
179 \vbox\bgroup
180 \noindentation
181 }
182
183 \def\pgfutil@endminipage{%
184 \egroup
185 \egroup
186 }
187
188 % global colors
189
190 \let\pgfutil@globalcolorsfalse\relax
191 \let\pgfutil@globalcolorstrue \relax
192
193 % font stuff
194
195 \def\pgfutil@font@tiny {\tfxx}
196 \def\pgfutil@font@scriptsize {\tfxx}
197 \def\pgfutil@font@footnotesize{\tfx}
198 \def\pgfutil@font@small {\tfx}
199 \def\pgfutil@font@normalsize {\tf}
200 \def\pgfutil@font@large {\tfa}
201 \def\pgfutil@font@Large {\tfb}
202 \def\pgfutil@font@huge {\tfc}
203 \def\pgfutil@font@Huge {\tfc}
204 \def\pgfutil@font@itshape {\it}
205 \def\pgfutil@font@bfseries {\bf}
206 \def\pgfutil@font@normalfont {\tf}
207 \def\pgfutil@selectfont {\tf}
208
209 % registers
210
211 \newcount\pgfutil@tempcnta
212 \newcount\pgfutil@tempcntb
213
214 \newbox \pgfutil@tempboxa
215
216 \newbox \pgfutil@voidb@x
217 \newtoks \pgfutil@toks@
218
219 \let\pgfmath@tempdima\pgfutil@tempdima
220 \let\pgfmath@tempdima\pgfutil@tempdima
221 \let\pgfmath@tempcnta\pgfutil@tempcnta
222 \let\pgfmath@tempcntb\pgfutil@tempcntb
223
224 % module stuff
225
226 \def\pgfutil@usemodule#1{\usemodule[#1]}
227
228 % more adaptions
229
230 \let\pgfutil@insertatbegincurrentpagefrombox\flushatshipout
231 \let\pgfutil@insertatbegincurrentpage \flushatshipout
232 \def\pgfutil@insertatbegineverypage #1{\appendtoks#1\to\everyshipout} % space removed after #1
233
234 \let\pgfutil@setuppdfresources \relax
235
236 \doifmodeelse {mkiv} {
237
238 \def\pgfutil@guessdriver{\def\pgfsysdriver{pgfsys-luatex.def}}
239
240 \def\pgfutil@driver@if@in#1#2{%
241 \edef\pgf@marshal{\noexpand\pgfutil@in@{#1}{\preloadedspecials}}%
242 \pgf@marshal
243 \ifpgfutil@in@
244 \def\pgfsysdriver{#2}%
245 \fi
246 }
247
248 \def\pgf@sys@pdf@pdfbackendset@one#1#2%
249 {\normalexpanded{\noexpand\pgf@sys@pdf@pdfbackendset@two\noexpand#1#2\relax}}
250
251 \def\pgf@sys@pdf@pdfbackendset@two#1/#2 #3\relax
252 {#1{#2}{#3}}
253
254 \def\pgf@sys@pdf@addtopageresource@pattern {\pgf@sys@pdf@pdfbackendset@one\pdfbackendsetpattern}
255 \def\pgf@sys@pdf@addtopageresource@colorspace{\pgf@sys@pdf@pdfbackendset@one\pdfbackendsetcolorspace}
256 \def\pgf@sys@pdf@addtopageresource@extgstate {\pgf@sys@pdf@pdfbackendset@one\pdfbackendsetextgstate}
257 \def\pgf@sys@pdf@possible@resources {\pdfbackendcurrentresources}
258 \def\pgf@sys@pdf@check@resources {}
259
260 \let\pgfutil@registercolor\pgf@context@registercolor
261 \let\pgfutil@registerrgb \pgf@context@registerrgb
262 \let\pgfutil@registercmyk \pgf@context@registercmyk
263 \let\pgfutil@registergray \pgf@context@registergray
264
265 } {
266 \def\pgf@sys@pdf@addtopageresource@extgstate {\appendtoPDFdocumentextgstates }
267 \def\pgf@sys@pdf@addtopageresource@colorspace {\appendtoPDFdocumentcolorspaces}
268 \def\pgf@sys@pdf@addtopageresource@pattern {\appendtoPDFdocumentpatterns }
269 \def\pgf@sys@pdf@possible@resources {\currentPDFresources}
270 \def\pgf@sys@pdf@check@resources {}
271
272
273 \ifx\pdfoutput\undefined\newcount\pdfoutput\fi
274 \ifx\pdfoutput\relax \newcount\pdfoutput\fi
275
276 \def\pgfutil@guessdriver{
277 \ifx\XeTeXversion\@undefined
278 \ifx\preloadedspecials\@undefined%
279 \ifcase\pdfoutput%
280 \def\pgfsysdriver{pgfsys-dvips.def}%
281 \else%
282 \def\pgfsysdriver{pgfsys-pdftex.def}% pdfTeX & LuaTeX
283 \fi%
284 \else%
285 \pgfutil@driver@if@in{postscript}{pgfsys-dvips.def}
286 \pgfutil@driver@if@in{tpd}{pgfsys-pdftex.def}
287 \pgfutil@driver@if@in{dpm}{pgfsys-dvipdfm.def}
288 \pgfutil@driver@if@in{dpx}{pgfsys-dvipdfmx.def}
289 \pgfutil@driver@if@in{xetex}{pgfsys-xetex.def}
290 \ifx\pgfsysdriver\relax%
291 \PackageWarning{pgf}{I was not able to discern the driver, the
292 preloaded specials were \preloadedspecials. I am going to use
293 pgfsys-dvips.def}%
294 \def\pgfsysdriver{pgfsys-dvips.def}
295 \fi%
296 \fi
297 \else
298 \def\pgfsysdriver{pgfsys-xetex.def}% should be right
299 \fi
300 }
301
302 \def\pgfutil@driver@if@in#1#2{%
303 \edef\pgf@marshal{\noexpand\pgfutil@in@{#1}{\preloadedspecials}}%
304 \pgf@marshal
305 \ifpgfutil@in@
306 \def\pgfsysdriver{#2}%
307 \fi
308 }
309
310 % The cmyk part is from Joseph Wright.
311 % See tex.stackexchange.com/questions/27952/cmyk-context-colors-in-tikz
312 \def\pgfutil@registercolor#1{%
313 \edef\pgf@temp{\PDFcolor{#1}}%
314 \edef\pgf@marshal{\noexpand\pgfutil@in@{rg}{\pgf@temp}}%
315 \pgf@marshal
316 \ifpgfutil@in@
317 \expandafter\pgfutil@context@parse@rgb\pgf@temp\pgf@stop{#1}%
318 \else
319 \edef\pgf@marshal{\noexpand\pgfutil@in@{g}{\pgf@temp}}%
320 \pgf@marshal
321 \ifpgfutil@in@
322 \expandafter\pgfutil@context@parse@gray\pgf@temp\pgf@stop{#1}%
323 \else
324 \edef\pgf@marshal{\noexpand\pgfutil@in@{k}{\pgf@temp}}%
325 \pgf@marshal
326 \ifpgfutil@in@
327 \expandafter\pgfutil@context@parse@cmyk\pgf@temp\pgf@stop{#1}%
328 \else
329 \pgferror{Color #1 has an unsupported color model.}%
330 \pgfutil@definecolor{#1}{gray}{0}%
331 \fi
332 \fi
333 \fi
334 }
335
336 \def\pgfutil@context@parse@gray#1 g#2\pgf@stop#3{%
337 \pgfutil@definecolor{#3}{gray}{#1}
338 }
339
340 \def\pgfutil@context@parse@rgb#1 #2 #3 rg#4\pgf@stop#5{%
341 \pgfutil@definecolor{#5}{rgb}{#1,#2,#3}
342 }
343
344 \def\pgfutil@context@parse@cmyk#1 #2 #3 #4k#5\pgf@stop #6{%
345 \pgfutil@definecolor{#6}{cmyk}{#1,#2,#3,#4}%
346 }
347
348 \def\pgfutil@emu@cmyk#1#2,#3,#4,#5\@nil{%
349 \expandafter\def\csname\string\color@#1\endcsname
350 {\xcolor@{}{}{cmyk}{#2,#3,#4,#5}}%
351 }
352
353 \let\pgfutil@registerrgb \pgfutil@registercolor
354 \let\pgfutil@registercmyk \pgfutil@registercolor
355 \let\pgfutil@registergray \pgfutil@registercolor
356
357
358 }
359
360 \let\pgf@sys@addpdfresource@extgs@plain \pgf@sys@pdf@addtopageresource@extgstate
361 \let\pgf@sys@addpdfresource@patterns@plain \pgf@sys@pdf@addtopageresource@pattern
362 \let\pgf@sys@addpdfresource@colorspaces@plain\pgf@sys@pdf@addtopageresource@colorspace
363 \let\pgf@sys@pdf@check@resources@plain \pgf@sys@pdf@check@resources
364
365 \pgf@sys@addpdfresource@colorspaces@plain{/pgfprgb [/Pattern /DeviceRGB]}
366
367 % do something at the end of a job
368
369 \appendtoks \the\pgfutil@everybye \to \everybye
370
371 \long\def\AtBeginDocument#1{\appendtoks#1\to\everystarttext}%
372
373 % pgfcalendar uses translations
374
375 \def\pgfutil@translate#1{#1} % \translate works very different in ConTeXt
376
377 % e-TeX primitives and beyond
378
379 \let\pgfutil@protected\normalprotected
380 \let\pgfutil@unexpanded\normalunexpanded
381 % the check for the availability of \expanded primitive is done in pgfkeys
382 \let\pgfutil@expanded\normalexpanded
383
384 \endinput