Deprecate GET_TT_SHORT() in favor of FXSYS_UINT16_GET_MSBFIRST()

Remove some identical macros from our code base.

-- Do the same for GET_TT_LONG().
-- Move fx_system.h and fx_freetype.h includes to .cpp file.

Change-Id: Ic27ad4559e22082791c79d17c4e510b1075d624d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/83270
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxge/cfx_folderfontinfo.cpp b/core/fxge/cfx_folderfontinfo.cpp
index a676534..e4812ef 100644
--- a/core/fxge/cfx_folderfontinfo.cpp
+++ b/core/fxge/cfx_folderfontinfo.cpp
@@ -15,6 +15,7 @@
 #include "core/fxcrt/fx_folder.h"
 #include "core/fxcrt/fx_memory_wrappers.h"
 #include "core/fxcrt/fx_safe_types.h"
+#include "core/fxcrt/fx_system.h"
 #include "core/fxge/cfx_fontmapper.h"
 #include "core/fxge/fx_font.h"
 #include "third_party/base/containers/contains.h"
@@ -86,9 +87,9 @@
                            uint32_t fileSize) {
   for (uint32_t i = 0; i < nTables; i++) {
     const uint8_t* p = pTables + i * 16;
-    if (GET_TT_LONG(p) == tag) {
-      uint32_t offset = GET_TT_LONG(p + 8);
-      uint32_t size = GET_TT_LONG(p + 12);
+    if (FXSYS_UINT32_GET_MSBFIRST(p) == tag) {
+      uint32_t offset = FXSYS_UINT32_GET_MSBFIRST(p + 8);
+      uint32_t size = FXSYS_UINT32_GET_MSBFIRST(p + 12);
       if (offset > std::numeric_limits<uint32_t>::max() - size ||
           offset + size > fileSize || fseek(pFile, offset, SEEK_SET) < 0) {
         return ByteString();
@@ -205,12 +206,12 @@
   if (readCnt != 1)
     return;
 
-  if (GET_TT_LONG(buffer) != kTableTTCF) {
+  if (FXSYS_UINT32_GET_MSBFIRST(buffer) != kTableTTCF) {
     ReportFace(path, pFile.get(), filesize, 0);
     return;
   }
 
-  uint32_t nFaces = GET_TT_LONG(buffer + 8);
+  uint32_t nFaces = FXSYS_UINT32_GET_MSBFIRST(buffer + 8);
   FX_SAFE_SIZE_T safe_face_bytes = nFaces;
   safe_face_bytes *= 4;
   if (!safe_face_bytes.IsValid())
@@ -224,8 +225,10 @@
     return;
 
   auto offsets_span = pdfium::make_span(offsets.get(), face_bytes);
-  for (uint32_t i = 0; i < nFaces; i++)
-    ReportFace(path, pFile.get(), filesize, GET_TT_LONG(&offsets_span[i * 4]));
+  for (uint32_t i = 0; i < nFaces; i++) {
+    ReportFace(path, pFile.get(), filesize,
+               FXSYS_UINT32_GET_MSBFIRST(&offsets_span[i * 4]));
+  }
 }
 
 void CFX_FolderFontInfo::ReportFace(const ByteString& path,
@@ -236,7 +239,7 @@
   if (fseek(pFile, offset, SEEK_SET) < 0 || !fread(buffer, 12, 1, pFile))
     return;
 
-  uint32_t nTables = GET_TT_SHORT(buffer + 4);
+  uint32_t nTables = FXSYS_UINT16_GET_MSBFIRST(buffer + 4);
   ByteString tables = ReadStringFromFile(pFile, nTables * 16);
   if (tables.IsEmpty())
     return;
@@ -263,7 +266,7 @@
       LoadTableFromTT(pFile, tables.raw_str(), nTables, 0x4f532f32, filesize);
   if (os2.GetLength() >= 86) {
     const uint8_t* p = os2.raw_str() + 78;
-    uint32_t codepages = GET_TT_LONG(p);
+    uint32_t codepages = FXSYS_UINT32_GET_MSBFIRST(p);
     if (codepages & (1U << 17)) {
       m_pMapper->AddInstalledFont(facename, FX_CHARSET_ShiftJIS);
       pInfo->m_Charsets |= CHARSET_FLAG_SHIFTJIS;
@@ -370,9 +373,9 @@
     uint32_t nTables = pFont->m_FontTables.GetLength() / 16;
     for (uint32_t i = 0; i < nTables; i++) {
       const uint8_t* p = pFont->m_FontTables.raw_str() + i * 16;
-      if (GET_TT_LONG(p) == table) {
-        offset = GET_TT_LONG(p + 8);
-        datasize = GET_TT_LONG(p + 12);
+      if (FXSYS_UINT32_GET_MSBFIRST(p) == table) {
+        offset = FXSYS_UINT32_GET_MSBFIRST(p + 8);
+        datasize = FXSYS_UINT32_GET_MSBFIRST(p + 12);
       }
     }
   }
diff --git a/core/fxge/fx_font.cpp b/core/fxge/fx_font.cpp
index fe2d6b1..9ea7201 100644
--- a/core/fxge/fx_font.cpp
+++ b/core/fxge/fx_font.cpp
@@ -7,8 +7,10 @@
 #include <algorithm>
 
 #include "core/fxcrt/fx_safe_types.h"
+#include "core/fxcrt/fx_system.h"
 #include "core/fxge/cfx_glyphbitmap.h"
 #include "core/fxge/dib/cfx_dibitmap.h"
+#include "core/fxge/fx_freetype.h"
 #include "core/fxge/text_glyph_pos.h"
 
 namespace {
@@ -80,8 +82,8 @@
   if (name_table.size() < 6)
     return ByteString();
 
-  uint32_t name_count = GET_TT_SHORT(&name_table[2]);
-  uint32_t string_offset = GET_TT_SHORT(&name_table[4]);
+  uint32_t name_count = FXSYS_UINT16_GET_MSBFIRST(&name_table[2]);
+  uint32_t string_offset = FXSYS_UINT16_GET_MSBFIRST(&name_table[4]);
   // We will ignore the possibility of overlap of structures and
   // string table as if it's all corrupt there's not a lot we can do.
   if (name_table.size() < string_offset)
@@ -94,21 +96,24 @@
 
   for (uint32_t i = 0; i < name_count;
        i++, name_table = name_table.subspan(12)) {
-    if (GET_TT_SHORT(&name_table[6]) == name_id) {
-      const uint16_t platform_identifier = GET_TT_SHORT(name_table);
-      const uint16_t platform_encoding = GET_TT_SHORT(&name_table[2]);
+    if (FXSYS_UINT16_GET_MSBFIRST(&name_table[6]) == name_id) {
+      const uint16_t platform_identifier =
+          FXSYS_UINT16_GET_MSBFIRST(name_table);
+      const uint16_t platform_encoding =
+          FXSYS_UINT16_GET_MSBFIRST(&name_table[2]);
 
       if (platform_identifier == kNamePlatformMac &&
           platform_encoding == kNameMacEncodingRoman) {
-        return GetStringFromTable(string_span, GET_TT_SHORT(&name_table[10]),
-                                  GET_TT_SHORT(&name_table[8]));
+        return GetStringFromTable(string_span,
+                                  FXSYS_UINT16_GET_MSBFIRST(&name_table[10]),
+                                  FXSYS_UINT16_GET_MSBFIRST(&name_table[8]));
       }
       if (platform_identifier == kNamePlatformWindows &&
           platform_encoding == kNameWindowsEncodingUnicode) {
         // This name is always UTF16-BE and we have to convert it to UTF8.
-        ByteString utf16_be =
-            GetStringFromTable(string_span, GET_TT_SHORT(&name_table[10]),
-                               GET_TT_SHORT(&name_table[8]));
+        ByteString utf16_be = GetStringFromTable(
+            string_span, FXSYS_UINT16_GET_MSBFIRST(&name_table[10]),
+            FXSYS_UINT16_GET_MSBFIRST(&name_table[8]));
         if (utf16_be.IsEmpty() || utf16_be.GetLength() % 2 != 0) {
           return ByteString();
         }
@@ -126,11 +131,11 @@
 
 int GetTTCIndex(pdfium::span<const uint8_t> pFontData, uint32_t font_offset) {
   const uint8_t* p = pFontData.data() + 8;
-  uint32_t nfont = GET_TT_LONG(p);
+  uint32_t nfont = FXSYS_UINT32_GET_MSBFIRST(p);
   uint32_t index;
   for (index = 0; index < nfont; index++) {
     p = pFontData.data() + 12 + index * 4;
-    if (GET_TT_LONG(p) == font_offset)
+    if (FXSYS_UINT32_GET_MSBFIRST(p) == font_offset)
       return index;
   }
   return 0;
diff --git a/core/fxge/fx_font.h b/core/fxge/fx_font.h
index df59db3..9a7fe05 100644
--- a/core/fxge/fx_font.h
+++ b/core/fxge/fx_font.h
@@ -11,8 +11,6 @@
 
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_string.h"
-#include "core/fxcrt/fx_system.h"
-#include "core/fxge/fx_freetype.h"
 #include "third_party/base/span.h"
 
 /* Font pitch and family flags */
@@ -40,10 +38,6 @@
 /* Other font flags */
 #define FXFONT_USEEXTERNATTR 0x80000
 
-#define GET_TT_SHORT(w) (uint16_t)(((w)[0] << 8) | (w)[1])
-#define GET_TT_LONG(w) \
-  (uint32_t)(((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
-
 #if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
 class SkTypeface;