use std::sync::Arc;
use crate::object::{NameId, ObjectId};
use crate::page_ir::{
BlendMode, FillRule, ImageColorSpace, ImageSMask, LineCap, LineJoin, MaskKind, Matrix,
PageBounds, PathData, Rect,
};
macro_rules! handle {
($(#[$doc:meta])* $name:ident) => {
$(#[$doc])*
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct $name(pub u32);
impl $name {
pub fn index(self) -> usize {
self.0 as usize
}
}
};
}
handle!(
PathId
);
handle!(
TextRunId
);
handle!(
ActualTextSpanId
);
handle!(
ImageId
);
handle!(
FontId
);
handle!(
ShadingId
);
handle!(
TilingId
);
#[derive(Debug, Clone, PartialEq)]
pub enum SemColor {
DeviceGray(f64),
DeviceRgb(f64, f64, f64),
DeviceCmyk(f64, f64, f64, f64),
Components {
space: NameId,
values: Vec<f64>,
},
Pattern {
name: NameId,
under: Option<Box<SemColor>>,
},
ShadingPattern {
shading: ShadingId,
matrix: Matrix,
},
TilingPattern {
tiling: TilingId,
matrix: Matrix,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum TextElement {
Show(Vec<u8>),
Adjust(f64),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActualTextSpan {
pub id: ActualTextSpanId,
pub utf16: Arc<[u16]>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TextRun {
pub font: FontId,
pub font_size: f64,
pub render_mode: u8,
pub char_spacing: f64,
pub word_spacing: f64,
pub horizontal_scale: f64,
pub rise: f64,
pub text_matrix: Matrix,
pub elements: Arc<[TextElement]>,
pub visible: bool,
pub actual_text: Option<ActualTextSpan>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SemFont {
pub resource_name: NameId,
pub object: Option<ObjectId>,
pub subtype: Vec<u8>,
pub base_font: Vec<u8>,
pub metrics: Arc<crate::font::FontMetrics>,
pub program: Option<Arc<[u8]>>,
pub face_index: u32,
pub glyph_map: Arc<crate::font::GlyphMap>,
pub synthesis: crate::font::Synthesis,
pub unicode_map: Arc<crate::font::UnicodeMap>,
pub charset: crate::font::Charset,
pub font_bbox: Option<[f64; 4]>,
pub type3_matrix: Option<Matrix>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SemImage {
pub object: Option<ObjectId>,
pub width: u32,
pub height: u32,
pub bits_per_component: u8,
pub is_mask: bool,
pub filters: Vec<Vec<u8>>,
pub inline_data: Vec<u8>,
pub color_space: Option<ImageColorSpace>,
pub interpolate: bool,
pub decode: Option<Vec<[f32; 2]>>,
pub samples: Option<Arc<[u8]>>,
pub codec: Option<crate::page_ir::ImageCodecKind>,
pub codec_data: Option<crate::page_ir::SharedBytes>,
pub codec_parms: Option<crate::page_ir::CodecParms>,
pub smask: Option<Arc<ImageSMask>>,
pub mask: Option<crate::page_ir::ImageMask>,
pub smask_in_data: u8,
pub lowering_degraded: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SemShading {
pub object: Option<ObjectId>,
pub kind: SemShadingKind,
pub bbox: Option<[f32; 4]>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum SemShadingKind {
Axial {
coords: [f64; 4],
domain: [f64; 2],
extend: [bool; 2],
ramp: Vec<[f32; 4]>,
background: Option<[f32; 4]>,
},
Radial {
coords: [f64; 6],
domain: [f64; 2],
extend: [bool; 2],
ramp: Vec<[f32; 4]>,
background: Option<[f32; 4]>,
},
MeshTriangles {
shading_type: u8,
triangles: Vec<[SemMeshVertex; 3]>,
background: Option<[f32; 4]>,
},
MeshPatches {
shading_type: u8,
patches: Vec<SemMeshPatch>,
background: Option<[f32; 4]>,
},
FunctionGrid {
domain: [f64; 4],
matrix: Matrix,
grid_w: u32,
grid_h: u32,
colors: Vec<[f32; 4]>,
background: Option<[f32; 4]>,
},
Unsupported {
background: Option<[f32; 4]>,
},
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SemMeshVertex {
pub x: f64,
pub y: f64,
pub color: [f32; 4],
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SemMeshPatch {
pub points: [[f64; 2]; 16],
pub colors: [[f32; 4]; 4],
}
#[derive(Debug, Clone, PartialEq)]
pub struct SemTiling {
pub object: Option<ObjectId>,
pub uncolored: bool,
pub under_color: [f32; 4],
pub bbox: [f64; 4],
pub x_step: f64,
pub y_step: f64,
pub cell: Arc<SemanticPage>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum SemanticOp {
Save,
Restore,
Concat(Matrix),
SetLineWidth(f64),
SetLineCap(LineCap),
SetLineJoin(LineJoin),
SetMiterLimit(f64),
SetDash {
pattern: Vec<f64>,
phase: f64,
},
SetFillColor(SemColor),
SetStrokeColor(SemColor),
SetFillAlpha(f32),
SetStrokeAlpha(f32),
SetBlendMode(BlendMode),
Fill {
path: PathId,
rule: FillRule,
},
Stroke {
path: PathId,
},
FillStroke {
path: PathId,
rule: FillRule,
},
Clip {
path: PathId,
rule: FillRule,
},
ClipText {
runs: Vec<TextRunId>,
},
ShowText(TextRunId),
DrawImage(ImageId),
BeginPaintOrigin(crate::page_ir::PaintOrigin),
EndPaintOrigin,
PaintShading(ShadingId),
BeginGroup {
isolated: bool,
knockout: bool,
bounds: Rect,
opacity: f32,
blend: BlendMode,
},
EndGroup,
BeginSoftMask {
kind: MaskKind,
transfer: Option<crate::page_ir::TransferLut>,
},
EndSoftMask,
ClearSoftMask,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SemanticPage {
pub bounds: PageBounds,
pub ops: Arc<[SemanticOp]>,
pub paths: Arc<[PathData]>,
pub text_runs: Arc<[TextRun]>,
pub images: Arc<[SemImage]>,
pub fonts: Arc<[SemFont]>,
pub shadings: Arc<[SemShading]>,
pub tilings: Arc<[SemTiling]>,
pub uses_icc_color: bool,
pub uses_overprint: bool,
}
impl SemanticPage {
pub fn empty(bounds: PageBounds) -> Self {
Self {
bounds,
ops: Arc::from([]),
paths: Arc::from([]),
text_runs: Arc::from([]),
images: Arc::from([]),
fonts: Arc::from([]),
shadings: Arc::from([]),
tilings: Arc::from([]),
uses_icc_color: false,
uses_overprint: false,
}
}
}
const fn _assert_send_sync<T: Send + Sync>() {}
const _: () = _assert_send_sync::<SemanticPage>();