Simplify font code.

- Remove parameter from CFX_FontMapper::GetCachedTTCFace() and use
  constant inside GetCachedTTCFace() directly.
- Remove unused parameter from CFX_FontMgr::GetCachedTTCFace().
- Change CFX_FontMgr methods to have an unsigned |font_offset|.
  Calculate it once in the caller.

Change-Id: I0fe8c4009c10bcdccfda02f4f3cdad777f9b8c17
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/56410
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp
index 6a81aff..fd736ba 100644
--- a/core/fxge/cfx_fontmapper.cpp
+++ b/core/fxge/cfx_fontmapper.cpp
@@ -628,7 +628,7 @@
   }
   RetainPtr<CFX_Face> face;
   if (ttc_size)
-    face = GetCachedTTCFace(hFont, kTableTTCF, ttc_size, font_size);
+    face = GetCachedTTCFace(hFont, ttc_size, font_size);
   else
     face = GetCachedFace(hFont, SubstName, weight, bItalic, font_size);
   if (!face) {
@@ -672,28 +672,28 @@
 }
 
 RetainPtr<CFX_Face> CFX_FontMapper::GetCachedTTCFace(void* hFont,
-                                                     const uint32_t tableTTCF,
                                                      uint32_t ttc_size,
                                                      uint32_t font_size) {
   uint32_t checksum = 0;
   {
     uint8_t buffer[1024];
-    m_pFontInfo->GetFontData(hFont, tableTTCF, buffer, sizeof(buffer));
+    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];
   }
-  uint8_t* pIgnore = nullptr;
-  RetainPtr<CFX_Face> face = m_pFontMgr->GetCachedTTCFace(
-      ttc_size, checksum, ttc_size - font_size, &pIgnore);
+  ASSERT(ttc_size >= font_size);
+  uint32_t font_offset = ttc_size - font_size;
+  RetainPtr<CFX_Face> face =
+      m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, font_offset);
   if (face)
     return face;
 
   std::unique_ptr<uint8_t, FxFreeDeleter> pFontData(
       FX_Alloc(uint8_t, ttc_size));
-  m_pFontInfo->GetFontData(hFont, tableTTCF, pFontData.get(), ttc_size);
+  m_pFontInfo->GetFontData(hFont, kTableTTCF, pFontData.get(), ttc_size);
   return m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, std::move(pFontData),
-                                      ttc_size, ttc_size - font_size);
+                                      ttc_size, font_offset);
 }
 
 RetainPtr<CFX_Face> CFX_FontMapper::GetCachedFace(void* hFont,
diff --git a/core/fxge/cfx_fontmapper.h b/core/fxge/cfx_fontmapper.h
index 450291f..b1b06e2 100644
--- a/core/fxge/cfx_fontmapper.h
+++ b/core/fxge/cfx_fontmapper.h
@@ -77,7 +77,6 @@
                                        int weight,
                                        int picthfamily);
   RetainPtr<CFX_Face> GetCachedTTCFace(void* hFont,
-                                       const uint32_t tableTTCF,
                                        uint32_t ttc_size,
                                        uint32_t font_size);
   RetainPtr<CFX_Face> GetCachedFace(void* hFont,
diff --git a/core/fxge/cfx_fontmgr.cpp b/core/fxge/cfx_fontmgr.cpp
index d4d3cde..34c564b 100644
--- a/core/fxge/cfx_fontmgr.cpp
+++ b/core/fxge/cfx_fontmgr.cpp
@@ -147,14 +147,12 @@
 
 RetainPtr<CFX_Face> CFX_FontMgr::GetCachedTTCFace(int ttc_size,
                                                   uint32_t checksum,
-                                                  int font_offset,
-                                                  uint8_t** pFontData) {
+                                                  uint32_t font_offset) {
   auto it = m_FaceMap.find(KeyNameFromSize(ttc_size, checksum));
   if (it == m_FaceMap.end())
     return nullptr;
 
   CTTFontDesc* pFontDesc = it->second.get();
-  *pFontData = pFontDesc->FontData();
   int face_index = GetTTCIndex(pFontDesc->FontData(), ttc_size, font_offset);
   return pdfium::WrapRetain(pFontDesc->GetFace(face_index));
 }
@@ -164,7 +162,7 @@
     uint32_t checksum,
     std::unique_ptr<uint8_t, FxFreeDeleter> pData,
     uint32_t size,
-    int font_offset) {
+    uint32_t font_offset) {
   int face_index = GetTTCIndex(pData.get(), ttc_size, font_offset);
   RetainPtr<CFX_Face> face =
       GetFixedFace({pData.get(), static_cast<size_t>(ttc_size)}, face_index);
diff --git a/core/fxge/cfx_fontmgr.h b/core/fxge/cfx_fontmgr.h
index 3498ea1..38de56f 100644
--- a/core/fxge/cfx_fontmgr.h
+++ b/core/fxge/cfx_fontmgr.h
@@ -44,14 +44,13 @@
       int face_index);
   RetainPtr<CFX_Face> GetCachedTTCFace(int ttc_size,
                                        uint32_t checksum,
-                                       int font_offset,
-                                       uint8_t** pFontData);
+                                       uint32_t font_offset);
   RetainPtr<CFX_Face> AddCachedTTCFace(
       int ttc_size,
       uint32_t checksum,
       std::unique_ptr<uint8_t, FxFreeDeleter> pData,
       uint32_t size,
-      int font_offset);
+      uint32_t font_offset);
   RetainPtr<CFX_Face> GetFixedFace(pdfium::span<const uint8_t> span,
                                    int face_index);
   void SetSystemFontInfo(std::unique_ptr<SystemFontInfoIface> pFontInfo);