xref: /aosp_15_r20/external/pdfium/core/fxge/cfx_unicodeencoding.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
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/freetype/fx_freetype.h"
13 #include "core/fxge/fx_font.h"
14 
CFX_UnicodeEncoding(const CFX_Font * pFont)15 CFX_UnicodeEncoding::CFX_UnicodeEncoding(const CFX_Font* pFont)
16     : m_pFont(pFont) {}
17 
18 CFX_UnicodeEncoding::~CFX_UnicodeEncoding() = default;
19 
GlyphFromCharCode(uint32_t charcode)20 uint32_t CFX_UnicodeEncoding::GlyphFromCharCode(uint32_t charcode) {
21   FXFT_FaceRec* face = m_pFont->GetFaceRec();
22   if (!face)
23     return charcode;
24 
25   if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) == 0)
26     return FT_Get_Char_Index(face, charcode);
27 
28   if (m_pFont->GetSubstFont() &&
29       m_pFont->GetSubstFont()->m_Charset == FX_Charset::kSymbol) {
30     uint32_t index = 0;
31     if (FT_Select_Charmap(face, FT_ENCODING_MS_SYMBOL) == 0)
32       index = FT_Get_Char_Index(face, charcode);
33     if (!index && !FT_Select_Charmap(face, FT_ENCODING_APPLE_ROMAN))
34       return FT_Get_Char_Index(face, charcode);
35   }
36   return charcode;
37 }
38