1 // Copyright 2014 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 #ifndef CORE_SRC_FXGE_ANDROID_FPF_SKIAFONTMGR_H_
8 #define CORE_SRC_FXGE_ANDROID_FPF_SKIAFONTMGR_H_
9 
10 #if _FX_OS_ == _FX_ANDROID_
11 #define FPF_SKIAFONTTYPE_Unknown	0
12 #define	FPF_SKIAFONTTYPE_Path		1
13 #define FPF_SKIAFONTTYPE_File		2
14 #define FPF_SKIAFONTTYPE_Buffer		3
15 class CFPF_SkiaFontDescriptor
16 {
17 public:
CFPF_SkiaFontDescriptor()18     CFPF_SkiaFontDescriptor() : m_pFamily(NULL), m_dwStyle(0), m_iFaceIndex(0), m_dwCharsets(0), m_iGlyphNum(0) {}
~CFPF_SkiaFontDescriptor()19     virtual ~CFPF_SkiaFontDescriptor()
20     {
21         if (m_pFamily) {
22             FX_Free(m_pFamily);
23         }
24     }
GetType()25     virtual	FX_INT32	GetType() const
26     {
27         return FPF_SKIAFONTTYPE_Unknown;
28     }
SetFamily(FX_LPCSTR pFamily)29     void				SetFamily(FX_LPCSTR pFamily)
30     {
31         if (m_pFamily) {
32             FX_Free(m_pFamily);
33         }
34         FX_INT32 iSize = FXSYS_strlen(pFamily);
35         m_pFamily = FX_Alloc(FX_CHAR, iSize + 1);
36         FXSYS_memcpy32(m_pFamily, pFamily, iSize * sizeof(FX_CHAR));
37         m_pFamily[iSize] = 0;
38     }
39     FX_LPSTR		m_pFamily;
40     FX_DWORD		m_dwStyle;
41     FX_INT32		m_iFaceIndex;
42     FX_DWORD		m_dwCharsets;
43     FX_INT32		m_iGlyphNum;
44 };
45 class CFPF_SkiaPathFont : public CFPF_SkiaFontDescriptor
46 {
47 public:
CFPF_SkiaPathFont()48     CFPF_SkiaPathFont() : m_pPath(NULL) {}
~CFPF_SkiaPathFont()49     virtual ~CFPF_SkiaPathFont()
50     {
51         if (m_pPath) {
52             FX_Free(m_pPath);
53         }
54     }
GetType()55     virtual	FX_INT32	GetType() const
56     {
57         return FPF_SKIAFONTTYPE_Path;
58     }
SetPath(FX_LPCSTR pPath)59     void				SetPath(FX_LPCSTR pPath)
60     {
61         if (m_pPath) {
62             FX_Free(m_pPath);
63         }
64         FX_INT32 iSize = FXSYS_strlen(pPath);
65         m_pPath = FX_Alloc(FX_CHAR, iSize + 1);
66         FXSYS_memcpy32(m_pPath, pPath, iSize * sizeof(FX_CHAR));
67         m_pPath[iSize] = 0;
68     }
69     FX_LPSTR		m_pPath;
70 };
71 class CFPF_SkiaFileFont : public CFPF_SkiaFontDescriptor
72 {
73 public:
CFPF_SkiaFileFont()74     CFPF_SkiaFileFont() : m_pFile(NULL) {}
GetType()75     virtual FX_INT32	GetType() const
76     {
77         return FPF_SKIAFONTTYPE_File;
78     }
79     IFX_FileRead		*m_pFile;
80 };
81 class CFPF_SkiaBufferFont : public CFPF_SkiaFontDescriptor
82 {
83 public:
CFPF_SkiaBufferFont()84     CFPF_SkiaBufferFont() : m_pBuffer(NULL), m_szBuffer(0) {}
GetType()85     virtual FX_INT32	GetType() const
86     {
87         return FPF_SKIAFONTTYPE_Buffer;
88     }
89     FX_LPVOID			m_pBuffer;
90     size_t				m_szBuffer;
91 };
92 class CFPF_SkiaFontMgr : public IFPF_FontMgr
93 {
94 public:
95     CFPF_SkiaFontMgr();
96     virtual ~CFPF_SkiaFontMgr();
97     FX_BOOL					InitFTLibrary();
98     virtual void			LoadSystemFonts();
99     virtual void			LoadPrivateFont(IFX_FileRead* pFontFile);
100     virtual void			LoadPrivateFont(FX_BSTR bsFileName);
101     virtual void			LoadPrivateFont(FX_LPVOID pBuffer, size_t szBuffer);
102 
103     virtual IFPF_Font*		CreateFont(FX_BSTR bsFamilyname, FX_BYTE uCharset, FX_DWORD dwStyle, FX_DWORD dwMatch = 0);
104     FXFT_Face				GetFontFace(IFX_FileRead *pFileRead, FX_INT32 iFaceIndex = 0);
105     FXFT_Face				GetFontFace(FX_BSTR bsFile, FX_INT32 iFaceIndex = 0);
106     FXFT_Face				GetFontFace(FX_LPCBYTE pBuffer, size_t szBuffer, FX_INT32 iFaceIndex = 0);
107 protected:
108     void				ScanPath(FX_BSTR path);
109     void				ScanFile(FX_BSTR file);
110     void				ReportFace(FXFT_Face face, CFPF_SkiaFontDescriptor *pFontDesc);
111     void				OutputSystemFonts();
112     FX_BOOL				m_bLoaded;
113     CFX_PtrArray		m_FontFaces;
114     FXFT_Library		m_FTLibrary;
115     CFX_MapPtrToPtr		m_FamilyFonts;
116 };
117 #endif
118 
119 #endif  // CORE_SRC_FXGE_ANDROID_FPF_SKIAFONTMGR_H_
120