DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, int page_index, double width, double height) { CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); if (!pDoc) return nullptr; page_index = std::min(std::max(page_index, 0), pDoc->GetPageCount()); CPDF_Dictionary* pPageDict = pDoc->CreateNewPage(page_index); if (!pPageDict) return nullptr; CPDF_Array* pMediaBoxArray = new CPDF_Array; pMediaBoxArray->Add(new CPDF_Number(0)); pMediaBoxArray->Add(new CPDF_Number(0)); pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(width))); pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(height))); pPageDict->SetAt("MediaBox", pMediaBoxArray); pPageDict->SetAt("Rotate", new CPDF_Number(0)); pPageDict->SetAt("Resources", new CPDF_Dictionary); #ifdef PDF_ENABLE_XFA CPDFXFA_Page* pPage = new CPDFXFA_Page((CPDFXFA_Document*)document, page_index); pPage->LoadPDFPage(pPageDict); #else // PDF_ENABLE_XFA CPDF_Page* pPage = new CPDF_Page(pDoc, pPageDict, true); pPage->ParseContent(); #endif // PDF_ENABLE_XFA return pPage; }
CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, bool bNext) { #ifdef PDF_ENABLE_XFA CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage(); if (pPage && !pPage->AsPDFPage()) { // For xfa annots in XFA pages not backed by PDF pages. std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator( pPage->GetXFAPageView()->CreateWidgetIterator( XFA_TRAVERSEWAY_Tranvalse, XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable | XFA_WidgetStatus_Focused)); if (!pWidgetIterator) return nullptr; if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget()) pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget()); CXFA_FFWidget* hNextFocus = bNext ? pWidgetIterator->MoveToNext() : pWidgetIterator->MoveToPrevious(); if (!hNextFocus && pSDKAnnot) hNextFocus = pWidgetIterator->MoveToFirst(); return pPageView->GetAnnotByXFAWidget(hNextFocus); } #endif // PDF_ENABLE_XFA // For PDF annots. CPDFSDK_Widget* pWidget = ToCPDFSDKWidget(pSDKAnnot); CPDFSDK_AnnotIterator ai(pWidget->GetPageView(), pWidget->GetAnnotSubtype()); return bNext ? ai.GetNextAnnot(pWidget) : ai.GetPrevAnnot(pWidget); }
CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, FX_BOOL bNext) { #ifdef PDF_ENABLE_XFA CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage(); if (!pPage) return nullptr; if (pPage->GetPDFPage()) { // for pdf annots. CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), pSDKAnnot->GetType(), ""); CPDFSDK_Annot* pNext = bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot); return pNext; } // for xfa annots std::unique_ptr<IXFA_WidgetIterator> pWidgetIterator( pPage->GetXFAPageView()->CreateWidgetIterator( XFA_TRAVERSEWAY_Tranvalse, XFA_WidgetStatus_Visible | XFA_WidgetStatus_Viewable | XFA_WidgetStatus_Focused)); if (!pWidgetIterator) return nullptr; if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget()) pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget()); CXFA_FFWidget* hNextFocus = bNext ? pWidgetIterator->MoveToNext() : pWidgetIterator->MoveToPrevious(); if (!hNextFocus && pSDKAnnot) hNextFocus = pWidgetIterator->MoveToFirst(); return pPageView->GetAnnotByXFAWidget(hNextFocus); #else // PDF_ENABLE_XFA CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", ""); return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot); #endif // PDF_ENABLE_XFA }
DLLEXPORT FPDF_TEXTPAGE STDCALL FPDFText_LoadPage(FPDF_PAGE page) { CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); if (!pPDFPage) return nullptr; #ifdef PDF_ENABLE_XFA CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; CPDFXFA_Document* pDoc = pPage->GetDocument(); CPDF_ViewerPreferences viewRef(pDoc->GetPDFDoc()); #else // PDF_ENABLE_XFA CPDF_ViewerPreferences viewRef(pPDFPage->m_pDocument); #endif // PDF_ENABLE_XFA CPDF_TextPage* textpage = new CPDF_TextPage( pPDFPage, viewRef.IsDirectionR2L() ? FPDFText_Direction::Right : FPDFText_Direction::Left); textpage->ParseTextPage(); return textpage; }
void CPDFXFA_DocEnvironment::PageViewEvent(CXFA_FFPageView* pPageView, uint32_t dwFlags) { CPDFSDK_FormFillEnvironment* pFormFillEnv = m_pContext->GetFormFillEnv(); if (!pFormFillEnv) return; if (m_pContext->GetLoadStatus() == FXFA_LOADSTATUS_LOADING || m_pContext->GetLoadStatus() == FXFA_LOADSTATUS_CLOSING || XFA_PAGEVIEWEVENT_StopLayout != dwFlags) return; int nNewCount = m_pContext->GetPageCount(); if (nNewCount == m_pContext->GetOriginalPageCount()) return; CXFA_FFDocView* pXFADocView = m_pContext->GetXFADocView(); if (!pXFADocView) return; for (int iPageIter = 0; iPageIter < m_pContext->GetOriginalPageCount(); iPageIter++) { CPDFXFA_Page* pPage = (*m_pContext->GetXFAPageList())[iPageIter]; if (!pPage) continue; m_pContext->GetFormFillEnv()->RemovePageView(pPage); pPage->SetXFAPageView(pXFADocView->GetPageView(iPageIter)); } int flag = (nNewCount < m_pContext->GetOriginalPageCount()) ? FXFA_PAGEVIEWEVENT_POSTREMOVED : FXFA_PAGEVIEWEVENT_POSTADDED; int count = FXSYS_abs(nNewCount - m_pContext->GetOriginalPageCount()); m_pContext->SetOriginalPageCount(nNewCount); pFormFillEnv->PageEvent(count, flag); }
CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, FX_BOOL bNext) { #ifdef PDF_ENABLE_XFA CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage(); if (pPage == NULL) return NULL; if (pPage->GetPDFPage()) { // for pdf annots. CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), pSDKAnnot->GetType(), ""); CPDFSDK_Annot* pNext = bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot); return pNext; } // for xfa annots IXFA_WidgetIterator* pWidgetIterator = pPage->GetXFAPageView()->CreateWidgetIterator( XFA_TRAVERSEWAY_Tranvalse, XFA_WIDGETFILTER_Visible | XFA_WIDGETFILTER_Viewable | XFA_WIDGETFILTER_Field); if (pWidgetIterator == NULL) return NULL; if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget()) pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget()); IXFA_Widget* hNextFocus = NULL; hNextFocus = bNext ? pWidgetIterator->MoveToNext() : pWidgetIterator->MoveToPrevious(); if (hNextFocus == NULL && pSDKAnnot != NULL) hNextFocus = pWidgetIterator->MoveToFirst(); pWidgetIterator->Release(); return pPageView->GetAnnotByXFAWidget(hNextFocus); #else // PDF_ENABLE_XFA CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", ""); return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot); #endif // PDF_ENABLE_XFA }
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; }