Add operator<< to CFX_FloatRect.

This helps debugging.

Change-Id: I4d14dd5975d8d8f4566009ed4a4127f9c56d36dd
Reviewed-on: https://pdfium-review.googlesource.com/22790
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index db4bea9..ac13a32 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -199,6 +199,14 @@
                  FXSYS_round(bottom));
 }
 
+#ifndef NDEBUG
+std::ostream& operator<<(std::ostream& os, const CFX_FloatRect& rect) {
+  os << "rect[" << rect.Width() << "x" << rect.Height() << " (" << rect.left
+     << ", " << rect.bottom << ")]";
+  return os;
+}
+#endif
+
 CFX_Matrix CFX_Matrix::GetInverse() const {
   CFX_Matrix inverse;
   float i = a * d - b * c;
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h
index c53d157..69d16d1 100644
--- a/core/fxcrt/fx_coordinates.h
+++ b/core/fxcrt/fx_coordinates.h
@@ -357,6 +357,10 @@
   float top;
 };
 
+#ifndef NDEBUG
+std::ostream& operator<<(std::ostream& os, const CFX_FloatRect& rect);
+#endif
+
 // LTWH rectangles (y-axis runs downwards).
 template <class BaseType>
 class CFX_RTemplate {
diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp
index 5be3aa8..3368a40 100644
--- a/core/fxcrt/fx_coordinates_unittest.cpp
+++ b/core/fxcrt/fx_coordinates_unittest.cpp
@@ -192,6 +192,25 @@
   EXPECT_FLOAT_EQ(0.0f, rect.top);
 }
 
+#ifndef NDEBUG
+TEST(CFX_FloatRect, Print) {
+  std::ostringstream os;
+  CFX_FloatRect rect;
+  os << rect;
+  EXPECT_STREQ("rect[0x0 (0, 0)]", os.str().c_str());
+
+  os.str("");
+  rect = CFX_FloatRect(10, 20, 14, 23);
+  os << rect;
+  EXPECT_STREQ("rect[4x3 (10, 20)]", os.str().c_str());
+
+  os.str("");
+  rect = CFX_FloatRect(10.5, 20.5, 14.75, 23.75);
+  os << rect;
+  EXPECT_STREQ("rect[4.25x3.25 (10.5, 20.5)]", os.str().c_str());
+}
+#endif
+
 TEST(CFX_Matrix, ReverseIdentity) {
   CFX_Matrix m;
   m.SetIdentity();