Remove m_bFlagExact from CFX_SubstFont This CL removes the single use case from |m_bFlagExact|. This flag allows the PDF viewer to treat a substitute font with a matching name as if it was actually an embedded font, which is wrong. For all substitute fonts, it is important to follow the longer process of first obtaining the unicode from the charcode to then obtain the glyph in the substitute font that corresponds to that unicode. Bug: chromium:781785 Change-Id: Ie5958b43914e0e46334b89b7c2c55c02d0da0c11 Reviewed-on: https://pdfium-review.googlesource.com/17859 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp index 4eedf7d..082b503 100644 --- a/core/fpdfapi/font/cpdf_cidfont.cpp +++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -407,7 +407,7 @@ if (!IsEmbedded()) LoadSubstFont(); - if (m_pFontFile || GetSubstFont()->m_bFlagExact) { + if (m_pFontFile) { CPDF_Object* pmap = pCIDFontDict->GetDirectObjectFor("CIDToGIDMap"); if (pmap) { if (CPDF_Stream* pStream = pmap->AsStream()) {
diff --git a/core/fxge/android/cfx_androidfontinfo.cpp b/core/fxge/android/cfx_androidfontinfo.cpp index 15ac8c2..61d213e 100644 --- a/core/fxge/android/cfx_androidfontinfo.cpp +++ b/core/fxge/android/cfx_androidfontinfo.cpp
@@ -30,8 +30,7 @@ bool bItalic, int charset, int pitch_family, - const char* face, - int& iExact) { + const char* face) { if (!m_pFontMgr) return nullptr;
diff --git a/core/fxge/android/cfx_androidfontinfo.h b/core/fxge/android/cfx_androidfontinfo.h index 653770f..bf5fae5 100644 --- a/core/fxge/android/cfx_androidfontinfo.h +++ b/core/fxge/android/cfx_androidfontinfo.h
@@ -28,8 +28,7 @@ bool bItalic, int charset, int pitch_family, - const char* face, - int& bExact) override; + const char* face) override; void* GetFont(const char* face) override; uint32_t GetFontData(void* hFont, uint32_t table,
diff --git a/core/fxge/apple/fx_mac_imp.cpp b/core/fxge/apple/fx_mac_imp.cpp index 324f020..edd36bf 100644 --- a/core/fxge/apple/fx_mac_imp.cpp +++ b/core/fxge/apple/fx_mac_imp.cpp
@@ -44,8 +44,7 @@ bool bItalic, int charset, int pitch_family, - const char* family, - int& iExact) override; + const char* family) override; }; const char JAPAN_GOTHIC[] = "Hiragino Kaku Gothic Pro W6"; @@ -64,13 +63,11 @@ bool bItalic, int charset, int pitch_family, - const char* cstr_face, - int& iExact) { + const char* cstr_face) { ByteString face = cstr_face; for (size_t i = 0; i < FX_ArraySize(g_Base14Substs); ++i) { if (face == ByteStringView(g_Base14Substs[i].m_pName)) { face = g_Base14Substs[i].m_pSubstName; - iExact = true; return GetFont(face.c_str()); } }
diff --git a/core/fxge/cfx_folderfontinfo.cpp b/core/fxge/cfx_folderfontinfo.cpp index 6b564f8..532824d 100644 --- a/core/fxge/cfx_folderfontinfo.cpp +++ b/core/fxge/cfx_folderfontinfo.cpp
@@ -313,8 +313,7 @@ bool bItalic, int charset, int pitch_family, - const char* family, - int& iExact) { + const char* family) { return nullptr; }
diff --git a/core/fxge/cfx_folderfontinfo.h b/core/fxge/cfx_folderfontinfo.h index 23c20d5..79faa01 100644 --- a/core/fxge/cfx_folderfontinfo.h +++ b/core/fxge/cfx_folderfontinfo.h
@@ -29,8 +29,7 @@ bool bItalic, int charset, int pitch_family, - const char* face, - int& bExact) override; + const char* face) override; #ifdef PDF_ENABLE_XFA void* MapFontByUnicode(uint32_t dwUnicode, int weight,
diff --git a/core/fxge/cfx_font.cpp b/core/fxge/cfx_font.cpp index da6b0e0..3f4f135 100644 --- a/core/fxge/cfx_font.cpp +++ b/core/fxge/cfx_font.cpp
@@ -237,7 +237,6 @@ m_pSubstFont = pdfium::MakeUnique<CFX_SubstFont>(); m_pSubstFont->m_Charset = pFont->m_pSubstFont->m_Charset; m_pSubstFont->m_bFlagMM = pFont->m_pSubstFont->m_bFlagMM; - m_pSubstFont->m_bFlagExact = pFont->m_pSubstFont->m_bFlagExact; #ifdef PDF_ENABLE_XFA m_pSubstFont->m_bFlagItalic = pFont->m_pSubstFont->m_bFlagItalic; #endif // PDF_ENABLE_XFA
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp index 0037288..0511b0a 100644 --- a/core/fxge/cfx_fontmapper.cpp +++ b/core/fxge/cfx_fontmapper.cpp
@@ -337,9 +337,7 @@ if (bLocalized) { void* hFont = m_pFontInfo->GetFont(name.c_str()); if (!hFont) { - int iExact; - hFont = m_pFontInfo->MapFont(0, 0, FX_CHARSET_Default, 0, name.c_str(), - iExact); + hFont = m_pFontInfo->MapFont(0, 0, FX_CHARSET_Default, 0, name.c_str()); if (!hFont) return; } @@ -554,7 +552,6 @@ if (FontStyleIsItalic(nStyle)) bItalic = true; - int iExact = 0; int Charset = FX_CHARSET_ANSI; if (WindowCP) Charset = GetCharsetFromCodePage(WindowCP); @@ -622,11 +619,8 @@ } else if (FontStyleIsItalic(flags)) { bItalic = true; } - iExact = !match.IsEmpty(); void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, - family.c_str(), iExact); - if (iExact) - pSubstFont->m_bFlagExact = true; + family.c_str()); if (!hFont) { #ifdef PDF_ENABLE_XFA if (flags & FXFONT_EXACTMATCH)
diff --git a/core/fxge/cfx_substfont.cpp b/core/fxge/cfx_substfont.cpp index 9058ab3..6c5459e 100644 --- a/core/fxge/cfx_substfont.cpp +++ b/core/fxge/cfx_substfont.cpp
@@ -19,6 +19,5 @@ #ifdef PDF_ENABLE_XFA m_bFlagItalic(false), #endif // PDF_ENABLE_XFA - m_bFlagMM(false), - m_bFlagExact(false) { + m_bFlagMM(false) { }
diff --git a/core/fxge/cfx_substfont.h b/core/fxge/cfx_substfont.h index 2076a09..e6d93a8 100644 --- a/core/fxge/cfx_substfont.h +++ b/core/fxge/cfx_substfont.h
@@ -25,7 +25,6 @@ bool m_bFlagItalic; #endif // PDF_ENABLE_XFA bool m_bFlagMM; - bool m_bFlagExact; }; #endif // CORE_FXGE_CFX_SUBSTFONT_H_
diff --git a/core/fxge/fx_ge_linux.cpp b/core/fxge/fx_ge_linux.cpp index c9d1dd1..22a3c4c 100644 --- a/core/fxge/fx_ge_linux.cpp +++ b/core/fxge/fx_ge_linux.cpp
@@ -74,8 +74,7 @@ bool bItalic, int charset, int pitch_family, - const char* family, - int& iExact) override; + const char* family) override; bool ParseFontCfg(const char** pUserPaths); }; @@ -83,13 +82,11 @@ bool bItalic, int charset, int pitch_family, - const char* cstr_face, - int& iExact) { + const char* cstr_face) { void* font = GetSubstFont(cstr_face); - if (font) { - iExact = 1; + if (font) return font; - } + bool bCJK = true; switch (charset) { case FX_CHARSET_ShiftJIS: {
diff --git a/core/fxge/ifx_systemfontinfo.h b/core/fxge/ifx_systemfontinfo.h index cb85f7f..b6d6626 100644 --- a/core/fxge/ifx_systemfontinfo.h +++ b/core/fxge/ifx_systemfontinfo.h
@@ -27,8 +27,7 @@ bool bItalic, int charset, int pitch_family, - const char* face, - int& iExact) = 0; + const char* face) = 0; #ifdef PDF_ENABLE_XFA virtual void* MapFontByUnicode(uint32_t dwUnicode,
diff --git a/core/fxge/win32/fx_win32_device.cpp b/core/fxge/win32/fx_win32_device.cpp index 35f9a5f..77e988c 100644 --- a/core/fxge/win32/fx_win32_device.cpp +++ b/core/fxge/win32/fx_win32_device.cpp
@@ -325,8 +325,7 @@ bool bItalic, int charset, int pitch_family, - const char* family, - int& iExact) override; + const char* family) override; }; class CFX_Win32FontInfo final : public IFX_SystemFontInfo { @@ -340,8 +339,7 @@ bool bItalic, int charset, int pitch_family, - const char* face, - int& iExact) override; + const char* face) override; void* GetFont(const char* face) override { return nullptr; } uint32_t GetFontData(void* hFont, uint32_t table, @@ -475,13 +473,11 @@ bool bItalic, int charset, int pitch_family, - const char* cstr_face, - int& iExact) { + const char* cstr_face) { void* font = GetSubstFont(cstr_face); - if (font) { - iExact = 1; + if (font) return font; - } + bool bCJK = true; switch (charset) { case FX_CHARSET_ShiftJIS: @@ -567,18 +563,17 @@ bool bItalic, int charset, int pitch_family, - const char* cstr_face, - int& iExact) { + const char* cstr_face) { ByteString face = cstr_face; int iBaseFont; - for (iBaseFont = 0; iBaseFont < 12; iBaseFont++) + for (iBaseFont = 0; iBaseFont < 12; iBaseFont++) { if (face == ByteStringView(g_Base14Substs[iBaseFont].m_pName)) { face = g_Base14Substs[iBaseFont].m_pWinName; weight = g_Base14Substs[iBaseFont].m_bBold ? FW_BOLD : FW_NORMAL; bItalic = g_Base14Substs[iBaseFont].m_bItalic; - iExact = true; break; } + } if (charset == FX_CHARSET_ANSI || charset == FX_CHARSET_Symbol) charset = FX_CHARSET_Default;
diff --git a/fpdfsdk/fpdf_sysfontinfo.cpp b/fpdfsdk/fpdf_sysfontinfo.cpp index f1f165a..9d5270c 100644 --- a/fpdfsdk/fpdf_sysfontinfo.cpp +++ b/fpdfsdk/fpdf_sysfontinfo.cpp
@@ -50,10 +50,11 @@ bool bItalic, int charset, int pitch_family, - const char* family, - int& iExact) override { + const char* family) override { if (!m_pInfo->MapFont) return nullptr; + + int iExact; return m_pInfo->MapFont(m_pInfo, weight, bItalic, charset, pitch_family, family, &iExact); } @@ -146,7 +147,7 @@ int* bExact) { auto* pDefault = static_cast<FPDF_SYSFONTINFO_DEFAULT*>(pThis); return pDefault->m_pFontInfo->MapFont(weight, !!bItalic, charset, - pitch_family, family, *bExact); + pitch_family, family); } void* DefaultGetFont(struct _FPDF_SYSFONTINFO* pThis, const char* family) {
diff --git a/public/fpdf_sysfontinfo.h b/public/fpdf_sysfontinfo.h index c9aa338..49302c8 100644 --- a/public/fpdf_sysfontinfo.h +++ b/public/fpdf_sysfontinfo.h
@@ -106,10 +106,7 @@ *constants. * face - Typeface name. Currently use system local encoding *only. - * bExact - Pointer to a boolean value receiving the indicator - *whether mapper found the exact match. - * If mapper is not sure whether it's exact match, - *ignore this paramter. + * bExact - Obsolete: this parameter is now ignored. * Return Value: * An opaque pointer for font handle, or NULL if system mapping is *not supported.
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index 7beba12..3838434 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp
@@ -957,10 +957,8 @@ CFX_FontMapper* pFontMapper, IFX_SystemFontInfo* pSystemFontInfo, uint32_t index) { - int iExact = 0; - void* hFont = - pSystemFontInfo->MapFont(0, 0, FX_CHARSET_Default, 0, - pFontMapper->GetFaceName(index).c_str(), iExact); + void* hFont = pSystemFontInfo->MapFont( + 0, 0, FX_CHARSET_Default, 0, pFontMapper->GetFaceName(index).c_str()); if (!hFont) return nullptr;