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 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | #include "../include/fsdk_define.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 10 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 11 | DLLEXPORT FPDF_PAGEOBJECT STDCALL |
| 12 | FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) { |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 13 | CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 14 | if (!pDoc) |
| 15 | return nullptr; |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 16 | CPDF_ImageObject* pImageObj = new CPDF_ImageObject; |
Tom Sepez | 471a103 | 2015-10-15 16:17:18 -0700 | [diff] [blame] | 17 | CPDF_Image* pImg = new CPDF_Image(pDoc); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 18 | pImageObj->m_pImage = pImg; |
| 19 | return pImageObj; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 20 | } |
| 21 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 22 | DLLEXPORT FPDF_BOOL STDCALL |
| 23 | FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, |
| 24 | int nCount, |
| 25 | FPDF_PAGEOBJECT image_object, |
| 26 | FPDF_FILEACCESS* fileAccess) { |
| 27 | if (!image_object || !fileAccess || !pages) |
| 28 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 29 | |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 30 | IFX_FileRead* pFile = new CPDF_CustomAccess(fileAccess); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object; |
| 32 | pImgObj->m_GeneralState.GetModify(); |
| 33 | for (int index = 0; index < nCount; index++) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 34 | CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 35 | if (!pPage) |
| 36 | continue; |
| 37 | pImgObj->m_pImage->ResetCache(pPage, NULL); |
| 38 | } |
| 39 | pImgObj->m_pImage->SetJpegImage(pFile); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 40 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 41 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object, |
| 45 | double a, |
| 46 | double b, |
| 47 | double c, |
| 48 | double d, |
| 49 | double e, |
| 50 | double f) { |
| 51 | if (!image_object) |
| 52 | return FALSE; |
| 53 | CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object; |
| 54 | pImgObj->m_Matrix.a = (FX_FLOAT)a; |
| 55 | pImgObj->m_Matrix.b = (FX_FLOAT)b; |
| 56 | pImgObj->m_Matrix.c = (FX_FLOAT)c; |
| 57 | pImgObj->m_Matrix.d = (FX_FLOAT)d; |
| 58 | pImgObj->m_Matrix.e = (FX_FLOAT)e; |
| 59 | pImgObj->m_Matrix.f = (FX_FLOAT)f; |
| 60 | pImgObj->CalcBoundingBox(); |
| 61 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 64 | DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages, |
| 65 | int nCount, |
| 66 | FPDF_PAGEOBJECT image_object, |
| 67 | FPDF_BITMAP bitmap) { |
| 68 | if (!image_object || !bitmap || !pages) |
| 69 | return FALSE; |
| 70 | CFX_DIBitmap* pBmp = NULL; |
| 71 | pBmp = (CFX_DIBitmap*)bitmap; |
| 72 | CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object; |
| 73 | pImgObj->m_GeneralState.GetModify(); |
| 74 | for (int index = 0; index < nCount; index++) { |
Tom Sepez | db0be96 | 2015-10-16 14:00:21 -0700 | [diff] [blame] | 75 | CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | if (!pPage) |
| 77 | continue; |
| 78 | pImgObj->m_pImage->ResetCache(pPage, NULL); |
| 79 | } |
| 80 | pImgObj->m_pImage->SetImage(pBmp, FALSE); |
| 81 | pImgObj->CalcBoundingBox(); |
| 82 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 83 | } |