summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/basiclayer/pgfcorearrows.code.tex
blob: bdf4906c1bef813ae84fc252371f0f01f6bfb0f9 (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
503
504
505
506
507
508
509
510
511
512
513
% 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 $Header: /cvsroot/pgf/pgf/generic/pgf/basiclayer/pgfcorearrows.code.tex,v 1.8 2007/06/07 07:41:10 tantau Exp $


% Sets the end arrow
%
% #1 = An arrow name
%
% Example:
%
% \pgfsetarrowsend{stealth}

\def\pgfsetarrowsend#1{\pgf@arrowset{end}{#1}}
\def\pgf@arrowset#1#2{%
  \pgfutil@ifundefined{pgf@arrow@code@#2}
  {\PackageError{pgf}{Arrow #1 type ``#2'' unknown}{}}
  {%
    \edef\pgf@arrow@temp{#2}%
    \ifx\pgf@arrow@temp\pgfutil@empty% ah. clear!
      \expandafter\let\csname pgf@#1arrow\endcsname=\pgfutil@empty%
      \expandafter\let\csname pgf@shorten@#1\endcsname=\pgfutil@empty%
    \else%
      %\pgf@arrow@prepare{#2}%
      \expandafter\def\csname pgf@#1arrow\endcsname{\pgf@arrow@call{#2}}%
      \expandafter\edef\csname pgf@shorten@#1\endcsname{\expandafter\noexpand\csname pgf@arrow@right@#2\endcsname}%
    \fi%
  }%
}


% Sets the start arrow
%
% #1 = An arrow name
%
% Example:
%
% \pgfsetarrowsstart{stealth}

\def\pgfsetarrowsstart#1{\pgf@arrowset{start}{\csname pgf@arrows@invert#1\endcsname}}

\def\pgf@arrows@invname#1#2{\expandafter\def\csname pgf@arrows@invert#1\endcsname{#2}}
\pgf@arrows@invname{}{}




% Sets arrows
%
% #1 = An arrow specification of the form ``left''-``right''. The last
%      and right should be arrow types that have been defined using
%      the \pgfarrowsdef command
%
% Example:
%
% \pgfsetarrows{-to}

\def\pgfsetarrows#1{\pgf@arrows#1\pgf@stop}
\def\pgf@arrows#1-#2\pgf@stop{%
  \pgfsetarrowsstart{#1}
  \pgfsetarrowsend{#2}
}

\def\pgf@arrows@checked#1#2#3{%
  \pgfutil@ifundefined{pgf@arrow@code@#2}%
  {%
    \PackageError{pgf}{Arrow end type ``#2'' unknown}{}}%
  {%
    \pgfutil@ifundefined{pgf@arrow@code@\csname pgf@arrows@invert#1\endcsname}
    {\PackageError{pgf}{Arrow start type ``#1'' unknown}{}}%
    {#3}%
  }%
}

\def\pgf@arrows@check@already#1#2#3{%
  \pgfutil@ifundefined{pgf@arrow@code@#2}
  {#3}%
  {\PackageError{pgf}{Arrow end type ``#2'' already defined}{}}%
}


% Called when an arrow needs to be rendered

\def\pgf@arrow@call#1{%
  \expandafter\ifx\csname pgf@arrow@prot@#1@\the\pgflinewidth\endcsname\relax%
    \pgfsysprotocol@getcurrentprotocol\pgf@arrow@temp%
    {%
      \pgfinterruptpath%
        \let\pgfusepath=\pgf@nousepath@here%
        \pgf@relevantforpicturesizefalse%
        \pgftransformreset%
        \pgfsysprotocol@setcurrentprotocol\pgfutil@empty%
        \pgfsysprotocol@bufferedtrue%
        \pgfsys@beginscope%
        \csname pgf@arrow@code@#1\endcsname%
        \pgfsys@endscope%
        \pgfsysprotocol@getcurrentprotocol\pgf@@arrow@temp%
        \global\let\pgf@@arrow@temp=\pgf@@arrow@temp%
      \endpgfinterruptpath%
      \expandafter\def\expandafter\pgf@temp\expandafter{\expandafter\pgfsys@invoke\expandafter{\pgf@@arrow@temp}}%
      \expandafter\global\expandafter\let\csname pgf@arrow@prot@#1@\the\pgflinewidth\endcsname=\pgf@temp%
    }%
    \pgfsysprotocol@setcurrentprotocol\pgf@arrow@temp%
  \fi%
  \csname pgf@arrow@prot@#1@\the\pgflinewidth\endcsname%
} 

\def\pgf@arrow@code@{} % dummy

\def\pgf@nousepath@here#1{%
  \PackageError{pgf}{The definition of an arrow may not use \string\pgfusepath}{}
}



% Define an arrow type.
%
% #1 = name or mnemonic for arrow when used at the start (examples: ``to'' or ``<'')
% #2 = name or mnemonic for arrow when used at the end (examples: ``to'' or ``>'')
% #3 = code to setup the left and right extend of the arrow. To set
%      the left extend, call \pgfarrowsleftextend, for the right \pgfarrowsrightextend.
% #4 = protocolable code
%
% Description:
%
% When you define an arrow using this command, you must give two
% names. The first is used for the arrow when it is ``at the start'',
% the other when it is at the end. For example, a simple arrow might
% have the names ``<'' and ``>'', though these particular names are
% not used by pgf and left for the user.
%
% The code should be ``protocolable'' code. This means that it uses
% only pretty simple commands. 
%
% The arrow code will be protocolled once for each line width at which
% the arrow is used. Thus, the code can (and often should) depend on
% the line width.
%
% The arrow should ``point right'' in the coordinate system. The end
% of the line at which the arrow should be drawn will be at the origin
% of the coordinate system. The coordinate system will be scaled and
% rotated appropriately before the arrow is drawn.
%
% The right extend of the arrow should be set to how much the arrow
% ``protrudes over the right''. Prior to drawing the arrow, the line
% will be shortened by this amount so that the arrow tip will exactly
% touch the original right end of the unshortened line.
%
% The left extend specifies the leftmost point of the arrow. This is
% important only if you use the swapping command, when this end is
% used to compute the shortening. 
%
% The definition of an arrow should normally take care of the fact
% that the line cap of the main line may be a butt cap, a round cap or
% a rect cap. In all cases, the arrow should ``cover'' the cap
% completely or not at all.
%
% Example:
%
% \pgfarrowsdeclare{stealth}{stealth}
% {
%   \pgfarrowsleftextend{-6\pgflinewidth}
%   \pgfarrowsrightextend{2\pgflinewidth}
% {
%   \pgfpathmoveto{\pgfpoint{2\pgflinewidth}{0pt}}
%   \pgfpathlineto{\pgfpoint{-6\pgflinewidth}{4\pgflinewidth}}
%   \pgfpathlineto{\pgfpoint{-3\pgflinewidth}{0pt}}
%   \pgfpathlineto{\pgfpoint{-6\pgflinewidth}{-4\pgflinewidth}}
%   \pgfusepathqfill
% }

\def\pgfarrowsdeclare#1#2#3#4{%
  \pgf@arrows@check@already{#1}{#2}
  {%
    \expandafter\def\csname pgf@arrow@code@#2\endcsname{#4}%
    \expandafter\def\csname pgf@arrow@left@#2\endcsname{#3\advance\pgf@x by-\pgf@xa}%
    \expandafter\def\csname pgf@arrow@right@#2\endcsname{#3\advance\pgf@x by\pgf@xb}%
    \pgf@arrows@invname{#1}{#2}%
  }%
}

\def\pgfarrowsleftextend#1{\pgfmathsetlength\pgf@xa{#1}}
\def\pgfarrowsrightextend#1{\pgfmathsetlength\pgf@xb{#1}}

\def\pgf@arrows@repeat#1#2{%
  \edef\pgf@arrows@marshal{\noexpand\let\expandafter\noexpand\csname#2\endcsname=\expandafter\noexpand\csname#1\endcsname}%
  \pgf@arrows@marshal}



% Declare a new arrow type to be the same as another one.
%
% #1 = name of new start
% #2 = name or new end
% #3 = name or old start
% #4 = name or old end
%
% Example:
%
% \pgfarrowsdeclarealias{<}{>}{to}{to}

\def\pgfarrowsdeclarealias#1#2#3#4{%
  \pgf@arrows@check@already{#1}{#2}
  {%
    \pgf@arrows@checked{#3}{#4}%
    {%
      \pgf@arrows@repeat{pgf@arrow@code@#4}{pgf@arrow@code@#2}%
      \pgf@arrows@repeat{pgf@arrow@left@#4}{pgf@arrow@left@#2}%
      \pgf@arrows@repeat{pgf@arrow@right@#4}{pgf@arrow@right@#2}%
      \pgf@arrows@invname{#1}{#2}%
    }%
  }%
}




% Creates a new arrows by ``swapping'' an existing arrow.
%
% #1 = name of new start
% #2 = name of new end
% #3 = name of old start
% #4 = name of old end
%
% Example:
%
% \pgfarrowsdeclarealias{]}{[}{[}{]}

\def\pgfarrowsdeclarereversed#1#2#3#4{%
  \pgf@arrows@check@already{#1}{#2}%
  {%
    \pgf@arrows@checked{#3}{#4}%
    {%
      \expandafter\def\csname pgf@arrow@code@#2\endcsname{%
        \pgflowlevel{\pgftransformxscale{-1}}%
        \csname pgf@arrow@code@#4\endcsname}%
      \pgf@arrows@repeat{pgf@arrow@right@#4}{pgf@arrow@left@#2}%
      \pgf@arrows@repeat{pgf@arrow@left@#4}{pgf@arrow@right@#2}%
      \pgf@arrows@invname{#1}{#2}%
    }%
  }%
}



% Creates new arrows by combining two existing arrows.
%
% #1 = optional additional space
% #2 = name of new start
% #3 = name of new end
% #4 = name of second (innermost) start
% #5 = name of second end
% #6 = name of first (outermost) start
% #7 = name of first end
%
% In the star form, the line will end at the innermost arrows,
% otherwise the line will end at the outermost arrows.
%
% Example:
%
% \pgfarrowsdeclarecombine*{|<}{>|}{|}{|}{<}{>}
% \pgfarrowsdeclarecombine{<<}{>>}{<}{>}{<}{>}

\def\pgfarrowsdeclarecombine{\pgfutil@ifnextchar*{\pgfarrowsdeclarecombine@star}{\pgf@@arrowsdeclarecombine}}

\def\pgf@@arrowsdeclarecombine{\pgfutil@ifnextchar[{\pgf@arrowsdeclarecombine}{\pgf@arrowsdeclarecombine[0pt]}}
\def\pgf@arrowsdeclarecombine[#1]#2#3#4#5#6#7{%
  \pgf@arrows@check@already{#2}{#3}%
  {%
    \pgf@arrows@checked{#4}{#5}%
    {%
      \pgf@arrows@checked{#6}{#7}%
      {%
        \expandafter\edef\csname pgf@arrow@code@#3\endcsname{%
          \noexpand\pgfscope%
          {\expandafter\noexpand\csname pgf@arrow@code@#7\endcsname}%
          \noexpand\endpgfscope%
          {%
            \noexpand\pgfmathsetlength\pgf@x{#1}%
            \noexpand\pgf@process{\expandafter\noexpand\csname pgf@arrow@left@#7\endcsname}%
            \noexpand\pgf@process{\expandafter\noexpand\csname pgf@arrow@right@#5\endcsname}%
            \pgf@x=-\pgf@x%
            \noexpand\pgflowlevel{\noexpand\pgftransformxshift{\pgf@x}}%
            \expandafter\noexpand\csname pgf@arrow@code@#5\endcsname}%
          }%
        \pgf@arrows@repeat{pgf@arrow@right@#7}{pgf@arrow@right@#3}%
        \expandafter\def\csname pgf@arrow@left@#3\endcsname{%
          \pgf@process{%
            \pgfmathsetlength\pgf@y{#1}%
            \advance\pgf@x by\pgf@y%
            \pgf@process{\csname pgf@arrow@left@#7\endcsname}%
            \pgf@process{\csname pgf@arrow@right@#5\endcsname}%
            \pgf@process{\csname pgf@arrow@left@#5\endcsname}%
          }%
        }%
        \pgf@arrows@invname{#2}{#3}%
      }%
    }%
  }%
}

\def\pgfarrowsdeclarecombine@star*{\pgfutil@ifnextchar[{\pgf@arrowsdeclarecombine@star}{\pgf@arrowsdeclarecombine@star[0pt]}}
\def\pgf@arrowsdeclarecombine@star[#1]#2#3#4#5#6#7{%
  \pgf@arrows@check@already{#2}{#3}%
  {%
    \pgf@arrows@checked{#4}{#5}%
    {%
      \pgf@arrows@checked{#6}{#7}%
      {%
        \expandafter\edef\csname pgf@arrow@code@#3\endcsname{%
          \noexpand\pgfscope%
            {%
              \noexpand\pgfmathsetlength\pgf@x{#1}%
              \pgf@process{\expandafter\noexpand\csname pgf@arrow@left@#7\endcsname}%
              \pgf@process{\expandafter\noexpand\csname pgf@arrow@right@#5\endcsname}%
              \noexpand\pgflowlevel{\noexpand\pgftransformxshift{\pgf@x}}%
            }%
            {\expandafter\noexpand\csname pgf@arrow@code@#7\endcsname}%
          \noexpand\endpgfscope%
          \expandafter\noexpand\csname pgf@arrow@code@#5\endcsname%
        }%
        \pgf@arrows@repeat{pgf@arrow@left@#7}{pgf@arrow@left@#3}%
        \expandafter\def\csname pgf@arrow@right@#3\endcsname{%
          \pgf@process{%
            \pgfmathsetlength\pgf@y{#1}%
            \advance\pgf@x by\pgf@y%
            \pgf@process{\csname pgf@arrow@left@#7\endcsname}%
            \pgf@process{\csname pgf@arrow@right@#5\endcsname}%
            \pgf@process{\csname pgf@arrow@right@#7\endcsname}%
          }%
        }%
        \pgf@arrows@invname{#2}{#3}%
      }%
    }%
  }%
}



% Creates new arrows by doubling/tripling existing arrows.
%
% #1 = optional additional space in multiples of line width
% #2 = name of new start
% #3 = name of new end
% #4 = name of old start
% #5 = name of old end
%
% Example:
%
% \pgfarrowsdeclaredouble{<<}{>>}{<}{>}

\def\pgfarrowsdeclaredouble{\pgfutil@ifnextchar[{\pgf@arrowsdeclaredouble}{\pgf@arrowsdeclaredouble[0pt]}}
\def\pgf@arrowsdeclaredouble[#1]#2#3#4#5{\pgfarrowsdeclarecombine[#1]{#2}{#3}{#4}{#5}{#4}{#5}}
\def\pgfarrowsdeclaretriple{\pgfutil@ifnextchar[{\pgf@arrowsdeclaretriple}{\pgf@arrowsdeclaretriple[0pt]}}
\def\pgf@arrowsdeclaretriple[#1]#2#3#4#5{%
  \pgfarrowsdeclarecombine[#1]{pgf@trip@#2}{pgf@trip@#3}{#4}{#5}{#4}{#5}%
  \pgfarrowsdeclarecombine[#1]{#2}{#3}{pgf@trip@#2}{pgf@trip@#3}{#4}{#5}%
}


% A stealth-fighter-like pointed arrow
%
% Example:
%
% \pgfsetarrows{-stealth}

\pgfarrowsdeclare{stealth}{stealth}
{
  \pgfutil@tempdima=0.28pt%
  \advance\pgfutil@tempdima by.3\pgflinewidth%
  \pgfarrowsleftextend{+-3\pgfutil@tempdima}
  \pgfarrowsrightextend{+5\pgfutil@tempdima}
}
{
  \pgfutil@tempdima=0.28pt%
  \advance\pgfutil@tempdima by.3\pgflinewidth%
  \pgfpathmoveto{\pgfqpoint{5\pgfutil@tempdima}{0pt}}
  \pgfpathlineto{\pgfqpoint{-3\pgfutil@tempdima}{4\pgfutil@tempdima}}
  \pgfpathlineto{\pgfpointorigin}
  \pgfpathlineto{\pgfqpoint{-3\pgfutil@tempdima}{-4\pgfutil@tempdima}}
  \pgfusepathqfill
}

\pgfarrowsdeclarereversed{stealth reversed}{stealth reversed}{stealth}{stealth}


% An arrow similar to the $\to$ arrow
%
% Example:
%
% \pgfsetarrow{-to}

\pgfarrowsdeclare{to}{to}
{
  \pgfutil@tempdima=-0.84pt%
  \advance\pgfutil@tempdima by-1.3\pgflinewidth%
  \pgfutil@tempdimb=0.21pt%
  \advance\pgfutil@tempdimb by.625\pgflinewidth%
  \pgfarrowsleftextend{+\pgfutil@tempdima}
  \pgfarrowsrightextend{+\pgfutil@tempdimb}
}
{
  \pgfutil@tempdima=0.28pt%
  \advance\pgfutil@tempdima by.3\pgflinewidth%
  \pgfsetlinewidth{0.8\pgflinewidth}
  \pgfsetdash{}{+0pt}
  \pgfsetroundcap
  \pgfsetroundjoin
  \pgfpathmoveto{\pgfqpoint{-3\pgfutil@tempdima}{4\pgfutil@tempdima}}
  \pgfpathcurveto
  {\pgfqpoint{-2.75\pgfutil@tempdima}{2.5\pgfutil@tempdima}}
  {\pgfqpoint{0pt}{0.25\pgfutil@tempdima}}
  {\pgfqpoint{0.75\pgfutil@tempdima}{0pt}}
  \pgfpathcurveto
  {\pgfqpoint{0pt}{-0.25\pgfutil@tempdima}}
  {\pgfqpoint{-2.75\pgfutil@tempdima}{-2.5\pgfutil@tempdima}}
  {\pgfqpoint{-3\pgfutil@tempdima}{-4\pgfutil@tempdima}}
  \pgfusepathqstroke
}

\pgfarrowsdeclare{to reversed}{to reversed}
{
  \pgfutil@tempdima=-0.21pt%
  \advance\pgfutil@tempdima by-0.475\pgflinewidth%
  \pgfutil@tempdimb=0.98pt%
  \advance\pgfutil@tempdimb by1.45\pgflinewidth%
  \pgfarrowsleftextend{+\pgfutil@tempdima}
  \pgfarrowsrightextend{+\pgfutil@tempdimb}
}
{
  \pgfutil@tempdima=0.28pt%
  \advance\pgfutil@tempdima by.3\pgflinewidth%
  \pgfsetlinewidth{+0.8\pgflinewidth}
  \pgfsetdash{}{+0pt}
  \pgfsetroundcap
  \pgfsetroundjoin
  \pgfpathmoveto{\pgfqpoint{3.5\pgfutil@tempdima}{4\pgfutil@tempdima}}
  \pgfpathcurveto
  {\pgfqpoint{3.25\pgfutil@tempdima}{2.5\pgfutil@tempdima}}
  {\pgfqpoint{0.5\pgfutil@tempdima}{0.25\pgfutil@tempdima}}
  {\pgfqpoint{-0.25\pgfutil@tempdima}{0\pgfutil@tempdima}}
  \pgfpathcurveto
  {\pgfqpoint{0.5\pgfutil@tempdima}{-0.25\pgfutil@tempdima}}
  {\pgfqpoint{3.25\pgfutil@tempdima}{-2.5\pgfutil@tempdima}}
  {\pgfqpoint{3.5\pgfutil@tempdima}{-4\pgfutil@tempdima}}
  \pgfusepathqstroke
}



% LaTeX's orginal arrow type
%
% Example:
%
% \pgfsetarrows{-latex}

\pgfarrowsdeclare{latex}{latex}
{
  \pgfutil@tempdima=0.28pt%
  \advance\pgfutil@tempdima by.3\pgflinewidth%
  \pgfarrowsleftextend{+-1\pgfutil@tempdima}
  \pgfarrowsrightextend{+9\pgfutil@tempdima}
}
{
  \pgfutil@tempdima=0.28pt%
  \advance\pgfutil@tempdima by.3\pgflinewidth%
  \pgfpathmoveto{\pgfqpoint{9\pgfutil@tempdima}{0pt}}
  \pgfpathcurveto
  {\pgfqpoint{6.3333\pgfutil@tempdima}{.5\pgfutil@tempdima}}
  {\pgfqpoint{2\pgfutil@tempdima}{2\pgfutil@tempdima}}
  {\pgfqpoint{-1\pgfutil@tempdima}{3.75\pgfutil@tempdima}}
  \pgfpathlineto{\pgfqpoint{-1\pgfutil@tempdima}{-3.75\pgfutil@tempdima}}
  \pgfpathcurveto
  {\pgfqpoint{2\pgfutil@tempdima}{-2\pgfutil@tempdima}}
  {\pgfqpoint{6.3333\pgfutil@tempdima}{-.5\pgfutil@tempdima}}
  {\pgfqpoint{9\pgfutil@tempdima}{0pt}}
  \pgfusepathqfill
}
\pgfarrowsdeclarereversed{latex reversed}{latex reversed}{latex}{latex}



% A bar shaped arrow
%
% Example:
%
% \pgfsetarrows{-|}

\pgfarrowsdeclare{|}{|}
{
  \pgfarrowsleftextend{+-0.25\pgflinewidth}
  \pgfarrowsrightextend{+.75\pgflinewidth}
}
{
  \pgfutil@tempdima=2pt%
  \advance\pgfutil@tempdima by1.5\pgflinewidth%
  \pgfsetdash{}{+0pt}
  \pgfsetrectcap
  \pgfpathmoveto{\pgfqpoint{0.25\pgflinewidth}{-\pgfutil@tempdima}}
  \pgfpathlineto{\pgfqpoint{0.25\pgflinewidth}{\pgfutil@tempdima}}
  \pgfusepathqstroke
}



\endinput