Move XFA-only fxcrt/ files to fgas/layout/ or fgas/crt.

Version cf1eb5a35107f25e5fbf1922a55264df79256d16 removed the last
entanglement between these components, so that they can now be
fully separated without introducing layering violations.

Version 0657332329cba8d5fbf7e694929d768da3524e8b avoid new circular
dependencies from forming as a result of this CL.

Rename the one fgas/crt file to have cfgas_ prefix to match
existing ones.

Change-Id: Idaf18c6b3768f51c184d68406425a006960e9e17
Reviewed-on: https://pdfium-review.googlesource.com/c/48231
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/BUILD.gn b/core/fxcrt/BUILD.gn
index a649346..de32771 100644
--- a/core/fxcrt/BUILD.gn
+++ b/core/fxcrt/BUILD.gn
@@ -116,19 +116,6 @@
       "cfx_fileaccess_windows.h",
     ]
   }
-  if (pdf_enable_xfa) {
-    sources += [
-      "cfx_char.cpp",
-      "cfx_char.h",
-      "cfx_decimal.cpp",
-      "cfx_decimal.h",
-      "fx_arabic.cpp",
-      "fx_arabic.h",
-      "fx_linebreak.cpp",
-      "fx_linebreak.h",
-      "locale_iface.h",
-    ]
-  }
 }
 
 if (pdf_enable_xfa) {
diff --git a/core/fxcrt/cfx_decimal.h b/core/fxcrt/cfx_decimal.h
deleted file mode 100644
index 6542eee..0000000
--- a/core/fxcrt/cfx_decimal.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef CORE_FXCRT_CFX_DECIMAL_H_
-#define CORE_FXCRT_CFX_DECIMAL_H_
-
-#include "core/fxcrt/fx_string.h"
-
-class CFX_Decimal {
- public:
-  CFX_Decimal();
-  explicit CFX_Decimal(uint32_t val);
-  explicit CFX_Decimal(uint64_t val);
-  explicit CFX_Decimal(int32_t val);
-  CFX_Decimal(float val, uint8_t scale);
-  explicit CFX_Decimal(WideStringView str);
-
-  operator WideString() const;
-  operator double() const;
-
-  CFX_Decimal operator*(const CFX_Decimal& val) const;
-  CFX_Decimal operator/(const CFX_Decimal& val) const;
-
-  void SetScale(uint8_t newScale);
-  uint8_t GetScale();
-  void SetNegate();
-
- private:
-  CFX_Decimal(uint32_t hi, uint32_t mid, uint32_t lo, bool neg, uint8_t scale);
-  bool IsNotZero() const { return m_uHi || m_uMid || m_uLo; }
-  void Swap(CFX_Decimal& val);
-
-  uint32_t m_uHi;
-  uint32_t m_uLo;
-  uint32_t m_uMid;
-  uint32_t m_uFlags;
-};
-
-#endif  // CORE_FXCRT_CFX_DECIMAL_H_
diff --git a/fxjs/BUILD.gn b/fxjs/BUILD.gn
index a8d850d..e4435b3 100644
--- a/fxjs/BUILD.gn
+++ b/fxjs/BUILD.gn
@@ -440,7 +440,11 @@
         "xfa/fxjse.h",
         "xfa/jse_define.h",
       ]
-      deps += [ "../xfa/fxfa/fm2js" ]
+      deps += [
+        "../xfa/fgas",
+        "../xfa/fgas/layout",
+        "../xfa/fxfa/fm2js",
+      ]
     }
   }
 }
diff --git a/fxjs/DEPS b/fxjs/DEPS
index 4cc93f9..bea61c1 100644
--- a/fxjs/DEPS
+++ b/fxjs/DEPS
@@ -7,5 +7,4 @@
   '+public',
   '+fpdfsdk',
   '+v8/include',
-  '+xfa/fxfa'
 ]
diff --git a/fxjs/xfa/DEPS b/fxjs/xfa/DEPS
new file mode 100644
index 0000000..5f8b44a
--- /dev/null
+++ b/fxjs/xfa/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+  '+xfa/fgas',
+  '+xfa/fxfa'
+]
diff --git a/fxjs/xfa/cfxjse_formcalc_context.cpp b/fxjs/xfa/cfxjse_formcalc_context.cpp
index 4aa537f..4b8a73f 100644
--- a/fxjs/xfa/cfxjse_formcalc_context.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context.cpp
@@ -11,11 +11,9 @@
 #include <string>
 #include <utility>
 
-#include "core/fxcrt/cfx_decimal.h"
 #include "core/fxcrt/cfx_widetextbuf.h"
 #include "core/fxcrt/fx_extension.h"
 #include "core/fxcrt/fx_random.h"
-#include "core/fxcrt/locale_iface.h"
 #include "fxjs/xfa/cfxjse_arguments.h"
 #include "fxjs/xfa/cfxjse_class.h"
 #include "fxjs/xfa/cfxjse_context.h"
@@ -24,6 +22,8 @@
 #include "fxjs/xfa/cjx_object.h"
 #include "third_party/base/ptr_util.h"
 #include "third_party/base/stl_util.h"
+#include "xfa/fgas/crt/cfgas_decimal.h"
+#include "xfa/fgas/crt/locale_iface.h"
 #include "xfa/fxfa/cxfa_ffnotify.h"
 #include "xfa/fxfa/fm2js/cxfa_fmparser.h"
 #include "xfa/fxfa/fm2js/cxfa_fmtojavascriptdepth.h"
@@ -1753,7 +1753,7 @@
     uPrecision = static_cast<uint8_t>(pdfium::clamp(dPrecision, 0.0, 12.0));
   }
 
-  CFX_Decimal decimalValue(static_cast<float>(dValue), uPrecision);
+  CFGAS_Decimal decimalValue(static_cast<float>(dValue), uPrecision);
   args.GetReturnValue()->SetDouble(decimalValue);
 }
 
diff --git a/fxjs/xfa/cjx_field.cpp b/fxjs/xfa/cjx_field.cpp
index c432ede..2bc5924 100644
--- a/fxjs/xfa/cjx_field.cpp
+++ b/fxjs/xfa/cjx_field.cpp
@@ -8,10 +8,10 @@
 
 #include <vector>
 
-#include "core/fxcrt/cfx_decimal.h"
 #include "fxjs/cfx_v8.h"
 #include "fxjs/js_resources.h"
 #include "fxjs/xfa/cfxjse_value.h"
+#include "xfa/fgas/crt/cfgas_decimal.h"
 #include "xfa/fxfa/cxfa_eventparam.h"
 #include "xfa/fxfa/cxfa_ffnotify.h"
 #include "xfa/fxfa/fxfa.h"
@@ -278,7 +278,7 @@
         (pNode->JSObject()->GetInteger(XFA_Attribute::FracDigits) == -1)) {
       pValue->SetString(content.ToUTF8().AsStringView());
     } else {
-      CFX_Decimal decimal(content.AsStringView());
+      CFGAS_Decimal decimal(content.AsStringView());
       pValue->SetFloat((float)(double)decimal);
     }
   } else if (pNode && pNode->GetElementType() == XFA_Element::Integer) {
@@ -286,7 +286,7 @@
   } else if (pNode && pNode->GetElementType() == XFA_Element::Boolean) {
     pValue->SetBoolean(FXSYS_wtoi(content.c_str()) == 0 ? false : true);
   } else if (pNode && pNode->GetElementType() == XFA_Element::Float) {
-    CFX_Decimal decimal(content.AsStringView());
+    CFGAS_Decimal decimal(content.AsStringView());
     pValue->SetFloat((float)(double)decimal);
   } else {
     pValue->SetString(content.ToUTF8().AsStringView());
diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp
index 3451537..9bf80eb 100644
--- a/fxjs/xfa/cjx_object.cpp
+++ b/fxjs/xfa/cjx_object.cpp
@@ -8,7 +8,6 @@
 
 #include <tuple>
 
-#include "core/fxcrt/cfx_decimal.h"
 #include "core/fxcrt/fx_extension.h"
 #include "core/fxcrt/xml/cfx_xmlelement.h"
 #include "core/fxcrt/xml/cfx_xmltext.h"
@@ -22,6 +21,7 @@
 #include "third_party/base/compiler_specific.h"
 #include "third_party/base/ptr_util.h"
 #include "third_party/base/stl_util.h"
+#include "xfa/fgas/crt/cfgas_decimal.h"
 #include "xfa/fxfa/cxfa_ffnotify.h"
 #include "xfa/fxfa/cxfa_ffwidget.h"
 #include "xfa/fxfa/parser/cxfa_border.h"
@@ -1471,7 +1471,7 @@
   } else if (eType == XFA_Element::Integer) {
     pValue->SetInteger(FXSYS_wtoi(content.c_str()));
   } else if (eType == XFA_Element::Float || eType == XFA_Element::Decimal) {
-    CFX_Decimal decimal(content.AsStringView());
+    CFGAS_Decimal decimal(content.AsStringView());
     pValue->SetFloat((float)(double)decimal);
   } else {
     pValue->SetString(content.ToUTF8().AsStringView());
diff --git a/testing/fuzzers/pdf_bidi_fuzzer.cc b/testing/fuzzers/pdf_bidi_fuzzer.cc
index 276e3df..d531280 100644
--- a/testing/fuzzers/pdf_bidi_fuzzer.cc
+++ b/testing/fuzzers/pdf_bidi_fuzzer.cc
@@ -4,12 +4,12 @@
 
 #include <cstdint>
 
-#include "core/fxcrt/cfx_char.h"
 #include "core/fxcrt/widestring.h"
 #include "core/fxge/cfx_font.h"
 #include "third_party/base/ptr_util.h"
 #include "xfa/fgas/font/cfgas_fontmgr.h"
 #include "xfa/fgas/font/cfgas_gefont.h"
+#include "xfa/fgas/layout/cfx_char.h"
 #include "xfa/fgas/layout/cfx_rtfbreak.h"
 
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
diff --git a/xfa/fde/cfde_textout.h b/xfa/fde/cfde_textout.h
index d20d33b..b6b0127 100644
--- a/xfa/fde/cfde_textout.h
+++ b/xfa/fde/cfde_textout.h
@@ -11,11 +11,11 @@
 #include <memory>
 #include <vector>
 
-#include "core/fxcrt/cfx_char.h"
 #include "core/fxge/cfx_renderdevice.h"
 #include "core/fxge/fx_dib.h"
 #include "third_party/base/span.h"
 #include "xfa/fde/cfde_data.h"
+#include "xfa/fgas/layout/cfx_char.h"
 
 class CFDE_RenderDevice;
 class CFGAS_GEFont;
diff --git a/xfa/fgas/BUILD.gn b/xfa/fgas/BUILD.gn
index 37c94f6..8099775 100644
--- a/xfa/fgas/BUILD.gn
+++ b/xfa/fgas/BUILD.gn
@@ -10,8 +10,11 @@
 
 jumbo_source_set("fgas") {
   sources = [
+    "crt/cfgas_decimal.cpp",
+    "crt/cfgas_decimal.h",
     "crt/cfgas_formatstring.cpp",
     "crt/cfgas_formatstring.h",
+    "crt/locale_iface.h",
     "font/cfgas_defaultfontmanager.cpp",
     "font/cfgas_defaultfontmanager.h",
     "font/cfgas_fontmgr.cpp",
diff --git a/core/fxcrt/cfx_decimal.cpp b/xfa/fgas/crt/cfgas_decimal.cpp
similarity index 89%
rename from core/fxcrt/cfx_decimal.cpp
rename to xfa/fgas/crt/cfgas_decimal.cpp
index 781aff5..f83d46f 100644
--- a/core/fxcrt/cfx_decimal.cpp
+++ b/xfa/fgas/crt/cfgas_decimal.cpp
@@ -4,7 +4,7 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#include "core/fxcrt/cfx_decimal.h"
+#include "xfa/fgas/crt/cfgas_decimal.h"
 
 #include <algorithm>
 #include <utility>
@@ -238,22 +238,22 @@
 
 }  // namespace
 
-CFX_Decimal::CFX_Decimal() : m_uHi(0), m_uLo(0), m_uMid(0), m_uFlags(0) {}
+CFGAS_Decimal::CFGAS_Decimal() : m_uHi(0), m_uLo(0), m_uMid(0), m_uFlags(0) {}
 
-CFX_Decimal::CFX_Decimal(uint64_t val)
+CFGAS_Decimal::CFGAS_Decimal(uint64_t val)
     : m_uHi(0),
       m_uLo(static_cast<uint32_t>(val)),
       m_uMid(static_cast<uint32_t>(FXMATH_DECIMAL_RSHIFT32BIT(val))),
       m_uFlags(0) {}
 
-CFX_Decimal::CFX_Decimal(uint32_t val)
+CFGAS_Decimal::CFGAS_Decimal(uint32_t val)
     : m_uHi(0), m_uLo(static_cast<uint32_t>(val)), m_uMid(0), m_uFlags(0) {}
 
-CFX_Decimal::CFX_Decimal(uint32_t lo,
-                         uint32_t mid,
-                         uint32_t hi,
-                         bool neg,
-                         uint8_t scale)
+CFGAS_Decimal::CFGAS_Decimal(uint32_t lo,
+                             uint32_t mid,
+                             uint32_t hi,
+                             bool neg,
+                             uint8_t scale)
     : m_uHi(hi),
       m_uLo(lo),
       m_uMid(mid),
@@ -261,16 +261,16 @@
           neg && IsNotZero(),
           (scale > FXMATH_DECIMAL_SCALELIMIT ? 0 : scale))) {}
 
-CFX_Decimal::CFX_Decimal(int32_t val) {
+CFGAS_Decimal::CFGAS_Decimal(int32_t val) {
   if (val >= 0) {
-    *this = CFX_Decimal(static_cast<uint32_t>(val));
+    *this = CFGAS_Decimal(static_cast<uint32_t>(val));
   } else {
-    *this = CFX_Decimal(static_cast<uint32_t>(-val));
+    *this = CFGAS_Decimal(static_cast<uint32_t>(-val));
     SetNegate();
   }
 }
 
-CFX_Decimal::CFX_Decimal(float val, uint8_t scale) {
+CFGAS_Decimal::CFGAS_Decimal(float val, uint8_t scale) {
   float newval = fabs(val);
   uint64_t phi;
   uint64_t pmid;
@@ -294,7 +294,7 @@
   m_uFlags = FXMATH_DECIMAL_MAKEFLAGS(val < 0 && IsNotZero(), scale);
 }
 
-CFX_Decimal::CFX_Decimal(WideStringView strObj) {
+CFGAS_Decimal::CFGAS_Decimal(WideStringView strObj) {
   const wchar_t* str = strObj.unterminated_c_str();
   const wchar_t* strBound = str + strObj.GetLength();
   bool pointmet = false;
@@ -329,7 +329,7 @@
   m_uFlags = FXMATH_DECIMAL_MAKEFLAGS(negmet && IsNotZero(), scale);
 }
 
-CFX_Decimal::operator WideString() const {
+CFGAS_Decimal::operator WideString() const {
   WideString retString;
   WideString tmpbuf;
   uint64_t phi = m_uHi;
@@ -355,7 +355,7 @@
   return retString;
 }
 
-CFX_Decimal::operator double() const {
+CFGAS_Decimal::operator double() const {
   double pow = (double)(1 << 16) * (1 << 16);
   double base = static_cast<double>(m_uHi) * pow * pow +
                 static_cast<double>(m_uMid) * pow + static_cast<double>(m_uLo);
@@ -364,7 +364,7 @@
   return (bNeg ? -1 : 1) * base * ::pow(10.0, -scale);
 }
 
-void CFX_Decimal::SetScale(uint8_t newscale) {
+void CFGAS_Decimal::SetScale(uint8_t newscale) {
   uint8_t oldscale = FXMATH_DECIMAL_FLAGS2SCALE(m_uFlags);
   if (newscale > oldscale) {
     uint64_t phi = m_uHi;
@@ -403,23 +403,23 @@
   }
 }
 
-uint8_t CFX_Decimal::GetScale() {
+uint8_t CFGAS_Decimal::GetScale() {
   return FXMATH_DECIMAL_FLAGS2SCALE(m_uFlags);
 }
 
-void CFX_Decimal::SetNegate() {
+void CFGAS_Decimal::SetNegate() {
   if (IsNotZero())
     m_uFlags ^= FXMATH_DECIMAL_NEGMASK;
 }
 
-void CFX_Decimal::Swap(CFX_Decimal& val) {
+void CFGAS_Decimal::Swap(CFGAS_Decimal& val) {
   std::swap(m_uHi, val.m_uHi);
   std::swap(m_uMid, val.m_uMid);
   std::swap(m_uLo, val.m_uLo);
   std::swap(m_uFlags, val.m_uFlags);
 }
 
-CFX_Decimal CFX_Decimal::operator*(const CFX_Decimal& val) const {
+CFGAS_Decimal CFGAS_Decimal::operator*(const CFGAS_Decimal& val) const {
   uint64_t a[3] = {m_uLo, m_uMid, m_uHi},
            b[3] = {val.m_uLo, val.m_uMid, val.m_uHi};
   uint64_t c[6];
@@ -429,13 +429,13 @@
   uint8_t scale = FXMATH_DECIMAL_FLAGS2SCALE(m_uFlags) +
                   FXMATH_DECIMAL_FLAGS2SCALE(val.m_uFlags);
   decimal_helper_shrinkintorange(c, 6, 3, scale);
-  return CFX_Decimal(static_cast<uint32_t>(c[0]), static_cast<uint32_t>(c[1]),
-                     static_cast<uint32_t>(c[2]), neg, scale);
+  return CFGAS_Decimal(static_cast<uint32_t>(c[0]), static_cast<uint32_t>(c[1]),
+                       static_cast<uint32_t>(c[2]), neg, scale);
 }
 
-CFX_Decimal CFX_Decimal::operator/(const CFX_Decimal& val) const {
+CFGAS_Decimal CFGAS_Decimal::operator/(const CFGAS_Decimal& val) const {
   if (!val.IsNotZero())
-    return CFX_Decimal();
+    return CFGAS_Decimal();
 
   bool neg = FXMATH_DECIMAL_FLAGS2NEG(m_uFlags) ^
              FXMATH_DECIMAL_FLAGS2NEG(val.m_uFlags);
@@ -456,7 +456,7 @@
 
   uint8_t minscale = scale;
   if (!IsNotZero())
-    return CFX_Decimal(0, 0, 0, 0, minscale);
+    return CFGAS_Decimal(0, 0, 0, 0, minscale);
 
   while (!a[6]) {
     decimal_helper_mul10_any(a, 7);
@@ -468,6 +468,6 @@
   decimal_helper_raw_div(a, 6, b, 3, c, 7);
   decimal_helper_shrinkintorange(c, 6, 3, scale);
   decimal_helper_truncate(c[2], c[1], c[0], scale, minscale);
-  return CFX_Decimal(static_cast<uint32_t>(c[0]), static_cast<uint32_t>(c[1]),
-                     static_cast<uint32_t>(c[2]), neg, scale);
+  return CFGAS_Decimal(static_cast<uint32_t>(c[0]), static_cast<uint32_t>(c[1]),
+                       static_cast<uint32_t>(c[2]), neg, scale);
 }
diff --git a/xfa/fgas/crt/cfgas_decimal.h b/xfa/fgas/crt/cfgas_decimal.h
new file mode 100644
index 0000000..e48e076
--- /dev/null
+++ b/xfa/fgas/crt/cfgas_decimal.h
@@ -0,0 +1,46 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef XFA_FGAS_CRT_CFGAS_DECIMAL_H_
+#define XFA_FGAS_CRT_CFGAS_DECIMAL_H_
+
+#include "core/fxcrt/fx_string.h"
+
+class CFGAS_Decimal {
+ public:
+  CFGAS_Decimal();
+  explicit CFGAS_Decimal(uint32_t val);
+  explicit CFGAS_Decimal(uint64_t val);
+  explicit CFGAS_Decimal(int32_t val);
+  CFGAS_Decimal(float val, uint8_t scale);
+  explicit CFGAS_Decimal(WideStringView str);
+
+  operator WideString() const;
+  operator double() const;
+
+  CFGAS_Decimal operator*(const CFGAS_Decimal& val) const;
+  CFGAS_Decimal operator/(const CFGAS_Decimal& val) const;
+
+  void SetScale(uint8_t newScale);
+  uint8_t GetScale();
+  void SetNegate();
+
+ private:
+  CFGAS_Decimal(uint32_t hi,
+                uint32_t mid,
+                uint32_t lo,
+                bool neg,
+                uint8_t scale);
+  bool IsNotZero() const { return m_uHi || m_uMid || m_uLo; }
+  void Swap(CFGAS_Decimal& val);
+
+  uint32_t m_uHi;
+  uint32_t m_uLo;
+  uint32_t m_uMid;
+  uint32_t m_uFlags;
+};
+
+#endif  // XFA_FGAS_CRT_CFGAS_DECIMAL_H_
diff --git a/xfa/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp
index f0adc7f..cc02425 100644
--- a/xfa/fgas/crt/cfgas_formatstring.cpp
+++ b/xfa/fgas/crt/cfgas_formatstring.cpp
@@ -10,8 +10,8 @@
 #include <utility>
 #include <vector>
 
-#include "core/fxcrt/cfx_decimal.h"
 #include "core/fxcrt/fx_extension.h"
+#include "xfa/fgas/crt/cfgas_decimal.h"
 #include "xfa/fxfa/parser/cxfa_localemgr.h"
 
 #define FX_LOCALECATEGORY_DateHash 0xbde9abde
@@ -1530,13 +1530,13 @@
       return false;
   }
   if (iExponent || bHavePercentSymbol) {
-    CFX_Decimal decimal = CFX_Decimal(wsValue->AsStringView());
+    CFGAS_Decimal decimal = CFGAS_Decimal(wsValue->AsStringView());
     if (iExponent) {
       decimal = decimal *
-                CFX_Decimal(FXSYS_pow(10, static_cast<float>(iExponent)), 3);
+                CFGAS_Decimal(FXSYS_pow(10, static_cast<float>(iExponent)), 3);
     }
     if (bHavePercentSymbol)
-      decimal = decimal / CFX_Decimal(100);
+      decimal = decimal / CFGAS_Decimal(100);
 
     *wsValue = decimal;
   }
@@ -1875,9 +1875,9 @@
   if (wsSrcNum.IsEmpty() || wsSrcNum[0] == '.')
     wsSrcNum.InsertAtFront('0');
 
-  CFX_Decimal decimal = CFX_Decimal(wsSrcNum.AsStringView());
+  CFGAS_Decimal decimal = CFGAS_Decimal(wsSrcNum.AsStringView());
   if (dwNumStyle & FX_NUMSTYLE_Percent) {
-    decimal = decimal * CFX_Decimal(100);
+    decimal = decimal * CFGAS_Decimal(100);
     wsSrcNum = decimal;
   }
 
@@ -1903,18 +1903,18 @@
       threshold *= 10;
       fixed_count--;
     }
-    if (decimal != CFX_Decimal(0)) {
-      if (decimal < CFX_Decimal(threshold)) {
-        decimal = decimal * CFX_Decimal(10);
+    if (decimal != CFGAS_Decimal(0)) {
+      if (decimal < CFGAS_Decimal(threshold)) {
+        decimal = decimal * CFGAS_Decimal(10);
         exponent = -1;
-        while (decimal < CFX_Decimal(threshold)) {
-          decimal = decimal * CFX_Decimal(10);
+        while (decimal < CFGAS_Decimal(threshold)) {
+          decimal = decimal * CFGAS_Decimal(10);
           exponent -= 1;
         }
-      } else if (decimal > CFX_Decimal(threshold)) {
+      } else if (decimal > CFGAS_Decimal(threshold)) {
         threshold *= 10;
-        while (decimal > CFX_Decimal(threshold)) {
-          decimal = decimal / CFX_Decimal(10);
+        while (decimal > CFGAS_Decimal(threshold)) {
+          decimal = decimal / CFGAS_Decimal(10);
           exponent += 1;
         }
       }
diff --git a/xfa/fgas/crt/cfgas_formatstring.h b/xfa/fgas/crt/cfgas_formatstring.h
index c581dda..5dab9ed 100644
--- a/xfa/fgas/crt/cfgas_formatstring.h
+++ b/xfa/fgas/crt/cfgas_formatstring.h
@@ -9,8 +9,8 @@
 
 #include <vector>
 
-#include "core/fxcrt/locale_iface.h"
 #include "core/fxcrt/unowned_ptr.h"
+#include "xfa/fgas/crt/locale_iface.h"
 
 class CXFA_LocaleMgr;
 
diff --git a/core/fxcrt/locale_iface.h b/xfa/fgas/crt/locale_iface.h
similarity index 94%
rename from core/fxcrt/locale_iface.h
rename to xfa/fgas/crt/locale_iface.h
index 7ee18d9..b5aecdb 100644
--- a/core/fxcrt/locale_iface.h
+++ b/xfa/fgas/crt/locale_iface.h
@@ -4,8 +4,8 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#ifndef CORE_FXCRT_LOCALE_IFACE_H_
-#define CORE_FXCRT_LOCALE_IFACE_H_
+#ifndef XFA_FGAS_CRT_LOCALE_IFACE_H_
+#define XFA_FGAS_CRT_LOCALE_IFACE_H_
 
 #include "core/fxcrt/cfx_datetime.h"
 #include "core/fxcrt/fx_string.h"
@@ -67,4 +67,4 @@
   virtual WideString GetNumPattern(FX_LOCALENUMSUBCATEGORY eType) const = 0;
 };
 
-#endif  // CORE_FXCRT_LOCALE_IFACE_H_
+#endif  // XFA_FGAS_CRT_LOCALE_IFACE_H_
diff --git a/xfa/fgas/layout/BUILD.gn b/xfa/fgas/layout/BUILD.gn
index 2749067..cc98267 100644
--- a/xfa/fgas/layout/BUILD.gn
+++ b/xfa/fgas/layout/BUILD.gn
@@ -16,10 +16,16 @@
     "cfx_breakline.h",
     "cfx_breakpiece.cpp",
     "cfx_breakpiece.h",
+    "cfx_char.cpp",
+    "cfx_char.h",
     "cfx_rtfbreak.cpp",
     "cfx_rtfbreak.h",
     "cfx_txtbreak.cpp",
     "cfx_txtbreak.h",
+    "fx_arabic.cpp",
+    "fx_arabic.h",
+    "fx_linebreak.cpp",
+    "fx_linebreak.h",
   ]
   deps = [
     "../:fgas",
diff --git a/xfa/fgas/layout/cfx_breakline.h b/xfa/fgas/layout/cfx_breakline.h
index feed4b7..e7635a5 100644
--- a/xfa/fgas/layout/cfx_breakline.h
+++ b/xfa/fgas/layout/cfx_breakline.h
@@ -9,8 +9,8 @@
 
 #include <vector>
 
-#include "core/fxcrt/cfx_char.h"
 #include "xfa/fgas/layout/cfx_breakpiece.h"
+#include "xfa/fgas/layout/cfx_char.h"
 
 class CFX_BreakLine {
  public:
diff --git a/xfa/fgas/layout/cfx_breakpiece.h b/xfa/fgas/layout/cfx_breakpiece.h
index 5dbc0e7..9b1ebd6 100644
--- a/xfa/fgas/layout/cfx_breakpiece.h
+++ b/xfa/fgas/layout/cfx_breakpiece.h
@@ -9,10 +9,10 @@
 
 #include <vector>
 
-#include "core/fxcrt/cfx_char.h"
 #include "core/fxcrt/fx_string.h"
 #include "core/fxcrt/retain_ptr.h"
 #include "core/fxcrt/unowned_ptr.h"
+#include "xfa/fgas/layout/cfx_char.h"
 #include "xfa/fxfa/cxfa_textuserdata.h"
 
 class CFX_BreakPiece {
diff --git a/core/fxcrt/cfx_char.cpp b/xfa/fgas/layout/cfx_char.cpp
similarity index 99%
rename from core/fxcrt/cfx_char.cpp
rename to xfa/fgas/layout/cfx_char.cpp
index 02d051f..311aff4 100644
--- a/core/fxcrt/cfx_char.cpp
+++ b/xfa/fgas/layout/cfx_char.cpp
@@ -4,7 +4,7 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#include "core/fxcrt/cfx_char.h"
+#include "xfa/fgas/layout/cfx_char.h"
 
 #include <algorithm>
 
diff --git a/core/fxcrt/cfx_char.h b/xfa/fgas/layout/cfx_char.h
similarity index 90%
rename from core/fxcrt/cfx_char.h
rename to xfa/fgas/layout/cfx_char.h
index e6c6978..ffd80ad 100644
--- a/core/fxcrt/cfx_char.h
+++ b/xfa/fgas/layout/cfx_char.h
@@ -4,16 +4,16 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#ifndef CORE_FXCRT_CFX_CHAR_H_
-#define CORE_FXCRT_CFX_CHAR_H_
+#ifndef XFA_FGAS_LAYOUT_CFX_CHAR_H_
+#define XFA_FGAS_LAYOUT_CFX_CHAR_H_
 
 #include <stdint.h>
 
 #include <vector>
 
-#include "core/fxcrt/fx_linebreak.h"
 #include "core/fxcrt/fx_unicode.h"
 #include "core/fxcrt/retain_ptr.h"
+#include "xfa/fgas/layout/fx_linebreak.h"
 
 enum class CFX_BreakType : uint8_t { None = 0, Piece, Line, Paragraph, Page };
 
@@ -52,4 +52,4 @@
   int32_t m_iVerticalScale;
 };
 
-#endif  // CORE_FXCRT_CFX_CHAR_H_
+#endif  // XFA_FGAS_LAYOUT_CFX_CHAR_H_
diff --git a/xfa/fgas/layout/cfx_rtfbreak.cpp b/xfa/fgas/layout/cfx_rtfbreak.cpp
index 40f73fb..be7f3f5 100644
--- a/xfa/fgas/layout/cfx_rtfbreak.cpp
+++ b/xfa/fgas/layout/cfx_rtfbreak.cpp
@@ -8,13 +8,13 @@
 
 #include <algorithm>
 
-#include "core/fxcrt/cfx_char.h"
-#include "core/fxcrt/fx_arabic.h"
-#include "core/fxcrt/fx_linebreak.h"
 #include "core/fxge/cfx_renderdevice.h"
 #include "third_party/base/numerics/safe_math.h"
 #include "third_party/base/stl_util.h"
 #include "xfa/fgas/font/cfgas_gefont.h"
+#include "xfa/fgas/layout/cfx_char.h"
+#include "xfa/fgas/layout/fx_arabic.h"
+#include "xfa/fgas/layout/fx_linebreak.h"
 
 CFX_RTFBreak::CFX_RTFBreak(uint32_t dwLayoutStyles)
     : CFX_Break(dwLayoutStyles),
diff --git a/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp b/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp
index 307fc8c..5bbfb4a 100644
--- a/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp
+++ b/xfa/fgas/layout/cfx_rtfbreak_unittest.cpp
@@ -9,7 +9,6 @@
 #include <memory>
 #include <utility>
 
-#include "core/fxcrt/cfx_char.h"
 #include "core/fxge/cfx_font.h"
 #include "core/fxge/cfx_gemodule.h"
 #include "testing/gtest/include/gtest/gtest.h"
@@ -17,6 +16,7 @@
 #include "third_party/base/ptr_util.h"
 #include "xfa/fgas/font/cfgas_fontmgr.h"
 #include "xfa/fgas/font/cfgas_gefont.h"
+#include "xfa/fgas/layout/cfx_char.h"
 
 class CFX_RTFBreakTest : public testing::Test {
  public:
diff --git a/xfa/fgas/layout/cfx_txtbreak.cpp b/xfa/fgas/layout/cfx_txtbreak.cpp
index acaf644..5f35cb7 100644
--- a/xfa/fgas/layout/cfx_txtbreak.cpp
+++ b/xfa/fgas/layout/cfx_txtbreak.cpp
@@ -8,12 +8,12 @@
 
 #include <algorithm>
 
-#include "core/fxcrt/cfx_char.h"
-#include "core/fxcrt/fx_arabic.h"
-#include "core/fxcrt/fx_linebreak.h"
 #include "core/fxge/cfx_renderdevice.h"
 #include "third_party/base/stl_util.h"
 #include "xfa/fgas/font/cfgas_gefont.h"
+#include "xfa/fgas/layout/cfx_char.h"
+#include "xfa/fgas/layout/fx_arabic.h"
+#include "xfa/fgas/layout/fx_linebreak.h"
 
 namespace {
 
diff --git a/xfa/fgas/layout/cfx_txtbreak.h b/xfa/fgas/layout/cfx_txtbreak.h
index 3cfd3a1..e9ed2d1 100644
--- a/xfa/fgas/layout/cfx_txtbreak.h
+++ b/xfa/fgas/layout/cfx_txtbreak.h
@@ -10,9 +10,9 @@
 #include <deque>
 #include <vector>
 
-#include "core/fxcrt/cfx_char.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "xfa/fgas/layout/cfx_break.h"
+#include "xfa/fgas/layout/cfx_char.h"
 
 class CFGAS_GEFont;
 class FXTEXT_CHARPOS;
diff --git a/xfa/fgas/layout/cfx_txtbreak_unittest.cpp b/xfa/fgas/layout/cfx_txtbreak_unittest.cpp
index 4b71df3..9dc4cc9 100644
--- a/xfa/fgas/layout/cfx_txtbreak_unittest.cpp
+++ b/xfa/fgas/layout/cfx_txtbreak_unittest.cpp
@@ -7,13 +7,13 @@
 #include <memory>
 #include <utility>
 
-#include "core/fxcrt/cfx_char.h"
 #include "core/fxge/cfx_font.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "testing/test_support.h"
 #include "third_party/base/ptr_util.h"
 #include "xfa/fgas/font/cfgas_fontmgr.h"
 #include "xfa/fgas/font/cfgas_gefont.h"
+#include "xfa/fgas/layout/cfx_char.h"
 
 class CFX_TxtBreakTest : public testing::Test {
  public:
diff --git a/core/fxcrt/fx_arabic.cpp b/xfa/fgas/layout/fx_arabic.cpp
similarity index 99%
rename from core/fxcrt/fx_arabic.cpp
rename to xfa/fgas/layout/fx_arabic.cpp
index a3d049a..886bb0d 100644
--- a/core/fxcrt/fx_arabic.cpp
+++ b/xfa/fgas/layout/fx_arabic.cpp
@@ -4,7 +4,7 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#include "core/fxcrt/fx_arabic.h"
+#include "xfa/fgas/layout/fx_arabic.h"
 
 #include <algorithm>
 #include <vector>
diff --git a/core/fxcrt/fx_arabic.h b/xfa/fgas/layout/fx_arabic.h
similarity index 79%
rename from core/fxcrt/fx_arabic.h
rename to xfa/fgas/layout/fx_arabic.h
index 6621649..ca33aa5 100644
--- a/core/fxcrt/fx_arabic.h
+++ b/xfa/fgas/layout/fx_arabic.h
@@ -4,11 +4,11 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#ifndef CORE_FXCRT_FX_ARABIC_H_
-#define CORE_FXCRT_FX_ARABIC_H_
+#ifndef XFA_FGAS_LAYOUT_FX_ARABIC_H_
+#define XFA_FGAS_LAYOUT_FX_ARABIC_H_
 
-#include "core/fxcrt/cfx_char.h"
 #include "core/fxcrt/fx_system.h"
+#include "xfa/fgas/layout/cfx_char.h"
 
 namespace pdfium {
 namespace arabic {
@@ -23,4 +23,4 @@
 
 wchar_t FX_GetArabicFromShaddaTable(wchar_t shadda);
 
-#endif  // CORE_FXCRT_FX_ARABIC_H_
+#endif  // XFA_FGAS_LAYOUT_FX_ARABIC_H_
diff --git a/core/fxcrt/fx_linebreak.cpp b/xfa/fgas/layout/fx_linebreak.cpp
similarity index 99%
rename from core/fxcrt/fx_linebreak.cpp
rename to xfa/fgas/layout/fx_linebreak.cpp
index 48b6633..96821f1 100644
--- a/core/fxcrt/fx_linebreak.cpp
+++ b/xfa/fgas/layout/fx_linebreak.cpp
@@ -4,7 +4,7 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#include "core/fxcrt/fx_linebreak.h"
+#include "xfa/fgas/layout/fx_linebreak.h"
 
 #include "core/fxcrt/fx_memory.h"
 #include "core/fxcrt/fx_unicode.h"
diff --git a/core/fxcrt/fx_linebreak.h b/xfa/fgas/layout/fx_linebreak.h
similarity index 84%
rename from core/fxcrt/fx_linebreak.h
rename to xfa/fgas/layout/fx_linebreak.h
index 38efc80..ac46a35 100644
--- a/core/fxcrt/fx_linebreak.h
+++ b/xfa/fgas/layout/fx_linebreak.h
@@ -4,8 +4,8 @@
 
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
 
-#ifndef CORE_FXCRT_FX_LINEBREAK_H_
-#define CORE_FXCRT_FX_LINEBREAK_H_
+#ifndef XFA_FGAS_LAYOUT_FX_LINEBREAK_H_
+#define XFA_FGAS_LAYOUT_FX_LINEBREAK_H_
 
 #include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/fx_unicode.h"
@@ -23,4 +23,4 @@
 FX_LINEBREAKTYPE GetLineBreakTypeFromPair(FX_BREAKPROPERTY curr_char,
                                           FX_BREAKPROPERTY next_char);
 
-#endif  // CORE_FXCRT_FX_LINEBREAK_H_
+#endif  // XFA_FGAS_LAYOUT_FX_LINEBREAK_H_
diff --git a/xfa/fxfa/cxfa_textlayout.h b/xfa/fxfa/cxfa_textlayout.h
index b222450..2deac8a 100644
--- a/xfa/fxfa/cxfa_textlayout.h
+++ b/xfa/fxfa/cxfa_textlayout.h
@@ -10,10 +10,10 @@
 #include <memory>
 #include <vector>
 
-#include "core/fxcrt/cfx_char.h"
 #include "core/fxcrt/css/cfx_css.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_string.h"
+#include "xfa/fgas/layout/cfx_char.h"
 #include "xfa/fxfa/cxfa_textparser.h"
 
 class CFDE_RenderDevice;
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index c70d31b..174d908 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -14,11 +14,9 @@
 #include <vector>
 
 #include "core/fxcrt/autorestorer.h"
-#include "core/fxcrt/cfx_decimal.h"
 #include "core/fxcrt/cfx_readonlymemorystream.h"
 #include "core/fxcrt/fx_codepage.h"
 #include "core/fxcrt/fx_extension.h"
-#include "core/fxcrt/locale_iface.h"
 #include "core/fxcrt/xml/cfx_xmldocument.h"
 #include "core/fxcrt/xml/cfx_xmlelement.h"
 #include "core/fxcrt/xml/cfx_xmlnode.h"
@@ -33,6 +31,8 @@
 #include "third_party/base/span.h"
 #include "third_party/base/stl_util.h"
 #include "xfa/fde/cfde_textout.h"
+#include "xfa/fgas/crt/cfgas_decimal.h"
+#include "xfa/fgas/crt/locale_iface.h"
 #include "xfa/fgas/font/cfgas_fontmgr.h"
 #include "xfa/fgas/font/cfgas_gefont.h"
 #include "xfa/fxfa/cxfa_eventparam.h"
@@ -4922,7 +4922,7 @@
         iTread_++;
         if (iTread_ > iTread) {
           if (iTread != -1) {
-            CFX_Decimal wsDeci = CFX_Decimal(wsValue.AsStringView());
+            CFGAS_Decimal wsDeci = CFGAS_Decimal(wsValue.AsStringView());
             wsDeci.SetScale(iTread);
             wsRet = wsDeci;
           }
diff --git a/xfa/fxfa/parser/cxfa_nodelocale.h b/xfa/fxfa/parser/cxfa_nodelocale.h
index b30decf..0ada1a4 100644
--- a/xfa/fxfa/parser/cxfa_nodelocale.h
+++ b/xfa/fxfa/parser/cxfa_nodelocale.h
@@ -7,7 +7,7 @@
 #ifndef XFA_FXFA_PARSER_CXFA_NODELOCALE_H_
 #define XFA_FXFA_PARSER_CXFA_NODELOCALE_H_
 
-#include "core/fxcrt/locale_iface.h"
+#include "xfa/fgas/crt/locale_iface.h"
 #include "xfa/fxfa/fxfa_basic.h"
 
 class CXFA_Node;
diff --git a/xfa/fxfa/parser/cxfa_xmllocale.h b/xfa/fxfa/parser/cxfa_xmllocale.h
index cacbddc..472f774 100644
--- a/xfa/fxfa/parser/cxfa_xmllocale.h
+++ b/xfa/fxfa/parser/cxfa_xmllocale.h
@@ -9,8 +9,8 @@
 
 #include <memory>
 
-#include "core/fxcrt/locale_iface.h"
 #include "third_party/base/span.h"
+#include "xfa/fgas/crt/locale_iface.h"
 
 class CFX_XMLDocument;
 class CFX_XMLElement;