Walking

Given a path, it can be useful to be able to read it out again. MuPDF uses this internally in a output devices such as the PDF or SVG devices (see PDFDevice PDFDevice or SVGDevice SVGDevice) to convert paths to a new representation, and in the draw device (see DrawDevice DrawDevice) for rendering.

To isolate callers from the implementation specifics of paths, MuPDF offers a mechanism to `walk' a fz_path, getting a callback for each command in the path.


\begin{lstlisting}
typedef struct
{
/* Compulsory ones */
void (*moveto)(fz_co...
... const fz_path *path, const fz_path_walker *walker, void *arg);
\end{lstlisting}

This function is called by giving a pointer to a structure containing callback functions, one for each type of path segment type. The function will walk the path structure and call the appropriate function pointer for each segment of the path in turn.

Callers of this function should not rely on getting exactly the same sequence of path segments out as was used to construct the path; the internal representation may have been optimised to an equivalent form on construction, and this will be reflected in the callbacks received. The path passed back will however be entirely identical (modulo possible infinitesimal rounding issues).

For example, MuPDF is capable of spotting that a cubic or quadratic bezier is actually a line; in such cases it may represent it as a line internally, saving memory and processing power.

Not all path consumers can cope with the full range of segment types that MuPDF natively supports, so some of the callback entries may be left blank (i.e. set to NULL). Rather than calling such an entry, MuPDF will decompose the path segment into one of the more basic types.

For example, if a path contains a quadratic segment and the quadto callback entry is NULL, MuPDF will automatically decompose it to a bezier segment and call the curveto entry instead.