Use int16_t with CPDF_CIDFont::GetVertOrigin().

Instead of using the type short, use int16_t, which is consistently 16
bits. Do the same for CPDF_CIDFont::GetVertWidth() and fix a few nits
along the way.

Change-Id: Ibef09146e09a079b55b8a60fcee4b6f6b8070d91
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/71915
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index 41b267f..327dbe2 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -201,8 +201,8 @@
     FT_Set_Charmap(face, *FXFT_Get_Face_Charmaps(face));
 }
 
-bool IsMetricForCID(const uint32_t* pEntry, uint16_t CID) {
-  return pEntry[0] <= CID && pEntry[1] >= CID;
+bool IsMetricForCID(const uint32_t* pEntry, uint16_t cid) {
+  return pEntry[0] <= cid && pEntry[1] >= cid;
 }
 
 }  // namespace
@@ -289,13 +289,13 @@
     case CIDCODING_CID: {
       if (!m_pCID2UnicodeMap || !m_pCID2UnicodeMap->IsLoaded())
         return 0;
-      uint32_t CID = 0;
-      while (CID < 65536) {
+      uint32_t cid = 0;
+      while (cid < 65536) {
         wchar_t this_unicode =
-            m_pCID2UnicodeMap->UnicodeFromCID(static_cast<uint16_t>(CID));
+            m_pCID2UnicodeMap->UnicodeFromCID(static_cast<uint16_t>(cid));
         if (this_unicode == unicode)
-          return CID;
-        CID++;
+          return cid;
+        cid++;
       }
       break;
     }
@@ -481,8 +481,8 @@
     }
   }
   if (!m_pFontFile && m_Charset == CIDSET_JAPAN1) {
-    uint16_t CID = CIDFromCharCode(charcode);
-    const uint8_t* pTransform = GetCIDTransform(CID);
+    uint16_t cid = CIDFromCharCode(charcode);
+    const uint8_t* pTransform = GetCIDTransform(cid);
     if (pTransform && !bVert) {
       CFX_Matrix matrix(CIDTransformToFloat(pTransform[0]),
                         CIDTransformToFloat(pTransform[1]),
@@ -514,28 +514,28 @@
   return m_DefaultWidth;
 }
 
-short CPDF_CIDFont::GetVertWidth(uint16_t CID) const {
+int16_t CPDF_CIDFont::GetVertWidth(uint16_t cid) const {
   size_t vertsize = m_VertMetrics.size() / 5;
   if (vertsize) {
     const uint32_t* pTable = m_VertMetrics.data();
     for (size_t i = 0; i < vertsize; i++) {
       const uint32_t* pEntry = pTable + (i * 5);
-      if (IsMetricForCID(pEntry, CID))
-        return static_cast<short>(pEntry[2]);
+      if (IsMetricForCID(pEntry, cid))
+        return static_cast<int16_t>(pEntry[2]);
     }
   }
   return m_DefaultW1;
 }
 
-void CPDF_CIDFont::GetVertOrigin(uint16_t CID, short& vx, short& vy) const {
+void CPDF_CIDFont::GetVertOrigin(uint16_t cid, int16_t& vx, int16_t& vy) const {
   size_t vertsize = m_VertMetrics.size() / 5;
   if (vertsize) {
     const uint32_t* pTable = m_VertMetrics.data();
     for (size_t i = 0; i < vertsize; i++) {
       const uint32_t* pEntry = pTable + (i * 5);
-      if (IsMetricForCID(pEntry, CID)) {
-        vx = static_cast<short>(pEntry[3]);
-        vy = static_cast<short>(pEntry[4]);
+      if (IsMetricForCID(pEntry, cid)) {
+        vx = static_cast<int16_t>(pEntry[3]);
+        vy = static_cast<int16_t>(pEntry[4]);
         return;
       }
     }
@@ -545,12 +545,12 @@
   const uint32_t* pList = m_WidthList.data();
   for (size_t i = 0; i < size; i += 3) {
     const uint32_t* pEntry = pList + i;
-    if (IsMetricForCID(pEntry, CID)) {
+    if (IsMetricForCID(pEntry, cid)) {
       dwWidth = pEntry[2];
       break;
     }
   }
-  vx = static_cast<short>(dwWidth) / 2;
+  vx = static_cast<int16_t>(dwWidth) / 2;
   vy = m_DefaultVY;
 }
 
@@ -839,14 +839,14 @@
   m_bAnsiWidthsFixed = true;
 }
 
-const uint8_t* CPDF_CIDFont::GetCIDTransform(uint16_t CID) const {
+const uint8_t* CPDF_CIDFont::GetCIDTransform(uint16_t cid) const {
   if (m_Charset != CIDSET_JAPAN1 || m_pFontFile)
     return nullptr;
 
   const auto* pEnd = g_Japan1_VertCIDs + pdfium::size(g_Japan1_VertCIDs);
   const auto* pTransform = std::lower_bound(
-      g_Japan1_VertCIDs, pEnd, CID,
+      g_Japan1_VertCIDs, pEnd, cid,
       [](const CIDTransform& entry, uint16_t cid) { return entry.cid < cid; });
-  return (pTransform < pEnd && CID == pTransform->cid) ? &pTransform->a
+  return (pTransform < pEnd && cid == pTransform->cid) ? &pTransform->a
                                                        : nullptr;
 }
diff --git a/core/fpdfapi/font/cpdf_cidfont.h b/core/fpdfapi/font/cpdf_cidfont.h
index 8a98d2e..08afc3c 100644
--- a/core/fpdfapi/font/cpdf_cidfont.h
+++ b/core/fpdfapi/font/cpdf_cidfont.h
@@ -56,9 +56,9 @@
   uint32_t CharCodeFromUnicode(wchar_t Unicode) const override;
 
   uint16_t CIDFromCharCode(uint32_t charcode) const;
-  const uint8_t* GetCIDTransform(uint16_t CID) const;
-  short GetVertWidth(uint16_t CID) const;
-  void GetVertOrigin(uint16_t CID, short& vx, short& vy) const;
+  const uint8_t* GetCIDTransform(uint16_t cid) const;
+  int16_t GetVertWidth(uint16_t cid) const;
+  void GetVertOrigin(uint16_t cid, int16_t& vx, int16_t& vy) const;
   int GetCharSize(uint32_t charcode) const;
 
  private:
@@ -83,8 +83,8 @@
   bool m_bAdobeCourierStd = false;
   CIDSet m_Charset = CIDSET_UNKNOWN;
   uint16_t m_DefaultWidth = 1000;
-  short m_DefaultVY = 880;
-  short m_DefaultW1 = -1000;
+  int16_t m_DefaultVY = 880;
+  int16_t m_DefaultW1 = -1000;
   std::vector<uint32_t> m_WidthList;
   std::vector<uint32_t> m_VertMetrics;
   FX_RECT m_CharBBox[256];
diff --git a/core/fpdfapi/page/cpdf_textobject.cpp b/core/fpdfapi/page/cpdf_textobject.cpp
index dc302ed..d32f8b8 100644
--- a/core/fpdfapi/page/cpdf_textobject.cpp
+++ b/core/fpdfapi/page/cpdf_textobject.cpp
@@ -45,12 +45,12 @@
   if (!pFont->IsCIDFont() || !pFont->AsCIDFont()->IsVertWriting())
     return;
 
-  uint16_t CID = pFont->AsCIDFont()->CIDFromCharCode(pInfo->m_CharCode);
+  uint16_t cid = pFont->AsCIDFont()->CIDFromCharCode(pInfo->m_CharCode);
   pInfo->m_Origin = CFX_PointF(0, pInfo->m_Origin.x);
 
-  short vx;
-  short vy;
-  pFont->AsCIDFont()->GetVertOrigin(CID, vx, vy);
+  int16_t vx;
+  int16_t vy;
+  pFont->AsCIDFont()->GetVertOrigin(cid, vx, vy);
 
   float fontsize = GetFontSize();
   pInfo->m_Origin.x -= fontsize * vx / 1000;
@@ -228,8 +228,8 @@
   if (!bVertWriting)
     return pFont->GetCharWidthF(charcode) * fontsize;
 
-  uint16_t CID = pCIDFont->CIDFromCharCode(charcode);
-  return pCIDFont->GetVertWidth(CID) * fontsize;
+  uint16_t cid = pCIDFont->CIDFromCharCode(charcode);
+  return pCIDFont->GetVertWidth(cid) * fontsize;
 }
 
 RetainPtr<CPDF_Font> CPDF_TextObject::GetFont() const {
@@ -285,10 +285,10 @@
       max_x = std::max(max_x, std::max(char_left, char_right));
       charwidth = pFont->GetCharWidthF(charcode) * fontsize / 1000;
     } else {
-      uint16_t CID = pCIDFont->CIDFromCharCode(charcode);
-      short vx;
-      short vy;
-      pCIDFont->GetVertOrigin(CID, vx, vy);
+      uint16_t cid = pCIDFont->CIDFromCharCode(charcode);
+      int16_t vx;
+      int16_t vy;
+      pCIDFont->GetVertOrigin(cid, vx, vy);
       char_rect.left -= vx;
       char_rect.right -= vx;
       char_rect.top -= vy;
@@ -301,7 +301,7 @@
       float char_bottom = curpos + char_rect.bottom * fontsize / 1000;
       min_y = std::min(min_y, std::min(char_top, char_bottom));
       max_y = std::max(max_y, std::max(char_top, char_bottom));
-      charwidth = pCIDFont->GetVertWidth(CID) * fontsize / 1000;
+      charwidth = pCIDFont->GetVertWidth(cid) * fontsize / 1000;
     }
     curpos += charwidth;
     if (charcode == ' ' && (!pCIDFont || pCIDFont->GetCharSize(' ') == 1))
diff --git a/core/fpdfapi/render/charposlist.cpp b/core/fpdfapi/render/charposlist.cpp
index 8392ab2..25842ca 100644
--- a/core/fpdfapi/render/charposlist.cpp
+++ b/core/fpdfapi/render/charposlist.cpp
@@ -118,8 +118,8 @@
     if (is_vertical_writing) {
       text_char_pos.m_Origin = CFX_PointF(0, text_char_pos.m_Origin.x);
 
-      short vx;
-      short vy;
+      int16_t vx;
+      int16_t vy;
       cid_font->GetVertOrigin(cid, vx, vy);
       text_char_pos.m_Origin.x -= font_size * vx / 1000;
       text_char_pos.m_Origin.y -= font_size * vy / 1000;
diff --git a/fpdfsdk/fpdf_text.cpp b/fpdfsdk/fpdf_text.cpp
index 3ec62e3..ad44680 100644
--- a/fpdfsdk/fpdf_text.cpp
+++ b/fpdfsdk/fpdf_text.cpp
@@ -248,12 +248,12 @@
       CPDF_CIDFont* pCIDFont = charinfo.m_pTextObj->GetFont()->AsCIDFont();
       uint16_t cid = pCIDFont->CIDFromCharCode(charinfo.m_CharCode);
 
-      short vx;
-      short vy;
+      int16_t vx;
+      int16_t vy;
       pCIDFont->GetVertOrigin(cid, vx, vy);
       double offsetx = (vx - 500) * font_size / 1000.0;
       double offsety = vy * font_size / 1000.0;
-      short vert_width = pCIDFont->GetVertWidth(cid);
+      int16_t vert_width = pCIDFont->GetVertWidth(cid);
       double height = vert_width * font_size / 1000.0;
 
       rect->left = charinfo.m_Origin.x + offsetx;