| 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/fxcodec/fx_codec.h" | 7 #include "../../core/include/fxcodec/fx_codec.h" |
| 8 #include "../../core/include/fxcrt/fx_safe_types.h" | 8 #include "../../core/include/fxcrt/fx_safe_types.h" |
| 9 #include "../../public/fpdf_ext.h" | 9 #include "../../public/fpdf_ext.h" |
| 10 #include "../../public/fpdf_progressive.h" | 10 #include "../../public/fpdf_progressive.h" |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 { | 317 { |
| 318 if (!page) return 0.0; | 318 if (!page) return 0.0; |
| 319 return ((CPDF_Page*)page)->GetPageHeight(); | 319 return ((CPDF_Page*)page)->GetPageHeight(); |
| 320 } | 320 } |
| 321 | 321 |
| 322 void DropContext(void* data) | 322 void DropContext(void* data) |
| 323 { | 323 { |
| 324 delete (CRenderContext*)data; | 324 delete (CRenderContext*)data; |
| 325 } | 325 } |
| 326 | 326 |
| 327 void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_
x, int start_y, int size_x, int size_y, | |
| 328 int rotate, int flags,FX_BOOL bN
eedToRestore, IFSDK_PAUSE_Adapter * pause ); | |
| 329 void (*Func_RenderPage)(CRenderContext*, FPDF_PAGE page, int start_x, int start_
y, int size_x, int size_y, | |
| 330 int rotate, int flags,FX_BOOL bN
eedToRestore, IFSDK_PAUSE_Adapter * pause ) = FPDF_RenderPage_Retail; | |
| 331 | |
| 332 #if defined(_DEBUG) || defined(DEBUG) | 327 #if defined(_DEBUG) || defined(DEBUG) |
| 333 #define DEBUG_TRACE | 328 #define DEBUG_TRACE |
| 334 #endif | 329 #endif |
| 335 | 330 |
| 336 #if defined(_WIN32) | 331 #if defined(_WIN32) |
| 337 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
start_y, int size_x, int size_y, | 332 DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
start_y, int size_x, int size_y, |
| 338 int rotate, int flags) | 333 int rotate, int flags) |
| 339 { | 334 { |
| 340 if (page==NULL) return; | 335 if (page==NULL) return; |
| 341 CPDF_Page* pPage = (CPDF_Page*)page; | 336 CPDF_Page* pPage = (CPDF_Page*)page; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 357 pContext->m_pDevice = new CFX_SkiaDevice; | 352 pContext->m_pDevice = new CFX_SkiaDevice; |
| 358 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pB
itmap); | 353 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pB
itmap); |
| 359 #else | 354 #else |
| 360 pContext->m_pDevice = new CFX_FxgeDevice; | 355 pContext->m_pDevice = new CFX_FxgeDevice; |
| 361 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pB
itmap); | 356 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)pB
itmap); |
| 362 #endif | 357 #endif |
| 363 } | 358 } |
| 364 else | 359 else |
| 365 pContext->m_pDevice = new CFX_WindowsDevice(dc); | 360 pContext->m_pDevice = new CFX_WindowsDevice(dc); |
| 366 | 361 |
| 367 » Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate
, flags,TRUE,NULL); | 362 » FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
| 363 rotate, flags, TRUE, NULL); |
| 368 | 364 |
| 369 if (bBackgroundAlphaNeeded) | 365 if (bBackgroundAlphaNeeded) |
| 370 { | 366 { |
| 371 if (pBitmap) | 367 if (pBitmap) |
| 372 { | 368 { |
| 373 CFX_WindowsDevice WinDC(dc); | 369 CFX_WindowsDevice WinDC(dc); |
| 374 | 370 |
| 375 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINT
ER) | 371 if (WinDC.GetDeviceCaps(FXDC_DEVICE_CLASS) == FXDC_PRINT
ER) |
| 376 { | 372 { |
| 377 CFX_DIBitmap* pDst = new CFX_DIBitmap; | 373 CFX_DIBitmap* pDst = new CFX_DIBitmap; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 pContext->m_pBitmap = new CFX_DIBitmap; | 436 pContext->m_pBitmap = new CFX_DIBitmap; |
| 441 pContext->m_pBitmap->Create(width, height, FXDIB_Rgb, (uint8_t*)pBuffer)
; | 437 pContext->m_pBitmap->Create(width, height, FXDIB_Rgb, (uint8_t*)pBuffer)
; |
| 442 pContext->m_pDevice = new CPDF_FxgeDevice; | 438 pContext->m_pDevice = new CPDF_FxgeDevice; |
| 443 ((CPDF_FxgeDevice*)pContext->m_pDevice)->Attach(pContext->m_pBitmap); | 439 ((CPDF_FxgeDevice*)pContext->m_pDevice)->Attach(pContext->m_pBitmap); |
| 444 | 440 |
| 445 #ifdef DEBUG_TRACE | 441 #ifdef DEBUG_TRACE |
| 446 CPDF_ModuleMgr::Get()->ReportError(999, "Ready for PDF rendering"); | 442 CPDF_ModuleMgr::Get()->ReportError(999, "Ready for PDF rendering"); |
| 447 #endif | 443 #endif |
| 448 | 444 |
| 449 // output to bitmap device | 445 // output to bitmap device |
| 450 » Func_RenderPage(pContext, page, start_x - rect.left, start_y - rect.top,
size_x, size_y, rotate, flags); | 446 » FPDF_RenderPage_Retail(pContext, page, start_x - rect.left, |
| 447 start_y - rect.top, size_x, size_y, rotate, flags); |
| 451 | 448 |
| 452 #ifdef DEBUG_TRACE | 449 #ifdef DEBUG_TRACE |
| 453 CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering"); | 450 CPDF_ModuleMgr::Get()->ReportError(999, "Finished PDF rendering"); |
| 454 #endif | 451 #endif |
| 455 | 452 |
| 456 // Now output to real device | 453 // Now output to real device |
| 457 HDC hMemDC = CreateCompatibleDC(dc); | 454 HDC hMemDC = CreateCompatibleDC(dc); |
| 458 if (hMemDC == NULL) { | 455 if (hMemDC == NULL) { |
| 459 #if defined(DEBUG) || defined(_DEBUG) | 456 #if defined(DEBUG) || defined(_DEBUG) |
| 460 char str[128]; | 457 char str[128]; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi
tmap); | 505 ((CFX_SkiaDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi
tmap); |
| 509 #else | 506 #else |
| 510 pContext->m_pDevice = new CFX_FxgeDevice; | 507 pContext->m_pDevice = new CFX_FxgeDevice; |
| 511 | 508 |
| 512 if (flags & FPDF_REVERSE_BYTE_ORDER) | 509 if (flags & FPDF_REVERSE_BYTE_ORDER) |
| 513 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi
tmap,0,TRUE); | 510 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi
tmap,0,TRUE); |
| 514 else | 511 else |
| 515 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi
tmap); | 512 ((CFX_FxgeDevice*)pContext->m_pDevice)->Attach((CFX_DIBitmap*)bi
tmap); |
| 516 #endif | 513 #endif |
| 517 | 514 |
| 518 » Func_RenderPage(pContext, page, start_x, start_y, size_x, size_y, rotate
, flags,TRUE,NULL); | 515 » FPDF_RenderPage_Retail(pContext, page, start_x, start_y, size_x, size_y, |
| 516 rotate, flags, TRUE, NULL); |
| 519 | 517 |
| 520 delete pContext; | 518 delete pContext; |
| 521 pPage->RemovePrivateData((void*)1); | 519 pPage->RemovePrivateData((void*)1); |
| 522 } | 520 } |
| 523 | 521 |
| 524 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) | 522 DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page) |
| 525 { | 523 { |
| 526 if (!page) return; | 524 if (!page) return; |
| 527 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)(((CPDF_Page*)page))->G
etPrivateData((void*)page); | 525 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)(((CPDF_Page*)page))->G
etPrivateData((void*)page); |
| 528 if (pPageView && pPageView->IsLocked()) { | 526 if (pPageView && pPageView->IsLocked()) { |
| 529 pPageView->TakeOverPage(); | 527 pPageView->TakeOverPage(); |
| 530 return; | 528 return; |
| 531 } | 529 } |
| 532 delete (CPDF_Page*)page; | 530 delete (CPDF_Page*)page; |
| 533 | 531 |
| 534 } | 532 } |
| 535 | 533 |
| 536 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) | 534 DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document) |
| 537 { | 535 { |
| 538 if (!document) | 536 if (!document) |
| 539 return; | 537 return; |
| 540 CPDF_Document* pDoc = (CPDF_Document*)document; | 538 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 541 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); | 539 CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser(); |
| 542 if (pParser == NULL) | 540 if (pParser == NULL) |
| 543 { | 541 { |
| 544 delete pDoc; | 542 delete pDoc; |
| 545 return; | 543 return; |
| 546 } | 544 } |
| 547 delete pParser; | 545 delete pParser; |
| 548 // delete pDoc; | |
| 549 } | 546 } |
| 550 | 547 |
| 551 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() | 548 DLLEXPORT unsigned long STDCALL FPDF_GetLastError() |
| 552 { | 549 { |
| 553 return GetLastError(); | 550 return GetLastError(); |
| 554 } | 551 } |
| 555 | 552 |
| 556 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, int start_x, int start_
y, int size_x, int size_y, | 553 DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, int start_x, int start_
y, int size_x, int size_y, |
| 557 int rotate, int device_x, int de
vice_y, double* page_x, double* page_y) | 554 int rotate, int device_x, int de
vice_y, double* page_x, double* page_y) |
| 558 { | 555 { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 if (bitmap == NULL) return 0; | 654 if (bitmap == NULL) return 0; |
| 658 return ((CFX_DIBitmap*)bitmap)->GetPitch(); | 655 return ((CFX_DIBitmap*)bitmap)->GetPitch(); |
| 659 } | 656 } |
| 660 | 657 |
| 661 DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) | 658 DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap) |
| 662 { | 659 { |
| 663 delete (CFX_DIBitmap*)bitmap; | 660 delete (CFX_DIBitmap*)bitmap; |
| 664 } | 661 } |
| 665 | 662 |
| 666 void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_
x, int start_y, int size_x, int size_y, | 663 void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_
x, int start_y, int size_x, int size_y, |
| 667 » » » » » » int rotate, int flags,FX_BOOL bN
eedToRestore, IFSDK_PAUSE_Adapter * pause ) | 664 int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_
PAUSE_Adapter * pause ) |
| 668 { | 665 { |
| 669 CPDF_Page* pPage = (CPDF_Page*)page; | 666 CPDF_Page* pPage = (CPDF_Page*)page; |
| 670 if (pPage == NULL) return; | 667 if (pPage == NULL) return; |
| 671 | 668 |
| 672 if (!pContext->m_pOptions) | 669 if (!pContext->m_pOptions) |
| 673 pContext->m_pOptions = new CPDF_RenderOptions; | 670 pContext->m_pOptions = new CPDF_RenderOptions; |
| 674 //» CPDF_RenderOptions options; | 671 |
| 675 if (flags & FPDF_LCD_TEXT) | 672 if (flags & FPDF_LCD_TEXT) |
| 676 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; | 673 pContext->m_pOptions->m_Flags |= RENDER_CLEARTYPE; |
| 677 else | 674 else |
| 678 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; | 675 pContext->m_pOptions->m_Flags &= ~RENDER_CLEARTYPE; |
| 679 if (flags & FPDF_NO_NATIVETEXT) | 676 if (flags & FPDF_NO_NATIVETEXT) |
| 680 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT; | 677 pContext->m_pOptions->m_Flags |= RENDER_NO_NATIVETEXT; |
| 681 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE) | 678 if (flags & FPDF_RENDER_LIMITEDIMAGECACHE) |
| 682 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; | 679 pContext->m_pOptions->m_Flags |= RENDER_LIMITEDIMAGECACHE; |
| 683 if (flags & FPDF_RENDER_FORCEHALFTONE) | 680 if (flags & FPDF_RENDER_FORCEHALFTONE) |
| 684 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; | 681 pContext->m_pOptions->m_Flags |= RENDER_FORCE_HALFTONE; |
| 685 if (flags & FPDF_RENDER_NO_SMOOTHTEXT) | 682 if (flags & FPDF_RENDER_NO_SMOOTHTEXT) |
| 686 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH; | 683 pContext->m_pOptions->m_Flags |= RENDER_NOTEXTSMOOTH; |
| 687 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE) | 684 if (flags & FPDF_RENDER_NO_SMOOTHIMAGE) |
| 688 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH; | 685 pContext->m_pOptions->m_Flags |= RENDER_NOIMAGESMOOTH; |
| 689 if (flags & FPDF_RENDER_NO_SMOOTHPATH) | 686 if (flags & FPDF_RENDER_NO_SMOOTHPATH) |
| 690 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH; | 687 pContext->m_pOptions->m_Flags |= RENDER_NOPATHSMOOTH; |
| 691 //Grayscale output | 688 //Grayscale output |
| 692 if (flags & FPDF_GRAYSCALE) | 689 if (flags & FPDF_GRAYSCALE) |
| 693 { | 690 { |
| 694 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; | 691 pContext->m_pOptions->m_ColorMode = RENDER_COLOR_GRAY; |
| 695 pContext->m_pOptions->m_ForeColor = 0; | 692 pContext->m_pOptions->m_ForeColor = 0; |
| 696 pContext->m_pOptions->m_BackColor = 0xffffff; | 693 pContext->m_pOptions->m_BackColor = 0xffffff; |
| 697 } | 694 } |
| 698 const CPDF_OCContext::UsageType usage = (flags & FPDF_PRINTING) ? CPDF_O
CContext::Print : CPDF_OCContext::View; | 695 const CPDF_OCContext::UsageType usage = (flags & FPDF_PRINTING) ? CPDF_O
CContext::Print : CPDF_OCContext::View; |
| 699 | |
| 700 pContext->m_pOptions->m_AddFlags = flags >> 8; | 696 pContext->m_pOptions->m_AddFlags = flags >> 8; |
| 701 | |
| 702 pContext->m_pOptions->m_pOCContext = new CPDF_OCContext(pPage->m_pDocume
nt, usage); | 697 pContext->m_pOptions->m_pOCContext = new CPDF_OCContext(pPage->m_pDocume
nt, usage); |
| 703 | 698 |
| 704 | |
| 705 CFX_AffineMatrix matrix; | 699 CFX_AffineMatrix matrix; |
| 706 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate
); | 700 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate
); |
| 707 | 701 |
| 708 FX_RECT clip; | 702 FX_RECT clip; |
| 709 clip.left = start_x; | 703 clip.left = start_x; |
| 710 clip.right = start_x + size_x; | 704 clip.right = start_x + size_x; |
| 711 clip.top = start_y; | 705 clip.top = start_y; |
| 712 clip.bottom = start_y + size_y; | 706 clip.bottom = start_y + size_y; |
| 713 pContext->m_pDevice->SaveState(); | 707 pContext->m_pDevice->SaveState(); |
| 714 pContext->m_pDevice->SetClip_Rect(&clip); | 708 pContext->m_pDevice->SetClip_Rect(&clip); |
| 715 | 709 |
| 716 pContext->m_pContext = new CPDF_RenderContext; | 710 pContext->m_pContext = new CPDF_RenderContext; |
| 717 pContext->m_pContext->Create(pPage); | 711 pContext->m_pContext->Create(pPage); |
| 718 pContext->m_pContext->AppendObjectList(pPage, &matrix); | 712 pContext->m_pContext->AppendObjectList(pPage, &matrix); |
| 719 | 713 |
| 720 if (flags & FPDF_ANNOT) { | 714 if (flags & FPDF_ANNOT) { |
| 721 pContext->m_pAnnots = new CPDF_AnnotList(pPage); | 715 pContext->m_pAnnots = new CPDF_AnnotList(pPage); |
| 722 FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXD
C_DISPLAY; | 716 FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXD
C_DISPLAY; |
| 723 pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext,
bPrinting, &matrix, TRUE, NULL); | 717 pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext,
bPrinting, &matrix, TRUE, NULL); |
| 724 } | 718 } |
| 725 | 719 |
| 726 pContext->m_pRenderer = new CPDF_ProgressiveRenderer; | 720 pContext->m_pRenderer = new CPDF_ProgressiveRenderer; |
| 727 pContext->m_pRenderer->Start(pContext->m_pContext, pContext->m_pDevice,
pContext->m_pOptions, pause); | 721 pContext->m_pRenderer->Start(pContext->m_pContext, pContext->m_pDevice,
pContext->m_pOptions, pause); |
| 728 if (bNeedToRestore) | 722 if (bNeedToRestore) |
| 729 { | 723 { |
| 730 » pContext->m_pDevice->RestoreState(); | 724 » » pContext->m_pDevice->RestoreState(); |
| 731 } | 725 } |
| 732 } | 726 } |
| 733 | 727 |
| 734 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_i
ndex, double* width, double* height) | 728 DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_i
ndex, double* width, double* height) |
| 735 { | 729 { |
| 736 CPDF_Document* pDoc = (CPDF_Document*)document; | 730 CPDF_Document* pDoc = (CPDF_Document*)document; |
| 737 if(pDoc == NULL) | 731 if(pDoc == NULL) |
| 738 return FALSE; | 732 return FALSE; |
| 739 | 733 |
| 740 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); | 734 CPDF_Dictionary* pDict = pDoc->GetPage(page_index); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 if (!buffer) { | 851 if (!buffer) { |
| 858 *buflen = len; | 852 *buflen = len; |
| 859 } else if (*buflen >= len) { | 853 } else if (*buflen >= len) { |
| 860 memcpy(buffer, utf16Name.c_str(), len); | 854 memcpy(buffer, utf16Name.c_str(), len); |
| 861 *buflen = len; | 855 *buflen = len; |
| 862 } else { | 856 } else { |
| 863 *buflen = -1; | 857 *buflen = -1; |
| 864 } | 858 } |
| 865 return (FPDF_DEST)pDestObj; | 859 return (FPDF_DEST)pDestObj; |
| 866 } | 860 } |
| OLD | NEW |