| 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 "../../core/include/fpdfapi/fpdf_module.h" | 7 #include "../../core/include/fpdfapi/fpdf_module.h" |
| 8 #include "../../core/include/fxcodec/fx_codec.h" | 8 #include "../../core/include/fxcodec/fx_codec.h" |
| 9 #include "../../core/include/fxcrt/fx_safe_types.h" | 9 #include "../../core/include/fxcrt/fx_safe_types.h" |
| 10 #include "../../public/fpdf_ext.h" | 10 #include "../../public/fpdf_ext.h" |
| 11 #include "../../public/fpdf_formfill.h" | 11 #include "../../public/fpdf_formfill.h" |
| 12 #include "../../public/fpdf_progressive.h" | 12 #include "../../public/fpdf_progressive.h" |
| 13 #include "../../public/fpdfview.h" | 13 #include "../../public/fpdfview.h" |
| 14 #include "../../third_party/base/nonstd_unique_ptr.h" | 14 #include "../../third_party/base/nonstd_unique_ptr.h" |
| 15 #include "../../third_party/base/numerics/safe_conversions_impl.h" | 15 #include "../../third_party/base/numerics/safe_conversions_impl.h" |
| 16 #include "../include/fsdk_define.h" | 16 #include "../include/fsdk_define.h" |
| 17 #include "../include/fsdk_mgr.h" | 17 #include "../include/fsdk_mgr.h" |
| 18 #include "../include/fsdk_rendercontext.h" | 18 #include "../include/fsdk_rendercontext.h" |
| 19 #include "../include/fpdfxfa/fpdfxfa_doc.h" | 19 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 20 #include "../include/fpdfxfa/fpdfxfa_app.h" | 20 #include "../include/fpdfxfa/fpdfxfa_app.h" |
| 21 #include "../include/fpdfxfa/fpdfxfa_page.h" | 21 #include "../include/fpdfxfa/fpdfxfa_page.h" |
| 22 #include "../include/fpdfxfa/fpdfxfa_util.h" | 22 #include "../include/fpdfxfa/fpdfxfa_util.h" |
| 23 #include "../include/javascript/IJavaScript.h" | 23 #include "../include/javascript/IJavaScript.h" |
| 24 | 24 |
| 25 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { | 25 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { |
| 26 return doc ? static_cast<CPDFXFA_Document*>(doc)->GetPDFDoc() : nullptr; | 26 return doc ? static_cast<CPDFXFA_Document*>(doc)->GetPDFDoc() : nullptr; |
| 27 } | 27 } |
| 28 | 28 |
| 29 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { |
| 30 return doc ? new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance()) : nullptr; |
| 31 } |
| 32 |
| 29 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { | 33 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { |
| 30 return page ? static_cast<CPDFXFA_Page*>(page)->GetPDFPage() : nullptr; | 34 return page ? static_cast<CPDFXFA_Page*>(page)->GetPDFPage() : nullptr; |
| 31 } | 35 } |
| 32 | 36 |
| 33 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { | 37 CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS) { |
| 34 m_pFS = pFS; | 38 m_pFS = pFS; |
| 35 m_nCurPos = 0; | 39 m_nCurPos = 0; |
| 36 } | 40 } |
| 37 | 41 |
| 38 IFX_FileStream* CFPDF_FileStream::Retain() { | 42 IFX_FileStream* CFPDF_FileStream::Retain() { |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); | 348 CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); |
| 345 FX_DWORD err_code = pParser->StartParse(pMemFile); | 349 FX_DWORD err_code = pParser->StartParse(pMemFile); |
| 346 if (err_code) { | 350 if (err_code) { |
| 347 delete pParser; | 351 delete pParser; |
| 348 ProcessParseError(err_code); | 352 ProcessParseError(err_code); |
| 349 return NULL; | 353 return NULL; |
| 350 } | 354 } |
| 351 CPDF_Document* pDoc = NULL; | 355 CPDF_Document* pDoc = NULL; |
| 352 pDoc = pParser ? pParser->GetDocument() : NULL; | 356 pDoc = pParser ? pParser->GetDocument() : NULL; |
| 353 CheckUnSupportError(pDoc, err_code); | 357 CheckUnSupportError(pDoc, err_code); |
| 354 CPDF_Document* pPDFDoc = pParser->GetDocument(); | 358 return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); |
| 355 if (!pPDFDoc) | |
| 356 return NULL; | |
| 357 | |
| 358 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); | |
| 359 return new CPDFXFA_Document(pPDFDoc, pProvider); | |
| 360 } | 359 } |
| 361 | 360 |
| 362 DLLEXPORT FPDF_DOCUMENT STDCALL | 361 DLLEXPORT FPDF_DOCUMENT STDCALL |
| 363 FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, | 362 FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, |
| 364 FPDF_BYTESTRING password) { | 363 FPDF_BYTESTRING password) { |
| 365 CPDF_Parser* pParser = new CPDF_Parser; | 364 CPDF_Parser* pParser = new CPDF_Parser; |
| 366 pParser->SetPassword(password); | 365 pParser->SetPassword(password); |
| 367 CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess); | 366 CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess); |
| 368 FX_DWORD err_code = pParser->StartParse(pFile); | 367 FX_DWORD err_code = pParser->StartParse(pFile); |
| 369 if (err_code) { | 368 if (err_code) { |
| 370 delete pParser; | 369 delete pParser; |
| 371 ProcessParseError(err_code); | 370 ProcessParseError(err_code); |
| 372 return NULL; | 371 return NULL; |
| 373 } | 372 } |
| 374 CPDF_Document* pDoc = NULL; | 373 CPDF_Document* pDoc = NULL; |
| 375 pDoc = pParser ? pParser->GetDocument() : NULL; | 374 pDoc = pParser ? pParser->GetDocument() : NULL; |
| 376 CheckUnSupportError(pDoc, err_code); | 375 CheckUnSupportError(pDoc, err_code); |
| 377 CPDF_Document* pPDFDoc = pParser->GetDocument(); | 376 return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); |
| 378 if (!pPDFDoc) | |
| 379 return NULL; | |
| 380 | |
| 381 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); | |
| 382 return new CPDFXFA_Document(pPDFDoc, pProvider); | |
| 383 } | 377 } |
| 384 | 378 |
| 385 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, | 379 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, |
| 386 int* fileVersion) { | 380 int* fileVersion) { |
| 387 if (!fileVersion) | 381 if (!fileVersion) |
| 388 return FALSE; | 382 return FALSE; |
| 389 | 383 |
| 390 *fileVersion = 0; | 384 *fileVersion = 0; |
| 391 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); | 385 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); |
| 392 if (!pDoc) | 386 if (!pDoc) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 if (!document) | 424 if (!document) |
| 431 return nullptr; | 425 return nullptr; |
| 432 CPDFXFA_Document* pDoc = static_cast<CPDFXFA_Document*>(document); | 426 CPDFXFA_Document* pDoc = static_cast<CPDFXFA_Document*>(document); |
| 433 if (page_index < 0 || page_index >= pDoc->GetPageCount()) | 427 if (page_index < 0 || page_index >= pDoc->GetPageCount()) |
| 434 return nullptr; | 428 return nullptr; |
| 435 | 429 |
| 436 return pDoc->GetPage(page_index); | 430 return pDoc->GetPage(page_index); |
| 437 } | 431 } |
| 438 | 432 |
| 439 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { | 433 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { |
| 440 if (!page) | 434 CPDFXFA_Page* pPage = static_cast<CPDFXFA_Page*>(page); |
| 441 return 0.0; | 435 return pPage ? pPage->GetPageWidth() : 0.0; |
| 442 return ((CPDFXFA_Page*)page)->GetPageWidth(); | |
| 443 } | 436 } |
| 444 | 437 |
| 445 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { | 438 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { |
| 446 if (!page) | 439 CPDFXFA_Page* pPage = static_cast<CPDFXFA_Page*>(page); |
| 447 return 0.0; | 440 return pPage ? pPage->GetPageHeight() : 0.0; |
| 448 return ((CPDFXFA_Page*)page)->GetPageHeight(); | |
| 449 } | 441 } |
| 450 | 442 |
| 451 void DropContext(void* data) { | 443 void DropContext(void* data) { |
| 452 delete (CRenderContext*)data; | 444 delete (CRenderContext*)data; |
| 453 } | 445 } |
| 454 | 446 |
| 455 #if defined(_DEBUG) || defined(DEBUG) | 447 #if defined(_DEBUG) || defined(DEBUG) |
| 456 #define DEBUG_TRACE | 448 #define DEBUG_TRACE |
| 457 #endif | 449 #endif |
| 458 | 450 |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 } | 1003 } |
| 1012 | 1004 |
| 1013 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, | 1005 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, |
| 1014 int index, | 1006 int index, |
| 1015 void* buffer, | 1007 void* buffer, |
| 1016 long* buflen) { | 1008 long* buflen) { |
| 1017 if (!buffer) | 1009 if (!buffer) |
| 1018 *buflen = 0; | 1010 *buflen = 0; |
| 1019 if (!document || index < 0) | 1011 if (!document || index < 0) |
| 1020 return NULL; | 1012 return NULL; |
| 1021 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | |
| 1022 | 1013 |
| 1014 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 1023 CPDF_Dictionary* pRoot = pDoc->GetRoot(); | 1015 CPDF_Dictionary* pRoot = pDoc->GetRoot(); |
| 1024 if (!pRoot) | 1016 if (!pRoot) |
| 1025 return NULL; | 1017 return NULL; |
| 1026 | 1018 |
| 1027 CPDF_Object* pDestObj = NULL; | 1019 CPDF_Object* pDestObj = NULL; |
| 1028 CFX_ByteString bsName; | 1020 CFX_ByteString bsName; |
| 1029 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests")); | 1021 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests")); |
| 1030 int count = nameTree.GetCount(); | 1022 int count = nameTree.GetCount(); |
| 1031 if (index >= count) { | 1023 if (index >= count) { |
| 1032 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests")); | 1024 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests")); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1063 if (!buffer) { | 1055 if (!buffer) { |
| 1064 *buflen = len; | 1056 *buflen = len; |
| 1065 } else if (*buflen >= len) { | 1057 } else if (*buflen >= len) { |
| 1066 memcpy(buffer, utf16Name.c_str(), len); | 1058 memcpy(buffer, utf16Name.c_str(), len); |
| 1067 *buflen = len; | 1059 *buflen = len; |
| 1068 } else { | 1060 } else { |
| 1069 *buflen = -1; | 1061 *buflen = -1; |
| 1070 } | 1062 } |
| 1071 return (FPDF_DEST)pDestObj; | 1063 return (FPDF_DEST)pDestObj; |
| 1072 } | 1064 } |
| OLD | NEW |