OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "public/fpdfview.h" | 7 #include "public/fpdfview.h" |
8 | 8 |
9 #ifdef PDF_ENABLE_XFA | |
10 #include "../include/fpdfxfa/fpdfxfa_app.h" | |
11 #include "../include/fpdfxfa/fpdfxfa_doc.h" | |
12 #include "../include/fpdfxfa/fpdfxfa_page.h" | |
13 #include "../include/fpdfxfa/fpdfxfa_util.h" | |
14 #include "core/include/fpdfapi/fpdf_module.h" | |
15 #endif | |
16 #include "core/include/fxcodec/fx_codec.h" | 9 #include "core/include/fxcodec/fx_codec.h" |
17 #include "core/include/fxcrt/fx_safe_types.h" | 10 #include "core/include/fxcrt/fx_safe_types.h" |
18 #include "fpdfsdk/include/fsdk_define.h" | 11 #include "fpdfsdk/include/fsdk_define.h" |
19 #include "fpdfsdk/include/fsdk_mgr.h" | 12 #include "fpdfsdk/include/fsdk_mgr.h" |
20 #include "fpdfsdk/include/fsdk_rendercontext.h" | 13 #include "fpdfsdk/include/fsdk_rendercontext.h" |
21 #include "fpdfsdk/include/javascript/IJavaScript.h" | 14 #include "fpdfsdk/include/javascript/IJavaScript.h" |
22 #include "public/fpdf_ext.h" | 15 #include "public/fpdf_ext.h" |
23 #ifdef PDF_ENABLE_XFA | |
24 #include "public/fpdf_formfill.h" | |
25 #endif | |
26 #include "public/fpdf_progressive.h" | 16 #include "public/fpdf_progressive.h" |
27 #include "third_party/base/nonstd_unique_ptr.h" | 17 #include "third_party/base/nonstd_unique_ptr.h" |
28 #include "third_party/base/numerics/safe_conversions_impl.h" | 18 #include "third_party/base/numerics/safe_conversions_impl.h" |
29 | 19 |
| 20 #ifdef PDF_ENABLE_XFA |
| 21 #include "../include/fpdfxfa/fpdfxfa_app.h" |
| 22 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 23 #include "../include/fpdfxfa/fpdfxfa_page.h" |
| 24 #include "../include/fpdfxfa/fpdfxfa_util.h" |
| 25 #include "core/include/fpdfapi/fpdf_module.h" |
| 26 #include "public/fpdf_formfill.h" |
| 27 #endif // PDF_ENABLE_XFA |
| 28 |
30 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { | 29 UnderlyingDocumentType* UnderlyingFromFPDFDocument(FPDF_DOCUMENT doc) { |
31 return static_cast<UnderlyingDocumentType*>(doc); | 30 return static_cast<UnderlyingDocumentType*>(doc); |
32 } | 31 } |
33 | 32 |
34 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { | 33 FPDF_DOCUMENT FPDFDocumentFromUnderlying(UnderlyingDocumentType* doc) { |
35 return static_cast<FPDF_DOCUMENT>(doc); | 34 return static_cast<FPDF_DOCUMENT>(doc); |
36 } | 35 } |
37 | 36 |
38 UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { | 37 UnderlyingPageType* UnderlyingFromFPDFPage(FPDF_PAGE page) { |
39 return static_cast<UnderlyingPageType*>(page); | 38 return static_cast<UnderlyingPageType*>(page); |
40 } | 39 } |
41 | 40 |
42 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { | 41 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { |
43 #ifndef PDF_ENABLE_XFA | 42 #ifdef PDF_ENABLE_XFA |
| 43 return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; |
| 44 #else // PDF_ENABLE_XFA |
44 return UnderlyingFromFPDFDocument(doc); | 45 return UnderlyingFromFPDFDocument(doc); |
45 #else | 46 #endif // PDF_ENABLE_XFA |
46 return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; | |
47 #endif | |
48 } | 47 } |
49 | 48 |
50 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { | 49 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { |
51 #ifndef PDF_ENABLE_XFA | 50 #ifdef PDF_ENABLE_XFA |
52 return FPDFDocumentFromUnderlying(doc); | |
53 #else | |
54 return doc ? FPDFDocumentFromUnderlying( | 51 return doc ? FPDFDocumentFromUnderlying( |
55 new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance())) | 52 new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance())) |
56 : nullptr; | 53 : nullptr; |
57 #endif | 54 #else // PDF_ENABLE_XFA |
| 55 return FPDFDocumentFromUnderlying(doc); |
| 56 #endif // PDF_ENABLE_XFA |
58 } | 57 } |
59 | 58 |
60 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { | 59 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { |
61 #ifndef PDF_ENABLE_XFA | 60 #ifdef PDF_ENABLE_XFA |
| 61 return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; |
| 62 #else // PDF_ENABLE_XFA |
62 return UnderlyingFromFPDFPage(page); | 63 return UnderlyingFromFPDFPage(page); |
63 #else | 64 #endif // PDF_ENABLE_XFA |
64 return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; | |
65 } | 65 } |
66 | 66 |
| 67 #ifdef PDF_ENABLE_XFA |
67 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { | 68 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { |
68 m_pFS = pFS; | 69 m_pFS = pFS; |
69 m_nCurPos = 0; | 70 m_nCurPos = 0; |
70 } | 71 } |
71 | 72 |
72 IFX_FileStream* CFPDF_FileStream::Retain() { | 73 IFX_FileStream* CFPDF_FileStream::Retain() { |
73 return this; | 74 return this; |
74 } | 75 } |
75 | 76 |
76 void CFPDF_FileStream::Release() { | 77 void CFPDF_FileStream::Release() { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 return TRUE; | 135 return TRUE; |
135 } | 136 } |
136 return FALSE; | 137 return FALSE; |
137 } | 138 } |
138 | 139 |
139 FX_BOOL CFPDF_FileStream::Flush() { | 140 FX_BOOL CFPDF_FileStream::Flush() { |
140 if (!m_pFS || !m_pFS->Flush) | 141 if (!m_pFS || !m_pFS->Flush) |
141 return TRUE; | 142 return TRUE; |
142 | 143 |
143 return m_pFS->Flush(m_pFS->clientData) == 0; | 144 return m_pFS->Flush(m_pFS->clientData) == 0; |
144 #endif | |
145 } | 145 } |
| 146 #endif // PDF_ENABLE_XFA |
146 | 147 |
147 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { | 148 CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess) { |
148 m_FileAccess = *pFileAccess; | 149 m_FileAccess = *pFileAccess; |
149 #ifdef PDF_ENABLE_XFA | 150 #ifdef PDF_ENABLE_XFA |
150 m_BufferOffset = (FX_DWORD)-1; | 151 m_BufferOffset = (FX_DWORD)-1; |
| 152 #endif // PDF_ENABLE_XFA |
151 } | 153 } |
152 | 154 |
| 155 #ifdef PDF_ENABLE_XFA |
153 FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, uint8_t& ch) { | 156 FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, uint8_t& ch) { |
154 if (pos >= m_FileAccess.m_FileLen) | 157 if (pos >= m_FileAccess.m_FileLen) |
155 return FALSE; | 158 return FALSE; |
156 if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || | 159 if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || |
157 pos >= m_BufferOffset + 512) { | 160 pos >= m_BufferOffset + 512) { |
158 // Need to read from file access | 161 // Need to read from file access |
159 m_BufferOffset = pos; | 162 m_BufferOffset = pos; |
160 int size = 512; | 163 int size = 512; |
161 if (pos + 512 > m_FileAccess.m_FileLen) | 164 if (pos + 512 > m_FileAccess.m_FileLen) |
162 size = m_FileAccess.m_FileLen - pos; | 165 size = m_FileAccess.m_FileLen - pos; |
163 if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffset, m_Buffer, | 166 if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffset, m_Buffer, |
164 size)) | 167 size)) |
165 return FALSE; | 168 return FALSE; |
166 } | 169 } |
167 ch = m_Buffer[pos - m_BufferOffset]; | 170 ch = m_Buffer[pos - m_BufferOffset]; |
168 return TRUE; | 171 return TRUE; |
169 } | 172 } |
170 | 173 |
171 FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, | 174 FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, |
172 uint8_t* pBuf, | 175 uint8_t* pBuf, |
173 FX_DWORD size) { | 176 FX_DWORD size) { |
174 if (pos + size > m_FileAccess.m_FileLen) | 177 if (pos + size > m_FileAccess.m_FileLen) |
175 return FALSE; | 178 return FALSE; |
176 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size); | 179 return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size); |
177 #endif | |
178 } | 180 } |
| 181 #endif // PDF_ENABLE_XFA |
179 | 182 |
180 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, | 183 FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, |
181 FX_FILESIZE offset, | 184 FX_FILESIZE offset, |
182 size_t size) { | 185 size_t size) { |
183 if (offset < 0) { | 186 if (offset < 0) { |
184 return FALSE; | 187 return FALSE; |
185 } | 188 } |
186 FX_SAFE_FILESIZE newPos = | 189 FX_SAFE_FILESIZE newPos = |
187 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); | 190 pdfium::base::checked_cast<FX_FILESIZE, size_t>(size); |
188 newPos += offset; | 191 newPos += offset; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 g_pCodecModule = new CCodec_ModuleMgr(); | 232 g_pCodecModule = new CCodec_ModuleMgr(); |
230 | 233 |
231 CFX_GEModule::Create(cfg ? cfg->m_pUserFontPaths : nullptr); | 234 CFX_GEModule::Create(cfg ? cfg->m_pUserFontPaths : nullptr); |
232 CFX_GEModule::Get()->SetCodecModule(g_pCodecModule); | 235 CFX_GEModule::Get()->SetCodecModule(g_pCodecModule); |
233 | 236 |
234 CPDF_ModuleMgr::Create(); | 237 CPDF_ModuleMgr::Create(); |
235 CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get(); | 238 CPDF_ModuleMgr* pModuleMgr = CPDF_ModuleMgr::Get(); |
236 pModuleMgr->SetCodecModule(g_pCodecModule); | 239 pModuleMgr->SetCodecModule(g_pCodecModule); |
237 pModuleMgr->InitPageModule(); | 240 pModuleMgr->InitPageModule(); |
238 pModuleMgr->InitRenderModule(); | 241 pModuleMgr->InitRenderModule(); |
239 #ifndef PDF_ENABLE_XFA | 242 #ifdef PDF_ENABLE_XFA |
| 243 CPDFXFA_App::GetInstance()->Initialize(); |
| 244 #else // PDF_ENABLE_XFA |
240 pModuleMgr->LoadEmbeddedGB1CMaps(); | 245 pModuleMgr->LoadEmbeddedGB1CMaps(); |
241 pModuleMgr->LoadEmbeddedJapan1CMaps(); | 246 pModuleMgr->LoadEmbeddedJapan1CMaps(); |
242 pModuleMgr->LoadEmbeddedCNS1CMaps(); | 247 pModuleMgr->LoadEmbeddedCNS1CMaps(); |
243 pModuleMgr->LoadEmbeddedKorea1CMaps(); | 248 pModuleMgr->LoadEmbeddedKorea1CMaps(); |
244 #else | 249 #endif // PDF_ENABLE_XFA |
245 CPDFXFA_App::GetInstance()->Initialize(); | |
246 #endif | |
247 if (cfg && cfg->version >= 2) | 250 if (cfg && cfg->version >= 2) |
248 IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate); | 251 IJS_Runtime::Initialize(cfg->m_v8EmbedderSlot, cfg->m_pIsolate); |
249 } | 252 } |
250 | 253 |
251 DLLEXPORT void STDCALL FPDF_DestroyLibrary() { | 254 DLLEXPORT void STDCALL FPDF_DestroyLibrary() { |
252 #ifdef PDF_ENABLE_XFA | 255 #ifdef PDF_ENABLE_XFA |
253 CPDFXFA_App::ReleaseInstance(); | 256 CPDFXFA_App::ReleaseInstance(); |
254 #endif | 257 #endif // PDF_ENABLE_XFA |
255 CPDF_ModuleMgr::Destroy(); | 258 CPDF_ModuleMgr::Destroy(); |
256 CFX_GEModule::Destroy(); | 259 CFX_GEModule::Destroy(); |
257 | 260 |
258 delete g_pCodecModule; | 261 delete g_pCodecModule; |
259 g_pCodecModule = nullptr; | 262 g_pCodecModule = nullptr; |
260 } | 263 } |
261 | 264 |
262 #ifndef _WIN32 | 265 #ifndef _WIN32 |
263 int g_LastError; | 266 int g_LastError; |
264 void SetLastError(int err) { | 267 void SetLastError(int err) { |
265 g_LastError = err; | 268 g_LastError = err; |
266 } | 269 } |
267 | 270 |
268 int GetLastError() { | 271 int GetLastError() { |
269 return g_LastError; | 272 return g_LastError; |
270 } | 273 } |
271 #endif | 274 #endif // _WIN32 |
272 | 275 |
273 void ProcessParseError(FX_DWORD err_code) { | 276 void ProcessParseError(FX_DWORD err_code) { |
274 // Translate FPDFAPI error code to FPDFVIEW error code | 277 // Translate FPDFAPI error code to FPDFVIEW error code |
275 switch (err_code) { | 278 switch (err_code) { |
276 case PDFPARSE_ERROR_FILE: | 279 case PDFPARSE_ERROR_FILE: |
277 err_code = FPDF_ERR_FILE; | 280 err_code = FPDF_ERR_FILE; |
278 break; | 281 break; |
279 case PDFPARSE_ERROR_FORMAT: | 282 case PDFPARSE_ERROR_FORMAT: |
280 err_code = FPDF_ERR_FORMAT; | 283 err_code = FPDF_ERR_FORMAT; |
281 break; | 284 break; |
(...skipping 23 matching lines...) Expand all Loading... |
305 | 308 |
306 CPDF_Parser* pParser = new CPDF_Parser; | 309 CPDF_Parser* pParser = new CPDF_Parser; |
307 pParser->SetPassword(password); | 310 pParser->SetPassword(password); |
308 | 311 |
309 FX_DWORD err_code = pParser->StartParse(pFileAccess); | 312 FX_DWORD err_code = pParser->StartParse(pFileAccess); |
310 if (err_code) { | 313 if (err_code) { |
311 delete pParser; | 314 delete pParser; |
312 ProcessParseError(err_code); | 315 ProcessParseError(err_code); |
313 return NULL; | 316 return NULL; |
314 } | 317 } |
315 #ifndef PDF_ENABLE_XFA | 318 #ifdef PDF_ENABLE_XFA |
316 return pParser->GetDocument(); | |
317 #else | |
318 CPDF_Document* pPDFDoc = pParser->GetDocument(); | 319 CPDF_Document* pPDFDoc = pParser->GetDocument(); |
319 if (!pPDFDoc) | 320 if (!pPDFDoc) |
320 return NULL; | 321 return NULL; |
321 | 322 |
322 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); | 323 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
323 return new CPDFXFA_Document(pPDFDoc, pProvider); | 324 return new CPDFXFA_Document(pPDFDoc, pProvider); |
| 325 #else // PDF_ENABLE_XFA |
| 326 return pParser->GetDocument(); |
| 327 #endif // PDF_ENABLE_XFA |
324 } | 328 } |
325 | 329 |
| 330 #ifdef PDF_ENABLE_XFA |
326 DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, | 331 DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, |
327 int* docType) { | 332 int* docType) { |
328 if (!document) | 333 if (!document) |
329 return FALSE; | 334 return FALSE; |
330 | 335 |
331 CPDF_Document* pdfDoc = | 336 CPDF_Document* pdfDoc = |
332 (static_cast<CPDFXFA_Document*>(document))->GetPDFDoc(); | 337 (static_cast<CPDFXFA_Document*>(document))->GetPDFDoc(); |
333 if (!pdfDoc) | 338 if (!pdfDoc) |
334 return FALSE; | 339 return FALSE; |
335 | 340 |
(...skipping 14 matching lines...) Expand all Loading... |
350 if (bDynamicXFA) | 355 if (bDynamicXFA) |
351 *docType = DOCTYPE_DYNAMIC_XFA; | 356 *docType = DOCTYPE_DYNAMIC_XFA; |
352 else | 357 else |
353 *docType = DOCTYPE_STATIC_XFA; | 358 *docType = DOCTYPE_STATIC_XFA; |
354 | 359 |
355 return TRUE; | 360 return TRUE; |
356 } | 361 } |
357 | 362 |
358 DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) { | 363 DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document) { |
359 return document && (static_cast<CPDFXFA_Document*>(document))->LoadXFADoc(); | 364 return document && (static_cast<CPDFXFA_Document*>(document))->LoadXFADoc(); |
360 #endif | |
361 } | 365 } |
| 366 #endif // PDF_ENABLE_XFA |
362 | 367 |
363 class CMemFile final : public IFX_FileRead { | 368 class CMemFile final : public IFX_FileRead { |
364 public: | 369 public: |
365 CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {} | 370 CMemFile(uint8_t* pBuf, FX_FILESIZE size) : m_pBuf(pBuf), m_size(size) {} |
366 | 371 |
367 void Release() override { delete this; } | 372 void Release() override { delete this; } |
368 FX_FILESIZE GetSize() override { return m_size; } | 373 FX_FILESIZE GetSize() override { return m_size; } |
369 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | 374 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { |
370 if (offset < 0) { | 375 if (offset < 0) { |
371 return FALSE; | 376 return FALSE; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 return TRUE; | 446 return TRUE; |
442 } | 447 } |
443 | 448 |
444 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match | 449 // jabdelmalek: changed return type from FX_DWORD to build on Linux (and match |
445 // header). | 450 // header). |
446 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) { | 451 DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document) { |
447 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 452 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
448 if (!pDoc) | 453 if (!pDoc) |
449 #ifndef PDF_ENABLE_XFA | 454 #ifndef PDF_ENABLE_XFA |
450 return 0; | 455 return 0; |
451 #else | 456 #else // PDF_ENABLE_XFA |
452 return (FX_DWORD)-1; | 457 return (FX_DWORD)-1; |
453 #endif | 458 #endif // PDF_ENABLE_XFA |
454 | 459 |
455 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); | 460 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); |
456 return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1; | 461 return pDict ? pDict->GetInteger("P") : (FX_DWORD)-1; |
457 } | 462 } |
458 | 463 |
459 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { | 464 DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document) { |
460 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 465 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
461 if (!pDoc) | 466 if (!pDoc) |
462 return -1; | 467 return -1; |
463 | 468 |
464 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); | 469 CPDF_Dictionary* pDict = pDoc->GetParser()->GetEncryptDict(); |
465 return pDict ? pDict->GetInteger("R") : -1; | 470 return pDict ? pDict->GetInteger("R") : -1; |
466 } | 471 } |
467 | 472 |
468 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { | 473 DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document) { |
469 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); | 474 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); |
470 return pDoc ? pDoc->GetPageCount() : 0; | 475 return pDoc ? pDoc->GetPageCount() : 0; |
471 } | 476 } |
472 | 477 |
473 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, | 478 DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, |
474 int page_index) { | 479 int page_index) { |
475 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); | 480 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); |
476 if (!pDoc) | 481 if (!pDoc) |
477 return nullptr; | 482 return nullptr; |
478 | 483 |
479 if (page_index < 0 || page_index >= pDoc->GetPageCount()) | 484 if (page_index < 0 || page_index >= pDoc->GetPageCount()) |
480 return nullptr; | 485 return nullptr; |
481 | 486 |
482 #ifndef PDF_ENABLE_XFA | 487 #ifdef PDF_ENABLE_XFA |
| 488 return pDoc->GetPage(page_index); |
| 489 #else // PDF_ENABLE_XFA |
483 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); | 490 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); |
484 if (pDict == NULL) | 491 if (pDict == NULL) |
485 return NULL; | 492 return NULL; |
486 CPDF_Page* pPage = new CPDF_Page; | 493 CPDF_Page* pPage = new CPDF_Page; |
487 pPage->Load(pDoc, pDict); | 494 pPage->Load(pDoc, pDict); |
488 pPage->ParseContent(); | 495 pPage->ParseContent(); |
489 return pPage; | 496 return pPage; |
490 #else | 497 #endif // PDF_ENABLE_XFA |
491 return pDoc->GetPage(page_index); | |
492 #endif | |
493 } | 498 } |
494 | 499 |
495 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { | 500 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { |
496 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 501 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
497 return pPage ? pPage->GetPageWidth() : 0.0; | 502 return pPage ? pPage->GetPageWidth() : 0.0; |
498 } | 503 } |
499 | 504 |
500 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { | 505 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { |
501 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 506 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
502 return pPage ? pPage->GetPageHeight() : 0.0; | 507 return pPage ? pPage->GetPageHeight() : 0.0; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, | 712 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
708 rotate, flags, TRUE, NULL); | 713 rotate, flags, TRUE, NULL); |
709 | 714 |
710 delete pContext; | 715 delete pContext; |
711 pPage->RemovePrivateData((void*)1); | 716 pPage->RemovePrivateData((void*)1); |
712 } | 717 } |
713 | 718 |
714 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { | 719 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { |
715 if (!page) | 720 if (!page) |
716 return; | 721 return; |
717 #ifndef PDF_ENABLE_XFA | 722 #ifdef PDF_ENABLE_XFA |
| 723 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; |
| 724 pPage->Release(); |
| 725 #else // PDF_ENABLE_XFA |
718 CPDFSDK_PageView* pPageView = | 726 CPDFSDK_PageView* pPageView = |
719 (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page); | 727 (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page); |
720 if (pPageView && pPageView->IsLocked()) { | 728 if (pPageView && pPageView->IsLocked()) { |
721 pPageView->TakeOverPage(); | 729 pPageView->TakeOverPage(); |
722 return; | 730 return; |
723 } | 731 } |
724 delete (CPDF_Page*)page; | 732 delete (CPDF_Page*)page; |
725 #else | 733 #endif // PDF_ENABLE_XFA |
726 | |
727 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; | |
728 pPage->Release(); | |
729 #endif | |
730 } | 734 } |
731 | 735 |
732 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { | 736 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { |
733 #ifndef PDF_ENABLE_XFA | 737 #ifdef PDF_ENABLE_XFA |
| 738 delete CPDFDocumentFromFPDFDocument(document); |
| 739 #else // PDF_ENABLE_XFA |
734 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 740 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
735 if (!pDoc) | 741 if (!pDoc) |
736 return; | 742 return; |
737 | 743 CPDF_Parser* pParser = pDoc->GetParser(); |
738 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); | |
739 if (!pParser) { | 744 if (!pParser) { |
740 delete pDoc; | 745 delete pDoc; |
741 return; | 746 return; |
742 } | 747 } |
743 delete pParser; | 748 delete pParser; |
744 #else | 749 #endif // PDF_ENABLE_XFA |
745 delete CPDFDocumentFromFPDFDocument(document); | |
746 #endif | |
747 } | 750 } |
748 | 751 |
749 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() { | 752 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() { |
750 return GetLastError(); | 753 return GetLastError(); |
751 } | 754 } |
752 | 755 |
753 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, | 756 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, |
754 int start_x, | 757 int start_x, |
755 int start_y, | 758 int start_y, |
756 int size_x, | 759 int size_x, |
757 int size_y, | 760 int size_y, |
758 int rotate, | 761 int rotate, |
759 int device_x, | 762 int device_x, |
760 int device_y, | 763 int device_y, |
761 double* page_x, | 764 double* page_x, |
762 double* page_y) { | 765 double* page_y) { |
763 if (page == NULL || page_x == NULL || page_y == NULL) | 766 if (page == NULL || page_x == NULL || page_y == NULL) |
764 return; | 767 return; |
765 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 768 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
766 #ifndef PDF_ENABLE_XFA | 769 #ifdef PDF_ENABLE_XFA |
767 | 770 pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x, |
| 771 device_y, page_x, page_y); |
| 772 #else // PDF_ENABLE_XFA |
768 CPDF_Matrix page2device; | 773 CPDF_Matrix page2device; |
769 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, | 774 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, |
770 rotate); | 775 rotate); |
771 CPDF_Matrix device2page; | 776 CPDF_Matrix device2page; |
772 device2page.SetReverse(page2device); | 777 device2page.SetReverse(page2device); |
773 | |
774 FX_FLOAT page_x_f, page_y_f; | 778 FX_FLOAT page_x_f, page_y_f; |
775 device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f, | 779 device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f, |
776 page_y_f); | 780 page_y_f); |
777 | |
778 *page_x = (page_x_f); | 781 *page_x = (page_x_f); |
779 *page_y = (page_y_f); | 782 *page_y = (page_y_f); |
780 #else | 783 #endif // PDF_ENABLE_XFA |
781 pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x, | |
782 device_y, page_x, page_y); | |
783 #endif | |
784 } | 784 } |
785 | 785 |
786 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, | 786 DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, |
787 int start_x, | 787 int start_x, |
788 int start_y, | 788 int start_y, |
789 int size_x, | 789 int size_x, |
790 int size_y, | 790 int size_y, |
791 int rotate, | 791 int rotate, |
792 double page_x, | 792 double page_x, |
793 double page_y, | 793 double page_y, |
794 int* device_x, | 794 int* device_x, |
795 int* device_y) { | 795 int* device_y) { |
796 if (!device_x || !device_y) | 796 if (!device_x || !device_y) |
797 return; | 797 return; |
798 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 798 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
799 if (!pPage) | 799 if (!pPage) |
800 return; | 800 return; |
801 #ifndef PDF_ENABLE_XFA | 801 #ifdef PDF_ENABLE_XFA |
| 802 pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, |
| 803 device_x, device_y); |
| 804 #else // PDF_ENABLE_XFA |
802 CPDF_Matrix page2device; | 805 CPDF_Matrix page2device; |
803 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, | 806 pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, |
804 rotate); | 807 rotate); |
805 | |
806 FX_FLOAT device_x_f, device_y_f; | 808 FX_FLOAT device_x_f, device_y_f; |
807 page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f, | 809 page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f, |
808 device_y_f); | 810 device_y_f); |
809 | |
810 *device_x = FXSYS_round(device_x_f); | 811 *device_x = FXSYS_round(device_x_f); |
811 *device_y = FXSYS_round(device_y_f); | 812 *device_y = FXSYS_round(device_y_f); |
812 #else | 813 #endif // PDF_ENABLE_XFA |
813 pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, | |
814 device_x, device_y); | |
815 #endif | |
816 } | 814 } |
817 | 815 |
818 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, | 816 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, |
819 int height, | 817 int height, |
820 int alpha) { | 818 int alpha) { |
821 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); | 819 nonstd::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); |
822 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) { | 820 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) { |
823 return NULL; | 821 return NULL; |
824 } | 822 } |
825 return pBitmap.release(); | 823 return pBitmap.release(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; | 925 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; |
928 if (flags & FPDF_RENDER_FORCEHALFTONE) | 926 if (flags & FPDF_RENDER_FORCEHALFTONE) |
929 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; | 927 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; |
930 #ifndef PDF_ENABLE_XFA | 928 #ifndef PDF_ENABLE_XFA |
931 if (flags & FPDF_RENDER_NO_SMOOTHTEXT) | 929 if (flags & FPDF_RENDER_NO_SMOOTHTEXT) |
932 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH; | 930 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH; |
933 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE) | 931 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE) |
934 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH; | 932 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH; |
935 if (flags & FPDF_RENDER_NO_SMOOTHPATH) | 933 if (flags & FPDF_RENDER_NO_SMOOTHPATH) |
936 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH; | 934 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH; |
937 #endif | 935 #endif // PDF_ENABLE_XFA |
938 // Grayscale output | 936 // Grayscale output |
939 if (flags & FPDF_GRAYSCALE) { | 937 if (flags & FPDF_GRAYSCALE) { |
940 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; | 938 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; |
941 pContext->m_pOptions->m_ForeColor = 0; | 939 pContext->m_pOptions->m_ForeColor = 0; |
942 pContext->m_pOptions->m_BackColor = 0xffffff; | 940 pContext->m_pOptions->m_BackColor = 0xffffff; |
943 } | 941 } |
944 const CPDF_OCContext::UsageType usage = | 942 const CPDF_OCContext::UsageType usage = |
945 (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View; | 943 (flags & FPDF_PRINTING) ? CPDF_OCContext::Print : CPDF_OCContext::View; |
946 pContext->m_pOptions->m_AddFlags = flags >> 8; | 944 pContext->m_pOptions->m_AddFlags = flags >> 8; |
947 pContext->m_pOptions->m_pOCContext = | 945 pContext->m_pOptions->m_pOCContext = |
(...skipping 29 matching lines...) Expand all Loading... |
977 } | 975 } |
978 | 976 |
979 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, | 977 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, |
980 int page_index, | 978 int page_index, |
981 double* width, | 979 double* width, |
982 double* height) { | 980 double* height) { |
983 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); | 981 UnderlyingDocumentType* pDoc = UnderlyingFromFPDFDocument(document); |
984 if (!pDoc) | 982 if (!pDoc) |
985 return FALSE; | 983 return FALSE; |
986 | 984 |
987 #ifndef PDF_ENABLE_XFA | 985 #ifdef PDF_ENABLE_XFA |
988 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); | |
989 if (!pDict) | |
990 #else | |
991 int count = pDoc->GetPageCount(); | 986 int count = pDoc->GetPageCount(); |
992 if (page_index < 0 || page_index >= count) | 987 if (page_index < 0 || page_index >= count) |
993 return FALSE; | 988 return FALSE; |
994 | |
995 CPDFXFA_Page* pPage = pDoc->GetPage(page_index); | 989 CPDFXFA_Page* pPage = pDoc->GetPage(page_index); |
996 if (!pPage) | 990 if (!pPage) |
997 #endif | |
998 return FALSE; | 991 return FALSE; |
999 | 992 *width = pPage->GetPageWidth(); |
1000 #ifndef PDF_ENABLE_XFA | 993 *height = pPage->GetPageHeight(); |
| 994 #else // PDF_ENABLE_XFA |
| 995 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); |
| 996 if (!pDict) |
| 997 return FALSE; |
1001 CPDF_Page page; | 998 CPDF_Page page; |
1002 page.Load(pDoc, pDict); | 999 page.Load(pDoc, pDict); |
1003 *width = page.GetPageWidth(); | 1000 *width = page.GetPageWidth(); |
1004 *height = page.GetPageHeight(); | 1001 *height = page.GetPageHeight(); |
1005 #else | 1002 #endif // PDF_ENABLE_XFA |
1006 *width = pPage->GetPageWidth(); | |
1007 *height = pPage->GetPageHeight(); | |
1008 #endif | |
1009 | 1003 |
1010 return TRUE; | 1004 return TRUE; |
1011 } | 1005 } |
1012 | 1006 |
1013 DLLEXPORT FPDF_BOOL STDCALL | 1007 DLLEXPORT FPDF_BOOL STDCALL |
1014 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) { | 1008 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document) { |
1015 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 1009 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
1016 if (!pDoc) | 1010 if (!pDoc) |
1017 return TRUE; | 1011 return TRUE; |
1018 CPDF_ViewerPreferences viewRef(pDoc); | 1012 CPDF_ViewerPreferences viewRef(pDoc); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 if (!str) | 1121 if (!str) |
1128 return -1; | 1122 return -1; |
1129 | 1123 |
1130 if (str->str) { | 1124 if (str->str) { |
1131 FX_Free(str->str); | 1125 FX_Free(str->str); |
1132 str->str = NULL; | 1126 str->str = NULL; |
1133 } | 1127 } |
1134 str->len = 0; | 1128 str->len = 0; |
1135 return 0; | 1129 return 0; |
1136 } | 1130 } |
| 1131 #endif // PDF_ENABLE_XFA |
1137 | 1132 |
1138 #endif | |
1139 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, | 1133 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, |
1140 int index, | 1134 int index, |
1141 void* buffer, | 1135 void* buffer, |
1142 long* buflen) { | 1136 long* buflen) { |
1143 if (!buffer) | 1137 if (!buffer) |
1144 *buflen = 0; | 1138 *buflen = 0; |
1145 | 1139 |
1146 if (index < 0) | 1140 if (index < 0) |
1147 return nullptr; | 1141 return nullptr; |
1148 | 1142 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 if (!buffer) { | 1188 if (!buffer) { |
1195 *buflen = len; | 1189 *buflen = len; |
1196 } else if (*buflen >= len) { | 1190 } else if (*buflen >= len) { |
1197 memcpy(buffer, utf16Name.c_str(), len); | 1191 memcpy(buffer, utf16Name.c_str(), len); |
1198 *buflen = len; | 1192 *buflen = len; |
1199 } else { | 1193 } else { |
1200 *buflen = -1; | 1194 *buflen = -1; |
1201 } | 1195 } |
1202 return (FPDF_DEST)pDestObj; | 1196 return (FPDF_DEST)pDestObj; |
1203 } | 1197 } |
OLD | NEW |