From 18ae06d9ae493276b3ddcd37eb19de7aeba1a0e8 Mon Sep 17 00:00:00 2001 From: Jane Liu Date: Tue, 18 Jul 2017 10:15:16 -0400 Subject: Basic APIs and tests for extracting attachments 1. Added API for extracting attachment properties and data. * Expanded the embedder test to cover all the new APIs. Bug=pdfium:174 Change-Id: I09bffd412410e9aea45faca442d2b72eefafef4e Reviewed-on: https://pdfium-review.googlesource.com/7790 Reviewed-by: dsinclair Commit-Queue: dsinclair --- public/fpdf_annot.h | 11 ------- public/fpdf_attachment.h | 85 +++++++++++++++++++++++++++++++++++++++++++----- public/fpdfview.h | 13 ++++++++ 3 files changed, 89 insertions(+), 20 deletions(-) (limited to 'public') diff --git a/public/fpdf_annot.h b/public/fpdf_annot.h index e6c33a59eb..5076470627 100644 --- a/public/fpdf_annot.h +++ b/public/fpdf_annot.h @@ -55,17 +55,6 @@ extern "C" { #define FPDF_ANNOT_FLAG_LOCKED (1 << 7) #define FPDF_ANNOT_FLAG_TOGGLENOVIEW (1 << 8) -#define FPDF_OBJECT_UNKNOWN 0 -#define FPDF_OBJECT_BOOLEAN 1 -#define FPDF_OBJECT_NUMBER 2 -#define FPDF_OBJECT_STRING 3 -#define FPDF_OBJECT_NAME 4 -#define FPDF_OBJECT_ARRAY 5 -#define FPDF_OBJECT_DICTIONARY 6 -#define FPDF_OBJECT_STREAM 7 -#define FPDF_OBJECT_NULLOBJ 8 -#define FPDF_OBJECT_REFERENCE 9 - typedef enum FPDFANNOT_COLORTYPE { FPDFANNOT_COLORTYPE_Color = 0, FPDFANNOT_COLORTYPE_InteriorColor diff --git a/public/fpdf_attachment.h b/public/fpdf_attachment.h index 07fdff5a9e..2c40992760 100644 --- a/public/fpdf_attachment.h +++ b/public/fpdf_attachment.h @@ -21,21 +21,88 @@ extern "C" { DLLEXPORT int STDCALL FPDFDoc_GetAttachmentCount(FPDF_DOCUMENT document); // Experimental API. -// Get the name of the embedded file at |index| in |document|. |buffer| is -// only modified if |buflen| is longer than the length of the file name. On -// errors, |buffer| is unmodified and the returned length is 0. +// Get the embedded attachment at |index| in |document|. Note that the returned +// attachment handle is only valid while |document| is open. // // document - handle to a document. // index - the index of the requested embedded file. -// buffer - buffer for holding the file name, encoded in UTF16-LE. -// buflen - length of the buffer. +// +// Returns the handle to the attachment object, or NULL on failure. +DLLEXPORT FPDF_ATTACHMENT STDCALL FPDFDoc_GetAttachment(FPDF_DOCUMENT document, + int index); + +// Experimental API. +// Get the name of the |attachment| file. |buffer| is only modified if |buflen| +// is longer than the length of the file name. On errors, |buffer| is unmodified +// and the returned length is 0. +// +// attachment - handle to an attachment. +// buffer - buffer for holding the file name, encoded in UTF16-LE. +// buflen - length of the buffer. // // Returns the length of the file name. DLLEXPORT unsigned long STDCALL -FPDFDoc_GetAttachmentName(FPDF_DOCUMENT document, - int index, - void* buffer, - unsigned long buflen); +FPDFAttachment_GetName(FPDF_ATTACHMENT attachment, + void* buffer, + unsigned long buflen); + +// Experimental API. +// Check if the params dictionary of |attachment| has |key| as a key. +// +// attachment - handle to an attachment. +// key - the key to look for. +// +// Returns true if |key| exists. +DLLEXPORT FPDF_BOOL STDCALL FPDFAttachment_HasKey(FPDF_ATTACHMENT attachment, + FPDF_WIDESTRING key); + +// Experimental API. +// Get the type of the value corresponding to |key| in the params dictionary of +// the embedded |attachment|. +// +// attachment - handle to an attachment. +// key - the key to look for. +// +// Returns the type of the dictionary value. +DLLEXPORT FPDF_OBJECT_TYPE STDCALL +FPDFAttachment_GetValueType(FPDF_ATTACHMENT attachment, FPDF_WIDESTRING key); + +// 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 +// than the length of the string value. Note that if |key| does not exist in the +// dictionary or if |key|'s corresponding value in the dictionary is not a +// string (i.e. the value is not of type FPDF_OBJECT_STRING or +// FPDF_OBJECT_NAME), then an empty string would be copied to |buffer| and the +// return value would be 2. On other errors, nothing would be added to |buffer| +// and the return value would be 0. +// +// 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. +// buflen - length of the buffer. +// +// Returns the length of the dictionary value string. +DLLEXPORT unsigned long STDCALL +FPDFAttachment_GetStringValue(FPDF_ATTACHMENT attachment, + FPDF_WIDESTRING key, + void* buffer, + unsigned long buflen); + +// 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. +// buflen - length of the buffer. +// +// Returns the length of the file. +DLLEXPORT unsigned long STDCALL +FPDFAttachment_GetFile(FPDF_ATTACHMENT attachment, + void* buffer, + unsigned long buflen); #ifdef __cplusplus } // extern "C" diff --git a/public/fpdfview.h b/public/fpdfview.h index 95900f3848..55897eb467 100644 --- a/public/fpdfview.h +++ b/public/fpdfview.h @@ -20,9 +20,22 @@ #define PDF_USE_XFA #endif // PDF_ENABLE_XFA +// PDF object types +#define FPDF_OBJECT_UNKNOWN 0 +#define FPDF_OBJECT_BOOLEAN 1 +#define FPDF_OBJECT_NUMBER 2 +#define FPDF_OBJECT_STRING 3 +#define FPDF_OBJECT_NAME 4 +#define FPDF_OBJECT_ARRAY 5 +#define FPDF_OBJECT_DICTIONARY 6 +#define FPDF_OBJECT_STREAM 7 +#define FPDF_OBJECT_NULLOBJ 8 +#define FPDF_OBJECT_REFERENCE 9 + // PDF types typedef void* FPDF_ACTION; typedef void* FPDF_ANNOTATION; +typedef void* FPDF_ATTACHMENT; typedef void* FPDF_BITMAP; typedef void* FPDF_BOOKMARK; typedef void* FPDF_CLIPPATH; -- cgit v1.2.3