Skip to content

Commit

Permalink
Add extgstates to page resources
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Nov 9, 2024
1 parent 6f54e8f commit 75911c1
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 50 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified examples/assets/.DS_Store
Binary file not shown.
9 changes: 6 additions & 3 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,18 @@ fn main() {
let xobject_id = doc.add_xobject(&svg);

for i in 0..10 {

let transform = XObjectTransform {
rotate: Some(XObjectRotation {
angle_ccw_degrees: i as f32 * 36.0,
rotation_center_x: rotation_center_x.into_pt(300.0),
rotation_center_y: rotation_center_y.into_pt(300.0),
rotation_center_x: rotation_center_x,
rotation_center_y: rotation_center_y,
}),
translate_x: Some(Mm(i as f32 * 20.0 % 50.0).into()),
translate_y: Some(Mm(i as f32 * 30.0).into()),
..Default::default()
dpi: Some(300.0),
scale_x: None,
scale_y: None,
};

ops.extend_from_slice(&[
Expand Down
87 changes: 78 additions & 9 deletions src/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ pub struct PageAnnotation {
pub struct LinkAnnotation {
pub rect: Rect,
pub border: BorderArray,
pub c: ColorArray,
pub a: Actions,
pub h: HighlightingMode,
pub color: ColorArray,
pub actions: Actions,
pub highlighting: HighlightingMode,
}

impl LinkAnnotation {
/// Creates a new LinkAnnotation
pub fn new(
rect: Rect,
actions: Actions,
border: Option<BorderArray>,
c: Option<ColorArray>,
a: Actions,
h: Option<HighlightingMode>,
color: Option<ColorArray>,
highlighting: Option<HighlightingMode>,
) -> Self {
Self {
rect,
border: border.unwrap_or_default(),
c: c.unwrap_or_default(),
a,
h: h.unwrap_or_default(),
color: color.unwrap_or_default(),
actions,
highlighting: highlighting.unwrap_or_default(),
}
}
}
Expand All @@ -44,6 +44,31 @@ pub enum BorderArray {
Dashed([f32; 3], DashPhase),
}

impl BorderArray {
pub fn to_array(&self) -> Vec<f32> {
match self {
BorderArray::Solid(s) => s.to_vec(),
BorderArray::Dashed(s, dash_phase) => {
let mut s = s.to_vec();
s.push(dash_phase.phase);
s
},
}
}
}

/*
impl Into<Object> for DashPhase {
fn into(self) -> Object {
Object::Array(vec![
Object::Array(self.dash_array.into_iter().map(|x| Object::Real(x.into())).collect()),
Object::Real(self.phase.into()),
])
}
}
*/

impl Default for BorderArray {
fn default() -> Self {
BorderArray::Solid([0.0, 0.0, 1.0])
Expand Down Expand Up @@ -86,13 +111,45 @@ pub enum Destination {
},
}

/*
GoTo Go to a destination in the current document. “Go-To Actions” on page 654
GoToR (“Go-to remote”) Go to a destination in another document. “Remote Go-To Actions” on page 655
GoToE (“Go-to embedded”; PDF 1.6) Go to a destination in an embedded file. “Embedded Go-To Actions” on page 655
Launch Launch an application, usually to open a file. “Launch Actions” on page 659
Thread Begin reading an article thread. “Thread Actions” on page 661
URI Resolve a uniform resource identifier. “URI Actions” on page 662
Sound (PDF 1.2) Play a sound. “Sound Actions” on page 663
Movie (PDF 1.2) Play a movie. “Movie Actions” on page 664
Hide (PDF 1.2) Set an annotation’s Hidden flag. “Hide Actions” on page 665
Named (PDF 1.2) Execute an action predefined by the viewer application. “Named Actions” on page 666
SubmitForm (PDF 1.2) Send data to a uniform resource locator. “Submit-Form Actions” on page 703
ResetForm (PDF 1.2) Set fields to their default values. “Reset-Form Actions” on page 707
ImportData (PDF 1.2) Import field values from a file. “Import-Data Actions” on page 708
JavaScript (PDF 1.3) Execute a JavaScript script. “JavaScript Actions” on page 709
SetOCGState (PDF 1.5) Set the states of optional content groups. “Set-OCG-State Actions” on page 667
Rendition (PDF 1.5) Controls the playing of multimedia content. “Rendition Actions” on page 668
Trans (PDF 1.5) Updates the display of a document, using a transition dictionary. “Transition Actions” on page 670
GoTo3DView (PDF 1.6) Set the current view of a 3D annotation “Go-To-3D-View Actions” on page 670
*/
#[derive(Debug, PartialEq, Clone)]
pub enum Actions {
GoTo(Destination),
URI(String),
}

impl Actions {

/// 8.5.3 Action Types: PDF supports the standard action types listed in Table 8.48.
///
/// The following sections describe each of these types in detail.
/// Plug-in extensions may add new action types.
pub fn get_action_type_id(&self) -> &'static str {
match self {
Actions::GoTo(_) => "GoTo",
Actions::URI(_) => "URI",
}
}

pub fn go_to(destination: Destination) -> Self {
Self::GoTo(destination)
}
Expand All @@ -115,3 +172,15 @@ impl Default for HighlightingMode {
HighlightingMode::Invert
}
}

impl HighlightingMode {
pub fn get_id(&self) -> &'static str {
use self::HighlightingMode::*;
match self {
None => "N",
Invert => "I",
Outline => "O",
Push => "P",
}
}
}
Empty file removed src/extgstate.rs
Empty file.
Loading

0 comments on commit 75911c1

Please sign in to comment.