Remove some checks for CPDF_TextObject::GetFont() return values.

Looking at other callers, it seems GetFont() never returns nullptr. So
remove the checks and hope this does not cause any crashes.

Along the way, simplify some callers in CPDF_TextObject to use GetFont()
instead of its implementation. Do the same for GetFontSize().

Change-Id: Id60e0519983571c2b810f43493921335d8b33e40
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/60270
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_textobject.cpp b/core/fpdfapi/page/cpdf_textobject.cpp
index feb49e4..fb365ac 100644
--- a/core/fpdfapi/page/cpdf_textobject.cpp
+++ b/core/fpdfapi/page/cpdf_textobject.cpp
@@ -42,7 +42,7 @@
   if (pInfo->m_CharCode == CPDF_Font::kInvalidCharCode)
     return;
 
-  RetainPtr<CPDF_Font> pFont = m_TextState.GetFont();
+  RetainPtr<CPDF_Font> pFont = GetFont();
   if (!pFont->IsCIDFont() || !pFont->AsCIDFont()->IsVertWriting())
     return;
 
@@ -53,7 +53,7 @@
   short vy;
   pFont->AsCIDFont()->GetVertOrigin(CID, vx, vy);
 
-  float fontsize = m_TextState.GetFontSize();
+  float fontsize = GetFontSize();
   pInfo->m_Origin.x -= fontsize * vx / 1000;
   pInfo->m_Origin.y -= fontsize * vy / 1000;
 }
@@ -103,9 +103,6 @@
 
 int CPDF_TextObject::CountWords() const {
   RetainPtr<CPDF_Font> pFont = GetFont();
-  if (!pFont)
-    return 0;
-
   bool bInLatinWord = false;
   int nWords = 0;
   for (size_t i = 0, sz = CountChars(); i < sz; ++i) {
@@ -132,9 +129,6 @@
 
 WideString CPDF_TextObject::GetWordString(int nWordIndex) const {
   RetainPtr<CPDF_Font> pFont = GetFont();
-  if (!pFont)
-    return WideString();
-
   WideString swRet;
   int nWords = 0;
   bool bInLatinWord = false;
@@ -209,7 +203,7 @@
                                   size_t nSegs) {
   m_CharCodes.clear();
   m_CharPos.clear();
-  RetainPtr<CPDF_Font> pFont = m_TextState.GetFont();
+  RetainPtr<CPDF_Font> pFont = GetFont();
   int nChars = 0;
   for (size_t i = 0; i < nSegs; ++i)
     nChars += pFont->CountChar(pStrs[i].AsStringView());
@@ -238,8 +232,8 @@
 }
 
 float CPDF_TextObject::GetCharWidth(uint32_t charcode) const {
-  float fontsize = m_TextState.GetFontSize() / 1000;
-  RetainPtr<CPDF_Font> pFont = m_TextState.GetFont();
+  float fontsize = GetFontSize() / 1000;
+  RetainPtr<CPDF_Font> pFont = GetFont();
   bool bVertWriting = false;
   CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
   if (pCIDFont)
@@ -265,13 +259,13 @@
   float max_x = -10000 * 1.0f;
   float min_y = 10000 * 1.0f;
   float max_y = -10000 * 1.0f;
-  RetainPtr<CPDF_Font> pFont = m_TextState.GetFont();
+  RetainPtr<CPDF_Font> pFont = GetFont();
   bool bVertWriting = false;
   CPDF_CIDFont* pCIDFont = pFont->AsCIDFont();
   if (pCIDFont)
     bVertWriting = pCIDFont->IsVertWriting();
 
-  float fontsize = m_TextState.GetFontSize();
+  float fontsize = GetFontSize();
   for (size_t i = 0; i < m_CharCodes.size(); ++i) {
     uint32_t charcode = m_CharCodes[i];
     if (i > 0) {
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index 3d3ba26..66f7080 100644
--- a/fpdfsdk/fpdf_edittext.cpp
+++ b/fpdfsdk/fpdf_edittext.cpp
@@ -542,9 +542,6 @@
     return 0;
 
   RetainPtr<CPDF_Font> pPdfFont = pTextObj->GetFont();
-  if (!pPdfFont)
-    return 0;
-
   CFX_Font* pFont = pPdfFont->GetFont();
   ByteString name = pFont->GetFamilyName();
   unsigned long dwStringLen = name.GetLength() + 1;
diff --git a/fpdfsdk/fpdf_text.cpp b/fpdfsdk/fpdf_text.cpp
index 1b39fea..a635847 100644
--- a/fpdfsdk/fpdf_text.cpp
+++ b/fpdfsdk/fpdf_text.cpp
@@ -104,9 +104,6 @@
     return 0;
 
   RetainPtr<CPDF_Font> font = charinfo.m_pTextObj->GetFont();
-  if (!font)
-    return 0;
-
   if (flags)
     *flags = font->GetFontFlags();