[][src]Trait spectrusty_utils::printer::DotMatrixGfx

pub trait DotMatrixGfx {
    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)>; fn is_empty(&self) -> bool { ... } }

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

fn is_spooling(&self) -> bool

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

fn lines_buffered(&self) -> usize

Returns an approximate number of graphic lines already buffered.

fn clear(&mut self)

Clears the buffered image data.

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

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();
}
Loading content...

Provided methods

fn is_empty(&self) -> bool

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

Loading content...

Implementors

impl DotMatrixGfx for EpsonPrinterGfx[src]

impl DotMatrixGfx for ImageSpooler[src]

Loading content...