Skip to content

Commit

Permalink
Add Operation constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
J-F-Liu committed Jan 29, 2017
1 parent 5210eb3 commit e259ccf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ let resources_id = doc.add_object(
])
);
let content = Content{operations: vec![
Operation{operator: "BT".into(), operands: vec![]},
Operation{operator: "Tf".into(), operands: vec!["F1".into(), 48.into()]},
Operation{operator: "Td".into(), operands: vec![100.into(), 600.into()]},
Operation{operator: "Tj".into(), operands: vec![String("Hello World!".as_bytes().to_vec(), StringFormat::Literal)]},
Operation{operator: "ET".into(), operands: vec![]},
Operation::new("BT", vec![]),
Operation::new("Tf", vec!["F1".into(), 48.into()]),
Operation::new("Td", vec![100.into(), 600.into()]),
Operation::new("Tj", vec![String("Hello World!".as_bytes().to_vec(), StringFormat::Literal)]),
Operation::new("ET", vec![]),
]};
let content_id = doc.add_object(Stream::new(Dictionary::new(), content.encode().unwrap()));
let page_id = doc.add_object(
Expand Down
9 changes: 9 additions & 0 deletions src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ pub struct Operation {
pub operands: Vec<Object>,
}

impl Operation {
pub fn new(operator: &str, operands: Vec<Object>) -> Operation {
Operation{
operator: operator.to_string(),
operands: operands,
}
}
}

#[derive(Debug, Clone)]
pub struct Content {
pub operations: Vec<Operation>,
Expand Down
10 changes: 5 additions & 5 deletions src/creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ fn create_document() {
])
);
let content = Content{operations: vec![
Operation{operator: "BT".into(), operands: vec![]},
Operation{operator: "Tf".into(), operands: vec!["F1".into(), 48.into()]},
Operation{operator: "Td".into(), operands: vec![100.into(), 600.into()]},
Operation{operator: "Tj".into(), operands: vec![String("Hello World!".as_bytes().to_vec(), StringFormat::Literal)]},
Operation{operator: "ET".into(), operands: vec![]},
Operation::new("BT", vec![]),
Operation::new("Tf", vec!["F1".into(), 48.into()]),
Operation::new("Td", vec![100.into(), 600.into()]),
Operation::new("Tj", vec![String("Hello World!".as_bytes().to_vec(), StringFormat::Literal)]),
Operation::new("ET", vec![]),
]};
let content_id = doc.add_object(Stream::new(Dictionary::new(), content.encode().unwrap()));
let page_id = doc.add_object(
Expand Down

0 comments on commit e259ccf

Please sign in to comment.