Chromium Code Reviews| Index: fpdfsdk/src/fpdfformfill.cpp |
| diff --git a/fpdfsdk/src/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp |
| index 5dcfb4789022b04e261597ececacde1032894926..a6811ef408c0e0ee6d047940604bb791176f4a17 100644 |
| --- a/fpdfsdk/src/fpdfformfill.cpp |
| +++ b/fpdfsdk/src/fpdfformfill.cpp |
| @@ -6,9 +6,11 @@ |
| #include "public/fpdf_formfill.h" |
| +#ifdef PDF_ENABLE_XFA |
| #include "../include/fpdfxfa/fpdfxfa_app.h" |
| #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| #include "../include/fpdfxfa/fpdfxfa_page.h" |
| +#endif |
| #include "fpdfsdk/include/fsdk_define.h" |
| #include "fpdfsdk/include/fsdk_mgr.h" |
| #include "public/fpdfview.h" |
| @@ -45,6 +47,15 @@ DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
| if (!hHandle) |
| return -1; |
| CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| +#ifndef PDF_ENABLE_XFA |
| + if (!pPage) |
| + return -1; |
| + CPDF_InterForm interform(pPage->m_pDocument, FALSE); |
| + CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( |
| + pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr); |
| + if (!pFormCtrl) |
| + return -1; |
| +#else |
| if (pPage) { |
| CPDF_InterForm interform(pPage->m_pDocument, FALSE); |
| CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( |
| @@ -99,8 +110,14 @@ DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
| pWidgetIterator->Release(); |
| } |
| +#endif |
| +#ifndef PDF_ENABLE_XFA |
| + CPDF_FormField* pFormField = pFormCtrl->GetField(); |
| + return pFormField ? pFormField->GetFieldType() : -1; |
| +#else |
| return -1; |
| +#endif |
| } |
| DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
| @@ -129,7 +146,11 @@ DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, |
| DLLEXPORT FPDF_FORMHANDLE STDCALL |
| FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, |
| FPDF_FORMFILLINFO* formInfo) { |
| +#ifndef PDF_ENABLE_XFA |
| + const int kRequiredVersion = 1; |
| +#else |
| const int kRequiredVersion = 2; |
| +#endif |
| if (!formInfo || formInfo->version != kRequiredVersion) |
| return nullptr; |
| @@ -138,10 +159,14 @@ FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, |
| return nullptr; |
| CPDFDoc_Environment* pEnv = new CPDFDoc_Environment(pDocument, formInfo); |
| +#ifndef PDF_ENABLE_XFA |
| + pEnv->SetSDKDocument(new CPDFSDK_Document(pDocument, pEnv)); |
| +#else |
| pEnv->SetSDKDocument(pDocument->GetSDKDocument(pEnv)); |
| CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); |
| pApp->AddFormFillEnv(pEnv); |
| +#endif |
| return pEnv; |
| } |
| @@ -149,9 +174,19 @@ DLLEXPORT void STDCALL |
| FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { |
| if (!hHandle) |
| return; |
| +#ifndef PDF_ENABLE_XFA |
| + |
| + CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; |
| + if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { |
| + pEnv->SetSDKDocument(NULL); |
| + delete pSDKDoc; |
| + } |
| + delete pEnv; |
| +#else |
| CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); |
| pApp->RemoveFormFillEnv((CPDFDoc_Environment*)hHandle); |
| delete (CPDFDoc_Environment*)hHandle; |
| +#endif |
| } |
| DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, |
| @@ -193,6 +228,7 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, |
| return pPageView->OnLButtonUp(pt, modifier); |
| } |
| +#ifdef PDF_ENABLE_XFA |
| DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle, |
| FPDF_PAGE page, |
| int modifier, |
| @@ -219,6 +255,7 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle, |
| return pPageView->OnRButtonUp(pt, modifier); |
| } |
| +#endif |
| DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, |
| FPDF_PAGE page, |
| int nKeyCode, |
| @@ -269,21 +306,48 @@ DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, |
| int size_y, |
| int rotate, |
| int flags) { |
| +#ifndef PDF_ENABLE_XFA |
| + if (!hHandle) |
| +#else |
| if (!hHandle || !page) |
|
Lei Zhang
2015/11/25 00:12:02
Needs more merging here.
|
| +#endif |
| return; |
| +#ifndef PDF_ENABLE_XFA |
| + CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| + if (!pPage) |
| +#else |
| CPDFXFA_Page* pPage = (CPDFXFA_Page*)page; |
| CPDFXFA_Document* pDocument = pPage->GetDocument(); |
| if (!pDocument) |
| return; |
| CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); |
| if (!pPDFDoc) |
| +#endif |
| 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 |
| CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; |
| CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument(); |
| if (!pFXDoc) |
| return; |
| +#endif |
| CFX_AffineMatrix matrix; |
| pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); |
| @@ -299,13 +363,19 @@ DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, |
| #else |
| nonstd::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice); |
| #endif |
| +#ifdef PDF_ENABLE_XFA |
| if (!pDevice) |
| return; |
| +#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 |
| CPDF_RenderOptions options; |
| if (flags & FPDF_LCD_TEXT) |
| options.m_Flags |= RENDER_CLEARTYPE; |
| @@ -323,9 +393,11 @@ DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, |
| if (CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDFXFA_Page*)page)) |
| pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); |
| +#endif |
| pDevice->RestoreState(); |
| delete options.m_pOCContext; |
| +#ifdef PDF_ENABLE_XFA |
| options.m_pOCContext = NULL; |
| } |
| DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document, |
| @@ -576,6 +648,7 @@ FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle, |
| stringArr->Add(bsStr); |
| return TRUE; |
| +#endif |
| } |
| DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, |