1
\immediate\write18{tex spath.dtx}
3
\usepackage[T1]{fontenc}
5
\usepackage{morefloats}
8
\usepackage[numbered]{hypdoc}
9
\definecolor{lstbgcolor}{rgb}{0.9,0.9,0.9}
12
\lstloadlanguages{[LaTeX]TeX}
13
\lstset{breakatwhitespace=true,breaklines=true,language=TeX}
17
\newenvironment{example}
19
\begin{VerbatimOut}{example.out}}
22
\setlength{\parindent}{0pt}
23
\fbox{\begin{minipage}{.9\linewidth}
24
\lstset{breakatwhitespace=true,breaklines=true,language=TeX,basicstyle=\small}
25
\lstinputlisting[]{example.out}
28
\fbox{\begin{minipage}{.9\linewidth}
34
\providecommand*{\url}{\texttt}
35
\GetFileInfo{spath.sty}
37
\title{The \textsf{spath} Package: Documentation}
38
\author{Andrew Stacey \\ \url{stacey@math.ntnu.no}}
39
\date{\fileversion~from \filedate}
45
\section{Introduction}
47
The \texttt{spath} library is an object-oriented interface to the \emph{soft path} system of PGF.
48
It allows one to save, manipulate, and use \emph{soft paths} in a more general way than is currently easy with TikZ/PGF.
49
This library was developed for use with the \texttt{calligraphy} package since that required various path manipulations that would have been hard to do otherwise.
51
There are several steps in the TikZ/PGF system between writing \Verb+\draw (0,0) -- (1,0);+ and a line appearing in the document.
52
The command just given is a TikZ command.
53
The TikZ frontend translates that into PGF commands.
54
These are then processed into a \emph{soft path}.
55
The soft path can be manipulated further before being ``baked'' into a hard path which is then written out into the output file via an appropriate driver.
57
A soft path is a simple object.
58
It consists of a list of tokens of the form \Verb+\pgfsyssoftpath@<something>token{x pt}{y pt}+\footnote{Except for the \Verb+closepath+ token which omits the final \Verb+token+.}.
59
There are only a handful of possible \Verb+<something>+s.
60
It is therefore quite straightforward to manipulate these paths in an orderly fashion.
61
However, the PGF code does not provide a particular method for doing complicated manipulations on these paths.
62
This library introduces some such methods.
64
One thing to note at the outset is that this library makes no attempt to optimise the code and so if the soft path is very long, it will take a considerable time to do any of these manipulations.
65
The PGF soft path system does have some optimisations to handle this.
69
Using this library is relatively straightforward.
70
After loading TikZ/PGF, simply \Verb+\usepackage{spath}+ in the preamble.
71
A typical example of using the library is in the following example.
75
\useasboundingbox (-1,1) rectangle (2,-2);
76
\path[save path=\tmppath] (-1,0) -- (0,0) .. controls +(1,0) and +(1,0) .. (1,1);
77
\pgfoonew \mypath=new spath(\tmppath)
79
\mypath.reverse path()
80
\mypath.use path with tikz(draw)
81
\mypath.translate path(,0cm,-2cm)
82
\mypath.at least three()
83
\mypath.split path by real length(\fpath,\mpath,1)
84
\begin{scope}[ultra thick]
86
\fpath.use path with tikz(fill)
87
\mpath.split path by real length(\mmpath,\epath,-1)
90
\epath.use path with tikz(fill)
91
\mmpath.use path with tikz(draw)
96
In this example, we start by defining a path in the usual TikZian manner.
97
However, instead of doing something with the path, we save it.
98
This saves the raw path as a macro.
99
In order to use this library on that path, we have to convert it into an \Verb+spath+ object.
100
This is done with the next line, starting \Verb+\pgfoonew+ (note the spacing: there must be no space after the \Verb+=+).
101
This command declares \Verb+\mypath+ to be an instance of the \Verb+spath+ class and initialises it with the path stored in \Verb+\tmppath+.
102
(For scoping reasons, we can't define a PGF key to be given to the original \Verb+\path+ command to do this in one go.)
103
This can now be manipulated with the \Verb+spath+ methods.
104
We shall explain the actual methods later so shall not go into detail now.
106
\section{Attributes and Methods}
108
The \texttt{spath} library defines two classes: the \Verb+spath+ and \Verb+spath component+.
109
The \Verb+spath+ is a soft path, the \Verb+spath component+ is an array of \Verb+spath+ objects.
111
\subsection{The \texttt{spath} Object}
113
The following is a list of the attributes that an \Verb+spath+ object has.
114
The class operates on a lazy system: attributes are not automatically worked out so they will not have values initially.
115
However, as soon as you do something that needs one to have a value it will be computed.
120
This holds the actual soft path.
124
This (when initialised) is the length of the soft path in number of soft path tokens.
126
\item \Verb+real length+
128
This is the number of actual drawing tokens in the soft path; that is, the number of \Verb+lineto+ and \Verb+curveto+ tokens.
130
(This ought to also count \Verb+rect+, but I don't know of a TikZ command that actually produces a \Verb+rect+.)
132
\item \Verb+number of components+
134
This is the number of components of the path when divided up by \Verb+moveto+s.
135
It is actually the number of \Verb+moveto+s so successive \Verb+moveto+s will each count.
137
\item \Verb+initial point+
139
This is the coordinates of the start of the path.
140
It is of the form \Verb+\pgfpoint{x coordinate}{y coordinate}+ so when executed will set \Verb+\pgf@x+ and \Verb+\pgf@y+ to the corresponding coordinates.
142
\item \Verb+final point+
144
This is the coordinates of the end of the path.
146
\item \Verb+first action+
148
This is the first drawing action on the path (that is, not the initial \Verb+moveto+).
150
\item \Verb+last action+
152
This is the last action on the path (which might be a \Verb+moveto+).
154
\item \Verb+prepared+
156
The attributes are not calculated initially, but are calculated as needed.
157
There is a method available for calculating them all in one fell swoop.
158
If this has been called, this attribute is set so that the path knows its attributes have all be computed and don't need to be computed again.
160
\item \Verb+taper line width+
162
When tapering a path, it is necessary to set both the current line width and a width to taper to.
163
This holds the latter.
167
The following is a list of the methods available for an \Verb+spath+ object with a brief explanation of what each does.
168
The contents of the parentheses are the arguments for the method.
171
\item \Verb+spath(#1)+
173
This is the creator method, it is called automatically when the object is created.
174
The argument, if given, is a macro containing a soft path which is used to set the \Verb+path+ attribute.
176
\item \Verb+value(#1)+
178
This method inserts the value of the attribute passed to it into the token stream.
180
\item \Verb+set(#1,#2)+
182
This method sets the attribute passed to it as the first argument to the second argument.
184
\item \Verb+let(#1,#2)+
186
This method lets the attribute passed to it as the first argument to be the second argument.
187
The second argument ought to be a macro, therefore.
189
\item \Verb+get(#1,#2)+
191
This method assigns the second argument to the value of the attribute passed to it as the first argument.
192
The second argument ought to be a macro, therefore.
194
\item \Verb+show(#1)+
196
This method shows the value of the attribute in the logs.
197
It uses \Verb+\show+ internally.
199
\item \Verb+clone(#1)+
201
This method clones the \Verb+spath+ object into the macro passed as the argument.
203
\item \Verb+translate path(#1,#2,#3)+
205
This method translates the path by \Verb+#2+ in the x-direction and \Verb+#3+ in the y-direction.
206
If \Verb+#1+ is not empty, it should be a macro which is used to store the translated object (it will be an \Verb+spath+ object).
207
If \Verb+#1+ is empty, the current object is modified.
209
\item \Verb+length()+
211
This method inserts the length of the path in the token stream, computing it if it is not already known.
212
(It is this computation which makes it differ from the \Verb+value+ method.)
214
\item \Verb+real length()+
216
This method inserts the real length of the path in the token stream, computing it if it is not already known.
218
\item \Verb+number of components()+
220
This method inserts the number of components of the path in the token stream, computing it if it is not already known.
222
\item \Verb+initial point()+
224
This method inserts the number of components of the path in the token stream, computing it if it is not already known.
226
\item \Verb+final point()+
228
This method inserts the number of components of the path in the token stream, computing it if it is not already known.
230
\item \Verb+reverse path(#1)+
232
This method reverses the soft path.
233
If the argument is given, the reverse path is stored in it as a new \Verb+spath+ object.
234
If not, the current path is modified.
236
\item \Verb+prepare()+
238
This fills out all the attributes.
239
Finding the information for an attribute involves ``walking'' along the path.
240
Therefore, if we're going to need more than one, it makes sense to do them all in one go.
241
Calling this method ensures that they are all filled in and does so more efficiently than calling each individually.
243
\item \Verb+at least three()+
245
One of the things that the \texttt{calligraphy} package wants to be able to do is taper a path.
246
To do this nicely, the path should have at least three drawing pieces.
247
This ensures that this is so by splitting it if it does not.
248
If it has one piece, it is split into three at the .3 and .7 marks.
249
If it has two pieces, each is split in half.
251
\item \Verb+taper out()+
253
This is used to taper a path.
254
In fact, it replaces the first drawing component by a simularted tapered path (actually the outline of the tapered path is returned).
255
The rest of the path is thrown away, so this should be used after the path has been split.
257
\item \Verb+split path by length(#1,#2,#3)+
259
This splits a path according to the length.
260
The first argument will be an \Verb+spath+ object corresponding to the first part of the path, the second the rest, and the third says how many tokens should be in the first part of the path.
261
Both pieces are ``proper'' paths, so the second will be given an initial \Verb+moveto+.
263
\item \Verb+split path by real length(#1,#2,#3)+
265
This is the same as \Verb+split path by length+ except that it uses the \Verb+real length+ as the criterion of when to split.
267
\item \Verb+split path by component(#1,#2,#3)+
269
This is the same as \Verb+split path by length+ except that it uses the \Verb+number of components+ as the criterion of when to split.
271
\item \Verb+split(#1,#2,#3)+
273
This is the method that actually does the splitting.
274
It depends on certain macros being set which the previous three methods initialise.
275
It should therefore not be called directly.
276
Consider it a ``private'' method.
278
\item \Verb+reprocess path()+
280
This reprocesses the path.
281
Some TikZ/PGF settings have implications for how a path is constructed (such as the \Verb+rounded corners+ option).
282
If these have changed since the path was originally defined, it might be reasonable to redraw the path under the new conditions.
285
\item \Verb+set as current path()+
287
This replaces the current path by the path stored in this object.
289
\item \Verb+get from current path()+
291
This replaces the path stored in this object by the current path.
293
\item \Verb+use path(#1)+
296
The argument should be one of the PGF usage commands: \Verb+draw+, \Verb+fill+, \Verb+clip+, or \Verb+discard+.
298
\item \Verb+use path with tikz(#1)+
300
This uses the path but in a TikZian way.
301
The argument should be a list of TikZ styles to be set for the path.
302
Imagine this as \Verb+\path[<options>] <path>;+.
304
\item \Verb+concatenate(#1,#2)+
306
This concatenates the path in the current object with that from another.
307
If the first argument is given (which should be a macro), the result will a new \Verb+spath+ object stored in that macro.
308
If not, the object will be modified itself.
309
Since paths start with a \Verb+moveto+, the concatenation will not be a continuous path.
311
\item \Verb+concatenate with lineto(#1,#2)+
313
This concatenates the path as \Verb+concatenate+ does, except that the \Verb+moveto+ in the middle is replaced by a \Verb+lineto+.
315
\item \Verb+weld(#1,#2)+
317
This welds two paths together.
318
Welding is like concatenation except that the second path is translated so that its starting point is the final point of the first path (and the \Verb+moveto+ is removed).
322
This closes the path.
325
\subsection{The \texttt{spath component} Object}
327
An \Verb+spath component+ object is an element in an array of \Verb+spath+ objects.
328
Each element contains an \Verb+spath+ object and pointers to the previous and successive components.
333
This is the \Verb+spath+ object of the current element.
335
\item \Verb+next component+
337
This is the next \Verb+spath component+ object (if non-empty).
339
\item \Verb+previous component+
341
This is the previous \Verb+spath component+ object (if non-empty).
344
The methods for \Verb+spath component+s are as follows.
347
\item \Verb+spath component(#1)+
349
This is the initialiser method.
350
The argument should be the previous component in the array.
352
\item \Verb+value(#1)+
354
This method, and the following ones, are exactly as in the \Verb+spath+ object.
356
\item \Verb+set(#1,#2)+
357
\item \Verb+let(#1,#2)+
358
\item \Verb+get(#1,#2)+
359
\item \Verb+show(#1)+
360
\item \Verb+set path(#1)+
362
This sets the \Verb+spath+ attribute of this object.
364
\item \Verb+apply to paths(#1,#2)+
366
This applies a method to all of the \Verb+spath+ objects in the array, starting with the current path and proceding to the next component, and so on.
367
The first argument is the method name, the second is any argument that is to be passed to that method.
369
\item \Verb+apply to previous paths(#1,#2)+
371
This applies a method to all of the \Verb+spath+ objects in the array, starting with the current path and proceding to the previous component, and so on.
374
There is an additional command for use when creating an array of \Verb+spath component+s.
375
This is \Verb+\spathsplit+.
376
It takes two arguments.
377
The first is a macro that will become the first component of an array of \Verb+spath component+s.
378
The second is a macro containing a soft path.
379
The soft path will be split into pieces according to its components (that is, at the \Verb+moveto+s) and stored in the array.
380
At the moment, the last component is (temporarily) available at the end of the split as the \Verb+\spath@this@component+ macro.
b'\\ No newline at end of file'