Shuffle some code out of fx_dib.h.

Reduce the cost of this widely included file.

Change-Id: Ief9bec2366d05c3ba80ef9d90b0c64c6e60d1e16
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/82990
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfdoc/cpdf_interactiveform.h b/core/fpdfdoc/cpdf_interactiveform.h
index 1b27dfe..d27dad3 100644
--- a/core/fpdfdoc/cpdf_interactiveform.h
+++ b/core/fpdfdoc/cpdf_interactiveform.h
@@ -14,6 +14,7 @@
 #include "core/fpdfapi/parser/fpdf_parser_decode.h"
 #include "core/fpdfdoc/cpdf_defaultappearance.h"
 #include "core/fpdfdoc/cpdf_formfield.h"
+#include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_string.h"
 #include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/retain_ptr.h"
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index 511e069..66ee9dc 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -88,6 +88,29 @@
   }
 }
 
+FX_RECT FX_RECT::SwappedClipBox(int width,
+                                int height,
+                                bool bFlipX,
+                                bool bFlipY) const {
+  FX_RECT rect;
+  if (bFlipY) {
+    rect.left = height - top;
+    rect.right = height - bottom;
+  } else {
+    rect.left = top;
+    rect.right = bottom;
+  }
+  if (bFlipX) {
+    rect.top = width - left;
+    rect.bottom = width - right;
+  } else {
+    rect.top = left;
+    rect.bottom = right;
+  }
+  rect.Normalize();
+  return rect;
+}
+
 // Y-axis runs the opposite way in FX_RECT.
 CFX_FloatRect::CFX_FloatRect(const FX_RECT& rect)
     : left(rect.left), bottom(rect.top), right(rect.right), top(rect.bottom) {}
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h
index 3f43d6c..39b4776 100644
--- a/core/fxcrt/fx_coordinates.h
+++ b/core/fxcrt/fx_coordinates.h
@@ -194,6 +194,7 @@
   void Normalize();
   void Intersect(const FX_RECT& src);
   void Intersect(int l, int t, int r, int b) { Intersect(FX_RECT(l, t, r, b)); }
+  FX_RECT SwappedClipBox(int width, int height, bool bFlipX, bool bFlipY) const;
 
   void Offset(int dx, int dy) {
     left += dx;
diff --git a/core/fxge/dib/cfx_imagerenderer.cpp b/core/fxge/dib/cfx_imagerenderer.cpp
index 1be59e7..9ceddf8 100644
--- a/core/fxge/dib/cfx_imagerenderer.cpp
+++ b/core/fxge/dib/cfx_imagerenderer.cpp
@@ -44,8 +44,8 @@
       int dest_height = image_rect.Height();
       FX_RECT bitmap_clip = m_ClipBox;
       bitmap_clip.Offset(-image_rect.left, -image_rect.top);
-      bitmap_clip = FXDIB_SwapClipBox(bitmap_clip, dest_width, dest_height,
-                                      m_Matrix.c > 0, m_Matrix.b < 0);
+      bitmap_clip = bitmap_clip.SwappedClipBox(dest_width, dest_height,
+                                               m_Matrix.c > 0, m_Matrix.b < 0);
       m_Composer.Compose(pDevice, pClipRgn, bitmap_alpha, mask_color, m_ClipBox,
                          true, m_Matrix.c > 0, m_Matrix.b < 0, m_bRgbByteOrder,
                          BlendMode::kNormal);
diff --git a/core/fxge/dib/cfx_imagetransformer.cpp b/core/fxge/dib/cfx_imagetransformer.cpp
index ff6baad..c9abd8f 100644
--- a/core/fxge/dib/cfx_imagetransformer.cpp
+++ b/core/fxge/dib/cfx_imagetransformer.cpp
@@ -149,8 +149,8 @@
     int dest_width = result_rect.Width();
     int dest_height = result_rect.Height();
     result_clip.Offset(-result_rect.left, -result_rect.top);
-    result_clip = FXDIB_SwapClipBox(result_clip, dest_width, dest_height,
-                                    m_matrix.c > 0, m_matrix.b < 0);
+    result_clip = result_clip.SwappedClipBox(dest_width, dest_height,
+                                             m_matrix.c > 0, m_matrix.b < 0);
     m_Stretcher = std::make_unique<CFX_ImageStretcher>(
         &m_Storer, m_pSrc, dest_height, dest_width, result_clip,
         m_ResampleOptions);
diff --git a/core/fxge/dib/fx_dib.cpp b/core/fxge/dib/fx_dib.cpp
index 1c408b6..ed275cc 100644
--- a/core/fxge/dib/fx_dib.cpp
+++ b/core/fxge/dib/fx_dib.cpp
@@ -10,7 +10,6 @@
 #include <utility>
 
 #include "build/build_config.h"
-#include "core/fxcrt/fx_extension.h"
 
 #if defined(OS_WIN)
 #include <windows.h>
@@ -42,30 +41,6 @@
   return bInterpolateBilinear || bHalftone || bNoSmoothing || bLossy;
 }
 
-FX_RECT FXDIB_SwapClipBox(const FX_RECT& clip,
-                          int width,
-                          int height,
-                          bool bFlipX,
-                          bool bFlipY) {
-  FX_RECT rect;
-  if (bFlipY) {
-    rect.left = height - clip.top;
-    rect.right = height - clip.bottom;
-  } else {
-    rect.left = clip.top;
-    rect.right = clip.bottom;
-  }
-  if (bFlipX) {
-    rect.top = width - clip.left;
-    rect.bottom = width - clip.right;
-  } else {
-    rect.top = clip.left;
-    rect.bottom = clip.right;
-  }
-  rect.Normalize();
-  return rect;
-}
-
 std::tuple<int, int, int, int> ArgbDecode(FX_ARGB argb) {
   return std::make_tuple(FXARGB_A(argb), FXARGB_R(argb), FXARGB_G(argb),
                          FXARGB_B(argb));
@@ -83,58 +58,3 @@
   return ArgbEncode(a, FXSYS_GetRValue(colorref), FXSYS_GetGValue(colorref),
                     FXSYS_GetBValue(colorref));
 }
-
-#if defined(PDF_ENABLE_XFA)
-FX_ARGB StringToFXARGB(WideStringView view) {
-  static constexpr FX_ARGB kDefaultValue = 0xff000000;
-  if (view.IsEmpty())
-    return kDefaultValue;
-
-  int cc = 0;
-  const wchar_t* str = view.unterminated_c_str();
-  int len = view.GetLength();
-  while (cc < len && FXSYS_iswspace(str[cc]))
-    cc++;
-
-  if (cc >= len)
-    return kDefaultValue;
-
-  uint8_t r = 0;
-  uint8_t g = 0;
-  uint8_t b = 0;
-  while (cc < len) {
-    if (str[cc] == ',' || !FXSYS_IsDecimalDigit(str[cc]))
-      break;
-
-    r = r * 10 + str[cc] - '0';
-    cc++;
-  }
-  if (cc < len && str[cc] == ',') {
-    cc++;
-    while (cc < len && FXSYS_iswspace(str[cc]))
-      cc++;
-
-    while (cc < len) {
-      if (str[cc] == ',' || !FXSYS_IsDecimalDigit(str[cc]))
-        break;
-
-      g = g * 10 + str[cc] - '0';
-      cc++;
-    }
-    if (cc < len && str[cc] == ',') {
-      cc++;
-      while (cc < len && FXSYS_iswspace(str[cc]))
-        cc++;
-
-      while (cc < len) {
-        if (str[cc] == ',' || !FXSYS_IsDecimalDigit(str[cc]))
-          break;
-
-        b = b * 10 + str[cc] - '0';
-        cc++;
-      }
-    }
-  }
-  return ArgbEncode(0xFF, r, g, b);
-}
-#endif  // defined(PDF_ENABLE_XFA)
diff --git a/core/fxge/dib/fx_dib.h b/core/fxge/dib/fx_dib.h
index b1d8b3f..9f858e8 100644
--- a/core/fxge/dib/fx_dib.h
+++ b/core/fxge/dib/fx_dib.h
@@ -12,12 +12,6 @@
 #include <tuple>
 #include <utility>
 
-#include "core/fxcrt/fx_coordinates.h"
-
-#if defined(PDF_ENABLE_XFA)
-#include "core/fxcrt/widestring.h"
-#endif
-
 enum class FXDIB_Format : uint16_t {
   kInvalid = 0,
   k1bppRgb = 0x001,
@@ -127,10 +121,6 @@
 
 FX_ARGB AlphaAndColorRefToArgb(int a, FX_COLORREF colorref);
 
-#if defined(PDF_ENABLE_XFA)
-FX_ARGB StringToFXARGB(WideStringView view);
-#endif
-
 #define FXARGB_A(argb) ((uint8_t)((argb) >> 24))
 #define FXARGB_R(argb) ((uint8_t)((argb) >> 16))
 #define FXARGB_G(argb) ((uint8_t)((argb) >> 8))
@@ -161,12 +151,6 @@
   ((uint8_t)(argb >> 16) | ((uint8_t)(argb >> 8)) << 8 | \
    ((uint8_t)(argb)) << 16 | ((uint8_t)(argb >> 24) << 24))
 
-FX_RECT FXDIB_SwapClipBox(const FX_RECT& clip,
-                          int width,
-                          int height,
-                          bool bFlipX,
-                          bool bFlipY);
-
 inline void ReverseCopy3Bytes(uint8_t* dest, const uint8_t* src) {
   dest[2] = src[0];
   dest[1] = src[1];
diff --git a/fxbarcode/oned/BC_OneDimWriter.h b/fxbarcode/oned/BC_OneDimWriter.h
index 682e3fc..4c63e05 100644
--- a/fxbarcode/oned/BC_OneDimWriter.h
+++ b/fxbarcode/oned/BC_OneDimWriter.h
@@ -18,6 +18,7 @@
 #include "fxbarcode/utils.h"
 
 class CFX_Font;
+class CFX_Matrix;
 class CFX_Path;
 class CFX_RenderDevice;
 class TextCharPos;
diff --git a/xfa/fgas/graphics/cfgas_gegraphics.h b/xfa/fgas/graphics/cfgas_gegraphics.h
index 377cb0d..cdeb1e1 100644
--- a/xfa/fgas/graphics/cfgas_gegraphics.h
+++ b/xfa/fgas/graphics/cfgas_gegraphics.h
@@ -10,6 +10,7 @@
 #include <memory>
 #include <vector>
 
+#include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/retain_ptr.h"
 #include "core/fxge/cfx_fillrenderoptions.h"
diff --git a/xfa/fxfa/cxfa_ffapp.h b/xfa/fxfa/cxfa_ffapp.h
index 6d9e4e8..f3a5c75 100644
--- a/xfa/fxfa/cxfa_ffapp.h
+++ b/xfa/fxfa/cxfa_ffapp.h
@@ -7,6 +7,7 @@
 #ifndef XFA_FXFA_CXFA_FFAPP_H_
 #define XFA_FXFA_CXFA_FFAPP_H_
 
+#include "core/fxcrt/fx_string.h"
 #include "core/fxcrt/unowned_ptr.h"
 #include "fxjs/gc/heap.h"
 #include "v8/include/cppgc/garbage-collected.h"
diff --git a/xfa/fxfa/parser/cxfa_color.cpp b/xfa/fxfa/parser/cxfa_color.cpp
index 3f3da16..9dc035b 100644
--- a/xfa/fxfa/parser/cxfa_color.cpp
+++ b/xfa/fxfa/parser/cxfa_color.cpp
@@ -6,6 +6,7 @@
 
 #include "xfa/fxfa/parser/cxfa_color.h"
 
+#include "core/fxcrt/fx_extension.h"
 #include "fxjs/xfa/cjx_node.h"
 #include "xfa/fxfa/parser/cxfa_document.h"
 
@@ -25,6 +26,60 @@
 
 }  // namespace
 
+// static
+FX_ARGB CXFA_Color::StringToFXARGB(WideStringView view) {
+  static constexpr FX_ARGB kDefaultValue = 0xff000000;
+  if (view.IsEmpty())
+    return kDefaultValue;
+
+  int cc = 0;
+  const wchar_t* str = view.unterminated_c_str();
+  int len = view.GetLength();
+  while (cc < len && FXSYS_iswspace(str[cc]))
+    cc++;
+
+  if (cc >= len)
+    return kDefaultValue;
+
+  uint8_t r = 0;
+  uint8_t g = 0;
+  uint8_t b = 0;
+  while (cc < len) {
+    if (str[cc] == ',' || !FXSYS_IsDecimalDigit(str[cc]))
+      break;
+
+    r = r * 10 + str[cc] - '0';
+    cc++;
+  }
+  if (cc < len && str[cc] == ',') {
+    cc++;
+    while (cc < len && FXSYS_iswspace(str[cc]))
+      cc++;
+
+    while (cc < len) {
+      if (str[cc] == ',' || !FXSYS_IsDecimalDigit(str[cc]))
+        break;
+
+      g = g * 10 + str[cc] - '0';
+      cc++;
+    }
+    if (cc < len && str[cc] == ',') {
+      cc++;
+      while (cc < len && FXSYS_iswspace(str[cc]))
+        cc++;
+
+      while (cc < len) {
+        if (str[cc] == ',' || !FXSYS_IsDecimalDigit(str[cc]))
+          break;
+
+        b = b * 10 + str[cc] - '0';
+        cc++;
+      }
+    }
+  }
+  return ArgbEncode(0xFF, r, g, b);
+}
+
 CXFA_Color::CXFA_Color(CXFA_Document* doc, XFA_PacketType packet)
     : CXFA_Node(doc,
                 packet,
diff --git a/xfa/fxfa/parser/cxfa_color.h b/xfa/fxfa/parser/cxfa_color.h
index 32706e9..683ce6e 100644
--- a/xfa/fxfa/parser/cxfa_color.h
+++ b/xfa/fxfa/parser/cxfa_color.h
@@ -7,11 +7,13 @@
 #ifndef XFA_FXFA_PARSER_CXFA_COLOR_H_
 #define XFA_FXFA_PARSER_CXFA_COLOR_H_
 
+#include "core/fxcrt/fx_string.h"
 #include "xfa/fxfa/parser/cxfa_node.h"
 
 class CXFA_Color final : public CXFA_Node {
  public:
   static constexpr FX_ARGB kBlackColor = 0xFF000000;
+  static FX_ARGB StringToFXARGB(WideStringView view);
 
   CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
   ~CXFA_Color() override;
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index 3a12edc..e33673b 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -11,6 +11,7 @@
 #include <utility>
 #include <vector>
 
+#include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_string.h"
 #include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/retain_ptr.h"
diff --git a/xfa/fxfa/parser/cxfa_stroke.cpp b/xfa/fxfa/parser/cxfa_stroke.cpp
index 45ac038..9056bed 100644
--- a/xfa/fxfa/parser/cxfa_stroke.cpp
+++ b/xfa/fxfa/parser/cxfa_stroke.cpp
@@ -113,7 +113,7 @@
   if (!pNode)
     return 0xFF000000;
 
-  return StringToFXARGB(
+  return CXFA_Color::StringToFXARGB(
       pNode->JSObject()->GetCData(XFA_Attribute::Value).AsStringView());
 }
 
diff --git a/xfa/fxfa/parser/xfa_utils.h b/xfa/fxfa/parser/xfa_utils.h
index 704aec1..59cef0f 100644
--- a/xfa/fxfa/parser/xfa_utils.h
+++ b/xfa/fxfa/parser/xfa_utils.h
@@ -8,6 +8,7 @@
 #define XFA_FXFA_PARSER_XFA_UTILS_H_
 
 #include "core/fxcrt/fx_stream.h"
+#include "core/fxcrt/fx_string.h"
 #include "core/fxcrt/retain_ptr.h"
 #include "xfa/fxfa/fxfa.h"
 #include "xfa/fxfa/fxfa_basic.h"