Remove typdefs for pointer types in fx_system.h.
[pdfium.git] / fpdfsdk / src / fpdf_flatten.cpp
index 26ea294..e9ab80e 100644 (file)
@@ -4,8 +4,8 @@
  
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
+#include "../../public/fpdf_flatten.h"
 #include "../include/fsdk_define.h"
-#include "../include/fpdf_flatten.h"
 
 typedef CFX_ArrayTemplate<CPDF_Dictionary*> CPDF_ObjectArray;
 typedef CFX_ArrayTemplate<CPDF_Rect> CPDF_RectArray;
@@ -86,47 +86,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;
 }
 
 
@@ -215,12 +212,12 @@ void SetPageContents(CFX_ByteString key, CPDF_Dictionary* pPage, CPDF_Document*
                //Create a new contents dictionary
                if (!key.IsEmpty())
                {
-                       CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, FX_NEW CPDF_Dictionary);
+                       CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary);
                        pPage->SetAtReference("Contents", pDocument, pDocument->AddIndirectObject(pNewContents));
 
                        CFX_ByteString sStream;
                        sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
-                       pNewContents->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE);
+                       pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, FALSE);
                }
                return;
        }
@@ -238,9 +235,9 @@ void SetPageContents(CFX_ByteString key, CPDF_Dictionary* pPage, CPDF_Document*
                        CPDF_StreamAcc acc;
                        acc.LoadAllData(pContents);
                        CFX_ByteString sStream = "q\n";
-                       CFX_ByteString sBody = CFX_ByteString((FX_LPCSTR)acc.GetData(), acc.GetSize());
+                       CFX_ByteString sBody = CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize());
                        sStream = sStream + sBody + "\nQ";
-                       pContents->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE);
+                       pContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, FALSE);
                        pContentsArray->AddReference(pDocument, dwObjNum);
                        break;
                }
@@ -261,13 +258,13 @@ void SetPageContents(CFX_ByteString key, CPDF_Dictionary* pPage, CPDF_Document*
        
        if (!key.IsEmpty())
        {
-               CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, FX_NEW CPDF_Dictionary);
+               CPDF_Stream* pNewContents = new CPDF_Stream(NULL, 0, new CPDF_Dictionary);
                dwObjNum = pDocument->AddIndirectObject(pNewContents);
                pContentsArray->AddReference(pDocument, dwObjNum);
-               
+
                CFX_ByteString sStream;
                sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
-               pNewContents->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE);
+               pNewContents->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, FALSE);
        }
 }
  
@@ -345,14 +342,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");
@@ -399,10 +391,10 @@ DLLEXPORT int STDCALL FPDFPage_Flatten( FPDF_PAGE page, int nFlag)
        if (!pRes)
        {
                pRes = new CPDF_Dictionary;
-               pPageDict->SetAt("Resources", pRes);
+               pPageDict->SetAt("Resources", pRes );
        }
 
-       CPDF_Stream* pNewXObject = new CPDF_Stream(NULL, 0, FX_NEW CPDF_Dictionary);
+       CPDF_Stream* pNewXObject = new CPDF_Stream(NULL, 0, new CPDF_Dictionary);
        FX_DWORD dwObjNum = pDocument->AddIndirectObject(pNewXObject);
        CPDF_Dictionary* pPageXObject = pRes->GetDict("XObject");
        if (!pPageXObject)
@@ -528,7 +520,7 @@ DLLEXPORT int STDCALL FPDFPage_Flatten( FPDF_PAGE page, int nFlag)
                CPDF_StreamAcc acc;
                acc.LoadAllData(pNewXObject);
 
-               FX_LPCBYTE pData = acc.GetData();
+               const uint8_t* pData = acc.GetData();
                CFX_ByteString sStream(pData, acc.GetSize());
                CFX_ByteString sTemp;
 
@@ -546,7 +538,7 @@ DLLEXPORT int STDCALL FPDFPage_Flatten( FPDF_PAGE page, int nFlag)
                sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, sFormName.c_str());
                sStream += sTemp;
 
-               pNewXObject->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE);
+               pNewXObject->SetData((const uint8_t*)sStream, sStream.GetLength(), FALSE, FALSE);
        }
        pPageDict->RemoveAt( "Annots" );