Expose MakeTag() as CFX_FontMapper::MakeTag().

MakeTag() is stashed away in core/fpdfapi/font/cfx_cttgsubtable.cpp.
Move it out to core/fxge/cfx_fontmapper.h, and use it in
core/fxge/systemfontinfo_iface.h to get the value for some constants.
Since MakeTag() is a constexpr function, the constants can also become
constexpr.

Add unit tests for MakeTag() as well.

Change-Id: I2723f0f427166e7ed8713a24ecb9b7b6c1a7d930
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/64131
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/font/cfx_cttgsubtable.cpp b/core/fpdfapi/font/cfx_cttgsubtable.cpp
index 5492fc2..49f93dc 100644
--- a/core/fpdfapi/font/cfx_cttgsubtable.cpp
+++ b/core/fpdfapi/font/cfx_cttgsubtable.cpp
@@ -8,21 +8,16 @@
 
 #include <utility>
 
-#include "core/fxge/fx_freetype.h"
+#include "core/fxge/cfx_fontmapper.h"
 #include "third_party/base/ptr_util.h"
 #include "third_party/base/stl_util.h"
 
 namespace {
 
-constexpr uint32_t MakeTag(char c1, char c2, char c3, char c4) {
-  return static_cast<uint8_t>(c1) << 24 | static_cast<uint8_t>(c2) << 16 |
-         static_cast<uint8_t>(c3) << 8 | static_cast<uint8_t>(c4);
-}
-
 bool IsVerticalFeatureTag(uint32_t tag) {
   static constexpr uint32_t kTags[] = {
-      MakeTag('v', 'r', 't', '2'),
-      MakeTag('v', 'e', 'r', 't'),
+      CFX_FontMapper::MakeTag('v', 'r', 't', '2'),
+      CFX_FontMapper::MakeTag('v', 'e', 'r', 't'),
   };
   return tag == kTags[0] || tag == kTags[1];
 }
diff --git a/core/fxge/BUILD.gn b/core/fxge/BUILD.gn
index ad47e0a..1c34eba 100644
--- a/core/fxge/BUILD.gn
+++ b/core/fxge/BUILD.gn
@@ -200,6 +200,7 @@
 
 pdfium_unittest_source_set("unittests") {
   sources = [
+    "cfx_fontmapper_unittest.cpp",
     "dib/cfx_cmyk_to_srgb_unittest.cpp",
     "dib/cfx_dibitmap_unittest.cpp",
     "dib/cstretchengine_unittest.cpp",
diff --git a/core/fxge/cfx_fontmapper.h b/core/fxge/cfx_fontmapper.h
index 89bdfb4..3ce0c29 100644
--- a/core/fxge/cfx_fontmapper.h
+++ b/core/fxge/cfx_fontmapper.h
@@ -44,6 +44,10 @@
   static Optional<StandardFont> GetStandardFontName(ByteString* name);
   static bool IsSymbolicFont(StandardFont font);
   static bool IsFixedFont(StandardFont font);
+  static constexpr uint32_t MakeTag(char c1, char c2, char c3, char c4) {
+    return static_cast<uint8_t>(c1) << 24 | static_cast<uint8_t>(c2) << 16 |
+           static_cast<uint8_t>(c3) << 8 | static_cast<uint8_t>(c4);
+  }
 
   void SetSystemFontInfo(std::unique_ptr<SystemFontInfoIface> pFontInfo);
   SystemFontInfoIface* GetSystemFontInfo() { return m_pFontInfo.get(); }
diff --git a/core/fxge/cfx_fontmapper_unittest.cpp b/core/fxge/cfx_fontmapper_unittest.cpp
new file mode 100644
index 0000000..e69387d
--- /dev/null
+++ b/core/fxge/cfx_fontmapper_unittest.cpp
@@ -0,0 +1,20 @@
+// Copyright 2019 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/fxge/cfx_fontmapper.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+// Deliberately give this global variable external linkage.
+char g_maybe_changes = '\xff';
+
+TEST(CFX_FontMapper, MakeTag) {
+  EXPECT_EQ(0x61626364u, CFX_FontMapper::MakeTag('a', 'b', 'c', 'd'));
+  EXPECT_EQ(0x00000000u, CFX_FontMapper::MakeTag('\0', '\0', '\0', '\0'));
+  EXPECT_EQ(0xfffe0a08u, CFX_FontMapper::MakeTag('\xff', '\xfe', '\n', '\b'));
+  EXPECT_EQ(0xffffffffu,
+            CFX_FontMapper::MakeTag('\xff', '\xff', '\xff', '\xff'));
+  EXPECT_EQ(0xffffffffu,
+            CFX_FontMapper::MakeTag(g_maybe_changes, '\xff', '\xff', '\xff'));
+}
diff --git a/core/fxge/systemfontinfo_iface.h b/core/fxge/systemfontinfo_iface.h
index d5d84c3..9a6fbc7 100644
--- a/core/fxge/systemfontinfo_iface.h
+++ b/core/fxge/systemfontinfo_iface.h
@@ -12,8 +12,8 @@
 #include "core/fxge/cfx_fontmapper.h"
 #include "third_party/base/span.h"
 
-const uint32_t kTableNAME = FXDWORD_GET_MSBFIRST("name");
-const uint32_t kTableTTCF = FXDWORD_GET_MSBFIRST("ttcf");
+constexpr uint32_t kTableNAME = CFX_FontMapper::MakeTag('n', 'a', 'm', 'e');
+constexpr uint32_t kTableTTCF = CFX_FontMapper::MakeTag('t', 't', 'c', 'f');
 
 class SystemFontInfoIface {
  public: