From 75f84a56fed36111ece82d0ac96e87289622b093 Mon Sep 17 00:00:00 2001 From: jaepark Date: Fri, 9 Sep 2016 15:39:09 -0700 Subject: Define behaviors of FPDF_RenderPageBitmap_Retail and FPDF_FFLDraw. Previously, PDFium only supported widget annotations to draw forms. As we've implemented other annotations, the behavior of FPDF_RenderPageBitmap_Retail and FPDF_FFLDraw changed. So, this CL clearly defines what needs to be done in FPDF_RenderPageBitmap_Retail and FPDF_FFLDraw. This CL first assumes that PDFium users will always call FPDF_RenderPageBitmap_Retail and FPDF_FFLDraw to render PDF pages, because otherwise they are not able to support PDF forms. FPDF_RenderPageBitmap_Retail should only deal with non-widget annotations, such as highlight, underline, text, etc. If FPDF_ANNOT flag is passed, non-widget annotations are drawn. Otherwise, they are hidden. FPDF_FFLDraw should only deal with annotations that requires user-interaction, such as widget annotations and popup annotation. Since popup annotation is associated with non-widget annotation, they should not be drawn if the associated annotation is hidden. Thus, if FPDF_ANNOT flag is passed, popup annotations are drawn. Otherwise, they are hidden. Widget annotations should be always drawn regardless of FPDF_ANNOT flag since they need to be always displayed for PDF forms. Also, roll DEPS for testing/corpus to 8485b30. BUG=pdfium:594 Review-Url: https://codereview.chromium.org/2323203002 --- fpdfsdk/cpdfsdk_annothandlermgr.cpp | 6 ++++-- fpdfsdk/cpdfsdk_baannothandler.cpp | 9 ++++++--- fpdfsdk/cpdfsdk_widgethandler.cpp | 3 ++- fpdfsdk/cpdfsdk_xfawidgethandler.cpp | 3 ++- fpdfsdk/fpdfformfill.cpp | 1 + fpdfsdk/fpdfview.cpp | 2 +- fpdfsdk/fsdk_mgr.cpp | 4 +++- fpdfsdk/include/cpdfsdk_annothandlermgr.h | 3 ++- fpdfsdk/include/cpdfsdk_baannothandler.h | 3 ++- fpdfsdk/include/cpdfsdk_widgethandler.h | 3 ++- fpdfsdk/include/cpdfsdk_xfawidgethandler.h | 3 ++- fpdfsdk/include/ipdfsdk_annothandler.h | 3 ++- 12 files changed, 29 insertions(+), 14 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/fpdfsdk/cpdfsdk_annothandlermgr.cpp index 12362e3781..0fd48d2aa0 100644 --- a/fpdfsdk/cpdfsdk_annothandlermgr.cpp +++ b/fpdfsdk/cpdfsdk_annothandlermgr.cpp @@ -93,9 +93,11 @@ IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { + CFX_Matrix* pUser2Device, + bool bDrawAnnots) { ASSERT(pAnnot); - GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, pUser2Device); + GetAnnotHandler(pAnnot)->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, + bDrawAnnots); } FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown( diff --git a/fpdfsdk/cpdfsdk_baannothandler.cpp b/fpdfsdk/cpdfsdk_baannothandler.cpp index 10071045ff..f0d67f4617 100644 --- a/fpdfsdk/cpdfsdk_baannothandler.cpp +++ b/fpdfsdk/cpdfsdk_baannothandler.cpp @@ -62,13 +62,16 @@ void CPDFSDK_BAAnnotHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {} void CPDFSDK_BAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { + CFX_Matrix* pUser2Device, + bool bDrawAnnots) { #ifdef PDF_ENABLE_XFA if (pAnnot->IsXFAField()) return; #endif // PDF_ENABLE_XFA - static_cast(pAnnot)->DrawAppearance( - pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); + if (bDrawAnnots && pAnnot->GetAnnotSubtype() == CPDF_Annot::Subtype::POPUP) { + static_cast(pAnnot)->DrawAppearance( + pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); + } } void CPDFSDK_BAAnnotHandler::OnDelete(CPDFSDK_Annot* pAnnot) {} diff --git a/fpdfsdk/cpdfsdk_widgethandler.cpp b/fpdfsdk/cpdfsdk_widgethandler.cpp index b490daa8ba..8a061e5541 100644 --- a/fpdfsdk/cpdfsdk_widgethandler.cpp +++ b/fpdfsdk/cpdfsdk_widgethandler.cpp @@ -92,7 +92,8 @@ void CPDFSDK_WidgetHandler::DeleteAnnot(CPDFSDK_Annot* pAnnot) {} void CPDFSDK_WidgetHandler::OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { + CFX_Matrix* pUser2Device, + bool bDrawAnnots) { if (pAnnot->IsSignatureWidget()) { static_cast(pAnnot)->DrawAppearance( pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); diff --git a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp index 74220118ce..8621f77dbd 100644 --- a/fpdfsdk/cpdfsdk_xfawidgethandler.cpp +++ b/fpdfsdk/cpdfsdk_xfawidgethandler.cpp @@ -46,7 +46,8 @@ CPDFSDK_Annot* CPDFSDK_XFAWidgetHandler::NewAnnot(CXFA_FFWidget* pAnnot, void CPDFSDK_XFAWidgetHandler::OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) { + CFX_Matrix* pUser2Device, + bool bDrawAnnots) { ASSERT(pPageView); ASSERT(pAnnot); diff --git a/fpdfsdk/fpdfformfill.cpp b/fpdfsdk/fpdfformfill.cpp index 449eac0870..2ac6c60999 100644 --- a/fpdfsdk/fpdfformfill.cpp +++ b/fpdfsdk/fpdfformfill.cpp @@ -114,6 +114,7 @@ void FFLCommon(FPDF_FORMHANDLE hHandle, options.m_BackColor = 0xffffff; } options.m_AddFlags = flags >> 8; + options.m_bDrawAnnots = flags & FPDF_ANNOT; #ifdef PDF_ENABLE_XFA options.m_pOCContext = new CPDF_OCContext(pPDFDoc, CPDF_OCContext::View); diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index 1c0af1dc10..4e20751f5d 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -896,7 +896,7 @@ void FPDF_RenderPage_Retail(CPDF_PageRenderContext* pContext, pContext->m_pAnnots.reset(new CPDF_AnnotList(pPage)); FX_BOOL bPrinting = pContext->m_pDevice->GetDeviceClass() != FXDC_DISPLAY; pContext->m_pAnnots->DisplayAnnots(pPage, pContext->m_pContext.get(), - bPrinting, &matrix, TRUE, nullptr); + bPrinting, &matrix, FALSE, nullptr); } pContext->m_pRenderer.reset(new CPDF_ProgressiveRenderer( diff --git a/fpdfsdk/fsdk_mgr.cpp b/fpdfsdk/fsdk_mgr.cpp index 694e3154ce..c8f387e903 100644 --- a/fpdfsdk/fsdk_mgr.cpp +++ b/fpdfsdk/fsdk_mgr.cpp @@ -12,6 +12,7 @@ #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" +#include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" #include "core/fpdfdoc/include/cpdf_docjsactions.h" #include "core/fpdfdoc/include/cpdf_interform.h" #include "core/fxcrt/include/cfx_retain_ptr.h" @@ -581,7 +582,8 @@ void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CPDFSDK_AnnotIterator annotIterator(this, true); while (CPDFSDK_Annot* pSDKAnnot = annotIterator.Next()) { CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); - pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device); + pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, + pOptions->m_bDrawAnnots); } } diff --git a/fpdfsdk/include/cpdfsdk_annothandlermgr.h b/fpdfsdk/include/cpdfsdk_annothandlermgr.h index 540bd985ac..f4be66a432 100644 --- a/fpdfsdk/include/cpdfsdk_annothandlermgr.h +++ b/fpdfsdk/include/cpdfsdk_annothandlermgr.h @@ -48,7 +48,8 @@ class CPDFSDK_AnnotHandlerMgr { virtual void Annot_OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device); + CFX_Matrix* pUser2Device, + bool bDrawAnnots); virtual void Annot_OnMouseEnter(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, diff --git a/fpdfsdk/include/cpdfsdk_baannothandler.h b/fpdfsdk/include/cpdfsdk_baannothandler.h index 5425b0bf36..ba50df3ccb 100644 --- a/fpdfsdk/include/cpdfsdk_baannothandler.h +++ b/fpdfsdk/include/cpdfsdk_baannothandler.h @@ -44,7 +44,8 @@ class CPDFSDK_BAAnnotHandler : public IPDFSDK_AnnotHandler { void OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) override; + CFX_Matrix* pUser2Device, + bool bDrawAnnots) override; void OnCreate(CPDFSDK_Annot* pAnnot) override; void OnLoad(CPDFSDK_Annot* pAnnot) override; void OnDelete(CPDFSDK_Annot* pAnnot) override; diff --git a/fpdfsdk/include/cpdfsdk_widgethandler.h b/fpdfsdk/include/cpdfsdk_widgethandler.h index b8cb182bf9..d34510d092 100644 --- a/fpdfsdk/include/cpdfsdk_widgethandler.h +++ b/fpdfsdk/include/cpdfsdk_widgethandler.h @@ -44,7 +44,8 @@ class CPDFSDK_WidgetHandler : public IPDFSDK_AnnotHandler { void OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) override; + CFX_Matrix* pUser2Device, + bool bDrawAnnots) override; void OnCreate(CPDFSDK_Annot* pAnnot) override; void OnLoad(CPDFSDK_Annot* pAnnot) override; void OnDelete(CPDFSDK_Annot* pAnnot) override; diff --git a/fpdfsdk/include/cpdfsdk_xfawidgethandler.h b/fpdfsdk/include/cpdfsdk_xfawidgethandler.h index 10eb1eeb87..dec2675ed8 100644 --- a/fpdfsdk/include/cpdfsdk_xfawidgethandler.h +++ b/fpdfsdk/include/cpdfsdk_xfawidgethandler.h @@ -39,7 +39,8 @@ class CPDFSDK_XFAWidgetHandler : public IPDFSDK_AnnotHandler { void OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) override; + CFX_Matrix* pUser2Device, + bool bDrawAnnots) override; void OnCreate(CPDFSDK_Annot* pAnnot) override; void OnLoad(CPDFSDK_Annot* pAnnot) override; void OnDelete(CPDFSDK_Annot* pAnnot) override; diff --git a/fpdfsdk/include/ipdfsdk_annothandler.h b/fpdfsdk/include/ipdfsdk_annothandler.h index 289d48007f..d2f9010b76 100644 --- a/fpdfsdk/include/ipdfsdk_annothandler.h +++ b/fpdfsdk/include/ipdfsdk_annothandler.h @@ -43,7 +43,8 @@ class IPDFSDK_AnnotHandler { virtual void OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, - CFX_Matrix* pUser2Device) = 0; + CFX_Matrix* pUser2Device, + bool bDrawAnnots) = 0; virtual void OnCreate(CPDFSDK_Annot* pAnnot) = 0; virtual void OnLoad(CPDFSDK_Annot* pAnnot) = 0; virtual void OnDelete(CPDFSDK_Annot* pAnnot) = 0; -- cgit v1.2.3