summaryrefslogtreecommitdiff
path: root/core/fxcrt
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2018-01-11 21:56:48 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-11 21:56:48 +0000
commit7c0a92e1761dddaf6ed84e3bea723dc7a40c8685 (patch)
treeaf3fae8b8025d77faf9233e8f50d7663254c6c3e /core/fxcrt
parent923948632fe798d1c17000803d9d4b1559b4ffa1 (diff)
downloadpdfium-7c0a92e1761dddaf6ed84e3bea723dc7a40c8685.tar.xz
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>
Diffstat (limited to 'core/fxcrt')
-rw-r--r--core/fxcrt/fx_coordinates.cpp8
-rw-r--r--core/fxcrt/fx_coordinates.h4
-rw-r--r--core/fxcrt/fx_coordinates_unittest.cpp19
3 files changed, 31 insertions, 0 deletions
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index db4bea945f..ac13a32329 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -199,6 +199,14 @@ FX_RECT CFX_FloatRect::ToRoundedFxRect() const {
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 c53d157610..69d16d1c55 100644
--- a/core/fxcrt/fx_coordinates.h
+++ b/core/fxcrt/fx_coordinates.h
@@ -357,6 +357,10 @@ class CFX_FloatRect {
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 5be3aa83f9..3368a40e18 100644
--- a/core/fxcrt/fx_coordinates_unittest.cpp
+++ b/core/fxcrt/fx_coordinates_unittest.cpp
@@ -192,6 +192,25 @@ TEST(CFX_FloatRect, ScaleFromCenterPointEmpty) {
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();