| Index: xfa/fxfa/parser/xfa_utils_imp.cpp
|
| diff --git a/xfa/fxfa/parser/xfa_utils_imp.cpp b/xfa/fxfa/parser/xfa_utils_imp.cpp
|
| index 2f9c3e0d8cc39ebe5218b711c48a29ae6779ad6c..50438b7a096ec8c5f226862e163883530df08f25 100644
|
| --- a/xfa/fxfa/parser/xfa_utils_imp.cpp
|
| +++ b/xfa/fxfa/parser/xfa_utils_imp.cpp
|
| @@ -8,6 +8,8 @@
|
|
|
| #include "core/fxcrt/include/fx_ext.h"
|
| #include "xfa/fde/xml/fde_xml_imp.h"
|
| +#include "xfa/fxfa/parser/cxfa_measurement.h"
|
| +#include "xfa/fxfa/parser/xfa_basic_data.h"
|
| #include "xfa/fxfa/parser/xfa_doclayout.h"
|
| #include "xfa/fxfa/parser/xfa_document.h"
|
| #include "xfa/fxfa/parser/xfa_localemgr.h"
|
| @@ -202,11 +204,12 @@ void XFA_GetPlainTextFromRichText(CFDE_XMLNode* pXMLNode,
|
| XFA_GetPlainTextFromRichText(pChildXML, wsPlainText);
|
| }
|
| }
|
| +
|
| FX_BOOL XFA_FieldIsMultiListBox(CXFA_Node* pFieldNode) {
|
| FX_BOOL bRet = FALSE;
|
| - if (!pFieldNode) {
|
| + if (!pFieldNode)
|
| return bRet;
|
| - }
|
| +
|
| CXFA_Node* pUIChild = pFieldNode->GetChild(0, XFA_Element::Ui);
|
| if (pUIChild) {
|
| CXFA_Node* pFirstChild = pUIChild->GetNodeItem(XFA_NODEITEM_FirstChild);
|
| @@ -229,3 +232,256 @@ int32_t XFA_MapRotation(int32_t nRotation) {
|
| nRotation = nRotation < 0 ? nRotation + 360 : nRotation;
|
| return nRotation;
|
| }
|
| +
|
| +const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName(
|
| + XFA_Element eElement,
|
| + const CFX_WideStringC& wsAttributeName) {
|
| + if (wsAttributeName.IsEmpty())
|
| + return nullptr;
|
| +
|
| + int32_t iElementIndex = static_cast<int32_t>(eElement);
|
| + while (iElementIndex != -1) {
|
| + const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex;
|
| + int32_t icount = scriptIndex->wAttributeCount;
|
| + if (icount == 0) {
|
| + iElementIndex = scriptIndex->wParentIndex;
|
| + continue;
|
| + }
|
| + uint32_t uHash = FX_HashCode_GetW(wsAttributeName, false);
|
| + int32_t iStart = scriptIndex->wAttributeStart, iEnd = iStart + icount - 1;
|
| + do {
|
| + int32_t iMid = (iStart + iEnd) / 2;
|
| + const XFA_SCRIPTATTRIBUTEINFO* pInfo = g_SomAttributeData + iMid;
|
| + if (uHash == pInfo->uHash)
|
| + return pInfo;
|
| + if (uHash < pInfo->uHash)
|
| + iEnd = iMid - 1;
|
| + else
|
| + iStart = iMid + 1;
|
| + } while (iStart <= iEnd);
|
| + iElementIndex = scriptIndex->wParentIndex;
|
| + }
|
| + return nullptr;
|
| +}
|
| +
|
| +const XFA_NOTSUREATTRIBUTE* XFA_GetNotsureAttribute(XFA_Element eElement,
|
| + XFA_ATTRIBUTE eAttribute,
|
| + XFA_ATTRIBUTETYPE eType) {
|
| + int32_t iStart = 0, iEnd = g_iXFANotsureCount - 1;
|
| + do {
|
| + int32_t iMid = (iStart + iEnd) / 2;
|
| + const XFA_NOTSUREATTRIBUTE* pAttr = g_XFANotsureAttributes + iMid;
|
| + if (eElement == pAttr->eElement) {
|
| + if (pAttr->eAttribute == eAttribute) {
|
| + if (eType == XFA_ATTRIBUTETYPE_NOTSURE || eType == pAttr->eType)
|
| + return pAttr;
|
| + return nullptr;
|
| + }
|
| + int32_t iBefore = iMid - 1;
|
| + if (iBefore >= 0) {
|
| + pAttr = g_XFANotsureAttributes + iBefore;
|
| + while (eElement == pAttr->eElement) {
|
| + if (pAttr->eAttribute == eAttribute) {
|
| + if (eType == XFA_ATTRIBUTETYPE_NOTSURE || eType == pAttr->eType)
|
| + return pAttr;
|
| + return nullptr;
|
| + }
|
| + iBefore--;
|
| + if (iBefore < 0)
|
| + break;
|
| +
|
| + pAttr = g_XFANotsureAttributes + iBefore;
|
| + }
|
| + }
|
| +
|
| + int32_t iAfter = iMid + 1;
|
| + if (iAfter <= g_iXFANotsureCount - 1) {
|
| + pAttr = g_XFANotsureAttributes + iAfter;
|
| + while (eElement == pAttr->eElement) {
|
| + if (pAttr->eAttribute == eAttribute) {
|
| + if (eType == XFA_ATTRIBUTETYPE_NOTSURE || eType == pAttr->eType)
|
| + return pAttr;
|
| + return nullptr;
|
| + }
|
| + iAfter++;
|
| + if (iAfter > g_iXFANotsureCount - 1)
|
| + break;
|
| +
|
| + pAttr = g_XFANotsureAttributes + iAfter;
|
| + }
|
| + }
|
| + return nullptr;
|
| + }
|
| +
|
| + if (eElement < pAttr->eElement)
|
| + iEnd = iMid - 1;
|
| + else
|
| + iStart = iMid + 1;
|
| + } while (iStart <= iEnd);
|
| + return nullptr;
|
| +}
|
| +
|
| +const XFA_PROPERTY* XFA_GetPropertyOfElement(XFA_Element eElement,
|
| + XFA_Element eProperty,
|
| + uint32_t dwPacket) {
|
| + int32_t iCount = 0;
|
| + const XFA_PROPERTY* pProperties = XFA_GetElementProperties(eElement, iCount);
|
| + if (!pProperties || iCount < 1)
|
| + return nullptr;
|
| +
|
| + auto it = std::find_if(pProperties, pProperties + iCount,
|
| + [eProperty](const XFA_PROPERTY& prop) {
|
| + return prop.eName == eProperty;
|
| + });
|
| + if (it == pProperties + iCount)
|
| + return nullptr;
|
| +
|
| + const XFA_ELEMENTINFO* pInfo = XFA_GetElementByID(eProperty);
|
| + ASSERT(pInfo);
|
| + if (dwPacket != XFA_XDPPACKET_UNKNOWN && !(dwPacket & pInfo->dwPackets))
|
| + return nullptr;
|
| + return it;
|
| +}
|
| +
|
| +const XFA_PROPERTY* XFA_GetElementProperties(XFA_Element eElement,
|
| + int32_t& iCount) {
|
| + if (eElement == XFA_Element::Unknown)
|
| + return nullptr;
|
| +
|
| + const XFA_ELEMENTHIERARCHY* pElement =
|
| + g_XFAElementPropertyIndex + static_cast<int32_t>(eElement);
|
| + iCount = pElement->wCount;
|
| + return g_XFAElementPropertyData + pElement->wStart;
|
| +}
|
| +
|
| +const uint8_t* XFA_GetElementAttributes(XFA_Element eElement, int32_t& iCount) {
|
| + if (eElement == XFA_Element::Unknown)
|
| + return nullptr;
|
| +
|
| + const XFA_ELEMENTHIERARCHY* pElement =
|
| + g_XFAElementAttributeIndex + static_cast<int32_t>(eElement);
|
| + iCount = pElement->wCount;
|
| + return g_XFAElementAttributeData + pElement->wStart;
|
| +}
|
| +
|
| +const XFA_ELEMENTINFO* XFA_GetElementByID(XFA_Element eName) {
|
| + return eName != XFA_Element::Unknown
|
| + ? g_XFAElementData + static_cast<int32_t>(eName)
|
| + : nullptr;
|
| +}
|
| +
|
| +XFA_Element XFA_GetElementTypeForName(const CFX_WideStringC& wsName) {
|
| + if (wsName.IsEmpty())
|
| + return XFA_Element::Unknown;
|
| +
|
| + uint32_t uHash = FX_HashCode_GetW(wsName, false);
|
| + const XFA_ELEMENTINFO* pEnd = g_XFAElementData + g_iXFAElementCount;
|
| + auto pInfo = std::lower_bound(g_XFAElementData, pEnd, uHash,
|
| + [](const XFA_ELEMENTINFO& info, uint32_t hash) {
|
| + return info.uHash < hash;
|
| + });
|
| + if (pInfo < pEnd && pInfo->uHash == uHash)
|
| + return pInfo->eName;
|
| + return XFA_Element::Unknown;
|
| +}
|
| +
|
| +CXFA_Measurement XFA_GetAttributeDefaultValue_Measure(XFA_Element eElement,
|
| + XFA_ATTRIBUTE eAttribute,
|
| + uint32_t dwPacket) {
|
| + void* pValue;
|
| + if (XFA_GetAttributeDefaultValue(pValue, eElement, eAttribute,
|
| + XFA_ATTRIBUTETYPE_Measure, dwPacket)) {
|
| + return *(CXFA_Measurement*)pValue;
|
| + }
|
| + return CXFA_Measurement();
|
| +}
|
| +
|
| +FX_BOOL XFA_GetAttributeDefaultValue(void*& pValue,
|
| + XFA_Element eElement,
|
| + XFA_ATTRIBUTE eAttribute,
|
| + XFA_ATTRIBUTETYPE eType,
|
| + uint32_t dwPacket) {
|
| + const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute);
|
| + if (!pInfo)
|
| + return FALSE;
|
| + if (dwPacket && (dwPacket & pInfo->dwPackets) == 0)
|
| + return FALSE;
|
| + if (pInfo->eType == eType) {
|
| + pValue = pInfo->pDefValue;
|
| + return TRUE;
|
| + }
|
| + if (pInfo->eType == XFA_ATTRIBUTETYPE_NOTSURE) {
|
| + const XFA_NOTSUREATTRIBUTE* pAttr =
|
| + XFA_GetNotsureAttribute(eElement, eAttribute, eType);
|
| + if (pAttr) {
|
| + pValue = pAttr->pValue;
|
| + return TRUE;
|
| + }
|
| + }
|
| + return FALSE;
|
| +}
|
| +
|
| +const XFA_ATTRIBUTEINFO* XFA_GetAttributeByName(const CFX_WideStringC& wsName) {
|
| + if (wsName.IsEmpty())
|
| + return nullptr;
|
| +
|
| + uint32_t uHash = FX_HashCode_GetW(wsName, false);
|
| + int32_t iStart = 0;
|
| + int32_t iEnd = g_iXFAAttributeCount - 1;
|
| + do {
|
| + int32_t iMid = (iStart + iEnd) / 2;
|
| + const XFA_ATTRIBUTEINFO* pInfo = g_XFAAttributeData + iMid;
|
| + if (uHash == pInfo->uHash)
|
| + return pInfo;
|
| + if (uHash < pInfo->uHash)
|
| + iEnd = iMid - 1;
|
| + else
|
| + iStart = iMid + 1;
|
| + } while (iStart <= iEnd);
|
| + return nullptr;
|
| +}
|
| +
|
| +const XFA_ATTRIBUTEINFO* XFA_GetAttributeByID(XFA_ATTRIBUTE eName) {
|
| + return (eName < g_iXFAAttributeCount) ? (g_XFAAttributeData + eName)
|
| + : nullptr;
|
| +}
|
| +
|
| +const XFA_ATTRIBUTEENUMINFO* XFA_GetAttributeEnumByName(
|
| + const CFX_WideStringC& wsName) {
|
| + if (wsName.IsEmpty())
|
| + return nullptr;
|
| +
|
| + uint32_t uHash = FX_HashCode_GetW(wsName, false);
|
| + int32_t iStart = 0;
|
| + int32_t iEnd = g_iXFAEnumCount - 1;
|
| + do {
|
| + int32_t iMid = (iStart + iEnd) / 2;
|
| + const XFA_ATTRIBUTEENUMINFO* pInfo = g_XFAEnumData + iMid;
|
| + if (uHash == pInfo->uHash)
|
| + return pInfo;
|
| + if (uHash < pInfo->uHash)
|
| + iEnd = iMid - 1;
|
| + else
|
| + iStart = iMid + 1;
|
| + } while (iStart <= iEnd);
|
| + return nullptr;
|
| +}
|
| +
|
| +const XFA_PACKETINFO* XFA_GetPacketByIndex(XFA_PACKET ePacket) {
|
| + return g_XFAPacketData + ePacket;
|
| +}
|
| +
|
| +const XFA_PACKETINFO* XFA_GetPacketByID(uint32_t dwPacket) {
|
| + int32_t iStart = 0, iEnd = g_iXFAPacketCount - 1;
|
| + do {
|
| + int32_t iMid = (iStart + iEnd) / 2;
|
| + uint32_t dwFind = (g_XFAPacketData + iMid)->eName;
|
| + if (dwPacket == dwFind)
|
| + return g_XFAPacketData + iMid;
|
| + if (dwPacket < dwFind)
|
| + iEnd = iMid - 1;
|
| + else
|
| + iStart = iMid + 1;
|
| + } while (iStart <= iEnd);
|
| + return nullptr;
|
| +}
|
|
|