John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Lei Zhang | b4e7f30 | 2015-11-06 15:52:32 -0800 | [diff] [blame] | 7 | #include "public/fpdf_edit.h" |
| 8 | |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame^] | 9 | #include "core/fpdfapi/fpdf_page/include/cpdf_image.h" |
Dan Sinclair | 584b1e6 | 2016-03-21 09:15:45 -0400 | [diff] [blame] | 10 | #include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" |
| 11 | #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 12 | #include "core/fpdfapi/include/cpdf_modulemgr.h" |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 13 | #include "fpdfsdk/include/fsdk_define.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 14 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 15 | DLLEXPORT FPDF_PAGEOBJECT STDCALL |
| 16 | FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 17 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 18 | if (!pDoc) |
| 19 | return nullptr; |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 20 | CPDF_ImageObject* pImageObj = new CPDF_ImageObject; |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 21 | CPDF_Image* pImg = new CPDF_Image(pDoc); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 22 | pImageObj->m_pImage = pImg; |
| 23 | return pImageObj; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 24 | } |
| 25 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 26 | DLLEXPORT FPDF_BOOL STDCALL |
| 27 | FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, |
| 28 | int nCount, |
| 29 | FPDF_PAGEOBJECT image_object, |
| 30 | FPDF_FILEACCESS* fileAccess) { |
| 31 | if (!image_object || !fileAccess || !pages) |
| 32 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 33 | |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 34 | IFX_FileRead* pFile = new CPDF_CustomAccess(fileAccess); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 35 | CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object; |
| 36 | pImgObj->m_GeneralState.GetModify(); |
| 37 | for (int index = 0; index < nCount; index++) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 38 | CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 39 | if (!pPage) |
| 40 | continue; |
| 41 | pImgObj->m_pImage->ResetCache(pPage, NULL); |
| 42 | } |
| 43 | pImgObj->m_pImage->SetJpegImage(pFile); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 45 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 48 | DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object, |
| 49 | double a, |
| 50 | double b, |
| 51 | double c, |
| 52 | double d, |
| 53 | double e, |
| 54 | double f) { |
| 55 | if (!image_object) |
| 56 | return FALSE; |
| 57 | CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object; |
| 58 | pImgObj->m_Matrix.a = (FX_FLOAT)a; |
| 59 | pImgObj->m_Matrix.b = (FX_FLOAT)b; |
| 60 | pImgObj->m_Matrix.c = (FX_FLOAT)c; |
| 61 | pImgObj->m_Matrix.d = (FX_FLOAT)d; |
| 62 | pImgObj->m_Matrix.e = (FX_FLOAT)e; |
| 63 | pImgObj->m_Matrix.f = (FX_FLOAT)f; |
| 64 | pImgObj->CalcBoundingBox(); |
| 65 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages, |
| 69 | int nCount, |
| 70 | FPDF_PAGEOBJECT image_object, |
| 71 | FPDF_BITMAP bitmap) { |
| 72 | if (!image_object || !bitmap || !pages) |
| 73 | return FALSE; |
| 74 | CFX_DIBitmap* pBmp = NULL; |
| 75 | pBmp = (CFX_DIBitmap*)bitmap; |
| 76 | CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object; |
| 77 | pImgObj->m_GeneralState.GetModify(); |
| 78 | for (int index = 0; index < nCount; index++) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 79 | CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | if (!pPage) |
| 81 | continue; |
| 82 | pImgObj->m_pImage->ResetCache(pPage, NULL); |
| 83 | } |
| 84 | pImgObj->m_pImage->SetImage(pBmp, FALSE); |
| 85 | pImgObj->CalcBoundingBox(); |
| 86 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 87 | } |