summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/src/fpdf_flatten.cpp90
-rw-r--r--public/fpdf_flatten.h38
-rw-r--r--public/fpdfview.h39
3 files changed, 72 insertions, 95 deletions
diff --git a/fpdfsdk/src/fpdf_flatten.cpp b/fpdfsdk/src/fpdf_flatten.cpp
index 9356db9842..3dd768742f 100644
--- a/fpdfsdk/src/fpdf_flatten.cpp
+++ b/fpdfsdk/src/fpdf_flatten.cpp
@@ -88,47 +88,44 @@ void ParserStream( CPDF_Dictionary * pPageDic, CPDF_Dictionary* pStream, CPDF_Re
int ParserAnnots( CPDF_Document* pSourceDoc, CPDF_Dictionary * pPageDic, CPDF_RectArray * pRectArray, CPDF_ObjectArray * pObjectArray, int nUsage)
{
- if (!pSourceDoc || !pPageDic) return FLATTEN_FAIL;
-
- GetContentsRect( pSourceDoc, pPageDic, pRectArray );
- CPDF_Array* pAnnots = pPageDic->GetArray("Annots");
- if (pAnnots)
- {
- FX_DWORD dwSize = pAnnots->GetCount();
-
- for (int i = 0; i < (int)dwSize; i++)
- {
- CPDF_Object* pObj = pAnnots->GetElementValue(i);
-
- if (!pObj)continue;
-
- if (pObj->GetType() == PDFOBJ_DICTIONARY)
- {
- CPDF_Dictionary* pAnnotDic = (CPDF_Dictionary*)pObj;
- CFX_ByteString sSubtype = pAnnotDic->GetString("Subtype");
- if (sSubtype == "Popup")continue;
-
- int nAnnotFlag = pAnnotDic->GetInteger("F");
-
- if(nAnnotFlag & ANNOTFLAG_HIDDEN)
- continue;
- if(nUsage == FLAT_NORMALDISPLAY)
- {
- if(nAnnotFlag & ANNOTFLAG_INVISIBLE)
- continue;
- ParserStream( pPageDic, pAnnotDic, pRectArray, pObjectArray );
- }
- else
- {
- if(nAnnotFlag & ANNOTFLAG_PRINT)
- ParserStream( pPageDic, pAnnotDic, pRectArray, pObjectArray );
- }
- }
- }
- return FLATTEN_SUCCESS;
- }else{
- return FLATTEN_NOTINGTODO;
- }
+ if (!pSourceDoc || !pPageDic)
+ return FLATTEN_FAIL;
+
+ GetContentsRect( pSourceDoc, pPageDic, pRectArray );
+ CPDF_Array* pAnnots = pPageDic->GetArray("Annots");
+ if (!pAnnots)
+ return FLATTEN_NOTHINGTODO;
+
+ FX_DWORD dwSize = pAnnots->GetCount();
+ for (int i = 0; i < (int)dwSize; i++)
+ {
+ CPDF_Object* pObj = pAnnots->GetElementValue(i);
+ if (!pObj || pObj->GetType() != PDFOBJ_DICTIONARY)
+ continue;
+
+ CPDF_Dictionary* pAnnotDic = (CPDF_Dictionary*)pObj;
+ CFX_ByteString sSubtype = pAnnotDic->GetString("Subtype");
+ if (sSubtype == "Popup")
+ continue;
+
+ int nAnnotFlag = pAnnotDic->GetInteger("F");
+ if (nAnnotFlag & ANNOTFLAG_HIDDEN)
+ continue;
+
+ if(nUsage == FLAT_NORMALDISPLAY)
+ {
+ if (nAnnotFlag & ANNOTFLAG_INVISIBLE)
+ continue;
+
+ ParserStream( pPageDic, pAnnotDic, pRectArray, pObjectArray );
+ }
+ else
+ {
+ if (nAnnotFlag & ANNOTFLAG_PRINT)
+ ParserStream( pPageDic, pAnnotDic, pRectArray, pObjectArray );
+ }
+ }
+ return FLATTEN_SUCCESS;
}
@@ -351,14 +348,9 @@ DLLEXPORT int STDCALL FPDFPage_Flatten( FPDF_PAGE page, int nFlag)
int iRet = FLATTEN_FAIL;
iRet = ParserAnnots( pDocument, pPageDict, &RectArray, &ObjectArray, nFlag);
- if (iRet == FLATTEN_NOTINGTODO)
- {
- return FLATTEN_NOTINGTODO;
- }else if (iRet == FLATTEN_FAIL)
- {
- return FLATTEN_FAIL;
- }
-
+ if (iRet == FLATTEN_NOTHINGTODO || iRet == FLATTEN_FAIL)
+ return iRet;
+
CPDF_Rect rcOriginalCB;
CPDF_Rect rcMerger = CalculateRect( &RectArray );
CPDF_Rect rcOriginalMB = pPageDict->GetRect("MediaBox");
diff --git a/public/fpdf_flatten.h b/public/fpdf_flatten.h
index 991fd7981e..3ae3cd57f3 100644
--- a/public/fpdf_flatten.h
+++ b/public/fpdf_flatten.h
@@ -9,34 +9,30 @@
#include "fpdfview.h"
+// Result codes.
#define FLATTEN_FAIL 0 // Flatten operation failed.
#define FLATTEN_SUCCESS 1 // Flatten operation succeed.
-#define FLATTEN_NOTINGTODO 2 // There is nothing can be flatten.
+#define FLATTEN_NOTHINGTODO 2 // There is nothing to be flattened.
+
+// Flags.
+#define FLAT_NORMALDISPLAY 0
+#define FLAT_PRINT 1
#ifdef __cplusplus
extern "C" {
#endif
-#define FLAT_NORMALDISPLAY 0
-#define FLAT_PRINT 1
- //Function: FPDFPage_Flatten
-
- // Flat a pdf page,annotations or form fields will become part of the page contents.
- //Parameters:
-
- // page - Handle to the page. Returned by FPDF_LoadPage function.
- // nFlag - the flag for the use of flatten result. Zero for normal display, 1 for print.
- //Return value:
- // The result flag of the function, See flags above ( FLATTEN_FAIL, FLATTEN_SUCCESS, FLATTEN_NOTINGTODO ).
- //
- //Comments: Current version all fails return zero. If necessary we will assign different value
- // to indicate different fail reason.
- //
- //Notes:
- // The method can not support to flatten the page which the document consists of dynamic XFA fields.
- //
- DLLEXPORT int STDCALL FPDFPage_Flatten( FPDF_PAGE page, int nFlag);
-
+// Function: FPDFPage_Flatten
+// Make annotations and form fields become part of the page contents itself.
+// Parameters:
+// page - Handle to the page, as returned by FPDF_LoadPage().
+// nFlag - Intended use of the flattened result: 0 for normal display, 1 for printing.
+// Return value:
+// Either FLATTEN_FAIL, FLATTEN_SUCCESS, or FLATTEN_NOTHINGTODO (see above).
+// Comments:
+// Currently, all failures return FLATTEN_FAIL, with no indication for the reason
+// for the failure. The method does not support flattening any dynamic XFA fields.
+DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag);
#ifdef __cplusplus
}
diff --git a/public/fpdfview.h b/public/fpdfview.h
index bc875fb463..e56071a557 100644
--- a/public/fpdfview.h
+++ b/public/fpdfview.h
@@ -100,8 +100,6 @@ typedef const unsigned short* FPDF_STRING;
typedef const char* FPDF_STRING;
#endif
-#ifndef _FS_DEF_MATRIX_
-#define _FS_DEF_MATRIX_
/** @brief Matrix for transformation. */
typedef struct _FS_MATRIX_
{
@@ -112,10 +110,7 @@ typedef struct _FS_MATRIX_
float e; /**< @brief Coefficient e.*/
float f; /**< @brief Coefficient f.*/
} FS_MATRIX;
-#endif
-#ifndef _FS_DEF_RECTF_
-#define _FS_DEF_RECTF_
/** @brief Rectangle area(float) in device or page coordination system. */
typedef struct _FS_RECTF_
{
@@ -132,7 +127,6 @@ typedef struct _FS_RECTF_
}* FS_LPRECTF, FS_RECTF;
/** @brief Const Pointer to ::FS_RECTF structure.*/
typedef const FS_RECTF* FS_LPCRECTF;
-#endif
#if defined(_WIN32) && defined(FPDFSDK_EXPORTS)
// On Windows system, functions are exported in a DLL
@@ -143,9 +137,6 @@ typedef const FS_RECTF* FS_LPCRECTF;
#define STDCALL
#endif
-extern const char g_ExpireDate[];
-extern const char g_ModuleCodes[];
-
// Exported Functions
#ifdef __cplusplus
extern "C" {
@@ -159,10 +150,8 @@ extern "C" {
// None.
// Comments:
// You have to call this function before you can call any PDF processing functions.
-
DLLEXPORT void STDCALL FPDF_InitLibrary();
-
// Function: FPDF_DestroyLibary
// Release all resources allocated by the FPDFSDK library.
// Parameters:
@@ -186,19 +175,20 @@ DLLEXPORT void STDCALL FPDF_DestroyLibrary();
// None.
DLLEXPORT void STDCALL FPDF_SetSandBoxPolicy(FPDF_DWORD policy, FPDF_BOOL enable);
-/**
-* Open and load a PDF document.
-* @param[in] file_path - Path to the PDF file (including extension).
-* @param[in] password - A string used as the password for PDF file.
-* If no password needed, empty or NULL can be used.
-* @note Loaded document can be closed by FPDF_CloseDocument.
-* If this function fails, you can use FPDF_GetLastError() to retrieve
-* the reason why it fails.
-* The application should call ::FPDF_LoadXFA function after PDF document loaded
-* to support XFA fields in fpdfformfill.h file.
-*
-* @retval A handle to the loaded document. If failed, NULL is returned.
-*/
+// Function: FPDF_LoadDocument
+// Open and load a PDF document.
+// Parameters:
+// file_path [in] - Path to the PDF file (including extension).
+// password [in] - A string used as the password for PDF file.
+// If no password needed, empty or NULL can be used.
+// Return value:
+// A handle to the loaded document, or NULL on failure.
+// Comments:
+// Loaded document can be closed by FPDF_CloseDocument().
+// If this function fails, you can use FPDF_GetLastError() to retrieve
+// the reason why it failed.
+// The application should call ::FPDF_LoadXFA function after PDF document loaded
+// to support XFA fields in fpdfformfill.h file.
DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path,
FPDF_BYTESTRING password);
@@ -437,7 +427,6 @@ DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page);
//
DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_index, double* width, double* height);
-
// Page rendering flags. They can be combined with bit OR.
#define FPDF_ANNOT 0x01 // Set if annotations are to be rendered.
#define FPDF_LCD_TEXT 0x02 // Set if using text rendering optimized for LCD display.