blob: f839d2c791d89e841fa9df4b7c2c6c5197195604 [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) {
14 if (!document)
15 return NULL;
Tom Sepezae51c812015-08-05 12:34:06 -070016 CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070017 CPDF_Image* pImg =
Tom Sepezae51c812015-08-05 12:34:06 -070018 new CPDF_Image(((CPDFXFA_Document*)document)->GetPDFDoc());
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);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033 CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
34 pImgObj->m_GeneralState.GetModify();
35 for (int index = 0; index < nCount; index++) {
36 CPDF_Page* pPage = ((CPDFXFA_Page*)pages[index])->GetPDFPage();
37 if (!pPage)
38 continue;
39 pImgObj->m_pImage->ResetCache(pPage, NULL);
40 }
41 pImgObj->m_pImage->SetJpegImage(pFile);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070042
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044}
45
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object,
47 double a,
48 double b,
49 double c,
50 double d,
51 double e,
52 double f) {
53 if (!image_object)
54 return FALSE;
55 CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
56 pImgObj->m_Matrix.a = (FX_FLOAT)a;
57 pImgObj->m_Matrix.b = (FX_FLOAT)b;
58 pImgObj->m_Matrix.c = (FX_FLOAT)c;
59 pImgObj->m_Matrix.d = (FX_FLOAT)d;
60 pImgObj->m_Matrix.e = (FX_FLOAT)e;
61 pImgObj->m_Matrix.f = (FX_FLOAT)f;
62 pImgObj->CalcBoundingBox();
63 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070064}
65
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,
67 int nCount,
68 FPDF_PAGEOBJECT image_object,
69 FPDF_BITMAP bitmap) {
70 if (!image_object || !bitmap || !pages)
71 return FALSE;
72 CFX_DIBitmap* pBmp = NULL;
73 pBmp = (CFX_DIBitmap*)bitmap;
74 CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
75 pImgObj->m_GeneralState.GetModify();
76 for (int index = 0; index < nCount; index++) {
77 CPDF_Page* pPage = ((CPDFXFA_Page*)pages[index])->GetPDFPage();
78 if (!pPage)
79 continue;
80 pImgObj->m_pImage->ResetCache(pPage, NULL);
81 }
82 pImgObj->m_pImage->SetImage(pBmp, FALSE);
83 pImgObj->CalcBoundingBox();
84 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070085}