Disambiguate CFX_PathData::IsRect().

Change one version to GetRect(), and change it to return an Optional.

Change-Id: I1a09816326df99122a7edd8b7f36415b8c01a203
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/67670
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/agg/fx_agg_driver.cpp b/core/fxge/agg/fx_agg_driver.cpp
index 9931fe0..8fd0315 100644
--- a/core/fxge/agg/fx_agg_driver.cpp
+++ b/core/fxge/agg/fx_agg_driver.cpp
@@ -1260,8 +1260,9 @@
   }
   size_t size = pPathData->GetPoints().size();
   if (size == 5 || size == 4) {
-    CFX_FloatRect rectf;
-    if (pPathData->IsRect(pObject2Device, &rectf)) {
+    Optional<CFX_FloatRect> maybe_rectf = pPathData->GetRect(pObject2Device);
+    if (maybe_rectf.has_value()) {
+      CFX_FloatRect& rectf = maybe_rectf.value();
       rectf.Intersect(CFX_FloatRect(
           0, 0, static_cast<float>(GetDeviceCaps(FXDC_PIXEL_WIDTH)),
           static_cast<float>(GetDeviceCaps(FXDC_PIXEL_HEIGHT))));
diff --git a/core/fxge/cfx_pathdata.cpp b/core/fxge/cfx_pathdata.cpp
index 55ce854..342495e 100644
--- a/core/fxge/cfx_pathdata.cpp
+++ b/core/fxge/cfx_pathdata.cpp
@@ -453,33 +453,28 @@
   return m_Points.size() == 5 || m_Points[3].m_CloseFigure;
 }
 
-bool CFX_PathData::IsRect(const CFX_Matrix* pMatrix,
-                          CFX_FloatRect* pRect) const {
+Optional<CFX_FloatRect> CFX_PathData::GetRect(const CFX_Matrix* pMatrix) const {
   if (!pMatrix) {
     if (!IsRect())
-      return false;
+      return pdfium::nullopt;
 
-    if (pRect) {
-      pRect->left = m_Points[0].m_Point.x;
-      pRect->right = m_Points[2].m_Point.x;
-      pRect->bottom = m_Points[0].m_Point.y;
-      pRect->top = m_Points[2].m_Point.y;
-      pRect->Normalize();
-    }
-    return true;
+    CFX_FloatRect rect(m_Points[0].m_Point.x, m_Points[0].m_Point.y,
+                       m_Points[2].m_Point.x, m_Points[2].m_Point.y);
+    rect.Normalize();
+    return rect;
   }
 
   if (m_Points.size() != 5 && m_Points.size() != 4)
-    return false;
+    return pdfium::nullopt;
 
   if ((m_Points.size() == 5 && m_Points[0].m_Point != m_Points[4].m_Point) ||
       m_Points[1].m_Point == m_Points[3].m_Point) {
-    return false;
+    return pdfium::nullopt;
   }
   // Note, both x,y not equal.
   if (m_Points.size() == 4 && m_Points[0].m_Point.x != m_Points[3].m_Point.x &&
       m_Points[0].m_Point.y != m_Points[3].m_Point.y) {
-    return false;
+    return pdfium::nullopt;
   }
 
   CFX_PointF points[5];
@@ -489,19 +484,14 @@
     if (i == 0)
       continue;
     if (m_Points[i].m_Type != FXPT_TYPE::LineTo)
-      return false;
+      return pdfium::nullopt;
     if (points[i].x != points[i - 1].x && points[i].y != points[i - 1].y)
-      return false;
+      return pdfium::nullopt;
   }
 
-  if (pRect) {
-    pRect->left = points[0].x;
-    pRect->right = points[2].x;
-    pRect->bottom = points[0].y;
-    pRect->top = points[2].y;
-    pRect->Normalize();
-  }
-  return true;
+  CFX_FloatRect rect(points[0].x, points[0].y, points[2].x, points[2].y);
+  rect.Normalize();
+  return rect;
 }
 
 CFX_RetainablePathData::CFX_RetainablePathData() = default;
diff --git a/core/fxge/cfx_pathdata.h b/core/fxge/cfx_pathdata.h
index 3fd57e2..9a6695a 100644
--- a/core/fxge/cfx_pathdata.h
+++ b/core/fxge/cfx_pathdata.h
@@ -12,6 +12,7 @@
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/retain_ptr.h"
+#include "third_party/base/optional.h"
 
 enum class FXPT_TYPE : uint8_t { LineTo, BezierTo, MoveTo };
 
@@ -59,7 +60,7 @@
                        CFX_PathData* NewPath,
                        bool* bThin,
                        bool* setIdentity) const;
-  bool IsRect(const CFX_Matrix* pMatrix, CFX_FloatRect* rect) const;
+  Optional<CFX_FloatRect> GetRect(const CFX_Matrix* pMatrix) const;
 
   void Append(const CFX_PathData* pSrc, const CFX_Matrix* pMatrix);
   void AppendFloatRect(const CFX_FloatRect& rect);
diff --git a/core/fxge/cfx_renderdevice.cpp b/core/fxge/cfx_renderdevice.cpp
index e5d20f9..9479825 100644
--- a/core/fxge/cfx_renderdevice.cpp
+++ b/core/fxge/cfx_renderdevice.cpp
@@ -526,10 +526,11 @@
     return true;
   }
 
-  if ((points.size() == 5 || points.size() == 4) && stroke_alpha == 0) {
-    CFX_FloatRect rect_f;
-    if (!(fill_mode & FXFILL_RECT_AA) &&
-        pPathData->IsRect(pObject2Device, &rect_f)) {
+  if ((points.size() == 5 || points.size() == 4) && stroke_alpha == 0 &&
+      !(fill_mode & FXFILL_RECT_AA)) {
+    Optional<CFX_FloatRect> maybe_rect_f = pPathData->GetRect(pObject2Device);
+    if (maybe_rect_f.has_value()) {
+      const CFX_FloatRect& rect_f = maybe_rect_f.value();
       FX_RECT rect_i = rect_f.GetOuterRect();
 
       // Depending on the top/bottom, left/right values of the rect it's
diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp
index 6617438..faf40d6 100644
--- a/core/fxge/skia/fx_skia_device.cpp
+++ b/core/fxge/skia/fx_skia_device.cpp
@@ -1031,8 +1031,9 @@
     SkPath skClipPath;
     if (pPathData->GetPoints().size() == 5 ||
         pPathData->GetPoints().size() == 4) {
-      CFX_FloatRect rectf;
-      if (pPathData->IsRect(pMatrix, &rectf)) {
+      Optional<CFX_FloatRect> maybe_rectf = pPathData->GetRect(pMatrix);
+      if (maybe_rectf.has_value()) {
+        CFX_FloatRect& rectf = maybe_rectf.value();
         rectf.Intersect(CFX_FloatRect(
             0, 0,
             static_cast<float>(m_pDriver->GetDeviceCaps(FXDC_PIXEL_WIDTH)),
@@ -1963,8 +1964,9 @@
 #endif  // _SKIA_SUPPORT_PATHS_
   if (pPathData->GetPoints().size() == 5 ||
       pPathData->GetPoints().size() == 4) {
-    CFX_FloatRect rectf;
-    if (pPathData->IsRect(deviceMatrix, &rectf)) {
+    Optional<CFX_FloatRect> maybe_rectf = pPathData->GetRect(deviceMatrix);
+    if (maybe_rectf.has_value()) {
+      CFX_FloatRect& rectf = maybe_rectf.value();
       rectf.Intersect(CFX_FloatRect(0, 0,
                                     (float)GetDeviceCaps(FXDC_PIXEL_WIDTH),
                                     (float)GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp
index 968eac5..5fabf87 100644
--- a/core/fxge/win32/fx_win32_device.cpp
+++ b/core/fxge/win32/fx_win32_device.cpp
@@ -1087,9 +1087,9 @@
                                         const CFX_Matrix* pMatrix,
                                         int fill_mode) {
   if (pPathData->GetPoints().size() == 5) {
-    CFX_FloatRect rectf;
-    if (pPathData->IsRect(pMatrix, &rectf)) {
-      FX_RECT rect = rectf.GetOuterRect();
+    Optional<CFX_FloatRect> maybe_rectf = pPathData->GetRect(pMatrix);
+    if (maybe_rectf.has_value()) {
+      FX_RECT rect = maybe_rectf.value().GetOuterRect();
       // Can easily apply base clip to protect against wildly large rectangular
       // clips. crbug.com/1019026
       if (m_BaseClipBox.has_value())