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