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
|
=head1 Name
lua-oocairo-path - Path object
=head1 Introduction
A path object represents a series of path instructions like C<move_to>
and C<line_to>, as supplied to a context object when defining shapes for
drawing. They can be created by issuing instructions on a context object
and then calling C<cr:copy_path()> or C<cr:copy_path_flat()> (see
L<lua-oocairo-context(3)>). A path can then be added back to the
current path by calling C<cr:append_path()>.
=head1 Methods
Currently only the following method can be called on a path object:
=over
=item path:each ()
Returns an iterator function and initial values needed to iterate over
the instructions in the path using a Lua C<for> loop. This can be used
to translate the Cairo path piece by piece, perhaps to encode it in some
unusual vector graphics format, or to translate it into calls to another
API like OpenGL.
The iterator function will return three values each time it is called.
The first is a number, which should be ignored (but is needed to keep track
of the current position in the list of instructions). The second value is
a string naming the instruction to be performed, and the last value is either
nil or a table (array) of numbers which are the arguments of the instruction.
This example simply prints out the instructions in the order they were
issued on the context object I<cr>:
=for syntax-highlight lua
for _, instr, args in cr:copy_path():each() do
if args then
print(instr, unpack(args))
else
print(instr)
end
end
The following instructions can be included:
=over
=item move-to
Set current point. Comes with a table of two numbers.
=item line-to
Draw straight line. Comes with a table of two numbers.
=item curve-to
Draw curved line. Comes with a table of two numbers, the two
control points first and then the destination point.
=item close-path
Draw line back to start point. The extra arguments value will be nil.
=back
=back
=for comment
vi:ts=4 sw=4 expandtab
|