Implementation

Support for a new type of document writer requires a new structure, derived from fz_document_writer:


\begin{lstlisting}
typedef struct
{
fz_document_writer_begin_page_fn *begin_pag...
..._writer_fn *drop_writer;
fz_device *dev;
} fz_document_writer;
\end{lstlisting}

For instance:


\begin{lstlisting}
typedef struct
{
fz_document_writer super;
<foo specific fields>
} foo_document_writer;
\end{lstlisting}

A generator function should be defined to return such an instance, perhaps:


\begin{lstlisting}
fz_document_writer *fz_new_foo_document_writer(fz_context *ct...
...par
<initialise foo specific fields>
\par
return &foo->super;
}
\end{lstlisting}

This uses a friendly macro that allocates a structure of the required size, initialises the function pointers as required, and zeroes the extra values in the structure.


\begin{lstlisting}
/*
fz_new_document_writer_of_size: Internal function to allo...
...f_size(CTX,sizeof(TYPE),BEGIN_PAGE,END_PAGE,CLOSE,DROP), ...

The actual work for the document writer is done in the functions that are passed to fz_new_derived_document_writer. In the example above these were foo_begin_page, foo_end_page, foo_close, and foo_drop. These have the following 4 types respectively.


\begin{lstlisting}
/*
fz_document_writer_begin_page_fn: Function type to start
...
...iter_drop_writer_fn)(fz_context *ctx, fz_document_writer *wri);
\end{lstlisting}

Once defined, if this is intended to be a generally useful document writer, it should probably be hooked into fz_new_document_writer, where it can be selected by appropriate format and options strings.