Fix enum type mismatch in CPDF_FontEncoding.

Apart from PDFFONT_ENCODING_BUILTIN and FT_ENCODING_NONE, none of
the PDFFONT_* definitions and FT_Encoding definitions have equivalent
values. Since we pass these around as ints, it is easy to mix them up
without compile-time detection. Once we re-write the FT_ functions to
take FT_Encoding enums, a couple of problems crop up:

CPDF_Type1Font.cpp:213 (and 275) are calling with the wrong enum, but
CPDF_FontEncoding.cpp:1810 handles a mismatched enum, but the
mismatched enum is not the one being passed by any of the mismatched
callers. The result is those calls always get back a 0.

So we are left to guess intent. The FT_ENCODING_ADOBE_STANDARD enum
matches against our StandardEncoding table, so perhaps that was the
intent when passing the mismatched PDFFONT_ENCODING_STANDARD value.
Alternatively, maybe the intent was to match against the odd
PDFFONT_ENCODING_PDFDOC case in the switch. Or it may just be that
getting 0 and removing dead code is the best option.

This CL tries the first option to see how it affects rendering,
since it the most uptight about type safety, and we remove the
mismatched case from the switch.

Change-Id: I08cf85a8adf1ddabc6c2aa4484972b262af7ee49
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/80610
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_fontencoding.cpp b/core/fpdfapi/font/cpdf_fontencoding.cpp
index c456b60..b727226 100644
--- a/core/fpdfapi/font/cpdf_fontencoding.cpp
+++ b/core/fpdfapi/font/cpdf_fontencoding.cpp
@@ -1723,7 +1723,7 @@
   return pDict;
 }
 
-uint32_t FT_CharCodeFromUnicode(int encoding, wchar_t unicode) {
+uint32_t FT_CharCodeFromUnicode(FT_Encoding encoding, wchar_t unicode) {
   switch (encoding) {
     case FT_ENCODING_UNICODE:
       return unicode;
@@ -1739,9 +1739,28 @@
       return PDF_FindCode(PDFDocEncoding, unicode);
     case FT_ENCODING_MS_SYMBOL:
       return PDF_FindCode(MSSymbolEncoding, unicode);
+    default:
+      return 0;
   }
-  return 0;
 }
+
+wchar_t FT_UnicodeFromCharCode(FT_Encoding encoding, uint32_t charcode) {
+  switch (encoding) {
+    case FT_ENCODING_UNICODE:
+      return (uint16_t)charcode;
+    case FT_ENCODING_ADOBE_STANDARD:
+      return StandardEncoding[(uint8_t)charcode];
+    case FT_ENCODING_ADOBE_EXPERT:
+      return MacExpertEncoding[(uint8_t)charcode];
+    case FT_ENCODING_ADOBE_LATIN_1:
+      return AdobeWinAnsiEncoding[(uint8_t)charcode];
+    case FT_ENCODING_APPLE_ROMAN:
+      return MacRomanEncoding[(uint8_t)charcode];
+    default:
+      return 0;
+  }
+}
+
 const uint16_t* PDF_UnicodesForPredefinedCharSet(int encoding) {
   switch (encoding) {
     case PDFFONT_ENCODING_WINANSI:
@@ -1794,21 +1813,3 @@
   }
   return nullptr;
 }
-
-wchar_t FT_UnicodeFromCharCode(int encoding, uint32_t charcode) {
-  switch (encoding) {
-    case FT_ENCODING_UNICODE:
-      return (uint16_t)charcode;
-    case FT_ENCODING_ADOBE_STANDARD:
-      return StandardEncoding[(uint8_t)charcode];
-    case FT_ENCODING_ADOBE_EXPERT:
-      return MacExpertEncoding[(uint8_t)charcode];
-    case FT_ENCODING_ADOBE_LATIN_1:
-      return AdobeWinAnsiEncoding[(uint8_t)charcode];
-    case FT_ENCODING_APPLE_ROMAN:
-      return MacRomanEncoding[(uint8_t)charcode];
-    case PDFFONT_ENCODING_PDFDOC:
-      return PDFDocEncoding[(uint8_t)charcode];
-  }
-  return 0;
-}
diff --git a/core/fpdfapi/font/cpdf_fontencoding.h b/core/fpdfapi/font/cpdf_fontencoding.h
index 4ff6403..1447042 100644
--- a/core/fpdfapi/font/cpdf_fontencoding.h
+++ b/core/fpdfapi/font/cpdf_fontencoding.h
@@ -11,6 +11,7 @@
 #include "core/fxcrt/retain_ptr.h"
 #include "core/fxcrt/string_pool_template.h"
 #include "core/fxcrt/weak_ptr.h"
+#include "core/fxge/fx_freetype.h"
 
 #define PDFFONT_ENCODING_BUILTIN 0
 #define PDFFONT_ENCODING_WINANSI 1
@@ -22,8 +23,8 @@
 #define PDFFONT_ENCODING_PDFDOC 7
 #define PDFFONT_ENCODING_MS_SYMBOL 8
 
-uint32_t FT_CharCodeFromUnicode(int encoding, wchar_t unicode);
-wchar_t FT_UnicodeFromCharCode(int encoding, uint32_t charcode);
+uint32_t FT_CharCodeFromUnicode(FT_Encoding encoding, wchar_t unicode);
+wchar_t FT_UnicodeFromCharCode(FT_Encoding encoding, uint32_t charcode);
 
 const uint16_t* PDF_UnicodesForPredefinedCharSet(int encoding);
 const char* PDF_CharNameFromPredefinedCharSet(int encoding, uint8_t charcode);
diff --git a/core/fpdfapi/font/cpdf_type1font.cpp b/core/fpdfapi/font/cpdf_type1font.cpp
index 90dd4dc..6ff2014 100644
--- a/core/fpdfapi/font/cpdf_type1font.cpp
+++ b/core/fpdfapi/font/cpdf_type1font.cpp
@@ -215,7 +215,7 @@
           wchar_t unicode = 0;
           if (m_GlyphIndex[charcode]) {
             unicode =
-                FT_UnicodeFromCharCode(PDFFONT_ENCODING_STANDARD, charcode);
+                FT_UnicodeFromCharCode(FT_ENCODING_ADOBE_STANDARD, charcode);
           }
           char name_glyph[kInternalTableSize] = {};
           FT_Get_Glyph_Name(m_Font.GetFaceRec(), m_GlyphIndex[charcode],
@@ -276,7 +276,7 @@
             FT_Get_Char_Index(m_Font.GetFaceRec(), charcode);
         if (m_GlyphIndex[charcode]) {
           wchar_t unicode =
-              FT_UnicodeFromCharCode(PDFFONT_ENCODING_STANDARD, charcode);
+              FT_UnicodeFromCharCode(FT_ENCODING_ADOBE_STANDARD, charcode);
           if (unicode == 0) {
             char name_glyph[kInternalTableSize] = {};
             FT_Get_Glyph_Name(m_Font.GetFaceRec(), m_GlyphIndex[charcode],