use crate::object::ObjectId;
use crate::page_ir::PaintOrigin;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TraceFrameKind {
FormXObject,
AnnotationAppearance,
TilingPattern,
ShadingPattern,
Shading,
Type3Glyph,
SoftMask,
}
impl TraceFrameKind {
pub fn paint_origin(self) -> Option<PaintOrigin> {
match self {
Self::FormXObject => Some(PaintOrigin::FormXObject),
Self::AnnotationAppearance => Some(PaintOrigin::AnnotationAppearance),
Self::TilingPattern | Self::ShadingPattern | Self::Shading => None,
Self::Type3Glyph => Some(PaintOrigin::Type3Glyph),
Self::SoftMask => Some(PaintOrigin::SoftMaskContent),
}
}
pub fn name(self) -> &'static str {
match self {
Self::FormXObject => "form-xobject",
Self::AnnotationAppearance => "annotation-appearance",
Self::TilingPattern => "tiling-pattern",
Self::ShadingPattern => "shading-pattern",
Self::Shading => "shading",
Self::Type3Glyph => "type3-glyph",
Self::SoftMask => "soft-mask",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TraceFrame {
pub kind: TraceFrameKind,
pub object: Option<ObjectId>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct OpTrace {
pub op_index: usize,
pub content_op_index: u64,
pub operator: Vec<u8>,
pub synthesized: bool,
pub stream: Option<ObjectId>,
pub stack: Vec<TraceFrame>,
pub span: (usize, usize),
pub origin: PaintOrigin,
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct PageTrace {
pub entries: Vec<OpTrace>,
}
impl PageTrace {
pub fn len(&self) -> usize {
self.entries.len()
}
pub fn is_empty(&self) -> bool {
self.entries.is_empty()
}
pub fn for_op(&self, op_index: usize) -> Option<&OpTrace> {
self.entries.get(op_index)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct ContentSegment {
pub object: Option<ObjectId>,
pub start: usize,
pub len: usize,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct TraceCurrent {
pub operator: Vec<u8>,
pub span_start: usize,
pub span_end: usize,
pub seq: u64,
}