| 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 CPDFDocumentToFPDFDocument(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 CPDFDocumentToFPDFDocument(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 CPDFDocumentToFPDFDocument(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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 if (!pDoc) | 425 if (!pDoc) |
| 432 return nullptr; | 426 return nullptr; |
| 433 | 427 |
| 434 if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) | 428 if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) |
| 435 return nullptr; | 429 return nullptr; |
| 436 | 430 |
| 437 return pDoc->GetPage(page_index); | 431 return pDoc->GetPage(page_index); |
| 438 } | 432 } |
| 439 | 433 |
| 440 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { | 434 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { |
| 441 if (!page) | 435 CPDFXFA_Page* pPage = static_cast<CPDFXFA_Page*>(page); |
| 442 return 0.0; | 436 return pPage ? pPage->GetPageWidth() : 0.0; |
| 443 return ((CPDFXFA_Page*)page)->GetPageWidth(); | |
| 444 } | 437 } |
| 445 | 438 |
| 446 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { | 439 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { |
| 447 if (!page) | 440 CPDFXFA_Page* pPage = static_cast<CPDFXFA_Page*>(page); |
| 448 return 0.0; | 441 return pPage ? pPage->GetPageHeight() : 0.0; |
| 449 return ((CPDFXFA_Page*)page)->GetPageHeight(); | |
| 450 } | 442 } |
| 451 | 443 |
| 452 void DropContext(void* data) { | 444 void DropContext(void* data) { |
| 453 delete (CRenderContext*)data; | 445 delete (CRenderContext*)data; |
| 454 } | 446 } |
| 455 | 447 |
| 456 #if defined(_DEBUG) || defined(DEBUG) | 448 #if defined(_DEBUG) || defined(DEBUG) |
| 457 #define DEBUG_TRACE | 449 #define DEBUG_TRACE |
| 458 #endif | 450 #endif |
| 459 | 451 |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 } | 1004 } |
| 1013 | 1005 |
| 1014 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, | 1006 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, |
| 1015 int index, | 1007 int index, |
| 1016 void* buffer, | 1008 void* buffer, |
| 1017 long* buflen) { | 1009 long* buflen) { |
| 1018 if (!buffer) | 1010 if (!buffer) |
| 1019 *buflen = 0; | 1011 *buflen = 0; |
| 1020 if (!document || index < 0) | 1012 if (!document || index < 0) |
| 1021 return NULL; | 1013 return NULL; |
| 1022 CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc(); | |
| 1023 | 1014 |
| 1015 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 1024 CPDF_Dictionary* pRoot = pDoc->GetRoot(); | 1016 CPDF_Dictionary* pRoot = pDoc->GetRoot(); |
| 1025 if (!pRoot) | 1017 if (!pRoot) |
| 1026 return NULL; | 1018 return NULL; |
| 1027 | 1019 |
| 1028 CPDF_Object* pDestObj = NULL; | 1020 CPDF_Object* pDestObj = NULL; |
| 1029 CFX_ByteString bsName; | 1021 CFX_ByteString bsName; |
| 1030 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests")); | 1022 CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests")); |
| 1031 int count = nameTree.GetCount(); | 1023 int count = nameTree.GetCount(); |
| 1032 if (index >= count) { | 1024 if (index >= count) { |
| 1033 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests")); | 1025 CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests")); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1064 if (!buffer) { | 1056 if (!buffer) { |
| 1065 *buflen = len; | 1057 *buflen = len; |
| 1066 } else if (*buflen >= len) { | 1058 } else if (*buflen >= len) { |
| 1067 memcpy(buffer, utf16Name.c_str(), len); | 1059 memcpy(buffer, utf16Name.c_str(), len); |
| 1068 *buflen = len; | 1060 *buflen = len; |
| 1069 } else { | 1061 } else { |
| 1070 *buflen = -1; | 1062 *buflen = -1; |
| 1071 } | 1063 } |
| 1072 return (FPDF_DEST)pDestObj; | 1064 return (FPDF_DEST)pDestObj; |
| 1073 } | 1065 } |
| OLD | NEW |