diff options
author | Nicolas Pena <npm@chromium.org> | 2017-04-12 15:05:15 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-12 19:52:00 +0000 |
commit | 27a0f350ff26ba752eb17a593bbaad17fbbe71d2 (patch) | |
tree | 48996b61ff35c5621b7658e8e73a655f6dc8c010 /core/fpdfapi | |
parent | 94c34c9934bf93fc68d0ab0bb0c6696ce71b6441 (diff) | |
download | pdfium-27a0f350ff26ba752eb17a593bbaad17fbbe71d2.tar.xz |
Some fixes to the fallback font code.
This CL applies several fixes to the fallback font code.
- PDFium uses -1 to indicate that no glyph index was found, but freetype uses
0. In CPDF_TrueTypeFont, an index of 0 indicates a freetype failure, which
means we should try to find the glyph from a fallback font.
- Improve the fallback glyph calculation by going from original font charcode
to unicode to fallback font charcode.
- Consider the m_ExtGID on Mac when deciding the fallback.
Bug: chromium:665467
Change-Id: I2be34983e0d768d9a598043f84edd2d70f033c86
Reviewed-on: https://pdfium-review.googlesource.com/4055
Commit-Queue: Nicolás Peña <npm@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/font/cpdf_font.cpp | 7 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_simplefont.cpp | 7 | ||||
-rw-r--r-- | core/fpdfapi/font/cpdf_truetypefont.cpp | 9 | ||||
-rw-r--r-- | core/fpdfapi/render/cpdf_charposlist.cpp | 14 |
4 files changed, 22 insertions, 15 deletions
diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp index a6a661b328..b9be3aa868 100644 --- a/core/fpdfapi/font/cpdf_font.cpp +++ b/core/fpdfapi/font/cpdf_font.cpp @@ -457,9 +457,12 @@ int CPDF_Font::FallbackGlyphFromCharcode(int fallbackFont, uint32_t charcode) { if (!pdfium::IndexInBounds(m_FontFallbacks, fallbackFont)) return -1; + CFX_WideString str = UnicodeFromCharCode(charcode); + uint32_t unicode = !str.IsEmpty() ? str.GetAt(0) : charcode; int glyph = - FXFT_Get_Char_Index(m_FontFallbacks[fallbackFont]->GetFace(), charcode); - if (glyph == 0 || glyph == 0xffff) + FXFT_Get_Char_Index(m_FontFallbacks[fallbackFont]->GetFace(), unicode); + if (glyph == 0) return -1; + return glyph; } diff --git a/core/fpdfapi/font/cpdf_simplefont.cpp b/core/fpdfapi/font/cpdf_simplefont.cpp index a3597824bd..cb8f00a98a 100644 --- a/core/fpdfapi/font/cpdf_simplefont.cpp +++ b/core/fpdfapi/font/cpdf_simplefont.cpp @@ -29,8 +29,11 @@ int CPDF_SimpleFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) { if (charcode > 0xff) return -1; - int index = m_GlyphIndex[(uint8_t)charcode]; - return index != 0xffff ? index : -1; + int index = m_GlyphIndex[charcode]; + if (index == 0xffff || (index == 0 && IsTrueTypeFont())) + return -1; + + return index; } void CPDF_SimpleFont::LoadCharMetrics(int charcode) { diff --git a/core/fpdfapi/font/cpdf_truetypefont.cpp b/core/fpdfapi/font/cpdf_truetypefont.cpp index 54e565bfd1..d78a5e0eb2 100644 --- a/core/fpdfapi/font/cpdf_truetypefont.cpp +++ b/core/fpdfapi/font/cpdf_truetypefont.cpp @@ -73,13 +73,11 @@ void CPDF_TrueTypeFont::LoadGlyphMap() { return; int charcode = 0; - for (; charcode < nStartChar; charcode++) { + for (; charcode < nStartChar; charcode++) m_GlyphIndex[charcode] = 0; - } uint16_t nGlyph = charcode - nStartChar + 3; - for (; charcode < 256; charcode++, nGlyph++) { + for (; charcode < 256; charcode++, nGlyph++) m_GlyphIndex[charcode] = nGlyph; - } return; } bool bMSUnicode = FT_UseTTCharmap(m_Font.GetFace(), 3, 1); @@ -108,9 +106,8 @@ void CPDF_TrueTypeFont::LoadGlyphMap() { uint16_t unicode = kPrefix[j] * 256 + charcode; m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), unicode); - if (m_GlyphIndex[charcode]) { + if (m_GlyphIndex[charcode]) break; - } } } else if (m_Encoding.m_Unicodes[charcode]) { if (bMSUnicode) { diff --git a/core/fpdfapi/render/cpdf_charposlist.cpp b/core/fpdfapi/render/cpdf_charposlist.cpp index 6d4540e163..d4c6b3b5f9 100644 --- a/core/fpdfapi/render/cpdf_charposlist.cpp +++ b/core/fpdfapi/render/cpdf_charposlist.cpp @@ -39,19 +39,23 @@ void CPDF_CharPosList::Load(const std::vector<uint32_t>& charCodes, charpos.m_bFontStyle = true; charpos.m_GlyphIndex = pFont->GlyphFromCharCode(CharCode, &bVert); - if (charpos.m_GlyphIndex != static_cast<uint32_t>(-1)) { + uint32_t GlyphID = charpos.m_GlyphIndex; +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode); + GlyphID = charpos.m_ExtGID; +#endif + if (GlyphID != static_cast<uint32_t>(-1)) { charpos.m_FallbackFontPosition = -1; } else { charpos.m_FallbackFontPosition = pFont->FallbackFontFromCharcode(CharCode); charpos.m_GlyphIndex = pFont->FallbackGlyphFromCharcode( charpos.m_FallbackFontPosition, CharCode); - } - -// TODO(npm): Figure out how this affects m_ExtGID #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ - charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode); + charpos.m_ExtGID = charpos.m_GlyphIndex; #endif + } + if (!pFont->IsEmbedded() && !pFont->IsCIDFont()) charpos.m_FontCharWidth = pFont->GetCharWidthF(CharCode); else |