Add CFX_CSSComputedStyle::GetLastFontFamily().

Combine CFX_CSSComputedStyle::CountFontFamilies() and GetFontFamily()
into what the sole caller needs.

Change-Id: Ib301e8e4bb832f8e8aeff582fbbbf0c4a06316e3
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/70871
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/css/cfx_csscomputedstyle.cpp b/core/fxcrt/css/cfx_csscomputedstyle.cpp
index f369b68..dcd7cc1 100644
--- a/core/fxcrt/css/cfx_csscomputedstyle.cpp
+++ b/core/fxcrt/css/cfx_csscomputedstyle.cpp
@@ -25,14 +25,14 @@
   return false;
 }
 
-size_t CFX_CSSComputedStyle::CountFontFamilies() const {
-  return m_InheritedData.m_pFontFamily
-             ? m_InheritedData.m_pFontFamily->values().size()
-             : 0;
-}
+Optional<WideString> CFX_CSSComputedStyle::GetLastFontFamily() const {
+  if (!m_InheritedData.m_pFontFamily ||
+      m_InheritedData.m_pFontFamily->values().empty()) {
+    return pdfium::nullopt;
+  }
 
-const WideString CFX_CSSComputedStyle::GetFontFamily(size_t index) const {
-  return m_InheritedData.m_pFontFamily->values()[index]
+  return m_InheritedData.m_pFontFamily->values()
+      .back()
       .As<CFX_CSSStringValue>()
       ->Value();
 }
diff --git a/core/fxcrt/css/cfx_csscomputedstyle.h b/core/fxcrt/css/cfx_csscomputedstyle.h
index 70848f3..41fcd67 100644
--- a/core/fxcrt/css/cfx_csscomputedstyle.h
+++ b/core/fxcrt/css/cfx_csscomputedstyle.h
@@ -13,6 +13,7 @@
 #include "core/fxcrt/css/cfx_csscustomproperty.h"
 #include "core/fxcrt/fx_string.h"
 #include "core/fxge/fx_dib.h"
+#include "third_party/base/optional.h"
 
 class CFX_CSSValueList;
 
@@ -58,8 +59,7 @@
 
   CONSTRUCT_VIA_MAKE_RETAIN;
 
-  size_t CountFontFamilies() const;
-  const WideString GetFontFamily(size_t index) const;
+  Optional<WideString> GetLastFontFamily() const;
   uint16_t GetFontWeight() const;
   CFX_CSSFontVariant GetFontVariant() const;
   CFX_CSSFontStyle GetFontStyle() const;
diff --git a/xfa/fxfa/cxfa_textparser.cpp b/xfa/fxfa/cxfa_textparser.cpp
index eb01fa8..fdbb3cb 100644
--- a/xfa/fxfa/cxfa_textparser.cpp
+++ b/xfa/fxfa/cxfa_textparser.cpp
@@ -350,9 +350,9 @@
   }
 
   if (pStyle) {
-    size_t count = pStyle->CountFontFamilies();
-    if (count > 0)
-      wsFamily = pStyle->GetFontFamily(count - 1).AsStringView();
+    Optional<WideString> last_family = pStyle->GetLastFontFamily();
+    if (last_family.has_value())
+      wsFamily = last_family.value();
 
     dwStyle = 0;
     if (pStyle->GetFontWeight() > FXFONT_FW_NORMAL)