summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fxcrt/fx_coordinates.cpp11
-rw-r--r--core/fxcrt/fx_coordinates.h1
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp2
-rw-r--r--fpdfsdk/pdfwindow/cpwl_utils.cpp17
-rw-r--r--fpdfsdk/pdfwindow/cpwl_utils.h1
5 files changed, 15 insertions, 17 deletions
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index 0b6aed44cc..752591d3ed 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -157,6 +157,17 @@ FX_RECT CFX_FloatRect::GetClosestRect() const {
return rect;
}
+CFX_FloatRect CFX_FloatRect::GetCenterSquare() const {
+ float fWidth = right - left;
+ float fHeight = top - bottom;
+ float fHalfWidth = (fWidth > fHeight) ? fHeight / 2 : fWidth / 2;
+
+ float fCenterX = (left + right) / 2.0f;
+ float fCenterY = (top + bottom) / 2.0f;
+ return CFX_FloatRect(fCenterX - fHalfWidth, fCenterY - fHalfWidth,
+ fCenterX + fHalfWidth, fCenterY + fHalfWidth);
+}
+
bool CFX_FloatRect::Contains(const CFX_PointF& point) const {
CFX_FloatRect n1(*this);
n1.Normalize();
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h
index 25923f7290..a1bf11b207 100644
--- a/core/fxcrt/fx_coordinates.h
+++ b/core/fxcrt/fx_coordinates.h
@@ -482,6 +482,7 @@ class CFX_FloatRect {
FX_RECT GetInnerRect() const;
FX_RECT GetOuterRect() const;
FX_RECT GetClosestRect() const;
+ CFX_FloatRect GetCenterSquare() const;
int Substract4(CFX_FloatRect& substract_rect, CFX_FloatRect* pRects);
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index b7391e6ebc..fc56d7e45b 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -1273,7 +1273,7 @@ void CPDFSDK_Widget::ResetAppearance_RadioButton() {
CFX_ByteString csAP_N_ON;
- CFX_FloatRect rcCenter = CPWL_Utils::GetCenterSquare(rcWindow);
+ CFX_FloatRect rcCenter = rcWindow.GetCenterSquare();
if (!rcCenter.IsEmpty()) {
rcCenter.Deflate(1.0f, 1.0f);
rcCenter.Normalize();
diff --git a/fpdfsdk/pdfwindow/cpwl_utils.cpp b/fpdfsdk/pdfwindow/cpwl_utils.cpp
index 651f21e0b7..ed1a94542e 100644
--- a/fpdfsdk/pdfwindow/cpwl_utils.cpp
+++ b/fpdfsdk/pdfwindow/cpwl_utils.cpp
@@ -264,19 +264,6 @@ CFX_ByteString CPWL_Utils::GetCircleFillAppStream(const CFX_FloatRect& rect,
return CFX_ByteString(sAppStream);
}
-CFX_FloatRect CPWL_Utils::GetCenterSquare(const CFX_FloatRect& rect) {
- float fWidth = rect.right - rect.left;
- float fHeight = rect.top - rect.bottom;
-
- float fCenterX = (rect.left + rect.right) / 2.0f;
- float fCenterY = (rect.top + rect.bottom) / 2.0f;
-
- float fRadius = (fWidth > fHeight) ? fHeight / 2 : fWidth / 2;
-
- return CFX_FloatRect(fCenterX - fRadius, fCenterY - fRadius,
- fCenterX + fRadius, fCenterY + fRadius);
-}
-
CFX_ByteString CPWL_Utils::GetEditAppStream(CFX_Edit* pEdit,
const CFX_PointF& ptOffset,
const CPVT_WordRange* pRange,
@@ -802,7 +789,7 @@ CFX_ByteString CPWL_Utils::GetAppStream_Star(const CFX_FloatRect& rcBBox,
CFX_ByteString CPWL_Utils::GetCheckBoxAppStream(const CFX_FloatRect& rcBBox,
int32_t nStyle,
const CPWL_Color& crText) {
- CFX_FloatRect rcCenter = GetCenterSquare(rcBBox);
+ CFX_FloatRect rcCenter = rcBBox.GetCenterSquare();
switch (nStyle) {
default:
case PCS_CHECK:
@@ -823,7 +810,7 @@ CFX_ByteString CPWL_Utils::GetCheckBoxAppStream(const CFX_FloatRect& rcBBox,
CFX_ByteString CPWL_Utils::GetRadioButtonAppStream(const CFX_FloatRect& rcBBox,
int32_t nStyle,
const CPWL_Color& crText) {
- CFX_FloatRect rcCenter = GetCenterSquare(rcBBox);
+ CFX_FloatRect rcCenter = rcBBox.GetCenterSquare();
switch (nStyle) {
default:
case PCS_CHECK:
diff --git a/fpdfsdk/pdfwindow/cpwl_utils.h b/fpdfsdk/pdfwindow/cpwl_utils.h
index b0caf0b386..df364c7f56 100644
--- a/fpdfsdk/pdfwindow/cpwl_utils.h
+++ b/fpdfsdk/pdfwindow/cpwl_utils.h
@@ -34,7 +34,6 @@ class CPWL_Utils {
public:
static CPVT_WordRange OverlapWordRange(const CPVT_WordRange& wr1,
const CPVT_WordRange& wr2);
- static CFX_FloatRect GetCenterSquare(const CFX_FloatRect& rect);
static CFX_ByteString GetColorAppStream(const CPWL_Color& color,
const bool& bFillOrStroke = true);