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 _PWL_FONTMAP_H_ 8 #define _PWL_FONTMAP_H_ 9 10 struct CPWL_FontMap_Data 11 { 12 CPDF_Font* pFont; 13 FX_INT32 nCharset; 14 CFX_ByteString sFontName; 15 }; 16 17 struct CPWL_FontMap_Native 18 { 19 FX_INT32 nCharset; 20 CFX_ByteString sFontName; 21 }; 22 23 #ifndef ANSI_CHARSET 24 25 #define ANSI_CHARSET 0 26 #define DEFAULT_CHARSET 1 27 #define SYMBOL_CHARSET 2 28 #define SHIFTJIS_CHARSET 128 29 #define HANGEUL_CHARSET 129 30 #define HANGUL_CHARSET 129 31 #define GB2312_CHARSET 134 32 #define CHINESEBIG5_CHARSET 136 33 #define OEM_CHARSET 255 34 #define JOHAB_CHARSET 130 35 #define HEBREW_CHARSET 177 36 #define ARABIC_CHARSET 178 37 #define GREEK_CHARSET 161 38 #define TURKISH_CHARSET 162 39 #define VIETNAMESE_CHARSET 163 40 #define THAI_CHARSET 222 41 #define EASTEUROPE_CHARSET 238 42 #define RUSSIAN_CHARSET 204 43 #define BALTIC_CHARSET 186 44 45 #endif 46 47 #ifndef PWL_CLASS 48 49 #ifdef FX_READER_DLL 50 #define PWL_CLASS __declspec(dllexport) 51 #else 52 #define PWL_CLASS 53 #endif 54 #endif 55 56 class IFX_SystemHandler; 57 class PWL_CLASS CPWL_FontMap : public IFX_Edit_FontMap 58 { 59 public: 60 CPWL_FontMap(IFX_SystemHandler* pSystemHandler); 61 virtual ~CPWL_FontMap(); 62 63 virtual CPDF_Font* GetPDFFont(FX_INT32 nFontIndex); 64 virtual CFX_ByteString GetPDFFontAlias(FX_INT32 nFontIndex); 65 virtual FX_INT32 GetWordFontIndex(FX_WORD word, FX_INT32 nCharset, FX_INT32 nFontIndex); 66 virtual FX_INT32 CharCodeFromUnicode(FX_INT32 nFontIndex, FX_WORD word); 67 virtual FX_INT32 CharSetFromUnicode(FX_WORD word, FX_INT32 nOldCharset); 68 69 public: 70 virtual void Initial(FX_LPCSTR fontname = NULL); 71 void SetSystemHandler(IFX_SystemHandler* pSystemHandler); 72 73 FX_INT32 GetFontMapCount() const; 74 const CPWL_FontMap_Data* GetFontMapData(FX_INT32 nIndex) const; 75 76 public: 77 static FX_INT32 GetNativeCharset(); 78 CFX_ByteString GetNativeFontName(FX_INT32 nCharset); 79 80 static CFX_ByteString GetDefaultFontByCharset(FX_INT32 nCharset); 81 82 CPDF_Font* AddFontToDocument(CPDF_Document* pDoc, CFX_ByteString& sFontName, FX_BYTE nCharset); 83 static FX_BOOL IsStandardFont(const CFX_ByteString& sFontName); 84 CPDF_Font* AddStandardFont(CPDF_Document* pDoc, CFX_ByteString& sFontName); 85 CPDF_Font* AddSystemFont(CPDF_Document* pDoc, CFX_ByteString& sFontName, 86 FX_BYTE nCharset); 87 88 protected: 89 virtual CPDF_Font* FindFontSameCharset(CFX_ByteString& sFontAlias, FX_INT32 nCharset); 90 virtual void AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias); 91 FX_BOOL KnowWord(FX_INT32 nFontIndex, FX_WORD word); 92 93 virtual CPDF_Document* GetDocument(); 94 95 void Empty(); 96 FX_INT32 GetFontIndex(const CFX_ByteString& sFontName, FX_INT32 nCharset, FX_BOOL bFind); 97 FX_INT32 GetPWLFontIndex(FX_WORD word, FX_INT32 nCharset); 98 FX_INT32 AddFontData(CPDF_Font* pFont, const CFX_ByteString& sFontAlias, FX_INT32 nCharset = DEFAULT_CHARSET); 99 100 CFX_ByteString EncodeFontAlias(const CFX_ByteString& sFontName, FX_INT32 nCharset); 101 CFX_ByteString EncodeFontAlias(const CFX_ByteString& sFontName); 102 103 private: 104 CFX_ByteString GetFontName(FX_INT32 nFontIndex); 105 FX_INT32 FindFont(const CFX_ByteString& sFontName, FX_INT32 nCharset = DEFAULT_CHARSET); 106 107 CFX_ByteString GetNativeFont(FX_INT32 nCharset); 108 109 public: 110 struct CharsetFontMap { 111 FX_INT32 charset; 112 const char* fontname; 113 }; 114 static const CharsetFontMap defaultTTFMap[]; 115 116 protected: 117 CFX_ArrayTemplate<CPWL_FontMap_Data*> m_aData; 118 CFX_ArrayTemplate<CPWL_FontMap_Native*> m_aNativeFont; 119 120 private: 121 CPDF_Document* m_pPDFDoc; 122 IFX_SystemHandler* m_pSystemHandler; 123 }; 124 125 class PWL_CLASS CPWL_DocFontMap : public CPWL_FontMap 126 { 127 public: 128 CPWL_DocFontMap(IFX_SystemHandler* pSystemHandler, CPDF_Document* pAttachedDoc); 129 virtual ~CPWL_DocFontMap(); 130 131 virtual CPDF_Document* GetDocument(); 132 133 private: 134 CPDF_Document* m_pAttachedDoc; 135 }; 136 137 #endif 138