summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-dvipdfmx.def
blob: 2077a2707b92f0a057a433593310041acc3a6082 (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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
% 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-dvipdfmx.def}

% Driver commands for dvipdfmx
%
% Modified by Jin-Hwan Cho <chofchof@ktug.or.kr> on April 18, 2009.
% This driver requires the version DVIPDFMX-20080605 that is contained
% in texlive 2008 or later.

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


% For unique object name:
\newcount\pgfsys@objnum\pgfsys@objnum\@ne

% `pdf:code' is an abbreviation of `pdf:literal direct', the idea of which
% came from pdfTeX's primitive \pdfliteral direct.
\def\pgfsys@invoke#1{\special{pdf:code #1}}

% If color is changed by \pgfsys@invoke explicitly, the color
% optimization routine in dvipdfmx does not work correctly
% because the routine checks color specials only. For example,
%
% \special{color push 0}\pgfsys@invoke{1 g 1 G}\special{color push 0}
%
% the last color special will be ignored the optimization routine
% thinks that the color has changed to the same color.
% To avoid this problem, we need to change the color temporarily to another.
%
% We assume that black is the default color when no color is specified.
\def\pgfsys@dvipdfmx@start@force@reset@color{%
  \special{pdf:bcolor [1]}%
  \special{pdf:bcolor [0]}%
}
\def\pgfsys@dvipdfmx@stop@force@reset@color{%
  \special{pdf:ecolor}%
  \special{pdf:ecolor}%
}


\def\pgfsys@dvipdfmx@suspendcontent{%
  \special{pdf:code q -1 0 0 -1 0 0 cm q}%
  \special{pdf: econtent}%
  \special{pdf: bcontent}%
  \special{pdf:code -1 0 0 -1 0 0 cm}%
  \special{pdf:code q}% translate to original system
  \special{pdf: econtent}%
}

\def\pgfsys@dvipdfmx@unsuspendcontent{%
  \special{pdf: bcontent}%
  \special{pdf:code Q Q Q}%
}

\def\pgfsys@hbox#1{%
  \pgfsys@begin@idscope%
  \pgfsys@beginscope%
    \setbox#1=\hbox{\box#1}%
    \wd#1=0pt%
    \ht#1=0pt%
    \dp#1=0pt%
    \pgfsys@dvipdfmx@suspendcontent%
    \pgfsys@invoke{0 J [] 0 d}% reset line cap and dash
    \pgfsys@dvipdfmx@start@force@reset@color%
    \box#1%
    \pgfsys@dvipdfmx@stop@force@reset@color%
    \pgfsys@dvipdfmx@unsuspendcontent%
  \pgfsys@endscope%
  \pgfsys@end@idscope%
}

% We cannot use many codes in pgfsys-common-pdf-via-dvi.def.
% So it is rewritten here (with some bugs fixed).
\def\pgfsys@hboxsynced#1{%
  \pgfsys@begin@idscope%
  \pgfsys@beginscope%
    \setbox#1=\hbox{\box#1}%
    \wd#1=0pt%
    \ht#1=0pt%
    \dp#1=0pt%
    \pgfsys@dvipdfmx@suspendcontent%
    \pgfsys@invoke{0 J [] 0 d}% reset line cap and dash
    \pgfsys@dvipdfmx@start@force@reset@color%
    \pgf@sys@bp@correct\pgf@pt@x%
    \pgf@sys@bp@correct\pgf@pt@y%
    \special{pdf:btrans matrix \pgf@pt@aa\space \pgf@pt@ab\space \pgf@pt@ba\space \pgf@pt@bb\space
      \pgf@sys@tonumber{\pgf@pt@x} \pgf@sys@tonumber{\pgf@pt@y}}%
    \box#1%
    \special{pdf:etrans}%
    \pgfsys@dvipdfmx@stop@force@reset@color%
    \pgfsys@dvipdfmx@unsuspendcontent%
  \pgfsys@endscope%
  \pgfsys@end@idscope%
}

% All text materials between `pdf:bcontent' and `pdf:econtent' are
% treated in the relative coordinate.
\def\pgfsys@beginpicture{\special{pdf:bcontent}}
\def\pgfsys@endpicture{\special{pdf:econtent}}

\def\pgfsys@imagesuffixlist{.pdf:.jpg:.jpeg:.png:.bmp:}

% Shaidng came from pgfsys-pdftex.def
\def\pgfsys@horishading#1#2#3{%
  {%
    \pgf@parsefunc{#3}%
    \pgfmathparse{#2}%
    \pgf@process{\pgfpoint{\pgf@max}{#2}}%
    \edef\@tempa{\noexpand\pgfutil@insertatbegincurrentpagefrombox{%
      \special{pdf:bxobj @pgfshade\the\pgfsys@objnum\space width \the\pgf@max\space height \pgfmathresult pt}%
      \special{pdf:put @resources
      <<
        /Shading << /Sh << /ShadingType 2
        /ColorSpace /DeviceRGB
        /Domain [\pgf@pdfparseddomain]
        /Coords [\pgf@doma\space0 \pgf@domb\space0]
        /Function \pgf@pdfparsedfunction
        /Extend [false false] >> >>
      >>}%
      \pgfsys@invoke{/Sh sh}%
      \special{pdf:exobj}}}\@tempa% <<
    \xdef\pgfutil@tempa{%
      \hbox to\the\pgf@max{\vbox to\pgfmathresult pt{\vfil\special{pdf:uxobj @pgfshade\the\pgfsys@objnum}}\hfil}}%
  }%
  \expandafter\let\csname @pgfshading#1!\endcsname=\pgfutil@tempa
  \global\advance\pgfsys@objnum\@ne%
}
\def\pgfsys@vertshading#1#2#3{%
  {%
    \pgf@parsefunc{#3}%
    \pgfmathparse{#2}%
    \pgf@process{\pgfpoint{\pgf@max}{#2}}%
    \edef\@tempa{\noexpand\pgfutil@insertatbegincurrentpagefrombox{%
      \special{pdf:bxobj @pgfshade\the\pgfsys@objnum\space width \pgfmathresult pt\space height \the\pgf@max}%
      \special{pdf:put @resources
      <<
        /Shading << /Sh << /ShadingType 2
        /ColorSpace /DeviceRGB
        /Domain [\pgf@pdfparseddomain]
        /Coords [0 \pgf@doma\space0 \pgf@domb]
        /Function \pgf@pdfparsedfunction
        /Extend [false false] >> >>
      >>}%
      \pgfsys@invoke{/Sh sh}%
      \special{pdf:exobj}}}\@tempa% <<
    \xdef\pgfutil@tempa{%
      \hbox to\pgfmathresult pt{\vbox to\the\pgf@max{\vfil\special{pdf:uxobj @pgfshade\the\pgfsys@objnum}}\hfil}}%
  }%
  \expandafter\let\csname @pgfshading#1!\endcsname=\pgfutil@tempa
  \global\advance\pgfsys@objnum\@ne%
}
\def\pgfsys@radialshading#1#2#3{%
  {%
    \pgf@parsefunc{#3}%
    \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}%
    \pgfutil@tempdima=2\pgf@max%
    \edef\@tempa{\noexpand\pgfutil@insertatbegincurrentpagefrombox{%
      \special{pdf:bxobj @pgfshade\the\pgfsys@objnum\space width \the\pgfutil@tempdima\space height \the\pgfutil@tempdima}%
      \special{pdf:put @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] >> >>
      >>}%
      \pgfsys@invoke{/Sh sh}%
      \special{pdf:exobj}}}\@tempa% <<
    \xdef\pgfutil@tempa{%
      \hbox to\the\pgfutil@tempdima{\vbox to\the\pgfutil@tempdima{\vfil\special{pdf:uxobj @pgfshade\the\pgfsys@objnum}}\hfil}}%
  }%
  \expandafter\let\csname @pgfshading#1!\endcsname=\pgfutil@tempa
  \global\advance\pgfsys@objnum\@ne%
}
\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%
    \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
    \edef\@tempa{\noexpand\pgfutil@insertatbegincurrentpagefrombox{%
      \special{pdf:stream @pgfstream\the\pgfsys@objnum\space({#4}) <</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]>>}}}\@tempa%
    \edef\@tempa{\noexpand\pgfutil@insertatbegincurrentpagefrombox{%
      \special{pdf:bxobj @pgfshade\the\pgfsys@objnum\space width \the\pgf@x\space height \the\pgf@y}%
      \special{pdf:put @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 @pgfstream\the\pgfsys@objnum>> >> >>}%
      \pgfsys@invoke{/Sh sh}%
      \special{pdf:exobj}}}\@tempa% <<
    \xdef\pgfutil@tempa{%
      \leavevmode\hbox to\the\pgf@x{\vbox to\the\pgf@y{\vfil\special{pdf:uxobj @pgfshade\the\pgfsys@objnum}}\hfil}}%
  }%
  \expandafter\let\csname @pgfshading#1!\endcsname=\pgfutil@tempa
  \global\advance\pgfsys@objnum\@ne%
}

% \pgf@sys@pdf@dvi@tracker was not touched!
\def\pgf@sys@pdf@dvi@tracker{
  \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{\pgfpointorigin}
}

% Resource management: bugs were fixed.
\newif\ifpgf@sys@pdf@colorspaces@exists
\newif\ifpgf@sys@pdf@patterns@exists
\newif\ifpgf@sys@pdf@extgs@exists
\newif\ifpgf@sys@pdf@colorspaces@created
\newif\ifpgf@sys@pdf@patterns@created
\newif\ifpgf@sys@pdf@extgs@created
\newif\ifpgf@sys@pdf@any@resources

\def\pgf@sys@setuppdfresources@plain{%
  % This command will setup pdf resource in plain and in latex
  % mode. ConTeXt has its own handler
  \pgfutil@insertatbegineverypage{%
    \pgf@sys@pdf@any@resourcesfalse%
    \ifpgf@sys@pdf@extgs@exists%
      \pgf@sys@pdf@any@resourcestrue%
      \ifpgf@sys@pdf@extgs@created\else\special{pdf:obj @pgfextgs <<>>}\global\pgf@sys@pdf@extgs@createdtrue\fi% <<
    \fi%
    \ifpgf@sys@pdf@colorspaces@exists%
      \pgf@sys@pdf@any@resourcestrue%
      \ifpgf@sys@pdf@colorspaces@created\else\special{pdf:obj @pgfcolorspaces <<>>}\global\pgf@sys@pdf@colorspaces@createdtrue\fi% <<
    \fi%
    \ifpgf@sys@pdf@patterns@exists%
      \pgf@sys@pdf@any@resourcestrue%
      \ifpgf@sys@pdf@patterns@created\else\special{pdf:obj @pgfpatterns <<>>}\global\pgf@sys@pdf@patterns@createdtrue\fi% <<
    \fi%
    \ifpgf@sys@pdf@any@resources%
      \special{pdf:put @resources
      <<
        \ifpgf@sys@pdf@extgs@exists /ExtGState @pgfextgs \fi
        \ifpgf@sys@pdf@patterns@exists /Pattern @pgfpatterns \fi
        \ifpgf@sys@pdf@colorspaces@exists /ColorSpace @pgfcolorspaces \fi
      >>}% <<
    \fi%
  }
  \def\pgf@sys@addpdfresource@extgs@plain##1{%
    \global\pgf@sys@pdf@extgs@existstrue%
    \pgfutil@insertatbegincurrentpage{\special{pdf:put @pgfextgs << ##1 >>}}% <<
  }
  \def\pgf@sys@addpdfresource@colorspaces@plain##1{%
    \global\pgf@sys@pdf@colorspaces@existstrue%
    \pgfutil@insertatbegincurrentpage{\special{pdf:put @pgfcolorspaces << ##1 >>}}% <<
  }
  \def\pgf@sys@addpdfresource@patterns@plain##1{%
    \global\pgf@sys@pdf@patterns@existstrue%
    \pgfutil@insertatbegincurrentpage{\special{pdf:put @pgfpatterns << ##1 >>}}% <<
  }
}
\pgfutil@setuppdfresources % possibly call the above

% As pgfsys-pdftex.def, the following code is required
% to give colors on pattern objects.
\pgfutil@addpdfresource@colorspaces{ /pgfprgb [/Pattern /DeviceRGB] }

% Image Mask came from pgfsys-pdftex.def
% generic/pgf/basiclayer/pgfcoreimage.code.tex must be modified!
\def\pgfsys@defineimage{% width, height, page number
  \ifx\includegraphics\undefined
    \ifx\pgf@imagewidth\pgfutil@empty\edef\pgf@imagewidth{1bp}\fi% width?
    \ifx\pgf@imageheight\pgfutil@empty\edef\pgf@imageheight{1bp}\fi% height?
    \ifx\pgf@imagepage\pgfutil@empty\else\edef\pgf@imagepage{ page \pgf@imagepage}\fi%
    \ifx\pgf@imageinterpolate\pgfutil@empty\else\edef\pgf@imageinterpolate{ /Interpolate\space\pgf@imageinterpolate}\fi%
    \ifx\pgf@imagemask\pgfutil@empty\else\xdef\pgf@imagemask{ /SMask @\pgf@imagemask}\fi%
    \edef\pgf@image{\noexpand\hbox to \pgf@imagewidth{\vbox to \pgf@imageheight{\vfil\special{pdf:image width \pgf@imagewidth\space height \pgf@imageheight\space\pgf@imagepage\space(\pgf@filename) <<\pgf@imageinterpolate\pgf@imagemask\space>>}}\hfil}}%
  \else
    \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\pgf@imageinterpolate\pgfutil@empty\else\edef\pgf@imageinterpolate{interpolate=\pgf@imageinterpolate,}\fi%
    \ifx\pgf@imagemask\pgfutil@empty\else\xdef\pgf@imagemask{mask=\pgf@imagemask,}\fi%
    \edef\pgf@image{\noexpand\includegraphics[\pgf@imageheight\pgf@imagewidth\pgf@imagepage\pgf@imageinterpolate\pgf@imagemask]{\pgf@filename}}%
  \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]}%
  \special{pdf:image @pgfmask\the\pgfsys@objnum\space hide (\pgf@filename) << \pgf@attr >>}%
  \edef\pgf@mask{pgfmask\the\pgfsys@objnum}%
  \global\advance\pgfsys@objnum\@ne%
}

% Patterns came from pgfsys-pdftex.def
% dvipdfmx provides a new special `pdf:stream' for a stream object.
\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:
  \pgfsys@dvipdfmx@patternobj{%
      \pgfsys@dvipdfmx@stream{@pgfpatternobject#1}{#8}{%
           /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 << >> %<<
      }%
  }%
  \pgfutil@addpdfresource@patterns{/pgfpat#1\space @pgfpatternobject#1}%
}

% hook for xdvipdfmx:
\def\pgfsys@dvipdfmx@patternobj#1{%
    #1%
}%

% hook for xdvipdfmx:
\def\pgfsys@dvipdfmx@stream#1#2#3{%
  \special{pdf:stream #1 (#2) << #3 >>}%
}%


\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}%
}

% Opacity masks (fadings) came from pgfsys-pdftex.def
%
% One problem was that the second argument of \pgfsys@fadingfrombox
% is a box so that \pgfutil@insertatbegincurrentpage cannot be used.
% So, the new command \pgfutil@insertatbegincurrentpagefrombox is written
% in generic/pgf/utilities/pgfutil-[context,latex,plain].def.
\def\pgfsys@fadingfrombox#1#2{%
  \expandafter\ifx\csname pgfsmaskxform@#1\endcsname\relax%
    {%
      \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}}}%
      \edef\@tempa{\noexpand\pgfutil@insertatbegincurrentpagefrombox{%
        \special{pdf:bxobj @pgfsmask\the\pgfsys@objnum\space%
          width \the\wd#2\space height \the\ht#2\space depth \the\dp#2}%
        \wd#2=0pt%
        \ht#2=0pt%
        \dp#2=0pt%
        \box#2%
        \special{pdf:put @resources
          <<
          \ifpgf@sys@pdf@extgs@exists /ExtGState @pgfextgs \fi
          \ifpgf@sys@pdf@patterns@exists /Pattern @pgfpatterns \fi
          \ifpgf@sys@pdf@colorspaces@exists /ColorSpace @pgfcolorspaces \fi
          >>}% <<
        \special{pdf:exobj <</Group <</S/Transparency /CS/DeviceGray>> >>}}}\@tempa%
      \expandafter\xdef\csname pgfsmaskxform@#1\endcsname{\the\pgfsys@objnum}%
    }%
    \global\advance\pgfsys@objnum\@ne%
  \fi%
}
\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 pgfsmask@#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 pgfsmaskxform@#1\endcsname\space gs}%
      }%
      \pgftransforminvert%
      \pgflowlevelsynccm%
    }%
  \fi
}
\def\pgf@sys@pdf@install@mask#1{%
  \pgfutil@addpdfresource@extgs{%
    /pgfsmask\csname pgfsmaskxform@#1\endcsname\space <<
      /SMask <<
        /S /Luminosity
        /G @pgfsmask\csname pgfsmaskxform@#1\endcsname
      >> >>}%<<
  \expandafter\let\csname pgfsmask@#1\endcsname\expandafter\csname pgfsmaskxform@#1\endcsname%
}

% Transparency groups came from pgfsys-pdftex.def
\def\pgfsys@transparencygroupfrombox#1{%
  {%
    \pgf@sys@bp@correct\pgf@picminx%
    \pgf@sys@bp@correct\pgf@picmaxx%
    \pgf@sys@bp@correct\pgf@picminy%
    \pgf@sys@bp@correct\pgf@picmaxy%
    \edef\@tempa{\noexpand\pgfutil@insertatbegincurrentpagefrombox{%
      \special{pdf:bxobj @pgftransgroup\the\pgfsys@objnum\space bbox \pgf@sys@tonumber\pgf@picminx\space\pgf@sys@tonumber\pgf@picminy\space\pgf@sys@tonumber\pgf@picmaxx\space\pgf@sys@tonumber\pgf@picmaxy}%
      \wd#1=0pt%
      \ht#1=0pt%
      \dp#1=0pt%
      \hskip\pgf@picminx bp\box#1\hskip-\pgf@picminx bp%
      \special{pdf:put @resources
      <<
        \ifpgf@sys@pdf@extgs@exists /ExtGState @pgfextgs \fi
        \ifpgf@sys@pdf@patterns@exists /Pattern @pgfpatterns \fi
        \ifpgf@sys@pdf@colorspaces@exists /ColorSpace @pgfcolorspaces \fi
      >>}% <<
      \special{pdf:exobj <</Group << /S /Transparency
    /I \ifpgfsys@transparency@group@isolated true \else false \fi
    /K \ifpgfsys@transparency@group@knockout true \else false \fi>> >>}%
    }}\@tempa%
    \special{pdf:uxobj @pgftransgroup\the\pgfsys@objnum}%
  }%
  \global\advance\pgfsys@objnum\@ne%
}

%
% Position tracking (needs pdftex >= 1.40.0-alpha-20051205 in dvi mode)
%
\ifx\pdfsavepos\@undefined
\else
  \pgf@sys@pdf@dvi@tracker
\fi

\def\pgfsys@papersize#1#2{%
%  \expandafter\gdef\expandafter\pgfsys@atbegindocument%%
%  \expandafter{\pgfsys@atbegindocument
    \special{papersize=#1,#2}%
%  }
}
\def\pgfsys@prepare@papersize#1#2{%
  \expandafter\gdef\expandafter\pgfsys@atbegindocument%%
  \expandafter{\pgfsys@atbegindocument
    \special{papersize=#1,#2}%
  }
}

\endinput

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