| 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" |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 if (!page) return 0.0; | 442 if (!page) return 0.0; |
| 443 // return ((CPDF_Page*)page)->GetPageHeight(); | 443 // return ((CPDF_Page*)page)->GetPageHeight(); |
| 444 return ((CPDFXFA_Page*)page)->GetPageHeight(); | 444 return ((CPDFXFA_Page*)page)->GetPageHeight(); |
| 445 } | 445 } |
| 446 | 446 |
| 447 void DropContext(void* data) | 447 void DropContext(void* data) |
| 448 { | 448 { |
| 449 delete (CRenderContext*)data; | 449 delete (CRenderContext*)data; |
| 450 } | 450 } |
| 451 | 451 |
| 452 void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_
x, int start_y, int size_x, int size_y, | |
| 453 int rotate, int flags,FX_BOOL bN
eedToRestore, IFSDK_PAUSE_Adapter * pause ); | |
| 454 void (*Func_RenderPage)(CRenderContext*, FPDF_PAGE page, int start_x, int start_
y, int size_x, int size_y, | |
| 455 int rotate, int flags,FX_BOOL bN
eedToRestore, IFSDK_PAUSE_Adapter * pause ) = FPDF_RenderPage_Retail; | |
| 456 | |
| 457 #if defined(_DEBUG) || defined(DEBUG) | 452 #if defined(_DEBUG) || defined(DEBUG) |
| 458 #define DEBUG_TRACE | 453 #define DEBUG_TRACE |
| 459 #endif | 454 #endif |
| 460 | 455 |
| 461 #if defined(_WIN32) | 456 #if defined(_WIN32) |
| 462 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
start_y, int size_x, int size_y, | 457 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
start_y, int size_x, int size_y, |
| 463 int rotate, int flags) | 458 int rotate, int flags) |
| 464 { | 459 { |
| 465 if (page==NULL) return; | 460 if (page==NULL) return; |
| 466 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); | 461 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 483 pContext->m_pDevice = FX_NEW CFX_SkiaDevice; | 478 pContext->m_pDevice = FX_NEW CFX_SkiaDevice; |
| 484 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pB
itmap); | 479 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pB
itmap); |
| 485 #else | 480 #else |
| 486 pContext->m_pDevice = FX_NEW CFX_FxgeDevice; | 481 pContext->m_pDevice = FX_NEW CFX_FxgeDevice; |
| 487 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pB
itmap); | 482 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pB
itmap); |
| 488 #endif | 483 #endif |
| 489 } | 484 } |
| 490 else | 485 else |
| 491 pContext->m_pDevice = FX_NEW CFX_WindowsDevice(dc); | 486 pContext->m_pDevice = FX_NEW CFX_WindowsDevice(dc); |
| 492 | 487 |
| 493 » Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate
, flags,TRUE,NULL); | 488 » FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
| 489 rotate, flags, TRUE, NULL); |
| 494 | 490 |
| 495 if (bBackgroundAlphaNeeded) | 491 if (bBackgroundAlphaNeeded) |
| 496 { | 492 { |
| 497 if (pBitmap) | 493 if (pBitmap) |
| 498 { | 494 { |
| 499 CFX_WindowsDevice WinDC(dc); | 495 CFX_WindowsDevice WinDC(dc); |
| 500 | 496 |
| 501 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINT
ER) | 497 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINT
ER) |
| 502 { | 498 { |
| 503 CFX_DIBitmap* pDst = FX_NEW CFX_DIBitmap; | 499 CFX_DIBitmap* pDst = FX_NEW CFX_DIBitmap; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 pContext->m_pBitmap = new CFX_DIBitmap; | 562 pContext->m_pBitmap = new CFX_DIBitmap; |
| 567 pContext->m_pBitmap->Create(width, height, FXDIB_Rgb, (uint8_t*)pBuffer)
; | 563 pContext->m_pBitmap->Create(width, height, FXDIB_Rgb, (uint8_t*)pBuffer)
; |
| 568 pContext->m_pDevice = new CPDF_FxgeDevice; | 564 pContext->m_pDevice = new CPDF_FxgeDevice; |
| 569 ((CPDF_FxgeDevice*)pContext->m_pDevice)->Attach(pContext->m_pBitmap); | 565 ((CPDF_FxgeDevice*)pContext->m_pDevice)->Attach(pContext->m_pBitmap); |
| 570 | 566 |
| 571 #ifdef DEBUG_TRACE | 567 #ifdef DEBUG_TRACE |
| 572 CPDF_ModuleMgr::Get()->ReportError(999, "Ready for PDF rendering"); | 568 CPDF_ModuleMgr::Get()->ReportError(999, "Ready for PDF rendering"); |
| 573 #endif | 569 #endif |
| 574 | 570 |
| 575 // output to bitmap device | 571 // output to bitmap device |
| 576 » Func_RenderPage(pContext, page, start_x - rect.left, start_y - rect.top,
size_x, size_y, rotate, flags); | 572 » FPDF_RenderPage_Retail(pContext, page, start_x - rect.left, |
| 573 start_y - rect.top, size_x, size_y, rotate, flags); |
| 577 | 574 |
| 578 #ifdef DEBUG_TRACE | 575 #ifdef DEBUG_TRACE |
| 579 CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering"); | 576 CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering"); |
| 580 #endif | 577 #endif |
| 581 | 578 |
| 582 // Now output to real device | 579 // Now output to real device |
| 583 HDC hMemDC = CreateCompatibleDC(dc); | 580 HDC hMemDC = CreateCompatibleDC(dc); |
| 584 if (hMemDC == NULL) { | 581 if (hMemDC == NULL) { |
| 585 #if defined(DEBUG) || defined(_DEBUG) | 582 #if defined(DEBUG) || defined(_DEBUG) |
| 586 char str[128]; | 583 char str[128]; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi
tmap); | 631 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi
tmap); |
| 635 #else | 632 #else |
| 636 pContext->m_pDevice = FX_NEW CFX_FxgeDevice; | 633 pContext->m_pDevice = FX_NEW CFX_FxgeDevice; |
| 637 | 634 |
| 638 if (flags & FPDF_REVERSE_BYTE_ORDER) | 635 if (flags & FPDF_REVERSE_BYTE_ORDER) |
| 639 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi
tmap,0,TRUE); | 636 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi
tmap,0,TRUE); |
| 640 else | 637 else |
| 641 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi
tmap); | 638 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi
tmap); |
| 642 #endif | 639 #endif |
| 643 | 640 |
| 644 » Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate
, flags,TRUE,NULL); | 641 » FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
| 642 rotate, flags, TRUE, NULL); |
| 645 | 643 |
| 646 delete pContext; | 644 delete pContext; |
| 647 pPage->RemovePrivateData((void*)1); | 645 pPage->RemovePrivateData((void*)1); |
| 648 } | 646 } |
| 649 | 647 |
| 650 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) | 648 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) |
| 651 { | 649 { |
| 652 if (!page) return; | 650 if (!page) return; |
| 653 | 651 |
| 654 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; | 652 CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; |
| 655 pPage->Release(); | 653 pPage->Release(); |
| 656 } | 654 } |
| 657 | 655 |
| 658 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) | 656 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) |
| 659 { | 657 { |
| 660 if (!document) | 658 if (!document) |
| 661 return; | 659 return; |
| 660 |
| 662 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; | 661 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; |
| 663 delete pDoc; | 662 delete pDoc; |
| 664 | |
| 665 // CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); | |
| 666 // if (pParser == NULL) | |
| 667 // { | |
| 668 // delete pDoc; | |
| 669 // return; | |
| 670 // } | |
| 671 // delete pParser; | |
| 672 // delete pDoc; | |
| 673 } | 663 } |
| 674 | 664 |
| 675 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() | 665 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() |
| 676 { | 666 { |
| 677 return GetLastError(); | 667 return GetLastError(); |
| 678 } | 668 } |
| 679 | 669 |
| 680 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, int start_x, int start_
y, int size_x, int size_y, | 670 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, int start_x, int start_
y, int size_x, int size_y, |
| 681 int rotate, int device_x, int de
vice_y, double* page_x, double* page_y) | 671 int rotate, int device_x, int de
vice_y, double* page_x, double* page_y) |
| 682 { | 672 { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 if (bitmap == NULL) return 0; | 754 if (bitmap == NULL) return 0; |
| 765 return ((CFX_DIBitmap*)bitmap)->GetPitch(); | 755 return ((CFX_DIBitmap*)bitmap)->GetPitch(); |
| 766 } | 756 } |
| 767 | 757 |
| 768 DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) | 758 DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) |
| 769 { | 759 { |
| 770 delete (CFX_DIBitmap*)bitmap; | 760 delete (CFX_DIBitmap*)bitmap; |
| 771 } | 761 } |
| 772 | 762 |
| 773 void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_
x, int start_y, int size_x, int size_y, | 763 void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_
x, int start_y, int size_x, int size_y, |
| 774 » » » » » » int rotate, int flags,FX_BOOL bN
eedToRestore, IFSDK_PAUSE_Adapter * pause ) | 764 int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_
PAUSE_Adapter * pause ) |
| 775 { | 765 { |
| 776 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); | 766 CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage(); |
| 777 if (pPage == NULL) return; | 767 if (pPage == NULL) return; |
| 778 | 768 |
| 779 if (!pContext->m_pOptions) | 769 if (!pContext->m_pOptions) |
| 780 pContext->m_pOptions = new CPDF_RenderOptions; | 770 pContext->m_pOptions = new CPDF_RenderOptions; |
| 781 //» CPDF_RenderOptions options; | 771 |
| 782 if (flags & FPDF_LCD_TEXT) | 772 if (flags & FPDF_LCD_TEXT) |
| 783 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; | 773 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; |
| 784 else | 774 else |
| 785 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; | 775 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; |
| 786 if (flags & FPDF_NO_NATIVETEXT) | 776 if (flags & FPDF_NO_NATIVETEXT) |
| 787 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT; | 777 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT; |
| 788 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE) | 778 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE) |
| 789 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; | 779 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; |
| 790 if (flags & FPDF_RENDER_FORCEHALFTONE) | 780 if (flags & FPDF_RENDER_FORCEHALFTONE) |
| 791 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; | 781 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; |
| 792 //Grayscale output | 782 //Grayscale output |
| 793 if (flags & FPDF_GRAYSCALE) | 783 if (flags & FPDF_GRAYSCALE) |
| 794 { | 784 { |
| 795 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; | 785 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; |
| 796 pContext->m_pOptions->m_ForeColor = 0; | 786 pContext->m_pOptions->m_ForeColor = 0; |
| 797 pContext->m_pOptions->m_BackColor = 0xffffff; | 787 pContext->m_pOptions->m_BackColor = 0xffffff; |
| 798 } | 788 } |
| 799 const CPDF_OCContext::UsageType usage = (flags & FPDF_PRINTING) ? CPDF_O
CContext::Print : CPDF_OCContext::View; | 789 const CPDF_OCContext::UsageType usage = (flags & FPDF_PRINTING) ? CPDF_O
CContext::Print : CPDF_OCContext::View; |
| 800 | |
| 801 pContext->m_pOptions->m_AddFlags = flags >> 8; | 790 pContext->m_pOptions->m_AddFlags = flags >> 8; |
| 802 | |
| 803 pContext->m_pOptions->m_pOCContext = new CPDF_OCContext(pPage->m_pDocume
nt, usage); | 791 pContext->m_pOptions->m_pOCContext = new CPDF_OCContext(pPage->m_pDocume
nt, usage); |
| 804 | 792 |
| 805 | |
| 806 CFX_AffineMatrix matrix; | 793 CFX_AffineMatrix matrix; |
| 807 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate
); | 794 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate
); |
| 808 | 795 |
| 809 FX_RECT clip; | 796 FX_RECT clip; |
| 810 clip.left = start_x; | 797 clip.left = start_x; |
| 811 clip.right = start_x + size_x; | 798 clip.right = start_x + size_x; |
| 812 clip.top = start_y; | 799 clip.top = start_y; |
| 813 clip.bottom = start_y + size_y; | 800 clip.bottom = start_y + size_y; |
| 814 pContext->m_pDevice->SaveState(); | 801 pContext->m_pDevice->SaveState(); |
| 815 pContext->m_pDevice->SetClip_Rect(&clip); | 802 pContext->m_pDevice->SetClip_Rect(&clip); |
| 816 | 803 |
| 817 pContext->m_pContext = FX_NEW CPDF_RenderContext; | 804 pContext->m_pContext = FX_NEW CPDF_RenderContext; |
| 818 pContext->m_pContext->Create(pPage); | 805 pContext->m_pContext->Create(pPage); |
| 819 pContext->m_pContext->AppendObjectList(pPage, &matrix); | 806 pContext->m_pContext->AppendObjectList(pPage, &matrix); |
| 820 | 807 |
| 821 if (flags & FPDF_ANNOT) { | 808 if (flags & FPDF_ANNOT) { |
| 822 pContext->m_pAnnots = FX_NEW CPDF_AnnotList(pPage); | 809 pContext->m_pAnnots = FX_NEW CPDF_AnnotList(pPage); |
| 823 FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXD
C_DISPLAY; | 810 FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXD
C_DISPLAY; |
| 824 pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext,
bPrinting, &matrix, TRUE, NULL); | 811 pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext,
bPrinting, &matrix, TRUE, NULL); |
| 825 } | 812 } |
| 826 | 813 |
| 827 pContext->m_pRenderer = FX_NEW CPDF_ProgressiveRenderer; | 814 pContext->m_pRenderer = FX_NEW CPDF_ProgressiveRenderer; |
| 828 pContext->m_pRenderer->Start(pContext->m_pContext, pContext->m_pDevice,
pContext->m_pOptions, pause); | 815 pContext->m_pRenderer->Start(pContext->m_pContext, pContext->m_pDevice,
pContext->m_pOptions, pause); |
| 829 if (bNeedToRestore) | 816 if (bNeedToRestore) |
| 830 { | 817 { |
| 831 » pContext->m_pDevice->RestoreState(); | 818 » » pContext->m_pDevice->RestoreState(); |
| 832 } | 819 } |
| 833 | 820 |
| 834 //#endif | 821 //#endif |
| 835 } | 822 } |
| 836 | 823 |
| 837 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_i
ndex, double* width, double* height) | 824 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_i
ndex, double* width, double* height) |
| 838 { | 825 { |
| 839 // CPDF_Document* pDoc = (CPDF_Document*)document; | 826 // CPDF_Document* pDoc = (CPDF_Document*)document; |
| 840 // if(pDoc == NULL) | 827 // if(pDoc == NULL) |
| 841 // return FALSE; | 828 // return FALSE; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 if (!buffer) { | 1024 if (!buffer) { |
| 1038 *buflen = len; | 1025 *buflen = len; |
| 1039 } else if (*buflen >= len) { | 1026 } else if (*buflen >= len) { |
| 1040 memcpy(buffer, utf16Name.c_str(), len); | 1027 memcpy(buffer, utf16Name.c_str(), len); |
| 1041 *buflen = len; | 1028 *buflen = len; |
| 1042 } else { | 1029 } else { |
| 1043 *buflen = -1; | 1030 *buflen = -1; |
| 1044 } | 1031 } |
| 1045 return (FPDF_DEST)pDestObj; | 1032 return (FPDF_DEST)pDestObj; |
| 1046 } | 1033 } |
| OLD | NEW |