Cover FPDF_GetDefaultTTFMap() from embedder tests.

Then add missing definitions exposed by tests.

Change-Id: I6fc35100890dd2bdfa9b92c7465ba2c94255ec41
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/64850
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp
index 5264639..96ceef2 100644
--- a/fpdfsdk/fpdf_sysfontinfo.cpp
+++ b/fpdfsdk/fpdf_sysfontinfo.cpp
@@ -6,6 +6,8 @@
 
 #include "public/fpdf_sysfontinfo.h"
 
+#include <stddef.h>
+
 #include <memory>
 
 #include "core/fxcrt/fx_codepage.h"
@@ -29,8 +31,21 @@
               "Charset must match");
 static_assert(FXFONT_CHINESEBIG5_CHARSET == FX_CHARSET_ChineseTraditional,
               "Charset must match");
+static_assert(FXFONT_ARABIC_CHARSET == FX_CHARSET_MSWin_Arabic,
+              "Charset must match");
+static_assert(FXFONT_CYRILLIC_CHARSET == FX_CHARSET_MSWin_Cyrillic,
+              "Charset must match");
+static_assert(FXFONT_EASTERNEUROPEAN_CHARSET ==
+                  FX_CHARSET_MSWin_EasternEuropean,
+              "Charset must match");
+static_assert(offsetof(CFX_Font::CharsetFontMap, charset) ==
+                  offsetof(FPDF_CharsetFontMap, charset),
+              "CFX_Font::CharsetFontMap must be same as FPDF_CharsetFontMap");
+static_assert(offsetof(CFX_Font::CharsetFontMap, fontname) ==
+                  offsetof(FPDF_CharsetFontMap, fontname),
+              "CFX_Font::CharsetFontMap must be same as FPDF_CharsetFontMap");
 static_assert(sizeof(CFX_Font::CharsetFontMap) == sizeof(FPDF_CharsetFontMap),
-              "CFX_Font::CharsetFontMap should be same as FPDF_CharsetFontMap");
+              "CFX_Font::CharsetFontMap must be same as FPDF_CharsetFontMap");
 
 class CFX_ExternalFontInfo final : public SystemFontInfoIface {
  public:
diff --git a/fpdfsdk/fpdf_sysfontinfo_embeddertest.cpp b/fpdfsdk/fpdf_sysfontinfo_embeddertest.cpp
index 290805b..61cec04 100644
--- a/fpdfsdk/fpdf_sysfontinfo_embeddertest.cpp
+++ b/fpdfsdk/fpdf_sysfontinfo_embeddertest.cpp
@@ -6,6 +6,7 @@
 
 #include "testing/embedder_test.h"
 #include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/base/stl_util.h"
 
 namespace {
 
@@ -122,3 +123,33 @@
 
   UnloadPage(page);
 }
+
+TEST_F(FPDFSysFontInfoEmbedderTest, DefaultTTFMap) {
+  static const int kAllowedCharsets[] = {
+      FXFONT_ANSI_CHARSET,        FXFONT_DEFAULT_CHARSET,
+      FXFONT_SYMBOL_CHARSET,      FXFONT_SHIFTJIS_CHARSET,
+      FXFONT_HANGEUL_CHARSET,     FXFONT_GB2312_CHARSET,
+      FXFONT_CHINESEBIG5_CHARSET, FXFONT_ARABIC_CHARSET,
+      FXFONT_CYRILLIC_CHARSET,    FXFONT_EASTERNEUROPEAN_CHARSET,
+  };
+  std::set<int> seen_charsets;
+
+  const FPDF_CharsetFontMap* cfmap = FPDF_GetDefaultTTFMap();
+  ASSERT_TRUE(cfmap);
+
+  // Stop at either end mark.
+  while (cfmap->charset != -1 && cfmap->fontname) {
+    // Only returns values described as legitimate in public header.
+    EXPECT_TRUE(pdfium::ContainsValue(kAllowedCharsets, cfmap->charset))
+        << " for " << cfmap->charset;
+
+    // Duplicates are not allowed.
+    EXPECT_TRUE(seen_charsets.insert(cfmap->charset).second)
+        << " for " << cfmap->charset;
+    ++cfmap;
+  }
+
+  // Confirm end marks only occur as a pair.
+  EXPECT_EQ(cfmap->charset, -1);
+  EXPECT_EQ(cfmap->fontname, nullptr);
+}
diff --git a/public/fpdf_sysfontinfo.h b/public/fpdf_sysfontinfo.h
index 30cdd44..936de96 100644
--- a/public/fpdf_sysfontinfo.h
+++ b/public/fpdf_sysfontinfo.h
@@ -19,6 +19,9 @@
 #define FXFONT_HANGEUL_CHARSET 129
 #define FXFONT_GB2312_CHARSET 134
 #define FXFONT_CHINESEBIG5_CHARSET 136
+#define FXFONT_ARABIC_CHARSET 178
+#define FXFONT_CYRILLIC_CHARSET 204
+#define FXFONT_EASTERNEUROPEAN_CHARSET 238
 
 /* Font pitch and family flags */
 #define FXFONT_FF_FIXEDPITCH (1 << 0)