Fix nits in CFX_TxtBreak and related code.

Use size_t where appropriate, fix lint errors, and remove dead code.

Change-Id: I2c79125b64ed0d1ea362194d2b31182a5c1289d6
Reviewed-on: https://pdfium-review.googlesource.com/c/47153
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fde/cfde_texteditengine.h b/xfa/fde/cfde_texteditengine.h
index 868be88..5971611 100644
--- a/xfa/fde/cfde_texteditengine.h
+++ b/xfa/fde/cfde_texteditengine.h
@@ -171,8 +171,6 @@
   std::vector<CFX_RectF> GetCharacterRectsInRange(int32_t start_idx,
                                                   int32_t count);
 
-  CFX_TxtBreak* GetTextBreak() { return &text_break_; }
-
   const std::vector<FDE_TEXTEDITPIECE>& GetTextPieces() {
     // Force a layout if needed.
     Layout();
diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp
index 46527f5..4f0e35b 100644
--- a/xfa/fde/cfde_textout.cpp
+++ b/xfa/fde/cfde_textout.cpp
@@ -37,17 +37,17 @@
                               FX_ARGB color,
                               const RetainPtr<CFGAS_GEFont>& pFont,
                               FXTEXT_CHARPOS* pCharPos,
-                              int32_t iCount,
+                              size_t szCount,
                               float fFontSize,
                               const CFX_Matrix* pMatrix) {
   ASSERT(pFont);
   ASSERT(pCharPos);
-  ASSERT(iCount > 0);
+  ASSERT(szCount > 0);
 
   CFX_Font* pFxFont = pFont->GetDevFont();
   if (FontStyleIsItalic(pFont->GetFontStyles()) && !pFxFont->IsItalic()) {
     FXTEXT_CHARPOS* pCharPosIter = pCharPos;
-    for (int32_t i = 0; i < iCount; ++i) {
+    for (size_t i = 0; i < szCount; ++i) {
       static const float mc = 0.267949f;
       float* pAM = pCharPosIter->m_AdjustMatrix;
       pAM[2] = mc * pAM[0] + pAM[2];
@@ -71,7 +71,7 @@
   FXTEXT_CHARPOS* pCurCP = nullptr;
   int32_t iCurCount = 0;
   FXTEXT_CHARPOS* pCharPosIter = pCharPos;
-  for (int32_t i = 0; i < iCount; ++i) {
+  for (size_t i = 0; i < szCount; ++i) {
     RetainPtr<CFGAS_GEFont> pSTFont =
         pFont->GetSubstFont(static_cast<int32_t>(pCharPosIter->m_GlyphIndex));
     pCharPosIter->m_GlyphIndex &= 0x00FFFFFF;
@@ -318,10 +318,10 @@
       if (!pPiece)
         continue;
 
-      int32_t iCount = GetDisplayPos(pPiece);
-      if (iCount > 0) {
+      size_t szCount = GetDisplayPos(pPiece);
+      if (szCount > 0) {
         CFDE_TextOut::DrawString(device, m_TxtColor, m_pFont, m_CharPos.data(),
-                                 iCount, m_fFontSize, &m_Matrix);
+                                 szCount, m_fFontSize, &m_Matrix);
       }
     }
   }
@@ -518,7 +518,7 @@
   }
 }
 
-int32_t CFDE_TextOut::GetDisplayPos(FDE_TTOPIECE* pPiece) {
+size_t CFDE_TextOut::GetDisplayPos(FDE_TTOPIECE* pPiece) {
   ASSERT(pPiece->iChars >= 0);
 
   if (pdfium::CollectionSize<int32_t>(m_CharPos) < pPiece->iChars)
diff --git a/xfa/fde/cfde_textout.h b/xfa/fde/cfde_textout.h
index 153f3f5..2a3942d 100644
--- a/xfa/fde/cfde_textout.h
+++ b/xfa/fde/cfde_textout.h
@@ -38,7 +38,7 @@
                          FX_ARGB color,
                          const RetainPtr<CFGAS_GEFont>& pFont,
                          FXTEXT_CHARPOS* pCharPos,
-                         int32_t iCount,
+                         size_t szCount,
                          float fFontSize,
                          const CFX_Matrix* pMatrix);
 
@@ -95,7 +95,7 @@
                       int32_t* pPieceWidths);
   void AppendPiece(const FDE_TTOPIECE& ttoPiece, bool bNeedReload, bool bEnd);
   void DoAlignment(const CFX_RectF& rect);
-  int32_t GetDisplayPos(FDE_TTOPIECE* pPiece);
+  size_t GetDisplayPos(FDE_TTOPIECE* pPiece);
 
   std::unique_ptr<CFX_TxtBreak> m_pTxtBreak;
   RetainPtr<CFGAS_GEFont> m_pFont;
diff --git a/xfa/fgas/layout/cfx_txtbreak.cpp b/xfa/fgas/layout/cfx_txtbreak.cpp
index ca422d2..d861058 100644
--- a/xfa/fgas/layout/cfx_txtbreak.cpp
+++ b/xfa/fgas/layout/cfx_txtbreak.cpp
@@ -301,7 +301,7 @@
   CFX_BreakPiece tp;
   if (bAllChars && !bDone) {
     int32_t iEndPos = m_pCurLine->m_iWidth;
-    GetBreakPos(m_pCurLine->m_LineChars, bAllChars, true, &iEndPos);
+    GetBreakPos(&m_pCurLine->m_LineChars, bAllChars, true, &iEndPos);
   }
   return false;
 }
@@ -522,11 +522,12 @@
   return dwStatus;
 }
 
-int32_t CFX_TxtBreak::GetBreakPos(std::vector<CFX_Char>& ca,
+int32_t CFX_TxtBreak::GetBreakPos(std::vector<CFX_Char>* pChars,
                                   bool bAllChars,
                                   bool bOnlyBrk,
                                   int32_t* pEndPos) {
-  int32_t iLength = pdfium::CollectionSize<int32_t>(ca) - 1;
+  std::vector<CFX_Char>& chars = *pChars;
+  int32_t iLength = pdfium::CollectionSize<int32_t>(chars) - 1;
   if (iLength < 1)
     return iLength;
 
@@ -548,7 +549,7 @@
   uint32_t nCodeProp;
   uint32_t nCur;
   uint32_t nNext;
-  CFX_Char* pCur = &ca[iLength--];
+  CFX_Char* pCur = &chars[iLength--];
   if (bAllChars)
     pCur->m_nBreakType = FX_LBT_UNKNOWN;
 
@@ -559,7 +560,7 @@
     *pEndPos -= iCharWidth;
 
   while (iLength >= 0) {
-    pCur = &ca[iLength];
+    pCur = &chars[iLength];
     nCodeProp = pCur->char_props();
     nCur = nCodeProp & 0x003F;
     if (nNext == kBreakPropertySpace)
@@ -620,7 +621,7 @@
 
   int32_t iEndPos = pCurLine->m_iWidth;
   std::vector<CFX_Char>& curChars = pCurLine->m_LineChars;
-  int32_t iCharPos = GetBreakPos(curChars, bAllChars, false, &iEndPos);
+  int32_t iCharPos = GetBreakPos(&curChars, bAllChars, false, &iEndPos);
   if (iCharPos < 0)
     iCharPos = 0;
 
@@ -656,8 +657,8 @@
   int32_t iWidth;
 };
 
-int32_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
-                                    FXTEXT_CHARPOS* pCharPos) const {
+size_t CFX_TxtBreak::GetDisplayPos(const FX_TXTRUN* pTxtRun,
+                                   FXTEXT_CHARPOS* pCharPos) const {
   if (!pTxtRun || pTxtRun->iLength < 1)
     return 0;
 
@@ -675,7 +676,7 @@
   int32_t iDescent = pFont->GetDescent();
   int32_t iMaxHeight = iAscent - iDescent;
   float fFontHeight = fFontSize;
-  float fAscent = fFontHeight * (float)iAscent / (float)iMaxHeight;
+  float fAscent = fFontHeight * iAscent / iMaxHeight;
   float fX = rtText.left;
   float fY;
   float fCharWidth;
@@ -691,7 +692,7 @@
   fYBase = rtText.top + (rtText.height - fFontSize) / 2.0f;
   fY = fYBase + fAscent;
 
-  int32_t iCount = 0;
+  size_t szCount = 0;
   int32_t iNext = 0;
   wchar_t wPrev = 0xFEFF;
   wchar_t wNext = 0xFEFF;
@@ -808,7 +809,7 @@
       bEmptyChar = true;
 
     int32_t iForms = bLam ? 3 : 1;
-    iCount += (bEmptyChar && bSkipSpace) ? 0 : iForms;
+    szCount += (bEmptyChar && bSkipSpace) ? 0 : iForms;
     if (!pCharPos) {
       if (iWidth > 0)
         wPrev = wch;
@@ -911,7 +912,7 @@
       wPrev = static_cast<wchar_t>(formChars[0].wch);
     wLast = wch;
   }
-  return iCount;
+  return szCount;
 }
 
 std::vector<CFX_RectF> CFX_TxtBreak::GetCharRects(const FX_TXTRUN* pTxtRun,
diff --git a/xfa/fgas/layout/cfx_txtbreak.h b/xfa/fgas/layout/cfx_txtbreak.h
index be9ddb7..9b095cc 100644
--- a/xfa/fgas/layout/cfx_txtbreak.h
+++ b/xfa/fgas/layout/cfx_txtbreak.h
@@ -63,8 +63,8 @@
   void SetCombWidth(float fCombWidth);
   CFX_BreakType EndBreak(CFX_BreakType dwStatus);
 
-  int32_t GetDisplayPos(const FX_TXTRUN* pTxtRun,
-                        FXTEXT_CHARPOS* pCharPos) const;
+  size_t GetDisplayPos(const FX_TXTRUN* pTxtRun,
+                       FXTEXT_CHARPOS* pCharPos) const;
   std::vector<CFX_RectF> GetCharRects(const FX_TXTRUN* pTxtRun,
                                       bool bCharBBox) const;
   CFX_BreakType AppendChar(wchar_t wch);
@@ -82,7 +82,7 @@
   void EndBreak_Alignment(const std::deque<FX_TPO>& tpos,
                           bool bAllChars,
                           CFX_BreakType dwStatus);
-  int32_t GetBreakPos(std::vector<CFX_Char>& ca,
+  int32_t GetBreakPos(std::vector<CFX_Char>* pChars,
                       bool bAllChars,
                       bool bOnlyBrk,
                       int32_t* pEndPos);
diff --git a/xfa/fxfa/cxfa_pieceline.h b/xfa/fxfa/cxfa_pieceline.h
index dc95e73..0e233ac 100644
--- a/xfa/fxfa/cxfa_pieceline.h
+++ b/xfa/fxfa/cxfa_pieceline.h
@@ -18,7 +18,7 @@
   ~CXFA_PieceLine();
 
   std::vector<std::unique_ptr<CXFA_TextPiece>> m_textPieces;
-  std::vector<int32_t> m_charCounts;
+  std::vector<size_t> m_charCounts;
 };
 
 #endif  // XFA_FXFA_CXFA_PIECELINE_H_
diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp
index efc2c0b..f083e24 100644
--- a/xfa/fxfa/cxfa_textlayout.cpp
+++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -1134,12 +1134,12 @@
                                    FXTEXT_CHARPOS* pCharPos,
                                    const CFX_Matrix& tmDoc2Device) {
   const CXFA_TextPiece* pPiece = pPieceLine->m_textPieces[iPiece].get();
-  int32_t iCount = GetDisplayPos(pPiece, pCharPos);
-  if (iCount > 0) {
+  size_t szCount = GetDisplayPos(pPiece, pCharPos);
+  if (szCount > 0) {
     CFDE_TextOut::DrawString(pDevice, pPiece->dwColor, pPiece->pFont, pCharPos,
-                             iCount, pPiece->fFontSize, &tmDoc2Device);
+                             szCount, pPiece->fFontSize, &tmDoc2Device);
   }
-  pPieceLine->m_charCounts.push_back(iCount);
+  pPieceLine->m_charCounts.push_back(szCount);
 }
 
 void CXFA_TextLayout::RenderPath(CFX_RenderDevice* pDevice,
@@ -1154,13 +1154,14 @@
     return;
 
   CFX_PathData path;
-  int32_t iChars = GetDisplayPos(pPiece, pCharPos);
-  if (iChars > 0) {
-    CFX_PointF pt1, pt2;
+  size_t szChars = GetDisplayPos(pPiece, pCharPos);
+  if (szChars > 0) {
+    CFX_PointF pt1;
+    CFX_PointF pt2;
     float fEndY = pCharPos[0].m_Origin.y + 1.05f;
     if (pPiece->iPeriod == XFA_AttributeValue::Word) {
       for (int32_t i = 0; i < pPiece->iUnderline; i++) {
-        for (int32_t j = 0; j < iChars; j++) {
+        for (size_t j = 0; j < szChars; j++) {
           pt1.x = pCharPos[j].m_Origin.x;
           pt2.x =
               pt1.x + pCharPos[j].m_FontCharWidth * pPiece->fFontSize / 1000.0f;
@@ -1172,8 +1173,8 @@
     } else {
       pt1.x = pCharPos[0].m_Origin.x;
       pt2.x =
-          pCharPos[iChars - 1].m_Origin.x +
-          pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f;
+          pCharPos[szChars - 1].m_Origin.x +
+          pCharPos[szChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f;
       for (int32_t i = 0; i < pPiece->iUnderline; i++) {
         pt1.y = pt2.y = fEndY;
         path.AppendLine(pt1, pt2);
@@ -1182,8 +1183,8 @@
     }
     fEndY = pCharPos[0].m_Origin.y - pPiece->rtPiece.height * 0.25f;
     pt1.x = pCharPos[0].m_Origin.x;
-    pt2.x = pCharPos[iChars - 1].m_Origin.x +
-            pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f;
+    pt2.x = pCharPos[szChars - 1].m_Origin.x +
+            pCharPos[szChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f;
     for (int32_t i = 0; i < pPiece->iLineThrough; i++) {
       pt1.y = pt2.y = fEndY;
       path.AppendLine(pt1, pt2);
@@ -1194,41 +1195,43 @@
         (bNoUnderline || pPiece->iPeriod != XFA_AttributeValue::All)) {
       return;
     }
-    int32_t iCharsTmp = 0;
+    bool bHasCount = false;
     int32_t iPiecePrev = iPiece;
     int32_t iPieceNext = iPiece;
     while (iPiecePrev > 0) {
       iPiecePrev--;
-      iCharsTmp = pPieceLine->m_charCounts[iPiecePrev];
-      if (iCharsTmp > 0)
+      if (pPieceLine->m_charCounts[iPiecePrev] > 0) {
+        bHasCount = true;
         break;
+      }
     }
-    if (iCharsTmp == 0)
+    if (!bHasCount)
       return;
 
-    iCharsTmp = 0;
+    bHasCount = false;
     int32_t iPieces = pdfium::CollectionSize<int32_t>(pPieceLine->m_textPieces);
     while (iPieceNext < iPieces - 1) {
       iPieceNext++;
-      iCharsTmp = pPieceLine->m_charCounts[iPieceNext];
-      if (iCharsTmp > 0)
+      if (pPieceLine->m_charCounts[iPieceNext] > 0) {
+        bHasCount = true;
         break;
+      }
     }
-    if (iCharsTmp == 0)
+    if (!bHasCount)
       return;
 
     float fOrgX = 0.0f;
     float fEndX = 0.0f;
     pPiece = pPieceLine->m_textPieces[iPiecePrev].get();
-    iChars = GetDisplayPos(pPiece, pCharPos);
-    if (iChars < 1)
+    szChars = GetDisplayPos(pPiece, pCharPos);
+    if (szChars < 1)
       return;
 
-    fOrgX = pCharPos[iChars - 1].m_Origin.x +
-            pCharPos[iChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f;
+    fOrgX = pCharPos[szChars - 1].m_Origin.x +
+            pCharPos[szChars - 1].m_FontCharWidth * pPiece->fFontSize / 1000.0f;
     pPiece = pPieceLine->m_textPieces[iPieceNext].get();
-    iChars = GetDisplayPos(pPiece, pCharPos);
-    if (iChars < 1)
+    szChars = GetDisplayPos(pPiece, pCharPos);
+    if (szChars < 1)
       return;
 
     fEndX = pCharPos[0].m_Origin.x;
@@ -1261,8 +1264,8 @@
   pDevice->DrawPath(&path, &tmDoc2Device, &graphState, 0, pPiece->dwColor, 0);
 }
 
-int32_t CXFA_TextLayout::GetDisplayPos(const CXFA_TextPiece* pPiece,
-                                       FXTEXT_CHARPOS* pCharPos) {
+size_t CXFA_TextLayout::GetDisplayPos(const CXFA_TextPiece* pPiece,
+                                      FXTEXT_CHARPOS* pCharPos) {
   if (!pPiece)
     return 0;
 
diff --git a/xfa/fxfa/cxfa_textlayout.h b/xfa/fxfa/cxfa_textlayout.h
index 97e1d65..b222450 100644
--- a/xfa/fxfa/cxfa_textlayout.h
+++ b/xfa/fxfa/cxfa_textlayout.h
@@ -104,7 +104,7 @@
                   int32_t iPiece,
                   FXTEXT_CHARPOS* pCharPos,
                   const CFX_Matrix& tmDoc2Device);
-  int32_t GetDisplayPos(const CXFA_TextPiece* pPiece, FXTEXT_CHARPOS* pCharPos);
+  size_t GetDisplayPos(const CXFA_TextPiece* pPiece, FXTEXT_CHARPOS* pCharPos);
   bool ToRun(const CXFA_TextPiece* pPiece, FX_RTFTEXTOBJ* tr);
   void DoTabstops(CFX_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine);
   bool Layout(int32_t iBlock);