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 "../../third_party/base/nonstd_unique_ptr.h" | 7 #include "../../third_party/base/nonstd_unique_ptr.h" |
8 #include "../include/fsdk_define.h" | 8 #include "../include/fsdk_define.h" |
9 #include "../include/fpdfxfa/fpdfxfa_doc.h" | 9 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
10 #include "../include/fpdfxfa/fpdfxfa_util.h" | 10 #include "../include/fpdfxfa/fpdfxfa_util.h" |
(...skipping 2441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2452 if (pFormField->CountSelectedItems() > 0) { | 2452 if (pFormField->CountSelectedItems() > 0) { |
2453 int index = pFormField->GetSelectedIndex(0); | 2453 int index = pFormField->GetSelectedIndex(0); |
2454 if (index >= 0) | 2454 if (index >= 0) |
2455 sValue = pFormField->GetOptionLabel(index); | 2455 sValue = pFormField->GetOptionLabel(index); |
2456 } | 2456 } |
2457 } | 2457 } |
2458 | 2458 |
2459 bFormated = FALSE; | 2459 bFormated = FALSE; |
2460 | 2460 |
2461 CPDF_AAction aAction = pFormField->GetAdditionalAction(); | 2461 CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
2462 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Format)) { | 2462 if (aAction && aAction.ActionExist(CPDF_AAction::Format)) { |
2463 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); | 2463 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); |
2464 if (action) { | 2464 if (action) { |
2465 CFX_WideString script = action.GetJavaScript(); | 2465 CFX_WideString script = action.GetJavaScript(); |
2466 if (!script.IsEmpty()) { | 2466 if (!script.IsEmpty()) { |
2467 CFX_WideString Value = sValue; | 2467 CFX_WideString Value = sValue; |
2468 | 2468 |
2469 IJS_Context* pContext = pRuntime->NewContext(); | 2469 IJS_Context* pContext = pRuntime->NewContext(); |
2470 ASSERT(pContext != NULL); | 2470 ASSERT(pContext != NULL); |
2471 | 2471 |
2472 pContext->OnField_Format(pFormField, Value, TRUE); | 2472 pContext->OnField_Format(pFormField, Value, TRUE); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2522 } | 2522 } |
2523 } | 2523 } |
2524 } | 2524 } |
2525 | 2525 |
2526 void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, | 2526 void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, |
2527 CFX_WideString& csValue, | 2527 CFX_WideString& csValue, |
2528 FX_BOOL& bRC) { | 2528 FX_BOOL& bRC) { |
2529 ASSERT(pFormField != NULL); | 2529 ASSERT(pFormField != NULL); |
2530 | 2530 |
2531 CPDF_AAction aAction = pFormField->GetAdditionalAction(); | 2531 CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
2532 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::KeyStroke)) { | 2532 if (aAction && aAction.ActionExist(CPDF_AAction::KeyStroke)) { |
2533 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); | 2533 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); |
2534 if (action) { | 2534 if (action) { |
2535 ASSERT(m_pDocument != NULL); | 2535 ASSERT(m_pDocument != NULL); |
2536 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 2536 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
2537 ASSERT(pEnv != NULL); | 2537 ASSERT(pEnv != NULL); |
2538 | 2538 |
2539 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); | 2539 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
2540 ASSERT(pActionHandler != NULL); | 2540 ASSERT(pActionHandler != NULL); |
2541 | 2541 |
2542 PDFSDK_FieldAction fa; | 2542 PDFSDK_FieldAction fa; |
2543 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); | 2543 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); |
2544 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); | 2544 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); |
2545 fa.sValue = csValue; | 2545 fa.sValue = csValue; |
2546 | 2546 |
2547 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, | 2547 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, |
2548 m_pDocument, pFormField, fa); | 2548 m_pDocument, pFormField, fa); |
2549 bRC = fa.bRC; | 2549 bRC = fa.bRC; |
2550 } | 2550 } |
2551 } | 2551 } |
2552 } | 2552 } |
2553 | 2553 |
2554 void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, | 2554 void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, |
2555 CFX_WideString& csValue, | 2555 CFX_WideString& csValue, |
2556 FX_BOOL& bRC) { | 2556 FX_BOOL& bRC) { |
2557 ASSERT(pFormField != NULL); | 2557 ASSERT(pFormField != NULL); |
2558 | 2558 |
2559 CPDF_AAction aAction = pFormField->GetAdditionalAction(); | 2559 CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
2560 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Validate)) { | 2560 if (aAction && aAction.ActionExist(CPDF_AAction::Validate)) { |
2561 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); | 2561 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); |
2562 if (action) { | 2562 if (action) { |
2563 ASSERT(m_pDocument != NULL); | 2563 ASSERT(m_pDocument != NULL); |
2564 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 2564 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
2565 ASSERT(pEnv != NULL); | 2565 ASSERT(pEnv != NULL); |
2566 | 2566 |
2567 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); | 2567 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
2568 ASSERT(pActionHandler != NULL); | 2568 ASSERT(pActionHandler != NULL); |
2569 | 2569 |
2570 PDFSDK_FieldAction fa; | 2570 PDFSDK_FieldAction fa; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2684 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, | 2684 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, |
2685 CFX_WideString csTxtFile) { | 2685 CFX_WideString csTxtFile) { |
2686 return TRUE; | 2686 return TRUE; |
2687 } | 2687 } |
2688 | 2688 |
2689 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, | 2689 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, |
2690 FX_STRSIZE& nBufSize) { | 2690 FX_STRSIZE& nBufSize) { |
2691 CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); | 2691 CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); |
2692 if (pFDF) { | 2692 if (pFDF) { |
2693 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF"); | 2693 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF"); |
2694 if (pMainDict == NULL) | 2694 if (!pMainDict) |
2695 return FALSE; | 2695 return FALSE; |
2696 | 2696 |
2697 // Get fields | 2697 // Get fields |
2698 CPDF_Array* pFields = pMainDict->GetArray("Fields"); | 2698 CPDF_Array* pFields = pMainDict->GetArray("Fields"); |
2699 if (pFields == NULL) | 2699 if (!pFields) |
2700 return FALSE; | 2700 return FALSE; |
2701 | 2701 |
2702 CFX_ByteTextBuf fdfEncodedData; | 2702 CFX_ByteTextBuf fdfEncodedData; |
2703 | 2703 |
2704 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) { | 2704 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) { |
2705 CPDF_Dictionary* pField = pFields->GetDict(i); | 2705 CPDF_Dictionary* pField = pFields->GetDict(i); |
2706 if (pField == NULL) | 2706 if (!pField) |
2707 continue; | 2707 continue; |
2708 CFX_WideString name; | 2708 CFX_WideString name; |
2709 name = pField->GetUnicodeText("T"); | 2709 name = pField->GetUnicodeText("T"); |
2710 CFX_ByteString name_b = CFX_ByteString::FromUnicode(name); | 2710 CFX_ByteString name_b = CFX_ByteString::FromUnicode(name); |
2711 CFX_ByteString csBValue = pField->GetString("V"); | 2711 CFX_ByteString csBValue = pField->GetString("V"); |
2712 CFX_WideString csWValue = PDF_DecodeText(csBValue); | 2712 CFX_WideString csWValue = PDF_DecodeText(csBValue); |
2713 CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue); | 2713 CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue); |
2714 | 2714 |
2715 fdfEncodedData = fdfEncodedData << name_b.GetBuffer(name_b.GetLength()); | 2715 fdfEncodedData = fdfEncodedData << name_b.GetBuffer(name_b.GetLength()); |
2716 name_b.ReleaseBuffer(); | 2716 name_b.ReleaseBuffer(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2771 } | 2771 } |
2772 | 2772 |
2773 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, | 2773 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, |
2774 FX_BOOL bUrlEncoded) { | 2774 FX_BOOL bUrlEncoded) { |
2775 if (sDestination.IsEmpty()) | 2775 if (sDestination.IsEmpty()) |
2776 return FALSE; | 2776 return FALSE; |
2777 | 2777 |
2778 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 2778 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
2779 ASSERT(pEnv != NULL); | 2779 ASSERT(pEnv != NULL); |
2780 | 2780 |
2781 if (NULL == m_pDocument) | 2781 if (!m_pDocument) |
2782 return FALSE; | 2782 return FALSE; |
2783 CFX_WideString wsPDFFilePath = m_pDocument->GetPath(); | 2783 CFX_WideString wsPDFFilePath = m_pDocument->GetPath(); |
2784 | 2784 |
2785 if (NULL == m_pInterForm) | 2785 if (!m_pInterForm) |
2786 return FALSE; | 2786 return FALSE; |
2787 CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath); | 2787 CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath); |
2788 if (NULL == pFDFDoc) | 2788 if (!pFDFDoc) |
2789 return FALSE; | 2789 return FALSE; |
2790 | 2790 |
2791 CFX_ByteTextBuf FdfBuffer; | 2791 CFX_ByteTextBuf FdfBuffer; |
2792 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer); | 2792 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer); |
2793 delete pFDFDoc; | 2793 delete pFDFDoc; |
2794 if (!bRet) | 2794 if (!bRet) |
2795 return FALSE; | 2795 return FALSE; |
2796 | 2796 |
2797 uint8_t* pBuffer = FdfBuffer.GetBuffer(); | 2797 uint8_t* pBuffer = FdfBuffer.GetBuffer(); |
2798 FX_STRSIZE nBufSize = FdfBuffer.GetLength(); | 2798 FX_STRSIZE nBufSize = FdfBuffer.GetLength(); |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3224 break; | 3224 break; |
3225 } | 3225 } |
3226 } | 3226 } |
3227 } | 3227 } |
3228 | 3228 |
3229 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) { | 3229 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) { |
3230 CPDF_Rect rcAnnot; | 3230 CPDF_Rect rcAnnot; |
3231 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); | 3231 pAnnot->GetPDFAnnot()->GetRect(rcAnnot); |
3232 return rcAnnot; | 3232 return rcAnnot; |
3233 } | 3233 } |
OLD | NEW |