From 81caaed2fd24b4699187d764b26084449cfc8951 Mon Sep 17 00:00:00 2001 From: Alastair Carey Date: Thu, 15 Aug 2024 22:54:20 +0100 Subject: [PATCH] Progressing #137 --- Cargo.toml | 3 +- README.md | 20 ++-- src/bindings.rs | 137 +++++++++++++++++++++++ src/bindings/dynamic.rs | 124 +++++++++++++++++++++ src/bindings/static_bindings.rs | 65 +++++++++++ src/bindings/thread_safe.rs | 61 ++++++++++ src/bindings/wasm.rs | 191 +++++++++++++++++++++++++++++++- 7 files changed, 589 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b9f977a..82e5ec3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pdfium-render" -version = "0.8.24" +version = "0.8.25" edition = "2018" publish = true description = "A high-level idiomatic Rust wrapper around Pdfium, the C++ PDF library used by the Google Chromium project." @@ -11,6 +11,7 @@ license = "MIT OR Apache-2.0" keywords = ["pdf", "pdfium"] categories = ["api-bindings", "multimedia::images", "visualization", "wasm"] authors = ["Alastair Carey "] +exclude = ["test/*.pdf"] [lib] name = "pdfium_render" diff --git a/README.md b/README.md index ddef047..4e1ce96 100644 --- a/README.md +++ b/README.md @@ -354,7 +354,7 @@ functions specific to interactive scripting, user interaction, and printing. * Releases numbered 0.8.x aim to progressively add support for all remaining Pdfium editing functions to `pdfium-render`. * Releases numbered 0.9.x aim to fill any remaining gaps in the high-level interface prior to 1.0. -There are 377 `FPDF_*` functions in the Pdfium API. As of version 0.8.24, 334 (89%) have +There are 377 `FPDF_*` functions in the Pdfium API. As of version 0.8.25, 338 (90%) have bindings available in `PdfiumLibraryBindings`, with the functionality of the majority of these available via the `pdfium-render` high-level interface. @@ -367,19 +367,25 @@ at . ## Version history -* 0.8.24: introduced crate feature flags for selecting Pdfium API versions to use in +* 0.8.25: adds bindings for `FPDFAnnot_GetFormAdditionalActionJavaScript()`, + `FPDFAnnot_GetFormFieldAlternateName()`, `FPDFAnnot_GetFileAttachment()`, and + `FPDFAnnot_AddFileAttachment()`. +* 0.8.24: introduces crate feature flags for selecting Pdfium API versions to use in `PdfiumLibraryBindings`; reworked `build.rs` to output bindings for multiple sets of Pdfium header - files; reworked bindings implementations to differentiate between API versions that include the + files; reworks bindings implementations to differentiate between API versions that include the `FPDFFont_*` and `FPDFText_GetTextObject()` functions added in 0.8.23, and API versions that do not; - internally reorganize source code layout to make the code structure clearer. -* 0.8.23: synchronized Pdfium API header files against mainline; removes binding for function + adds WASM bindings utility function `copy_string_to_pdfium()` to correctly copy the string data of an + `FPDF_WIDESTRING` to Pdfium's WASM memory module, instead of just the pointer location; + adds `PdfiumLibraryBindings::version()` function for reporting the currently configured API version; + internally reorganized source code layout to make the code structure clearer. +* 0.8.23: synchronizes Pdfium API header files against mainline; removes binding for function `FPDFText_GetTextRenderMode()` in response to upstream change described at ; adds bindings for `FPDFText_GetTextObject()`, `FPDFFont_GetFamilyName()`, `FPDFFont_GetIsEmbedded()`, and `FPDFFont_GetFontData()` functions; deprecates `PdfFont::name()` function in favour of `PdfFont::family()` to match upstream naming changes; adds new functions `PdfFont::is_embedded()` and `PdfFont::data()` for retrieving embedded font data; updates `examples/fonts.rs` example; adds new function `PdfPageTextChar::text_object()` - for retrieving the page object containing a specific character; adds WASM bindings utility function - `copy_string_to_pdfium()` to correctly copy the string data of an `FPDF_WIDESTRING` to Pdfium's WASM memory module, instead of just the pointer location. Deprecated items will be removed in release 0.9.0. + for retrieving the page object containing a specific character. Deprecated items will be removed + in release 0.9.0. * 0.8.22: adds bindings for `FPDFPage_TransformAnnots()`, thanks to an excellent contribution from ; adds bindings for `FPDF_GetPageSizeByIndexF()`, thanks to an excellent contribution from ; updates all examples and tests that reference diff --git a/src/bindings.rs b/src/bindings.rs index 2c5808e..3b13d34 100644 --- a/src/bindings.rs +++ b/src/bindings.rs @@ -696,6 +696,7 @@ pub trait PdfiumLibraryBindings { #[allow(non_snake_case)] fn FPDFPage_GenerateContent(&self, page: FPDF_PAGE) -> FPDF_BOOL; + #[cfg(any(feature = "pdfium_latest", feature = "pdfium_future"))] #[allow(non_snake_case)] #[allow(clippy::too_many_arguments)] fn FPDFPage_TransformAnnots( @@ -1328,6 +1329,63 @@ pub trait PdfiumLibraryBindings { border_width: *mut c_float, ) -> FPDF_BOOL; + /// Get the JavaScript of an event of the annotation's additional actions. + /// + /// `buffer` is only modified if `buflen` is large enough to hold the whole + /// JavaScript string. If `buflen` is smaller, the total size of the JavaScript + /// is still returned, but nothing is copied. If there is no JavaScript for + /// `event` in `annot`, an empty string is written to `buf` and 2 is returned, + /// denoting the size of the null terminator in the buffer. On other errors, + /// nothing is written to `buffer` and 0 is returned. + /// + /// `hHandle` - handle to the form fill module, returned by + /// [PdfiumLibraryBindings::FPDFDOC_InitFormFillEnvironment()]. + /// + /// `annot` - handle to an interactive form annotation. + /// + /// `event` - event type, one of the `FPDF_ANNOT_AACTION_*` values. + /// + /// `buffer` - buffer for holding the value string, encoded in UTF-16LE. + /// + /// `buflen` - length of the buffer in bytes. + /// + /// Returns the length of the string value in bytes, including the 2-byte null terminator. + #[allow(non_snake_case)] + fn FPDFAnnot_GetFormAdditionalActionJavaScript( + &self, + hHandle: FPDF_FORMHANDLE, + annot: FPDF_ANNOTATION, + event: c_int, + buffer: *mut FPDF_WCHAR, + buflen: c_ulong, + ) -> c_ulong; + + /// Gets the alternate name of `annot`, which is an interactive form annotation. + /// + /// `buffer` is only modified if `buflen` is longer than the length of contents. + /// In case of error, nothing will be added to `buffer` and the return value will be 0. + /// Note that return value of empty string is 2 for `\0\0`. + /// + /// `hHandle` - handle to the form fill module, returned by + /// [PdfiumLibraryBindings::FPDFDOC_InitFormFillEnvironment()]. + /// + /// `annot` - handle to an interactive form annotation. + /// + /// `buffer` - buffer for holding the alternate name string, encoded in + /// UTF-16LE. + /// + /// `buflen` - length of the buffer in bytes. + /// + /// Returns the length of the string value in bytes. + #[allow(non_snake_case)] + fn FPDFAnnot_GetFormFieldAlternateName( + &self, + hHandle: FPDF_FORMHANDLE, + annot: FPDF_ANNOTATION, + buffer: *mut FPDF_WCHAR, + buflen: c_ulong, + ) -> c_ulong; + /// Check if `annot`'s dictionary has `key` as a key. /// /// `annot` - handle to an annotation. @@ -1894,6 +1952,80 @@ pub trait PdfiumLibraryBindings { #[allow(non_snake_case)] fn FPDFAnnot_SetURI(&self, annot: FPDF_ANNOTATION, uri: &str) -> FPDF_BOOL; + /// Get the attachment from `annot`. + /// + /// `annot` - handle to a file annotation. + /// + /// Returns the handle to the attachment object, or NULL on failure. + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + #[allow(non_snake_case)] + fn FPDFAnnot_GetFileAttachment(&self, annot: FPDF_ANNOTATION) -> FPDF_ATTACHMENT; + + /// Add an embedded file with `name` to `annot`. + /// + /// `annot` - handle to a file annotation. + /// + /// `name` - name of the new attachment. + /// + /// Returns a handle to the new attachment object, or NULL on failure. + /// + /// A [&str]-friendly helper function is available for this function. + /// See [PdfiumLibraryBindings::FPDFAnnot_AddFileAttachment_str]. + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + #[allow(non_snake_case)] + fn FPDFAnnot_AddFileAttachment( + &self, + annot: FPDF_ANNOTATION, + name: FPDF_WIDESTRING, + ) -> FPDF_ATTACHMENT; + + /// A [&str]-friendly helper function for [PdfiumLibraryBindings::FPDFAnnot_AddFileAttachment]. + /// + /// Add an embedded file with `name` to `annot`. + /// + /// `annot` - handle to a file annotation. + /// + /// `name` - name of the new attachment. + /// + /// Returns a handle to the new attachment object, or NULL on failure. + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + #[inline] + #[allow(non_snake_case)] + fn FPDFAnnot_AddFileAttachment_str( + &self, + annot: FPDF_ANNOTATION, + name: &str, + ) -> FPDF_ATTACHMENT { + self.FPDFAnnot_AddFileAttachment( + annot, + get_pdfium_utf16le_bytes_from_str(name).as_ptr() as FPDF_WIDESTRING, + ) + } + /// Initializes the form fill environment. /// /// `document` - Handle to document from [PdfiumLibraryBindings::FPDF_LoadDocument]. @@ -1929,6 +2061,7 @@ pub trait PdfiumLibraryBindings { /// /// `hHandle` - Handle to the form fill module, as returned by /// [PdfiumLibraryBindings::FPDFDOC_InitFormFillEnvironment]. + #[cfg(any(feature = "pdfium_latest", feature = "pdfium_future"))] #[allow(non_snake_case)] fn FORM_OnAfterLoadPage(&self, page: FPDF_PAGE, hHandle: FPDF_FORMHANDLE); @@ -1939,6 +2072,7 @@ pub trait PdfiumLibraryBindings { /// /// `hHandle` - Handle to the form fill module, as returned by /// [PdfiumLibraryBindings::FPDFDOC_InitFormFillEnvironment]. + #[cfg(any(feature = "pdfium_latest", feature = "pdfium_future"))] #[allow(non_snake_case)] fn FORM_OnBeforeClosePage(&self, page: FPDF_PAGE, hHandle: FPDF_FORMHANDLE); @@ -2042,6 +2176,7 @@ pub trait PdfiumLibraryBindings { /// (open state). If the value is negative, child items shall be hidden by /// default (closed state). Please refer to PDF 32000-1:2008, Table 153. /// Returns 0 if the bookmark has no children or is invalid. + #[cfg(any(feature = "pdfium_latest", feature = "pdfium_future"))] #[allow(non_snake_case)] fn FPDFBookmark_GetCount(&self, bookmark: FPDF_BOOKMARK) -> c_int; @@ -2388,6 +2523,7 @@ pub trait PdfiumLibraryBindings { /// /// If this function returns a valid handle, it is valid as long as `page` is /// valid. + #[cfg(any(feature = "pdfium_latest", feature = "pdfium_future"))] #[allow(non_snake_case)] fn FPDF_GetPageAAction(&self, page: FPDF_PAGE, aa_type: c_int) -> FPDF_ACTION; @@ -3659,6 +3795,7 @@ pub trait PdfiumLibraryBindings { /// `document` - handle to a document. /// /// Returns `true` if `document` is a tagged PDF. + #[cfg(any(feature = "pdfium_latest", feature = "pdfium_future"))] #[allow(non_snake_case)] fn FPDFCatalog_IsTagged(&self, document: FPDF_DOCUMENT) -> FPDF_BOOL; } diff --git a/src/bindings/dynamic.rs b/src/bindings/dynamic.rs index 2b8d066..e4fb7cd 100644 --- a/src/bindings/dynamic.rs +++ b/src/bindings/dynamic.rs @@ -460,6 +460,19 @@ pub(crate) struct DynamicPdfiumBindings { vertical_radius: *mut f32, border_width: *mut f32, ) -> FPDF_BOOL, + extern_FPDFAnnot_GetFormAdditionalActionJavaScript: unsafe extern "C" fn( + hHandle: FPDF_FORMHANDLE, + annot: FPDF_ANNOTATION, + event: c_int, + buffer: *mut FPDF_WCHAR, + buflen: c_ulong, + ) -> c_ulong, + extern_FPDFAnnot_GetFormFieldAlternateName: unsafe extern "C" fn( + hHandle: FPDF_FORMHANDLE, + annot: FPDF_ANNOTATION, + buffer: *mut FPDF_WCHAR, + buflen: c_ulong, + ) -> c_ulong, extern_FPDFAnnot_HasKey: unsafe extern "C" fn(annot: FPDF_ANNOTATION, key: FPDF_BYTESTRING) -> FPDF_BOOL, extern_FPDFAnnot_GetValueType: @@ -563,6 +576,28 @@ pub(crate) struct DynamicPdfiumBindings { ) -> c_ulong, extern_FPDFAnnot_SetURI: unsafe extern "C" fn(annot: FPDF_ANNOTATION, uri: *const c_char) -> FPDF_BOOL, + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + extern_FPDFAnnot_GetFileAttachment: + unsafe extern "C" fn(annot: FPDF_ANNOTATION) -> FPDF_ATTACHMENT, + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + extern_FPDFAnnot_AddFileAttachment: + unsafe extern "C" fn(annot: FPDF_ANNOTATION, name: FPDF_WIDESTRING) -> FPDF_ATTACHMENT, extern_FPDFDOC_InitFormFillEnvironment: unsafe extern "C" fn( document: FPDF_DOCUMENT, form_info: *mut FPDF_FORMFILLINFO, @@ -1376,6 +1411,10 @@ impl DynamicPdfiumBindings { extern_FPDFAnnot_GetLine: *(library.get(b"FPDFAnnot_GetLine\0")?), extern_FPDFAnnot_SetBorder: *(library.get(b"FPDFAnnot_SetBorder\0")?), extern_FPDFAnnot_GetBorder: *(library.get(b"FPDFAnnot_GetBorder\0")?), + extern_FPDFAnnot_GetFormAdditionalActionJavaScript: *(library + .get(b"FPDFAnnot_GetFormAdditionalActionJavaScript\0")?), + extern_FPDFAnnot_GetFormFieldAlternateName: *(library + .get(b"FPDFAnnot_GetFormFieldAlternateName\0")?), extern_FPDFAnnot_HasKey: *(library.get(b"FPDFAnnot_HasKey\0")?), extern_FPDFAnnot_GetValueType: *(library.get(b"FPDFAnnot_GetValueType\0")?), extern_FPDFAnnot_SetStringValue: *(library.get(b"FPDFAnnot_SetStringValue\0")?), @@ -1416,6 +1455,28 @@ impl DynamicPdfiumBindings { extern_FPDFAnnot_GetFormFieldExportValue: *(library .get(b"FPDFAnnot_GetFormFieldExportValue\0")?), extern_FPDFAnnot_SetURI: *(library.get(b"FPDFAnnot_SetURI\0")?), + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + extern_FPDFAnnot_GetFileAttachment: *(library + .get(b"FPDFAnnot_GetFileAttachment\0")?), + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + extern_FPDFAnnot_AddFileAttachment: *(library + .get(b"FPDFAnnot_AddFileAttachment\0")?), extern_FPDFDOC_InitFormFillEnvironment: *(library .get(b"FPDFDOC_InitFormFillEnvironment\0")?), extern_FPDFDOC_ExitFormFillEnvironment: *(library @@ -2839,6 +2900,35 @@ impl PdfiumLibraryBindings for DynamicPdfiumBindings { } } + #[inline] + #[allow(non_snake_case)] + fn FPDFAnnot_GetFormAdditionalActionJavaScript( + &self, + hHandle: FPDF_FORMHANDLE, + annot: FPDF_ANNOTATION, + event: c_int, + buffer: *mut FPDF_WCHAR, + buflen: c_ulong, + ) -> c_ulong { + unsafe { + (self.extern_FPDFAnnot_GetFormAdditionalActionJavaScript)( + hHandle, annot, event, buffer, buflen, + ) + } + } + + #[inline] + #[allow(non_snake_case)] + fn FPDFAnnot_GetFormFieldAlternateName( + &self, + hHandle: FPDF_FORMHANDLE, + annot: FPDF_ANNOTATION, + buffer: *mut FPDF_WCHAR, + buflen: c_ulong, + ) -> c_ulong { + unsafe { (self.extern_FPDFAnnot_GetFormFieldAlternateName)(hHandle, annot, buffer, buflen) } + } + #[inline] #[allow(non_snake_case)] fn FPDFAnnot_HasKey(&self, annot: FPDF_ANNOTATION, key: &str) -> FPDF_BOOL { @@ -3114,6 +3204,40 @@ impl PdfiumLibraryBindings for DynamicPdfiumBindings { unsafe { (self.extern_FPDFAnnot_SetURI)(annot, c_uri.as_ptr()) } } + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + #[inline] + #[allow(non_snake_case)] + fn FPDFAnnot_GetFileAttachment(&self, annot: FPDF_ANNOTATION) -> FPDF_ATTACHMENT { + unsafe { (self.extern_FPDFAnnot_GetFileAttachment)(annot) } + } + + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + #[inline] + #[allow(non_snake_case)] + fn FPDFAnnot_AddFileAttachment( + &self, + annot: FPDF_ANNOTATION, + name: FPDF_WIDESTRING, + ) -> FPDF_ATTACHMENT { + unsafe { (self.extern_FPDFAnnot_AddFileAttachment)(annot, name) } + } + #[inline] #[allow(non_snake_case)] fn FPDFDOC_InitFormFillEnvironment( diff --git a/src/bindings/static_bindings.rs b/src/bindings/static_bindings.rs index 6247bfa..5f84514 100644 --- a/src/bindings/static_bindings.rs +++ b/src/bindings/static_bindings.rs @@ -1135,6 +1135,37 @@ impl PdfiumLibraryBindings for StaticPdfiumBindings { } } + #[inline] + #[allow(non_snake_case)] + fn FPDFAnnot_GetFormAdditionalActionJavaScript( + &self, + hHandle: FPDF_FORMHANDLE, + annot: FPDF_ANNOTATION, + event: c_int, + buffer: *mut FPDF_WCHAR, + buflen: c_ulong, + ) -> c_ulong { + unsafe { + crate::bindgen::FPDFAnnot_GetFormAdditionalActionJavaScript( + hHandle, annot, event, buffer, buflen, + ) + } + } + + #[inline] + #[allow(non_snake_case)] + fn FPDFAnnot_GetFormFieldAlternateName( + &self, + hHandle: FPDF_FORMHANDLE, + annot: FPDF_ANNOTATION, + buffer: *mut FPDF_WCHAR, + buflen: c_ulong, + ) -> c_ulong { + unsafe { + crate::bindgen::FPDFAnnot_GetFormFieldAlternateName(hHandle, annot, buffer, buflen) + } + } + #[inline] #[allow(non_snake_case)] fn FPDFAnnot_HasKey(&self, annot: FPDF_ANNOTATION, key: &str) -> FPDF_BOOL { @@ -1410,6 +1441,40 @@ impl PdfiumLibraryBindings for StaticPdfiumBindings { unsafe { crate::bindgen::FPDFAnnot_SetURI(annot, c_uri.as_ptr()) } } + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + #[inline] + #[allow(non_snake_case)] + fn FPDFAnnot_GetFileAttachment(&self, annot: FPDF_ANNOTATION) -> FPDF_ATTACHMENT { + unsafe { crate::bindgen::FPDFAnnot_GetFileAttachment(annot) } + } + + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + #[inline] + #[allow(non_snake_case)] + fn FPDFAnnot_AddFileAttachment( + &self, + annot: FPDF_ANNOTATION, + name: FPDF_WIDESTRING, + ) -> FPDF_ATTACHMENT { + unsafe { crate::bindgen::FPDFAnnot_AddFileAttachment(annot, name) } + } + #[inline] #[allow(non_snake_case)] fn FPDFDOC_InitFormFillEnvironment( diff --git a/src/bindings/thread_safe.rs b/src/bindings/thread_safe.rs index b2dc881..b4fb4c6 100644 --- a/src/bindings/thread_safe.rs +++ b/src/bindings/thread_safe.rs @@ -1209,6 +1209,33 @@ impl PdfiumLibraryBindings for ThreadSafePdfiumBinding .FPDFAnnot_GetBorder(annot, horizontal_radius, vertical_radius, border_width) } + #[inline] + #[allow(non_snake_case)] + fn FPDFAnnot_GetFormAdditionalActionJavaScript( + &self, + hHandle: FPDF_FORMHANDLE, + annot: FPDF_ANNOTATION, + event: c_int, + buffer: *mut FPDF_WCHAR, + buflen: c_ulong, + ) -> c_ulong { + self.bindings + .FPDFAnnot_GetFormAdditionalActionJavaScript(hHandle, annot, event, buffer, buflen) + } + + #[inline] + #[allow(non_snake_case)] + fn FPDFAnnot_GetFormFieldAlternateName( + &self, + hHandle: FPDF_FORMHANDLE, + annot: FPDF_ANNOTATION, + buffer: *mut FPDF_WCHAR, + buflen: c_ulong, + ) -> c_ulong { + self.bindings + .FPDFAnnot_GetFormFieldAlternateName(hHandle, annot, buffer, buflen) + } + #[inline] #[allow(non_snake_case)] fn FPDFAnnot_HasKey(&self, annot: FPDF_ANNOTATION, key: &str) -> FPDF_BOOL { @@ -1480,6 +1507,40 @@ impl PdfiumLibraryBindings for ThreadSafePdfiumBinding self.bindings.FPDFAnnot_SetURI(annot, uri) } + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + #[inline] + #[allow(non_snake_case)] + fn FPDFAnnot_GetFileAttachment(&self, annot: FPDF_ANNOTATION) -> FPDF_ATTACHMENT { + self.bindings.FPDFAnnot_GetFileAttachment(annot) + } + + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + #[inline] + #[allow(non_snake_case)] + fn FPDFAnnot_AddFileAttachment( + &self, + annot: FPDF_ANNOTATION, + name: FPDF_WIDESTRING, + ) -> FPDF_ATTACHMENT { + self.bindings.FPDFAnnot_AddFileAttachment(annot, name) + } + #[inline] #[allow(non_snake_case)] fn FPDFDOC_InitFormFillEnvironment( diff --git a/src/bindings/wasm.rs b/src/bindings/wasm.rs index b130de6..a8e66c0 100644 --- a/src/bindings/wasm.rs +++ b/src/bindings/wasm.rs @@ -5020,6 +5020,128 @@ impl PdfiumLibraryBindings for WasmPdfiumBindings { result } + #[allow(non_snake_case)] + fn FPDFAnnot_GetFormAdditionalActionJavaScript( + &self, + hHandle: FPDF_FORMHANDLE, + annot: FPDF_ANNOTATION, + event: c_int, + buffer: *mut FPDF_WCHAR, + buflen: c_ulong, + ) -> c_ulong { + log::debug!("pdfium-render::PdfiumLibraryBindings::FPDFAnnot_GetFormAdditionalActionJavaScript(): entering"); + + let state = PdfiumRenderWasmState::lock(); + + let buffer_length = buflen as usize; + + let buffer_ptr = if buffer_length > 0 { + log::debug!("pdfium-render::PdfiumLibraryBindings::FPDFAnnot_GetFormAdditionalActionJavaScript(): allocating buffer of {} bytes in Pdfium's WASM heap", buffer_length); + + state.malloc(buffer_length) + } else { + 0 + }; + + log::debug!( + "pdfium-render::PdfiumLibraryBindings::FPDFAnnot_GetFormAdditionalActionJavaScript(): calling FPDFAnnot_GetFormAdditionalActionJavaScript()" + ); + + let result = state + .call( + "FPDFAnnot_GetFormAdditionalActionJavaScript", + JsFunctionArgumentType::Number, + Some(vec![ + JsFunctionArgumentType::Pointer, + JsFunctionArgumentType::Pointer, + JsFunctionArgumentType::Number, + JsFunctionArgumentType::Pointer, + JsFunctionArgumentType::Number, + ]), + Some(&JsValue::from(Array::of5( + &Self::js_value_from_form(hHandle), + &Self::js_value_from_annotation(annot), + &JsValue::from_f64(event as f64), + &Self::js_value_from_offset(buffer_ptr), + &JsValue::from_f64(buffer_length as f64), + ))), + ) + .as_f64() + .unwrap() as usize; + + if result > 0 && result <= buffer_length { + state.copy_struct_from_pdfium(buffer_ptr, result, buffer); + } + + state.free(buffer_ptr); + + log::debug!("pdfium-render::PdfiumLibraryBindings::FPDFAnnot_GetFormAdditionalActionJavaScript(): leaving"); + + result as c_ulong + } + + #[allow(non_snake_case)] + fn FPDFAnnot_GetFormFieldAlternateName( + &self, + hHandle: FPDF_FORMHANDLE, + annot: FPDF_ANNOTATION, + buffer: *mut FPDF_WCHAR, + buflen: c_ulong, + ) -> c_ulong { + log::debug!( + "pdfium-render::PdfiumLibraryBindings::FPDFAnnot_GetFormFieldAlternateName(): entering" + ); + + let state = PdfiumRenderWasmState::lock(); + + let buffer_length = buflen as usize; + + let buffer_ptr = if buffer_length > 0 { + log::debug!("pdfium-render::PdfiumLibraryBindings::FPDFAnnot_GetFormFieldAlternateName(): allocating buffer of {} bytes in Pdfium's WASM heap", buffer_length); + + state.malloc(buffer_length) + } else { + 0 + }; + + log::debug!( + "pdfium-render::PdfiumLibraryBindings::FPDFAnnot_GetFormFieldAlternateName(): calling FPDFAnnot_GetFormFieldAlternateName()" + ); + + let result = state + .call( + "FPDFAnnot_GetFormFieldAlternateName", + JsFunctionArgumentType::Number, + Some(vec![ + JsFunctionArgumentType::Pointer, + JsFunctionArgumentType::Pointer, + JsFunctionArgumentType::Number, + JsFunctionArgumentType::Pointer, + JsFunctionArgumentType::Number, + ]), + Some(&JsValue::from(Array::of4( + &Self::js_value_from_form(hHandle), + &Self::js_value_from_annotation(annot), + &Self::js_value_from_offset(buffer_ptr), + &JsValue::from_f64(buffer_length as f64), + ))), + ) + .as_f64() + .unwrap() as usize; + + if result > 0 && result <= buffer_length { + state.copy_struct_from_pdfium(buffer_ptr, result, buffer); + } + + state.free(buffer_ptr); + + log::debug!( + "pdfium-render::PdfiumLibraryBindings::FPDFAnnot_GetFormFieldAlternateName(): leaving" + ); + + result as c_ulong + } + #[allow(non_snake_case)] fn FPDFAnnot_HasKey(&self, annot: FPDF_ANNOTATION, key: &str) -> FPDF_BOOL { log::debug!("pdfium-render::PdfiumLibraryBindings::FPDFAnnot_HasKey()"); @@ -6015,10 +6137,6 @@ impl PdfiumLibraryBindings for WasmPdfiumBindings { state.free(buffer_ptr); - log::debug!( - "pdfium-render::PdfiumLibraryBindings::FPDFAnnot_GetFormFieldExportValue(): leaving" - ); - result as c_ulong } @@ -6053,6 +6171,71 @@ impl PdfiumLibraryBindings for WasmPdfiumBindings { result } + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + #[allow(non_snake_case)] + fn FPDFAnnot_GetFileAttachment(&self, annot: FPDF_ANNOTATION) -> FPDF_ATTACHMENT { + log::debug!("pdfium-render::PdfiumLibraryBindings::FPDFAnnot_GetFileAttachment()"); + + PdfiumRenderWasmState::lock() + .call( + "FPDFAnnot_GetFileAttachment", + JsFunctionArgumentType::Pointer, + Some(vec![JsFunctionArgumentType::Pointer]), + Some(&JsValue::from(Array::of1(&Self::js_value_from_annotation( + annot, + )))), + ) + .as_f64() + .unwrap() as usize as FPDF_ATTACHMENT + } + + #[cfg(any( + feature = "pdfium_6337", + feature = "pdfium_6406", + feature = "pdfium_6490", + feature = "pdfium_6555", + feature = "pdfium_6569", + feature = "pdfium_6611", + feature = "pdfium_future" + ))] + #[allow(non_snake_case)] + fn FPDFAnnot_AddFileAttachment( + &self, + annot: FPDF_ANNOTATION, + name: FPDF_WIDESTRING, + ) -> FPDF_ATTACHMENT { + log::debug!("pdfium-render::PdfiumLibraryBindings::FPDFAnnot_AddFileAttachment()"); + + let state = PdfiumRenderWasmState::lock(); + + let name_ptr = state.copy_string_to_pdfium(name); + + let result = state + .call( + "FPDFAnnot_AddFileAttachment", + JsFunctionArgumentType::Pointer, + Some(vec![JsFunctionArgumentType::Pointer]), + Some(&JsValue::from(Array::of2( + &Self::js_value_from_annotation(annot), + &Self::js_value_from_offset(name_ptr), + ))), + ) + .as_f64() + .unwrap() as usize as FPDF_ATTACHMENT; + + state.free(name_ptr); + + result + } + #[allow(non_snake_case)] fn FPDFDOC_InitFormFillEnvironment( &self,