summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-pdftex.def
blob: 1e8df9b6628f08618d054eba0c397d65544fffda (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
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
% Copyright 2006 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

\ProvidesFileRCS{pgfsys-pdftex.def}


% Driver commands for pdf

%
% Load common pdf commands:
%
\input pgfsys-common-pdf.def

%
% pdftex-specific stuff:
%
\def\pgfsys@invoke#1{\pdfliteral{#1}}

% Synced hboxes
\def\pgfsys@hboxsynced#1{%
  {%
    \pgfsys@begin@idscope%
    \pgfsys@beginscope%
    \setbox\pgf@hbox=\hbox{%
      \hskip\pgf@pt@x%
      \raise\pgf@pt@y\hbox{%
        \pgf@pt@x=0pt%
        \pgf@pt@y=0pt%
        \pgflowlevelsynccm%
        \pgfsys@hbox#1}%
      \hss%
    }%
    \wd\pgf@hbox=0pt%
    \ht\pgf@hbox=0pt%
    \dp\pgf@hbox=0pt%
    \box\pgf@hbox%
    \pgfsys@endscope%
    \pgfsys@end@idscope%
  }%
}



\def\pgfsys@imagesuffixlist{.pdf:.jpg:.jpeg:.png:}
\def\pgfsys@defineimage{% width, height, page number
  \ifx\pgf@imagewidth\pgfutil@empty\else\edef\pgf@imagewidth{ width \pgf@imagewidth }\fi%
  \ifx\pgf@imageheight\pgfutil@empty\else\edef\pgf@imageheight{ height \pgf@imageheight }\fi%
  \ifx\pgf@imagepage\pgfutil@empty\else\edef\pgf@imagepage{ page \pgf@imagepage }\fi%
  \ifx\pdfximage\@undefined% old version of pdflatex
    \ifx\pgf@imagepage\pgfutil@empty\else%
      \pgfwarning{Page selection not supported. Ignoring page selection}%
    \fi%
    \setbox\pgfutil@tempboxa=\hbox{%
      \pdfimage \pgf@imageheight \pgf@imagewidth {\pgf@filename}}%
    \pdfform\pgfutil@tempboxa%
    \edef\pgf@image{\noexpand\pdfrefform\the\pdflastform}%
  \else% new version
    {\pdfximage \pgf@imageheight \pgf@imagewidth attr
      {/Interpolate \pgf@imageinterpolate\space\pgf@imagemask} \pgf@imagepage
      {\pgf@filename}}%
    \edef\pgf@image{\noexpand\pdfrefximage\the\pdflastximage}%
  \fi
}%
\def\pgfsys@definemask#1{%
  \ifx\pgf@maskmatte\pgfutil@empty%
  \else%
    \edef\pgf@maskmatte{/Matte [\pgf@maskmatte]}%
  \fi%
  \edef\pgf@attr{{\pgf@maskmatte\space /Decode [1 0]}}%
  \immediate\pdfximage attr \pgf@attr {\pgf@filename}%
  \edef\pgf@mask{/SMask \the\pdflastximage\space 0 R}%
}
\def\pgfsys@horishading#1#2#3{%
  {%
    \pgf@parsefunc{#3}%
    \pgfmathparse{#2}%
    \setbox\pgfutil@tempboxa=\hbox to\pgf@max{\vbox to\pgfmathresult pt{\vfil\pgfsys@invoke{/Sh sh}}\hfil}%
    \pgf@process{\pgfpoint{\pgf@max}{#2}}%
    \immediate\pdfxform resources {%
      /Shading << /Sh << /ShadingType 2
      /ColorSpace /DeviceRGB
      /Domain [\pgf@pdfparseddomain]
      /Coords [\pgf@doma\space0 \pgf@domb\space0]
      /Function \pgf@pdfparsedfunction
      /Extend [false false] >> >>}\pgfutil@tempboxa% <<
    \xdef\pgfutil@tempa{\leavevmode\noexpand\pdfrefxform\the\pdflastxform}%
  }%
  \expandafter\let\csname @pgfshading#1!\endcsname=\pgfutil@tempa
}
\def\pgfsys@vertshading#1#2#3{%
  {%
    \pgf@parsefunc{#3}%
    \pgfmathparse{#2}%
    \setbox\pgfutil@tempboxa=\hbox to\pgfmathresult pt{\vbox to\pgf@max{\vfil\pgfsys@invoke{/Sh sh}}\hfil}%
    \pgf@process{\pgfpoint{#2}{\pgf@max}}%
    \immediate\pdfxform resources {%
      /Shading << /Sh << /ShadingType 2
      /ColorSpace /DeviceRGB
      /Domain [\pgf@pdfparseddomain]
      /Coords [0 \pgf@doma\space0 \pgf@domb]
      /Function \pgf@pdfparsedfunction
      /Extend [false false] >> >>}\pgfutil@tempboxa% <<
    \xdef\pgfutil@tempa{\leavevmode\noexpand\pdfrefxform\the\pdflastxform}%
  }%
  \expandafter\let\csname @pgfshading#1!\endcsname=\pgfutil@tempa
}
\def\pgfsys@radialshading#1#2#3{%
  {%
    \pgf@parsefunc{#3}%
    \setbox\pgfutil@tempboxa=\hbox to2\pgf@max{\vbox to2\pgf@max{\vfil\pgfsys@invoke{/Sh sh}}\hfil}%
    \pgf@process{#2}%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{\pgfpoint{\pgf@max}{\pgf@max}}%
    \advance\pgf@xa by \pgf@x%
    \advance\pgf@ya by \pgf@y%
    \pgf@sys@bp@correct{\pgf@x}%
    \pgf@sys@bp@correct{\pgf@y}%
    \pgf@sys@bp@correct{\pgf@xa}%
    \pgf@sys@bp@correct{\pgf@ya}%
    \immediate\pdfxform resources {%
      /Shading << /Sh << /ShadingType 3
      /ColorSpace /DeviceRGB
      /Domain [\pgf@pdfparseddomain]
      /Coords [\pgf@sys@tonumber{\pgf@xa} \pgf@sys@tonumber{\pgf@ya} \pgf@doma\space \pgf@sys@tonumber{\pgf@x} \pgf@sys@tonumber{\pgf@y} \pgf@domb]
      /Function \pgf@pdfparsedfunction
      /Extend [true false] >> >>}\pgfutil@tempboxa% <<
    \xdef\pgfutil@tempa{\leavevmode\noexpand\pdfrefxform\the\pdflastxform}%
  }%
  \expandafter\let\csname @pgfshading#1!\endcsname=\pgfutil@tempa
}%
\def\pgfsys@functionalshading#1#2#3#4{%
  {%
    \pgf@process{#2}%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y%
    \pgf@process{#3}%
    \pgf@xb=\pgf@x%
    \pgf@yb=\pgf@y%
    \advance\pgf@x by-\pgf@xa%
    \advance\pgf@y by-\pgf@ya%
    \setbox\pgfutil@tempboxa=\hbox to\pgf@x{\vbox to\pgf@y{\vfil\pgfsys@invoke{/Sh sh}}\hfil}%
    \pgf@sys@bp@correct{\pgf@xa}%
    \pgf@sys@bp@correct{\pgf@ya}%
    \pgf@sys@bp@correct{\pgf@xb}%
    \pgf@sys@bp@correct{\pgf@yb}%
    \pgf@xc=-\pgf@xa%
    \pgf@yc=-\pgf@ya%
    % Now build the function
    \pdfobj
    stream
    attr
    {
      /FunctionType 4
      /Domain [\pgf@sys@tonumber{\pgf@xa}\space\pgf@sys@tonumber{\pgf@xb}\space\pgf@sys@tonumber{\pgf@ya}\space\pgf@sys@tonumber{\pgf@yb}]
      /Range [0 1 0 1 0 1]
    }
    {{#4}}%
    \edef\pgf@temp@num{\the\pdflastobj}%
    \pdfxform resources {%
      /Shading << /Sh << /ShadingType 1
      /ColorSpace /DeviceRGB
      /Matrix [1 0 0 1 \pgf@sys@tonumber{\pgf@xc}\space\pgf@sys@tonumber{\pgf@yc}]
      /Domain [\pgf@sys@tonumber{\pgf@xa}\space\pgf@sys@tonumber{\pgf@xb}\space\pgf@sys@tonumber{\pgf@ya}\space\pgf@sys@tonumber{\pgf@yb}]
      /Function \pgf@temp@num\space 0 R
      >> >>}\pgfutil@tempboxa% <<
    \xdef\pgfutil@tempa{%
      \leavevmode%
      \noexpand\pdfrefxform\the\pdflastxform%
      \noexpand\pdfrefobj\pgf@temp@num%
    }%
  }%
  \expandafter\let\csname @pgfshading#1!\endcsname=\pgfutil@tempa
}



% Patterns

\def\pgfsys@declarepattern#1#2#3#4#5#6#7#8#9{%
  % Start building the pattern dictionary:
  \pgf@xa=#2\relax%
  \pgf@ya=#3\relax%
  \pgf@xb=#4\relax%
  \pgf@yb=#5\relax%
  \pgf@xc=#6\relax%
  \pgf@yc=#7\relax%
  \pgf@sys@bp@correct\pgf@xa%
  \pgf@sys@bp@correct\pgf@ya%
  \pgf@sys@bp@correct\pgf@xb%
  \pgf@sys@bp@correct\pgf@yb%
  \pgf@sys@bp@correct\pgf@xc%
  \pgf@sys@bp@correct\pgf@yc%
  % Now create the pattern object:
  \immediate\pdfobj stream
  attr
  {
    /Type /Pattern
    /PatternType 1
    /PaintType \ifnum#9=0 2 \else 1 \fi
    /TilingType 1
    /BBox [\pgf@sys@tonumber\pgf@xa\space\pgf@sys@tonumber\pgf@ya\space\pgf@sys@tonumber\pgf@xb\space\pgf@sys@tonumber\pgf@yb]
    /XStep \pgf@sys@tonumber\pgf@xc\space
    /YStep \pgf@sys@tonumber\pgf@yc\space
    /Resources << >> %<<
  }
  {#8}%
  \pgfutil@addpdfresource@patterns{/pgfpat#1\space \the\pdflastobj\space 0 R}%
}

\def\pgfsys@setpatternuncolored#1#2#3#4{%
  \pgfsysprotocol@literal{/pgfprgb cs #2 #3 #4 /pgfpat#1\space scn}%
}

\def\pgfsys@setpatterncolored#1{%
  \pgfsysprotocol@literal{/Pattern cs /pgfpat#1\space scn}%
}

% System layer for meta patterns
% Takes 15(!) arguments
% #1    pattern name
% #2 #3 bounding box lower left
% #4 #5 bounding box upper right
% #6 #7 tile size
% #8 #9 #10 #11 #12 #13 transformation matrix
% #14   protocoled text
% #15   pattern type
\def\pgfsys@declarepattern@meta#1#2#3#4#5#6#7{%
  % Start building the pattern dictionary:
  \pgf@xa=#2\relax%
  \pgf@ya=#3\relax%
  \pgf@xb=#4\relax%
  \pgf@yb=#5\relax%
  \pgf@xc=#6\relax%
  \pgf@yc=#7\relax%
  \pgf@sys@bp@correct\pgf@xa%
  \pgf@sys@bp@correct\pgf@ya%
  \pgf@sys@bp@correct\pgf@xb%
  \pgf@sys@bp@correct\pgf@yb%
  \pgf@sys@bp@correct\pgf@xc%
  \pgf@sys@bp@correct\pgf@yc%
  \pgfsys@@declarepattern@meta{#1}}

\def\pgfsys@@declarepattern@meta#1#2#3#4#5#6#7#8#9{%
   \pgfutil@tempdima=#6\relax%
   \pgfutil@tempdimb=#7\relax%
   \pgf@sys@bp@correct\pgf@xa%
   \pgf@sys@bp@correct\pgf@ya%
   % Now create the pattern object:
   \immediate\pdfobj stream
   attr
   {
     /Type /Pattern
     /PatternType 1
     /PaintType \ifnum#9=0 2 \else 1 \fi
     /TilingType 1
     /BBox [\pgf@sys@tonumber\pgf@xa\space\pgf@sys@tonumber\pgf@ya\space\pgf@sys@tonumber\pgf@xb\space\pgf@sys@tonumber\pgf@yb]
     /XStep \pgf@sys@tonumber\pgf@xc\space
     /YStep \pgf@sys@tonumber\pgf@yc\space
     /Matrix [#2\space#3\space#4\space#5\space\pgf@sys@tonumber\pgfutil@tempdima\space\pgf@sys@tonumber\pgfutil@tempdimb]
     /Resources << >> %<<
   }
   {#8}%
   \pgfutil@addpdfresource@patterns{/pgfpat#1\space \the\pdflastobj\space 0 R}%
 }



\def\pgfsys@papersize#1#2{\pdfpageheight#2\relax\pdfpagewidth#1\relax}

\def\pgfsys@global@papersize#1#2{\global\pdfpageheight#2\relax\global\pdfpagewidth#1\relax}

\ifx\paperheight\@undefined
  \def\pgfsys@thepageheight{\pdfpageheight}
  \def\pgfsys@thepagewidth{\pdfpagewidth}
\fi


%
% Position tracking
%
\def\pgfsys@markposition#1{%
  \pdfsavepos%
  \edef\pgf@temp{#1}%
  \expandafter\pgfutil@writetoaux\expandafter{%
    \expandafter\noexpand\expandafter\pgfsyspdfmark\expandafter{\pgf@temp}{\the\pdflastxpos}{\the\pdflastypos}}%
}

\def\pgfsyspdfmark#1#2#3{%
  \expandafter\gdef\csname pgf@sys@pdf@mark@pos@#1\endcsname{\pgfqpoint{#2sp}{#3sp}}%
  \pgfutil@check@rerun{#1}{{#2}{#3}}%
}

\def\pgfsys@getposition#1#2{%
  \edef\pgf@marshal{\let\noexpand#2=\expandafter\noexpand\csname pgf@sys@pdf@mark@pos@#1\endcsname}%
  \pgf@marshal%
}

\def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfqpoint{\hoffset}{\voffset}}


%
% Opacity masks
%
\def\pgfsys@fadingfrombox#1#2{%
  {%
    \pgf@sys@pdf@check@resources%
    \pgf@x=-.5\wd#2%
    \pgf@y=-.5\ht#2%
    \advance\pgf@y by.5\dp#2%
    \expandafter\xdef\csname pgfsmasktrans@#1\endcsname{%
      \noexpand\pgftransformcm{1}{0}{0}{1}{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}%
    \pdfxform resources { \pgf@sys@pdf@possible@resources } #2%
    \expandafter\xdef\csname pgfsmaskxform@#1\endcsname{\the\pdflastxform}%
  }%
}
\def\pgfsys@usefading#1#2#3#4#5#6#7{%
  \expandafter\ifx\csname pgfsmaskxform@#1\endcsname\relax%
    \pgferror{Undefined fading '#1'}%
  \else%
    {%
      \expandafter\ifx\csname pgfsmaks@#1\endcsname\relax%
        \pgf@sys@pdf@install@mask{#1}%
      \fi%
      \pgftransformreset%
      \pgftransformcm{#2}{#3}{#4}{#5}{\pgfpoint{#6}{#7}}%
      \csname pgfsmasktrans@#1\endcsname%
      {%
        \pgflowlevelsynccm%
        \pgfsys@invoke{/pgfsmask\csname pgfsmask@#1\endcsname\space gs}%
      }%
      \pgftransforminvert%
      \pgflowlevelsynccm%
    }%
  \fi
}

\def\pgf@sys@pdf@install@mask#1{%
  \setbox\pgfutil@tempboxa=\hbox{\pdfrefxform\csname pgfsmaskxform@#1\endcsname}
  \immediate\pdfxform%
    attr {
    /Group
    <<
      /S /Transparency
      /CS /DeviceGray
    >>
  }% <<
  \pgfutil@tempboxa%
  \pgfutil@addpdfresource@extgs{%
    /pgfsmask\the\pdflastxform\space
    <<
      /SMask
      <<
        /S /Luminosity
        /G \the\pdflastxform\space 0 R
      >>
    >> } %<<
  \expandafter\xdef\csname pgfsmask@#1\endcsname{\the\pdflastxform}%
}

%
% Transparency groups
%
\def\pgfsys@transparencygroupfrombox#1{%
  \pgf@sys@pdf@check@resources%
  \pdfxform
  attr { /Group << /S /Transparency
    /I \ifpgfsys@transparency@group@isolated true \else false \fi
    /K \ifpgfsys@transparency@group@knockout true \else false \fi >> } %<<
  resources { \pgf@sys@pdf@possible@resources }
  #1%
  \setbox#1=\hbox{\pdfrefxform\pdflastxform}%
}




%
% Resource management
%

\def\pgf@sys@setuppdfresources@plain{%
  % This command will setup pdf resource in plain and in latex
  % mode. ConTeXt has its own handler
  % Page resources (they are kept in objects and only written at the
  % very end)
  \pdfobj reserveobjnum \edef\pgf@sys@pdf@extgs@objnum{\the\pdflastobj}
  \pdfobj reserveobjnum \edef\pgf@sys@pdf@pattern@objnum{\the\pdflastobj}
  \pdfobj reserveobjnum \edef\pgf@sys@pdf@colrospaces@objnum{\the\pdflastobj}
  \def\pgf@sys@pdf@possible@resources{%
    /ColorSpace \pgf@sys@pdf@colrospaces@objnum\space 0 R
    /Pattern    \pgf@sys@pdf@pattern@objnum\space 0 R
    /ExtGState  \pgf@sys@pdf@extgs@objnum\space 0 R
  }
  \let\pgf@sys@pdf@check@resources=\relax%
  \def\pgf@sys@pdf@install@pageresources{
    {
      \edef\temp{
        \pgf@sys@pdf@possible@resources
      }
      \expandafter\global\expandafter\pdfpageresources\expandafter{\temp}
    }
  }
  \pgf@sys@pdf@install@pageresources
  \expandafter\pgfutil@everybye\expandafter{%
    \the\pgfutil@everybye%
    \immediate \pdfobj useobjnum \pgf@sys@pdf@extgs@objnum {<<\pgf@sys@pgf@resource@list@extgs>>}%<<
    \immediate \pdfobj useobjnum \pgf@sys@pdf@pattern@objnum {<<\pgf@sys@pgf@resource@list@patterns>>}%<<
    \immediate \pdfobj useobjnum \pgf@sys@pdf@colrospaces@objnum {<<\pgf@sys@pgf@resource@list@colorspaces>>}%<<
  }
  \let\pgf@sys@pgf@resource@list@extgs=\pgfutil@empty%
  \let\pgf@sys@pgf@resource@list@patterns=\pgfutil@empty%
  \let\pgf@sys@pgf@resource@list@colorspaces=\pgfutil@empty%
  \def\pgf@sys@addpdfresource@extgs@plain##1{\xdef\pgf@sys@pgf@resource@list@extgs{\pgf@sys@pgf@resource@list@extgs\space##1}}
  \def\pgf@sys@addpdfresource@patterns@plain##1{\xdef\pgf@sys@pgf@resource@list@patterns{\pgf@sys@pgf@resource@list@patterns\space##1}}
  \def\pgf@sys@addpdfresource@colorspaces@plain##1{\xdef\pgf@sys@pgf@resource@list@colorspaces{\pgf@sys@pgf@resource@list@colorspaces\space##1}}
}
\pgfutil@setuppdfresources % possibly call the above

\pgfutil@addpdfresource@colorspaces{ /pgfprgb [/Pattern /DeviceRGB] }

\def\pgfsys@color@unstacked#1{%
    \pdfliteral{\csname\string\color@#1\endcsname}%
}

\endinput


%%% Local Variables:
%%% mode: latex
%%% End: