FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point) { if (!pPageView || !pAnnot) return FALSE; CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); if (!pSDKDoc) return FALSE; CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); if (!pDoc) return FALSE; IXFA_DocView* pDocView = pDoc->GetXFADocView(); if (!pDocView) return FALSE; IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); if (!pWidgetHandler) return FALSE; FX_DWORD dwHitTest = pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y); return (dwHitTest != FWL_WGTHITTEST_Unknown); }
FX_BOOL _SendPostSaveToXFADoc(CPDFXFA_Document* pDocument) { if (!pDocument) return FALSE; if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && pDocument->GetDocType() != DOCTYPE_STATIC_XFA) return TRUE; IXFA_DocView* pXFADocView = pDocument->GetXFADocView(); if (NULL == pXFADocView) return FALSE; IXFA_WidgetHandler* pWidgetHander = pXFADocView->GetWidgetHandler(); CXFA_WidgetAcc* pWidgetAcc = NULL; IXFA_WidgetAccIterator* pWidgetAccIterator = pXFADocView->CreateWidgetAccIterator(); pWidgetAcc = pWidgetAccIterator->MoveToNext(); while (pWidgetAcc) { CXFA_EventParam preParam; preParam.m_eType = XFA_EVENT_PostSave; pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); pWidgetAcc = pWidgetAccIterator->MoveToNext(); } pWidgetAccIterator->Release(); pXFADocView->UpdateDocView(); pDocument->_ClearChangeMark(); return TRUE; }
IXFA_WidgetHandler* CPDFSDK_XFAAnnotHandler::GetXFAWidgetHandler( CPDFSDK_Annot* pAnnot) { if (!pAnnot) return NULL; CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); if (!pPageView) return NULL; CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); if (!pSDKDoc) return NULL; CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); if (!pDoc) return NULL; IXFA_DocView* pDocView = pDoc->GetXFADocView(); if (!pDocView) return NULL; return pDocView->GetWidgetHandler(); }
FX_BOOL _SendPreSaveToXFADoc(CPDFXFA_Document* pDocument, CFX_PtrArray& fileList) { if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && pDocument->GetDocType() != DOCTYPE_STATIC_XFA) return TRUE; IXFA_DocView* pXFADocView = pDocument->GetXFADocView(); if (NULL == pXFADocView) return TRUE; IXFA_WidgetHandler* pWidgetHander = pXFADocView->GetWidgetHandler(); CXFA_WidgetAcc* pWidgetAcc = NULL; IXFA_WidgetAccIterator* pWidgetAccIterator = pXFADocView->CreateWidgetAccIterator(); pWidgetAcc = pWidgetAccIterator->MoveToNext(); while (pWidgetAcc) { CXFA_EventParam preParam; preParam.m_eType = XFA_EVENT_PreSave; pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); pWidgetAcc = pWidgetAccIterator->MoveToNext(); } pWidgetAccIterator->Release(); pXFADocView->UpdateDocView(); return _SaveXFADocumentData(pDocument, fileList); }
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; }
FX_BOOL _SaveXFADocumentData(CPDFXFA_Document* pDocument, CFX_PtrArray& fileList) { if (!pDocument) return FALSE; if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && pDocument->GetDocType() != DOCTYPE_STATIC_XFA) return TRUE; if (!CPDFXFA_App::GetInstance()->GetXFAApp()) return TRUE; IXFA_DocView* pXFADocView = pDocument->GetXFADocView(); if (NULL == pXFADocView) return TRUE; IXFA_DocHandler* pXFADocHandler = CPDFXFA_App::GetInstance()->GetXFAApp()->GetDocHandler(); CPDF_Document* pPDFDocument = pDocument->GetPDFDoc(); if (pDocument == NULL) return FALSE; CPDF_Dictionary* pRoot = pPDFDocument->GetRoot(); if (pRoot == NULL) return FALSE; CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm"); if (NULL == pAcroForm) return FALSE; CPDF_Object* pXFA = pAcroForm->GetElement("XFA"); if (pXFA == NULL) return TRUE; if (pXFA->GetType() != PDFOBJ_ARRAY) return FALSE; CPDF_Array* pArray = pXFA->GetArray(); if (NULL == pArray) return FALSE; int size = pArray->GetCount(); int iFormIndex = -1; int iDataSetsIndex = -1; int iTemplate = -1; int iLast = size - 2; for (int i = 0; i < size - 1; i++) { CPDF_Object* pPDFObj = pArray->GetElement(i); if (pPDFObj->GetType() != PDFOBJ_STRING) continue; if (pPDFObj->GetString() == "form") iFormIndex = i + 1; else if (pPDFObj->GetString() == "datasets") iDataSetsIndex = i + 1; else if (pPDFObj->GetString() == "template") iTemplate = i + 1; } IXFA_ChecksumContext* pContext = NULL; // Checksum pContext = XFA_Checksum_Create(); FXSYS_assert(pContext); pContext->StartChecksum(); // template if (iTemplate > -1) { CPDF_Stream* pTemplateStream = pArray->GetStream(iTemplate); CPDF_StreamAcc streamAcc; streamAcc.LoadAllData(pTemplateStream); uint8_t* pData = (uint8_t*)streamAcc.GetData(); FX_DWORD dwSize2 = streamAcc.GetSize(); IFX_FileStream* pTemplate = FX_CreateMemoryStream(pData, dwSize2); pContext->UpdateChecksum((IFX_FileRead*)pTemplate); pTemplate->Release(); } CPDF_Stream* pFormStream = NULL; CPDF_Stream* pDataSetsStream = NULL; if (iFormIndex != -1) { // Get form CPDF_Stream CPDF_Object* pFormPDFObj = pArray->GetElement(iFormIndex); if (pFormPDFObj->GetType() == PDFOBJ_REFERENCE) { CPDF_Object* pFormDircetObj = pFormPDFObj->GetDirect(); if (NULL != pFormDircetObj && pFormDircetObj->GetType() == PDFOBJ_STREAM) { pFormStream = (CPDF_Stream*)pFormDircetObj; } } else if (pFormPDFObj->GetType() == PDFOBJ_STREAM) { pFormStream = (CPDF_Stream*)pFormPDFObj; } } if (iDataSetsIndex != -1) { // Get datasets CPDF_Stream CPDF_Object* pDataSetsPDFObj = pArray->GetElement(iDataSetsIndex); if (pDataSetsPDFObj->GetType() == PDFOBJ_REFERENCE) { CPDF_Reference* pDataSetsRefObj = (CPDF_Reference*)pDataSetsPDFObj; CPDF_Object* pDataSetsDircetObj = pDataSetsRefObj->GetDirect(); if (NULL != pDataSetsDircetObj && pDataSetsDircetObj->GetType() == PDFOBJ_STREAM) { pDataSetsStream = (CPDF_Stream*)pDataSetsDircetObj; } } else if (pDataSetsPDFObj->GetType() == PDFOBJ_STREAM) { pDataSetsStream = (CPDF_Stream*)pDataSetsPDFObj; } } // end // L"datasets" { IFX_FileStream* pDsfileWrite = FX_CreateMemoryStream(); if (NULL == pDsfileWrite) { pContext->Release(); pDsfileWrite->Release(); return FALSE; } if (pXFADocHandler->SavePackage(pXFADocView->GetDoc(), CFX_WideStringC(L"datasets"), pDsfileWrite) && pDsfileWrite->GetSize() > 0) { // Datasets pContext->UpdateChecksum((IFX_FileRead*)pDsfileWrite); pContext->FinishChecksum(); CPDF_Dictionary* pDataDict = new CPDF_Dictionary; if (iDataSetsIndex != -1) { if (pDataSetsStream) pDataSetsStream->InitStreamFromFile(pDsfileWrite, pDataDict); } else { CPDF_Stream* pData = new CPDF_Stream(NULL, 0, NULL); pData->InitStreamFromFile(pDsfileWrite, pDataDict); pPDFDocument->AddIndirectObject(pData); iLast = pArray->GetCount() - 2; pArray->InsertAt(iLast, new CPDF_String("datasets", FALSE)); pArray->InsertAt(iLast + 1, pData, pPDFDocument); } fileList.Add(pDsfileWrite); } } // L"form" { IFX_FileStream* pfileWrite = FX_CreateMemoryStream(); if (NULL == pfileWrite) { pContext->Release(); return FALSE; } if (pXFADocHandler->SavePackage(pXFADocView->GetDoc(), CFX_WideStringC(L"form"), pfileWrite, pContext) && pfileWrite > 0) { CPDF_Dictionary* pDataDict = new CPDF_Dictionary; if (iFormIndex != -1) { if (pFormStream) pFormStream->InitStreamFromFile(pfileWrite, pDataDict); } else { CPDF_Stream* pData = new CPDF_Stream(NULL, 0, NULL); pData->InitStreamFromFile(pfileWrite, pDataDict); pPDFDocument->AddIndirectObject(pData); iLast = pArray->GetCount() - 2; pArray->InsertAt(iLast, new CPDF_String("form", FALSE)); pArray->InsertAt(iLast + 1, pData, pPDFDocument); } fileList.Add(pfileWrite); } } pContext->Release(); return TRUE; }