1 // Copyright 2016 The PDFium Authors 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_fontencoding.h" 14 CFX_UnicodeEncoding(const CFX_Font * pFont)15CFX_UnicodeEncoding::CFX_UnicodeEncoding(const CFX_Font* pFont) 16 : m_pFont(pFont) {} 17 18 CFX_UnicodeEncoding::~CFX_UnicodeEncoding() = default; 19 GlyphFromCharCode(uint32_t charcode)20uint32_t CFX_UnicodeEncoding::GlyphFromCharCode(uint32_t charcode) { 21 RetainPtr<CFX_Face> face = m_pFont->GetFace(); 22 if (!face) 23 return charcode; 24 25 if (face->SelectCharMap(fxge::FontEncoding::kUnicode)) { 26 return face->GetCharIndex(charcode); 27 } 28 29 if (m_pFont->GetSubstFont() && 30 m_pFont->GetSubstFont()->m_Charset == FX_Charset::kSymbol) { 31 uint32_t index = 0; 32 if (face->SelectCharMap(fxge::FontEncoding::kSymbol)) { 33 index = face->GetCharIndex(charcode); 34 } 35 if (!index && face->SelectCharMap(fxge::FontEncoding::kAppleRoman)) { 36 return face->GetCharIndex(charcode); 37 } 38 } 39 return charcode; 40 } 41