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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 return nullptr; | 328 return nullptr; |
329 } | 329 } |
330 | 330 |
331 CPDF_Parser* pParser = new CPDF_Parser; | 331 CPDF_Parser* pParser = new CPDF_Parser; |
332 pParser->SetPassword(password); | 332 pParser->SetPassword(password); |
333 | 333 |
334 CPDF_Parser::Error error = pParser->StartParse(pFileAccess); | 334 CPDF_Parser::Error error = pParser->StartParse(pFileAccess); |
335 if (error != CPDF_Parser::SUCCESS) { | 335 if (error != CPDF_Parser::SUCCESS) { |
336 delete pParser; | 336 delete pParser; |
337 ProcessParseError(error); | 337 ProcessParseError(error); |
338 return NULL; | 338 return nullptr; |
339 } | 339 } |
340 #ifdef PDF_ENABLE_XFA | 340 #ifdef PDF_ENABLE_XFA |
341 CPDF_Document* pPDFDoc = pParser->GetDocument(); | 341 CPDF_Document* pPDFDoc = pParser->GetDocument(); |
342 if (!pPDFDoc) | 342 if (!pPDFDoc) |
343 return NULL; | 343 return nullptr; |
344 | 344 |
345 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); | 345 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
346 return new CPDFXFA_Document(pPDFDoc, pProvider); | 346 return new CPDFXFA_Document(pPDFDoc, pProvider); |
347 #else // PDF_ENABLE_XFA | 347 #else // PDF_ENABLE_XFA |
348 return pParser->GetDocument(); | 348 return pParser->GetDocument(); |
349 #endif // PDF_ENABLE_XFA | 349 #endif // PDF_ENABLE_XFA |
350 } | 350 } |
351 | 351 |
352 #ifdef PDF_ENABLE_XFA | 352 #ifdef PDF_ENABLE_XFA |
353 DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, | 353 DLLEXPORT FPDF_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, | 412 DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, |
413 int size, | 413 int size, |
414 FPDF_BYTESTRING password) { | 414 FPDF_BYTESTRING password) { |
415 CPDF_Parser* pParser = new CPDF_Parser; | 415 CPDF_Parser* pParser = new CPDF_Parser; |
416 pParser->SetPassword(password); | 416 pParser->SetPassword(password); |
417 CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); | 417 CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); |
418 CPDF_Parser::Error error = pParser->StartParse(pMemFile); | 418 CPDF_Parser::Error error = pParser->StartParse(pMemFile); |
419 if (error != CPDF_Parser::SUCCESS) { | 419 if (error != CPDF_Parser::SUCCESS) { |
420 delete pParser; | 420 delete pParser; |
421 ProcessParseError(error); | 421 ProcessParseError(error); |
422 return NULL; | 422 return nullptr; |
423 } | 423 } |
424 CPDF_Document* pDoc = NULL; | 424 CPDF_Document* pDoc = pParser ? pParser->GetDocument() : nullptr; |
425 pDoc = pParser ? pParser->GetDocument() : NULL; | |
426 CheckUnSupportError(pDoc, error); | 425 CheckUnSupportError(pDoc, error); |
427 return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); | 426 return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); |
428 } | 427 } |
429 | 428 |
430 DLLEXPORT FPDF_DOCUMENT STDCALL | 429 DLLEXPORT FPDF_DOCUMENT STDCALL |
431 FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, | 430 FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, |
432 FPDF_BYTESTRING password) { | 431 FPDF_BYTESTRING password) { |
433 CPDF_Parser* pParser = new CPDF_Parser; | 432 CPDF_Parser* pParser = new CPDF_Parser; |
434 pParser->SetPassword(password); | 433 pParser->SetPassword(password); |
435 CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess); | 434 CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess); |
436 CPDF_Parser::Error error = pParser->StartParse(pFile); | 435 CPDF_Parser::Error error = pParser->StartParse(pFile); |
437 if (error != CPDF_Parser::SUCCESS) { | 436 if (error != CPDF_Parser::SUCCESS) { |
438 delete pParser; | 437 delete pParser; |
439 ProcessParseError(error); | 438 ProcessParseError(error); |
440 return NULL; | 439 return nullptr; |
441 } | 440 } |
442 CPDF_Document* pDoc = NULL; | 441 CPDF_Document* pDoc = pParser ? pParser->GetDocument() : nullptr; |
443 pDoc = pParser ? pParser->GetDocument() : NULL; | |
444 CheckUnSupportError(pDoc, error); | 442 CheckUnSupportError(pDoc, error); |
445 return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); | 443 return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); |
446 } | 444 } |
447 | 445 |
448 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, | 446 DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, |
449 int* fileVersion) { | 447 int* fileVersion) { |
450 if (!fileVersion) | 448 if (!fileVersion) |
451 return FALSE; | 449 return FALSE; |
452 | 450 |
453 *fileVersion = 0; | 451 *fileVersion = 0; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 if (bBackgroundAlphaNeeded || bHasImageMask) { | 559 if (bBackgroundAlphaNeeded || bHasImageMask) { |
562 if (pBitmap) { | 560 if (pBitmap) { |
563 CFX_WindowsDevice WinDC(dc); | 561 CFX_WindowsDevice WinDC(dc); |
564 | 562 |
565 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { | 563 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINTER) { |
566 CFX_DIBitmap* pDst = new CFX_DIBitmap; | 564 CFX_DIBitmap* pDst = new CFX_DIBitmap; |
567 int pitch = pBitmap->GetPitch(); | 565 int pitch = pBitmap->GetPitch(); |
568 pDst->Create(size_x, size_y, FXDIB_Rgb32); | 566 pDst->Create(size_x, size_y, FXDIB_Rgb32); |
569 FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y); | 567 FXSYS_memset(pDst->GetBuffer(), -1, pitch * size_y); |
570 pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0, | 568 pDst->CompositeBitmap(0, 0, size_x, size_y, pBitmap, 0, 0, |
571 FXDIB_BLEND_NORMAL, NULL, FALSE, NULL); | 569 FXDIB_BLEND_NORMAL, nullptr, FALSE, nullptr); |
572 WinDC.StretchDIBits(pDst, 0, 0, size_x, size_y); | 570 WinDC.StretchDIBits(pDst, 0, 0, size_x, size_y); |
573 delete pDst; | 571 delete pDst; |
574 } else { | 572 } else { |
575 WinDC.SetDIBits(pBitmap, 0, 0); | 573 WinDC.SetDIBits(pBitmap, 0, 0); |
576 } | 574 } |
577 } | 575 } |
578 } | 576 } |
579 if (bBackgroundAlphaNeeded || bHasImageMask) | 577 if (bBackgroundAlphaNeeded || bHasImageMask) |
580 delete pBitmap; | 578 delete pBitmap; |
581 | 579 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 *device_x = FXSYS_round(device_x_f); | 724 *device_x = FXSYS_round(device_x_f); |
727 *device_y = FXSYS_round(device_y_f); | 725 *device_y = FXSYS_round(device_y_f); |
728 #endif // PDF_ENABLE_XFA | 726 #endif // PDF_ENABLE_XFA |
729 } | 727 } |
730 | 728 |
731 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, | 729 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, |
732 int height, | 730 int height, |
733 int alpha) { | 731 int alpha) { |
734 std::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); | 732 std::unique_ptr<CFX_DIBitmap> pBitmap(new CFX_DIBitmap); |
735 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) { | 733 if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) { |
736 return NULL; | 734 return nullptr; |
737 } | 735 } |
738 return pBitmap.release(); | 736 return pBitmap.release(); |
739 } | 737 } |
740 | 738 |
741 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width, | 739 DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width, |
742 int height, | 740 int height, |
743 int format, | 741 int format, |
744 void* first_scan, | 742 void* first_scan, |
745 int stride) { | 743 int stride) { |
746 FXDIB_Format fx_format; | 744 FXDIB_Format fx_format; |
747 switch (format) { | 745 switch (format) { |
748 case FPDFBitmap_Gray: | 746 case FPDFBitmap_Gray: |
749 fx_format = FXDIB_8bppRgb; | 747 fx_format = FXDIB_8bppRgb; |
750 break; | 748 break; |
751 case FPDFBitmap_BGR: | 749 case FPDFBitmap_BGR: |
752 fx_format = FXDIB_Rgb; | 750 fx_format = FXDIB_Rgb; |
753 break; | 751 break; |
754 case FPDFBitmap_BGRx: | 752 case FPDFBitmap_BGRx: |
755 fx_format = FXDIB_Rgb32; | 753 fx_format = FXDIB_Rgb32; |
756 break; | 754 break; |
757 case FPDFBitmap_BGRA: | 755 case FPDFBitmap_BGRA: |
758 fx_format = FXDIB_Argb; | 756 fx_format = FXDIB_Argb; |
759 break; | 757 break; |
760 default: | 758 default: |
761 return NULL; | 759 return nullptr; |
762 } | 760 } |
763 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; | 761 CFX_DIBitmap* pBitmap = new CFX_DIBitmap; |
764 pBitmap->Create(width, height, fx_format, (uint8_t*)first_scan, stride); | 762 pBitmap->Create(width, height, fx_format, (uint8_t*)first_scan, stride); |
765 return pBitmap; | 763 return pBitmap; |
766 } | 764 } |
767 | 765 |
768 DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, | 766 DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap, |
769 int left, | 767 int left, |
770 int top, | 768 int top, |
771 int width, | 769 int width, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 pContext->m_pDevice->SetClip_Rect( | 855 pContext->m_pDevice->SetClip_Rect( |
858 FX_RECT(start_x, start_y, start_x + size_x, start_y + size_y)); | 856 FX_RECT(start_x, start_y, start_x + size_x, start_y + size_y)); |
859 | 857 |
860 pContext->m_pContext = new CPDF_RenderContext(pPage); | 858 pContext->m_pContext = new CPDF_RenderContext(pPage); |
861 pContext->m_pContext->AppendLayer(pPage, &matrix); | 859 pContext->m_pContext->AppendLayer(pPage, &matrix); |
862 | 860 |
863 if (flags & FPDF_ANNOT) { | 861 if (flags & FPDF_ANNOT) { |
864 pContext->m_pAnnots = new CPDF_AnnotList(pPage); | 862 pContext->m_pAnnots = new CPDF_AnnotList(pPage); |
865 FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY; | 863 FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY; |
866 pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext, bPrinting, | 864 pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext, bPrinting, |
867 &matrix, TRUE, NULL); | 865 &matrix, TRUE, nullptr); |
868 } | 866 } |
869 | 867 |
870 pContext->m_pRenderer = new CPDF_ProgressiveRenderer( | 868 pContext->m_pRenderer = new CPDF_ProgressiveRenderer( |
871 pContext->m_pContext, pContext->m_pDevice, pContext->m_pOptions); | 869 pContext->m_pContext, pContext->m_pDevice, pContext->m_pOptions); |
872 pContext->m_pRenderer->Start(pause); | 870 pContext->m_pRenderer->Start(pause); |
873 if (bNeedToRestore) | 871 if (bNeedToRestore) |
874 pContext->m_pDevice->RestoreState(false); | 872 pContext->m_pDevice->RestoreState(false); |
875 } | 873 } |
876 | 874 |
877 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, | 875 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 if (!pDoc) | 916 if (!pDoc) |
919 return 1; | 917 return 1; |
920 CPDF_ViewerPreferences viewRef(pDoc); | 918 CPDF_ViewerPreferences viewRef(pDoc); |
921 return viewRef.NumCopies(); | 919 return viewRef.NumCopies(); |
922 } | 920 } |
923 | 921 |
924 DLLEXPORT FPDF_PAGERANGE STDCALL | 922 DLLEXPORT FPDF_PAGERANGE STDCALL |
925 FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) { | 923 FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document) { |
926 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 924 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
927 if (!pDoc) | 925 if (!pDoc) |
928 return NULL; | 926 return nullptr; |
929 CPDF_ViewerPreferences viewRef(pDoc); | 927 CPDF_ViewerPreferences viewRef(pDoc); |
930 return viewRef.PrintPageRange(); | 928 return viewRef.PrintPageRange(); |
931 } | 929 } |
932 | 930 |
933 DLLEXPORT FPDF_DUPLEXTYPE STDCALL | 931 DLLEXPORT FPDF_DUPLEXTYPE STDCALL |
934 FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) { | 932 FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document) { |
935 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 933 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
936 if (!pDoc) | 934 if (!pDoc) |
937 return DuplexUndefined; | 935 return DuplexUndefined; |
938 CPDF_ViewerPreferences viewRef(pDoc); | 936 CPDF_ViewerPreferences viewRef(pDoc); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 if (!str) | 993 if (!str) |
996 return -1; | 994 return -1; |
997 if (!bstr || !length) | 995 if (!bstr || !length) |
998 return -1; | 996 return -1; |
999 if (length == -1) | 997 if (length == -1) |
1000 length = FXSYS_strlen(bstr); | 998 length = FXSYS_strlen(bstr); |
1001 | 999 |
1002 if (length == 0) { | 1000 if (length == 0) { |
1003 if (str->str) { | 1001 if (str->str) { |
1004 FX_Free(str->str); | 1002 FX_Free(str->str); |
1005 str->str = NULL; | 1003 str->str = nullptr; |
1006 } | 1004 } |
1007 str->len = 0; | 1005 str->len = 0; |
1008 return 0; | 1006 return 0; |
1009 } | 1007 } |
1010 | 1008 |
1011 if (str->str && str->len < length) | 1009 if (str->str && str->len < length) |
1012 str->str = FX_Realloc(char, str->str, length + 1); | 1010 str->str = FX_Realloc(char, str->str, length + 1); |
1013 else if (!str->str) | 1011 else if (!str->str) |
1014 str->str = FX_Alloc(char, length + 1); | 1012 str->str = FX_Alloc(char, length + 1); |
1015 | 1013 |
1016 str->str[length] = 0; | 1014 str->str[length] = 0; |
1017 if (str->str == NULL) | |
1018 return -1; | |
1019 | |
1020 FXSYS_memcpy(str->str, bstr, length); | 1015 FXSYS_memcpy(str->str, bstr, length); |
1021 str->len = length; | 1016 str->len = length; |
1022 | 1017 |
1023 return 0; | 1018 return 0; |
1024 } | 1019 } |
1025 | 1020 |
1026 DLLEXPORT FPDF_RESULT STDCALL FPDF_BStr_Clear(FPDF_BSTR* str) { | 1021 DLLEXPORT FPDF_RESULT STDCALL FPDF_BStr_Clear(FPDF_BSTR* str) { |
1027 if (!str) | 1022 if (!str) |
1028 return -1; | 1023 return -1; |
1029 | 1024 |
1030 if (str->str) { | 1025 if (str->str) { |
1031 FX_Free(str->str); | 1026 FX_Free(str->str); |
1032 str->str = NULL; | 1027 str->str = nullptr; |
1033 } | 1028 } |
1034 str->len = 0; | 1029 str->len = 0; |
1035 return 0; | 1030 return 0; |
1036 } | 1031 } |
1037 #endif // PDF_ENABLE_XFA | 1032 #endif // PDF_ENABLE_XFA |
1038 | 1033 |
1039 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, | 1034 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, |
1040 int index, | 1035 int index, |
1041 void* buffer, | 1036 void* buffer, |
1042 long* buflen) { | 1037 long* buflen) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 if (!buffer) { | 1093 if (!buffer) { |
1099 *buflen = len; | 1094 *buflen = len; |
1100 } else if (*buflen >= len) { | 1095 } else if (*buflen >= len) { |
1101 memcpy(buffer, utf16Name.c_str(), len); | 1096 memcpy(buffer, utf16Name.c_str(), len); |
1102 *buflen = len; | 1097 *buflen = len; |
1103 } else { | 1098 } else { |
1104 *buflen = -1; | 1099 *buflen = -1; |
1105 } | 1100 } |
1106 return (FPDF_DEST)pDestObj; | 1101 return (FPDF_DEST)pDestObj; |
1107 } | 1102 } |
OLD | NEW |