# scanline handling.

## Data Structures
struct | hpgs_scanline_point_st
| An intersection point of a path with a scanline. More...
struct | hpgs_paint_scanline_st
| A scanline of the pixel renderer. More...
struct | hpgs_paint_clipper_st
| A collection of scanlines for mapping paths onto images. More...
## Functions
HPGS_INTERNAL_API hpgs_paint_clipper * | hpgs_new_paint_clipper (const hpgs_bbox *bb, int height, int scanline_msize, int overscan)
HPGS_INTERNAL_API hpgs_paint_clipper * | hpgs_paint_clipper_clip (const hpgs_paint_clipper *orig, const hpgs_paint_clipper *clip, hpgs_bool winding)
HPGS_INTERNAL_API int | hpgs_paint_clipper_cut (hpgs_paint_clipper *c, hpgs_paint_path *path)
HPGS_INTERNAL_API int | hpgs_paint_clipper_thin_cut (hpgs_paint_clipper *c, hpgs_paint_path *path, const hpgs_gstate *gstate)
HPGS_INTERNAL_API int | hpgs_paint_clipper_emit (hpgs_image *image, const hpgs_paint_clipper *img, const hpgs_paint_clipper *clip, const hpgs_paint_color *c, hpgs_bool winding, hpgs_bool stroke)
HPGS_INTERNAL_API int | hpgs_paint_clipper_reset (hpgs_paint_clipper *c, double llx, double urx)
HPGS_INTERNAL_API void | hpgs_paint_clipper_clear (hpgs_paint_clipper *c)
HPGS_INTERNAL_API void | hpgs_paint_clipper_destroy (hpgs_paint_clipper *c)

## Detailed Description

This module contains the documentation of the internals of the vector graphics renderer `hpgs_paint_device`.

The dcomumentation of `hpgs_paint_clipper_st` explains the concepts used throughout the implementation of the objects in this module.

## Function Documentation

HPGS_INTERNAL_API hpgs_paint_clipper* hpgs_new_paint_clipper | ( | const hpgs_bbox * | bb,
|  | int | height,
|  | int | scanline_msize,
|  | int | overscan |
| ) |  |  |

Returns a new clipper on the heap, which covers the given bounding box an applies to an image with `height` rows.

`scanline_msize` determines the number of intersection points, for which memory is preallocated in each scanline.

The value of `overscan` determines the type of antialiasing applied as described under `hpgs_paint_device_st::overscan`.

Use `hpgs_paint_clipper_destroy` in order to destroy the returned `hpgs_paint_clipper` from the heap.

Returns a null pointer, if the system is out of memory.

References hpgs_paint_clipper_st::bb, hpgs_paint_clipper_st::height, hpgs_paint_clipper_st::iscan0, hpgs_paint_clipper_st::iscan1, hpgs_bbox_st::lly, hpgs_paint_clipper_st::n_scanlines, hpgs_paint_clipper_st::overscan, hpgs_paint_clipper_st::scanlines, hpgs_bbox_st::ury, hpgs_paint_clipper_st::y0, and hpgs_paint_clipper_st::yfac.

Referenced by hpgs_new_paint_device(), and hpgs_paint_clipper_clip().

HPGS_INTERNAL_API void hpgs_paint_clipper_clear | ( | hpgs_paint_clipper * | c | ) |

Resets a clipper to be completely empty .

- 0 Sucess.
- -1 The system is out of memory.

References hpgs_paint_clipper_st::iscan0, hpgs_paint_clipper_st::iscan1, hpgs_paint_scanline_st::n_points, hpgs_paint_clipper_st::n_scanlines, and hpgs_paint_clipper_st::scanlines.

Referenced by hpgs_paint_device_clip(), and hpgs_paint_device_fill().

HPGS_INTERNAL_API hpgs_paint_clipper* hpgs_paint_clipper_clip | ( | const hpgs_paint_clipper * | orig,
|  | const hpgs_paint_clipper * | clip,
|  | hpgs_bool | winding |
| ) |  |  |

Returna a new clipper on the heap, which holds the intersection of the given path clipper with the current clip clipper.

If `winding` is `HPGS_TRUE`, the non-zero winding rule is used for the path intersection, otherwise the exclusive-or rule applies.

Use `hpgs_paint_clipper_destroy` in order to destroy the returned `hpgs_paint_clipper` from the heap.

Returns a null pointer, if the system is out of memory.

References hpgs_paint_clipper_st::bb, hpgs_paint_clipper_st::height, hpgs_log(), hpgs_new_paint_clipper(), hpgs_paint_clipper_destroy(), hpgs_paint_clipper_st::iscan0, hpgs_paint_clipper_st::iscan1, hpgs_paint_clipper_st::n_scanlines, hpgs_paint_clipper_st::overscan, and hpgs_paint_clipper_st::scanlines.

Referenced by hpgs_paint_device_clip().

HPGS_INTERNAL_API int hpgs_paint_clipper_cut | ( | hpgs_paint_clipper * | c,
|  | hpgs_paint_path * | path |
| ) |  |  |

Cuts te given `path` with the scanlines of the given clipper `c`. If you emit the clipper afterwards, the interior of the given path is drawn to the image.

If you want to stroke the path use either `hpgs_paint_clipper_thin_cut` for thin lines or contruct the outline of a thick line using the line style of a graphics state with `hpgs_paint_path_stroke_path`.

Return value:

- 0 Success.
- -1 The system is out of memory.

References hpgs_paint_clipper_st::overscan.

Referenced by hpgs_paint_device_clip(), and hpgs_paint_device_fill().

HPGS_INTERNAL_API void hpgs_paint_clipper_destroy | ( | hpgs_paint_clipper * | c | ) |

Destroys a clipper from the heap.

References hpgs_paint_clipper_st::n_scanlines, and hpgs_paint_clipper_st::scanlines.

Referenced by hpgs_new_paint_device(), hpgs_paint_clipper_clip(), and hpgs_paint_device_clip().

HPGS_INTERNAL_API int hpgs_paint_clipper_emit | ( | hpgs_image * | image,
|  | const hpgs_paint_clipper * | img,
|  | const hpgs_paint_clipper * | clip,
|  | const hpgs_paint_color * | c,
|  | hpgs_bool | winding,
|  | hpgs_bool | stroke |
| ) |  |  |

Emits the intersection of the visible segments of the given clippers `img` and `clip` to the given image `img` using the given color `c`.

If `stroke` is `HPGS_TRUE`, zero-width segments are also emitted, which is feasible for clippers retrieved through `hpgs_paint_clipper_thin_cut`.

If `winding` is `HPGS_TRUE`, the non-zero winding rule is used for the segment intersection, otherwise the exclusive-or rule applies.

Return values:

- 0 Sucess.
- -1 The system is out of memory or an error from the image has occurred.

References hpgs_paint_clipper_st::bb, hpgs_paint_clipper_st::height, hpgs_image_st::height, hpgs_log(), hpgs_paint_clipper_st::iscan0, hpgs_paint_clipper_st::iscan1, hpgs_bbox_st::llx, hpgs_paint_clipper_st::n_scanlines, hpgs_paint_clipper_st::overscan, hpgs_paint_clipper_st::scanlines, and hpgs_bbox_st::urx.

Referenced by hpgs_paint_device_fill().

HPGS_INTERNAL_API int hpgs_paint_clipper_reset | ( | hpgs_paint_clipper * | c,
|  | double | llx,
|  | double | urx |
| ) |  |  |

Resets a clipper to be empty and to cover the whole rectanlge of an image covering the `x` coordinates in the range from `llx` to `urx`.

- 0 Sucess.
- -1 The system is out of memory.

References hpgs_paint_clipper_st::iscan0, hpgs_paint_clipper_st::iscan1, hpgs_paint_scanline_st::n_points, hpgs_paint_clipper_st::n_scanlines, hpgs_paint_clipper_st::overscan, and hpgs_paint_clipper_st::scanlines.

Referenced by hpgs_new_paint_device().

HPGS_INTERNAL_API int hpgs_paint_clipper_thin_cut | ( | hpgs_paint_clipper * | c,
|  | hpgs_paint_path * | path,
|  | const hpgs_gstate * | gstate |
| ) |  |  |

Cuts the border of the given `path` with the scanlines of the given clipper `c`. The linewidth of the given `gstate` is ignored and an optimized algorithm is used in order to retrieve the cut of the border of the path as if the linewidth has been exactly one pixel of the underlying image.

Return value:

- 0 Success.
- -1 The system is out of memory.

References hpgs_paint_clipper_st::bb, hpgs_paint_path_st::bb, hpgs_log(), hpgs_paint_clipper_st::iscan0, hpgs_bbox_st::llx, hpgs_bbox_st::lly, hpgs_gstate_st::n_dashes, hpgs_paint_scanline_st::n_points, hpgs_paint_path_st::n_points, hpgs_scanline_point_st::order, hpgs_paint_scanline_st::points, hpgs_paint_clipper_st::scanlines, hpgs_bbox_st::urx, hpgs_bbox_st::ury, and hpgs_scanline_point_st::x.