22.5 Clipping and Masking

Graphical objects can be restricted to a given area using Clipping. The area to clip to can be specified as paths, text, or images as explained in section 22.1 Line Art, section 22.2 Text, and section 22.3 Images.

Each call to such a function starts a clipping group, which will be terminated by calling:

void fz_pop_clip(fz_context *ctx, fz_device *dev);

Clipping groups can be nested, allowing complex graphical effects.

A related concept to clipping, is that of masking. Whereas clipping regions are simple on or off things, where content is chopped off at hard edges, masking allows for regions that allow just some proportion of the content to show through.

Masking operations take place in 2 stages; first the mask itself is defined, then the content to be masked.

Stage 1 begins by calling fz_begin_mask to start a mask definition group. Any series of graphical operations can now be sent to the device which will combine together to create the mask.

Stage 1 is terminated and Stage 2 begins by calling fz_end_mask. This converts the mask definition into a ‘soft clip’. Any series of graphical operations can now be sent to the device which will combine together to create the mask contents.

The whole process is then completed by calling fz_pop_clip. This renders the mask contents through the soft clip, giving the final results.

void fz_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *area, int luminosity, fz_colorspace *colorspace, const float *bc, const fz_color_params *color_params); 
void fz_end_mask(fz_context *ctx, fz_device *dev);