Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "public/fpdf_edit.h" | 7 #include "public/fpdf_edit.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" | 9 #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" |
| 10 #include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" | 10 #include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" |
| 11 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" | 11 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" |
| 12 #include "core/fpdfapi/include/cpdf_modulemgr.h" | 12 #include "core/fpdfapi/include/cpdf_modulemgr.h" |
| 13 #include "fpdfsdk/include/fsdk_define.h" | 13 #include "fpdfsdk/include/fsdk_define.h" |
| 14 | 14 |
| 15 DLLEXPORT FPDF_PAGEOBJECT STDCALL | 15 DLLEXPORT FPDF_PAGEOBJECT STDCALL |
| 16 FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) { | 16 FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) { |
| 17 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 17 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 18 if (!pDoc) | 18 if (!pDoc) |
| 19 return nullptr; | 19 return nullptr; |
| 20 | |
| 20 CPDF_ImageObject* pImageObj = new CPDF_ImageObject; | 21 CPDF_ImageObject* pImageObj = new CPDF_ImageObject; |
| 21 CPDF_Image* pImg = new CPDF_Image(pDoc); | 22 pImageObj->m_pImage = new CPDF_Image(pDoc); |
|
dsinclair
2016/07/29 13:22:49
Should this be a unique_ptr?
Lei Zhang
2016/07/29 14:46:15
No. CPDF_Image is Released half the time. It's won
| |
| 22 pImageObj->m_pImage = pImg; | |
| 23 return pImageObj; | 23 return pImageObj; |
| 24 } | 24 } |
| 25 | 25 |
| 26 DLLEXPORT FPDF_BOOL STDCALL | 26 DLLEXPORT FPDF_BOOL STDCALL |
| 27 FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, | 27 FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, |
| 28 int nCount, | 28 int nCount, |
| 29 FPDF_PAGEOBJECT image_object, | 29 FPDF_PAGEOBJECT image_object, |
| 30 FPDF_FILEACCESS* fileAccess) { | 30 FPDF_FILEACCESS* fileAccess) { |
| 31 if (!image_object || !fileAccess || !pages) | 31 if (!image_object || !fileAccess || !pages) |
| 32 return FALSE; | 32 return FALSE; |
| 33 | 33 |
| 34 IFX_FileRead* pFile = new CPDF_CustomAccess(fileAccess); | 34 IFX_FileRead* pFile = new CPDF_CustomAccess(fileAccess); |
| 35 CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object; | 35 CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object); |
| 36 pImgObj->m_GeneralState.GetModify(); | 36 pImgObj->m_GeneralState.GetModify(); |
| 37 for (int index = 0; index < nCount; index++) { | 37 for (int index = 0; index < nCount; index++) { |
| 38 CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); | 38 CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); |
| 39 if (!pPage) | 39 if (pPage) |
| 40 continue; | 40 pImgObj->m_pImage->ResetCache(pPage, nullptr); |
| 41 pImgObj->m_pImage->ResetCache(pPage, nullptr); | |
| 42 } | 41 } |
| 43 pImgObj->m_pImage->SetJpegImage(pFile); | 42 pImgObj->m_pImage->SetJpegImage(pFile); |
| 44 | 43 |
| 45 return TRUE; | 44 return TRUE; |
| 46 } | 45 } |
| 47 | 46 |
| 48 DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object, | 47 DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object, |
| 49 double a, | 48 double a, |
| 50 double b, | 49 double b, |
| 51 double c, | 50 double c, |
| 52 double d, | 51 double d, |
| 53 double e, | 52 double e, |
| 54 double f) { | 53 double f) { |
| 55 if (!image_object) | 54 if (!image_object) |
| 56 return FALSE; | 55 return FALSE; |
| 57 CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object; | 56 |
| 58 pImgObj->m_Matrix.a = (FX_FLOAT)a; | 57 CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object); |
| 59 pImgObj->m_Matrix.b = (FX_FLOAT)b; | 58 pImgObj->m_Matrix.a = static_cast<FX_FLOAT>(a); |
| 60 pImgObj->m_Matrix.c = (FX_FLOAT)c; | 59 pImgObj->m_Matrix.b = static_cast<FX_FLOAT>(b); |
| 61 pImgObj->m_Matrix.d = (FX_FLOAT)d; | 60 pImgObj->m_Matrix.c = static_cast<FX_FLOAT>(c); |
| 62 pImgObj->m_Matrix.e = (FX_FLOAT)e; | 61 pImgObj->m_Matrix.d = static_cast<FX_FLOAT>(d); |
| 63 pImgObj->m_Matrix.f = (FX_FLOAT)f; | 62 pImgObj->m_Matrix.e = static_cast<FX_FLOAT>(e); |
| 63 pImgObj->m_Matrix.f = static_cast<FX_FLOAT>(f); | |
| 64 pImgObj->CalcBoundingBox(); | 64 pImgObj->CalcBoundingBox(); |
| 65 return TRUE; | 65 return TRUE; |
| 66 } | 66 } |
| 67 | 67 |
| 68 DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages, | 68 DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages, |
| 69 int nCount, | 69 int nCount, |
| 70 FPDF_PAGEOBJECT image_object, | 70 FPDF_PAGEOBJECT image_object, |
| 71 FPDF_BITMAP bitmap) { | 71 FPDF_BITMAP bitmap) { |
| 72 if (!image_object || !bitmap || !pages) | 72 if (!image_object || !bitmap || !pages) |
| 73 return FALSE; | 73 return FALSE; |
| 74 CFX_DIBitmap* pBmp = nullptr; | 74 |
| 75 pBmp = (CFX_DIBitmap*)bitmap; | 75 CPDF_ImageObject* pImgObj = reinterpret_cast<CPDF_ImageObject*>(image_object); |
| 76 CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object; | |
| 77 pImgObj->m_GeneralState.GetModify(); | 76 pImgObj->m_GeneralState.GetModify(); |
| 78 for (int index = 0; index < nCount; index++) { | 77 for (int index = 0; index < nCount; index++) { |
| 79 CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); | 78 CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); |
| 80 if (!pPage) | 79 if (pPage) |
| 81 continue; | 80 pImgObj->m_pImage->ResetCache(pPage, nullptr); |
| 82 pImgObj->m_pImage->ResetCache(pPage, nullptr); | |
| 83 } | 81 } |
| 84 pImgObj->m_pImage->SetImage(pBmp, FALSE); | 82 pImgObj->m_pImage->SetImage(reinterpret_cast<CFX_DIBitmap*>(bitmap), FALSE); |
| 85 pImgObj->CalcBoundingBox(); | 83 pImgObj->CalcBoundingBox(); |
| 86 return TRUE; | 84 return TRUE; |
| 87 } | 85 } |
| OLD | NEW |