summaryrefslogtreecommitdiff
path: root/graphics/pgf/base/tex/pgfsys-common-pdf-via-dvi.def
blob: 0678b188207fa140dc9e2cd90d8afcd491737ddc (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
% Copyright 2019 by Till Tantau
% CMYK and grayscale shadings adaptation copyright 2019 by David Purton
%
% 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-common-pdf-via-dvi.def}

% Common driver commands for all drivers that produce pdf via the
% detour of a dvi file

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

% Hboxes

\def\pgfsys@beginpurepicture{\special{pdf: content q}}


\def\pgfsys@imagesuffixlist{.pdf:.jpg:.jpeg:.png:}
\def\pgfsys@horishading#1#2#3{%
  {%
    \pgf@parsefunc{#3}%
    \pgf@process{\pgfpoint{\pgf@max}{#2}}%
    \edef\@temp{\noexpand\pgfutil@insertatbegincurrentpage{\special{pdf: beginxobj @pgfshade\the\pgfsys@objnum\space width \the\pgf@max\space height \the\pgf@y}}}\@temp%
    \edef\@temp{\noexpand\pgfutil@insertatbegincurrentpage{\special{pdf: put @resources <<
      /Shading << /Sh << /ShadingType 2
      /ColorSpace \pgf@shading@device\space
      /Domain [\pgf@pdfparseddomain]
      /Coords [\pgf@doma\space0 \pgf@domb\space0]
      /Function \pgf@pdfparsedfunction
      /Extend [false false] >> >> >>}}}\@temp% <<
      \pgfutil@insertatbegincurrentpage{\special{pdf: content /Sh sh}%
      \special{pdf: endxobj}}%
    \xdef\pgfutil@tempa{%
      \hbox to\the\pgf@max{\vbox to#2{\vfil\special{pdf: usexobj @pgfshade\the\pgfsys@objnum}}\hfil}}%
  }%
  \global\expandafter\let\csname @pgfshading#1!\endcsname=\pgfutil@tempa
  \global\advance\pgfsys@objnum\@ne
}
\def\pgfsys@vertshading#1#2#3{%
  {%
    \pgf@parsefunc{#3}%
    \pgf@process{\pgfpoint{\pgf@max}{#2}}%
    \edef\@temp{\noexpand\pgfutil@insertatbegincurrentpage{\special{pdf: beginxobj @pgfshade\the\pgfsys@objnum\space width \the\pgf@y\space height \the\pgf@max\space}}}\@temp%
    \edef\@temp{\noexpand\pgfutil@insertatbegincurrentpage{\special{pdf: put @resources <<
      /Shading << /Sh << /ShadingType 2
      /ColorSpace \pgf@shading@device\space
      /Domain [\pgf@pdfparseddomain]
      /Coords [0 \pgf@doma\space0 \pgf@domb]
      /Function \pgf@pdfparsedfunction
      /Extend [false false] >> >> >>}}}\@temp% <<
      \pgfutil@insertatbegincurrentpage{\special{pdf: content /Sh sh}%
      \special{pdf: endxobj}}%
    \xdef\pgfutil@tempa{%
      \hbox to#2{\vbox to\the\pgf@max{\vfil\special{pdf: usexobj @pgfshade\the\pgfsys@objnum}}\hfil}}%
  }%
  \global\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\relax%
    \advance\pgf@ya by \pgf@y\relax%
    \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\relax%
    \edef\@temp{\noexpand\pgfutil@insertatbegincurrentpage{\special{pdf: beginxobj @pgfshade\the\pgfsys@objnum\space width \the\pgfutil@tempdima\space height \the\pgfutil@tempdima}}}\@temp%
    \edef\@temp{\noexpand\pgfutil@insertatbegincurrentpage{\special{pdf: put @resources <<
      /Shading << /Sh << /ShadingType 3
      /ColorSpace \pgf@shading@device\space
      /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] >> >> >>}}}\@temp% <<
      \pgfutil@insertatbegincurrentpage{\special{pdf: content /Sh sh}%
      \special{pdf: endxobj}}%
    \xdef\pgfutil@tempa{%
      \hbox to\the\pgfutil@tempdima{\vbox to\the\pgfutil@tempdima{\vfil\special{pdf: usexobj @pgfshade\the\pgfsys@objnum}}\hfil}}%
  }%
  \global\expandafter\let\csname @pgfshading#1!\endcsname=\pgfutil@tempa
  \global\advance\pgfsys@objnum\@ne
}%

\def\pgf@sys@pdf@dvi@tracker{
  \def\pgfsys@markposition##1{%
    \pdfsavepos%
    \edef\pgf@temp{##1}%
    \expandafter\write\expandafter\pgfutil@auxout\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}}%
  }
  \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
%

\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 @pgfpattern \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


\endinput

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