Purge every C-style cast of int32_t

Meanwhile, include fx_system.h in more places in the spirit of IWYU.

Change-Id: I5332d5fb8c16d8ff126df740a397c8f2298aa57d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/76210
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 8e6a57f..06389bc 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -825,8 +825,8 @@
                      !PDFCharIsWhitespace(tag[taglen - 1]);
 
   uint8_t ch;
-  if (bCheckRight && startpos + (int32_t)taglen <= limit &&
-      GetCharAt(startpos + (int32_t)taglen, ch)) {
+  if (bCheckRight && startpos + static_cast<int32_t>(taglen) <= limit &&
+      GetCharAt(startpos + static_cast<int32_t>(taglen), ch)) {
     if (PDFCharIsNumeric(ch) || PDFCharIsOther(ch) ||
         (checkKeyword && PDFCharIsDelimiter(ch))) {
       return false;
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.h b/core/fpdfapi/parser/cpdf_syntax_parser.h
index 14629f9..74e18f1 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.h
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.h
@@ -12,6 +12,7 @@
 
 #include "core/fpdfapi/parser/cpdf_stream.h"
 #include "core/fxcrt/fx_memory_wrappers.h"
+#include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/string_pool_template.h"
 #include "core/fxcrt/unowned_ptr.h"
 #include "core/fxcrt/weak_ptr.h"
diff --git a/core/fpdfapi/render/cpdf_rendershading.cpp b/core/fpdfapi/render/cpdf_rendershading.cpp
index 3886312..1723f17 100644
--- a/core/fpdfapi/render/cpdf_rendershading.cpp
+++ b/core/fpdfapi/render/cpdf_rendershading.cpp
@@ -136,7 +136,7 @@
       float scale =
           (((pos.x - start_x) * x_span) + ((pos.y - start_y) * y_span)) /
           axis_len_square;
-      int index = (int32_t)(scale * (kShadingSteps - 1));
+      int index = static_cast<int32_t>(scale * (kShadingSteps - 1));
       if (index < 0) {
         if (!bStartExtend)
           continue;
@@ -307,8 +307,9 @@
       float G = 0.0f;
       float B = 0.0f;
       pCS->GetRGB(result_array, &R, &G, &B);
-      dib_buf[column] = ArgbEncode(alpha, (int32_t)(R * 255),
-                                   (int32_t)(G * 255), (int32_t)(B * 255));
+      dib_buf[column] = ArgbEncode(alpha, static_cast<int32_t>(R * 255),
+                                   static_cast<int32_t>(G * 255),
+                                   static_cast<int32_t>(B * 255));
     }
   }
 }
@@ -825,9 +826,9 @@
       float b;
       std::tie(r, g, b) = stream.ReadColor();
 
-      patch.patch_colors[i].comp[0] = (int32_t)(r * 255);
-      patch.patch_colors[i].comp[1] = (int32_t)(g * 255);
-      patch.patch_colors[i].comp[2] = (int32_t)(b * 255);
+      patch.patch_colors[i].comp[0] = static_cast<int32_t>(r * 255);
+      patch.patch_colors[i].comp[1] = static_cast<int32_t>(g * 255);
+      patch.patch_colors[i].comp[2] = static_cast<int32_t>(b * 255);
     }
     CFX_FloatRect bbox = CFX_FloatRect::GetBBox(coords, point_count);
     if (bbox.right <= 0 || bbox.left >= (float)pBitmap->GetWidth() ||
@@ -875,8 +876,9 @@
       float G = 0.0f;
       float B = 0.0f;
       pColorSpace->GetRGB(comps, &R, &G, &B);
-      background = ArgbEncode(255, (int32_t)(R * 255), (int32_t)(G * 255),
-                              (int32_t)(B * 255));
+      background = ArgbEncode(255, static_cast<int32_t>(R * 255),
+                              static_cast<int32_t>(G * 255),
+                              static_cast<int32_t>(B * 255));
     }
   }
   FX_RECT clip_rect_bbox = clip_rect;
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 4baedf5..98f1c1d 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -708,7 +708,7 @@
   }
   int32_t blitAlpha = 255;
   if (group_alpha != 1.0f && transparency.IsGroup()) {
-    blitAlpha = (int32_t)(group_alpha * 255);
+    blitAlpha = static_cast<int32_t>(group_alpha * 255);
 #if !defined(_SKIA_SUPPORT_)
     bitmap->MultiplyAlpha(blitAlpha);
     blitAlpha = 255;
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index 405e9b6..a657ec3 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -495,9 +495,9 @@
   CPDF_Array* pColor = m_pAnnotDict->GetArrayFor(pdfium::annotation::kC);
   uint32_t argb = 0xff000000;
   if (pColor) {
-    int R = (int32_t)(pColor->GetNumberAt(0) * 255);
-    int G = (int32_t)(pColor->GetNumberAt(1) * 255);
-    int B = (int32_t)(pColor->GetNumberAt(2) * 255);
+    int R = static_cast<int32_t>(pColor->GetNumberAt(0) * 255);
+    int G = static_cast<int32_t>(pColor->GetNumberAt(1) * 255);
+    int B = static_cast<int32_t>(pColor->GetNumberAt(2) * 255);
     argb = ArgbEncode(0xff, R, G, B);
   }
   CFX_GraphStateData graph_state;
diff --git a/core/fxcodec/progressive_decoder.cpp b/core/fxcodec/progressive_decoder.cpp
index b32d456..a21012a 100644
--- a/core/fxcodec/progressive_decoder.cpp
+++ b/core/fxcodec/progressive_decoder.cpp
@@ -315,7 +315,8 @@
   }
   if (line >= m_clipBox.top && line < m_clipBox.bottom) {
     double scale_y = static_cast<double>(m_sizeY) / m_clipBox.Height();
-    int32_t row = (int32_t)((line - m_clipBox.top) * scale_y) + m_startY;
+    int32_t row =
+        static_cast<int32_t>((line - m_clipBox.top) * scale_y) + m_startY;
     const uint8_t* src_scan = pDIBitmap->GetScanline(row);
     uint8_t* dest_scan = m_pDecodeBuf.get();
     *pSrcBuf = m_pDecodeBuf.get();
@@ -2176,19 +2177,21 @@
   if (start_x < 0 || out_range_x > 0) {
     float scaleX = (float)m_clipBox.Width() / (float)size_x;
     if (start_x < 0) {
-      m_clipBox.left -= (int32_t)ceil((float)start_x * scaleX);
+      m_clipBox.left -= static_cast<int32_t>(ceil((float)start_x * scaleX));
     }
     if (out_range_x > 0) {
-      m_clipBox.right -= (int32_t)floor((float)out_range_x * scaleX);
+      m_clipBox.right -=
+          static_cast<int32_t>(floor((float)out_range_x * scaleX));
     }
   }
   if (start_y < 0 || out_range_y > 0) {
     float scaleY = (float)m_clipBox.Height() / (float)size_y;
     if (start_y < 0) {
-      m_clipBox.top -= (int32_t)ceil((float)start_y * scaleY);
+      m_clipBox.top -= static_cast<int32_t>(ceil((float)start_y * scaleY));
     }
     if (out_range_y > 0) {
-      m_clipBox.bottom -= (int32_t)floor((float)out_range_y * scaleY);
+      m_clipBox.bottom -=
+          static_cast<int32_t>(floor((float)out_range_y * scaleY));
     }
   }
   if (m_clipBox.IsEmpty()) {
diff --git a/core/fxcodec/tiff/tiff_decoder.cpp b/core/fxcodec/tiff/tiff_decoder.cpp
index 2595425..7fcc59b 100644
--- a/core/fxcodec/tiff/tiff_decoder.cpp
+++ b/core/fxcodec/tiff/tiff_decoder.cpp
@@ -14,6 +14,7 @@
 #include "core/fxcodec/fx_codec_def.h"
 #include "core/fxcrt/fx_safe_types.h"
 #include "core/fxcrt/fx_stream.h"
+#include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/retain_ptr.h"
 #include "core/fxge/dib/cfx_dibitmap.h"
 #include "core/fxge/dib/fx_dib.h"
@@ -263,13 +264,13 @@
                                pAttribute)) {
     void* val = pAttribute->m_Exif[TIFFTAG_XRESOLUTION];
     float fDpi = val ? *reinterpret_cast<float*>(val) : 0;
-    pAttribute->m_nXDPI = (int32_t)(fDpi + 0.5f);
+    pAttribute->m_nXDPI = static_cast<int32_t>(fDpi + 0.5f);
   }
   if (Tiff_Exif_GetInfo<float>(m_tif_ctx.get(), TIFFTAG_YRESOLUTION,
                                pAttribute)) {
     void* val = pAttribute->m_Exif[TIFFTAG_YRESOLUTION];
     float fDpi = val ? *reinterpret_cast<float*>(val) : 0;
-    pAttribute->m_nYDPI = (int32_t)(fDpi + 0.5f);
+    pAttribute->m_nYDPI = static_cast<int32_t>(fDpi + 0.5f);
   }
   Tiff_Exif_GetStringInfo(m_tif_ctx.get(), TIFFTAG_IMAGEDESCRIPTION,
                           pAttribute);
@@ -358,7 +359,7 @@
     return false;
   }
   SetPalette(pDIBitmap, bps);
-  int32_t size = (int32_t)TIFFScanlineSize(m_tif_ctx.get());
+  int32_t size = static_cast<int32_t>(TIFFScanlineSize(m_tif_ctx.get()));
   uint8_t* buf = (uint8_t*)_TIFFmalloc(size);
   if (!buf) {
     TIFFError(TIFFFileName(m_tif_ctx.get()), "No space for scanline buffer");
@@ -386,7 +387,7 @@
     return false;
   }
   SetPalette(pDIBitmap, bps);
-  int32_t size = (int32_t)TIFFScanlineSize(m_tif_ctx.get());
+  int32_t size = static_cast<int32_t>(TIFFScanlineSize(m_tif_ctx.get()));
   uint8_t* buf = (uint8_t*)_TIFFmalloc(size);
   if (!buf) {
     TIFFError(TIFFFileName(m_tif_ctx.get()), "No space for scanline buffer");
@@ -420,7 +421,7 @@
   if (pDIBitmap->GetBPP() != 24 || !IsSupport(pDIBitmap))
     return false;
 
-  int32_t size = (int32_t)TIFFScanlineSize(m_tif_ctx.get());
+  int32_t size = static_cast<int32_t>(TIFFScanlineSize(m_tif_ctx.get()));
   uint8_t* buf = (uint8_t*)_TIFFmalloc(size);
   if (!buf) {
     TIFFError(TIFFFileName(m_tif_ctx.get()), "No space for scanline buffer");
diff --git a/core/fxcrt/css/cfx_cssdeclaration.cpp b/core/fxcrt/css/cfx_cssdeclaration.cpp
index ff7e3be..ad49588 100644
--- a/core/fxcrt/css/cfx_cssdeclaration.cpp
+++ b/core/fxcrt/css/cfx_cssdeclaration.cpp
@@ -18,6 +18,7 @@
 #include "core/fxcrt/css/cfx_cssvaluelist.h"
 #include "core/fxcrt/css/cfx_cssvaluelistparser.h"
 #include "core/fxcrt/fx_extension.h"
+#include "core/fxcrt/fx_system.h"
 #include "third_party/base/notreached.h"
 
 namespace {
@@ -576,7 +577,7 @@
         if (!ParseCSSNumber(pszValue, iValueLen, &fValue, &eNumType))
           break;
         if (eType == CFX_CSSPrimitiveType::Number) {
-          switch ((int32_t)fValue) {
+          switch (static_cast<int32_t>(fValue)) {
             case 100:
             case 200:
             case 300:
diff --git a/core/fxcrt/css/cfx_cssstyleselector.cpp b/core/fxcrt/css/cfx_cssstyleselector.cpp
index 5cc1312..2c119b0 100644
--- a/core/fxcrt/css/cfx_cssstyleselector.cpp
+++ b/core/fxcrt/css/cfx_cssstyleselector.cpp
@@ -219,7 +219,8 @@
               ToFontWeight(pValue.As<CFX_CSSEnumValue>()->Value());
         } else if (eType == CFX_CSSPrimitiveType::Number) {
           int32_t iValue =
-              (int32_t)pValue.As<CFX_CSSNumberValue>()->Value() / 100;
+              static_cast<int32_t>(pValue.As<CFX_CSSNumberValue>()->Value()) /
+              100;
           if (iValue >= 1 && iValue <= 9) {
             pComputedStyle->m_InheritedData.m_wFontWeight = iValue * 100;
           }
diff --git a/fxbarcode/oned/BC_OneDimWriter.cpp b/fxbarcode/oned/BC_OneDimWriter.cpp
index b4db093..e194bd1 100644
--- a/fxbarcode/oned/BC_OneDimWriter.cpp
+++ b/fxbarcode/oned/BC_OneDimWriter.cpp
@@ -169,7 +169,7 @@
                                        float locX,
                                        float locY,
                                        int32_t barWidth) {
-  int32_t iFontSize = (int32_t)fabs(m_fFontSize);
+  int32_t iFontSize = static_cast<int32_t>(fabs(m_fFontSize));
   int32_t iTextHeight = iFontSize + 1;
   CFX_FloatRect rect((float)locX, (float)locY, (float)(locX + geWidth),
                      (float)(locY + iTextHeight));
@@ -207,7 +207,7 @@
              m_locTextLoc == BC_TEXT_LOC_BELOW) {
     geWidth = (float)barWidth;
   }
-  int32_t iFontSize = (int32_t)fabs(m_fFontSize);
+  int32_t iFontSize = static_cast<int32_t>(fabs(m_fFontSize));
   int32_t iTextHeight = iFontSize + 1;
   CalcTextInfo(str, charpos.data(), m_pFont.Get(), geWidth, iFontSize,
                charsLen);
@@ -218,7 +218,7 @@
   int32_t locY = 0;
   switch (m_locTextLoc) {
     case BC_TEXT_LOC_ABOVEEMBED:
-      locX = (int32_t)(barWidth - charsLen) / 2;
+      locX = static_cast<int32_t>(barWidth - charsLen) / 2;
       locY = 0;
       geWidth = charsLen;
       break;
@@ -228,7 +228,7 @@
       geWidth = (float)barWidth;
       break;
     case BC_TEXT_LOC_BELOWEMBED:
-      locX = (int32_t)(barWidth - charsLen) / 2;
+      locX = static_cast<int32_t>(barWidth - charsLen) / 2;
       locY = m_Height - iTextHeight;
       geWidth = charsLen;
       break;
diff --git a/fxbarcode/oned/BC_OneDimWriter.h b/fxbarcode/oned/BC_OneDimWriter.h
index 32664a0..38f5879 100644
--- a/fxbarcode/oned/BC_OneDimWriter.h
+++ b/fxbarcode/oned/BC_OneDimWriter.h
@@ -10,6 +10,7 @@
 #include <vector>
 
 #include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/unowned_ptr.h"
 #include "core/fxge/cfx_textrenderoptions.h"
 #include "fxbarcode/BC_Library.h"
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
index 2e68114..2cdb341 100644
--- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp
@@ -140,7 +140,7 @@
   ByteString str = FX_UTF8Encode(contents);
   size_t length = str.GetLength();
   std::vector<TextCharPos> charpos(length);
-  int32_t iFontSize = (int32_t)fabs(m_fFontSize);
+  int32_t iFontSize = static_cast<int32_t>(fabs(m_fFontSize));
   int32_t iTextHeight = iFontSize + 1;
   ByteString tempStr = str.Substr(1, 6);
   int32_t strWidth = multiple * 42;
@@ -168,7 +168,7 @@
 
   float blank = 0.0;
   length = tempStr.GetLength();
-  strWidth = (int32_t)(strWidth * m_outputHScale);
+  strWidth = static_cast<int32_t>(strWidth * m_outputHScale);
 
   CalcTextInfo(tempStr, &charpos[1], m_pFont.Get(), (float)strWidth, iFontSize,
                blank);
@@ -200,7 +200,7 @@
   tempStr = str.First(1);
   length = tempStr.GetLength();
   strWidth = multiple * 7;
-  strWidth = (int32_t)(strWidth * m_outputHScale);
+  strWidth = static_cast<int32_t>(strWidth * m_outputHScale);
 
   CalcTextInfo(tempStr, charpos.data(), m_pFont.Get(), (float)strWidth,
                iFontSize, blank);
diff --git a/fxbarcode/oned/BC_OnedEAN8Writer.cpp b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
index 9826054..e35784f 100644
--- a/fxbarcode/oned/BC_OnedEAN8Writer.cpp
+++ b/fxbarcode/oned/BC_OnedEAN8Writer.cpp
@@ -144,7 +144,7 @@
   int32_t strWidth = 7 * multiple * 4;
   float blank = 0.0;
 
-  int32_t iFontSize = (int32_t)fabs(m_fFontSize);
+  int32_t iFontSize = static_cast<int32_t>(fabs(m_fFontSize));
   int32_t iTextHeight = iFontSize + 1;
 
   CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
@@ -160,7 +160,7 @@
   matr1.Concat(*matrix);
   re = matr1.TransformRect(rect1).GetOuterRect();
   device->FillRect(re, kBackgroundColor);
-  strWidth = (int32_t)(strWidth * m_outputHScale);
+  strWidth = static_cast<int32_t>(strWidth * m_outputHScale);
 
   CalcTextInfo(tempStr, charpos.data(), m_pFont.Get(), (float)strWidth,
                iFontSize, blank);
diff --git a/fxbarcode/oned/BC_OnedUPCAWriter.cpp b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
index b344999..c9b3691 100644
--- a/fxbarcode/oned/BC_OnedUPCAWriter.cpp
+++ b/fxbarcode/oned/BC_OnedUPCAWriter.cpp
@@ -119,7 +119,7 @@
   float blank = 0.0;
 
   length = tempStr.GetLength();
-  int32_t iFontSize = (int32_t)fabs(m_fFontSize);
+  int32_t iFontSize = static_cast<int32_t>(fabs(m_fFontSize));
   int32_t iTextHeight = iFontSize + 1;
 
   CFX_Matrix matr(m_outputHScale, 0.0, 0.0, 1.0, 0.0, 0.0);
diff --git a/fxjs/xfa/cfxjse_formcalc_context.cpp b/fxjs/xfa/cfxjse_formcalc_context.cpp
index bff56a5..dfd60b3 100644
--- a/fxjs/xfa/cfxjse_formcalc_context.cpp
+++ b/fxjs/xfa/cfxjse_formcalc_context.cpp
@@ -6,8 +6,10 @@
 
 #include "fxjs/xfa/cfxjse_formcalc_context.h"
 
+#include <stdlib.h>
+
 #include <algorithm>
-#include <cstdlib>
+#include <cctype>
 #include <utility>
 
 #include "core/fxcrt/cfx_widetextbuf.h"
@@ -819,7 +821,7 @@
     ++dDays;
     ++i;
   }
-  return (int32_t)dDays;
+  return static_cast<int32_t>(dDays);
 }
 
 void GetLocalTimeZone(int32_t* pHour, int32_t* pMin, int32_t* pSec) {
@@ -2106,8 +2108,8 @@
     return;
   }
 
-  info.GetReturnValue().Set(dDividend -
-                            dDivisor * (int32_t)(dDividend / dDivisor));
+  info.GetReturnValue().Set(
+      dDividend - dDivisor * static_cast<int32_t>(dDividend / dDivisor));
 }
 
 // static
@@ -2332,7 +2334,7 @@
       return;
     }
 
-    iStyle = (int32_t)ValueToFloat(info.GetIsolate(), infotyle);
+    iStyle = static_cast<int32_t>(ValueToFloat(info.GetIsolate(), infotyle));
     if (iStyle < 0 || iStyle > 4)
       iStyle = 0;
   }
@@ -2441,7 +2443,7 @@
       info.GetReturnValue().SetNull();
       return;
     }
-    iStyle = (int32_t)ValueToFloat(info.GetIsolate(), infotyle);
+    iStyle = static_cast<int32_t>(ValueToFloat(info.GetIsolate(), infotyle));
     if (iStyle > 4 || iStyle < 0)
       iStyle = 0;
   }
@@ -2479,7 +2481,7 @@
       info.GetReturnValue().SetNull();
       return;
     }
-    iStyle = (int32_t)ValueToFloat(info.GetIsolate(), infotyle);
+    iStyle = static_cast<int32_t>(ValueToFloat(info.GetIsolate(), infotyle));
     if (iStyle > 4 || iStyle < 0)
       iStyle = 0;
   }
@@ -2515,7 +2517,8 @@
     info.GetReturnValue().SetNull();
     return;
   }
-  int32_t dDate = (int32_t)ValueToFloat(info.GetIsolate(), dateValue);
+  int32_t dDate =
+      static_cast<int32_t>(ValueToFloat(info.GetIsolate(), dateValue));
   if (dDate < 1) {
     info.GetReturnValue().SetNull();
     return;
@@ -2656,7 +2659,8 @@
     info.GetReturnValue().SetNull();
     return;
   }
-  int32_t iTime = (int32_t)ValueToFloat(info.GetIsolate(), timeValue);
+  int32_t iTime =
+      static_cast<int32_t>(ValueToFloat(info.GetIsolate(), timeValue));
   if (abs(iTime) < 1.0) {
     info.GetReturnValue().SetNull();
     return;
@@ -2854,7 +2858,7 @@
       info.GetReturnValue().SetNull();
       return;
     }
-    iStyle = (int32_t)ValueToFloat(info.GetIsolate(), infotyle);
+    iStyle = static_cast<int32_t>(ValueToFloat(info.GetIsolate(), infotyle));
     if (iStyle > 4 || iStyle < 0)
       iStyle = 0;
   }
@@ -3177,11 +3181,12 @@
   }
 
   float nRateOfMonth = nRate / 12;
-  int32_t iNums =
-      (int32_t)((log10((float)(nPayment / nPrincipalAmount)) -
-                 log10((float)(nPayment / nPrincipalAmount - nRateOfMonth))) /
-                log10((float)(1 + nRateOfMonth)));
-  int32_t iEnd = std::min((int32_t)(nFirstMonth + nNumberOfMonths - 1), iNums);
+  int32_t iNums = static_cast<int32_t>(
+      (log10((float)(nPayment / nPrincipalAmount)) -
+       log10((float)(nPayment / nPrincipalAmount - nRateOfMonth))) /
+      log10((float)(1 + nRateOfMonth)));
+  int32_t iEnd =
+      std::min(static_cast<int32_t>(nFirstMonth + nNumberOfMonths - 1), iNums);
 
   if (nPayment < nPrincipalAmount * nRateOfMonth) {
     info.GetReturnValue().Set(0);
@@ -3315,11 +3320,12 @@
   }
 
   float nRateOfMonth = nRate / 12;
-  int32_t iNums =
-      (int32_t)((log10((float)(nPayment / nPrincipalAmount)) -
-                 log10((float)(nPayment / nPrincipalAmount - nRateOfMonth))) /
-                log10((float)(1 + nRateOfMonth)));
-  int32_t iEnd = std::min((int32_t)(nFirstMonth + nNumberOfMonths - 1), iNums);
+  int32_t iNums = static_cast<int32_t>(
+      (log10((float)(nPayment / nPrincipalAmount)) -
+       log10((float)(nPayment / nPrincipalAmount - nRateOfMonth))) /
+      log10((float)(1 + nRateOfMonth)));
+  int32_t iEnd =
+      std::min(static_cast<int32_t>(nFirstMonth + nNumberOfMonths - 1), iNums);
   if (nPayment < nPrincipalAmount * nRateOfMonth) {
     pContext->ThrowArgumentMismatchException();
     return;
@@ -3455,7 +3461,8 @@
     return;
   }
 
-  int32_t iIndex = (int32_t)ValueToFloat(info.GetIsolate(), info[0]);
+  int32_t iIndex =
+      static_cast<int32_t>(ValueToFloat(info.GetIsolate(), info[0]));
   if (iIndex < 1) {
     info.GetReturnValue().SetEmptyString();
     return;
diff --git a/fxjs/xfa/cfxjse_formcalc_context.h b/fxjs/xfa/cfxjse_formcalc_context.h
index 9fdd4f8..c382ab8 100644
--- a/fxjs/xfa/cfxjse_formcalc_context.h
+++ b/fxjs/xfa/cfxjse_formcalc_context.h
@@ -10,6 +10,7 @@
 #include <memory>
 #include <vector>
 
+#include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/unowned_ptr.h"
 #include "fxjs/xfa/fxjse.h"
 #include "third_party/base/optional.h"
diff --git a/xfa/fgas/graphics/cfgas_gegraphics.cpp b/xfa/fgas/graphics/cfgas_gegraphics.cpp
index ae2c0c7..5c5d8a7 100644
--- a/xfa/fgas/graphics/cfgas_gegraphics.cpp
+++ b/xfa/fgas/graphics/cfgas_gegraphics.cpp
@@ -376,7 +376,7 @@
               continue;
             s = 1.0f;
           }
-          int index = (int32_t)(s * (FX_SHADING_Steps - 1));
+          int index = static_cast<int32_t>(s * (FX_SHADING_Steps - 1));
           dib_buf[column] = m_info.fillColor.GetShading()->m_argbArray[index];
         }
       }
diff --git a/xfa/fxfa/cxfa_ffwidget.cpp b/xfa/fxfa/cxfa_ffwidget.cpp
index ccc604a..ab93a8a 100644
--- a/xfa/fxfa/cxfa_ffwidget.cpp
+++ b/xfa/fxfa/cxfa_ffwidget.cpp
@@ -164,12 +164,14 @@
   pProgressiveDecoder->LoadImageInfo(pImageFileRead, type, &dibAttr, false);
   switch (dibAttr.m_wDPIUnit) {
     case FXCODEC_RESUNIT_CENTIMETER:
-      dibAttr.m_nXDPI = (int32_t)(dibAttr.m_nXDPI * 2.54f);
-      dibAttr.m_nYDPI = (int32_t)(dibAttr.m_nYDPI * 2.54f);
+      dibAttr.m_nXDPI = static_cast<int32_t>(dibAttr.m_nXDPI * 2.54f);
+      dibAttr.m_nYDPI = static_cast<int32_t>(dibAttr.m_nYDPI * 2.54f);
       break;
     case FXCODEC_RESUNIT_METER:
-      dibAttr.m_nXDPI = (int32_t)(dibAttr.m_nXDPI / (float)100 * 2.54f);
-      dibAttr.m_nYDPI = (int32_t)(dibAttr.m_nYDPI / (float)100 * 2.54f);
+      dibAttr.m_nXDPI =
+          static_cast<int32_t>(dibAttr.m_nXDPI / (float)100 * 2.54f);
+      dibAttr.m_nYDPI =
+          static_cast<int32_t>(dibAttr.m_nYDPI / (float)100 * 2.54f);
       break;
     default:
       break;
diff --git a/xfa/fxfa/cxfa_ffwidget.h b/xfa/fxfa/cxfa_ffwidget.h
index b319ad4..8ce7ed7 100644
--- a/xfa/fxfa/cxfa_ffwidget.h
+++ b/xfa/fxfa/cxfa_ffwidget.h
@@ -9,6 +9,7 @@
 
 #include "core/fpdfdoc/cpdf_formfield.h"
 #include "core/fxcodec/fx_codec_def.h"
+#include "core/fxcrt/fx_system.h"
 #include "core/fxge/cfx_graphstatedata.h"
 #include "fxjs/gc/heap.h"
 #include "v8/include/cppgc/garbage-collected.h"
diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp
index 1e74a81..3ae9307 100644
--- a/xfa/fxfa/parser/cxfa_document.cpp
+++ b/xfa/fxfa/parser/cxfa_document.cpp
@@ -1475,7 +1475,8 @@
                      .Substr(nDotPos.value() + 1,
                              wsTemplateNS.GetLength() - nDotPos.value() - 2)
                      .c_str());
-  XFA_VERSION eVersion = (XFA_VERSION)((int32_t)iMajor * 100 + iMinor);
+  XFA_VERSION eVersion =
+      static_cast<XFA_VERSION>(static_cast<int32_t>(iMajor) * 100 + iMinor);
   if (eVersion < XFA_VERSION_MIN || eVersion > XFA_VERSION_MAX)
     return XFA_VERSION_UNKNOWN;
 
diff --git a/xfa/fxfa/parser/cxfa_document.h b/xfa/fxfa/parser/cxfa_document.h
index ca8d8fc..c27d76a 100644
--- a/xfa/fxfa/parser/cxfa_document.h
+++ b/xfa/fxfa/parser/cxfa_document.h
@@ -11,6 +11,7 @@
 #include <memory>
 #include <vector>
 
+#include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/unowned_ptr.h"
 #include "fxjs/gc/heap.h"
 #include "third_party/base/optional.h"
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index af3473c..e441d58 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -3660,7 +3660,7 @@
     return pdfium::nullopt;
 
   for (size_t i = 0; i < szBlockIndex * 3; i += 3) {
-    iLinesCount -= (int32_t)(*pFieldArray)[i + 1];
+    iLinesCount -= static_cast<int32_t>((*pFieldArray)[i + 1]);
     fHeight -= (*pFieldArray)[i + 2];
   }
   if (iLinesCount == 0)
@@ -3758,8 +3758,8 @@
 
   float fTextNum =
       fCalcHeight + kXFAWidgetPrecision - fCapReserve - fStartOffset;
-  int32_t iLineNum =
-      (int32_t)((fTextNum + (fLineHeight - fFontSize)) / fLineHeight);
+  int32_t iLineNum = static_cast<int32_t>(
+      (fTextNum + (fLineHeight - fFontSize)) / fLineHeight);
   if (iLineNum >= iLinesCount) {
     if (fCalcHeight - fStartOffset - fTextHeight >= fFontSize) {
       if (szFieldSplitCount / 3 == (szBlockIndex + 1)) {
@@ -3776,7 +3776,7 @@
       if (iLineNum == 0)
         return 0.0f;
     } else {
-      iLineNum = (int32_t)(fTextNum / fLineHeight);
+      iLineNum = static_cast<int32_t>(fTextNum / fLineHeight);
     }
   }
   if (iLineNum <= 0)
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index ce11e31..e249814 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -11,6 +11,7 @@
 #include <vector>
 
 #include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/unowned_ptr.h"
 #include "core/fxge/dib/fx_dib.h"
 #include "fxjs/gc/gced_tree_node_mixin.h"