summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/systemlayer/pgfsys-common-svg.def
blob: 0046ff5a2c1d97d18a904204c7bf937bfb410068 (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
\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/systemlayer/pgfsys-common-svg.def,v 1.13 2005/11/15 17:46:37 tantau Exp $

% Copyright 2005 by Till Tantau <tantau@cs.tu-berlin.de>.
%
% This program can be redistributed and/or modified under the terms
% of the GNU Public License, version 2.




% Driver commands for svg


% Helping functions:
\let\pgf@sys@svgpath=\@empty
\def\pgf@sys@svgnum#1{%
  {%
    \pgf@x=#1\relax%
    \edef\temp{\expandafter\Pgf@geT\the\pgf@x\space}%
    \toks@\expandafter\expandafter\expandafter{\expandafter\pgf@sys@svgpath\temp}%
    \xdef\pgf@sys@svgpath{\the\toks@}%
  }%
}
\def\pgf@sys@addtosvgpath#1{\g@addto@macro\pgf@sys@svgpath{#1\space}}
\def\pgf@sys@flushsvgpath{\pgfsysprotocol@literal{\pgf@sys@svgpath}\global\let\pgf@sys@svgpath=\@empty}
\def\pgf@sys@svg@gs#1{%
  {\pgfsysprotocol@literal{<g #1>\Hnewline }}\global\advance\pgf@sys@svg@scopecount by1\relax%
}
\newcount\pgf@sys@svg@objectcount
\let\Hnewline=\@empty

% Path construction:
\def\pgfsys@lineto#1#2{\pgf@sys@addtosvgpath{L }\pgf@sys@svgnum{#1}\pgf@sys@svgnum{#2}}
\def\pgfsys@moveto#1#2{\pgf@sys@addtosvgpath{M }\pgf@sys@svgnum{#1}\pgf@sys@svgnum{#2}}
\def\pgfsys@curveto#1#2#3#4#5#6{%
  \pgf@sys@addtosvgpath{C }%
  \pgf@sys@svgnum{#1}\pgf@sys@svgnum{#2}%
  \pgf@sys@svgnum{#3}\pgf@sys@svgnum{#4}%
  \pgf@sys@svgnum{#5}\pgf@sys@svgnum{#6}}
\def\pgfsys@rect#1#2#3#4{%
  \pgfsys@moveto{#1}{#2}%
  \pgf@sys@addtosvgpath{h }\pgf@sys@svgnum{#3}%
  \pgf@sys@addtosvgpath{v }\pgf@sys@svgnum{#4}%
  \pgf@sys@addtosvgpath{h }{\pgf@x=#3\pgf@x=-\pgf@x\pgf@sys@svgnum{\pgf@x}}%
  \pgfsys@closepath}
\def\pgfsys@closepath{\pgf@sys@addtosvgpath{Z}}

% Path usage:
\newif\ifpgf@sys@svg@clipnext
\def\pgf@sys@svg@possiblyclippedpath#1{%
  \ifpgf@sys@svg@clipnext%
    \global\advance\pgf@sys@svg@objectcount by1\relax%
    \pgfsysprotocol@literal{<clipPath id="pgfcp\the\pgf@sys@svg@objectcount">
      <path id="pgfpath\the\pgf@sys@svg@objectcount" d="}%
    \pgf@sys@flushsvgpath%
    \pgfsysprotocol@literal{"/>\Hnewline  </clipPath>\Hnewline }
    \pgfsysprotocol@literal{<use xlink:href="\#pgfpath\the\pgf@sys@svg@objectcount" #1/>\Hnewline }%
    \pgf@sys@svg@gs{clip-path="url(\#pgfcp\the\pgf@sys@svg@objectcount)"}
    \pgf@sys@svg@clipnextfalse%
  \else%
    \pgfsysprotocol@literal{<path d="}%
    \pgf@sys@flushsvgpath%
    \pgfsysprotocol@literal{" #1/>\Hnewline }
  \fi%
}
\def\pgfsys@stroke{\pgf@sys@svg@possiblyclippedpath{style="fill:none"}}
\def\pgfsys@fill{\pgf@sys@svg@possiblyclippedpath{style="stroke:none"}}
\def\pgfsys@fillstroke{\pgf@sys@svg@possiblyclippedpath{}}
\def\pgfsys@clipnext{\pgf@sys@svg@clipnexttrue}
\def\pgfsys@discardpath{%
  \ifpgf@sys@svg@clipnext%
    \global\advance\pgf@sys@svg@objectcount by1\relax%
    \pgfsysprotocol@literal{<clipPath id="pgfcp\the\pgf@sys@svg@objectcount">
      <path d="}%
    \pgf@sys@flushsvgpath%
    \pgfsysprotocol@literal{"/>\Hnewline </clipPath>\Hnewline }
    \pgf@sys@svg@gs{clip-path="url(\#pgfcp\the\pgf@sys@svg@objectcount)"}
    \pgf@sys@svg@clipnextfalse%
  \else%
    \global\let\pgf@sys@svgpath=\@empty
  \fi}

% Fill rules:
\def\pgfsys@eoruletrue{\pgf@sys@svg@gs{fill-rule="evenodd"}}
\def\pgfsys@eorulefalse{\pgf@sys@svg@gs{fill-rule="nonzero"}}

% Transparency:
\def\pgfsys@stroke@opacity#1{\pgf@sys@svg@gs{stroke-opacity="#1"}}
\def\pgfsys@fill@opacity#1{\pgf@sys@svg@gs{fill-opacity="#1"}}

% Transformation:
\def\pgfsys@transformcm#1#2#3#4#5#6{%
  {\pgf@x=#5\pgf@y=#6%
  \pgf@sys@svg@gs{transform="matrix(#1,#2,#3,#4,\pgf@sys@tonumber{\pgf@x},\pgf@sys@tonumber{\pgf@y})"}}}

% Scopes
\newcount\pgf@sys@svg@scopecount
\def\pgfsys@beginscope{%
  \edef\pgf@sys@svg@thescopecount{\the\pgf@sys@svg@scopecount}%
  \begingroup%
    \pgf@sys@svg@scopecount=1\relax%
    \pgfsysprotocol@literal{<g>\Hnewline }%
  }
\def\pgfsys@endscope{%
    \loop%
      \pgfsysprotocol@literal{</g>\Hnewline }%
      \advance\pgf@sys@svg@scopecount by-1\relax%
    \ifnum\pgf@sys@svg@scopecount>0\relax%
    \repeat%
  \endgroup%
  \global\pgf@sys@svg@scopecount=\pgf@sys@svg@thescopecount\relax%  
}

% Graphics state
\def\pgfsys@setdash#1#2{%
  \edef\pgf@test@dashpattern{#1}%
  \ifx\pgf@test@dashpattern\@empty%
    \pgf@sys@svg@gs{stroke-dasharray="none" stroke-dashoffset="#2"}%
  \else%
    \pgf@sys@svg@gs{stroke-dasharray="#1" stroke-dashoffset="#2"}%
  \fi}
\def\pgfsys@setlinewidth#1{\pgf@sys@svg@gs{stroke-width="#1"}}
\def\pgfsys@setmiterlimit#1{\pgf@sys@svg@gs{stroke-miterlimit="#1"}}
\def\pgfsys@buttcap{\pgf@sys@svg@gs{stroke-linecap="butt"}}
\def\pgfsys@roundcap{\pgf@sys@svg@gs{stroke-linecap="round"}}
\def\pgfsys@rectcap{\pgf@sys@svg@gs{stroke-linecap="square"}}
\def\pgfsys@miterjoin{\pgf@sys@svg@gs{stroke-linejoin="miter"}}
\def\pgfsys@roundjoin{\pgf@sys@svg@gs{stroke-linejoin="round"}}
\def\pgfsys@beveljoin{\pgf@sys@svg@gs{stroke-linejoin="bevel"}}


%
% Color management
% 

\def\XC@mcolor{\ifpgfpicture\pgfsetcolor{.}\fi}

\def\pgf@sys@svg@color@rgb#1,#2,#3\relax{%
 {%
    \pgf@xa=#1pt%
    \pgf@xa=100\pgf@xa%
    \pgf@xb=#2pt%
    \pgf@xb=100\pgf@xb%
    \pgf@xc=#3pt%
    \pgf@xc=100\pgf@xc%
    \xdef\pgf@sys@svg@prepared{rgb(\pgf@sys@tonumber\pgf@xa\%,\pgf@sys@tonumber\pgf@xb\%,\pgf@sys@tonumber\pgf@xc\%)}%
  }%
}
\def\pgf@sys@svg@color@cmy#1,#2,#3\relax{%
  {%
    \pgf@xa=1pt%
    \advance\pgf@xa by-#1pt%
    \pgf@xa=100\pgf@xa%
    \pgf@xb=1pt%
    \advance\pgf@xb by-#2pt%
    \pgf@xb=100\pgf@xb%
    \pgf@xc=1pt%
    \advance\pgf@xc by-#3pt%
    \pgf@xc=100\pgf@xc%
    \xdef\pgf@sys@svg@prepared{rgb(\pgf@sys@tonumber\pgf@xa\%,\pgf@sys@tonumber\pgf@xb\%,\pgf@sys@tonumber\pgf@xc\%)}%
  }%
}
\def\pgf@sys@svg@color@cmyk#1,#2,#3,#4\relax{%
  {%
    \pgf@xa=1pt%
    \advance\pgf@xa by-#4pt%
    \pgf@xa=#1\pgf@xa%
    \advance\pgf@xa by#4pt%
    \advance\pgf@xa by-1pt%
    \pgf@xa=-100\pgf@xa%
    \pgf@xb=1pt%
    \advance\pgf@xb by-#4pt%
    \pgf@xb=#2\pgf@xb%
    \advance\pgf@xb by#4pt%
    \advance\pgf@xb by-1pt%
    \pgf@xb=-100\pgf@xb%
    \pgf@xc=1pt%
    \advance\pgf@xc by-#4pt%
    \pgf@xc=#3\pgf@xc%
    \advance\pgf@xc by#4pt%
    \advance\pgf@xc by-1pt%
    \pgf@xc=-100\pgf@xc%
    \xdef\pgf@sys@svg@prepared{rgb(\pgf@sys@tonumber\pgf@xa\%,\pgf@sys@tonumber\pgf@xb\%,\pgf@sys@tonumber\pgf@xc\%)}%
  }%
}
\def\pgf@sys@svg@color@gray#1\relax{%
 {%
    \pgf@xa=#1pt%
    \pgf@xa=100\pgf@xa%
    \xdef\pgf@sys@svg@prepared{rgb(\pgf@sys@tonumber\pgf@xa\%,\pgf@sys@tonumber\pgf@xa\%,\pgf@sys@tonumber\pgf@xa\%)}%
  }%
}

\def\pgfsys@color@rgb@stroke#1#2#3{%
  \pgf@sys@svg@color@rgb#1,#2,#3\relax%
  \pgf@sys@svg@gs{stroke="\pgf@sys@svg@prepared"}}
\def\pgfsys@color@rgb@fill#1#2#3{%
  \pgf@sys@svg@color@rgb#1,#2,#3\relax%
  \pgf@sys@svg@gs{fill="\pgf@sys@svg@prepared"}}
\def\pgfsys@color@cmyk@stroke#1#2#3#4{%
  \pgf@sys@svg@color@cmyk#1,#2,#3,#4\relax%
  \pgf@sys@svg@gs{stroke="\pgf@sys@svg@prepared"}}
\def\pgfsys@color@cmyk@fill#1#2#3#4{%
  \pgf@sys@svg@color@cmyk#1,#2,#3,#4\relax%
  \pgf@sys@svg@gs{fill="\pgf@sys@svg@prepared"}}
\def\pgfsys@color@cmy@stroke#1#2#3{%
  \pgf@sys@svg@color@cmy#1,#2,#3\relax%
  \pgf@sys@svg@gs{stroke="\pgf@sys@svg@prepared"}}
\def\pgfsys@color@cmy@fill#1#2#3{%
  \pgf@sys@svg@color@cmy#1,#2,#3\relax%
  \pgf@sys@svg@gs{fill="\pgf@sys@svg@prepared"}}
\def\pgfsys@color@gray@stroke#1{%
  \pgf@sys@svg@color@gray#1\relax%
  \pgf@sys@svg@gs{stroke="\pgf@sys@svg@prepared"}}
\def\pgfsys@color@gray@fill#1{%
  \pgf@sys@svg@color@gray#1\relax%
  \pgf@sys@svg@gs{fill="\pgf@sys@svg@prepared"}}


% Shadings:
\def\pgf@sys@svg@shading@stops{%
  % Step 1: Compute 1/\pgf@sys@shading@end@pos
  \pgf@x=\pgf@sys@shading@end@pos\relax%
  \c@pgf@counta=\pgf@x\relax%
  \divide\c@pgf@counta by4096\relax%
  % Step 2: Insert stops.
  \expandafter\pgf@sys@svg@shading@dostops\pgf@sys@shading@ranges%
    % dummy for end:
    {{\pgf@sys@shading@end@pos}{\pgf@sys@shading@end@pos}{\pgf@sys@shading@end@rgb}{\pgf@sys@shading@end@rgb}}%
    {}% end
}
\def\pgf@sys@svg@shading@dostops#1{%
  \edef\pgf@test{#1}%
  \ifx\pgf@test\@empty%
  \else%
    \expandafter\pgf@sys@svg@shading@dostop\pgf@test%
    \expandafter\pgf@sys@svg@shading@dostops%
  \fi%
}
\def\pgf@sys@svg@shading@dostop#1#2#3#4{%
  % #1 start pos
  % #2 end pos
  % #3 start rgb
  % #4 end rgb
  \pgf@sys@svg@addtostops{<stop offset="}%
  \pgf@x=#1%
  \pgf@x=16\pgf@x%
  \divide\pgf@x by \c@pgf@counta\relax%
  \pgf@sys@svg@addtostops{\pgf@sys@tonumber\pgf@x" stop-color="}%
  \pgf@sys@svg@shading@dorgb#3%
  \pgf@sys@svg@addtostops{"/>\noexpand\Hnewline}%
}
\def\pgf@sys@svg@shading@dorgb#1#2#3{%
  \pgf@sys@svg@color@rgb#1,#2,#3\relax%
  \pgf@sys@svg@addtostops{\pgf@sys@svg@prepared}%
}

\let\pgf@sys@svg@thestops=\@empty
\def\pgf@sys@svg@addtostops#1{%
  \edef\pgf@temp{#1}%
  \expandafter\expandafter\expandafter\def
  \expandafter\expandafter\expandafter\pgf@sys@svg@thestops
  \expandafter\expandafter\expandafter{\expandafter\pgf@sys@svg@thestops\expandafter\space\pgf@temp}%
}


\def\pgfsys@horishading#1#2#3{%
  {%
    \pgf@parsefunc{#3}%
    \global\advance\pgf@sys@svg@objectcount by1\relax%
    \pgf@sys@svg@addtostops{<linearGradient id="pgfsh\the\pgf@sys@svg@objectcount">\noexpand\Hnewline}
    \pgf@sys@svg@shading@stops%
    \pgf@sys@svg@addtostops{</linearGradient>\noexpand\Hnewline}%
    \pgf@process{\pgfpoint{\pgf@sys@shading@end@pos}{#2}}%
    \expandafter\xdef\csname @pgfshading#1!\endcsname{%
      \def\noexpand\pgf@sys@svg@sh@defs{\noexpand\pgfsysprotocol@literal{\pgf@sys@svg@thestops}}%
      \def\noexpand\pgf@sys@svg@sh{\noexpand\pgfsysprotocol@literal{<rect
        width="\the\pgf@x"
        height="\the\pgf@y"
        style="fill:url(\noexpand\#pgfsh\the\pgf@sys@svg@objectcount);
          stroke:none"/>\noexpand\Hnewline}}%
      \def\noexpand\pgf@sys@svg@pos{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}%
    }%
  }%
}


\def\pgfsys@vertshading#1#2#3{%
  {%
    \pgf@parsefunc{#3}%
    \global\advance\pgf@sys@svg@objectcount by1\relax%
    \pgf@sys@svg@addtostops{<linearGradient
      id="pgfsh\the\pgf@sys@svg@objectcount"
      gradientTransform="rotate(90)">\noexpand\Hnewline}
    \pgf@sys@svg@shading@stops%
    \pgf@sys@svg@addtostops{</linearGradient>\noexpand\Hnewline}%
    \pgf@process{\pgfpoint{\pgf@sys@shading@end@pos}{#2}}%
    \expandafter\xdef\csname @pgfshading#1!\endcsname{%
      \def\noexpand\pgf@sys@svg@sh@defs{\noexpand\pgfsysprotocol@literal{\pgf@sys@svg@thestops}}%
      \def\noexpand\pgf@sys@svg@sh{\noexpand\pgfsysprotocol@literal{<rect
        width="\the\pgf@y"
        height="\the\pgf@x"
        style="fill:url(\noexpand\#pgfsh\the\pgf@sys@svg@objectcount);
          stroke:none"/>\noexpand\Hnewline}}%
      \def\noexpand\pgf@sys@svg@pos{\noexpand\pgfpoint{\the\pgf@y}{\the\pgf@x}}%
    }%
  }%
}

\def\pgfsys@radialshading#1#2#3{%
  {%
    \pgf@parsefunc{#3}%
    \pgf@x=\pgf@sys@shading@end@pos\relax%
    \c@pgf@counta=\pgf@x\relax%
    \divide\c@pgf@counta by4096\relax%
    \global\advance\pgf@sys@svg@objectcount by1\relax%
    \pgf@process{#2}%
    % Divide by 2\pgf@sys@shading@end@pos%
    \pgf@x=8\pgf@x%
    \divide\pgf@x by \c@pgf@counta\relax%
    \pgf@y=8\pgf@y%
    \divide\pgf@y by \c@pgf@counta\relax%
    \advance\pgf@x by.5pt%
    \advance\pgf@y by.5pt%
    \pgf@sys@svg@addtostops{<radialGradient
      id="pgfsh\the\pgf@sys@svg@objectcount"
      fx="\pgf@sys@tonumber\pgf@x"
      fy="\pgf@sys@tonumber\pgf@y"
      >\noexpand\Hnewline}
    \pgf@sys@svg@shading@stops%
    \pgf@sys@svg@addtostops{</radialGradient>\noexpand\Hnewline}%
    \pgf@xa=\pgf@sys@shading@end@pos%
    \pgf@xb=2\pgf@xa%    
    \expandafter\xdef\csname @pgfshading#1!\endcsname{%
      \def\noexpand\pgf@sys@svg@sh@defs{\noexpand\pgfsysprotocol@literal{\pgf@sys@svg@thestops}}%
      \def\noexpand\pgf@sys@svg@sh{\noexpand\pgfsysprotocol@literal{<circle
        cx="\the\pgf@xa"
        cy="\the\pgf@xa"
        r="\the\pgf@xa"
        style="fill:url(\noexpand\#pgfsh\the\pgf@sys@svg@objectcount);
          stroke:none"/>\noexpand\Hnewline}}%
      \def\noexpand\pgf@sys@svg@pos{\noexpand\pgfpoint{\the\pgf@xb}{\the\pgf@xb}}%
    }%
  }%
}


\endinput


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