Revert "Revert "Add type cast definitions for CPDF_Dictionary.""
[pdfium.git] / fpdfsdk / src / fpdfeditimg.cpp
index ea81203..73fc251 100644 (file)
@@ -1,74 +1,82 @@
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../include/fsdk_define.h"\r
-#include "../include/fpdfedit.h"\r
-\r
-\r
-DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document)\r
-{\r
-       if (!document)\r
-               return NULL;\r
-       CPDF_ImageObject* pImageObj = FX_NEW CPDF_ImageObject;\r
-       CPDF_Image* pImg = FX_NEW CPDF_Image((CPDF_Document *)document);\r
-       pImageObj->m_pImage = pImg;\r
-       return pImageObj;\r
-}\r
-\r
-DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, int nCount,FPDF_PAGEOBJECT image_object, FPDF_FILEACCESS* fileAccess)\r
-{\r
-       if (!image_object || !fileAccess)\r
-               return FALSE;\r
-\r
-       IFX_FileRead* pFile = FX_NEW CPDF_CustomAccess(fileAccess);\r
-\r
-       CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;\r
-       pImgObj->m_GeneralState.GetModify();\r
-       for (int index=0;index<nCount;index++)\r
-       {\r
-               CPDF_Page* pPage = (CPDF_Page*)pages[index]; \r
-               pImgObj->m_pImage->ResetCache(pPage,NULL);\r
-       }\r
-       pImgObj->m_pImage->SetJpegImage(pFile);\r
-\r
-       return TRUE;\r
-}\r
-\r
-\r
-DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix     (FPDF_PAGEOBJECT image_object,\r
-                                                                                                double a, double b, double c, double d, double e, double f)\r
-{\r
-       if (!image_object)\r
-               return FALSE;\r
-       CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;\r
-       pImgObj->m_Matrix.a = (FX_FLOAT)a;\r
-       pImgObj->m_Matrix.b = (FX_FLOAT)b;\r
-       pImgObj->m_Matrix.c = (FX_FLOAT)c;\r
-       pImgObj->m_Matrix.d = (FX_FLOAT)d;\r
-       pImgObj->m_Matrix.e = (FX_FLOAT)e;\r
-       pImgObj->m_Matrix.f = (FX_FLOAT)f;\r
-       pImgObj->CalcBoundingBox();\r
-       return  TRUE;\r
-}\r
-\r
-DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,int nCount,FPDF_PAGEOBJECT image_object,FPDF_BITMAP bitmap)\r
-{\r
-       if (!image_object || !bitmap)\r
-               return FALSE;\r
-       CFX_DIBitmap* pBmp = NULL;\r
-       pBmp = (CFX_DIBitmap*)bitmap;\r
-       CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;\r
-       pImgObj->m_GeneralState.GetModify();\r
-       for (int index=0;index<nCount;index++)\r
-       {\r
-               CPDF_Page* pPage = (CPDF_Page*)pages[index]; \r
-               pImgObj->m_pImage->ResetCache(pPage,NULL);\r
-       }\r
-       pImgObj->m_pImage->SetImage(pBmp,FALSE);\r
-       pImgObj->CalcBoundingBox();\r
-       return TRUE;\r
-}\r
-\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../public/fpdf_edit.h"
+#include "../include/fsdk_define.h"
+
+DLLEXPORT FPDF_PAGEOBJECT STDCALL
+FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) {
+  CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+  if (!pDoc)
+    return nullptr;
+  CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
+  CPDF_Image* pImg = new CPDF_Image(pDoc);
+  pImageObj->m_pImage = pImg;
+  return pImageObj;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL
+FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
+                          int nCount,
+                          FPDF_PAGEOBJECT image_object,
+                          FPDF_FILEACCESS* fileAccess) {
+  if (!image_object || !fileAccess || !pages)
+    return FALSE;
+
+  IFX_FileRead* pFile = new CPDF_CustomAccess(fileAccess);
+  CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
+  pImgObj->m_GeneralState.GetModify();
+  for (int index = 0; index < nCount; index++) {
+    CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
+    if (!pPage)
+      continue;
+    pImgObj->m_pImage->ResetCache(pPage, NULL);
+  }
+  pImgObj->m_pImage->SetJpegImage(pFile);
+
+  return TRUE;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object,
+                                                   double a,
+                                                   double b,
+                                                   double c,
+                                                   double d,
+                                                   double e,
+                                                   double f) {
+  if (!image_object)
+    return FALSE;
+  CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
+  pImgObj->m_Matrix.a = (FX_FLOAT)a;
+  pImgObj->m_Matrix.b = (FX_FLOAT)b;
+  pImgObj->m_Matrix.c = (FX_FLOAT)c;
+  pImgObj->m_Matrix.d = (FX_FLOAT)d;
+  pImgObj->m_Matrix.e = (FX_FLOAT)e;
+  pImgObj->m_Matrix.f = (FX_FLOAT)f;
+  pImgObj->CalcBoundingBox();
+  return TRUE;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,
+                                                   int nCount,
+                                                   FPDF_PAGEOBJECT image_object,
+                                                   FPDF_BITMAP bitmap) {
+  if (!image_object || !bitmap || !pages)
+    return FALSE;
+  CFX_DIBitmap* pBmp = NULL;
+  pBmp = (CFX_DIBitmap*)bitmap;
+  CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
+  pImgObj->m_GeneralState.GetModify();
+  for (int index = 0; index < nCount; index++) {
+    CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
+    if (!pPage)
+      continue;
+    pImgObj->m_pImage->ResetCache(pPage, NULL);
+  }
+  pImgObj->m_pImage->SetImage(pBmp, FALSE);
+  pImgObj->CalcBoundingBox();
+  return TRUE;
+}