FX_BOOL app::activeDocs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return FALSE; CJS_Context* pContext = (CJS_Context *)cc; CPDFDoc_Environment* pApp = pContext->GetReaderApp(); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); CJS_Array aDocs(pRuntime->GetIsolate()); if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) { CJS_Document* pJSDocument = NULL; if (pDoc == pCurDoc) { JSFXObject pObj = JS_GetThisObj(*pRuntime); if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document")) pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj); } else { JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document")); pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj); ASSERT(pJSDocument != NULL); } aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument)); } if (aDocs.GetLength() > 0) vp << aDocs; else vp.SetNull(); return TRUE; }
FX_BOOL Document::pageNum(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); if (vp.IsGetting()) { if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView()) { vp << pPageView->GetPageIndex(); } } else { int iPageCount = m_pDocument->GetPageCount(); int iPageNum = 0; vp >> iPageNum; CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); if (iPageNum >= 0 && iPageNum < iPageCount) { pEnv->JS_docgotoPage(iPageNum); } else if (iPageNum >= iPageCount) { pEnv->JS_docgotoPage(iPageCount-1); } else if (iPageNum < 0) { pEnv->JS_docgotoPage(0); } } return TRUE; }
FX_BOOL Document::dirty(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); if (vp.IsGetting()) { if (m_pDocument->GetChangeMark()) vp << true; else vp << false; } else { bool bChanged = false; vp >> bChanged; if (bChanged) m_pDocument->SetChangeMark(); else m_pDocument->ClearChangeMark(); } return TRUE; }
FX_BOOL Document::title(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL) return FALSE; CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); if (!pDictionary)return FALSE; if (vp.IsGetting()) { vp << pDictionary->GetUnicodeText("Title"); return TRUE; } else { if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; CFX_WideString cstitle; vp >> cstitle; pDictionary->SetAtString("Title", PDF_EncodeText(cstitle)); m_pDocument->SetChangeMark(); return TRUE; } }
FX_BOOL Annot::hidden(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsGetting()) { CPDF_Annot* pPDFAnnot = m_BAAnnot->GetPDFAnnot(); vp << CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict()); return TRUE; } bool bHidden; vp >> bHidden; uint32_t flags = m_BAAnnot->GetFlags(); if (bHidden) { flags |= ANNOTFLAG_HIDDEN; flags |= ANNOTFLAG_INVISIBLE; flags |= ANNOTFLAG_NOVIEW; flags &= ~ANNOTFLAG_PRINT; } else { flags &= ~ANNOTFLAG_HIDDEN; flags &= ~ANNOTFLAG_INVISIBLE; flags &= ~ANNOTFLAG_NOVIEW; flags |= ANNOTFLAG_PRINT; } m_BAAnnot->SetFlags(flags); return TRUE; }
FX_BOOL Icon::name(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return FALSE; vp << m_swIconName; return TRUE; }
FX_BOOL Document::external(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { //In Chrome case,should always return true. if (vp.IsGetting()) { vp << TRUE; } return TRUE; }
FX_BOOL Document::info(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); if (!pDictionary)return FALSE; CFX_WideString cwAuthor = pDictionary->GetUnicodeText("Author"); CFX_WideString cwTitle = pDictionary->GetUnicodeText("Title"); CFX_WideString cwSubject = pDictionary->GetUnicodeText("Subject"); CFX_WideString cwKeywords = pDictionary->GetUnicodeText("Keywords"); CFX_WideString cwCreator = pDictionary->GetUnicodeText("Creator"); CFX_WideString cwProducer = pDictionary->GetUnicodeText("Producer"); CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationDate"); CFX_WideString cwModDate = pDictionary->GetUnicodeText("ModDate"); CFX_WideString cwTrapped = pDictionary->GetUnicodeText("Trapped"); v8::Isolate* isolate = GetIsolate(cc); if (vp.IsGetting()) { CJS_Context* pContext = (CJS_Context *)cc; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1); JS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str()); JS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str()); JS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()); JS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str()); JS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str()); JS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str()); JS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDate.c_str()); JS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str()); JS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str()); // It's to be compatible to non-standard info dictionary. FX_POSITION pos = pDictionary->GetStartPos(); while(pos) { CFX_ByteString bsKey; CPDF_Object* pValueObj = pDictionary->GetNextElement(pos, bsKey); CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength()); if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj->GetType()==PDFOBJ_NAME) ) JS_PutObjectString(isolate, pObj, wsKey.c_str(), pValueObj->GetUnicodeText().c_str()); if(pValueObj->GetType()==PDFOBJ_NUMBER) JS_PutObjectNumber(isolate,pObj, wsKey.c_str(), (float)pValueObj->GetNumber()); if(pValueObj->GetType()==PDFOBJ_BOOLEAN) JS_PutObjectBoolean(isolate,pObj, wsKey.c_str(), (bool)pValueObj->GetInteger()); } vp << pObj; return TRUE; } else { return TRUE; } }
FX_BOOL Document::baseURL(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsGetting()) { vp << m_cwBaseURL; } else { vp >> m_cwBaseURL; } return TRUE; }
FX_BOOL Annot::name(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsGetting()) { vp << m_BAAnnot->GetAnnotName(); return TRUE; } CFX_WideString annotName; vp >> annotName; m_BAAnnot->SetAnnotName(annotName); return TRUE; }
FX_BOOL Document::delay(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { if (vp.IsGetting()) { vp << m_bDelay; return TRUE; } else { ASSERT(m_pDocument != NULL); if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE; bool b; vp >> b; m_bDelay = b; if (m_bDelay) { for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++) delete m_DelayData.GetAt(i); m_DelayData.RemoveAll(); } else { CFX_ArrayTemplate<CJS_DelayData*> DelayDataToProcess; for (int i=0,sz=m_DelayData.GetSize(); i < sz; i++) { if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { DelayDataToProcess.Add(pData); m_DelayData.SetAt(i, NULL); } } m_DelayData.RemoveAll(); for (int i=0,sz=DelayDataToProcess.GetSize(); i < sz; i++) { CJS_DelayData* pData = DelayDataToProcess.GetAt(i); Field::DoDelay(m_pDocument, pData); DelayDataToProcess.SetAt(i,NULL); delete pData; } } return TRUE; } }
FX_BOOL Document::ADBE(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); if (vp.IsGetting()) { vp.SetNull(); } else { } return TRUE; }
bool color::PropertyHelper(CJS_Runtime* pRuntime, CJS_PropValue& vp, CPWL_Color* var) { CJS_Array array; if (vp.IsGetting()) { ConvertPWLColorToArray(pRuntime, *var, &array); vp << array; return true; } if (!vp.GetJSValue()->ConvertToArray(pRuntime, array)) return false; ConvertArrayToPWLColor(pRuntime, array, var); return true; }
FX_BOOL Document::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { ASSERT(m_pDocument != NULL); CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); ASSERT(pInterForm != NULL); if (vp.IsGetting()) { if (pInterForm->IsCalculateEnabled()) vp << true; else vp << false; } else { bool bCalculate; vp >> bCalculate; pInterForm->EnableCalculate(bCalculate); } return TRUE; }
bool app::activeDocs(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { if (!vp.IsGetting()) return false; CJS_Context* pContext = (CJS_Context*)cc; CJS_Runtime* pRuntime = pContext->GetJSRuntime(); CJS_Document* pJSDocument = nullptr; v8::Local<v8::Object> pObj = pRuntime->GetThisObj(); if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) { pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj)); } CJS_Array aDocs; aDocs.SetElement(pRuntime, 0, CJS_Value(pRuntime, pJSDocument)); if (aDocs.GetLength(pRuntime) > 0) vp << aDocs; else vp.GetJSValue()->SetNull(pRuntime); return true; }