From 54a4214c86bc790cc2a3ae454b1aa709e868fa1a Mon Sep 17 00:00:00 2001 From: Jane Liu Date: Mon, 24 Jul 2017 16:40:54 -0400 Subject: Basic APIs and tests for adding attachments 1. Added APIs for adding attachments, setting attachment files, and modifying attachment dictionary entries. * Added two embedder tests covering all new APIs. Bug=pdfium:174 Change-Id: I65f43cd6ca4887b71f9f7bcee64a87ba6b7e2706 Reviewed-on: https://pdfium-review.googlesource.com/8671 Commit-Queue: Jane Liu Reviewed-by: Lei Zhang Reviewed-by: dsinclair --- public/fpdf_attachment.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'public') diff --git a/public/fpdf_attachment.h b/public/fpdf_attachment.h index 2c40992760..6a23970c45 100644 --- a/public/fpdf_attachment.h +++ b/public/fpdf_attachment.h @@ -20,6 +20,19 @@ extern "C" { // Returns the number of embedded files in |document|. DLLEXPORT int STDCALL FPDFDoc_GetAttachmentCount(FPDF_DOCUMENT document); +// Experimental API. +// Add an embedded file with |name| in |document|. If |name| is empty, or if +// |name| is the name of a existing embedded file in |document|, or if +// |document|'s embedded file name tree is too deep (i.e. |document| has too +// many embedded files already), then a new attachment will not be added. +// +// document - handle to a document. +// name - name of the new attachment. +// +// Returns a handle to the new attachment object, or NULL on failure. +DLLEXPORT FPDF_ATTACHMENT FPDFDoc_AddAttachment(FPDF_DOCUMENT document, + FPDF_WIDESTRING name); + // Experimental API. // Get the embedded attachment at |index| in |document|. Note that the returned // attachment handle is only valid while |document| is open. @@ -67,6 +80,21 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFAttachment_HasKey(FPDF_ATTACHMENT attachment, DLLEXPORT FPDF_OBJECT_TYPE STDCALL FPDFAttachment_GetValueType(FPDF_ATTACHMENT attachment, FPDF_WIDESTRING key); +// Experimental API. +// Set the string value corresponding to |key| in the params dictionary of the +// embedded file |attachment|, overwriting the existing value if any. The value +// type should be FPDF_OBJECT_STRING after this function call succeeds. +// +// attachment - handle to an attachment. +// key - the key to the dictionary entry, encoded in UTF16-LE. +// value - the string value to be set, encoded in UTF16-LE. +// +// Returns true if successful. +DLLEXPORT FPDF_BOOL STDCALL +FPDFAttachment_SetStringValue(FPDF_ATTACHMENT attachment, + FPDF_WIDESTRING key, + FPDF_WIDESTRING value); + // Experimental API. // Get the string value corresponding to |key| in the params dictionary of the // embedded file |attachment|. |buffer| is only modified if |buflen| is longer @@ -79,7 +107,7 @@ FPDFAttachment_GetValueType(FPDF_ATTACHMENT attachment, FPDF_WIDESTRING key); // // attachment - handle to an attachment. // key - the key to the requested string value. -// buffer - buffer for holding the file's date string encoded in UTF16-LE. +// buffer - buffer for holding the string value encoded in UTF16-LE. // buflen - length of the buffer. // // Returns the length of the dictionary value string. @@ -89,13 +117,29 @@ FPDFAttachment_GetStringValue(FPDF_ATTACHMENT attachment, void* buffer, unsigned long buflen); +// Experimental API. +// Set the file data of |attachment|, overwriting the existing file data if any. +// The creation date and checksum will be updated, while all other dictionary +// entries will be deleted. Note that only contents with |len| smaller than +// INT_MAX is supported. +// +// attachment - handle to an attachment. +// contents - buffer holding the file data to be written in raw bytes. +// len - length of file data. +// +// Returns true if successful. +DLLEXPORT FPDF_BOOL FPDFAttachment_SetFile(FPDF_ATTACHMENT attachment, + FPDF_DOCUMENT document, + const void* contents, + const unsigned long len); + // Experimental API. // Get the file data of |attachment|. |buffer| is only modified if |buflen| is // longer than the length of the file. On errors, |buffer| is unmodified and the // returned length is 0. // // attachment - handle to an attachment. -// buffer - buffer for holding the file's data in raw bytes. +// buffer - buffer for holding the file data in raw bytes. // buflen - length of the buffer. // // Returns the length of the file. -- cgit v1.2.3