• 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/android/cfx_androidfontinfo.h"
8 
9 #include "core/fxcrt/fx_system.h"
10 #include "core/fxge/android/cfpf_skiafont.h"
11 #include "core/fxge/android/cfpf_skiafontmgr.h"
12 #include "core/fxge/cfx_fontmapper.h"
13 #include "core/fxge/fx_font.h"
14 
CFX_AndroidFontInfo()15 CFX_AndroidFontInfo::CFX_AndroidFontInfo() : m_pFontMgr(nullptr) {}
~CFX_AndroidFontInfo()16 CFX_AndroidFontInfo::~CFX_AndroidFontInfo() {}
Init(CFPF_SkiaFontMgr * pFontMgr)17 bool CFX_AndroidFontInfo::Init(CFPF_SkiaFontMgr* pFontMgr) {
18   if (!pFontMgr)
19     return false;
20 
21   pFontMgr->LoadSystemFonts();
22   m_pFontMgr = pFontMgr;
23   return true;
24 }
25 
EnumFontList(CFX_FontMapper * pMapper)26 bool CFX_AndroidFontInfo::EnumFontList(CFX_FontMapper* pMapper) {
27   return false;
28 }
29 
MapFont(int weight,bool bItalic,int charset,int pitch_family,const char * face)30 void* CFX_AndroidFontInfo::MapFont(int weight,
31                                    bool bItalic,
32                                    int charset,
33                                    int pitch_family,
34                                    const char* face) {
35   if (!m_pFontMgr)
36     return nullptr;
37 
38   uint32_t dwStyle = 0;
39   if (weight >= 700)
40     dwStyle |= FXFONT_FORCE_BOLD;
41   if (bItalic)
42     dwStyle |= FXFONT_ITALIC;
43   if (FontFamilyIsFixedPitch(pitch_family))
44     dwStyle |= FXFONT_FIXED_PITCH;
45   if (FontFamilyIsScript(pitch_family))
46     dwStyle |= FXFONT_SCRIPT;
47   if (FontFamilyIsRoman(pitch_family))
48     dwStyle |= FXFONT_SERIF;
49   return m_pFontMgr->CreateFont(face, charset, dwStyle);
50 }
51 
GetFont(const char * face)52 void* CFX_AndroidFontInfo::GetFont(const char* face) {
53   return nullptr;
54 }
55 
GetFontData(void * hFont,uint32_t table,pdfium::span<uint8_t> buffer)56 uint32_t CFX_AndroidFontInfo::GetFontData(void* hFont,
57                                           uint32_t table,
58                                           pdfium::span<uint8_t> buffer) {
59   if (!hFont)
60     return 0;
61   return static_cast<CFPF_SkiaFont*>(hFont)->GetFontData(table, buffer);
62 }
63 
GetFaceName(void * hFont,ByteString * name)64 bool CFX_AndroidFontInfo::GetFaceName(void* hFont, ByteString* name) {
65   if (!hFont)
66     return false;
67 
68   *name = static_cast<CFPF_SkiaFont*>(hFont)->GetFamilyName();
69   return true;
70 }
71 
GetFontCharset(void * hFont,int * charset)72 bool CFX_AndroidFontInfo::GetFontCharset(void* hFont, int* charset) {
73   if (!hFont)
74     return false;
75 
76   *charset = static_cast<CFPF_SkiaFont*>(hFont)->GetCharset();
77   return false;
78 }
79 
DeleteFont(void * hFont)80 void CFX_AndroidFontInfo::DeleteFont(void* hFont) {}
81