diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-11-14 21:29:35 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-11-14 21:29:35 +0000 |
commit | 4011677aed8b258fcf87cf52b0d541ef04c832ff (patch) | |
tree | dc5f8124fc0e81c15213e4b0ebeecc83c96049d7 /fxjs | |
parent | aee28693976cc246eea8230a999906802e52cab7 (diff) | |
download | pdfium-4011677aed8b258fcf87cf52b0d541ef04c832ff.tar.xz |
Move code out of xfa_utilschromium/3271chromium/3270chromium/3269
This CL splits the node template out of xfa_utils into its own file. The
XFA_ByteStringToDouble method was moved to the only calling file.
Change-Id: I85fb2dfa3afc4a675ec69574e32d643c0dca731f
Reviewed-on: https://pdfium-review.googlesource.com/18490
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/cfxjse_formcalc_context.cpp | 92 | ||||
-rw-r--r-- | fxjs/cjx_layoutpseudomodel.cpp | 2 |
2 files changed, 90 insertions, 4 deletions
diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp index 55fab55722..30fa18737b 100644 --- a/fxjs/cfxjse_formcalc_context.cpp +++ b/fxjs/cfxjse_formcalc_context.cpp @@ -532,6 +532,90 @@ ByteString GUIDString(bool bSeparator) { return bsStr; } +double ByteStringToDouble(const ByteStringView& szStringVal) { + WideString wsValue = WideString::FromUTF8(szStringVal); + wsValue.TrimLeft(); + wsValue.TrimRight(); + + int32_t cc = 0; + bool bNegative = false; + + const wchar_t* str = wsValue.c_str(); + int32_t len = wsValue.GetLength(); + if (str[0] == '+') { + cc++; + } else if (str[0] == '-') { + bNegative = true; + cc++; + } + + int32_t nIntegralLen = 0; + int64_t nIntegral = 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; + double fraction = 0.0; + uint32_t dwFractional = 0; + if (cc < len && str[cc] == '.') { + cc++; + while (cc < len) { + fraction += XFA_GetFractionalScale(scale) * (str[cc] - '0'); + scale++; + cc++; + if (cc == len) + break; + if (scale == XFA_GetMaxFractionalScale() || str[cc] == 'E' || + str[cc] == 'e') { + break; + } + if (!FXSYS_isDecimalDigit(str[cc])) + return 0; + } + dwFractional = static_cast<uint32_t>(fraction * 4294967296.0); + } + + int32_t nExponent = 0; + bool bExpSign = false; + 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; + } + + double dValue = dwFractional / 4294967296.0; + dValue = nIntegral + (nIntegral >= 0 ? dValue : -dValue); + if (nExponent != 0) + dValue *= FXSYS_pow(10, static_cast<float>(nExponent)); + + return dValue; +} + } // namespace // static @@ -6005,8 +6089,10 @@ float CFXJSE_FormCalcContext::ValueToFloat(CFXJSE_Value* pThis, GetObjectDefaultValue(arg, newPropertyValue.get()); return ValueToFloat(pThis, newPropertyValue.get()); } - if (arg->IsString()) - return (float)XFA_ByteStringToDouble(arg->ToString().AsStringView()); + if (arg->IsString()) { + return static_cast<float>( + ByteStringToDouble(arg->ToString().AsStringView())); + } if (arg->IsUndefined()) return 0; @@ -6040,7 +6126,7 @@ double CFXJSE_FormCalcContext::ValueToDouble(CFXJSE_Value* pThis, return ValueToDouble(pThis, newPropertyValue.get()); } if (arg->IsString()) - return XFA_ByteStringToDouble(arg->ToString().AsStringView()); + return ByteStringToDouble(arg->ToString().AsStringView()); if (arg->IsUndefined()) return 0; return arg->ToDouble(); diff --git a/fxjs/cjx_layoutpseudomodel.cpp b/fxjs/cjx_layoutpseudomodel.cpp index 79e7fc8cf1..9767c15d3a 100644 --- a/fxjs/cjx_layoutpseudomodel.cpp +++ b/fxjs/cjx_layoutpseudomodel.cpp @@ -21,8 +21,8 @@ #include "xfa/fxfa/parser/cxfa_layoutprocessor.h" #include "xfa/fxfa/parser/cxfa_measurement.h" #include "xfa/fxfa/parser/cxfa_node.h" +#include "xfa/fxfa/parser/cxfa_nodeiteratortemplate.h" #include "xfa/fxfa/parser/cxfa_traversestrategy_contentlayoutitem.h" -#include "xfa/fxfa/parser/xfa_utils.h" CJX_LayoutPseudoModel::CJX_LayoutPseudoModel(CScript_LayoutPseudoModel* model) : CJX_Object(model) {} |