Clean up star drawing code. - Use float version of sin() and cos(), instead of casting doubles to floats. - Make small improvements to the for-loops. - Fix typos for the word "angle". - Synchronize the non-XFA version with the XFA version. Change-Id: Ic28ac21ee9c90aabc7e2f058e09caf2fe2b0ebcf Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/70930 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_appstream.cpp b/fpdfsdk/cpdfsdk_appstream.cpp index 66e8768..7be7c09 100644 --- a/fpdfsdk/cpdfsdk_appstream.cpp +++ b/fpdfsdk/cpdfsdk_appstream.cpp
@@ -274,27 +274,25 @@ ByteString GetAP_Star(const CFX_FloatRect& crBBox) { std::ostringstream csAP; - float fRadius = (crBBox.top - crBBox.bottom) / (1 + (float)cos(FX_PI / 5.0f)); + float fRadius = (crBBox.top - crBBox.bottom) / (1 + cosf(FX_PI / 5.0f)); CFX_PointF ptCenter = CFX_PointF((crBBox.left + crBBox.right) / 2.0f, (crBBox.top + crBBox.bottom) / 2.0f); - float px[5]; - float py[5]; - float fAngel = FX_PI / 10.0f; - for (int32_t i = 0; i < 5; i++) { - px[i] = ptCenter.x + fRadius * (float)cos(fAngel); - py[i] = ptCenter.y + fRadius * (float)sin(fAngel); - fAngel += FX_PI * 2 / 5.0f; + CFX_PointF points[5]; + float fAngle = FX_PI / 10.0f; + for (auto& point : points) { + point = + ptCenter + CFX_PointF(fRadius * cosf(fAngle), fRadius * sinf(fAngle)); + fAngle += FX_PI * 2 / 5.0f; } - csAP << px[0] << " " << py[0] << " " << kMoveToOperator << "\n"; + csAP << points[0].x << " " << points[0].y << " " << kMoveToOperator << "\n"; - int32_t nNext = 0; - for (int32_t j = 0; j < 5; j++) { - nNext += 2; - if (nNext >= 5) - nNext -= 5; - csAP << px[nNext] << " " << py[nNext] << " " << kLineToOperator << "\n"; + int next = 0; + for (size_t i = 0; i < pdfium::size(points); ++i) { + next = (next + 2) % pdfium::size(points); + csAP << points[next].x << " " << points[next].y << " " << kLineToOperator + << "\n"; } return ByteString(csAP);
diff --git a/xfa/fwl/theme/cfwl_checkboxtp.cpp b/xfa/fwl/theme/cfwl_checkboxtp.cpp index 953523d..516ff97 100644 --- a/xfa/fwl/theme/cfwl_checkboxtp.cpp +++ b/xfa/fwl/theme/cfwl_checkboxtp.cpp
@@ -8,6 +8,7 @@ #include "core/fxge/cfx_pathdata.h" #include "core/fxge/render_defines.h" +#include "third_party/base/stl_util.h" #include "xfa/fde/cfde_textout.h" #include "xfa/fwl/cfwl_checkbox.h" #include "xfa/fwl/cfwl_themebackground.h" @@ -128,28 +129,23 @@ const CFX_Matrix& matrix) { CXFA_GEPath path; float fBottom = rtSign.bottom(); - float fRadius = - (rtSign.top - fBottom) / (1 + static_cast<float>(cos(FX_PI / 5.0f))); + float fRadius = (rtSign.top - fBottom) / (1 + cosf(FX_PI / 5.0f)); CFX_PointF ptCenter((rtSign.left + rtSign.right()) / 2.0f, (rtSign.top + fBottom) / 2.0f); CFX_PointF points[5]; - float fAngel = FX_PI / 10.0f; - for (int32_t i = 0; i < 5; i++) { - points[i] = - ptCenter + CFX_PointF(fRadius * static_cast<float>(cos(fAngel)), - fRadius * static_cast<float>(sin(fAngel))); - fAngel += FX_PI * 2 / 5.0f; + float fAngle = FX_PI / 10.0f; + for (auto& point : points) { + point = + ptCenter + CFX_PointF(fRadius * cosf(fAngle), fRadius * sinf(fAngle)); + fAngle += FX_PI * 2 / 5.0f; } path.MoveTo(points[0]); - int32_t nNext = 0; - for (int32_t j = 0; j < 5; j++) { - nNext += 2; - if (nNext >= 5) - nNext -= 5; - - path.LineTo(points[nNext]); + int next = 0; + for (size_t i = 0; i < pdfium::size(points); ++i) { + next = (next + 2) % pdfium::size(points); + path.LineTo(points[next]); } pGraphics->SaveGraphState(); pGraphics->SetFillColor(CXFA_GEColor(argbFill));