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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { | 510 DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page) { |
511 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 511 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
512 return pPage ? pPage->GetPageWidth() : 0.0; | 512 return pPage ? pPage->GetPageWidth() : 0.0; |
513 } | 513 } |
514 | 514 |
515 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { | 515 DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page) { |
516 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 516 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
517 return pPage ? pPage->GetPageHeight() : 0.0; | 517 return pPage ? pPage->GetPageHeight() : 0.0; |
518 } | 518 } |
519 | 519 |
520 void DropContext(void* data) { | |
521 delete (CRenderContext*)data; | |
522 } | |
523 | |
524 #if defined(_WIN32) | 520 #if defined(_WIN32) |
525 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, | 521 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, |
526 FPDF_PAGE page, | 522 FPDF_PAGE page, |
527 int start_x, | 523 int start_x, |
528 int start_y, | 524 int start_y, |
529 int size_x, | 525 int size_x, |
530 int size_y, | 526 int size_y, |
531 int rotate, | 527 int rotate, |
532 int flags) { | 528 int flags) { |
533 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 529 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
534 if (!pPage) | 530 if (!pPage) |
535 return; | 531 return; |
536 | 532 |
537 CRenderContext* pContext = new CRenderContext; | 533 CRenderContext* pContext = new CRenderContext; |
538 pPage->SetPrivateData((void*)1, pContext, DropContext); | 534 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>(pContext)); |
539 | 535 |
540 #if !defined(_WIN32_WCE) | 536 #if !defined(_WIN32_WCE) |
541 CFX_DIBitmap* pBitmap = nullptr; | 537 CFX_DIBitmap* pBitmap = nullptr; |
542 FX_BOOL bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); | 538 FX_BOOL bBackgroundAlphaNeeded = pPage->BackgroundAlphaNeeded(); |
543 FX_BOOL bHasImageMask = pPage->HasImageMask(); | 539 FX_BOOL bHasImageMask = pPage->HasImageMask(); |
544 if (bBackgroundAlphaNeeded || bHasImageMask) { | 540 if (bBackgroundAlphaNeeded || bHasImageMask) { |
545 pBitmap = new CFX_DIBitmap; | 541 pBitmap = new CFX_DIBitmap; |
546 pBitmap->Create(size_x, size_y, FXDIB_Argb); | 542 pBitmap->Create(size_x, size_y, FXDIB_Argb); |
547 pBitmap->Clear(0x00ffffff); | 543 pBitmap->Clear(0x00ffffff); |
548 pContext->m_pDevice = new CFX_FxgeDevice; | 544 pContext->m_pDevice = new CFX_FxgeDevice; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 HGDIOBJ hOldBitmap = SelectObject(hMemDC, pContext->m_hBitmap); | 608 HGDIOBJ hOldBitmap = SelectObject(hMemDC, pContext->m_hBitmap); |
613 | 609 |
614 BitBlt(dc, rect.left, rect.top, width, height, hMemDC, 0, 0, SRCCOPY); | 610 BitBlt(dc, rect.left, rect.top, width, height, hMemDC, 0, 0, SRCCOPY); |
615 SelectObject(hMemDC, hOldBitmap); | 611 SelectObject(hMemDC, hOldBitmap); |
616 DeleteDC(hMemDC); | 612 DeleteDC(hMemDC); |
617 | 613 |
618 #endif // !defined(_WIN32_WCE) | 614 #endif // !defined(_WIN32_WCE) |
619 if (bBackgroundAlphaNeeded || bHasImageMask) | 615 if (bBackgroundAlphaNeeded || bHasImageMask) |
620 delete pBitmap; | 616 delete pBitmap; |
621 | 617 |
622 delete pContext; | 618 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>()); |
623 pPage->RemovePrivateData((void*)1); | |
624 } | 619 } |
625 #endif // defined(_WIN32) | 620 #endif // defined(_WIN32) |
626 | 621 |
627 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, | 622 DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, |
628 FPDF_PAGE page, | 623 FPDF_PAGE page, |
629 int start_x, | 624 int start_x, |
630 int start_y, | 625 int start_y, |
631 int size_x, | 626 int size_x, |
632 int size_y, | 627 int size_y, |
633 int rotate, | 628 int rotate, |
634 int flags) { | 629 int flags) { |
635 if (!bitmap) | 630 if (!bitmap) |
636 return; | 631 return; |
| 632 |
637 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 633 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
638 if (!pPage) | 634 if (!pPage) |
639 return; | 635 return; |
| 636 |
640 CRenderContext* pContext = new CRenderContext; | 637 CRenderContext* pContext = new CRenderContext; |
641 pPage->SetPrivateData((void*)1, pContext, DropContext); | 638 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>(pContext)); |
642 pContext->m_pDevice = new CFX_FxgeDevice; | 639 pContext->m_pDevice = new CFX_FxgeDevice; |
643 | 640 if (flags & FPDF_REVERSE_BYTE_ORDER) { |
644 if (flags & FPDF_REVERSE_BYTE_ORDER) | |
645 ((CFX_FxgeDevice*)pContext->m_pDevice) | 641 ((CFX_FxgeDevice*)pContext->m_pDevice) |
646 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); | 642 ->Attach((CFX_DIBitmap*)bitmap, 0, TRUE); |
647 else | 643 } else { |
648 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); | 644 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bitmap); |
| 645 } |
649 | 646 |
650 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, | 647 FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
651 rotate, flags, TRUE, NULL); | 648 rotate, flags, TRUE, nullptr); |
652 | 649 |
653 delete pContext; | 650 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>()); |
654 pPage->RemovePrivateData((void*)1); | |
655 } | 651 } |
656 | 652 |
657 #ifdef _SKIA_SUPPORT_ | 653 #ifdef _SKIA_SUPPORT_ |
658 DLLEXPORT FPDF_RECORDER STDCALL FPDF_RenderPageSkp(FPDF_PAGE page, | 654 DLLEXPORT FPDF_RECORDER STDCALL FPDF_RenderPageSkp(FPDF_PAGE page, |
659 int size_x, | 655 int size_x, |
660 int size_y) { | 656 int size_y) { |
661 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 657 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
662 if (!pPage) | 658 if (!pPage) |
663 return nullptr; | 659 return nullptr; |
664 std::unique_ptr<CRenderContext> pContext(new CRenderContext); | 660 |
665 pPage->SetPrivateData((void*)1, pContext.get(), DropContext); | 661 CRenderContext* pContext = new CRenderContext; |
| 662 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>(pContext)); |
666 CFX_FxgeDevice* skDevice = new CFX_FxgeDevice; | 663 CFX_FxgeDevice* skDevice = new CFX_FxgeDevice; |
667 FPDF_RECORDER recorder = skDevice->CreateRecorder(size_x, size_y); | 664 FPDF_RECORDER recorder = skDevice->CreateRecorder(size_x, size_y); |
668 pContext->m_pDevice = skDevice; | 665 pContext->m_pDevice = skDevice; |
669 | |
670 FPDF_RenderPage_Retail(pContext.get(), page, 0, 0, size_x, size_y, 0, 0, TRUE, | 666 FPDF_RenderPage_Retail(pContext.get(), page, 0, 0, size_x, size_y, 0, 0, TRUE, |
671 NULL); | 667 nullptr); |
672 pPage->RemovePrivateData((void*)1); | 668 pPage->SetRenderContext(std::unique_ptr<CFX_Deletable>()); |
673 return recorder; | 669 return recorder; |
674 } | 670 } |
675 #endif | 671 #endif |
676 | 672 |
677 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { | 673 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) { |
| 674 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
678 if (!page) | 675 if (!page) |
679 return; | 676 return; |
680 #ifdef PDF_ENABLE_XFA | 677 #ifdef PDF_ENABLE_XFA |
681 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; | |
682 pPage->Release(); | 678 pPage->Release(); |
683 #else // PDF_ENABLE_XFA | 679 #else // PDF_ENABLE_XFA |
684 CPDFSDK_PageView* pPageView = | 680 CPDFSDK_PageView* pPageView = |
685 (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((void*)page); | 681 static_cast<CPDFSDK_PageView*>(pPage->GetView()); |
686 if (pPageView && pPageView->IsLocked()) { | 682 if (pPageView && pPageView->IsLocked()) { |
687 pPageView->TakeOverPage(); | 683 pPageView->TakeOverPage(); |
688 return; | 684 return; |
689 } | 685 } |
690 delete (CPDF_Page*)page; | 686 delete pPage; |
691 #endif // PDF_ENABLE_XFA | 687 #endif // PDF_ENABLE_XFA |
692 } | 688 } |
693 | 689 |
694 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { | 690 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) { |
695 #ifdef PDF_ENABLE_XFA | 691 #ifdef PDF_ENABLE_XFA |
696 delete UnderlyingFromFPDFDocument(document); | 692 delete UnderlyingFromFPDFDocument(document); |
697 #else // PDF_ENABLE_XFA | 693 #else // PDF_ENABLE_XFA |
698 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 694 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
699 if (!pDoc) | 695 if (!pDoc) |
700 return; | 696 return; |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 if (!buffer) { | 1135 if (!buffer) { |
1140 *buflen = len; | 1136 *buflen = len; |
1141 } else if (*buflen >= len) { | 1137 } else if (*buflen >= len) { |
1142 memcpy(buffer, utf16Name.c_str(), len); | 1138 memcpy(buffer, utf16Name.c_str(), len); |
1143 *buflen = len; | 1139 *buflen = len; |
1144 } else { | 1140 } else { |
1145 *buflen = -1; | 1141 *buflen = -1; |
1146 } | 1142 } |
1147 return (FPDF_DEST)pDestObj; | 1143 return (FPDF_DEST)pDestObj; |
1148 } | 1144 } |
OLD | NEW |