| 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 #include <memory> | 9 #include <memory> | 
| 10 | 10 | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 59 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { | 59 CPDF_Document* CPDFDocumentFromFPDFDocument(FPDF_DOCUMENT doc) { | 
| 60 #ifdef PDF_ENABLE_XFA | 60 #ifdef PDF_ENABLE_XFA | 
| 61   return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; | 61   return doc ? UnderlyingFromFPDFDocument(doc)->GetPDFDoc() : nullptr; | 
| 62 #else   // PDF_ENABLE_XFA | 62 #else   // PDF_ENABLE_XFA | 
| 63   return UnderlyingFromFPDFDocument(doc); | 63   return UnderlyingFromFPDFDocument(doc); | 
| 64 #endif  // PDF_ENABLE_XFA | 64 #endif  // PDF_ENABLE_XFA | 
| 65 } | 65 } | 
| 66 | 66 | 
| 67 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { | 67 FPDF_DOCUMENT FPDFDocumentFromCPDFDocument(CPDF_Document* doc) { | 
| 68 #ifdef PDF_ENABLE_XFA | 68 #ifdef PDF_ENABLE_XFA | 
| 69   return doc ? FPDFDocumentFromUnderlying( | 69   return doc ? FPDFDocumentFromUnderlying(new CPDFXFA_Document( | 
| 70                    new CPDFXFA_Document(doc, CPDFXFA_App::GetInstance())) | 70                    WrapUnique(doc), CPDFXFA_App::GetInstance())) | 
| 71              : nullptr; | 71              : nullptr; | 
| 72 #else   // PDF_ENABLE_XFA | 72 #else   // PDF_ENABLE_XFA | 
| 73   return FPDFDocumentFromUnderlying(doc); | 73   return FPDFDocumentFromUnderlying(doc); | 
| 74 #endif  // PDF_ENABLE_XFA | 74 #endif  // PDF_ENABLE_XFA | 
| 75 } | 75 } | 
| 76 | 76 | 
| 77 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { | 77 CPDF_Page* CPDFPageFromFPDFPage(FPDF_PAGE page) { | 
| 78 #ifdef PDF_ENABLE_XFA | 78 #ifdef PDF_ENABLE_XFA | 
| 79   return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; | 79   return page ? UnderlyingFromFPDFPage(page)->GetPDFPage() : nullptr; | 
| 80 #else   // PDF_ENABLE_XFA | 80 #else   // PDF_ENABLE_XFA | 
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 358   // NOTE: the creation of the file needs to be by the embedder on the | 358   // NOTE: the creation of the file needs to be by the embedder on the | 
| 359   // other side of this API. | 359   // other side of this API. | 
| 360   IFX_FileRead* pFileAccess = FX_CreateFileRead((const FX_CHAR*)file_path); | 360   IFX_FileRead* pFileAccess = FX_CreateFileRead((const FX_CHAR*)file_path); | 
| 361   if (!pFileAccess) { | 361   if (!pFileAccess) { | 
| 362     return nullptr; | 362     return nullptr; | 
| 363   } | 363   } | 
| 364 | 364 | 
| 365   std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser); | 365   std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser); | 
| 366   pParser->SetPassword(password); | 366   pParser->SetPassword(password); | 
| 367 | 367 | 
| 368   std::unique_ptr<CPDF_Document> pDocument(new CPDF_Document(pParser.get())); | 368   std::unique_ptr<CPDF_Document> pDocument( | 
| 369   CPDF_Parser::Error error = | 369       new CPDF_Document(std::move(pParser))); | 
| 370       pParser->StartParse(pFileAccess, std::move(pDocument)); | 370   CPDF_Parser::Error error = pParser->StartParse(pFileAccess, pDocument.get()); | 
| 371   if (error != CPDF_Parser::SUCCESS) { | 371   if (error != CPDF_Parser::SUCCESS) { | 
| 372     ProcessParseError(error); | 372     ProcessParseError(error); | 
| 373     return nullptr; | 373     return nullptr; | 
| 374   } | 374   } | 
| 375 #ifdef PDF_ENABLE_XFA | 375 #ifdef PDF_ENABLE_XFA | 
| 376   CPDF_Document* pPDFDoc = pParser.release()->GetDocument(); | 376   return new CPDFXFA_Document(std::move(pDocument), CPDFXFA_App::GetInstance()); | 
| 377   if (!pPDFDoc) |  | 
| 378     return nullptr; |  | 
| 379 |  | 
| 380   CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |  | 
| 381   return new CPDFXFA_Document(pPDFDoc, pProvider); |  | 
| 382 #else   // PDF_ENABLE_XFA | 377 #else   // PDF_ENABLE_XFA | 
| 383   return pParser.release()->GetDocument(); | 378   return pDocument.release(); | 
| 384 #endif  // PDF_ENABLE_XFA | 379 #endif  // PDF_ENABLE_XFA | 
| 385 } | 380 } | 
| 386 | 381 | 
| 387 #ifdef PDF_ENABLE_XFA | 382 #ifdef PDF_ENABLE_XFA | 
| 388 DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, | 383 DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, | 
| 389                                              int* docType) { | 384                                              int* docType) { | 
| 390   if (!document) | 385   if (!document) | 
| 391     return FALSE; | 386     return FALSE; | 
| 392 | 387 | 
| 393   CPDF_Document* pdfDoc = | 388   CPDF_Document* pdfDoc = | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 444   const FX_FILESIZE m_size; | 439   const FX_FILESIZE m_size; | 
| 445 }; | 440 }; | 
| 446 | 441 | 
| 447 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, | 442 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, | 
| 448                                                      int size, | 443                                                      int size, | 
| 449                                                      FPDF_BYTESTRING password) { | 444                                                      FPDF_BYTESTRING password) { | 
| 450   CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); | 445   CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); | 
| 451   std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser); | 446   std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser); | 
| 452   pParser->SetPassword(password); | 447   pParser->SetPassword(password); | 
| 453 | 448 | 
| 454   std::unique_ptr<CPDF_Document> pDocument(new CPDF_Document(pParser.get())); | 449   std::unique_ptr<CPDF_Document> pDocument( | 
|  | 450       new CPDF_Document(std::move(pParser))); | 
| 455   CPDF_Parser::Error error = | 451   CPDF_Parser::Error error = | 
| 456       pParser->StartParse(pMemFile, std::move(pDocument)); | 452       pDocument->GetParser()->StartParse(pMemFile, pDocument.get()); | 
| 457   if (error != CPDF_Parser::SUCCESS) { | 453   if (error != CPDF_Parser::SUCCESS) { | 
| 458     ProcessParseError(error); | 454     ProcessParseError(error); | 
| 459     return nullptr; | 455     return nullptr; | 
| 460   } | 456   } | 
| 461   CheckUnSupportError(pParser->GetDocument(), error); | 457   CheckUnSupportError(pDocument.get(), error); | 
| 462   return FPDFDocumentFromCPDFDocument(pParser.release()->GetDocument()); | 458   return FPDFDocumentFromCPDFDocument(pDocument.release()); | 
| 463 } | 459 } | 
| 464 | 460 | 
| 465 DLLEXPORT FPDF_DOCUMENT STDCALL | 461 DLLEXPORT FPDF_DOCUMENT STDCALL | 
| 466 FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, | 462 FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, | 
| 467                         FPDF_BYTESTRING password) { | 463                         FPDF_BYTESTRING password) { | 
| 468   CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess); | 464   CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess); | 
| 469   std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser); | 465   std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser); | 
| 470   pParser->SetPassword(password); | 466   pParser->SetPassword(password); | 
| 471 | 467 | 
| 472   std::unique_ptr<CPDF_Document> pDocument(new CPDF_Document(pParser.get())); | 468   std::unique_ptr<CPDF_Document> pDocument( | 
| 473   CPDF_Parser::Error error = pParser->StartParse(pFile, std::move(pDocument)); | 469       new CPDF_Document(std::move(pParser))); | 
|  | 470   CPDF_Parser::Error error = | 
|  | 471       pDocument->GetParser()->StartParse(pFile, pDocument.get()); | 
| 474   if (error != CPDF_Parser::SUCCESS) { | 472   if (error != CPDF_Parser::SUCCESS) { | 
| 475     ProcessParseError(error); | 473     ProcessParseError(error); | 
| 476     return nullptr; | 474     return nullptr; | 
| 477   } | 475   } | 
| 478   CheckUnSupportError(pParser->GetDocument(), error); | 476   CheckUnSupportError(pDocument.get(), error); | 
| 479   return FPDFDocumentFromCPDFDocument(pParser.release()->GetDocument()); | 477   return FPDFDocumentFromCPDFDocument(pDocument.release()); | 
| 480 } | 478 } | 
| 481 | 479 | 
| 482 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, | 480 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, | 
| 483                                                 int* fileVersion) { | 481                                                 int* fileVersion) { | 
| 484   if (!fileVersion) | 482   if (!fileVersion) | 
| 485     return FALSE; | 483     return FALSE; | 
| 486 | 484 | 
| 487   *fileVersion = 0; | 485   *fileVersion = 0; | 
| 488   CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); | 486   CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); | 
| 489   if (!pDoc) | 487   if (!pDoc) | 
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 676       static_cast<CPDFSDK_PageView*>(pPage->GetView()); | 674       static_cast<CPDFSDK_PageView*>(pPage->GetView()); | 
| 677   if (pPageView && pPageView->IsLocked()) { | 675   if (pPageView && pPageView->IsLocked()) { | 
| 678     pPageView->TakeOverPage(); | 676     pPageView->TakeOverPage(); | 
| 679     return; | 677     return; | 
| 680   } | 678   } | 
| 681   delete pPage; | 679   delete pPage; | 
| 682 #endif  // PDF_ENABLE_XFA | 680 #endif  // PDF_ENABLE_XFA | 
| 683 } | 681 } | 
| 684 | 682 | 
| 685 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { | 683 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { | 
| 686 #ifdef PDF_ENABLE_XFA |  | 
| 687   delete UnderlyingFromFPDFDocument(document); | 684   delete UnderlyingFromFPDFDocument(document); | 
| 688 #else   // PDF_ENABLE_XFA |  | 
| 689   CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |  | 
| 690   if (!pDoc) |  | 
| 691     return; |  | 
| 692   CPDF_Parser* pParser = pDoc->GetParser(); |  | 
| 693   if (!pParser) { |  | 
| 694     delete pDoc; |  | 
| 695     return; |  | 
| 696   } |  | 
| 697   delete pParser; |  | 
| 698 #endif  // PDF_ENABLE_XFA |  | 
| 699 } | 685 } | 
| 700 | 686 | 
| 701 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() { | 687 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() { | 
| 702   return GetLastError(); | 688   return GetLastError(); | 
| 703 } | 689 } | 
| 704 | 690 | 
| 705 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, | 691 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, | 
| 706                                          int start_x, | 692                                          int start_x, | 
| 707                                          int start_y, | 693                                          int start_y, | 
| 708                                          int size_x, | 694                                          int size_x, | 
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1130   if (!buffer) { | 1116   if (!buffer) { | 
| 1131     *buflen = len; | 1117     *buflen = len; | 
| 1132   } else if (*buflen >= len) { | 1118   } else if (*buflen >= len) { | 
| 1133     memcpy(buffer, utf16Name.c_str(), len); | 1119     memcpy(buffer, utf16Name.c_str(), len); | 
| 1134     *buflen = len; | 1120     *buflen = len; | 
| 1135   } else { | 1121   } else { | 
| 1136     *buflen = -1; | 1122     *buflen = -1; | 
| 1137   } | 1123   } | 
| 1138   return (FPDF_DEST)pDestObj; | 1124   return (FPDF_DEST)pDestObj; | 
| 1139 } | 1125 } | 
| OLD | NEW | 
|---|