| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../public/fpdf_formfill.h" | 7 #include "../../public/fpdf_formfill.h" |
| 8 #include "../../public/fpdfview.h" | 8 #include "../../public/fpdfview.h" |
| 9 #include "../../third_party/base/nonstd_unique_ptr.h" | 9 #include "../../third_party/base/nonstd_unique_ptr.h" |
| 10 #include "../include/fsdk_define.h" | 10 #include "../include/fsdk_define.h" |
| 11 #include "../include/fsdk_mgr.h" | 11 #include "../include/fsdk_mgr.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 CPDFSDK_Document* FormHandleToSDKDoc(FPDF_FORMHANDLE hHandle) { | 15 CPDFSDK_Document* FormHandleToSDKDoc(FPDF_FORMHANDLE hHandle) { |
| 16 CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; | 16 CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; |
| 17 return pEnv ? pEnv->GetSDKDocument() : nullptr; | 17 return pEnv ? pEnv->GetSDKDocument() : nullptr; |
| 18 } | 18 } |
| 19 | 19 |
| 20 CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { | 20 CPDFSDK_InterForm* FormHandleToInterForm(FPDF_FORMHANDLE hHandle) { |
| 21 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); | 21 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); |
| 22 return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr; | 22 return pSDKDoc ? pSDKDoc->GetInterForm() : nullptr; |
| 23 } | 23 } |
| 24 | 24 |
| 25 CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, | 25 CPDFSDK_PageView* FormHandleToPageView(FPDF_FORMHANDLE hHandle, |
| 26 FPDF_PAGE page) { | 26 FPDF_PAGE page) { |
| 27 if (!page) | 27 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 28 if (!pPage) |
| 28 return nullptr; | 29 return nullptr; |
| 29 | 30 |
| 30 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); | 31 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); |
| 31 return pSDKDoc ? pSDKDoc->GetPageView((CPDF_Page*)page, TRUE) : nullptr; | 32 return pSDKDoc ? pSDKDoc->GetPageView(pPage, TRUE) : nullptr; |
| 32 } | 33 } |
| 33 | 34 |
| 34 } // namespace | 35 } // namespace |
| 35 | 36 |
| 36 DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, | 37 DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
| 37 FPDF_PAGE page, | 38 FPDF_PAGE page, |
| 38 double page_x, | 39 double page_x, |
| 39 double page_y) { | 40 double page_y) { |
| 40 if (!page || !hHandle) | 41 if (!hHandle) |
| 41 return -1; | 42 return -1; |
| 42 | 43 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 43 CPDF_Page* pPage = (CPDF_Page*)page; | 44 if (!pPage) |
| 45 return -1; |
| 44 CPDF_InterForm interform(pPage->m_pDocument, FALSE); | 46 CPDF_InterForm interform(pPage->m_pDocument, FALSE); |
| 45 CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( | 47 CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( |
| 46 pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr); | 48 pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr); |
| 47 if (!pFormCtrl) | 49 if (!pFormCtrl) |
| 48 return -1; | 50 return -1; |
| 49 | 51 |
| 50 CPDF_FormField* pFormField = pFormCtrl->GetField(); | 52 CPDF_FormField* pFormField = pFormCtrl->GetField(); |
| 51 if (!pFormField) | 53 return pFormField ? pFormField->GetFieldType() : -1; |
| 52 return -1; | |
| 53 | |
| 54 return pFormField->GetFieldType(); | |
| 55 } | 54 } |
| 56 | 55 |
| 57 DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, | 56 DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
| 58 FPDF_PAGE page, | 57 FPDF_PAGE page, |
| 59 double page_x, | 58 double page_x, |
| 60 double page_y) { | 59 double page_y) { |
| 61 return FPDFPage_HasFormFieldAtPoint(hHandle, page, page_x, page_y); | 60 return FPDFPage_HasFormFieldAtPoint(hHandle, page, page_x, page_y); |
| 62 } | 61 } |
| 63 | 62 |
| 64 DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, | 63 DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, |
| 65 FPDF_PAGE page, | 64 FPDF_PAGE page, |
| 66 double page_x, | 65 double page_x, |
| 67 double page_y) { | 66 double page_y) { |
| 68 if (!page || !hHandle) | 67 if (!hHandle) |
| 69 return -1; | 68 return -1; |
| 70 | 69 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 71 CPDF_Page* pPage = (CPDF_Page*)page; | 70 if (!pPage) |
| 71 return -1; |
| 72 CPDF_InterForm interform(pPage->m_pDocument, FALSE); | 72 CPDF_InterForm interform(pPage->m_pDocument, FALSE); |
| 73 int z_order = -1; | 73 int z_order = -1; |
| 74 (void)interform.GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, | 74 (void)interform.GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, |
| 75 &z_order); | 75 &z_order); |
| 76 return z_order; | 76 return z_order; |
| 77 } | 77 } |
| 78 | 78 |
| 79 DLLEXPORT FPDF_FORMHANDLE STDCALL | 79 DLLEXPORT FPDF_FORMHANDLE STDCALL |
| 80 FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, | 80 FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, |
| 81 FPDF_FORMFILLINFO* formInfo) { | 81 FPDF_FORMFILLINFO* formInfo) { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 185 |
| 186 DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, | 186 DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, |
| 187 FPDF_BITMAP bitmap, | 187 FPDF_BITMAP bitmap, |
| 188 FPDF_PAGE page, | 188 FPDF_PAGE page, |
| 189 int start_x, | 189 int start_x, |
| 190 int start_y, | 190 int start_y, |
| 191 int size_x, | 191 int size_x, |
| 192 int size_y, | 192 int size_y, |
| 193 int rotate, | 193 int rotate, |
| 194 int flags) { | 194 int flags) { |
| 195 if (!hHandle || !page) | 195 if (!hHandle) |
| 196 return; | 196 return; |
| 197 | 197 |
| 198 CPDF_Page* pPage = (CPDF_Page*)page; | 198 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 199 if (!pPage) |
| 200 return; |
| 201 |
| 199 CPDF_RenderOptions options; | 202 CPDF_RenderOptions options; |
| 200 if (flags & FPDF_LCD_TEXT) | 203 if (flags & FPDF_LCD_TEXT) |
| 201 options.m_Flags |= RENDER_CLEARTYPE; | 204 options.m_Flags |= RENDER_CLEARTYPE; |
| 202 else | 205 else |
| 203 options.m_Flags &= ~RENDER_CLEARTYPE; | 206 options.m_Flags &= ~RENDER_CLEARTYPE; |
| 204 | 207 |
| 205 // Grayscale output | 208 // Grayscale output |
| 206 if (flags & FPDF_GRAYSCALE) { | 209 if (flags & FPDF_GRAYSCALE) { |
| 207 options.m_ColorMode = RENDER_COLOR_GRAY; | 210 options.m_ColorMode = RENDER_COLOR_GRAY; |
| 208 options.m_ForeColor = 0; | 211 options.m_ForeColor = 0; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 259 } |
| 257 | 260 |
| 258 DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, | 261 DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, |
| 259 FPDF_FORMHANDLE hHandle) { | 262 FPDF_FORMHANDLE hHandle) { |
| 260 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) | 263 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page)) |
| 261 pPageView->SetValid(TRUE); | 264 pPageView->SetValid(TRUE); |
| 262 } | 265 } |
| 263 | 266 |
| 264 DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, | 267 DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, |
| 265 FPDF_FORMHANDLE hHandle) { | 268 FPDF_FORMHANDLE hHandle) { |
| 266 if (!hHandle || !page) | 269 if (!hHandle) |
| 267 return; | 270 return; |
| 268 | 271 |
| 269 CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); | 272 CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); |
| 270 if (!pSDKDoc) | 273 if (!pSDKDoc) |
| 271 return; | 274 return; |
| 272 | 275 |
| 273 CPDF_Page* pPage = (CPDF_Page*)page; | 276 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 277 if (!pPage) |
| 278 return; |
| 279 |
| 274 CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE); | 280 CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE); |
| 275 if (pPageView) { | 281 if (pPageView) { |
| 276 pPageView->SetValid(FALSE); | 282 pPageView->SetValid(FALSE); |
| 277 // ReMovePageView() takes care of the delete for us. | 283 // ReMovePageView() takes care of the delete for us. |
| 278 pSDKDoc->ReMovePageView(pPage); | 284 pSDKDoc->ReMovePageView(pPage); |
| 279 } | 285 } |
| 280 } | 286 } |
| 281 | 287 |
| 282 DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { | 288 DLLEXPORT void STDCALL FORM_DoDocumentJSAction(FPDF_FORMHANDLE hHandle) { |
| 283 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); | 289 CPDFSDK_Document* pSDKDoc = FormHandleToSDKDoc(hHandle); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 309 ((CPDFDoc_Environment*)hHandle)->GetActionHander(); | 315 ((CPDFDoc_Environment*)hHandle)->GetActionHander(); |
| 310 ASSERT(pActionHandler != NULL); | 316 ASSERT(pActionHandler != NULL); |
| 311 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, | 317 pActionHandler->DoAction_Document(action, (CPDF_AAction::AActionType)aaType, |
| 312 pSDKDoc); | 318 pSDKDoc); |
| 313 } | 319 } |
| 314 } | 320 } |
| 315 | 321 |
| 316 DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, | 322 DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, |
| 317 FPDF_FORMHANDLE hHandle, | 323 FPDF_FORMHANDLE hHandle, |
| 318 int aaType) { | 324 int aaType) { |
| 319 if (!hHandle || !page) | 325 if (!hHandle) |
| 320 return; | 326 return; |
| 321 CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); | 327 CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetSDKDocument(); |
| 322 CPDF_Page* pPage = (CPDF_Page*)page; | 328 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 329 if (!pPage) |
| 330 return; |
| 323 CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE); | 331 CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE); |
| 324 if (pPageView) { | 332 if (pPageView) { |
| 325 CPDFDoc_Environment* pEnv = pSDKDoc->GetEnv(); | 333 CPDFDoc_Environment* pEnv = pSDKDoc->GetEnv(); |
| 326 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); | 334 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 327 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; | 335 CPDF_Dictionary* pPageDict = pPage->m_pFormDict; |
| 328 CPDF_AAction aa = pPageDict->GetDict(FX_BSTRC("AA")); | 336 CPDF_AAction aa = pPageDict->GetDict(FX_BSTRC("AA")); |
| 329 | 337 |
| 330 FX_BOOL bExistOAAction = FALSE; | 338 FX_BOOL bExistOAAction = FALSE; |
| 331 FX_BOOL bExistCAAction = FALSE; | 339 FX_BOOL bExistCAAction = FALSE; |
| 332 if (FPDFPAGE_AACTION_OPEN == aaType) { | 340 if (FPDFPAGE_AACTION_OPEN == aaType) { |
| 333 bExistOAAction = aa.ActionExist(CPDF_AAction::OpenPage); | 341 bExistOAAction = aa.ActionExist(CPDF_AAction::OpenPage); |
| 334 if (bExistOAAction) { | 342 if (bExistOAAction) { |
| 335 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); | 343 CPDF_Action action = aa.GetAction(CPDF_AAction::OpenPage); |
| 336 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); | 344 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); |
| 337 } | 345 } |
| 338 } else { | 346 } else { |
| 339 bExistCAAction = aa.ActionExist(CPDF_AAction::ClosePage); | 347 bExistCAAction = aa.ActionExist(CPDF_AAction::ClosePage); |
| 340 if (bExistCAAction) { | 348 if (bExistCAAction) { |
| 341 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); | 349 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); |
| 342 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); | 350 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); |
| 343 } | 351 } |
| 344 } | 352 } |
| 345 } | 353 } |
| 346 } | 354 } |
| OLD | NEW |