blob: 73fc2511957666e42453747554a758c48bd1d394 [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"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Nico Weber9d8ec5a2015-08-04 13:00:21 -070010DLLEXPORT FPDF_PAGEOBJECT STDCALL
11FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) {
Tom Sepez471a1032015-10-15 16:17:18 -070012 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
13 if (!pDoc)
14 return nullptr;
Tom Sepezae51c812015-08-05 12:34:06 -070015 CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
Tom Sepez471a1032015-10-15 16:17:18 -070016 CPDF_Image* pImg = new CPDF_Image(pDoc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070017 pImageObj->m_pImage = pImg;
18 return pImageObj;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070019}
20
Nico Weber9d8ec5a2015-08-04 13:00:21 -070021DLLEXPORT FPDF_BOOL STDCALL
22FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages,
23 int nCount,
24 FPDF_PAGEOBJECT image_object,
25 FPDF_FILEACCESS* fileAccess) {
26 if (!image_object || !fileAccess || !pages)
27 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070028
Tom Sepezae51c812015-08-05 12:34:06 -070029 IFX_FileRead* pFile = new CPDF_CustomAccess(fileAccess);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070030 CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
31 pImgObj->m_GeneralState.GetModify();
32 for (int index = 0; index < nCount; index++) {
Tom Sepezdb0be962015-10-16 14:00:21 -070033 CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070034 if (!pPage)
35 continue;
36 pImgObj->m_pImage->ResetCache(pPage, NULL);
37 }
38 pImgObj->m_pImage->SetJpegImage(pFile);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070041}
42
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix(FPDF_PAGEOBJECT image_object,
44 double a,
45 double b,
46 double c,
47 double d,
48 double e,
49 double f) {
50 if (!image_object)
51 return FALSE;
52 CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
53 pImgObj->m_Matrix.a = (FX_FLOAT)a;
54 pImgObj->m_Matrix.b = (FX_FLOAT)b;
55 pImgObj->m_Matrix.c = (FX_FLOAT)c;
56 pImgObj->m_Matrix.d = (FX_FLOAT)d;
57 pImgObj->m_Matrix.e = (FX_FLOAT)e;
58 pImgObj->m_Matrix.f = (FX_FLOAT)f;
59 pImgObj->CalcBoundingBox();
60 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070061}
62
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,
64 int nCount,
65 FPDF_PAGEOBJECT image_object,
66 FPDF_BITMAP bitmap) {
67 if (!image_object || !bitmap || !pages)
68 return FALSE;
69 CFX_DIBitmap* pBmp = NULL;
70 pBmp = (CFX_DIBitmap*)bitmap;
71 CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
72 pImgObj->m_GeneralState.GetModify();
73 for (int index = 0; index < nCount; index++) {
Tom Sepezdb0be962015-10-16 14:00:21 -070074 CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075 if (!pPage)
76 continue;
77 pImgObj->m_pImage->ResetCache(pPage, NULL);
78 }
79 pImgObj->m_pImage->SetImage(pBmp, FALSE);
80 pImgObj->CalcBoundingBox();
81 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070082}