diff options
author | Nicolas Pena <npm@chromium.org> | 2017-05-17 14:48:29 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-05-17 19:08:33 +0000 |
commit | 17f4e0268b31f2f75a01567b83dbb763680344e1 (patch) | |
tree | 3d9a738f0063a68be17d5011949ab255861ff85b | |
parent | c559156da52805513e11b1b2a057001b6fa63f90 (diff) | |
download | pdfium-17f4e0268b31f2f75a01567b83dbb763680344e1.tar.xz |
Reland: Small fix in CPDF_TrueTypeFont load
The ToUnicode map should not be ignored when it exists. Doing so can cause a
charcode to be assigned an incorrect glyph index, and will result in garbled
text.
Previously, some bots failed with 'unable to open' the .png file.
Bug: chromium:665467
Change-Id: I435a73647eadcc3ba37bb0120f3b5cee381ae7a3
Reviewed-on: https://pdfium-review.googlesource.com/5610
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Nicolás Peña <npm@chromium.org>
-rw-r--r-- | core/fpdfapi/font/cpdf_truetypefont.cpp | 40 | ||||
-rw-r--r-- | testing/resources/pixel/bug_665467.in | 99 | ||||
-rw-r--r-- | testing/resources/pixel/bug_665467_expected.pdf.0.png | bin | 0 -> 467 bytes | |||
-rw-r--r-- | testing/resources/pixel/bug_665467_expected_mac.pdf.0.png | bin | 0 -> 509 bytes |
4 files changed, 117 insertions, 22 deletions
diff --git a/core/fpdfapi/font/cpdf_truetypefont.cpp b/core/fpdfapi/font/cpdf_truetypefont.cpp index d78a5e0eb2..7f4512da05 100644 --- a/core/fpdfapi/font/cpdf_truetypefont.cpp +++ b/core/fpdfapi/font/cpdf_truetypefont.cpp @@ -125,28 +125,24 @@ void CPDF_TrueTypeFont::LoadGlyphMap() { } } } - if ((m_GlyphIndex[charcode] == 0 || m_GlyphIndex[charcode] == 0xffff) && - name) { - if (name[0] == '.' && strcmp(name, ".notdef") == 0) { - m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), 32); - } else { - m_GlyphIndex[charcode] = - FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name); - if (m_GlyphIndex[charcode] == 0) { - if (bToUnicode) { - CFX_WideString wsUnicode = UnicodeFromCharCode(charcode); - if (!wsUnicode.IsEmpty()) { - m_GlyphIndex[charcode] = - FXFT_Get_Char_Index(m_Font.GetFace(), wsUnicode[0]); - m_Encoding.m_Unicodes[charcode] = wsUnicode[0]; - } - } - if (m_GlyphIndex[charcode] == 0) { - m_GlyphIndex[charcode] = - FXFT_Get_Char_Index(m_Font.GetFace(), charcode); - } - } - } + if ((m_GlyphIndex[charcode] != 0 && m_GlyphIndex[charcode] != 0xffff) || + !name) { + continue; + } + if (strcmp(name, ".notdef") == 0) { + m_GlyphIndex[charcode] = FXFT_Get_Char_Index(m_Font.GetFace(), 32); + continue; + } + m_GlyphIndex[charcode] = + FXFT_Get_Name_Index(m_Font.GetFace(), (char*)name); + if (m_GlyphIndex[charcode] != 0 || !bToUnicode) + continue; + + CFX_WideString wsUnicode = UnicodeFromCharCode(charcode); + if (!wsUnicode.IsEmpty()) { + m_GlyphIndex[charcode] = + FXFT_Get_Char_Index(m_Font.GetFace(), wsUnicode[0]); + m_Encoding.m_Unicodes[charcode] = wsUnicode[0]; } } return; diff --git a/testing/resources/pixel/bug_665467.in b/testing/resources/pixel/bug_665467.in new file mode 100644 index 0000000000..6ef2c1cb82 --- /dev/null +++ b/testing/resources/pixel/bug_665467.in @@ -0,0 +1,99 @@ +{{header}} +{{object 1 0}} << + /Type /Catalog + /Pages 2 0 R +>> +endobj + +{{object 2 0}} << + /Type /Pages + /MediaBox [ 0 0 100 100 ] + /Count 1 + /Kids [ 3 0 R ] +>> +endobj + +{{object 3 0}} << + /Type /Page + /Parent 2 0 R + /Resources + << + /Font << /F1 4 0 R >> + >> + /Contents 8 0 R +>> +endobj + +{{object 4 0}} << + /Type /Font + /Subtype /TrueType + /BaseFont /ChromeSansMM + /Encoding 5 0 R + /FirstChar 32 + /LastChar 255 + /Name /F1 + /ToUnicode 6 0 R + /FontDescriptor 7 0 R +>> +endobj + +{{object 5 0}} << + /Differences [ 161 /someunknownname ] + /Type /Encoding +>> +endobj + +{{object 6 0}} << +>> +stream +/CIDInit /ProcSet findresource begin +12 dict begin +begincmap +/CIDSystemInfo +<</Registry (Adobe) +/Ordering (Identity) +/Supplement 0 +>> def +/CMapName /Adobe-Identity-H def +CMapType 2 def +1 begincodespacerange +<00> <FF> +endcodespacerange +1 beginbfchar +<A1> <043B> +endbfchar +endcmap +CMapName currentdict /CMap defineresource pop +end +end +endstream +endobj + +{{object 7 0}} << + << /Ascent 1000 + /CapHeight 0 + /Descent -200 + /Flags 32 + /FontBBox [ -599 -207 1338 1034 ] + /FontName /ChromeSansMM + /ItalicAngle 0 + /StemV 0 + /Type /FontDescriptor +>> +endobj + +{{object 8 0}} << +>> +stream +BT +50 50 Td /F1 15 Tf <A1> Tj +ET +endstream +endobj + +{{xref}} +trailer << + /Root 1 0 R +>> +{{startxref}} +%%EOF diff --git a/testing/resources/pixel/bug_665467_expected.pdf.0.png b/testing/resources/pixel/bug_665467_expected.pdf.0.png Binary files differnew file mode 100644 index 0000000000..617cb0a916 --- /dev/null +++ b/testing/resources/pixel/bug_665467_expected.pdf.0.png diff --git a/testing/resources/pixel/bug_665467_expected_mac.pdf.0.png b/testing/resources/pixel/bug_665467_expected_mac.pdf.0.png Binary files differnew file mode 100644 index 0000000000..9f51dcb855 --- /dev/null +++ b/testing/resources/pixel/bug_665467_expected_mac.pdf.0.png |