1 // Copyright 2016 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #include "core/fxge/cfx_unicodeencoding.h" 8 9 #include "core/fxcrt/fx_codepage.h" 10 #include "core/fxge/cfx_font.h" 11 #include "core/fxge/cfx_substfont.h" 12 #include "core/fxge/fx_font.h" 13 #include "core/fxge/fx_freetype.h" 14 CFX_UnicodeEncoding(CFX_Font * pFont)15CFX_UnicodeEncoding::CFX_UnicodeEncoding(CFX_Font* pFont) : m_pFont(pFont) {} 16 ~CFX_UnicodeEncoding()17CFX_UnicodeEncoding::~CFX_UnicodeEncoding() {} 18 GlyphFromCharCode(uint32_t charcode)19uint32_t CFX_UnicodeEncoding::GlyphFromCharCode(uint32_t charcode) { 20 FXFT_FaceRec* face = m_pFont->GetFaceRec(); 21 if (!face) 22 return charcode; 23 24 if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) == 0) 25 return FT_Get_Char_Index(face, charcode); 26 27 if (m_pFont->GetSubstFont() && 28 m_pFont->GetSubstFont()->m_Charset == FX_CHARSET_Symbol) { 29 uint32_t index = 0; 30 if (FT_Select_Charmap(face, FT_ENCODING_MS_SYMBOL) == 0) 31 index = FT_Get_Char_Index(face, charcode); 32 if (!index && !FT_Select_Charmap(face, FT_ENCODING_APPLE_ROMAN)) 33 return FT_Get_Char_Index(face, charcode); 34 } 35 return charcode; 36 } 37