Skip to content

Commit

Permalink
Progressing #68
Browse files Browse the repository at this point in the history
  • Loading branch information
Alastair Carey committed Feb 20, 2023
1 parent 66cbfd7 commit 77c7169
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pdfium-render"
version = "0.7.30"
version = "0.7.31"
edition = "2018"
publish = true
description = "A high-level idiomatic Rust wrapper around Pdfium, the C++ PDF library used by the Google Chromium project."
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ available at </~https://github.com/ajrcarey/pdfium-render/tree/master/examples>. T
* Document concatenation.
* Page object introspection.
* Page annotation introspection.
* Page link introspection.
* Creation of new documents and new pages.
* Creation of page objects for text, paths, and bitmaps.
* Multi-page tiled output.
Expand All @@ -87,7 +88,7 @@ an owned `PdfPages` instance. For the motivation behind this change, see
Version 0.7.31 adds the `PdfPageLinks` collection, the `PdfPage::links()` and `PdfPage::links_mut()`
functions, the `PdfLink` and `PdfDestination` structs, and fleshes out the implementation of
`PdfAction`. It is now possible to retrieve the URI of an action associated with a link using the
`PdfActionUri::uri()` function.
`PdfActionUri::uri()` function. `examples/links.rs` demonstrates the new functionality.

Version 0.7.30 corrects a potential use-after-free error in the high level interface by deprecating
the `PdfPages::delete_page_at_index()` and `PdfPages::delete_page_range()` functions in favour of
Expand Down Expand Up @@ -355,7 +356,8 @@ at </~https://github.com/ajrcarey/pdfium-render/issues>.

* 0.7.31: adds the `PdfPageLinks` collection, the `PdfPage::links()` and `PdfPage::links_mut()`
functions, the `PdfLink` and `PdfDestination` structs, the `PdfActionCommon` and `PdfActionPrivate`
traits, structs for the action types supported by Pdfium, and the `PdfActionUri::uri()` function.
traits, structs for the action types supported by Pdfium, the `PdfActionUri::uri()` function
to address </~https://github.com/ajrcarey/pdfium-render/issues/68>, and the new `examples/links.rs` example.
* 0.7.30: deprecates the `PdfPages::delete_page_at_index()` and `PdfPages::delete_page_range()` functions;
adds `PdfPage::delete()` function in response to </~https://github.com/ajrcarey/pdfium-render/issues/67>.
Deprecated items will be removed in release 0.9.0, although it may be possible to restore these
Expand Down
31 changes: 26 additions & 5 deletions examples/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ pub async fn log_page_metrics_to_console(url: String) {
.pages()
.iter()
.enumerate()
.for_each(|(index, page)| {
.for_each(|(page_index, page)| {
if let Some(label) = page.label() {
log::info!("Page {} has a label: {}", index, label);
log::info!("Page {} has a label: {}", page_index, label);
}

log::info!(
"Page {} width: {}, height: {}",
index,
page_index,
page.width().value,
page.height().value
);

for boundary in page.boundaries().iter() {
log::info!(
"Page {} has defined {:#?} box ({}, {}) - ({}, {})",
index,
page_index,
boundary.box_type,
boundary.bounds.left.value,
boundary.bounds.top.value,
Expand All @@ -74,7 +74,28 @@ pub async fn log_page_metrics_to_console(url: String) {
);
}

log::info!("Page {} has paper size {:#?}", index, page.paper_size());
log::info!(
"Page {} has paper size {:#?}",
page_index,
page.paper_size()
);

for (link_index, link) in page.links().iter().enumerate() {
log::info!(
"Page {} link {} has action of type {:?}",
page_index,
link_index,
link.action().map(|action| action.action_type())
);

// For links that have URI actions, output the destination URI.

if let Some(action) = link.action() {
if let Some(uri_action) = action.as_uri_action() {
log::info!("Link URI destination: {:#?}", uri_action.uri())
}
}
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub const __STDC_IEC_60559_COMPLEX__: u32 = 201404;
pub const __STDC_ISO_10646__: u32 = 201706;
pub const __GNU_LIBRARY__: u32 = 6;
pub const __GLIBC__: u32 = 2;
pub const __GLIBC_MINOR__: u32 = 36;
pub const __GLIBC_MINOR__: u32 = 37;
pub const _SYS_CDEFS_H: u32 = 1;
pub const __glibc_c99_flexarr_available: u32 = 1;
pub const __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI: u32 = 0;
Expand Down
5 changes: 4 additions & 1 deletion src/destination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub struct PdfDestination<'a> {
}

impl<'a> PdfDestination<'a> {
// TODO: AJRC - 18/2/23 - as the PdfDestination struct is fleshed out, the example at
// examples/links.rs should be expanded to demonstrate the new functionality.

pub(crate) fn from_pdfium(handle: FPDF_DEST, bindings: &'a dyn PdfiumLibraryBindings) -> Self {
PdfDestination { handle, bindings }
}
Expand All @@ -23,7 +26,7 @@ impl<'a> PdfDestination<'a> {
&self.handle
}

/// Returns the [PdfiumLibraryBindings] used by this [PdfAction].
/// Returns the [PdfiumLibraryBindings] used by this [PdfDestination].
#[inline]
pub fn bindings(&self) -> &dyn PdfiumLibraryBindings {
self.bindings
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod action;
pub mod action_embedded_destination;
pub mod action_launch;
pub mod action_local_destination;
pub mod action_private;
mod action_private; // Keep private so that the PdfActionPrivate trait is not exposed.
pub mod action_remote_destination;
pub mod action_unsupported;
pub mod action_uri;
Expand Down
8 changes: 8 additions & 0 deletions src/link.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Defines the [PdfLink] struct, exposing functionality related to a single link contained
//! within a `PdfPage`, a `PdfPageAnnotation`, or a `PdfBookmark`.
use crate::action::PdfAction;
use crate::bindgen::{FPDF_DOCUMENT, FPDF_LINK};
use crate::bindings::PdfiumLibraryBindings;
Expand All @@ -9,6 +12,11 @@ pub struct PdfLink<'a> {
bindings: &'a dyn PdfiumLibraryBindings,
}

/// A single link contained within a `PdfPage`, a `PdfPageAnnotation`, or a `PdfBookmark`.
///
/// Each link may have a corresponding [PdfAction] that will be triggered when the user
/// interacts with the link, and a [PdfDestination] that indicates the target of any behaviour
/// triggered by the [PdfAction].
impl<'a> PdfLink<'a> {
#[inline]
pub(crate) fn from_pdfium(
Expand Down
2 changes: 2 additions & 0 deletions src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ pub enum PdfPageContentRegenerationStrategy {
/// * [PdfPage::annotations_mut()], a mutable collection of all the user annotations attached to the [PdfPage].
/// * [PdfPage::boundaries()], an immutable collection of the boundary boxes relating to the [PdfPage].
/// * [PdfPage::boundaries_mut()], a mutable collection of the boundary boxes relating to the [PdfPage].
/// * [PdfPage::links()], an immutable collection of the links on the [PdfPage].
/// * [PdfPage::links_mut()], a mutable collection of the links on the [PdfPage].
/// * [PdfPage::objects()], an immutable collection of all the displayable objects on the [PdfPage].
/// * [PdfPage::objects_mut()], a mutable collection of all the displayable objects on the [PdfPage].
pub struct PdfPage<'a> {
Expand Down
1 change: 1 addition & 0 deletions src/page_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ impl<'a> Iterator for PdfPageLinksIterator<'a> {
&mut self.start_pos,
&mut handle,
))
&& !handle.is_null()
{
Some(PdfLink::from_pdfium(
handle,
Expand Down
2 changes: 1 addition & 1 deletion src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6376,7 +6376,7 @@ impl PdfiumLibraryBindings for WasmPdfiumBindings {

let len_start_pos = size_of::<c_int>();

let ptr_start_pos = state.malloc(len_start_pos);
let ptr_start_pos = state.copy_ptr_with_len_to_pdfium(start_pos, len_start_pos);

let len_link_annot = size_of::<FPDF_LINK>();

Expand Down

0 comments on commit 77c7169

Please sign in to comment.