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/fxge/fx_font.h" 10 #include "core/fxge/fx_freetype.h" 11 CFX_UnicodeEncoding(CFX_Font * pFont)12CFX_UnicodeEncoding::CFX_UnicodeEncoding(CFX_Font* pFont) : m_pFont(pFont) {} 13 ~CFX_UnicodeEncoding()14CFX_UnicodeEncoding::~CFX_UnicodeEncoding() {} 15 GlyphFromCharCode(uint32_t charcode)16uint32_t CFX_UnicodeEncoding::GlyphFromCharCode(uint32_t charcode) { 17 FXFT_Face face = m_pFont->GetFace(); 18 if (!face) 19 return charcode; 20 21 if (FXFT_Select_Charmap(face, FXFT_ENCODING_UNICODE) == 0) 22 return FXFT_Get_Char_Index(face, charcode); 23 24 if (m_pFont->GetSubstFont() && 25 m_pFont->GetSubstFont()->m_Charset == FXFONT_SYMBOL_CHARSET) { 26 uint32_t index = 0; 27 if (FXFT_Select_Charmap(face, FXFT_ENCODING_MS_SYMBOL) == 0) 28 index = FXFT_Get_Char_Index(face, charcode); 29 if (!index && !FXFT_Select_Charmap(face, FXFT_ENCODING_APPLE_ROMAN)) 30 return FXFT_Get_Char_Index(face, charcode); 31 } 32 return charcode; 33 } 34