Use a struct for |CXFA_TextLayout::m_Blocks|.

Instead of interpreting even/odd members of the vector as different
types.

Change-Id: I6407582490a05341174b0591b3729e3844b79934
Reviewed-on: https://pdfium-review.googlesource.com/c/49494
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp
index bb7b99e..d181683 100644
--- a/xfa/fxfa/cxfa_textlayout.cpp
+++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -345,11 +345,11 @@
   int32_t iBlockCount = pdfium::CollectionSize<int32_t>(m_Blocks);
   float fLinePos = m_pLoader->fStartLineOffset;
   int32_t iLineIndex = 0;
-  if (iBlockCount > 1) {
-    if (iBlockCount >= (iBlockIndex + 1) * 2) {
+  if (iBlockCount > 0) {
+    if (iBlockCount >= iBlockIndex + 1) {
       iLineIndex = GetBlockIndex(iBlockIndex);
     } else {
-      int32_t iLast = iBlockCount / 2 - 1;
+      int32_t iLast = iBlockCount - 1;
       iLineIndex = GetBlockIndex(iLast) + GetBlockLength(iLast);
     }
     if (!m_pLoader->blockHeights.empty()) {
@@ -374,12 +374,11 @@
       continue;
     }
 
-    if (iBlockCount >= (iBlockIndex + 1) * 2) {
+    if (iBlockCount >= iBlockIndex + 1) {
       GetBlockIndex(iBlockIndex) = iLineIndex;
       GetBlockLength(iBlockIndex) = i - iLineIndex;
     } else {
-      m_Blocks.push_back(iLineIndex);
-      m_Blocks.push_back(i - iLineIndex);
+      m_Blocks.push_back({iLineIndex, i - iLineIndex});
     }
 
     if (i != iLineIndex)
@@ -401,7 +400,7 @@
 }
 
 int32_t CXFA_TextLayout::CountBlocks() const {
-  int32_t iCount = pdfium::CollectionSize<int32_t>(m_Blocks) / 2;
+  int32_t iCount = pdfium::CollectionSize<int32_t>(m_Blocks);
   return iCount > 0 ? iCount : 1;
 }
 
@@ -466,14 +465,14 @@
       fLinePos -= m_pLoader->blockHeights[i].fHeight;
 
     m_pLoader->iChar = 0;
-    if (iCount > 1)
+    if (iCount > 0)
       m_pLoader->iTotalLines = GetBlockLength(iBlock);
 
     Loader(szText.width, &fLinePos, true);
     if (iCount == 0 && m_pLoader->fStartLineOffset < 0.1f)
       UpdateAlign(szText.height, fLinePos);
   } else if (m_pTextDataNode) {
-    if (iBlock * 2 < iCount - 2)
+    if (iBlock < iCount - 1)
       m_pLoader->iTotalLines = GetBlockLength(iBlock);
 
     m_pBreak->Reset();
@@ -522,7 +521,7 @@
       LoadText(pNode, szText.width, &fLinePos, true);
     }
   }
-  if (iBlock * 2 == iCount) {
+  if (iBlock == iCount) {
     m_pTabstopContext.reset();
     m_pLoader.reset();
   }
@@ -539,7 +538,6 @@
     return;
 
   bool bEndItem = true;
-  int32_t iBlockCount = pdfium::CollectionSize<int32_t>(m_Blocks);
   float fLinePos = m_pLoader->fStartLineOffset;
   int32_t iLineIndex = 0;
   if (iBlockIndex > 0) {
@@ -551,7 +549,7 @@
     } else {
       fLinePos = 0;
     }
-    int32_t iLast = iBlockCount / 2 - 1;
+    int32_t iLast = pdfium::CollectionSize<int32_t>(m_Blocks) - 1;
     iLineIndex = GetBlockIndex(iLast) + GetBlockLength(iLast);
   }
 
@@ -559,17 +557,14 @@
   for (i = iLineIndex; i < iCountHeight; i++) {
     float fLineHeight = m_pLoader->lineHeights[i];
     if (fLinePos + fLineHeight - rtText.height > kHeightTolerance) {
-      m_Blocks.push_back(iLineIndex);
-      m_Blocks.push_back(i - iLineIndex);
+      m_Blocks.push_back({iLineIndex, i - iLineIndex});
       bEndItem = false;
       break;
     }
     fLinePos += fLineHeight;
   }
-  if (iCountHeight > 0 && (i - iLineIndex) > 0 && bEndItem) {
-    m_Blocks.push_back(iLineIndex);
-    m_Blocks.push_back(i - iLineIndex);
-  }
+  if (iCountHeight > 0 && (i - iLineIndex) > 0 && bEndItem)
+    m_Blocks.push_back({iLineIndex, i - iLineIndex});
 }
 
 bool CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice,
@@ -592,9 +587,8 @@
   int32_t iCharCount = 1;
   int32_t iLineStart = 0;
   int32_t iPieceLines = pdfium::CollectionSize<int32_t>(m_pieceLines);
-  int32_t iCount = pdfium::CollectionSize<int32_t>(m_Blocks);
-  if (iCount > 0) {
-    if (iBlock * 2 < iCount) {
+  if (!m_Blocks.empty()) {
+    if (iBlock < pdfium::CollectionSize<int32_t>(m_Blocks)) {
       iLineStart = GetBlockIndex(iBlock);
       iPieceLines = GetBlockLength(iBlock);
     } else {
diff --git a/xfa/fxfa/cxfa_textlayout.h b/xfa/fxfa/cxfa_textlayout.h
index 64c4c89..fd60005 100644
--- a/xfa/fxfa/cxfa_textlayout.h
+++ b/xfa/fxfa/cxfa_textlayout.h
@@ -62,6 +62,11 @@
   void ResetHasBlock() { m_bHasBlock = false; }
 
  private:
+  struct BlockData {
+    int32_t iIndex;
+    int32_t iLength;
+  };
+
   void GetTextDataNode();
   CFX_XMLNode* GetXMLContainerNode();
   std::unique_ptr<CFX_RTFBreak> CreateBreak(bool bDefault);
@@ -111,15 +116,15 @@
   void DoTabstops(CFX_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine);
   bool Layout(int32_t iBlock);
   int32_t CountBlocks() const;
-  int32_t& GetBlockIndex(int32_t index) { return m_Blocks[index * 2]; }
-  int32_t& GetBlockLength(int32_t index) { return m_Blocks[index * 2 + 1]; }
+  int32_t& GetBlockIndex(int32_t index) { return m_Blocks[index].iIndex; }
+  int32_t& GetBlockLength(int32_t index) { return m_Blocks[index].iLength; }
 
   bool m_bHasBlock = false;
   bool m_bRichText = false;
   bool m_bBlockContinue = true;
   int32_t m_iLines = 0;
   float m_fMaxWidth = 0;
-  std::vector<int32_t> m_Blocks;
+  std::vector<BlockData> m_Blocks;
   UnownedPtr<CXFA_FFDoc> const m_pDoc;
   CXFA_TextProvider* const m_pTextProvider;  // Raw, owned by tree node.
   CXFA_Node* m_pTextDataNode = nullptr;      // Raw, owned by tree node.