summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fxcrt/fx_coordinates.cpp14
-rw-r--r--core/fxcrt/fx_coordinates.h13
-rw-r--r--core/fxcrt/fx_coordinates_unittest.cpp22
-rw-r--r--fpdfsdk/pwl/cpwl_appstream.cpp16
4 files changed, 34 insertions, 31 deletions
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index c345a822b9..136ae72527 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -148,6 +148,20 @@ void CFX_FloatRect::UpdateRect(const CFX_PointF& point) {
top = std::max(top, point.y);
}
+void CFX_FloatRect::ScaleFromCenterPoint(float fScale) {
+ float fHalfWidth = (right - left) / 2.0f;
+ float fHalfHeight = (top - bottom) / 2.0f;
+
+ float center_x = (left + right) / 2;
+ float center_y = (top + bottom) / 2;
+
+ left = center_x - fHalfWidth * fScale;
+ bottom = center_y - fHalfHeight * fScale;
+ right = center_x + fHalfWidth * fScale;
+ top = center_y + fHalfHeight * fScale;
+}
+
+// static
CFX_FloatRect CFX_FloatRect::GetBBox(const CFX_PointF* pPoints, int nPoints) {
if (nPoints == 0)
return CFX_FloatRect();
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h
index 49173a38e8..0d3d123a59 100644
--- a/core/fxcrt/fx_coordinates.h
+++ b/core/fxcrt/fx_coordinates.h
@@ -329,18 +329,7 @@ class CFX_FloatRect {
bottom += f;
}
- void Scale(float fScale) {
- float fHalfWidth = (right - left) / 2.0f;
- float fHalfHeight = (top - bottom) / 2.0f;
-
- float center_x = (left + right) / 2;
- float center_y = (top + bottom) / 2;
-
- left = center_x - fHalfWidth * fScale;
- bottom = center_y - fHalfHeight * fScale;
- right = center_x + fHalfWidth * fScale;
- top = center_y + fHalfHeight * fScale;
- }
+ void ScaleFromCenterPoint(float fScale);
static CFX_FloatRect GetBBox(const CFX_PointF* pPoints, int nPoints);
diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp
index b692b2e485..23d99e46d1 100644
--- a/core/fxcrt/fx_coordinates_unittest.cpp
+++ b/core/fxcrt/fx_coordinates_unittest.cpp
@@ -64,53 +64,53 @@ TEST(CFX_FloatRect, GetBBox) {
EXPECT_FLOAT_EQ(6.3f, rect.top);
}
-TEST(CFX_FloatRect, Scale) {
+TEST(CFX_FloatRect, ScaleFromCenterPoint) {
CFX_FloatRect rect(-1.0f, -3.0f, 4.5f, 3.2f);
- rect.Scale(1.0f);
+ rect.ScaleFromCenterPoint(1.0f);
EXPECT_FLOAT_EQ(-1.0f, rect.left);
EXPECT_FLOAT_EQ(-3.0f, rect.bottom);
EXPECT_FLOAT_EQ(4.5f, rect.right);
EXPECT_FLOAT_EQ(3.2f, rect.top);
- rect.Scale(0.5f);
+ rect.ScaleFromCenterPoint(0.5f);
EXPECT_FLOAT_EQ(0.375f, rect.left);
EXPECT_FLOAT_EQ(-1.45f, rect.bottom);
EXPECT_FLOAT_EQ(3.125f, rect.right);
EXPECT_FLOAT_EQ(1.65f, rect.top);
- rect.Scale(2.0f);
+ rect.ScaleFromCenterPoint(2.0f);
EXPECT_FLOAT_EQ(-1.0f, rect.left);
EXPECT_FLOAT_EQ(-3.0f, rect.bottom);
EXPECT_FLOAT_EQ(4.5f, rect.right);
EXPECT_FLOAT_EQ(3.2f, rect.top);
- rect.Scale(-1.0f);
+ rect.ScaleFromCenterPoint(-1.0f);
EXPECT_FLOAT_EQ(4.5f, rect.left);
EXPECT_FLOAT_EQ(3.2f, rect.bottom);
EXPECT_FLOAT_EQ(-1.0f, rect.right);
EXPECT_FLOAT_EQ(-3.0f, rect.top);
- rect.Scale(0.0f);
+ rect.ScaleFromCenterPoint(0.0f);
EXPECT_FLOAT_EQ(1.75f, rect.left);
EXPECT_NEAR(0.1f, rect.bottom, 0.001f);
EXPECT_FLOAT_EQ(1.75f, rect.right);
EXPECT_NEAR(0.1f, rect.top, 0.001f);
}
-TEST(CFX_FloatRect, ScaleEmpty) {
+TEST(CFX_FloatRect, ScaleFromCenterPointEmpty) {
CFX_FloatRect rect;
- rect.Scale(1.0f);
+ rect.ScaleFromCenterPoint(1.0f);
EXPECT_FLOAT_EQ(0.0f, rect.left);
EXPECT_FLOAT_EQ(0.0f, rect.bottom);
EXPECT_FLOAT_EQ(0.0f, rect.right);
EXPECT_FLOAT_EQ(0.0f, rect.top);
- rect.Scale(0.5f);
+ rect.ScaleFromCenterPoint(0.5f);
EXPECT_FLOAT_EQ(0.0f, rect.left);
EXPECT_FLOAT_EQ(0.0f, rect.bottom);
EXPECT_FLOAT_EQ(0.0f, rect.right);
EXPECT_FLOAT_EQ(0.0f, rect.top);
- rect.Scale(2.0f);
+ rect.ScaleFromCenterPoint(2.0f);
EXPECT_FLOAT_EQ(0.0f, rect.left);
EXPECT_FLOAT_EQ(0.0f, rect.bottom);
EXPECT_FLOAT_EQ(0.0f, rect.right);
EXPECT_FLOAT_EQ(0.0f, rect.top);
- rect.Scale(0.0f);
+ rect.ScaleFromCenterPoint(0.0f);
EXPECT_FLOAT_EQ(0.0f, rect.left);
EXPECT_FLOAT_EQ(0.0f, rect.bottom);
EXPECT_FLOAT_EQ(0.0f, rect.right);
diff --git a/fpdfsdk/pwl/cpwl_appstream.cpp b/fpdfsdk/pwl/cpwl_appstream.cpp
index 27fa09bc31..203a634bfa 100644
--- a/fpdfsdk/pwl/cpwl_appstream.cpp
+++ b/fpdfsdk/pwl/cpwl_appstream.cpp
@@ -514,18 +514,18 @@ ByteString GetCheckBoxAppStream(const CFX_FloatRect& rcBBox,
case CheckStyle::kCheck:
return GetAppStream_Check(rcCenter, crText);
case CheckStyle::kCircle:
- rcCenter.Scale(2.0f / 3.0f);
+ rcCenter.ScaleFromCenterPoint(2.0f / 3.0f);
return GetAppStream_Circle(rcCenter, crText);
case CheckStyle::kCross:
return GetAppStream_Cross(rcCenter, crText);
case CheckStyle::kDiamond:
- rcCenter.Scale(2.0f / 3.0f);
+ rcCenter.ScaleFromCenterPoint(2.0f / 3.0f);
return GetAppStream_Diamond(rcCenter, crText);
case CheckStyle::kSquare:
- rcCenter.Scale(2.0f / 3.0f);
+ rcCenter.ScaleFromCenterPoint(2.0f / 3.0f);
return GetAppStream_Square(rcCenter, crText);
case CheckStyle::kStar:
- rcCenter.Scale(2.0f / 3.0f);
+ rcCenter.ScaleFromCenterPoint(2.0f / 3.0f);
return GetAppStream_Star(rcCenter, crText);
}
}
@@ -539,18 +539,18 @@ ByteString GetRadioButtonAppStream(const CFX_FloatRect& rcBBox,
case CheckStyle::kCheck:
return GetAppStream_Check(rcCenter, crText);
case CheckStyle::kCircle:
- rcCenter.Scale(1.0f / 2.0f);
+ rcCenter.ScaleFromCenterPoint(1.0f / 2.0f);
return GetAppStream_Circle(rcCenter, crText);
case CheckStyle::kCross:
return GetAppStream_Cross(rcCenter, crText);
case CheckStyle::kDiamond:
- rcCenter.Scale(2.0f / 3.0f);
+ rcCenter.ScaleFromCenterPoint(2.0f / 3.0f);
return GetAppStream_Diamond(rcCenter, crText);
case CheckStyle::kSquare:
- rcCenter.Scale(2.0f / 3.0f);
+ rcCenter.ScaleFromCenterPoint(2.0f / 3.0f);
return GetAppStream_Square(rcCenter, crText);
case CheckStyle::kStar:
- rcCenter.Scale(2.0f / 3.0f);
+ rcCenter.ScaleFromCenterPoint(2.0f / 3.0f);
return GetAppStream_Star(rcCenter, crText);
}
}