Remove circular includes from core/fpdfapi/cmaps.

Make the caller pass a lower-level structure.

Change-Id: I15e1fad985d77dca5b06b69585a8b716dd9b176c
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/54993
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/BUILD.gn b/core/fpdfapi/BUILD.gn
index 020c07d..1b8c39e 100644
--- a/core/fpdfapi/BUILD.gn
+++ b/core/fpdfapi/BUILD.gn
@@ -26,7 +26,6 @@
     "render",
   ]
   allow_circular_includes_from = [
-    "cmaps",
     "font",
     "page",
     "parser",
diff --git a/core/fpdfapi/cmaps/cmap_int.h b/core/fpdfapi/cmaps/cmap_int.h
index e532c76..f9f1490 100644
--- a/core/fpdfapi/cmaps/cmap_int.h
+++ b/core/fpdfapi/cmaps/cmap_int.h
@@ -9,6 +9,7 @@
 
 #include "core/fxcrt/fx_string.h"
 #include "core/fxcrt/fx_system.h"
+#include "third_party/base/span.h"
 
 struct FXCMAP_DWordCIDMap {
   uint16_t m_HiWord;
@@ -29,9 +30,8 @@
   int8_t m_UseOffset;
 };
 
-const FXCMAP_CMap* FindEmbeddedCMap(const ByteString& name,
-                                    int charset,
-                                    int coding);
+const FXCMAP_CMap* FindEmbeddedCMap(pdfium::span<const FXCMAP_CMap> pCMaps,
+                                    const ByteString& name);
 uint16_t CIDFromCharCode(const FXCMAP_CMap* pMap, uint32_t charcode);
 uint32_t CharCodeFromCID(const FXCMAP_CMap* pMap, uint16_t cid);
 
diff --git a/core/fpdfapi/cmaps/fpdf_cmaps.cpp b/core/fpdfapi/cmaps/fpdf_cmaps.cpp
index 5d2143c..13d467e 100644
--- a/core/fpdfapi/cmaps/fpdf_cmaps.cpp
+++ b/core/fpdfapi/cmaps/fpdf_cmaps.cpp
@@ -8,9 +8,6 @@
 
 #include <algorithm>
 
-#include "core/fpdfapi/cpdf_modulemgr.h"
-#include "core/fpdfapi/font/cpdf_fontglobals.h"
-#include "core/fpdfapi/page/cpdf_pagemodule.h"
 #include "third_party/base/span.h"
 
 namespace {
@@ -32,15 +29,8 @@
 
 }  // namespace
 
-const FXCMAP_CMap* FindEmbeddedCMap(const ByteString& bsName,
-                                    int charset,
-                                    int coding) {
-  CPDF_FontGlobals* pFontGlobals =
-      CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
-
-  pdfium::span<const FXCMAP_CMap> pCMaps =
-      pFontGlobals->GetEmbeddedCharset(charset);
-
+const FXCMAP_CMap* FindEmbeddedCMap(pdfium::span<const FXCMAP_CMap> pCMaps,
+                                    const ByteString& bsName) {
   for (size_t i = 0; i < pCMaps.size(); i++) {
     if (bsName == pCMaps[i].m_Name)
       return &pCMaps[i];
diff --git a/core/fpdfapi/font/BUILD.gn b/core/fpdfapi/font/BUILD.gn
index ae873cb..b3bff1c 100644
--- a/core/fpdfapi/font/BUILD.gn
+++ b/core/fpdfapi/font/BUILD.gn
@@ -51,10 +51,7 @@
   if (is_mac) {
     libs = [ "CoreFoundation.framework" ]
   }
-  allow_circular_includes_from = [
-    "../cmaps",
-    "../parser",
-  ]
+  allow_circular_includes_from = [ "../parser" ]
   visibility = [ "../../../*" ]
 }
 
diff --git a/core/fpdfapi/font/cpdf_cmap.cpp b/core/fpdfapi/font/cpdf_cmap.cpp
index d6fdd23..998ee71 100644
--- a/core/fpdfapi/font/cpdf_cmap.cpp
+++ b/core/fpdfapi/font/cpdf_cmap.cpp
@@ -11,8 +11,11 @@
 #include <vector>
 
 #include "core/fpdfapi/cmaps/cmap_int.h"
+#include "core/fpdfapi/cpdf_modulemgr.h"
 #include "core/fpdfapi/font/cpdf_cmapmanager.h"
 #include "core/fpdfapi/font/cpdf_cmapparser.h"
+#include "core/fpdfapi/font/cpdf_fontglobals.h"
+#include "core/fpdfapi/page/cpdf_pagemodule.h"
 #include "core/fpdfapi/parser/cpdf_simple_parser.h"
 
 namespace {
@@ -282,7 +285,10 @@
         m_MixedTwoByteLeadingBytes[b] = true;
     }
   }
-  m_pEmbedMap = FindEmbeddedCMap(bsName, m_Charset, m_Coding);
+  CPDF_FontGlobals* pFontGlobals =
+      CPDF_ModuleMgr::Get()->GetPageModule()->GetFontGlobals();
+  m_pEmbedMap =
+      FindEmbeddedCMap(pFontGlobals->GetEmbeddedCharset(m_Charset), bsName);
   if (!m_pEmbedMap)
     return;
 
diff --git a/core/fpdfapi/page/BUILD.gn b/core/fpdfapi/page/BUILD.gn
index 9529dad..ed9f1fb 100644
--- a/core/fpdfapi/page/BUILD.gn
+++ b/core/fpdfapi/page/BUILD.gn
@@ -101,7 +101,6 @@
     "../parser",
   ]
   allow_circular_includes_from = [
-    "../cmaps",
     "../font",
     "../parser",
     "../../fxcodec",