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