void CPDFSDK_WidgetHandler::OnLoad(CPDFSDK_Annot* pAnnot) { if (pAnnot->IsSignatureWidget()) return; CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot); if (!pWidget->IsAppearanceValid()) pWidget->ResetAppearance(nullptr, FALSE); int nFieldType = pWidget->GetFieldType(); if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) { FX_BOOL bFormatted = FALSE; CFX_WideString sValue = pWidget->OnFormat(bFormatted); if (bFormatted && nFieldType == FIELDTYPE_COMBOBOX) pWidget->ResetAppearance(&sValue, FALSE); } #ifdef PDF_ENABLE_XFA CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) pWidget->ResetAppearance(FALSE); } #endif // PDF_ENABLE_XFA if (m_pFormFiller) m_pFormFiller->OnLoad(pAnnot); }
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); }
DLLEXPORT void STDCALL FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, float x, float y, FPDF_STRINGHANDLE* stringHandle) { if (NULL == hWidget || NULL == document) return; CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) return; IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); if (pXFAMenuHander == NULL) return; CFX_ByteStringArray* sSuggestWords = new CFX_ByteStringArray; CFX_PointF ptPopup; ptPopup.x = x; ptPopup.y = y; pXFAMenuHander->GetSuggestWords((IXFA_Widget*)hWidget, ptPopup, *sSuggestWords); *stringHandle = (FPDF_STRINGHANDLE)sSuggestWords; }
void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) { if (pAnnot->GetSubType() == BFFT_SIGNATURE) return; CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; if (!pWidget->IsAppearanceValid()) pWidget->ResetAppearance(NULL, FALSE); int nFieldType = pWidget->GetFieldType(); if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) { FX_BOOL bFormated = FALSE; CFX_WideString sValue = pWidget->OnFormat(bFormated); if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) { pWidget->ResetAppearance(sValue.c_str(), FALSE); } } #ifdef PDF_ENABLE_XFA CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) pWidget->ResetAppearance(FALSE); } #endif // PDF_ENABLE_XFA if (m_pFormFiller) m_pFormFiller->OnLoad(pAnnot); }
DLLEXPORT void STDCALL FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, float x, float y, FPDF_BYTESTRING bsText) { if (NULL == hWidget || NULL == document) return; CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) return; IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); if (pXFAMenuHander == NULL) return; CFX_PointF ptPopup; ptPopup.x = x; ptPopup.y = y; CFX_ByteStringC bs(bsText); pXFAMenuHander->ReplaceSpellCheckWord((IXFA_Widget*)hWidget, ptPopup, bs); }
DLLEXPORT void STDCALL FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, float x, float y, FPDF_STRINGHANDLE* stringHandle) { if (!hWidget || !document) return; CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) return; IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); if (!pXFAMenuHander) return; std::vector<CFX_ByteString>* sSuggestWords = new std::vector<CFX_ByteString>; CFX_PointF ptPopup; ptPopup.x = x; ptPopup.y = y; pXFAMenuHander->GetSuggestWords(reinterpret_cast<IXFA_Widget*>(hWidget), ptPopup, *sSuggestWords); *stringHandle = ToFPDFStringHandle(sSuggestWords); }
DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, FPDF_WIDESTRING wsText, FPDF_DWORD* size) { if (NULL == hWidget || NULL == document) return; CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) return; IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); if (pXFAMenuHander == NULL) return; CFX_WideString wsCpText; pXFAMenuHander->Cut((IXFA_Widget*)hWidget, wsCpText); CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode(); int len = bsCpText.GetLength() / sizeof(unsigned short); if (wsText == NULL) { *size = len; return; } int real_size = len < *size ? len : *size; if (real_size > 0) { FXSYS_memcpy((void*)wsText, bsCpText.GetBuffer(real_size * sizeof(unsigned short)), real_size * sizeof(unsigned short)); bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short)); } *size = real_size; }
DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, FPDF_WIDESTRING wsText, FPDF_DWORD* size) { if (!hWidget || !document) return; CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) return; CFX_WideString wsCpText; static_cast<CXFA_FFWidget*>(hWidget)->Cut(wsCpText); CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode(); uint32_t len = bsCpText.GetLength() / sizeof(unsigned short); if (!wsText) { *size = len; return; } uint32_t real_size = len < *size ? len : *size; if (real_size > 0) { FXSYS_memcpy((void*)wsText, bsCpText.GetBuffer(real_size * sizeof(unsigned short)), real_size * sizeof(unsigned short)); bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short)); } *size = real_size; }
FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot, const CFX_FloatPoint& point) { if (!pPageView || !pAnnot) return FALSE; CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); if (!pSDKDoc) return FALSE; CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); if (!pDoc) return FALSE; CXFA_FFDocView* pDocView = pDoc->GetXFADocView(); if (!pDocView) return FALSE; CXFA_FFWidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); if (!pWidgetHandler) return FALSE; FWL_WidgetHit dwHitTest = pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y); return dwHitTest != FWL_WidgetHit::Unknown; }
DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document, FPDF_WIDGET hWidget) { if (!hWidget || !document) return; CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) return; static_cast<CXFA_FFWidget*>(hWidget)->SelectAll(); }
DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, FPDF_WIDESTRING wsText, FPDF_DWORD size) { if (!hWidget || !document) return; CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) return; CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size); static_cast<CXFA_FFWidget*>(hWidget)->Paste(wstr); }
DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document, FPDF_WIDGET hWidget) { if (NULL == hWidget || NULL == document) return; CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) return; IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); if (pXFAMenuHander == NULL) return; pXFAMenuHander->SelectAll((IXFA_Widget*)hWidget); }
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; }
DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, FPDF_WIDESTRING wsText, FPDF_DWORD size) { if (NULL == hWidget || NULL == document) return; CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) return; IXFA_MenuHandler* pXFAMenuHander = CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); if (pXFAMenuHander == NULL) return; CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size); pXFAMenuHander->Paste((IXFA_Widget*)hWidget, wstr); }
DLLEXPORT void STDCALL FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, float x, float y, FPDF_BYTESTRING bsText) { if (!hWidget || !document) return; CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) return; CFX_PointF ptPopup; ptPopup.x = x; ptPopup.y = y; CFX_ByteStringC bs(bsText); static_cast<CXFA_FFWidget*>(hWidget)->ReplaceSpellCheckWord(ptPopup, bs); }
DLLEXPORT void STDCALL FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, float x, float y, FPDF_STRINGHANDLE* stringHandle) { if (!hWidget || !document) return; CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static) return; std::vector<CFX_ByteString>* sSuggestWords = new std::vector<CFX_ByteString>; CFX_PointF ptPopup; ptPopup.x = x; ptPopup.y = y; static_cast<CXFA_FFWidget*>(hWidget) ->GetSuggestWords(ptPopup, *sSuggestWords); *stringHandle = ToFPDFStringHandle(sSuggestWords); }
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(); }
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 }