Home | History | Annotate | Download | only in fm2js
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #include "xfa_fm2js.h"
      8 #ifdef __cplusplus
      9 extern "C" {
     10 #endif
     11 int32_t XFA_FM2JS_Translate(const CFX_WideStringC& wsFormcalc,
     12                             CFX_WideTextBuf& wsJavascript,
     13                             CFX_WideString& wsError) {
     14   if (wsFormcalc.IsEmpty()) {
     15     wsJavascript.Clear();
     16     wsError.Empty();
     17     return 0;
     18   }
     19   int32_t status = 0;
     20   CXFA_FMProgram program;
     21   status = program.Init(wsFormcalc);
     22   if (status) {
     23     wsError = program.GetError().message;
     24     return status;
     25   }
     26   status = program.ParseProgram();
     27   if (status) {
     28     wsError = program.GetError().message;
     29     return status;
     30   }
     31   program.TranslateProgram(wsJavascript);
     32   return 0;
     33 }
     34 XFA_HFM2JSCONTEXT XFA_FM2JS_ContextCreate() {
     35   return (XFA_HFM2JSCONTEXT)CXFA_FM2JSContext::Create();
     36 }
     37 void XFA_FM2JS_ContextInitialize(XFA_HFM2JSCONTEXT hFM2JSContext,
     38                                  FXJSE_HRUNTIME hScriptRuntime,
     39                                  FXJSE_HCONTEXT hScriptContext,
     40                                  CXFA_Document* pDocument) {
     41   CXFA_FM2JSContext* pContext =
     42       reinterpret_cast<CXFA_FM2JSContext*>(hFM2JSContext);
     43   pContext->Initialize(hScriptRuntime, hScriptContext, pDocument);
     44 }
     45 void XFA_FM2JS_GlobalPropertyGetter(XFA_HFM2JSCONTEXT hFM2JSContext,
     46                                     FXJSE_HVALUE hValue) {
     47   CXFA_FM2JSContext* pContext =
     48       reinterpret_cast<CXFA_FM2JSContext*>(hFM2JSContext);
     49   pContext->GlobalPropertyGetter(hValue);
     50 }
     51 void XFA_FM2JS_ContextRelease(XFA_HFM2JSCONTEXT hFM2JSContext) {
     52   CXFA_FM2JSContext* pContext =
     53       reinterpret_cast<CXFA_FM2JSContext*>(hFM2JSContext);
     54   pContext->Release();
     55 }
     56 #ifdef __cplusplus
     57 }
     58 #endif
     59