int32_t CXFA_LayoutProcessor::DoLayout(IFX_Pause* pPause) { if (m_nProgressCounter < 1) return -1; XFA_ItemLayoutProcessorResult eStatus; CXFA_Node* pFormNode = m_pRootItemLayoutProcessor->GetFormNode(); FX_FLOAT fPosX = pFormNode->GetMeasure(XFA_ATTRIBUTE_X).ToUnit(XFA_UNIT_Pt); FX_FLOAT fPosY = pFormNode->GetMeasure(XFA_ATTRIBUTE_Y).ToUnit(XFA_UNIT_Pt); do { FX_FLOAT fAvailHeight = m_pLayoutPageMgr->GetAvailHeight(); eStatus = m_pRootItemLayoutProcessor->DoLayout(true, fAvailHeight, fAvailHeight, nullptr); if (eStatus != XFA_ItemLayoutProcessorResult::Done) m_nProgressCounter++; CXFA_ContentLayoutItem* pLayoutItem = m_pRootItemLayoutProcessor->ExtractLayoutItem(); if (pLayoutItem) pLayoutItem->m_sPos = CFX_PointF(fPosX, fPosY); m_pLayoutPageMgr->SubmitContentItem(pLayoutItem, eStatus); } while (eStatus != XFA_ItemLayoutProcessorResult::Done && (!pPause || !pPause->NeedToPauseNow())); if (eStatus == XFA_ItemLayoutProcessorResult::Done) { m_pLayoutPageMgr->FinishPaginatedPageSets(); m_pLayoutPageMgr->SyncLayoutData(); m_bNeeLayout = false; m_rgChangedContainers.RemoveAll(); } return 100 * (eStatus == XFA_ItemLayoutProcessorResult::Done ? m_nProgressCounter : m_nProgressCounter - 1) / m_nProgressCounter; }
FX_BOOL CXFA_FFConfigAcc::GetFontInfo(int32_t index, CFX_WideString& wsFontFamily, CFX_WideString& wsPsName, FX_BOOL bBold, FX_BOOL bItalic) { if (index < 0 || index >= CountChildren()) { return FALSE; } CXFA_Node* pFontNode = m_pPsMapNode->GetChild(index, XFA_ELEMENT_Font); if (pFontNode == NULL) { return FALSE; } wsFontFamily.Empty(); wsPsName.Empty(); bBold = FALSE; bItalic = FALSE; pFontNode->GetAttribute(XFA_ATTRIBUTE_Typeface, wsFontFamily); pFontNode->GetAttribute(XFA_ATTRIBUTE_PsName, wsPsName); CFX_WideString wsValue; pFontNode->GetAttribute(XFA_ATTRIBUTE_Weight, wsValue); wsValue.MakeLower(); if (wsValue == FX_WSTRC(L"bold")) { bBold = TRUE; } pFontNode->GetAttribute(XFA_ATTRIBUTE_Posture, wsValue); wsValue.MakeLower(); if (wsValue == FX_WSTRC(L"italic")) { bItalic = TRUE; } return wsFontFamily.GetLength() > 0; }
void CXFA_FFDocView::StopLayout() { CXFA_Node* pRootItem = ToNode(m_pDoc->GetXFADoc()->GetXFAObject(XFA_HASHCODE_Form)); if (!pRootItem) { return; } CXFA_Node* pSubformNode = pRootItem->GetChild(0, XFA_ELEMENT_Subform); if (!pSubformNode) { return; } CXFA_Node* pPageSetNode = pSubformNode->GetFirstChildByClass(XFA_ELEMENT_PageSet); if (!pPageSetNode) { return; } RunCalculateWidgets(); RunValidate(); InitLayout(pPageSetNode); InitCalculate(pPageSetNode); InitValidate(pPageSetNode); ExecEventActivityByDeepFirst(pPageSetNode, XFA_EVENT_Ready, TRUE); ExecEventActivityByDeepFirst(pRootItem, XFA_EVENT_Ready); ExecEventActivityByDeepFirst(pRootItem, XFA_EVENT_DocReady); RunCalculateWidgets(); RunValidate(); if (RunLayout()) { ExecEventActivityByDeepFirst(pRootItem, XFA_EVENT_Ready); } m_CalculateAccs.RemoveAll(); if (m_pFocusAcc && !m_pFocusWidget) { SetFocusWidgetAcc(m_pFocusAcc); } m_iStatus = XFA_DOCVIEW_LAYOUTSTATUS_End; }
int32_t CXFA_NodeHelper::XFA_CountSiblings(CXFA_Node* pNode, XFA_LOGIC_TYPE eLogicType, CXFA_NodeArray* pSiblings, FX_BOOL bIsClassName) { if (!pNode) return 0; CXFA_Node* parent = XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); if (!parent) return 0; XFA_LPCPROPERTY pPropert = XFA_GetPropertyOfElement( parent->GetClassID(), pNode->GetClassID(), XFA_XDPPACKET_UNKNOWN); if (!pPropert && eLogicType == XFA_LOGIC_Transparent) { parent = XFA_ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); if (parent == NULL) { return 0; } } if (bIsClassName) { return XFA_NodeAcc_TraverseSiblings(parent, pNode->GetClassHashCode(), pSiblings, eLogicType, bIsClassName); } else { return XFA_NodeAcc_TraverseSiblings(parent, pNode->GetNameHash(), pSiblings, eLogicType, bIsClassName); } }
CXFA_Node* CXFA_NodeHelper::XFA_ResolveNodes_GetParent( CXFA_Node* pNode, XFA_LOGIC_TYPE eLogicType) { if (!pNode) { return NULL; } if (eLogicType == XFA_LOGIC_NoTransparent) { return pNode->GetNodeItem(XFA_NODEITEM_Parent); } CXFA_Node* parent; CXFA_Node* node = pNode; while (TRUE) { parent = XFA_ResolveNodes_GetParent(node); if (parent == NULL) { break; } XFA_ELEMENT parentElement = parent->GetClassID(); if ((!parent->IsUnnamed() && parentElement != XFA_ELEMENT_SubformSet) || parentElement == XFA_ELEMENT_Variables) { break; } node = parent; } return parent; }
FX_BOOL CXFA_NodeHelper::NodeIsProperty(CXFA_Node* refNode) { CXFA_Node* parent = ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); return parent && refNode && XFA_GetPropertyOfElement(parent->GetElementType(), refNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); }
int32_t CXFA_FFField::CalculateOverride() { CXFA_WidgetAcc* pAcc = m_pDataAcc->GetExclGroup(); if (!pAcc) { return CalculateWidgetAcc(m_pDataAcc); } if (CalculateWidgetAcc(pAcc) == 0) { return 0; } CXFA_Node* pNode = pAcc->GetExclGroupFirstMember(); if (!pNode) { return 1; } CXFA_WidgetAcc* pWidgetAcc = nullptr; while (pNode) { pWidgetAcc = static_cast<CXFA_WidgetAcc*>(pNode->GetWidgetData()); if (!pWidgetAcc) { return 1; } if (CalculateWidgetAcc(pWidgetAcc) == 0) { return 0; } pNode = pWidgetAcc->GetExclGroupNextMember(pNode); } return 1; }
CXFA_WidgetAcc* CXFA_FFDocView::GetWidgetAccByName( const CFX_WideStringC& wsName, CXFA_WidgetAcc* pRefWidgetAcc) { CFX_WideString wsExpression; FX_DWORD dwStyle = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent; IXFA_ScriptContext* pScriptContext = m_pDoc->GetXFADoc()->GetScriptContext(); if (!pScriptContext) { return NULL; } CXFA_Node* refNode = NULL; if (pRefWidgetAcc != NULL) { refNode = pRefWidgetAcc->GetNode(); wsExpression = wsName; } else { wsExpression = L"$form." + wsName; } XFA_RESOLVENODE_RS resoveNodeRS; int32_t iRet = pScriptContext->ResolveObjects(refNode, wsExpression, resoveNodeRS, dwStyle); if (iRet < 1) { return NULL; } if (resoveNodeRS.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { CXFA_Node* pNode = resoveNodeRS.nodes[0]->AsNode(); if (pNode) { return (CXFA_WidgetAcc*)pNode->GetWidgetData(); } } return NULL; }
FX_BOOL CXFA_NodeHelper::ResolveNodes_CreateNode( CFX_WideString wsName, CFX_WideString wsCondition, FX_BOOL bLastNode, CXFA_ScriptContext* pScriptContext) { if (!m_pCreateParent) { return FALSE; } FX_BOOL bIsClassName = FALSE; FX_BOOL bResult = FALSE; if (wsName.GetAt(0) == '!') { wsName = wsName.Right(wsName.GetLength() - 1); m_pCreateParent = ToNode( pScriptContext->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets)); } if (wsName.GetAt(0) == '#') { bIsClassName = TRUE; wsName = wsName.Right(wsName.GetLength() - 1); } if (m_iCreateCount == 0) { CreateNode_ForCondition(wsCondition); } if (bIsClassName) { XFA_Element eType = XFA_GetElementTypeForName(wsName.AsStringC()); if (eType == XFA_Element::Unknown) return FALSE; for (int32_t iIndex = 0; iIndex < m_iCreateCount; iIndex++) { CXFA_Node* pNewNode = m_pCreateParent->CreateSamePacketNode(eType); if (pNewNode) { m_pCreateParent->InsertChild(pNewNode); if (iIndex == m_iCreateCount - 1) { m_pCreateParent = pNewNode; } bResult = TRUE; } } } else { XFA_Element eClassType = XFA_Element::DataGroup; if (bLastNode) { eClassType = m_eLastCreateType; } for (int32_t iIndex = 0; iIndex < m_iCreateCount; iIndex++) { CXFA_Node* pNewNode = m_pCreateParent->CreateSamePacketNode(eClassType); if (pNewNode) { pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, wsName.AsStringC()); pNewNode->CreateXMLMappingNode(); m_pCreateParent->InsertChild(pNewNode); if (iIndex == m_iCreateCount - 1) { m_pCreateParent = pNewNode; } bResult = TRUE; } } } if (!bResult) { m_pCreateParent = nullptr; } return bResult; }
int32_t CXFA_NodeHelper::CountSiblings(CXFA_Node* pNode, XFA_LOGIC_TYPE eLogicType, CXFA_NodeArray* pSiblings, bool bIsClassName) { if (!pNode) return 0; CXFA_Node* parent = ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); if (!parent) return 0; const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( parent->GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); if (!pProperty && eLogicType == XFA_LOGIC_Transparent) { parent = ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); if (!parent) { return 0; } } if (bIsClassName) { return NodeAcc_TraverseSiblings(parent, pNode->GetClassHashCode(), pSiblings, eLogicType, bIsClassName); } else { return NodeAcc_TraverseSiblings(parent, pNode->GetNameHash(), pSiblings, eLogicType, bIsClassName); } }
CXFA_Node* CXFA_FFWidgetHandler::CreatePasswordEdit(CXFA_Node* pParent, CXFA_Node* pBefore) const { CXFA_Node* pField = CreateField(XFA_ELEMENT_PasswordEdit, pParent, pBefore); CXFA_Node* pBind = CreateCopyNode(XFA_ELEMENT_Bind, pField); pBind->SetEnum(XFA_ATTRIBUTE_Match, XFA_ATTRIBUTEENUM_None, FALSE); return pField; }
int32_t CXFA_LayoutProcessor::StartLayout(FX_BOOL bForceRestart) { if (!bForceRestart && !IsNeedLayout()) { return 100; } if (m_pRootItemLayoutProcessor) { delete m_pRootItemLayoutProcessor; m_pRootItemLayoutProcessor = NULL; } m_nProgressCounter = 0; CXFA_Node* pFormPacketNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)); if (!pFormPacketNode) { return -1; } CXFA_Node* pFormRoot = pFormPacketNode->GetFirstChildByClass(XFA_ELEMENT_Subform); if (!pFormRoot) { return -1; } if (!m_pLayoutPageMgr) { m_pLayoutPageMgr = new CXFA_LayoutPageMgr(this); } if (!m_pLayoutPageMgr->InitLayoutPage(pFormRoot)) { return -1; } if (!m_pLayoutPageMgr->PrepareFirstPage(pFormRoot)) { return -1; } m_pRootItemLayoutProcessor = new CXFA_ItemLayoutProcessor(pFormRoot, m_pLayoutPageMgr); m_nProgressCounter = 1; return 0; }
void CXFA_FFDocView::ResetWidgetData(CXFA_WidgetAcc* pWidgetAcc) { m_bLayoutEvent = TRUE; FX_BOOL bChanged = FALSE; CXFA_Node* pFormNode = NULL; if (pWidgetAcc) { bChanged = ResetSingleWidgetAccData(pWidgetAcc); pFormNode = pWidgetAcc->GetNode(); } else { pFormNode = GetRootSubform(); } if (!pFormNode) { return; } if (pFormNode->GetClassID() != XFA_ELEMENT_Field && pFormNode->GetClassID() != XFA_ELEMENT_ExclGroup) { CXFA_WidgetAccIterator Iterator(this, pFormNode); while (CXFA_WidgetAcc* pAcc = Iterator.MoveToNext()) { bChanged |= ResetSingleWidgetAccData(pAcc); if (pAcc->GetNode()->GetClassID() == XFA_ELEMENT_ExclGroup) { Iterator.SkipTree(); } } } if (bChanged) { m_pDoc->GetDocProvider()->SetChangeMark(m_pDoc); } }
FX_BOOL CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) { if (!pScriptNode) return FALSE; if (pScriptNode->GetElementType() != XFA_Element::Script) return TRUE; CXFA_Node* pParent = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); if (!pParent || pParent->GetElementType() != XFA_Element::Variables) return FALSE; if (m_mapVariableToContext.GetValueAt(pScriptNode)) return TRUE; CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); if (!pTextNode) return FALSE; CFX_WideStringC wsScript; if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript)) return FALSE; CFX_ByteString btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); std::unique_ptr<CFXJSE_Value> hRetValue(new CFXJSE_Value(m_pIsolate)); CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent); CFXJSE_Context* pVariablesContext = CreateVariablesContext(pScriptNode, pThisObject); CXFA_Object* pOriginalObject = m_pThisObject; m_pThisObject = pThisObject; FX_BOOL bRet = pVariablesContext->ExecuteScript(btScript.c_str(), hRetValue.get()); m_pThisObject = pOriginalObject; return bRet; }
void CScript_LayoutPseudoModel::Script_LayoutPseudoModel_NumberedPageCount( CFXJSE_Arguments* pArguments, FX_BOOL bNumbered) { IXFA_DocLayout* pDocLayout = m_pDocument->GetDocLayout(); if (!pDocLayout) { return; } int32_t iPageCount = 0; int32_t iPageNum = pDocLayout->CountPages(); if (bNumbered) { for (int32_t i = 0; i < iPageNum; i++) { IXFA_LayoutPage* pLayoutPage = pDocLayout->GetPage(i); if (!pLayoutPage) { continue; } CXFA_Node* pMasterPage = pLayoutPage->GetMasterPage(); if (pMasterPage->GetInteger(XFA_ATTRIBUTE_Numbered)) { iPageCount++; } } } else { iPageCount = iPageNum; } FXJSE_HVALUE hValue = pArguments->GetReturnValue(); if (hValue) { FXJSE_Value_SetInteger(hValue, iPageCount); } }
void CScript_LayoutPseudoModel::NumberedPageCount(CFXJSE_Arguments* pArguments, FX_BOOL bNumbered) { CXFA_LayoutProcessor* pDocLayout = m_pDocument->GetDocLayout(); if (!pDocLayout) { return; } int32_t iPageCount = 0; int32_t iPageNum = pDocLayout->CountPages(); if (bNumbered) { for (int32_t i = 0; i < iPageNum; i++) { CXFA_ContainerLayoutItem* pLayoutPage = pDocLayout->GetPage(i); if (!pLayoutPage) { continue; } CXFA_Node* pMasterPage = pLayoutPage->GetMasterPage(); if (pMasterPage->GetInteger(XFA_ATTRIBUTE_Numbered)) { iPageCount++; } } } else { iPageCount = iPageNum; } CFXJSE_Value* pValue = pArguments->GetReturnValue(); if (pValue) pValue->SetInteger(iPageCount); }
int32_t CXFA_LayoutProcessor::StartLayout(bool bForceRestart) { if (!bForceRestart && !IsNeedLayout()) return 100; m_pRootItemLayoutProcessor.reset(); m_nProgressCounter = 0; CXFA_Node* pFormPacketNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Form)); if (!pFormPacketNode) return -1; CXFA_Node* pFormRoot = pFormPacketNode->GetFirstChildByClass(XFA_Element::Subform); if (!pFormRoot) return -1; if (!m_pLayoutPageMgr) m_pLayoutPageMgr = pdfium::MakeUnique<CXFA_LayoutPageMgr>(this); if (!m_pLayoutPageMgr->InitLayoutPage(pFormRoot)) return -1; if (!m_pLayoutPageMgr->PrepareFirstPage(pFormRoot)) return -1; m_pRootItemLayoutProcessor = pdfium::MakeUnique<CXFA_ItemLayoutProcessor>( pFormRoot, m_pLayoutPageMgr.get()); m_nProgressCounter = 1; return 0; }
void CXFA_Fill::SetColor(FX_ARGB color) { CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_Element::Color); CFX_WideString wsColor; int a, r, g, b; ArgbDecode(color, a, r, g, b); wsColor.Format(L"%d,%d,%d", r, g, b); pNode->SetCData(XFA_ATTRIBUTE_Value, wsColor); }
uint32_t CXFA_FFField::UpdateUIProperty() { CXFA_Node* pUiNode = m_pDataAcc->GetUIChild(); uint32_t dwStyle = 0; if (pUiNode && pUiNode->GetElementType() == XFA_Element::DefaultUi) { dwStyle = FWL_STYLEEXT_EDT_ReadOnly; } return dwStyle; }
CXFA_Node* CXFA_FFDocView::GetRootSubform() { CXFA_Node* pFormPacketNode = ToNode(m_pDoc->GetXFADoc()->GetXFAObject(XFA_HASHCODE_Form)); if (!pFormPacketNode) { return NULL; } return pFormPacketNode->GetFirstChildByClass(XFA_ELEMENT_Subform); }
CJS_Result CJX_Field::clearItems( CFX_V8* runtime, const std::vector<v8::Local<v8::Value>>& params) { CXFA_Node* node = GetXFANode(); if (node->IsWidgetReady()) node->DeleteItem(-1, true, false); return CJS_Result::Success(); }
void CXFA_Calculate::GetMessageText(CFX_WideString& wsMessage) { CXFA_Node* pNode = m_pNode->GetChild(0, XFA_Element::Message); if (!pNode) return; CXFA_Text text(pNode->GetChild(0, XFA_Element::Text)); if (text) text.GetContent(wsMessage); }
int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_Asterisk( CXFA_ResolveNodesData& rnd) { CXFA_Node* curNode = ToNode(rnd.m_CurNode); CXFA_ObjArray& nodes = rnd.m_Nodes; CXFA_NodeArray array; curNode->GetNodeList(array, XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties); nodes.Append((CXFA_ObjArray&)array); return nodes.GetSize(); }
CXFA_Node* CXFA_NodeList::NamedItem(const CFX_WideStringC& wsName) { uint32_t dwHashCode = FX_HashCode_GetW(wsName, false); int32_t iCount = GetLength(); for (int32_t i = 0; i < iCount; i++) { CXFA_Node* ret = Item(i); if (dwHashCode == ret->GetNameHash()) return ret; } return nullptr; }
XFA_Element CXFA_Fill::GetFillType() { CXFA_Node* pChild = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); while (pChild) { XFA_Element eType = pChild->GetElementType(); if (eType != XFA_Element::Color && eType != XFA_Element::Extras) return eType; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); } return XFA_Element::Solid; }
void CScript_LayoutPseudoModel::Relayout(CFXJSE_Arguments* pArguments) { CXFA_Node* pRootNode = m_pDocument->GetRoot(); CXFA_Node* pFormRoot = pRootNode->GetFirstChildByClass(XFA_Element::Form); ASSERT(pFormRoot); CXFA_Node* pContentRootNode = pFormRoot->GetNodeItem(XFA_NODEITEM_FirstChild); CXFA_LayoutProcessor* pLayoutProcessor = m_pDocument->GetLayoutProcessor(); if (pContentRootNode) { pLayoutProcessor->AddChangedContainer(pContentRootNode); } pLayoutProcessor->SetForceReLayout(TRUE); }
int32_t CXFA_Fill::GetPattern(FX_ARGB& foreColor) { CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_Element::Pattern); if (CXFA_Node* pColor = pNode->GetChild(0, XFA_Element::Color)) { CFX_WideStringC wsColor; pColor->TryCData(XFA_ATTRIBUTE_Value, wsColor, false); foreColor = CXFA_Data::ToColor(wsColor); } else { foreColor = 0xFF000000; } return pNode->GetEnum(XFA_ATTRIBUTE_Type); }
CXFA_WidgetAcc* CXFA_WidgetAccIterator::MoveToNext() { CXFA_Node* pItem = m_pCurWidgetAcc ? m_ContentIterator.MoveToNext() : m_ContentIterator.GetCurrent(); while (pItem) { m_pCurWidgetAcc = static_cast<CXFA_WidgetAcc*>(pItem->GetWidgetData()); if (m_pCurWidgetAcc) return m_pCurWidgetAcc; pItem = m_ContentIterator.MoveToNext(); } return nullptr; }
CXFA_WidgetAcc* CXFA_WidgetAccIterator::MoveToNext() { CXFA_Node* pItem = m_pCurWidgetAcc ? m_ContentIterator.MoveToNext() : m_ContentIterator.GetCurrent(); while (pItem) { if ((m_pCurWidgetAcc = (CXFA_WidgetAcc*)pItem->GetWidgetData()) != NULL) { return m_pCurWidgetAcc; } pItem = m_ContentIterator.MoveToNext(); } return NULL; }
CXFA_Node* CXFA_FFWidgetHandler::CreateFormItem(XFA_ELEMENT eElement, CXFA_Node* pParent, CXFA_Node* pBefore) const { CXFA_Node* pTemplateParent = pParent != NULL ? pParent->GetTemplateNode() : NULL; CXFA_Node* pNewFormItem = pTemplateParent->CloneTemplateToForm(FALSE); if (pParent != NULL) { pParent->InsertChild(pNewFormItem, pBefore); } return pNewFormItem; }