Fix an assertion failure in CXFA_DefFontMgr::GetDefaultFont()

BUG=pdfium:385
TBR=tsepez@chromium.org

Review URL: https://codereview.chromium.org/1668813002 .

Review URL: https://codereview.chromium.org/1669193002 .
diff --git a/xfa/src/fxfa/src/app/xfa_ffdocview.cpp b/xfa/src/fxfa/src/app/xfa_ffdocview.cpp
index 345b142..9d8e049 100644
--- a/xfa/src/fxfa/src/app/xfa_ffdocview.cpp
+++ b/xfa/src/fxfa/src/app/xfa_ffdocview.cpp
@@ -180,7 +180,6 @@
   this->RunCalculateWidgets();
   this->RunValidate();
   ShowNullTestMsg();
-  m_iStatus = XFA_DOCVIEW_LAYOUTSTATUS_Next;
   if (RunLayout() && m_bLayoutEvent) {
     RunEventLayoutReady();
   }
@@ -396,7 +395,7 @@
       pWidgetAcc ? pWidgetAcc->GetNextWidget(NULL) : NULL;
   if (SetFocus(pNewFocus)) {
     m_pFocusAcc = pWidgetAcc;
-    if (m_iStatus >= XFA_DOCVIEW_LAYOUTSTATUS_End) {
+    if (m_iStatus == XFA_DOCVIEW_LAYOUTSTATUS_End) {
       m_pDoc->GetDocProvider()->SetFocusWidget(m_pDoc, m_pFocusWidget);
     }
   }
@@ -535,20 +534,15 @@
 void CXFA_FFDocView::OnPageEvent(IXFA_LayoutPage* pSender,
                                  XFA_PAGEEVENT eEvent,
                                  int32_t iPageIndex) {
-  FX_BOOL bNofify = m_iStatus >= XFA_DOCVIEW_LAYOUTSTATUS_End;
   CXFA_FFPageView* pFFPageView = static_cast<CXFA_FFPageView*>(pSender);
   if (eEvent == XFA_PAGEEVENT_PageRemoved) {
-    if (bNofify) {
       m_pDoc->GetDocProvider()->PageViewEvent(pFFPageView,
                                               XFA_PAGEVIEWEVENT_PostRemoved);
-    }
-  } else if (eEvent == XFA_PAGEEVENT_PageAdded) {
-    if (bNofify) {
-      m_pDoc->GetDocProvider()->PageViewEvent(pFFPageView,
-                                              XFA_PAGEVIEWEVENT_PostAdded);
-      pFFPageView->LoadPageView();
-    }
+      return;
   }
+  m_pDoc->GetDocProvider()->PageViewEvent(pFFPageView,
+                                          XFA_PAGEVIEWEVENT_PostAdded);
+  pFFPageView->LoadPageView();
 }
 void CXFA_FFDocView::LockUpdate() {
   m_iLock++;
diff --git a/xfa/src/fxfa/src/app/xfa_ffdocview.h b/xfa/src/fxfa/src/app/xfa_ffdocview.h
index a8d39b5..df70925 100644
--- a/xfa/src/fxfa/src/app/xfa_ffdocview.h
+++ b/xfa/src/fxfa/src/app/xfa_ffdocview.h
@@ -28,8 +28,7 @@
   XFA_DOCVIEW_LAYOUTSTATUS_PagesetFormReady,
   XFA_DOCVIEW_LAYOUTSTATUS_LayoutReady,
   XFA_DOCVIEW_LAYOUTSTATUS_DocReady,
-  XFA_DOCVIEW_LAYOUTSTATUS_End,
-  XFA_DOCVIEW_LAYOUTSTATUS_Next,
+  XFA_DOCVIEW_LAYOUTSTATUS_End
 };
 class CXFA_FFDocView : public IXFA_DocView {
  public:
diff --git a/xfa/src/fxfa/src/app/xfa_ffnotify.cpp b/xfa/src/fxfa/src/app/xfa_ffnotify.cpp
index 9dd93f3..ebd9d06 100644
--- a/xfa/src/fxfa/src/app/xfa_ffnotify.cpp
+++ b/xfa/src/fxfa/src/app/xfa_ffnotify.cpp
@@ -551,7 +551,7 @@
   }
   FX_BOOL bLayoutReady =
       !(pDocView->m_bInLayoutStatus) &&
-      (pDocView->GetLayoutStatus() >= XFA_DOCVIEW_LAYOUTSTATUS_End);
+      (pDocView->GetLayoutStatus() == XFA_DOCVIEW_LAYOUTSTATUS_End);
   if (bLayoutReady) {
     m_pDoc->GetDocProvider()->SetChangeMark(m_pDoc);
   }
@@ -562,7 +562,7 @@
   if (CXFA_FFDocView* pDocView = m_pDoc->GetDocView()) {
     FX_BOOL bLayoutReady =
         !(pDocView->m_bInLayoutStatus) &&
-        (pDocView->GetLayoutStatus() >= XFA_DOCVIEW_LAYOUTSTATUS_End);
+        (pDocView->GetLayoutStatus() == XFA_DOCVIEW_LAYOUTSTATUS_End);
     if (bLayoutReady) {
       m_pDoc->GetDocProvider()->SetChangeMark(m_pDoc);
     }
@@ -580,33 +580,28 @@
   FX_DWORD dwFilter = XFA_WIDGETSTATUS_Visible | XFA_WIDGETSTATUS_Viewable |
                       XFA_WIDGETSTATUS_Printable;
   pWidget->ModifyStatus(dwStatus, dwFilter);
-  if (pDocView->GetLayoutStatus() >= XFA_DOCVIEW_LAYOUTSTATUS_End) {
-    IXFA_PageView* pPrePageView = pWidget->GetPageView();
-    if (pPrePageView != pNewPageView ||
-        (dwStatus & (XFA_WIDGETSTATUS_Visible | XFA_WIDGETSTATUS_Viewable)) ==
-            (XFA_WIDGETSTATUS_Visible | XFA_WIDGETSTATUS_Viewable)) {
-      pWidget->SetPageView(pNewPageView);
-      m_pDoc->GetDocProvider()->WidgetEvent(pWidget, pWidget->GetDataAcc(),
-                                            XFA_WIDGETEVENT_PostAdded,
-                                            pNewPageView, pPrePageView);
-    }
-    if ((dwStatus & XFA_WIDGETSTATUS_Visible) == 0) {
-      return;
-    }
-    if (pWidget->IsLoaded()) {
-      CFX_RectF rtOld;
-      pWidget->GetWidgetRect(rtOld);
-      CFX_RectF rtNew = pWidget->ReCacheWidgetRect();
-      if (rtOld != rtNew) {
-        pWidget->PerformLayout();
-      }
-    } else {
-      pWidget->LoadWidget();
-    }
-    pWidget->AddInvalidateRect(NULL);
-  } else {
+  IXFA_PageView* pPrePageView = pWidget->GetPageView();
+  if (pPrePageView != pNewPageView ||
+      (dwStatus & (XFA_WIDGETSTATUS_Visible | XFA_WIDGETSTATUS_Viewable)) ==
+          (XFA_WIDGETSTATUS_Visible | XFA_WIDGETSTATUS_Viewable)) {
     pWidget->SetPageView(pNewPageView);
+    m_pDoc->GetDocProvider()->WidgetEvent(pWidget, pWidget->GetDataAcc(),
+                                          XFA_WIDGETEVENT_PostAdded,
+                                          pNewPageView, pPrePageView);
   }
+  if (pDocView->GetLayoutStatus() != XFA_DOCVIEW_LAYOUTSTATUS_End ||
+      !(dwStatus & XFA_WIDGETSTATUS_Visible)) {
+    return;
+  }
+  if (pWidget->IsLoaded()) {
+    CFX_RectF rtOld;
+    pWidget->GetWidgetRect(rtOld);
+    if (rtOld != pWidget->ReCacheWidgetRect())
+      pWidget->PerformLayout();
+  } else {
+    pWidget->LoadWidget();
+  }
+  pWidget->AddInvalidateRect(nullptr);
 }
 void CXFA_FFNotify::OnLayoutItemRemoving(CXFA_FFDocView* pDocView,
                                          IXFA_DocLayout* pLayout,
@@ -615,8 +610,6 @@
                                          void* pParam2) {
   CXFA_FFWidget* pWidget = static_cast<CXFA_FFWidget*>(pSender);
   pDocView->DeleteLayoutItem(pWidget);
-  if (pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End)
-    return;
   m_pDoc->GetDocProvider()->WidgetEvent(pWidget, pWidget->GetDataAcc(),
                                         XFA_WIDGETEVENT_PreRemoved, nullptr,
                                         pWidget->GetPageView());