use crate::BasicPdfWriter;
use crate::page::Page;
use format_bytes::write_bytes as wb;
pub struct Image<'a> {
pub obj: usize,
pub data: &'a [u8],
pub width: usize,
pub height: usize,
pub bits_per_component: u8,
pub color_space: &'a [u8],
pub other: &'a [u8],
}
impl<'a> Image<'a>
{
pub fn init(&mut self, w: &mut BasicPdfWriter) {
self.obj = w.begin();
let _ = wb!(
&mut w.b,
b"<</Type/XObject/Subtype/Image/Width {}/Height {}/ColorSpace{}/BitsPerComponent {}/Length {}{}>>stream\n",
self.width, self.height, self.color_space, self.bits_per_component, self.data.len(), self.other
);
w.b.extend_from_slice(&self.data);
w.b.extend_from_slice(b"\nendstream");
w.end();
}
pub fn draw(&self, page: &mut Page, x: f32, y: f32, scale:f32)
{
let obj = self.obj;
let w = (self.width as f32) * scale;
let h = (self.height as f32) * scale;
page.xobjs.insert(obj);
let _ = wb!(&mut page.os, b"\nq {} 0 0 {} {} {} cm /X{} Do Q", w,h,x,y,obj);
}
}