DotMatrixGfx

Trait DotMatrixGfx 

Source
pub trait DotMatrixGfx {
    // Required methods
    fn is_spooling(&self) -> bool;
    fn lines_buffered(&self) -> usize;
    fn clear(&mut self);
    fn write_svg_dot_gfx_lines(
        &self,
        description: &str,
        target: &mut dyn Write,
    ) -> Result<bool>;
    fn write_gfx_data(&mut self, target: &mut Vec<u8>) -> Option<(u32, u32)>;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A trait for dot matrix printer spoolers that can produce monochromatic images.

This trait defines an interface for the emulator program to be able to produce buffered images.

Required Methods§

Source

fn is_spooling(&self) -> bool

Returns true if the printer is currently capturing data. Returns false otherwise.

Source

fn lines_buffered(&self) -> usize

Returns an approximate number of graphic lines already buffered.

Source

fn clear(&mut self)

Clears the buffered image data.

Source

fn write_svg_dot_gfx_lines( &self, description: &str, target: &mut dyn Write, ) -> Result<bool>

Renders already buffered image data as an SVG image written to the provided target. Returns Ok(true) if an image has been rendered. If there was no image data spooled, returns Ok(false).

Source

fn write_gfx_data(&mut self, target: &mut Vec<u8>) -> Option<(u32, u32)>

Renders already buffered image data as a monochrome 8-bit greyscale image data. Returns Some(width, height) if an image has been rendered. If there was no image data spooled, returns None.

You may use image crate to render an actual image in some popular format:

let mut buf: Vec<u8> = Vec::new();
if let Some((width, height)) = printer.write_gfx_data(&mut buf) {
    let img = image::ImageBuffer::<image::Luma<u8>, _>::from_vec(width, height, buf);
    img.save("printed.png").unwrap();
    // or alternatively
    image::save_buffer("printed.png", &buf, width, height, image::ColorType::L8).unwrap();
}

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if no image has been buffered. Otherwise returns false

Implementors§