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
CFX_AndroidFontInfo()14 CFX_AndroidFontInfo::CFX_AndroidFontInfo() : m_pFontMgr(nullptr) {}
~CFX_AndroidFontInfo()15 CFX_AndroidFontInfo::~CFX_AndroidFontInfo() {}
Init(CFPF_SkiaFontMgr * pFontMgr)16 bool CFX_AndroidFontInfo::Init(CFPF_SkiaFontMgr* pFontMgr) {
17 if (!pFontMgr)
18 return false;
19
20 pFontMgr->LoadSystemFonts();
21 m_pFontMgr = pFontMgr;
22 return true;
23 }
24
EnumFontList(CFX_FontMapper * pMapper)25 bool CFX_AndroidFontInfo::EnumFontList(CFX_FontMapper* pMapper) {
26 return false;
27 }
28
MapFont(int weight,bool bItalic,int charset,int pitch_family,const char * face)29 void* CFX_AndroidFontInfo::MapFont(int weight,
30 bool bItalic,
31 int charset,
32 int pitch_family,
33 const char* face) {
34 if (!m_pFontMgr)
35 return nullptr;
36
37 uint32_t dwStyle = 0;
38 if (weight >= 700)
39 dwStyle |= FXFONT_BOLD;
40 if (bItalic)
41 dwStyle |= FXFONT_ITALIC;
42 if (FontFamilyIsFixedPitch(pitch_family))
43 dwStyle |= FXFONT_FIXED_PITCH;
44 if (FontFamilyIsScript(pitch_family))
45 dwStyle |= FXFONT_SCRIPT;
46 if (FontFamilyIsRoman(pitch_family))
47 dwStyle |= FXFONT_SERIF;
48 return m_pFontMgr->CreateFont(face, charset, dwStyle,
49 FPF_MATCHFONT_REPLACEANSI);
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,uint8_t * buffer,uint32_t size)56 uint32_t CFX_AndroidFontInfo::GetFontData(void* hFont,
57 uint32_t table,
58 uint8_t* buffer,
59 uint32_t size) {
60 if (!hFont)
61 return 0;
62 return static_cast<CFPF_SkiaFont*>(hFont)->GetFontData(table, buffer, size);
63 }
64
GetFaceName(void * hFont,ByteString * name)65 bool CFX_AndroidFontInfo::GetFaceName(void* hFont, ByteString* name) {
66 if (!hFont)
67 return false;
68
69 *name = static_cast<CFPF_SkiaFont*>(hFont)->GetFamilyName();
70 return true;
71 }
72
GetFontCharset(void * hFont,int * charset)73 bool CFX_AndroidFontInfo::GetFontCharset(void* hFont, int* charset) {
74 if (!hFont)
75 return false;
76
77 *charset = static_cast<CFPF_SkiaFont*>(hFont)->GetCharset();
78 return false;
79 }
80
DeleteFont(void * hFont)81 void CFX_AndroidFontInfo::DeleteFont(void* hFont) {
82 if (!hFont)
83 return;
84
85 static_cast<CFPF_SkiaFont*>(hFont)->Release();
86 }
87