Skip to content

Commit

Permalink
Progressing #145
Browse files Browse the repository at this point in the history
  • Loading branch information
Alastair Carey committed Aug 4, 2024
1 parent e169da3 commit d98ef05
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 89 deletions.
21 changes: 16 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pdfium-render"
version = "0.8.22"
version = "0.8.23"
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 Expand Up @@ -36,25 +36,36 @@ console_error_panic_hook = "0"
js-sys = "0"
wasm-bindgen = { version = "0", features = ["enable-interning"] }
wasm-bindgen-futures = { version = "0" }
web-sys = { version = "0", features = ["TextDecoder", "ImageData", "Window", "Response", "Blob"] }
web-sys = { version = "0", features = [
"TextDecoder",
"ImageData",
"Window",
"Response",
"Blob",
] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
libloading = "0"
libloading = "0.8.1"

[build-dependencies]
bindgen = { version = "0" }

[dev-dependencies]
# Dependencies specific to examples. Dependencies for the WASM example in examples/wasm.rs
# are specified separately in examples/Cargo.toml.
rand = "0" # Used by examples/create.rs, examples/matrix.rs
rand = "0" # Used by examples/create.rs, examples/matrix.rs
rayon = "1" # Used by examples/thread_safe.rs

[features]
default = ["image", "thread_safe"] # The image feature is implicit because the image dependency is optional.
default = [
"image",
"thread_safe",
] # The image feature is implicit because the image dependency is optional.
bindings = []
static = []
thread_safe = []
"libstdc++" = ["static"]
"libc++" = ["static"]
sync = ["thread_safe"]
paragraph = []
flatten = []
4 changes: 2 additions & 2 deletions src/attachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ impl<'a> PdfAttachment<'a> {
/// This function is not available when compiling to WASM. You have several options for
/// saving attachment data in WASM:
/// * Use either the [PdfAttachment::save_to_writer()] or the [PdfAttachment::save_to_bytes()] functions,
/// both of which are available when compiling to WASM.
/// both of which are available when compiling to WASM.
/// * Use the [PdfAttachment::save_to_blob()] function to save attachment data directly into a new
/// Javascript `Blob` object. This function is only available when compiling to WASM.
/// Javascript `Blob` object. This function is only available when compiling to WASM.
#[cfg(not(target_arch = "wasm32"))]
pub fn save_to_file(&self, path: &(impl AsRef<Path> + ?Sized)) -> Result<(), PdfiumError> {
self.save_to_writer(&mut File::create(path).map_err(PdfiumError::IoError)?)
Expand Down
12 changes: 6 additions & 6 deletions src/attachments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ impl<'a> PdfAttachments<'a> {
/// This function is not available when compiling to WASM. You have several options for
/// loading attachment data in WASM:
/// * Use the [PdfAttachments::create_attachment_from_fetch()] function to download attachment data
/// from a URL using the browser's built-in `fetch()` API. This function is only available when
/// compiling to WASM.
/// from a URL using the browser's built-in `fetch()` API. This function is only available when
/// compiling to WASM.
/// * Use the [PdfAttachments::create_attachment_from_blob()] function to load attachment data
/// from a Javascript `File` or `Blob` object (such as a `File` object returned from an HTML
/// `<input type="file">` element). This function is only available when compiling to WASM.
/// from a Javascript `File` or `Blob` object (such as a `File` object returned from an HTML
/// `<input type="file">` element). This function is only available when compiling to WASM.
/// * Use another method to retrieve the bytes of the target attachment over the network,
/// then load those bytes into Pdfium using the [PdfAttachments::create_attachment_from_bytes()] function.
/// then load those bytes into Pdfium using the [PdfAttachments::create_attachment_from_bytes()] function.
/// * Embed the bytes of the target attachment directly into the compiled WASM module
/// using the `include_bytes!()` macro.
/// using the `include_bytes!()` macro.
#[cfg(not(target_arch = "wasm32"))]
pub fn create_attachment_from_file(
&mut self,
Expand Down
24 changes: 12 additions & 12 deletions src/color_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ use crate::error::PdfiumError;
/// share the same general characteristics. Families fall into three broad categories:
///
/// * **Device color spaces** directly specify colors or shades of gray that the output
/// device is to produce. The precise displayed color is device-specific and is not calibrated.
/// Color space families in this category include [PdfColorSpace::DeviceGray],
/// [PdfColorSpace::DeviceRGB], and [PdfColorSpace::DeviceCMYK].
/// device is to produce. The precise displayed color is device-specific and is not calibrated.
/// Color space families in this category include [PdfColorSpace::DeviceGray],
/// [PdfColorSpace::DeviceRGB], and [PdfColorSpace::DeviceCMYK].
/// * **Calibrated color spaces** are based on international standards for specifying human-visible
/// colors created by the Commission Internationale de l'Éclairage (International Commission on
/// Illumination) and the International Color Consortium. The precise displayed color is
/// device-independent; it does not rely on the characteristics of any particular output device.
/// Color space families in this category include [PdfColorSpace::CalibratedCIEGray],
/// [PdfColorSpace::CalibratedCIERGB], [PdfColorSpace::CalibratedCIELab], and
/// [PdfColorSpace::CalibratedICCProfile].
/// colors created by the Commission Internationale de l'Éclairage (International Commission on
/// Illumination) and the International Color Consortium. The precise displayed color is
/// device-independent; it does not rely on the characteristics of any particular output device.
/// Color space families in this category include [PdfColorSpace::CalibratedCIEGray],
/// [PdfColorSpace::CalibratedCIERGB], [PdfColorSpace::CalibratedCIELab], and
/// [PdfColorSpace::CalibratedICCProfile].
/// * **Special color spaces** add features or properties to another color space, such as
/// patterns, color mapping, separations, and high-fidelity and/or multi-tone color.
/// Color space families in this category include [PdfColorSpace::Pattern],
/// [PdfColorSpace::Indexed], [PdfColorSpace::Separation], and [PdfColorSpace::DeviceN].
/// patterns, color mapping, separations, and high-fidelity and/or multi-tone color.
/// Color space families in this category include [PdfColorSpace::Pattern],
/// [PdfColorSpace::Indexed], [PdfColorSpace::Separation], and [PdfColorSpace::DeviceN].
///
/// Non-RGB color spaces typically define a transform that enables color values in the color
/// space to be converted to an RGB approximation for on-screen display.
Expand Down
6 changes: 3 additions & 3 deletions src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl PdfDocumentVersion {
/// * [PdfDocument::pages()], an immutable collection of all the [PdfPages] in the document.
/// * [PdfDocument::pages_mut()], a mutable collection of all the [PdfPages] in the document.
/// * [PdfDocument::permissions()], settings relating to security handlers and document permissions
/// for the document.
/// for the document.
/// * [PdfDocument::signatures()], an immutable collection of all the [PdfSignatures] in the document.
pub struct PdfDocument<'a> {
handle: FPDF_DOCUMENT,
Expand Down Expand Up @@ -344,9 +344,9 @@ impl<'a> PdfDocument<'a> {
/// This function is not available when compiling to WASM. You have several options for
/// saving your PDF document data in WASM:
/// * Use either the [PdfDocument::save_to_writer()] or the [PdfDocument::save_to_bytes()] functions,
/// both of which are available when compiling to WASM.
/// both of which are available when compiling to WASM.
/// * Use the [PdfDocument::save_to_blob()] function to save document data directly into a new
/// Javascript `Blob` object. This function is only available when compiling to WASM.
/// Javascript `Blob` object. This function is only available when compiling to WASM.
#[cfg(not(target_arch = "wasm32"))]
pub fn save_to_file(&self, path: &(impl AsRef<Path> + ?Sized)) -> Result<(), PdfiumError> {
self.save_to_writer(&mut File::create(path).map_err(PdfiumError::IoError)?)
Expand Down
7 changes: 7 additions & 0 deletions src/flatten.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::bindgen::FPDF_PAGE;
use crate::error::PdfiumError;

#[allow(dead_code)] // During development of feature
fn flatten(_page_handle: FPDF_PAGE) -> Result<(), PdfiumError> {
unimplemented!()
}
28 changes: 14 additions & 14 deletions src/fonts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,17 @@ impl<'a> PdfFonts<'a> {
/// This function is not available when compiling to WASM. You have several options for
/// loading font data in WASM:
/// * Use the [PdfFont::load_type1_from_fetch()] function to download font data from a
/// URL using the browser's built-in `fetch()` API. This function is only available when
/// compiling to WASM.
/// URL using the browser's built-in `fetch()` API. This function is only available when
/// compiling to WASM.
/// * Use the [PdfFont::load_type1_from_blob()] function to load font data from a
/// Javascript File or Blob object (such as a File object returned from an HTML
/// `<input type="file">` element). This function is only available when compiling to WASM.
/// Javascript File or Blob object (such as a File object returned from an HTML
/// `<input type="file">` element). This function is only available when compiling to WASM.
/// * Use the [PdfFont::load_type1_from_reader()] function to load font data from any
/// valid Rust reader.
/// valid Rust reader.
/// * Use another method to retrieve the bytes of the target font over the network,
/// then load those bytes into Pdfium using the [PdfFont::new_type1_from_bytes()] function.
/// then load those bytes into Pdfium using the [PdfFont::new_type1_from_bytes()] function.
/// * Embed the bytes of the desired font directly into the compiled WASM module
/// using the `include_bytes!()` macro.
/// using the `include_bytes!()` macro.
#[cfg(not(target_arch = "wasm32"))]
pub fn load_type1_from_file(
&mut self,
Expand Down Expand Up @@ -405,17 +405,17 @@ impl<'a> PdfFonts<'a> {
/// This function is not available when compiling to WASM. You have several options for
/// loading font data in WASM:
/// * Use the [PdfFont::load_true_type_from_fetch()] function to download font data from a
/// URL using the browser's built-in `fetch()` API. This function is only available when
/// compiling to WASM.
/// URL using the browser's built-in `fetch()` API. This function is only available when
/// compiling to WASM.
/// * Use the [PdfFont::load_true_type_from_blob()] function to load font data from a
/// Javascript `File` or `Blob` object (such as a `File` object returned from an HTML
/// `<input type="file">` element). This function is only available when compiling to WASM.
/// Javascript `File` or `Blob` object (such as a `File` object returned from an HTML
/// `<input type="file">` element). This function is only available when compiling to WASM.
/// * Use the [PdfFont::load_true_type_from_reader()] function to load font data from any
/// valid Rust reader.
/// valid Rust reader.
/// * Use another method to retrieve the bytes of the target font over the network,
/// then load those bytes into Pdfium using the [PdfFont::new_true_type_from_bytes()] function.
/// then load those bytes into Pdfium using the [PdfFont::new_true_type_from_bytes()] function.
/// * Embed the bytes of the desired font directly into the compiled WASM module
/// using the `include_bytes!()` macro.
/// using the `include_bytes!()` macro.
#[cfg(not(target_arch = "wasm32"))]
pub fn load_true_type_from_file(
&mut self,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod color_space;
pub mod destination;
pub mod document;
pub mod error;
mod flatten; // Keep internal flatten operation private.
pub mod font;
pub mod font_glyph;
pub mod font_glyphs;
Expand Down Expand Up @@ -96,6 +97,7 @@ pub mod page_text_search;
pub mod page_text_segment;
pub mod page_text_segments;
pub mod pages;
#[cfg(feature = "paragraph")]
pub mod paragraph;
pub mod path_segment;
pub mod path_segments;
Expand Down
22 changes: 17 additions & 5 deletions src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,14 +784,14 @@ impl<'a> PdfPage<'a> {
/// * [PdfPage::translate()]: changes the position of each object on this [PdfPage].
/// * [PdfPage::scale()]: changes the size of each object on this [PdfPage].
/// * [PdfPage::flip_horizontally()]: flips each object on this [PdfPage] horizontally around
/// the page origin point.
/// the page origin point.
/// * [PdfPage::flip_vertically()]: flips each object on this [PdfPage] vertically around
/// the page origin point.
/// the page origin point.
/// * [PdfPage::rotate_clockwise_degrees()], [PdfPage::rotate_counter_clockwise_degrees()],
/// [PdfPage::rotate_clockwise_radians()], [PdfPage::rotate_counter_clockwise_radians()]:
/// rotates each object on this [PdfPage] around its origin.
/// [PdfPage::rotate_clockwise_radians()], [PdfPage::rotate_counter_clockwise_radians()]:
/// rotates each object on this [PdfPage] around its origin.
/// * [PdfPage::skew_degrees()], [PdfPage::skew_radians()]: skews each object
/// on this [PdfPage] relative to its axes.
/// on this [PdfPage] relative to its axes.
///
/// **The order in which transformations are applied is significant.**
/// For example, the result of rotating _then_ translating an object may be vastly different
Expand Down Expand Up @@ -891,6 +891,17 @@ impl<'a> PdfPage<'a> {
}

/// Flattens all annotations and form fields on this [PdfPage] into the page contents.
#[cfg(feature = "flatten")]
// Use a custom-written flatten operation, rather than Pdfium's built-in flatten. See:
// https://github.com/ajrcarey/pdfium-render/issues/140
pub fn flatten(&mut self) -> Result<(), PdfiumError> {
flatten_page(self.handle())
}

/// Flattens all annotations and form fields on this [PdfPage] into the page contents.
#[cfg(not(feature = "flatten"))]
// Use Pdfium's built-in flatten. This has some problems; see:
// https://github.com/ajrcarey/pdfium-render/issues/140
pub fn flatten(&mut self) -> Result<(), PdfiumError> {
// TODO: AJRC - 28/5/22 - consider allowing the caller to set the FLAT_NORMALDISPLAY or FLAT_PRINT flag.
let flag = FLAT_PRINT;
Expand Down Expand Up @@ -998,6 +1009,7 @@ impl<'a> PdfPage<'a> {
}

/// Commits any staged but unsaved changes to this [PdfPage] to the underlying [PdfDocument].
#[inline]
pub(crate) fn regenerate_content_immut(&self) -> Result<(), PdfiumError> {
Self::regenerate_content_immut_for_handle(self.page_handle, self.bindings)
}
Expand Down
8 changes: 4 additions & 4 deletions src/page_boundaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ impl PdfPageBoundaryBox {
/// The content of a page can be bounded by up to six different boxes:
///
/// * Media box: the full page size, equivalent to the target paper size when the document is printed.
/// All other page boundaries must fit inside the Media box.
/// All other page boundaries must fit inside the Media box.
/// * Art box: the maximum extent of out-of-bleed page art when offset printing.
/// Typically cropped out when viewing the document on-screen.
/// Typically cropped out when viewing the document on-screen.
/// * Bleed box: the maximum extent of outside-trim page bleeds when offset printing.
/// Typically cropped out when viewing the document on-screen.
/// Typically cropped out when viewing the document on-screen.
/// * Trim box: the maximum extent of page trims when offset printing.
/// Typically cropped out when viewing the document on-screen.
/// Typically cropped out when viewing the document on-screen.
/// * Crop box: the maximum extent of user-visible content when viewing the document on-screen.
/// * Bounding box ("BBox"): the smallest rectangle that can enclose all the content contained in the page.
///
Expand Down
24 changes: 12 additions & 12 deletions src/page_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,14 +705,14 @@ pub trait PdfPageObjectCommon<'a> {
/// Not all page objects can be successfully copied. The following restrictions apply:
///
/// * For path objects, it is not possible to copy a path object that contains a Bézier path
/// segment, because Pdfium does not currently provide any way to retrieve the control points of a
/// Bézier curve of an existing path object.
/// segment, because Pdfium does not currently provide any way to retrieve the control points of a
/// Bézier curve of an existing path object.
/// * For text objects, the font used by the object must be present in the destination document,
/// or text rendering behaviour will be unpredictable. While text objects refer to fonts,
/// font data is embedded into documents separately from text objects.
/// or text rendering behaviour will be unpredictable. While text objects refer to fonts,
/// font data is embedded into documents separately from text objects.
/// * For image objects, Pdfium allows iterating over the list of image filters applied
/// to an image object, but currently provides no way to set a new object's image filters.
/// As a result, it is not possible to copy an image object that has any image filters applied.
/// to an image object, but currently provides no way to set a new object's image filters.
/// As a result, it is not possible to copy an image object that has any image filters applied.
///
/// Pdfium currently allows setting the blend mode for a page object, but provides no way
/// to retrieve an object's current blend mode. As a result, the blend mode setting of the
Expand All @@ -725,14 +725,14 @@ pub trait PdfPageObjectCommon<'a> {
/// Not all page objects can be successfully copied. The following restrictions apply:
///
/// * For path objects, it is not possible to copy a path object that contains a Bézier path
/// segment, because Pdfium does not currently provide any way to retrieve the control points of a
/// Bézier curve of an existing path object.
/// segment, because Pdfium does not currently provide any way to retrieve the control points of a
/// Bézier curve of an existing path object.
/// * For text objects, the font used by the object must be present in the destination document,
/// or text rendering behaviour will be unpredictable. While text objects refer to fonts,
/// font data is embedded into documents separately from text objects.
/// or text rendering behaviour will be unpredictable. While text objects refer to fonts,
/// font data is embedded into documents separately from text objects.
/// * For image objects, Pdfium allows iterating over the list of image filters applied
/// to an image object, but currently provides no way to set a new object's image filters.
/// As a result, it is not possible to copy an image object that has any image filters applied.
/// to an image object, but currently provides no way to set a new object's image filters.
/// As a result, it is not possible to copy an image object that has any image filters applied.
///
/// Pdfium currently allows setting the blend mode for a page object, but provides no way
/// to retrieve an object's current blend mode. As a result, the blend mode setting of the
Expand Down
Loading

0 comments on commit d98ef05

Please sign in to comment.