DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, FPDF_FORMHANDLE hHandle, int aaType) { if (!hHandle) return; CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); if (!pPDFPage) return; if (pSDKDoc->GetPageView(pPage, FALSE)) { CPDFDoc_Environment* pEnv = pSDKDoc->GetEnv(); CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; CPDF_AAction aa(pPageDict->GetDictBy("AA")); if (FPDFPAGE_AACTION_OPEN == aaType) { if (aa.ActionExist(CPDF_AAction::OpenPage)) { CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); } } else { if (aa.ActionExist(CPDF_AAction::ClosePage)) { CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); } } } }
DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle) { if (!hHandle) return; CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); if (!pSDKDoc) return; UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); if (!pPage) return; CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE); if (pPageView) { pPageView->SetValid(FALSE); // RemovePageView() takes care of the delete for us. pSDKDoc->RemovePageView(pPage); } }
DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, FPDF_FORMHANDLE hHandle) { if (!hHandle) return; CPDFSDK_FormFillEnvironment* pFormFillEnv = HandleToCPDFSDKEnvironment(hHandle); if (!pFormFillEnv) return; UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); if (!pPage) return; CPDFSDK_PageView* pPageView = pFormFillEnv->GetPageView(pPage, false); if (pPageView) { pPageView->SetValid(false); // RemovePageView() takes care of the delete for us. pFormFillEnv->RemovePageView(pPage); } }
DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, FPDF_FORMHANDLE hHandle, int aaType) { if (!hHandle) return; CPDFSDK_FormFillEnvironment* pFormFillEnv = HandleToCPDFSDKEnvironment(hHandle); if (!pFormFillEnv) return; UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); if (!pPDFPage) return; if (!pFormFillEnv->GetPageView(pPage, false)) return; CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander(); CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict; CPDF_AAction aa(pPageDict->GetDictFor("AA")); if (FPDFPAGE_AACTION_OPEN == aaType) { if (aa.ActionExist(CPDF_AAction::OpenPage)) { CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pFormFillEnv); } } else { if (aa.ActionExist(CPDF_AAction::ClosePage)) { CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pFormFillEnv); } } }
DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, double page_x, double page_y) { if (!hHandle) return -1; CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (pPage) { CPDF_InterForm interform(pPage->m_pDocument, FALSE); CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint(pPage, static_cast<FX_FLOAT>(page_x), static_cast<FX_FLOAT>(page_y), nullptr); if (!pFormCtrl) return -1; CPDF_FormField* pFormField = pFormCtrl->GetField(); return pFormField ? pFormField->GetFieldType() : -1; } #ifdef PDF_ENABLE_XFA CPDFXFA_Page* pXFAPage = UnderlyingFromFPDFPage(page); if (!pXFAPage) return -1; IXFA_PageView* pPageView = pXFAPage->GetXFAPageView(); if (!pPageView) return -1; IXFA_DocView* pDocView = pPageView->GetDocView(); if (!pDocView) return -1; IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); if (!pWidgetHandler) return -1; std::unique_ptr<IXFA_WidgetIterator, ReleaseDeleter<IXFA_WidgetIterator>> pWidgetIterator(pPageView->CreateWidgetIterator( XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Viewable | XFA_WIDGETFILTER_AllType)); if (!pWidgetIterator) return -1; IXFA_Widget* pXFAAnnot = pWidgetIterator->MoveToNext(); while (pXFAAnnot) { CFX_RectF rcBBox; pWidgetHandler->GetBBox(pXFAAnnot, rcBBox, 0); CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, rcBBox.top + rcBBox.height); rcWidget.left -= 1.0f; rcWidget.right += 1.0f; rcWidget.bottom -= 1.0f; rcWidget.top += 1.0f; if (rcWidget.Contains(static_cast<FX_FLOAT>(page_x), static_cast<FX_FLOAT>(page_y))) { return FPDF_FORMFIELD_XFA; } pXFAAnnot = pWidgetIterator->MoveToNext(); } #endif // PDF_ENABLE_XFA return -1; }
DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, int flags) { if (!hHandle) return; UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); if (!pPage) return; #ifndef PDF_ENABLE_XFA CPDF_RenderOptions options; if (flags & FPDF_LCD_TEXT) options.m_Flags |= RENDER_CLEARTYPE; else options.m_Flags &= ~RENDER_CLEARTYPE; // Grayscale output if (flags & FPDF_GRAYSCALE) { options.m_ColorMode = RENDER_COLOR_GRAY; options.m_ForeColor = 0; options.m_BackColor = 0xffffff; } options.m_AddFlags = flags >> 8; options.m_pOCContext = new CPDF_OCContext(pPage->m_pDocument); #else // PDF_ENABLE_XFA CPDFXFA_Document* pDocument = pPage->GetDocument(); if (!pDocument) return; CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); if (!pPDFDoc) return; CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument(); if (!pFXDoc) return; #endif // PDF_ENABLE_XFA CFX_Matrix matrix; pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y); #ifdef _SKIA_SUPPORT_ std::unique_ptr<CFX_SkiaDevice> pDevice(new CFX_SkiaDevice); #else std::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice); #endif pDevice->Attach((CFX_DIBitmap*)bitmap); pDevice->SaveState(); pDevice->SetClip_Rect(clip); #ifndef PDF_ENABLE_XFA if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage)) pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options); #else // PDF_ENABLE_XFA CPDF_RenderOptions options; if (flags & FPDF_LCD_TEXT) options.m_Flags |= RENDER_CLEARTYPE; else options.m_Flags &= ~RENDER_CLEARTYPE; // Grayscale output if (flags & FPDF_GRAYSCALE) { options.m_ColorMode = RENDER_COLOR_GRAY; options.m_ForeColor = 0; options.m_BackColor = 0xffffff; } options.m_AddFlags = flags >> 8; options.m_pOCContext = new CPDF_OCContext(pPDFDoc); if (CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage)) pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); #endif // PDF_ENABLE_XFA pDevice->RestoreState(); delete options.m_pOCContext; #ifdef PDF_ENABLE_XFA options.m_pOCContext = NULL; #endif // PDF_ENABLE_XFA }