Convert another batch of fpdfsdk files to avoid shortening

Many of these are just checked_cast, because they are assigned
at API boundaries to types that can't be changed, or used in
arithmetic.

Change-Id: I5ab65bb51279b235a9e25dfb742eabf37697a75c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/91351
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_annotiterator.cpp b/fpdfsdk/cpdfsdk_annotiterator.cpp
index aa373d4..2bc4c67 100644
--- a/fpdfsdk/cpdfsdk_annotiterator.cpp
+++ b/fpdfsdk/cpdfsdk_annotiterator.cpp
@@ -10,6 +10,7 @@
 
 #include "core/fpdfapi/page/cpdf_page.h"
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
+#include "core/fxcrt/stl_util.h"
 #include "fpdfsdk/cpdfsdk_annot.h"
 #include "fpdfsdk/cpdfsdk_pageview.h"
 #include "fpdfsdk/cpdfsdk_widget.h"
@@ -94,8 +95,8 @@
   for (size_t i = 0; i < aSelect->size(); ++i)
     m_Annots.emplace_back(sa->at(aSelect->at(i)));
 
-  for (int i = aSelect->size() - 1; i >= 0; --i)
-    sa->erase(sa->begin() + aSelect->at(i));
+  for (size_t i = aSelect->size(); i > 0; --i)
+    sa->erase(sa->begin() + aSelect->at(i - 1));
 }
 
 // static
@@ -124,7 +125,7 @@
       while (!sa.empty()) {
         int nLeftTopIndex = -1;
         float fTop = 0.0f;
-        for (int i = sa.size() - 1; i >= 0; i--) {
+        for (int i = fxcrt::CollectionSize<int>(sa) - 1; i >= 0; i--) {
           CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
           if (rcAnnot.top > fTop) {
             nLeftTopIndex = i;
@@ -156,7 +157,7 @@
       while (!sa.empty()) {
         int nLeftTopIndex = -1;
         float fLeft = -1.0f;
-        for (int i = sa.size() - 1; i >= 0; --i) {
+        for (int i = fxcrt::CollectionSize<int>(sa) - 1; i >= 0; --i) {
           CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]);
           if (fLeft < 0) {
             nLeftTopIndex = 0;
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index 95b2bb7..beed063 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -340,7 +340,8 @@
     return;
 
   ByteString bsUrl = URL.ToUTF16LE();
-  js_platform->Doc_submitForm(js_platform, form_data.data(), form_data.size(),
+  js_platform->Doc_submitForm(js_platform, form_data.data(),
+                              fxcrt::CollectionSize<int>(form_data),
                               AsFPDFWideString(&bsUrl));
 }
 
@@ -404,7 +405,7 @@
     const WideString& text,
     bool bFocus) {
   if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus) {
-    int nCharacters = text.GetLength();
+    size_t nCharacters = text.GetLength();
     ByteString bsUTFText = text.ToUTF16LE();
     auto* pBuffer = reinterpret_cast<const unsigned short*>(bsUTFText.c_str());
     m_pInfo->FFI_SetTextFieldFocus(m_pInfo, pBuffer, nCharacters, bFocus);
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp
index 11b9872..5c93834 100644
--- a/fpdfsdk/cpdfsdk_helpers.cpp
+++ b/fpdfsdk/cpdfsdk_helpers.cpp
@@ -445,10 +445,14 @@
 void SetColorFromScheme(const FPDF_COLORSCHEME* pColorScheme,
                         CPDF_RenderOptions* pRenderOptions) {
   CPDF_RenderOptions::ColorScheme color_scheme;
-  color_scheme.path_fill_color = pColorScheme->path_fill_color;
-  color_scheme.path_stroke_color = pColorScheme->path_stroke_color;
-  color_scheme.text_fill_color = pColorScheme->text_fill_color;
-  color_scheme.text_stroke_color = pColorScheme->text_stroke_color;
+  color_scheme.path_fill_color =
+      static_cast<FX_ARGB>(pColorScheme->path_fill_color);
+  color_scheme.path_stroke_color =
+      static_cast<FX_ARGB>(pColorScheme->path_stroke_color);
+  color_scheme.text_fill_color =
+      static_cast<FX_ARGB>(pColorScheme->text_fill_color);
+  color_scheme.text_stroke_color =
+      static_cast<FX_ARGB>(pColorScheme->text_stroke_color);
   pRenderOptions->SetColorScheme(color_scheme);
 }
 
diff --git a/fpdfsdk/cpdfsdk_interactiveform.cpp b/fpdfsdk/cpdfsdk_interactiveform.cpp
index 696e16c..9d56709 100644
--- a/fpdfsdk/cpdfsdk_interactiveform.cpp
+++ b/fpdfsdk/cpdfsdk_interactiveform.cpp
@@ -155,7 +155,7 @@
 void CPDFSDK_InteractiveForm::GetWidgets(
     const WideString& sFieldName,
     std::vector<ObservedPtr<CPDFSDK_Annot>>* widgets) const {
-  for (int i = 0, sz = m_pInteractiveForm->CountFields(sFieldName); i < sz;
+  for (size_t i = 0, sz = m_pInteractiveForm->CountFields(sFieldName); i < sz;
        ++i) {
     CPDF_FormField* pFormField = m_pInteractiveForm->GetField(i, sFieldName);
     DCHECK(pFormField);
diff --git a/fpdfsdk/fpdf_editimg.cpp b/fpdfsdk/fpdf_editimg.cpp
index fae6b4c..4f63807 100644
--- a/fpdfsdk/fpdf_editimg.cpp
+++ b/fpdfsdk/fpdf_editimg.cpp
@@ -21,6 +21,7 @@
 #include "core/fpdfapi/render/cpdf_imagerenderer.h"
 #include "core/fpdfapi/render/cpdf_rendercontext.h"
 #include "core/fpdfapi/render/cpdf_renderstatus.h"
+#include "core/fxcrt/stl_util.h"
 #include "core/fxge/cfx_defaultrenderdevice.h"
 #include "fpdfsdk/cpdfsdk_customaccess.h"
 #include "fpdfsdk/cpdfsdk_helpers.h"
@@ -312,7 +313,8 @@
     return 0;
 
   if (pFilter->IsArray())
-    return pFilter->AsArray()->size();
+    return fxcrt::CollectionSize<int>(*pFilter->AsArray());
+
   if (pFilter->IsName())
     return 1;
 
diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp
index d238e4a..a027c9c 100644
--- a/fpdfsdk/fpdf_formfill.cpp
+++ b/fpdfsdk/fpdf_formfill.cpp
@@ -713,7 +713,7 @@
     return;
 
   if (cast_input.value() == FormFieldType::kUnknown)
-    pForm->SetAllHighlightColors(color);
+    pForm->SetAllHighlightColors(static_cast<FX_COLORREF>(color));
   else
     pForm->SetHighlightColor(color, cast_input.value());
 }
diff --git a/fpdfsdk/fpdf_javascript.cpp b/fpdfsdk/fpdf_javascript.cpp
index e333bfa..0f6826a 100644
--- a/fpdfsdk/fpdf_javascript.cpp
+++ b/fpdfsdk/fpdf_javascript.cpp
@@ -11,6 +11,7 @@
 #include "core/fpdfdoc/cpdf_action.h"
 #include "core/fpdfdoc/cpdf_nametree.h"
 #include "fpdfsdk/cpdfsdk_helpers.h"
+#include "third_party/base/numerics/safe_conversions.h"
 
 struct CPDF_JavaScript {
   WideString name;
@@ -24,7 +25,7 @@
     return -1;
 
   auto name_tree = CPDF_NameTree::Create(doc, "JavaScript");
-  return name_tree ? name_tree->GetCount() : 0;
+  return name_tree ? pdfium::base::checked_cast<int>(name_tree->GetCount()) : 0;
 }
 
 FPDF_EXPORT FPDF_JAVASCRIPT_ACTION FPDF_CALLCONV
diff --git a/fpdfsdk/fpdf_save.cpp b/fpdfsdk/fpdf_save.cpp
index f7ffabd..4fb5d3f 100644
--- a/fpdfsdk/fpdf_save.cpp
+++ b/fpdfsdk/fpdf_save.cpp
@@ -18,6 +18,7 @@
 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
 #include "core/fpdfapi/parser/cpdf_string.h"
 #include "core/fxcrt/fx_extension.h"
+#include "core/fxcrt/stl_util.h"
 #include "fpdfsdk/cpdfsdk_filewriteadapter.h"
 #include "fpdfsdk/cpdfsdk_helpers.h"
 #include "public/fpdf_edit.h"
@@ -61,7 +62,7 @@
   if (!pArray)
     return false;
 
-  int size = pArray->size();
+  int size = fxcrt::CollectionSize<int>(*pArray);
   int iFormIndex = -1;
   int iDataSetsIndex = -1;
   for (int i = 0; i < size - 1; i++) {
@@ -116,7 +117,7 @@
       } else {
         CPDF_Stream* pData = pPDFDocument->NewIndirect<CPDF_Stream>();
         pData->InitStreamFromFile(pFileWrite, std::move(pDataDict));
-        int iLast = pArray->size() - 2;
+        int iLast = fxcrt::CollectionSize<int>(*pArray) - 2;
         pArray->InsertNewAt<CPDF_String>(iLast, "datasets", false);
         pArray->InsertNewAt<CPDF_Reference>(iLast + 1, pPDFDocument,
                                             pData->GetObjNum());
@@ -136,7 +137,7 @@
       } else {
         CPDF_Stream* pData = pPDFDocument->NewIndirect<CPDF_Stream>();
         pData->InitStreamFromFile(pFileWrite, std::move(pDataDict));
-        int iLast = pArray->size() - 2;
+        int iLast = fxcrt::CollectionSize<int>(*pArray) - 2;
         pArray->InsertNewAt<CPDF_String>(iLast, "form", false);
         pArray->InsertNewAt<CPDF_Reference>(iLast + 1, pPDFDocument,
                                             pData->GetObjNum());
@@ -177,7 +178,7 @@
     fileMaker.RemoveSecurity();
   }
 
-  bool bRet = fileMaker.Create(flags);
+  bool bRet = fileMaker.Create(static_cast<uint32_t>(flags));
 
 #ifdef PDF_ENABLE_XFA
   if (pContext)
diff --git a/fpdfsdk/fpdf_structtree.cpp b/fpdfsdk/fpdf_structtree.cpp
index 89f5f30..e121e48 100644
--- a/fpdfsdk/fpdf_structtree.cpp
+++ b/fpdfsdk/fpdf_structtree.cpp
@@ -140,7 +140,7 @@
     return -1;
 
   if (attr_obj->IsArray())
-    return attr_obj->AsArray()->size();
+    return fxcrt::CollectionSize<int>(*attr_obj->AsArray());
   return attr_obj->IsDictionary() ? 1 : -1;
 }
 
diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp
index 3ab7ba5..ffdb842 100644
--- a/fpdfsdk/fpdf_sysfontinfo.cpp
+++ b/fpdfsdk/fpdf_sysfontinfo.cpp
@@ -112,7 +112,7 @@
   bool GetFaceName(void* hFont, ByteString* name) override {
     if (!m_pInfo->GetFaceName)
       return false;
-    uint32_t size = m_pInfo->GetFaceName(m_pInfo, hFont, nullptr, 0);
+    size_t size = m_pInfo->GetFaceName(m_pInfo, hFont, nullptr, 0);
     if (size == 0)
       return false;
     char* buffer = FX_Alloc(char, size);
diff --git a/fpdfsdk/fpdf_text.cpp b/fpdfsdk/fpdf_text.cpp
index 10a82ff..d766393 100644
--- a/fpdfsdk/fpdf_text.cpp
+++ b/fpdfsdk/fpdf_text.cpp
@@ -20,7 +20,7 @@
 #include "core/fpdftext/cpdf_textpagefind.h"
 #include "core/fxcrt/stl_util.h"
 #include "fpdfsdk/cpdfsdk_helpers.h"
-#include "third_party/base/check.h"
+#include "third_party/base/check_op.h"
 #include "third_party/base/numerics/safe_conversions.h"
 
 namespace {
@@ -310,11 +310,13 @@
   // the number of items to stay the same.
   ByteString byte_str = str.ToUTF16LE();
   size_t byte_str_len = byte_str.GetLength();
-  int ret_count = byte_str_len / kBytesPerCharacter;
+  size_t ret_count = byte_str_len / kBytesPerCharacter;
 
-  DCHECK(ret_count <= char_count + 1);  // +1 to account for the NUL terminator.
+  // +1 to account for the NUL terminator.
+  DCHECK_LE(ret_count, static_cast<size_t>(char_count) + 1);
+
   memcpy(result, byte_str.c_str(), byte_str_len);
-  return ret_count;
+  return pdfium::base::checked_cast<int>(ret_count);
 }
 
 FPDF_EXPORT int FPDF_CALLCONV FPDFText_CountRects(FPDF_TEXTPAGE text_page,
@@ -359,14 +361,14 @@
   WideString str = textpage->GetTextByRect(rect);
 
   if (buflen <= 0 || !buffer)
-    return str.GetLength();
+    return pdfium::base::checked_cast<int>(str.GetLength());
 
   ByteString cbUTF16Str = str.ToUTF16LE();
-  int len = cbUTF16Str.GetLength() / sizeof(unsigned short);
+  int len = pdfium::base::checked_cast<int>(cbUTF16Str.GetLength()) /
+            sizeof(unsigned short);
   int size = buflen > len ? len : buflen;
   memcpy(buffer, cbUTF16Str.c_str(), size * sizeof(unsigned short));
   cbUTF16Str.ReleaseBuffer(size * sizeof(unsigned short));
-
   return size;
 }
 
@@ -465,7 +467,8 @@
     wsUrl = pageLink->GetURL(link_index);
   }
   ByteString cbUTF16URL = wsUrl.ToUTF16LE();
-  int required = cbUTF16URL.GetLength() / sizeof(unsigned short);
+  int required = pdfium::base::checked_cast<int>(cbUTF16URL.GetLength() /
+                                                 sizeof(unsigned short));
   if (!buffer || buflen <= 0)
     return required;
 
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index ea41d00..ffd3540 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -26,6 +26,7 @@
 #include "core/fxge/cfx_fillrenderoptions.h"
 #include "core/fxge/cfx_path.h"
 #include "fpdfsdk/cpdfsdk_helpers.h"
+#include "third_party/base/numerics/safe_conversions.h"
 #include "third_party/base/span.h"
 
 namespace {
@@ -321,7 +322,7 @@
   if (!pClipPath || !pClipPath->HasRef())
     return -1;
 
-  return pClipPath->GetPathCount();
+  return pdfium::base::checked_cast<int>(pClipPath->GetPathCount());
 }
 
 FPDF_EXPORT int FPDF_CALLCONV