static CFX_WideString FILESPEC_DecodeFileName(const CFX_WideStringC& filepath) { if (filepath.GetLength() <= 1) { return CFX_WideString(); } #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ if (filepath.Left(sizeof("/Mac") - 1) == CFX_WideStringC(L"/Mac")) { return ChangeSlashToPlatform(filepath.GetPtr() + 1); } return ChangeSlashToPlatform(filepath.GetPtr()); #elif _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ if (filepath.GetAt(0) != '/') { return ChangeSlashToPlatform(filepath.GetPtr()); } if (filepath.GetAt(1) == '/') { return ChangeSlashToPlatform(filepath.GetPtr() + 1); } if (filepath.GetAt(2) == '/') { CFX_WideString result; result += filepath.GetAt(1); result += ':'; result += ChangeSlashToPlatform(filepath.GetPtr() + 2); return result; } CFX_WideString result; result += '\\'; result += ChangeSlashToPlatform(filepath.GetPtr()); return result; #else return filepath; #endif }
TEST(FMCallExpression, more_than_32_arguments) { // Use sign as it has 3 object parameters at positions 0, 5, and 6. std::unique_ptr<CXFA_FMIdentifierExpression> exp( new CXFA_FMIdentifierExpression(0, CFX_WideStringC(L"sign"))); std::unique_ptr<CFX_ArrayTemplate<CXFA_FMSimpleExpression*>> args( new CFX_ArrayTemplate<CXFA_FMSimpleExpression*>()); for (size_t i = 0; i < 50; i++) args->Add(new CXFA_FMSimpleExpression(0, TOKnan)); CXFA_FMCallExpression callExp(0, exp.release(), args.release(), true); CFX_WideTextBuf js; callExp.ToJavaScript(js); // Generate the result javascript string. CFX_WideString result = L"sign("; for (size_t i = 0; i < 50; i++) { if (i > 0) result += L", "; result += L"foxit_xfa_formcalc_runtime.get_fm_"; // Object positions for sign() method. if (i == 0 || i == 5 || i == 6) result += L"jsobj()"; else result += L"value()"; } result += L")"; EXPECT_EQ(result.AsStringC(), js.AsStringC()); }
CFX_WideString CPDF_FileSpec::DecodeFileName(const CFX_WideStringC& filepath) { if (filepath.GetLength() <= 1) return CFX_WideString(); #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ if (filepath.Left(sizeof("/Mac") - 1) == CFX_WideStringC(L"/Mac")) return ChangeSlashToPlatform(filepath.c_str() + 1); return ChangeSlashToPlatform(filepath.c_str()); #elif _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ if (filepath.GetAt(0) != '/') return ChangeSlashToPlatform(filepath.c_str()); if (filepath.GetAt(1) == '/') return ChangeSlashToPlatform(filepath.c_str() + 1); if (filepath.GetAt(2) == '/') { CFX_WideString result; result += filepath.GetAt(1); result += ':'; result += ChangeSlashToPlatform(filepath.c_str() + 2); return result; } CFX_WideString result; result += '\\'; result += ChangeSlashToPlatform(filepath.c_str()); return result; #else return CFX_WideString(filepath); #endif }
CFDE_CSSSelector::CFDE_CSSSelector(FDE_CSSSELECTORTYPE eType, const FX_WCHAR* psz, int32_t iLen, bool bIgnoreCase) : m_eType(eType), m_dwHash(FX_HashCode_GetW(CFX_WideStringC(psz, iLen), bIgnoreCase)), m_pNext(nullptr) {}
CXFA_NodeList::CXFA_NodeList(CXFA_Document* pDocument) : CXFA_Object(pDocument, XFA_ObjectType::NodeList, XFA_Element::NodeList, CFX_WideStringC(L"nodeList")) { m_pDocument->GetScriptContext()->AddToCacheList( std::unique_ptr<CXFA_NodeList>(this)); }
CXFA_Node* CXFA_NodeHelper::ResolveNodes_GetOneChild(CXFA_Node* parent, const FX_WCHAR* pwsName, FX_BOOL bIsClassName) { if (!parent) { return nullptr; } CXFA_NodeArray siblings; uint32_t uNameHash = FX_HashCode_GetW(CFX_WideStringC(pwsName), false); NodeAcc_TraverseAnySiblings(parent, uNameHash, &siblings, bIsClassName); if (siblings.GetSize() == 0) { return nullptr; } return siblings[0]; }
FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadFontFaceRule( CFDE_CSSSyntaxParser* pSyntax, CFX_MassArrayTemplate<IFDE_CSSRule*>& ruleArray) { CFDE_CSSFontFaceRule* pFontFaceRule = nullptr; const FX_WCHAR* pszValue = nullptr; int32_t iValueLen = 0; FDE_CSSPROPERTYARGS propertyArgs; propertyArgs.pStaticStore = m_pAllocator.get(); propertyArgs.pStringCache = &m_StringCache; propertyArgs.pProperty = nullptr; for (;;) { switch (pSyntax->DoSyntaxParse()) { case FDE_CSSSYNTAXSTATUS_PropertyName: pszValue = pSyntax->GetCurrentString(iValueLen); propertyArgs.pProperty = FDE_GetCSSPropertyByName(CFX_WideStringC(pszValue, iValueLen)); break; case FDE_CSSSYNTAXSTATUS_PropertyValue: if (propertyArgs.pProperty) { pszValue = pSyntax->GetCurrentString(iValueLen); if (iValueLen > 0) { pFontFaceRule->GetDeclImp().AddProperty(&propertyArgs, pszValue, iValueLen); } } break; case FDE_CSSSYNTAXSTATUS_DeclOpen: if (!pFontFaceRule) { pFontFaceRule = FXTARGET_NewWith(m_pAllocator.get()) CFDE_CSSFontFaceRule; ruleArray.Add(pFontFaceRule); } break; case FDE_CSSSYNTAXSTATUS_DeclClose: return FDE_CSSSYNTAXSTATUS_None; FDE_CSSSWITCHDEFAULTS(); } } }
FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadMediaRule( CFDE_CSSSyntaxParser* pSyntax) { uint32_t dwMediaList = 0; CFDE_CSSMediaRule* pMediaRule = nullptr; for (;;) { switch (pSyntax->DoSyntaxParse()) { case FDE_CSSSYNTAXSTATUS_MediaType: { int32_t iLen; const FX_WCHAR* psz = pSyntax->GetCurrentString(iLen); FDE_LPCCSSMEDIATYPETABLE pMediaType = FDE_GetCSSMediaTypeByName(CFX_WideStringC(psz, iLen)); if (pMediaType) dwMediaList |= pMediaType->wValue; } break; case FDE_CSSSYNTAXSTATUS_StyleRule: if (pMediaRule) { FDE_CSSSYNTAXSTATUS eStatus = LoadStyleRule(pSyntax, pMediaRule->GetArray()); if (eStatus < FDE_CSSSYNTAXSTATUS_None) { return eStatus; } } else { SkipRuleSet(pSyntax); } break; case FDE_CSSSYNTAXSTATUS_DeclOpen: if ((dwMediaList & m_dwMediaList) > 0 && !pMediaRule) { pMediaRule = FXTARGET_NewWith(m_pAllocator.get()) CFDE_CSSMediaRule(dwMediaList); m_RuleArray.Add(pMediaRule); } break; case FDE_CSSSYNTAXSTATUS_DeclClose: return FDE_CSSSYNTAXSTATUS_None; FDE_CSSSWITCHDEFAULTS(); } } }
CFX_WideStringC CFX_WideTextBuf::GetWideString() const { return CFX_WideStringC((const FX_WCHAR*)m_pBuffer, m_DataSize / sizeof(FX_WCHAR)); }
CScript_LayoutPseudoModel::CScript_LayoutPseudoModel(CXFA_Document* pDocument) : CXFA_Object(pDocument, XFA_ObjectType::Object, XFA_Element::LayoutPseudoModel, CFX_WideStringC(L"layoutPseudoModel")) {}
FDE_CSSSYNTAXSTATUS CFDE_CSSStyleSheet::LoadStyleRule( IFDE_CSSSyntaxParser* pSyntax, CFDE_CSSRuleArray& ruleArray) { m_Selectors.RemoveAt(0, m_Selectors.GetSize()); CFDE_CSSStyleRule* pStyleRule = NULL; const FX_WCHAR* pszValue = NULL; int32_t iValueLen = 0; FDE_CSSPROPERTYARGS propertyArgs; propertyArgs.pStaticStore = m_pAllocator; propertyArgs.pStringCache = &m_StringCache; propertyArgs.pProperty = NULL; CFX_WideString wsName; for (;;) { switch (pSyntax->DoSyntaxParse()) { case FDE_CSSSYNTAXSTATUS_Selector: { pszValue = pSyntax->GetCurrentString(iValueLen); IFDE_CSSSelector* pSelector = CFDE_CSSSelector::FromString(m_pAllocator, pszValue, iValueLen); if (pSelector != NULL) { m_Selectors.Add(pSelector); } } break; case FDE_CSSSYNTAXSTATUS_PropertyName: pszValue = pSyntax->GetCurrentString(iValueLen); propertyArgs.pProperty = FDE_GetCSSPropertyByName(pszValue, iValueLen); if (propertyArgs.pProperty == NULL) { wsName = CFX_WideStringC(pszValue, iValueLen); } break; case FDE_CSSSYNTAXSTATUS_PropertyValue: if (propertyArgs.pProperty != NULL) { pszValue = pSyntax->GetCurrentString(iValueLen); if (iValueLen > 0) { pStyleRule->GetDeclImp().AddProperty(&propertyArgs, pszValue, iValueLen); } } else if (iValueLen > 0) { pszValue = pSyntax->GetCurrentString(iValueLen); if (iValueLen > 0) { pStyleRule->GetDeclImp().AddProperty( &propertyArgs, wsName, wsName.GetLength(), pszValue, iValueLen); } } break; case FDE_CSSSYNTAXSTATUS_DeclOpen: if (pStyleRule == NULL && m_Selectors.GetSize() > 0) { pStyleRule = FDE_NewWith(m_pAllocator) CFDE_CSSStyleRule; pStyleRule->SetSelector(m_pAllocator, m_Selectors); ruleArray.Add(pStyleRule); } else { SkipRuleSet(pSyntax); return FDE_CSSSYNTAXSTATUS_None; } break; case FDE_CSSSYNTAXSTATUS_DeclClose: if (pStyleRule != NULL && pStyleRule->GetDeclImp().GetStartPosition() == NULL) { pStyleRule->~CFDE_CSSStyleRule(); ruleArray.RemoveLast(1); } return FDE_CSSSYNTAXSTATUS_None; FDE_CSSSWITCHDEFAULTS(); } } }
CScript_SignaturePseudoModel::CScript_SignaturePseudoModel( CXFA_Document* pDocument) : CXFA_Object(pDocument, XFA_ObjectType::Object, XFA_Element::SignaturePseudoModel, CFX_WideStringC(L"signaturePseudoModel")) {}
bool CFWL_FormProxy::IsInstance(const CFX_WideStringC& wsClass) const { if (wsClass == CFX_WideStringC(FWL_CLASS_FormProxy)) return true; return CFWL_Form::IsInstance(wsClass); }
FX_BOOL CXFA_LocaleValue::ValidateNumericTemp(CFX_WideString& wsNumeric, CFX_WideString& wsFormat, IFX_Locale* pLocale, int32_t* pos) { if (wsFormat.IsEmpty() || wsNumeric.IsEmpty()) { return TRUE; } const FX_WCHAR* pNum = wsNumeric.c_str(); const FX_WCHAR* pFmt = wsFormat.c_str(); int32_t n = 0, nf = 0; FX_WCHAR c = pNum[n]; FX_WCHAR cf = pFmt[nf]; if (cf == L's') { if (c == L'-' || c == L'+') { ++n; } ++nf; } FX_BOOL bLimit = TRUE; int32_t nCount = wsNumeric.GetLength(); int32_t nCountFmt = wsFormat.GetLength(); while (n < nCount && (bLimit ? nf < nCountFmt : TRUE) && FXSYS_isDecimalDigit(c = pNum[n])) { if (bLimit == TRUE) { if ((cf = pFmt[nf]) == L'*') { bLimit = FALSE; } else if (cf == L'z') { nf++; } else { return FALSE; } } n++; } if (n == nCount) { return TRUE; } if (nf == nCountFmt) { return FALSE; } while (nf < nCountFmt && (cf = pFmt[nf]) != L'.') { ASSERT(cf == L'z' || cf == L'*'); ++nf; } CFX_WideString wsDecimalSymbol; if (pLocale) { pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal, wsDecimalSymbol); } else { wsDecimalSymbol = CFX_WideString(L'.'); } if (pFmt[nf] != L'.') { return FALSE; } if (wsDecimalSymbol != CFX_WideStringC(c) && c != L'.') { return FALSE; } ++nf; ++n; bLimit = TRUE; while (n < nCount && (bLimit ? nf < nCountFmt : TRUE) && FXSYS_isDecimalDigit(c = pNum[n])) { if (bLimit == TRUE) { if ((cf = pFmt[nf]) == L'*') { bLimit = FALSE; } else if (cf == L'z') { nf++; } else { return FALSE; } } n++; } return n == nCount; }
FX_BOOL _SaveXFADocumentData(CPDFXFA_Document* pDocument, CFX_PtrArray& fileList) { if (!pDocument) return FALSE; if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && pDocument->GetDocType() != DOCTYPE_STATIC_XFA) return TRUE; if (!CPDFXFA_App::GetInstance()->GetXFAApp()) return TRUE; IXFA_DocView* pXFADocView = pDocument->GetXFADocView(); if (NULL == pXFADocView) return TRUE; IXFA_DocHandler* pXFADocHandler = CPDFXFA_App::GetInstance()->GetXFAApp()->GetDocHandler(); CPDF_Document* pPDFDocument = pDocument->GetPDFDoc(); if (pDocument == NULL) return FALSE; CPDF_Dictionary* pRoot = pPDFDocument->GetRoot(); if (pRoot == NULL) return FALSE; CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm"); if (NULL == pAcroForm) return FALSE; CPDF_Object* pXFA = pAcroForm->GetElement("XFA"); if (pXFA == NULL) return TRUE; if (pXFA->GetType() != PDFOBJ_ARRAY) return FALSE; CPDF_Array* pArray = pXFA->GetArray(); if (NULL == pArray) return FALSE; int size = pArray->GetCount(); int iFormIndex = -1; int iDataSetsIndex = -1; int iTemplate = -1; int iLast = size - 2; for (int i = 0; i < size - 1; i++) { CPDF_Object* pPDFObj = pArray->GetElement(i); if (pPDFObj->GetType() != PDFOBJ_STRING) continue; if (pPDFObj->GetString() == "form") iFormIndex = i + 1; else if (pPDFObj->GetString() == "datasets") iDataSetsIndex = i + 1; else if (pPDFObj->GetString() == "template") iTemplate = i + 1; } IXFA_ChecksumContext* pContext = NULL; // Checksum pContext = XFA_Checksum_Create(); FXSYS_assert(pContext); pContext->StartChecksum(); // template if (iTemplate > -1) { CPDF_Stream* pTemplateStream = pArray->GetStream(iTemplate); CPDF_StreamAcc streamAcc; streamAcc.LoadAllData(pTemplateStream); uint8_t* pData = (uint8_t*)streamAcc.GetData(); FX_DWORD dwSize2 = streamAcc.GetSize(); IFX_FileStream* pTemplate = FX_CreateMemoryStream(pData, dwSize2); pContext->UpdateChecksum((IFX_FileRead*)pTemplate); pTemplate->Release(); } CPDF_Stream* pFormStream = NULL; CPDF_Stream* pDataSetsStream = NULL; if (iFormIndex != -1) { // Get form CPDF_Stream CPDF_Object* pFormPDFObj = pArray->GetElement(iFormIndex); if (pFormPDFObj->GetType() == PDFOBJ_REFERENCE) { CPDF_Object* pFormDircetObj = pFormPDFObj->GetDirect(); if (NULL != pFormDircetObj && pFormDircetObj->GetType() == PDFOBJ_STREAM) { pFormStream = (CPDF_Stream*)pFormDircetObj; } } else if (pFormPDFObj->GetType() == PDFOBJ_STREAM) { pFormStream = (CPDF_Stream*)pFormPDFObj; } } if (iDataSetsIndex != -1) { // Get datasets CPDF_Stream CPDF_Object* pDataSetsPDFObj = pArray->GetElement(iDataSetsIndex); if (pDataSetsPDFObj->GetType() == PDFOBJ_REFERENCE) { CPDF_Reference* pDataSetsRefObj = (CPDF_Reference*)pDataSetsPDFObj; CPDF_Object* pDataSetsDircetObj = pDataSetsRefObj->GetDirect(); if (NULL != pDataSetsDircetObj && pDataSetsDircetObj->GetType() == PDFOBJ_STREAM) { pDataSetsStream = (CPDF_Stream*)pDataSetsDircetObj; } } else if (pDataSetsPDFObj->GetType() == PDFOBJ_STREAM) { pDataSetsStream = (CPDF_Stream*)pDataSetsPDFObj; } } // end // L"datasets" { IFX_FileStream* pDsfileWrite = FX_CreateMemoryStream(); if (NULL == pDsfileWrite) { pContext->Release(); pDsfileWrite->Release(); return FALSE; } if (pXFADocHandler->SavePackage(pXFADocView->GetDoc(), CFX_WideStringC(L"datasets"), pDsfileWrite) && pDsfileWrite->GetSize() > 0) { // Datasets pContext->UpdateChecksum((IFX_FileRead*)pDsfileWrite); pContext->FinishChecksum(); CPDF_Dictionary* pDataDict = new CPDF_Dictionary; if (iDataSetsIndex != -1) { if (pDataSetsStream) pDataSetsStream->InitStreamFromFile(pDsfileWrite, pDataDict); } else { CPDF_Stream* pData = new CPDF_Stream(NULL, 0, NULL); pData->InitStreamFromFile(pDsfileWrite, pDataDict); pPDFDocument->AddIndirectObject(pData); iLast = pArray->GetCount() - 2; pArray->InsertAt(iLast, new CPDF_String("datasets", FALSE)); pArray->InsertAt(iLast + 1, pData, pPDFDocument); } fileList.Add(pDsfileWrite); } } // L"form" { IFX_FileStream* pfileWrite = FX_CreateMemoryStream(); if (NULL == pfileWrite) { pContext->Release(); return FALSE; } if (pXFADocHandler->SavePackage(pXFADocView->GetDoc(), CFX_WideStringC(L"form"), pfileWrite, pContext) && pfileWrite > 0) { CPDF_Dictionary* pDataDict = new CPDF_Dictionary; if (iFormIndex != -1) { if (pFormStream) pFormStream->InitStreamFromFile(pfileWrite, pDataDict); } else { CPDF_Stream* pData = new CPDF_Stream(NULL, 0, NULL); pData->InitStreamFromFile(pfileWrite, pDataDict); pPDFDocument->AddIndirectObject(pData); iLast = pArray->GetCount() - 2; pArray->InsertAt(iLast, new CPDF_String("form", FALSE)); pArray->InsertAt(iLast + 1, pData, pPDFDocument); } fileList.Add(pfileWrite); } } pContext->Release(); return TRUE; }