Skip to content

Commit

Permalink
Run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
reknih committed Feb 16, 2024
1 parent 4379dcd commit ad7d0a5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
47 changes: 25 additions & 22 deletions examples/video.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
//! This example demonstrates how to link/embed videos.
use image::ColorType;
use pdf_writer::types::{
ActionType, AnnotationType, MediaClipType, RenditionType,
RenditionOperation, TempFileType
ActionType, AnnotationType, MediaClipType, RenditionOperation, RenditionType,
TempFileType,
};
use pdf_writer::{Content, Finish, Pdf, Rect, Ref, Str, TextStr, Name, Filter};
use image::ColorType;

use pdf_writer::{Content, Filter, Finish, Name, Pdf, Rect, Ref, Str, TextStr};

fn get_bbox(page: &Rect, mut w: f32, mut h: f32) -> Rect {
// Limit the width and height of the object to the page size, retaining the
// aspect ratio.
if w > (page.x2 - page.x1) {
let f = (page.x2 - page.x1)/w;
let f = (page.x2 - page.x1) / w;
w *= f;
h *= f;
}
if h > (page.y2 - page.y1) {
let f = (page.y2 - page.y1)/h;
let f = (page.y2 - page.y1) / h;
w *= f;
h *= f;
}

// Return a bounding box for the object centered on the page.
Rect::new((page.x2 - w)/2.0,
(page.y2 - h)/2.0,
(page.x2 + w)/2.0,
(page.y2 + h)/2.0)
Rect::new(
(page.x2 - w) / 2.0,
(page.y2 - h) / 2.0,
(page.x2 + w) / 2.0,
(page.y2 + h) / 2.0,
)
}


fn main() -> std::io::Result<()> {
let embedded = true;

Expand Down Expand Up @@ -75,9 +75,7 @@ fn main() -> std::io::Result<()> {
image.finish();

// Get a centered and fitted bounding box for the screen annotation and image.
let bbox = get_bbox(&a4_landscape,
dynamic.width() as f32,
dynamic.height() as f32);
let bbox = get_bbox(&a4_landscape, dynamic.width() as f32, dynamic.height() as f32);

// Place and size the image in a content stream.
//
Expand All @@ -90,12 +88,14 @@ fn main() -> std::io::Result<()> {
// restore the state so that they are not affected by the transformation.
let mut content = Content::new();
content.save_state();
content.transform([(bbox.x2 - bbox.x1),
0.0,
0.0,
(bbox.y2 - bbox.y1),
bbox.x1,
bbox.y1]);
content.transform([
(bbox.x2 - bbox.x1),
0.0,
0.0,
(bbox.y2 - bbox.y1),
bbox.x1,
bbox.y1,
]);
content.x_object(image_name);
content.restore_state();
let content_data = content.finish();
Expand Down Expand Up @@ -141,7 +141,10 @@ fn main() -> std::io::Result<()> {
let mut media_clip = rendition.media_clip();
media_clip.subtype(MediaClipType::Data);
if embedded {
media_clip.data().path(Str(file_name.as_encoded_bytes())).embedded_file(video_file_id);
media_clip
.data()
.path(Str(file_name.as_encoded_bytes()))
.embedded_file(video_file_id);
} else {
// FIXME: Is there a more elegant way to assemble the URL?
let file_url = &[b"file://", file_path.as_os_str().as_encoded_bytes()].concat();
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ mod font;
mod forms;
mod functions;
mod object;
mod renumber;
mod renditions;
mod renumber;
mod structure;
mod transitions;
mod xobject;
Expand Down Expand Up @@ -135,7 +135,7 @@ pub mod writers {
ExponentialFunction, PostScriptFunction, SampledFunction, StitchingFunction,
};
pub use object::{NameTree, NameTreeEntries, NumberTree, NumberTreeEntries};
pub use renditions::{Rendition, MediaClip, MediaPlayParams, MediaPermissions};
pub use renditions::{MediaClip, MediaPermissions, MediaPlayParams, Rendition};
pub use structure::{
Catalog, ClassMap, Destination, DeveloperExtension, DocumentInfo, MarkInfo,
MarkedRef, Metadata, Names, ObjectRef, Outline, OutlineItem, Page, PageLabel,
Expand Down
5 changes: 2 additions & 3 deletions src/renditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ impl<'a> MediaClip<'a> {
self
}


/// Write the `/N` attribute. Specifies the name of the media clip, for use
/// in the user interface.
pub fn name(&mut self, text: TextStr) -> &mut Self {
Expand Down Expand Up @@ -112,7 +111,7 @@ impl<'a> MediaClip<'a> {
/// array shall contain pairs of strings.
pub fn alt_texts<'b>(
&mut self,
texts: impl IntoIterator<Item = TextStr<'b>>
texts: impl IntoIterator<Item = TextStr<'b>>,
) -> &mut Self {
self.insert(Name(b"Alt")).array().items(texts);
self
Expand Down Expand Up @@ -141,7 +140,7 @@ impl<'a> MediaPlayParams<'a> {
/// This avoids implementing the "must honour" (MH) or "best effort" (BE)
/// dictionaries for MediaPlayParams, as the required boiler-plate code
/// would be high, and its usefulness low.
pub fn controls (&mut self, c: bool) -> &mut Self {
pub fn controls(&mut self, c: bool) -> &mut Self {
self.insert(Name(b"BE")).dict().pair(Name(b"C"), c);
self
}
Expand Down

0 comments on commit ad7d0a5

Please sign in to comment.