188b5f070df388a0394a8ce54c09100c4f8786b7
[pdfium.git] / fpdfsdk / src / fpdfeditimg.cpp
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.
4  
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "../include/fsdk_define.h"
8 #include "../include/fpdfedit.h"
9 #include "../include/fpdfxfa/fpdfxfa_doc.h"
10 #include "../include/fpdfxfa/fpdfxfa_page.h"
11
12
13 DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document)
14 {
15         if (!document)
16                 return NULL;
17         CPDF_ImageObject* pImageObj = FX_NEW CPDF_ImageObject;
18         CPDF_Image* pImg = FX_NEW CPDF_Image(((CPDFXFA_Document *)document)->GetPDFDoc());
19         pImageObj->m_pImage = pImg;
20         return pImageObj;
21 }
22
23 DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, int nCount,FPDF_PAGEOBJECT image_object, FPDF_FILEACCESS* fileAccess)
24 {
25         if (!image_object || !fileAccess || !pages)
26                 return FALSE;
27
28         IFX_FileRead* pFile = FX_NEW CPDF_CustomAccess(fileAccess);
29
30         CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
31         pImgObj->m_GeneralState.GetModify();
32         for (int index=0;index<nCount;index++)
33         {
34                 CPDF_Page* pPage = ((CPDFXFA_Page*)pages[index])->GetPDFPage(); 
35                 if (!pPage)
36                         continue;
37                 pImgObj->m_pImage->ResetCache(pPage,NULL);
38         }
39         pImgObj->m_pImage->SetJpegImage(pFile);
40
41         return TRUE;
42 }
43
44
45 DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix      (FPDF_PAGEOBJECT image_object,
46                                                                                                  double a, double b, double c, double d, double e, double f)
47 {
48         if (!image_object)
49                 return FALSE;
50         CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
51         pImgObj->m_Matrix.a = (FX_FLOAT)a;
52         pImgObj->m_Matrix.b = (FX_FLOAT)b;
53         pImgObj->m_Matrix.c = (FX_FLOAT)c;
54         pImgObj->m_Matrix.d = (FX_FLOAT)d;
55         pImgObj->m_Matrix.e = (FX_FLOAT)e;
56         pImgObj->m_Matrix.f = (FX_FLOAT)f;
57         pImgObj->CalcBoundingBox();
58         return  TRUE;
59 }
60
61 DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,int nCount,FPDF_PAGEOBJECT image_object,FPDF_BITMAP bitmap)
62 {
63         if (!image_object || !bitmap || !pages)
64                 return FALSE;
65         CFX_DIBitmap* pBmp = NULL;
66         pBmp = (CFX_DIBitmap*)bitmap;
67         CPDF_ImageObject* pImgObj = (CPDF_ImageObject*)image_object;
68         pImgObj->m_GeneralState.GetModify();
69         for (int index=0;index<nCount;index++)
70         {
71                 CPDF_Page* pPage = ((CPDFXFA_Page*)pages[index])->GetPDFPage();
72                 if (!pPage) continue;
73                 pImgObj->m_pImage->ResetCache(pPage,NULL);
74         }
75         pImgObj->m_pImage->SetImage(pBmp,FALSE);
76         pImgObj->CalcBoundingBox();
77         return TRUE;
78 }
79