blob: 09295aa3c45293646cb55116a32559b197069cfd [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez1ed8a212015-05-11 15:25:39 -07007#include "../../public/fpdf_edit.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07008#include "../include/fsdk_define.h"
Bo Xufdc00a72014-10-28 23:03:33 -07009#include "../include/fpdfxfa/fpdfxfa_doc.h"
10#include "../include/fpdfxfa/fpdfxfa_page.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070011
Nico Weber9d8ec5a2015-08-04 13:00:21 -070012DLLEXPORT FPDF_PAGEOBJECT STDCALL
13FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) {
Tom Sepez471a1032015-10-15 16:17:18 -070014 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
15 if (!pDoc)
16 return nullptr;
Tom Sepezae51c812015-08-05 12:34:06 -070017 CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
Tom Sepez471a1032015-10-15 16:17:18 -070018 CPDF_Image* pImg = new CPDF_Image(pDoc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070019 pImageObj->m_pImage = pImg;
20 return pImageObj;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070021}
22
Nico Weber9d8ec5a2015-08-04 13:00:21 -070023DLLEXPORT FPDF_BOOL STDCALL
24FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
25 int nCount,
26 FPDF_PAGEOBJECT image_object,
27 FPDF_FILEACCESS* fileAccess) {
28 if (!image_object || !fileAccess || !pages)
29 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030
Tom Sepezae51c812015-08-05 12:34:06 -070031 IFX_FileRead* pFile = new CPDF_CustomAccess(fileAccess);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032 CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
33 pImgObj->m_GeneralState.GetModify();
34 for (int index = 0; index < nCount; index++) {
35 CPDF_Page* pPage = ((CPDFXFA_Page*)pages[index])->GetPDFPage();
36 if (!pPage)
37 continue;
38 pImgObj->m_pImage->ResetCache(pPage, NULL);
39 }
40 pImgObj->m_pImage->SetJpegImage(pFile);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070041
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070043}
44
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object,
46 double a,
47 double b,
48 double c,
49 double d,
50 double e,
51 double f) {
52 if (!image_object)
53 return FALSE;
54 CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
55 pImgObj->m_Matrix.a = (FX_FLOAT)a;
56 pImgObj->m_Matrix.b = (FX_FLOAT)b;
57 pImgObj->m_Matrix.c = (FX_FLOAT)c;
58 pImgObj->m_Matrix.d = (FX_FLOAT)d;
59 pImgObj->m_Matrix.e = (FX_FLOAT)e;
60 pImgObj->m_Matrix.f = (FX_FLOAT)f;
61 pImgObj->CalcBoundingBox();
62 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070063}
64
Nico Weber9d8ec5a2015-08-04 13:00:21 -070065DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,
66 int nCount,
67 FPDF_PAGEOBJECT image_object,
68 FPDF_BITMAP bitmap) {
69 if (!image_object || !bitmap || !pages)
70 return FALSE;
71 CFX_DIBitmap* pBmp = NULL;
72 pBmp = (CFX_DIBitmap*)bitmap;
73 CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
74 pImgObj->m_GeneralState.GetModify();
75 for (int index = 0; index < nCount; index++) {
76 CPDF_Page* pPage = ((CPDFXFA_Page*)pages[index])->GetPDFPage();
77 if (!pPage)
78 continue;
79 pImgObj->m_pImage->ResetCache(pPage, NULL);
80 }
81 pImgObj->m_pImage->SetImage(pBmp, FALSE);
82 pImgObj->CalcBoundingBox();
83 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070084}