The Rasterizer is used to perform coverage rasterization for lines, quadratic beziers, and cubic beziers. This is particularly useful for drawing .otf font glyphs.
To use it:
- Initialize a
Rasterizer with a specific width and height. - Use
draw_line, draw_quad, or draw_cubic to draw outlines onto the rasterizer. - Use
for_each_pixel to iterate over the resulting pixel alpha values (e.g., to save them to a buffer).
Note: You must activate either the std or libm feature in your configuration.
use ab_glyph_rasterizer::Rasterizer;
use ab_glyph_rasterizer::point;
let (width, height) = (100, 100);
let mut rasterizer = Rasterizer::new(width, height);
// Define points using the point() helper
let [l0, l1, q0, q1, q2, c0, c1, c2, c3] = [point(0.0, 0.0); 9];
// Draw outlines
rasterizer.draw_line(l0, l1);
rasterizer.draw_quad(q0, q1, q2);
rasterizer.draw_cubic(c0, c1, c2, c3);
// Iterate over the resultant pixel alphas
rasterizer.for_each_pixel(|index, alpha| {
// index is the pixel index, alpha is the coverage value
// e.g., save pixel to a buffer
});