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