Struct ab_glyph_rasterizer::Rasterizer[][src]

pub struct Rasterizer { /* fields omitted */ }

Coverage rasterizer for lines, quadratic & cubic beziers.

Implementations

impl Rasterizer[src]

pub fn new(width: usize, height: usize) -> Self[src]

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);

pub fn reset(&mut self, width: usize, height: usize)[src]

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));

pub fn clear(&mut self)[src]

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();

pub fn dimensions(&self) -> (usize, usize)[src]

Returns the dimensions the rasterizer was built to draw to.

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

pub fn draw_line(&mut self, p0: Point, p1: Point)[src]

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

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

pub fn draw_quad(&mut self, p0: Point, p1: Point, p2: Point)[src]

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));

pub fn draw_cubic(&mut self, p0: Point, p1: Point, p2: Point, p3: Point)[src]

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),
);

pub fn for_each_pixel<O: FnMut(usize, f32)>(&self, px_fn: O)[src]

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

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

pub fn for_each_pixel_2d<O: FnMut(u32, u32, f32)>(&self, px_fn: O)[src]

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

Convenience wrapper for for_each_pixel.

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

Trait Implementations

impl Debug for Rasterizer[src]

let rasterizer = ab_glyph_rasterizer::Rasterizer::new(3, 4);
assert_eq!(&format!("{:?}", rasterizer), "Rasterizer { width: 3, height: 4 }");

Auto Trait Implementations

impl RefUnwindSafe for Rasterizer

impl Send for Rasterizer

impl Sync for Rasterizer

impl Unpin for Rasterizer

impl UnwindSafe for Rasterizer

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.