1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../include/fsdk_define.h"
#include "../include/fpdf_dataavail.h"
#include "../include/fpdfxfa/fpdfxfa_doc.h"
#include "../include/fpdfformfill.h"
#include "../include/fpdfxfa/fpdfxfa_app.h"
extern void ProcessParseError(FX_DWORD err_code);
class CFPDF_FileAvailWrap : public IFX_FileAvail
{
public:
CFPDF_FileAvailWrap()
{
m_pfileAvail = NULL;
}
void Set(FX_FILEAVAIL* pfileAvail)
{
m_pfileAvail = pfileAvail;
}
virtual FX_BOOL IsDataAvail( FX_FILESIZE offset, FX_DWORD size)
{
return m_pfileAvail->IsDataAvail(m_pfileAvail, offset, size);
}
private:
FX_FILEAVAIL* m_pfileAvail;
};
class CFPDF_FileAccessWrap : public IFX_FileRead
{
public:
CFPDF_FileAccessWrap()
{
m_pFileAccess = NULL;
}
void Set(FPDF_FILEACCESS* pFile)
{
m_pFileAccess = pFile;
}
virtual FX_FILESIZE GetSize()
{
return m_pFileAccess->m_FileLen;
}
virtual FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size)
{
return m_pFileAccess->m_GetBlock(m_pFileAccess->m_Param, offset, (FX_LPBYTE)buffer, size);
}
virtual void Release()
{
}
private:
FPDF_FILEACCESS* m_pFileAccess;
};
class CFPDF_DownloadHintsWrap : public IFX_DownloadHints
{
public:
CFPDF_DownloadHintsWrap(FX_DOWNLOADHINTS* pDownloadHints)
{
m_pDownloadHints = pDownloadHints;
}
public:
virtual void AddSegment(FX_FILESIZE offset, FX_DWORD size)
{
m_pDownloadHints->AddSegment(m_pDownloadHints, offset, size);
}
private:
FX_DOWNLOADHINTS* m_pDownloadHints;
};
class CFPDF_DataAvail : public CFX_Object
{
public:
CFPDF_DataAvail()
{
m_pDataAvail = NULL;
}
~CFPDF_DataAvail()
{
if (m_pDataAvail) delete m_pDataAvail;
}
CPDF_DataAvail* m_pDataAvail;
CFPDF_FileAvailWrap m_FileAvail;
CFPDF_FileAccessWrap m_FileRead;
};
DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail, FPDF_FILEACCESS* file)
{
CFPDF_DataAvail* pAvail = FX_NEW CFPDF_DataAvail;
pAvail->m_FileAvail.Set(file_avail);
pAvail->m_FileRead.Set(file);
pAvail->m_pDataAvail = FX_NEW CPDF_DataAvail(&pAvail->m_FileAvail, &pAvail->m_FileRead);
return pAvail;
}
DLLEXPORT void STDCALL FPDFAvail_Destroy(FPDF_AVAIL avail)
{
if (avail == NULL) return;
delete (CFPDF_DataAvail*)avail;
}
DLLEXPORT int STDCALL FPDFAvail_IsDocAvail(FPDF_AVAIL avail, FX_DOWNLOADHINTS* hints)
{
if (avail == NULL || hints == NULL) return 0;
CFPDF_DownloadHintsWrap hints_wrap(hints);
return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsDocAvail(&hints_wrap);
}
extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code);
DLLEXPORT FPDF_DOCUMENT STDCALL FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password)
{
if (avail == NULL) return NULL;
CPDF_Parser* pParser = FX_NEW CPDF_Parser;
pParser->SetPassword(password);
FX_DWORD err_code = pParser->StartAsynParse(((CFPDF_DataAvail*)avail)->m_pDataAvail->GetFileRead());
if (err_code) {
delete pParser;
ProcessParseError(err_code);
return NULL;
}
((CFPDF_DataAvail*)avail)->m_pDataAvail->SetDocument(pParser->GetDocument());
CheckUnSupportError(pParser->GetDocument(), FPDF_ERR_SUCCESS);
CPDF_Document* pPDFDoc = pParser->GetDocument();
CPDFXFA_App* pApp = FPDFXFA_GetApp();
CPDFXFA_Document* pDocument = FX_NEW CPDFXFA_Document(pPDFDoc, pApp);
//pDocument->LoadXFADoc();
return pDocument;
}
DLLEXPORT int STDCALL FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc)
{
if (doc == NULL) return 0;
CPDF_Document* pDoc = ((CPDFXFA_Document*)doc)->GetPDFDoc();
return ((CPDF_Parser*)pDoc->GetParser())->GetFirstPageNo();
}
DLLEXPORT int STDCALL FPDFAvail_IsPageAvail(FPDF_AVAIL avail, int page_index, FX_DOWNLOADHINTS* hints)
{
if (avail == NULL || hints == NULL) return 0;
CFPDF_DownloadHintsWrap hints_wrap(hints);
return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsPageAvail(page_index, &hints_wrap);
}
DLLEXPORT int STDCALL FPDFAvail_IsFormAvail(FPDF_AVAIL avail, FX_DOWNLOADHINTS* hints)
{
if (avail == NULL || hints == NULL) return -1;
CFPDF_DownloadHintsWrap hints_wrap(hints);
return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsFormAvail(&hints_wrap);
}
DLLEXPORT FPDF_BOOL STDCALL FPDFAvail_IsLinearized(FPDF_AVAIL avail)
{
if (avail == NULL) return -1;
return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsLinearizedPDF();
}
|