Clean up parts of CXFA_TextLayout::DoLayout().

- Assert |iBlockIndex| is not negative.
- Avoid using the same |fHeight| variable for two different things.
- Declare |iBlockCount| later.

Change-Id: I86d00d53f6e349138e4ea55923ad0c342ec71be1
Reviewed-on: https://pdfium-review.googlesource.com/c/49491
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 1b0d9c7..ca4eda4 100644
--- a/xfa/fxfa/cxfa_textlayout.cpp
+++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -317,21 +317,21 @@
                                 float fCalcHeight,
                                 float fContentAreaHeight,
                                 float fTextHeight) {
+  ASSERT(iBlockIndex >= 0);
+
   if (!m_pLoader)
     return fCalcHeight;
 
-  int32_t iBlockCount = pdfium::CollectionSize<int32_t>(m_Blocks);
-  float fHeight = fTextHeight;
-  if (fHeight < 0)
-    fHeight = GetLayoutHeight();
+  m_pLoader->fHeight = fTextHeight;
+  if (m_pLoader->fHeight < 0)
+    m_pLoader->fHeight = GetLayoutHeight();
 
-  m_pLoader->fHeight = fHeight;
   if (fContentAreaHeight < 0)
     return fCalcHeight;
 
   m_bHasBlock = true;
-  if (iBlockCount == 0 && fHeight > 0) {
-    fHeight = fTextHeight - GetLayoutHeight();
+  if (m_Blocks.empty() && m_pLoader->fHeight > 0) {
+    float fHeight = fTextHeight - GetLayoutHeight();
     if (fHeight > 0) {
       XFA_AttributeValue iAlign = m_textParser.GetVAlign(m_pTextProvider);
       if (iAlign == XFA_AttributeValue::Middle)
@@ -342,6 +342,7 @@
     }
   }
 
+  int32_t iBlockCount = pdfium::CollectionSize<int32_t>(m_Blocks);
   float fLinePos = m_pLoader->fStartLineOffset;
   int32_t iLineIndex = 0;
   if (iBlockCount > 1) {