diff options
Diffstat (limited to 'core/fpdfapi/fpdf_font/cpdf_cidfont.cpp')
-rw-r--r-- | core/fpdfapi/fpdf_font/cpdf_cidfont.cpp | 199 |
1 files changed, 92 insertions, 107 deletions
diff --git a/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp b/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp index 317e6ddb01..73197a8427 100644 --- a/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp +++ b/core/fpdfapi/fpdf_font/cpdf_cidfont.cpp @@ -463,7 +463,7 @@ FX_RECT CPDF_CIDFont::GetCharBBox(uint32_t charcode, int level) { return FX_RECT(m_CharBBox[charcode]); FX_RECT rect; - FX_BOOL bVert = FALSE; + bool bVert = false; int glyph_index = GlyphFromCharCode(charcode, &bVert); FXFT_Face face = m_Font.GetFace(); if (face) { @@ -579,60 +579,55 @@ void CPDF_CIDFont::GetVertOrigin(uint16_t CID, short& vx, short& vy) const { vx = (short)dwWidth / 2; vy = (short)m_DefaultVY; } -int CPDF_CIDFont::GetGlyphIndex(uint32_t unicode, FX_BOOL* pVertGlyph) { - if (pVertGlyph) { - *pVertGlyph = FALSE; - } + +int CPDF_CIDFont::GetGlyphIndex(uint32_t unicode, bool* pVertGlyph) { + if (pVertGlyph) + *pVertGlyph = false; + FXFT_Face face = m_Font.GetFace(); int index = FXFT_Get_Char_Index(face, unicode); - if (unicode == 0x2502) { + if (unicode == 0x2502) return index; - } - if (index && IsVertWriting()) { - if (m_pTTGSUBTable) { - uint32_t vindex = 0; - m_pTTGSUBTable->GetVerticalGlyph(index, &vindex); - if (vindex) { - index = vindex; - if (pVertGlyph) { - *pVertGlyph = TRUE; - } - } - return index; - } - if (!m_Font.GetSubData()) { - unsigned long length = 0; - int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, - nullptr, &length); - if (!error) { - m_Font.SetSubData(FX_Alloc(uint8_t, length)); - } - } - int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, - m_Font.GetSubData(), nullptr); - if (!error && m_Font.GetSubData()) { - m_pTTGSUBTable.reset(new CFX_CTTGSUBTable); - m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.GetSubData()); - uint32_t vindex = 0; - m_pTTGSUBTable->GetVerticalGlyph(index, &vindex); - if (vindex) { - index = vindex; - if (pVertGlyph) { - *pVertGlyph = TRUE; - } - } - } + + if (!index || !IsVertWriting()) return index; + + if (m_pTTGSUBTable) + return GetVerticalGlyph(index, pVertGlyph); + + if (!m_Font.GetSubData()) { + unsigned long length = 0; + int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, + nullptr, &length); + if (!error) + m_Font.SetSubData(FX_Alloc(uint8_t, length)); } - if (pVertGlyph) { - *pVertGlyph = FALSE; - } + int error = FXFT_Load_Sfnt_Table(face, FT_MAKE_TAG('G', 'S', 'U', 'B'), 0, + m_Font.GetSubData(), nullptr); + if (error || !m_Font.GetSubData()) + return index; + + m_pTTGSUBTable.reset(new CFX_CTTGSUBTable); + m_pTTGSUBTable->LoadGSUBTable((FT_Bytes)m_Font.GetSubData()); + return GetVerticalGlyph(index, pVertGlyph); +} + +int CPDF_CIDFont::GetVerticalGlyph(int index, bool* pVertGlyph) { + uint32_t vindex = 0; + m_pTTGSUBTable->GetVerticalGlyph(index, &vindex); + if (!vindex) + return index; + + index = vindex; + if (pVertGlyph) + *pVertGlyph = true; return index; } -int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, FX_BOOL* pVertGlyph) { - if (pVertGlyph) { + +int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, bool* pVertGlyph) { + if (pVertGlyph) *pVertGlyph = FALSE; - } + if (!m_pFontFile && !m_pStreamAcc) { uint16_t cid = CIDFromCharCode(charcode); FX_WCHAR unicode = 0; @@ -640,66 +635,60 @@ int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, FX_BOOL* pVertGlyph) { #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ return cid; #else - if (m_Flags & PDFFONT_SYMBOLIC) { + if (m_Flags & PDFFONT_SYMBOLIC) return cid; - } + CFX_WideString uni_str = UnicodeFromCharCode(charcode); - if (uni_str.IsEmpty()) { + if (uni_str.IsEmpty()) return cid; - } + unicode = uni_str.GetAt(0); #endif } else { - if (cid && m_pCID2UnicodeMap && m_pCID2UnicodeMap->IsLoaded()) { + if (cid && m_pCID2UnicodeMap && m_pCID2UnicodeMap->IsLoaded()) unicode = m_pCID2UnicodeMap->UnicodeFromCID(cid); - } - if (unicode == 0) { + if (unicode == 0) unicode = GetUnicodeFromCharCode(charcode); - } - if (unicode == 0 && !(m_Flags & PDFFONT_SYMBOLIC)) { + if (unicode == 0 && !(m_Flags & PDFFONT_SYMBOLIC)) unicode = UnicodeFromCharCode(charcode).GetAt(0); - } } FXFT_Face face = m_Font.GetFace(); if (unicode == 0) { - if (!m_bAdobeCourierStd) { - return charcode == 0 ? -1 : (int)charcode; - } + if (!m_bAdobeCourierStd) + return charcode ? static_cast<int>(charcode) : -1; + charcode += 31; - int index = 0, iBaseEncoding; FX_BOOL bMSUnicode = FT_UseTTCharmap(face, 3, 1); - FX_BOOL bMacRoman = FALSE; - if (!bMSUnicode) { - bMacRoman = FT_UseTTCharmap(face, 1, 0); - } - iBaseEncoding = PDFFONT_ENCODING_STANDARD; + FX_BOOL bMacRoman = bMSUnicode ? FALSE : FT_UseTTCharmap(face, 1, 0); + int iBaseEncoding = PDFFONT_ENCODING_STANDARD; if (bMSUnicode) { iBaseEncoding = PDFFONT_ENCODING_WINANSI; } else if (bMacRoman) { iBaseEncoding = PDFFONT_ENCODING_MACROMAN; } const FX_CHAR* name = GetAdobeCharName(iBaseEncoding, nullptr, charcode); - if (!name) { - return charcode == 0 ? -1 : (int)charcode; - } + if (!name) + return charcode ? static_cast<int>(charcode) : -1; + + int index = 0; uint16_t name_unicode = PDF_UnicodeFromAdobeName(name); - if (name_unicode) { - if (bMSUnicode) { - index = FXFT_Get_Char_Index(face, name_unicode); - } else if (bMacRoman) { - uint32_t maccode = - FT_CharCodeFromUnicode(FXFT_ENCODING_APPLE_ROMAN, name_unicode); - index = !maccode ? FXFT_Get_Name_Index(face, (char*)name) - : FXFT_Get_Char_Index(face, maccode); - } else { - return FXFT_Get_Char_Index(face, name_unicode); - } + if (!name_unicode) + return charcode ? static_cast<int>(charcode) : -1; + + if (iBaseEncoding == PDFFONT_ENCODING_STANDARD) + return FXFT_Get_Char_Index(face, name_unicode); + + if (iBaseEncoding == PDFFONT_ENCODING_WINANSI) { + index = FXFT_Get_Char_Index(face, name_unicode); } else { - return charcode == 0 ? -1 : (int)charcode; - } - if (index == 0 || index == 0xffff) { - return charcode == 0 ? -1 : (int)charcode; + ASSERT(iBaseEncoding == PDFFONT_ENCODING_MACROMAN); + uint32_t maccode = + FT_CharCodeFromUnicode(FXFT_ENCODING_APPLE_ROMAN, name_unicode); + index = maccode ? FXFT_Get_Char_Index(face, maccode) + : FXFT_Get_Name_Index(face, const_cast<char*>(name)); } + if (index == 0 || index == 0xffff) + return charcode ? static_cast<int>(charcode) : -1; return index; } if (m_Charset == CIDSET_JAPAN1) { @@ -715,7 +704,7 @@ int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, FX_BOOL* pVertGlyph) { return unicode; int err = FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE); - if (err != 0) { + if (err) { int i; for (i = 0; i < FXFT_Get_Face_CharmapCount(face); i++) { uint32_t ret = FT_CharCodeFromUnicode( @@ -735,38 +724,34 @@ int CPDF_CIDFont::GlyphFromCharCode(uint32_t charcode, FX_BOOL* pVertGlyph) { } if (FXFT_Get_Face_Charmap(face)) { int index = GetGlyphIndex(unicode, pVertGlyph); - if (index == 0) - return -1; - return index; + return index != 0 ? index : -1; } return unicode; } + if (!m_Font.GetFace()) return -1; uint16_t cid = CIDFromCharCode(charcode); - if (m_bType1) { - if (!m_pStreamAcc) { + if (!m_pStreamAcc) { + if (m_bType1) + return cid; + + if (m_pFontFile && !m_pCMap->m_pMapping) + return cid; + if (m_pCMap->m_Coding == CIDCODING_UNKNOWN || + !FXFT_Get_Face_Charmap(m_Font.GetFace())) { return cid; } - } else { - if (!m_pStreamAcc) { - if (m_pFontFile && !m_pCMap->m_pMapping) - return cid; - if (m_pCMap->m_Coding == CIDCODING_UNKNOWN || - !FXFT_Get_Face_Charmap(m_Font.GetFace())) { - return cid; - } - if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmap(m_Font.GetFace())) == - FXFT_ENCODING_UNICODE) { - CFX_WideString unicode_str = UnicodeFromCharCode(charcode); - if (unicode_str.IsEmpty()) { - return -1; - } - charcode = unicode_str.GetAt(0); - } - return GetGlyphIndex(charcode, pVertGlyph); + if (FXFT_Get_Charmap_Encoding(FXFT_Get_Face_Charmap(m_Font.GetFace())) == + FXFT_ENCODING_UNICODE) { + CFX_WideString unicode_str = UnicodeFromCharCode(charcode); + if (unicode_str.IsEmpty()) + return -1; + + charcode = unicode_str.GetAt(0); } + return GetGlyphIndex(charcode, pVertGlyph); } uint32_t byte_pos = cid * 2; if (byte_pos + 2 > m_pStreamAcc->GetSize()) |