# Trait ColorPainter

    pub trait ColorPainter {
        // Required methods
        fn push_transform(&mut self, transform: Transform);
        fn pop_transform(&mut self);
        fn push_clip_glyph(&mut self, glyph_id: GlyphId);
        fn push_clip_box(&mut self, clip_box: BoundingBox<f32>);
        fn pop_clip(&mut self);
        fn fill(&mut self, brush: Brush<'_>);
        fn push_layer(&mut self, composite_mode: CompositeMode);

        // Provided methods
        fn fill_glyph(
            &mut self,
            glyph_id: GlyphId,
            brush_transform: Option<Transform>,
            brush: Brush<'_>,
        ) { ... }
        fn paint_cached_color_glyph(
            &mut self,
            _glyph: GlyphId,
        ) -> Result<PaintCachedColorGlyph, PaintError> { ... }
        fn pop_layer(&mut self) { ... }
        fn pop_layer_with_mode(&mut self, _composite_mode: CompositeMode) { ... }
    }

Expand description

A group of required painting callbacks to be provided by the client.

Each callback is executing a particular drawing or canvas transformation operation. The trait’s callback functions are invoked when `paint` is called with a `ColorPainter` trait object. The documentation for each function describes what actions are to be executed using the client side 2D graphics API, usually by performing some kind of canvas operation.

## Required Methods§

#### fn push_transform(&mut self, transform: Transform)

Push the specified transform by concatenating it to the current transformation matrix.

#### fn pop_transform(&mut self)

Restore the transformation matrix to the state before the previous `push_transform` call.

#### fn push_clip_glyph(&mut self, glyph_id: GlyphId)

Apply a clip path in the shape of glyph specified by `glyph_id`.

#### fn push_clip_box(&mut self, clip_box: BoundingBox<f32>)

Apply a clip rectangle specified by `clip_rect`.

#### fn pop_clip(&mut self)

Restore the clip state to the state before a previous `push_clip_glyph` or `push_clip_box` call.

#### fn fill(&mut self, brush: Brush<'_>)

Fill the current clip area with the specified gradient fill.

#### fn push_layer(&mut self, composite_mode: CompositeMode)

Open a new layer, and merge the layer down using `composite_mode` when `pop_layer` is called, signalling that this layer is done drawing.

## Provided Methods§

#### fn fill_glyph( &mut self, glyph_id: GlyphId, brush_transform: Option<Transform>, brush: Brush<'_>, )

Combined clip and fill operation.

Apply the clip path determined by the specified `glyph_id`, then fill it with the specified `brush`, applying the `_brush_transform` transformation matrix to the brush. The default implementation works based on existing methods in this trait. It is recommended for clients to override the default implementaition with a custom combined clip and fill operation. In this way overriding likely results in performance gains depending on performance characteristics of the 2D graphics stack that these calls are mapped to.

#### fn paint_cached_color_glyph( &mut self, _glyph: GlyphId, ) -> Result<PaintCachedColorGlyph, PaintError>

Optionally implement this method: Draw an unscaled COLRv1 glyph given the current transformation matrix (as accumulated by `push_transform` calls).

#### fn pop_layer(&mut self)

Merge the pushed layer down using `composite_mode` passed to the matching `push_layer`.

#### fn pop_layer_with_mode(&mut self, _composite_mode: CompositeMode)

Alternative version of `push_layer` where the `composite_mode` is also passed to the method. This is useful for graphics libraries that need the compositing mode at layer pop time and do not want to manually track the mode.

Only one of `pop_layer` or this method need to be implemented. By default, this simply calls `pop_layer`.

## Implementors§