Cleanup some code involving rectangles

-- Initialize in header and default where possible.
-- Add CFX_RectF ctor from FX_RECT
-- Add GetOuterRect() method and use appropriately.
-- Do simple rectangle assign in one place found during audit.

Change-Id: I6542187673b36b06de27579002ab814f3fb369ce
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/59130
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index 2969315..c6d5393 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -268,6 +268,13 @@
                  FXSYS_round(bottom));
 }
 
+FX_RECT CFX_RectF::GetOuterRect() const {
+  return FX_RECT(static_cast<int32_t>(floor(left)),
+                 static_cast<int32_t>(floor(top)),
+                 static_cast<int32_t>(ceil(right())),
+                 static_cast<int32_t>(ceil(bottom())));
+}
+
 #ifndef NDEBUG
 std::ostream& operator<<(std::ostream& os, const CFX_FloatRect& rect) {
   os << "rect[w " << rect.Width() << " x h " << rect.Height() << " (left "
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h
index 5bb36da..c3ea480 100644
--- a/core/fxcrt/fx_coordinates.h
+++ b/core/fxcrt/fx_coordinates.h
@@ -182,7 +182,7 @@
 // LTRB rectangles (y-axis runs downwards).
 // Struct layout is compatible with win32 RECT.
 struct FX_RECT {
-  FX_RECT() : left(0), top(0), right(0), bottom(0) {}
+  FX_RECT() = default;
   FX_RECT(int l, int t, int r, int b) : left(l), top(t), right(r), bottom(b) {}
 
   int Width() const { return right - left; }
@@ -198,7 +198,6 @@
   }
 
   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)); }
 
@@ -218,16 +217,16 @@
     return x >= left && x < right && y >= top && y < bottom;
   }
 
-  int32_t left;
-  int32_t top;
-  int32_t right;
-  int32_t bottom;
+  int32_t left = 0;
+  int32_t top = 0;
+  int32_t right = 0;
+  int32_t bottom = 0;
 };
 
 // LTRB rectangles (y-axis runs upwards).
 class CFX_FloatRect {
  public:
-  constexpr CFX_FloatRect() : CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f) {}
+  constexpr CFX_FloatRect() = default;
   constexpr CFX_FloatRect(float l, float b, float r, float t)
       : left(l), bottom(b), right(r), top(t) {}
 
@@ -310,10 +309,10 @@
   // Rounds LBRT values.
   FX_RECT ToRoundedFxRect() const;
 
-  float left;
-  float bottom;
-  float right;
-  float top;
+  float left = 0.0f;
+  float bottom = 0.0f;
+  float right = 0.0f;
+  float top = 0.0f;
 };
 
 #ifndef NDEBUG
@@ -326,7 +325,7 @@
   using PointType = CFX_PointF;
   using SizeType = CFX_SizeF;
 
-  CFX_RectF() : left(0), top(0), width(0), height(0) {}
+  CFX_RectF() = default;
   CFX_RectF(float dst_left, float dst_top, float dst_width, float dst_height)
       : left(dst_left), top(dst_top), width(dst_width), height(dst_height) {}
   CFX_RectF(float dst_left, float dst_top, const SizeType& dst_size)
@@ -338,13 +337,14 @@
       : left(p.x), top(p.y), width(dst_width), height(dst_height) {}
   CFX_RectF(const PointType& p1, const SizeType& s2)
       : left(p1.x), top(p1.y), width(s2.width), height(s2.height) {}
+  explicit CFX_RectF(const FX_RECT& that)
+      : left(static_cast<float>(that.left)),
+        top(static_cast<float>(that.top)),
+        width(static_cast<float>(that.Width())),
+        height(static_cast<float>(that.Height())) {}
 
   // NOLINTNEXTLINE(runtime/explicit)
-  CFX_RectF(const CFX_RectF& other)
-      : left(other.left),
-        top(other.top),
-        width(other.width),
-        height(other.height) {}
+  CFX_RectF(const CFX_RectF& other) = default;
 
   CFX_RectF& operator+=(const PointType& p) {
     left += p.x;
@@ -498,10 +498,14 @@
     return CFX_FloatRect(left, top, right(), bottom());
   }
 
-  float left;
-  float top;
-  float width;
-  float height;
+  // Returned rect has bounds rounded up/down such that the original is
+  // contained in it.
+  FX_RECT GetOuterRect() const;
+
+  float left = 0.0f;
+  float top = 0.0f;
+  float width = 0.0f;
+  float height = 0.0f;
 };
 
 #ifndef NDEBUG
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index 2b79abe..b431cc2 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -481,15 +481,6 @@
   return true;
 }
 
-#ifdef PDF_ENABLE_XFA
-bool CFX_RenderDevice::SetClip_Rect(const CFX_RectF& rtClip) {
-  return SetClip_Rect(FX_RECT(static_cast<int32_t>(floor(rtClip.left)),
-                              static_cast<int32_t>(floor(rtClip.top)),
-                              static_cast<int32_t>(ceil(rtClip.right())),
-                              static_cast<int32_t>(ceil(rtClip.bottom()))));
-}
-#endif
-
 bool CFX_RenderDevice::SetClip_Rect(const FX_RECT& rect) {
   CFX_PathData path;
   path.AppendRect(rect.left, rect.bottom, rect.right, rect.top);
diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h
index a20df32..b8d9221 100644
--- a/core/fxge/cfx_renderdevice.h
+++ b/core/fxge/cfx_renderdevice.h
@@ -67,13 +67,10 @@
                               int width,
                               int height) const;
   const FX_RECT& GetClipBox() const { return m_ClipBox; }
+  bool SetClip_Rect(const FX_RECT& pRect);
   bool SetClip_PathFill(const CFX_PathData* pPathData,
                         const CFX_Matrix* pObject2Device,
                         int fill_mode);
-#ifdef PDF_ENABLE_XFA
-  bool SetClip_Rect(const CFX_RectF& rtClip);
-#endif
-  bool SetClip_Rect(const FX_RECT& pRect);
   bool SetClip_PathStroke(const CFX_PathData* pPathData,
                           const CFX_Matrix* pObject2Device,
                           const CFX_GraphStateData* pGraphState);
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
index 19e1fe1..45d6e90 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp
@@ -234,10 +234,7 @@
                                   CPDFSDK_Annot* pAnnot,
                                   const CFX_Matrix& mtUser2Device,
                                   const FX_RECT& rtClip) {
-  CFX_RectF rectClip(
-      static_cast<float>(rtClip.left), static_cast<float>(rtClip.top),
-      static_cast<float>(rtClip.Width()), static_cast<float>(rtClip.Height()));
-
+  CFX_RectF rectClip(rtClip);
   CXFA_Graphics gs(pDevice);
   gs.SetClipRect(rectClip);
 
diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp
index 82ac53d..6e2915e 100644
--- a/xfa/fde/cfde_textout.cpp
+++ b/xfa/fde/cfde_textout.cpp
@@ -295,7 +295,7 @@
   CFX_RectF rtClip = m_Matrix.TransformRect(CFX_RectF());
   device->SaveState();
   if (rtClip.Width() > 0.0f && rtClip.Height() > 0.0f)
-    device->SetClip_Rect(rtClip);
+    device->SetClip_Rect(rtClip.GetOuterRect());
 
   for (auto& line : m_ttoLines) {
     int32_t iPieces = line.GetSize();
diff --git a/xfa/fwl/cfwl_checkbox.cpp b/xfa/fwl/cfwl_checkbox.cpp
index 06dd54e..ba8d4ae 100644
--- a/xfa/fwl/cfwl_checkbox.cpp
+++ b/xfa/fwl/cfwl_checkbox.cpp
@@ -127,9 +127,7 @@
                           m_rtClient.right() - fTextLeft, m_rtClient.height);
   m_rtCaption.Inflate(-kCaptionMargin, -kCaptionMargin);
 
-  CFX_RectF rtFocus(m_rtCaption.left, m_rtCaption.top, m_rtCaption.width,
-                    m_rtCaption.height);
-
+  CFX_RectF rtFocus = m_rtCaption;
   CalcTextRect(L"Check box", m_pProperties->m_pThemeProvider.Get(), m_TTOStyles,
                m_iTTOAlign, &rtFocus);
 
diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp
index 2f26706..5b70b98 100644
--- a/xfa/fwl/cfwl_edit.cpp
+++ b/xfa/fwl/cfwl_edit.cpp
@@ -445,7 +445,7 @@
   if (!font)
     return;
 
-  pRenderDev->SetClip_Rect(clipRect);
+  pRenderDev->SetClip_Rect(clipRect.GetOuterRect());
 
   CFX_RectF rtDocClip = clipRect;
   if (rtDocClip.IsEmpty()) {
diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp
index b57c77a..9772f5d 100644
--- a/xfa/fxfa/cxfa_textlayout.cpp
+++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -571,7 +571,7 @@
     return false;
 
   pFxDevice->SaveState();
-  pFxDevice->SetClip_Rect(rtClip);
+  pFxDevice->SetClip_Rect(rtClip.GetOuterRect());
 
   if (m_pieceLines.empty()) {
     size_t szBlockCount = CountBlocks();