blob: c4fa2d654e3f010c325fdae237c252f8cc03d931 [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
Lei Zhangb4e7f302015-11-06 15:52:32 -08007#include "public/fpdf_edit.h"
8
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009#include "../include/fsdk_define.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070010
Nico Weber9d8ec5a2015-08-04 13:00:21 -070011DLLEXPORT FPDF_PAGEOBJECT STDCALL
12FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document) {
Tom Sepez471a1032015-10-15 16:17:18 -070013 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
14 if (!pDoc)
15 return nullptr;
Tom Sepezae51c812015-08-05 12:34:06 -070016 CPDF_ImageObject* pImageObj = new CPDF_ImageObject;
Tom Sepez471a1032015-10-15 16:17:18 -070017 CPDF_Image* pImg = new CPDF_Image(pDoc);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070018 pImageObj->m_pImage = pImg;
19 return pImageObj;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020}
21
Nico Weber9d8ec5a2015-08-04 13:00:21 -070022DLLEXPORT FPDF_BOOL STDCALL
23FPDFImageObj_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-Malek3f3b45c2014-05-23 17:28:10 -070029
Tom Sepezae51c812015-08-05 12:34:06 -070030 IFX_FileRead* pFile = new CPDF_CustomAccess(fileAccess);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070031 CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
32 pImgObj->m_GeneralState.GetModify();
33 for (int index = 0; index < nCount; index++) {
Tom Sepezdb0be962015-10-16 14:00:21 -070034 CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035 if (!pPage)
36 continue;
37 pImgObj->m_pImage->ResetCache(pPage, NULL);
38 }
39 pImgObj->m_pImage->SetJpegImage(pFile);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070040
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070042}
43
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044DLLEXPORT 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-Malek3f3b45c2014-05-23 17:28:10 -070062}
63
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064DLLEXPORT 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 Sepezdb0be962015-10-16 14:00:21 -070075 CPDF_Page* pPage = CPDFPageFromFPDFPage(pages[index]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 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-Malek3f3b45c2014-05-23 17:28:10 -070083}