Revert "Fix enum type mismatch in CPDF_FontEncoding." This reverts commit 18192fde8ddc9cb87afd8a5f1c869e73bcb3484d. Reason for revert: Regressed text extraction for bigtable-osdi06.pdf. Original change's description: > 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> # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: If1233bc8b67dcf23e5827e9d4adda22d24483e79 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/83070 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_fontencoding.cpp b/core/fpdfapi/font/cpdf_fontencoding.cpp index b727226..c456b60 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(FT_Encoding encoding, wchar_t unicode) { +uint32_t FT_CharCodeFromUnicode(int encoding, wchar_t unicode) { switch (encoding) { case FT_ENCODING_UNICODE: return unicode; @@ -1739,28 +1739,9 @@ 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: @@ -1813,3 +1794,21 @@ } 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 1447042..4ff6403 100644 --- a/core/fpdfapi/font/cpdf_fontencoding.h +++ b/core/fpdfapi/font/cpdf_fontencoding.h
@@ -11,7 +11,6 @@ #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 @@ -23,8 +22,8 @@ #define PDFFONT_ENCODING_PDFDOC 7 #define PDFFONT_ENCODING_MS_SYMBOL 8 -uint32_t FT_CharCodeFromUnicode(FT_Encoding encoding, wchar_t unicode); -wchar_t FT_UnicodeFromCharCode(FT_Encoding encoding, uint32_t charcode); +uint32_t FT_CharCodeFromUnicode(int encoding, wchar_t unicode); +wchar_t FT_UnicodeFromCharCode(int 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 6ff2014..90dd4dc 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(FT_ENCODING_ADOBE_STANDARD, charcode); + FT_UnicodeFromCharCode(PDFFONT_ENCODING_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(FT_ENCODING_ADOBE_STANDARD, charcode); + FT_UnicodeFromCharCode(PDFFONT_ENCODING_STANDARD, charcode); if (unicode == 0) { char name_glyph[kInternalTableSize] = {}; FT_Get_Glyph_Name(m_Font.GetFaceRec(), m_GlyphIndex[charcode],