Add CFX_FontMapper::GetChecksumFromTT() helper method

The code is already indented a block so it might as well be
moved into its own helper.

- Remove redundant check from GetPSNameFromTT() already made by
  its only caller.

Change-Id: I56145e87dc913ac810cd4e6dee26334b2d4836b4
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/56632
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index fb88b3c..ef79e6f 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -269,10 +269,19 @@
   m_pFontInfo = std::move(pFontInfo);
 }
 
-ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont) {
-  if (!m_pFontInfo)
-    return ByteString();
+uint32_t CFX_FontMapper::GetChecksumFromTT(void* hFont) {
+  uint32_t buffer[256];
+  m_pFontInfo->GetFontData(hFont, kTableTTCF,
+                           reinterpret_cast<uint8_t*>(buffer), sizeof(buffer));
 
+  uint32_t checksum = 0;
+  for (auto x : buffer)
+    checksum += x;
+
+  return checksum;
+}
+
+ByteString CFX_FontMapper::GetPSNameFromTT(void* hFont) {
   uint32_t size = m_pFontInfo->GetFontData(hFont, kTableNAME, nullptr, 0);
   if (!size)
     return ByteString();
@@ -674,14 +683,7 @@
 RetainPtr<CFX_Face> CFX_FontMapper::GetCachedTTCFace(void* hFont,
                                                      uint32_t ttc_size,
                                                      uint32_t font_size) {
-  uint32_t checksum = 0;
-  {
-    uint8_t buffer[1024];
-    m_pFontInfo->GetFontData(hFont, kTableTTCF, buffer, sizeof(buffer));
-    uint32_t* pBuffer = reinterpret_cast<uint32_t*>(buffer);
-    for (int i = 0; i < 256; i++)
-      checksum += pBuffer[i];
-  }
+  uint32_t checksum = GetChecksumFromTT(hFont);
   CFX_FontMgr::FontDesc* pFontDesc =
       m_pFontMgr->GetCachedTTCFontDesc(ttc_size, checksum);
   if (!pFontDesc) {
diff --git a/core/fxge/cfx_fontmapper.h b/core/fxge/cfx_fontmapper.h
index b1b06e2..682b4c5 100644
--- a/core/fxge/cfx_fontmapper.h
+++ b/core/fxge/cfx_fontmapper.h
@@ -69,6 +69,7 @@
   static const size_t MM_FACE_COUNT = 2;
   static const size_t FOXIT_FACE_COUNT = 14;
 
+  uint32_t GetChecksumFromTT(void* hFont);
   ByteString GetPSNameFromTT(void* hFont);
   ByteString MatchInstalledFonts(const ByteString& norm_name);
   RetainPtr<CFX_Face> UseInternalSubst(CFX_SubstFont* pSubstFont,