use pdf_writer::Ref;
#[derive(Clone, Copy, Eq, PartialEq)]
pub struct RefAllocator {
ref_alloc: Ref,
}
impl RefAllocator {
pub fn new() -> Self {
Self { ref_alloc: Ref::new(1) }
}
pub fn alloc_ref(&mut self) -> Ref {
self.ref_alloc.bump()
}
}
#[derive(Clone, Copy, Eq, PartialEq, Default)]
pub struct NameAllocator {
next_x_object_num: i32,
next_graphics_state_num: i32,
next_patterns_num: i32,
next_shadings_num: i32,
next_fonts_num: i32,
next_color_space_num: i32,
}
impl NameAllocator {
pub fn alloc_x_object_name(&mut self) -> String {
let num = self.next_x_object_num;
self.next_x_object_num += 1;
format!("xo{}", num)
}
pub fn alloc_graphics_state_name(&mut self) -> String {
let num = self.next_graphics_state_num;
self.next_graphics_state_num += 1;
format!("gs{}", num)
}
pub fn alloc_pattern_name(&mut self) -> String {
let num = self.next_patterns_num;
self.next_patterns_num += 1;
format!("po{}", num)
}
pub fn alloc_shading_name(&mut self) -> String {
let num = self.next_shadings_num;
self.next_shadings_num += 1;
format!("sh{}", num)
}
pub fn alloc_font_name(&mut self) -> String {
let num = self.next_fonts_num;
self.next_fonts_num += 1;
format!("fo{}", num)
}
pub fn alloc_color_space_name(&mut self) -> String {
let num = self.next_color_space_num;
self.next_color_space_num += 1;
format!("cs{}", num)
}
}