pub struct Rasterizer { /* private fields */ }
Expand description

Coverage rasterizer for lines, quadratic & cubic beziers.

Implementations§

Allocates a new rasterizer that can draw onto a width x height alpha grid.

use ab_glyph_rasterizer::Rasterizer;
let mut rasterizer = Rasterizer::new(14, 38);

Resets the rasterizer to an empty width x height alpha grid. This method behaves as if the Rasterizer were re-created, with the advantage of not allocating if the total number of pixels of the grid does not increase.

rasterizer.reset(12, 24);
assert_eq!(rasterizer.dimensions(), (12, 24));

Clears the rasterizer. This method behaves as if the Rasterizer were re-created with the same dimensions, but does not perform an allocation.

rasterizer.clear();

Returns the dimensions the rasterizer was built to draw to.

let rasterizer = Rasterizer::new(9, 8);
assert_eq!((9, 8), rasterizer.dimensions());

Adds a straight line from p0 to p1 to the outline.

rasterizer.draw_line(point(0.0, 0.48), point(1.22, 0.48));

Adds a quadratic Bézier curve from p0 to p2 to the outline using p1 as the control.

rasterizer.draw_quad(point(6.2, 34.5), point(7.2, 34.5), point(9.2, 34.0));

Adds a cubic Bézier curve from p0 to p3 to the outline using p1 as the control at the beginning of the curve and p2 at the end of the curve.

rasterizer.draw_cubic(
    point(10.3, 16.4),
    point(8.6, 16.9),
    point(7.7, 16.5),
    point(8.2, 15.2),
);

Run a callback for each pixel index & alpha, with indices in 0..width * height.

An alpha coverage value of 0.0 means the pixel is not covered at all by the glyph, whereas a value of 1.0 (or greater) means the pixel is totally covered.

let mut pixels = vec![0u8; width * height];
rasterizer.for_each_pixel(|index, alpha| {
    pixels[index] = (alpha * 255.0) as u8;
});

Run a callback for each pixel x position, y position & alpha.

Convenience wrapper for Rasterizer::for_each_pixel.

rasterizer.for_each_pixel_2d(|x, y, alpha| {
    image.set_pixel(x, y, (alpha * 255.0) as u8);
});

Trait Implementations§

let rasterizer = ab_glyph_rasterizer::Rasterizer::new(3, 4);
assert_eq!(
    &format!("{:?}", rasterizer),
    "Rasterizer { width: 3, height: 4 }"
);
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.