Chromium Code Reviews| 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 f5da036498dbe07bc741168521d91cf193bce4c5..25160edc07bf7a1c68c9f4f32e41edd8cffd20db 100644 |
| --- a/xfa/fxfa/parser/xfa_utils_imp.cpp |
| +++ b/xfa/fxfa/parser/xfa_utils_imp.cpp |
| @@ -16,133 +16,106 @@ |
| #include "xfa/fxfa/parser/xfa_parser.h" |
| #include "xfa/fxfa/parser/xfa_script.h" |
| -CXFA_Node* XFA_CreateUIChild(CXFA_Node* pNode, XFA_Element& eWidgetType) { |
| - XFA_Element eType = pNode->GetElementType(); |
| - eWidgetType = eType; |
| - if (eType != XFA_Element::Field && eType != XFA_Element::Draw) { |
| - return nullptr; |
| +namespace { |
| + |
| +const FX_DOUBLE fraction_scales[] = {0.1, |
|
Lei Zhang
2016/07/07 19:36:18
Needs Mario ASCII art.
dsinclair
2016/07/07 19:47:49
Acknowledged.
|
| + 0.01, |
| + 0.001, |
| + 0.0001, |
| + 0.00001, |
| + 0.000001, |
| + 0.0000001, |
| + 0.00000001, |
| + 0.000000001, |
| + 0.0000000001, |
| + 0.00000000001, |
| + 0.000000000001, |
| + 0.0000000000001, |
| + 0.00000000000001, |
| + 0.000000000000001, |
| + 0.0000000000000001}; |
| + |
| +FX_DOUBLE WideStringToDouble(const CFX_WideString& wsStringVal) { |
| + CFX_WideString wsValue = wsStringVal; |
| + wsValue.TrimLeft(); |
| + wsValue.TrimRight(); |
| + int64_t nIntegral = 0; |
| + uint32_t dwFractional = 0; |
| + int32_t nExponent = 0; |
| + int32_t cc = 0; |
| + FX_BOOL bNegative = FALSE, bExpSign = FALSE; |
|
Lei Zhang
2016/07/07 20:24:06
One per line, bool.
dsinclair
2016/07/11 13:22:39
Done.
|
| + const FX_WCHAR* str = wsValue.c_str(); |
| + int32_t len = wsValue.GetLength(); |
| + if (str[0] == '+') { |
| + cc++; |
| + } else if (str[0] == '-') { |
| + bNegative = TRUE; |
| + cc++; |
| } |
| - eWidgetType = XFA_Element::Unknown; |
| - XFA_Element eUIType = XFA_Element::Unknown; |
| - CXFA_Value defValue(pNode->GetProperty(0, XFA_Element::Value, TRUE)); |
| - XFA_Element eValueType = defValue.GetChildValueClassID(); |
| - switch (eValueType) { |
| - case XFA_Element::Boolean: |
| - eUIType = XFA_Element::CheckButton; |
| - break; |
| - case XFA_Element::Integer: |
| - case XFA_Element::Decimal: |
| - case XFA_Element::Float: |
| - eUIType = XFA_Element::NumericEdit; |
| - break; |
| - case XFA_Element::ExData: |
| - case XFA_Element::Text: |
| - eUIType = XFA_Element::TextEdit; |
| - eWidgetType = XFA_Element::Text; |
| - break; |
| - case XFA_Element::Date: |
| - case XFA_Element::Time: |
| - case XFA_Element::DateTime: |
| - eUIType = XFA_Element::DateTimeEdit; |
| - break; |
| - case XFA_Element::Image: |
| - eUIType = XFA_Element::ImageEdit; |
| - eWidgetType = XFA_Element::Image; |
| - break; |
| - case XFA_Element::Arc: |
| - case XFA_Element::Line: |
| - case XFA_Element::Rectangle: |
| - eUIType = XFA_Element::DefaultUi; |
| - eWidgetType = eValueType; |
| - break; |
| - default: |
| + int32_t nIntegralLen = 0; |
| + while (cc < len) { |
| + if (str[cc] == '.' || str[cc] == 'E' || str[cc] == 'e' || |
| + nIntegralLen > 17) { |
| break; |
| - } |
| - CXFA_Node* pUIChild = nullptr; |
| - CXFA_Node* pUI = pNode->GetProperty(0, XFA_Element::Ui, TRUE); |
| - CXFA_Node* pChild = pUI->GetNodeItem(XFA_NODEITEM_FirstChild); |
| - for (; pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| - XFA_Element eChildType = pChild->GetElementType(); |
| - if (eChildType == XFA_Element::Extras || |
| - eChildType == XFA_Element::Picture) { |
| - continue; |
| } |
| - const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( |
| - XFA_Element::Ui, eChildType, XFA_XDPPACKET_Form); |
| - if (pProperty && (pProperty->uFlags & XFA_PROPERTYFLAG_OneOf)) { |
| - pUIChild = pChild; |
| - break; |
| + if (!FXSYS_isDecimalDigit(str[cc])) { |
| + return 0; |
| } |
| + nIntegral = nIntegral * 10 + str[cc] - '0'; |
| + cc++; |
| + nIntegralLen++; |
| } |
| - if (eType == XFA_Element::Draw) { |
| - XFA_Element eDraw = |
| - pUIChild ? pUIChild->GetElementType() : XFA_Element::Unknown; |
| - switch (eDraw) { |
| - case XFA_Element::TextEdit: |
| - eWidgetType = XFA_Element::Text; |
| - break; |
| - case XFA_Element::ImageEdit: |
| - eWidgetType = XFA_Element::Image; |
| + nIntegral = bNegative ? -nIntegral : nIntegral; |
| + int32_t scale = 0; |
| + FX_DOUBLE fraction = 0.0; |
| + if (cc < len && str[cc] == '.') { |
| + cc++; |
| + while (cc < len) { |
| + fraction += fraction_scales[scale] * (str[cc] - '0'); |
| + scale++; |
| + cc++; |
| + if (cc == len) { |
| break; |
| - default: |
| - eWidgetType = eWidgetType == XFA_Element::Unknown ? XFA_Element::Text |
| - : eWidgetType; |
| + } |
| + if (scale == sizeof(fraction_scales) / sizeof(FX_DOUBLE) || |
| + str[cc] == 'E' || str[cc] == 'e') { |
| break; |
| + } |
| + if (!FXSYS_isDecimalDigit(str[cc])) { |
| + return 0; |
| + } |
| } |
| - } else { |
| - if (pUIChild && pUIChild->GetElementType() == XFA_Element::DefaultUi) { |
| - eWidgetType = XFA_Element::TextEdit; |
| - } else { |
| - eWidgetType = |
| - pUIChild ? pUIChild->GetElementType() |
| - : (eUIType == XFA_Element::Unknown ? XFA_Element::TextEdit |
| - : eUIType); |
| - } |
| + dwFractional = (uint32_t)(fraction * 4294967296.0); |
| } |
| - if (!pUIChild) { |
| - if (eUIType == XFA_Element::Unknown) { |
| - eUIType = XFA_Element::TextEdit; |
| - defValue.GetNode()->GetProperty(0, XFA_Element::Text, TRUE); |
| + if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) { |
| + cc++; |
| + if (cc < len) { |
| + if (str[cc] == '+') { |
| + cc++; |
| + } else if (str[cc] == '-') { |
| + bExpSign = TRUE; |
| + cc++; |
| + } |
| } |
| - pUIChild = pUI->GetProperty(0, eUIType, TRUE); |
| - } else if (eUIType == XFA_Element::Unknown) { |
| - switch (pUIChild->GetElementType()) { |
| - case XFA_Element::CheckButton: { |
| - eValueType = XFA_Element::Text; |
| - if (CXFA_Node* pItems = pNode->GetChild(0, XFA_Element::Items)) { |
| - if (CXFA_Node* pItem = pItems->GetChild(0, XFA_Element::Unknown)) { |
| - eValueType = pItem->GetElementType(); |
| - } |
| - } |
| - } break; |
| - case XFA_Element::DateTimeEdit: |
| - eValueType = XFA_Element::DateTime; |
| - break; |
| - case XFA_Element::ImageEdit: |
| - eValueType = XFA_Element::Image; |
| - break; |
| - case XFA_Element::NumericEdit: |
| - eValueType = XFA_Element::Float; |
| - break; |
| - case XFA_Element::ChoiceList: { |
| - eValueType = (pUIChild->GetEnum(XFA_ATTRIBUTE_Open) == |
| - XFA_ATTRIBUTEENUM_MultiSelect) |
| - ? XFA_Element::ExData |
| - : XFA_Element::Text; |
| - } break; |
| - case XFA_Element::Barcode: |
| - case XFA_Element::Button: |
| - case XFA_Element::PasswordEdit: |
| - case XFA_Element::Signature: |
| - case XFA_Element::TextEdit: |
| - default: |
| - eValueType = XFA_Element::Text; |
| - break; |
| + while (cc < len) { |
| + if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) { |
| + return 0; |
| + } |
| + nExponent = nExponent * 10 + str[cc] - '0'; |
| + cc++; |
| } |
| - defValue.GetNode()->GetProperty(0, eValueType, TRUE); |
| + nExponent = bExpSign ? -nExponent : nExponent; |
| } |
| - return pUIChild; |
| + FX_DOUBLE dValue = (dwFractional / 4294967296.0); |
| + dValue = nIntegral + (nIntegral >= 0 ? dValue : -dValue); |
| + if (nExponent != 0) { |
| + dValue *= FXSYS_pow(10, (FX_FLOAT)nExponent); |
| + } |
| + return dValue; |
| } |
| + |
| +} // namespace |
| + |
| CXFA_LocaleValue XFA_GetLocaleValue(CXFA_WidgetData* pWidgetData) { |
| CXFA_Node* pNodeValue = |
| pWidgetData->GetNode()->GetChild(0, XFA_Element::Value); |
| @@ -246,122 +219,10 @@ FX_BOOL XFA_FieldIsMultiListBox(CXFA_Node* pFieldNode) { |
| } |
| return bRet; |
| } |
| -FX_BOOL XFA_IsLayoutElement(XFA_Element eElement, FX_BOOL bLayoutContainer) { |
| - switch (eElement) { |
| - case XFA_Element::Draw: |
| - case XFA_Element::Field: |
| - case XFA_Element::InstanceManager: |
| - return !bLayoutContainer; |
| - case XFA_Element::Area: |
| - case XFA_Element::Subform: |
| - case XFA_Element::ExclGroup: |
| - case XFA_Element::SubformSet: |
| - case XFA_Element::PageArea: |
| - case XFA_Element::Form: |
| - return TRUE; |
| - default: |
| - return FALSE; |
| - } |
| -} |
| - |
| -static const FX_DOUBLE fraction_scales[] = {0.1, |
| - 0.01, |
| - 0.001, |
| - 0.0001, |
| - 0.00001, |
| - 0.000001, |
| - 0.0000001, |
| - 0.00000001, |
| - 0.000000001, |
| - 0.0000000001, |
| - 0.00000000001, |
| - 0.000000000001, |
| - 0.0000000000001, |
| - 0.00000000000001, |
| - 0.000000000000001, |
| - 0.0000000000000001}; |
| -FX_DOUBLE XFA_WideStringToDouble(const CFX_WideString& wsStringVal) { |
| - CFX_WideString wsValue = wsStringVal; |
| - wsValue.TrimLeft(); |
| - wsValue.TrimRight(); |
| - int64_t nIntegral = 0; |
| - uint32_t dwFractional = 0; |
| - int32_t nExponent = 0; |
| - int32_t cc = 0; |
| - FX_BOOL bNegative = FALSE, bExpSign = FALSE; |
| - const FX_WCHAR* str = wsValue.c_str(); |
| - int32_t len = wsValue.GetLength(); |
| - if (str[0] == '+') { |
| - cc++; |
| - } else if (str[0] == '-') { |
| - bNegative = TRUE; |
| - cc++; |
| - } |
| - int32_t nIntegralLen = 0; |
| - while (cc < len) { |
| - if (str[cc] == '.' || str[cc] == 'E' || str[cc] == 'e' || |
| - nIntegralLen > 17) { |
| - break; |
| - } |
| - if (!FXSYS_isDecimalDigit(str[cc])) { |
| - return 0; |
| - } |
| - nIntegral = nIntegral * 10 + str[cc] - '0'; |
| - cc++; |
| - nIntegralLen++; |
| - } |
| - nIntegral = bNegative ? -nIntegral : nIntegral; |
| - int32_t scale = 0; |
| - FX_DOUBLE fraction = 0.0; |
| - if (cc < len && str[cc] == '.') { |
| - cc++; |
| - while (cc < len) { |
| - fraction += fraction_scales[scale] * (str[cc] - '0'); |
| - scale++; |
| - cc++; |
| - if (cc == len) { |
| - break; |
| - } |
| - if (scale == sizeof(fraction_scales) / sizeof(FX_DOUBLE) || |
| - str[cc] == 'E' || str[cc] == 'e') { |
| - break; |
| - } |
| - if (!FXSYS_isDecimalDigit(str[cc])) { |
| - return 0; |
| - } |
| - } |
| - dwFractional = (uint32_t)(fraction * 4294967296.0); |
| - } |
| - if (cc < len && (str[cc] == 'E' || str[cc] == 'e')) { |
| - cc++; |
| - if (cc < len) { |
| - if (str[cc] == '+') { |
| - cc++; |
| - } else if (str[cc] == '-') { |
| - bExpSign = TRUE; |
| - cc++; |
| - } |
| - } |
| - while (cc < len) { |
| - if (str[cc] == '.' || !FXSYS_isDecimalDigit(str[cc])) { |
| - return 0; |
| - } |
| - nExponent = nExponent * 10 + str[cc] - '0'; |
| - cc++; |
| - } |
| - nExponent = bExpSign ? -nExponent : nExponent; |
| - } |
| - FX_DOUBLE dValue = (dwFractional / 4294967296.0); |
| - dValue = nIntegral + (nIntegral >= 0 ? dValue : -dValue); |
| - if (nExponent != 0) { |
| - dValue *= FXSYS_pow(10, (FX_FLOAT)nExponent); |
| - } |
| - return dValue; |
| -} |
| FX_DOUBLE XFA_ByteStringToDouble(const CFX_ByteStringC& szStringVal) { |
| CFX_WideString wsValue = CFX_WideString::FromUTF8(szStringVal); |
| - return XFA_WideStringToDouble(wsValue); |
| + return WideStringToDouble(wsValue); |
| } |
| int32_t XFA_MapRotation(int32_t nRotation) { |