John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 7 | #ifndef FPDFSDK_INCLUDE_PDFWINDOW_PWL_FONTMAP_H_ |
| 8 | #define FPDFSDK_INCLUDE_PDFWINDOW_PWL_FONTMAP_H_ |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 9 | |
Tom Sepez | 2a0bb3b | 2015-05-12 12:37:14 -0700 | [diff] [blame] | 10 | #include "../../../public/fpdf_sysfontinfo.h" |
Tom Sepez | 870292c | 2015-04-07 16:12:46 -0700 | [diff] [blame] | 11 | #include "../fxedit/fx_edit.h" |
| 12 | |
| 13 | class CPDF_Document; |
| 14 | class IFX_SystemHandler; |
| 15 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 16 | struct CPWL_FontMap_Data { |
| 17 | CPDF_Font* pFont; |
| 18 | int32_t nCharset; |
| 19 | CFX_ByteString sFontName; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 20 | }; |
| 21 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 22 | struct CPWL_FontMap_Native { |
| 23 | int32_t nCharset; |
| 24 | CFX_ByteString sFontName; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | #ifndef ANSI_CHARSET |
| 28 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 29 | #define ANSI_CHARSET 0 |
| 30 | #define DEFAULT_CHARSET 1 |
| 31 | #define SYMBOL_CHARSET 2 |
| 32 | #define SHIFTJIS_CHARSET 128 |
| 33 | #define HANGEUL_CHARSET 129 |
| 34 | #define HANGUL_CHARSET 129 |
| 35 | #define GB2312_CHARSET 134 |
| 36 | #define CHINESEBIG5_CHARSET 136 |
| 37 | #define OEM_CHARSET 255 |
| 38 | #define JOHAB_CHARSET 130 |
| 39 | #define HEBREW_CHARSET 177 |
| 40 | #define ARABIC_CHARSET 178 |
| 41 | #define GREEK_CHARSET 161 |
| 42 | #define TURKISH_CHARSET 162 |
| 43 | #define VIETNAMESE_CHARSET 163 |
| 44 | #define THAI_CHARSET 222 |
| 45 | #define EASTEUROPE_CHARSET 238 |
| 46 | #define RUSSIAN_CHARSET 204 |
| 47 | #define BALTIC_CHARSET 186 |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 48 | |
| 49 | #endif |
| 50 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 51 | class CPWL_FontMap : public IFX_Edit_FontMap { |
| 52 | public: |
| 53 | CPWL_FontMap(IFX_SystemHandler* pSystemHandler); |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 54 | ~CPWL_FontMap() override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 55 | |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 56 | // IFX_Edit_FontMap |
| 57 | CPDF_Font* GetPDFFont(int32_t nFontIndex) override; |
| 58 | CFX_ByteString GetPDFFontAlias(int32_t nFontIndex) override; |
| 59 | int32_t GetWordFontIndex(FX_WORD word, |
| 60 | int32_t nCharset, |
| 61 | int32_t nFontIndex) override; |
| 62 | int32_t CharCodeFromUnicode(int32_t nFontIndex, FX_WORD word) override; |
| 63 | int32_t CharSetFromUnicode(FX_WORD word, int32_t nOldCharset) override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 64 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | void SetSystemHandler(IFX_SystemHandler* pSystemHandler); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 66 | int32_t GetFontMapCount() const; |
| 67 | const CPWL_FontMap_Data* GetFontMapData(int32_t nIndex) const; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | static int32_t GetNativeCharset(); |
| 69 | CFX_ByteString GetNativeFontName(int32_t nCharset); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 70 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 71 | static CFX_ByteString GetDefaultFontByCharset(int32_t nCharset); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 72 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 73 | CPDF_Font* AddFontToDocument(CPDF_Document* pDoc, |
| 74 | CFX_ByteString& sFontName, |
| 75 | uint8_t nCharset); |
| 76 | static FX_BOOL IsStandardFont(const CFX_ByteString& sFontName); |
| 77 | CPDF_Font* AddStandardFont(CPDF_Document* pDoc, CFX_ByteString& sFontName); |
| 78 | CPDF_Font* AddSystemFont(CPDF_Document* pDoc, |
| 79 | CFX_ByteString& sFontName, |
| 80 | uint8_t nCharset); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 81 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 82 | protected: |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 83 | void Initial(const FX_CHAR* fontname = NULL); |
| 84 | CPDF_Document* GetDocument(); |
| 85 | CPDF_Font* FindFontSameCharset(CFX_ByteString& sFontAlias, int32_t nCharset); |
| 86 | void AddedFont(CPDF_Font* pFont, const CFX_ByteString& sFontAlias); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 87 | |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 88 | FX_BOOL KnowWord(int32_t nFontIndex, FX_WORD word); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 89 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | void Empty(); |
| 91 | int32_t GetFontIndex(const CFX_ByteString& sFontName, |
| 92 | int32_t nCharset, |
| 93 | FX_BOOL bFind); |
| 94 | int32_t GetPWLFontIndex(FX_WORD word, int32_t nCharset); |
| 95 | int32_t AddFontData(CPDF_Font* pFont, |
| 96 | const CFX_ByteString& sFontAlias, |
| 97 | int32_t nCharset = DEFAULT_CHARSET); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 98 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 99 | CFX_ByteString EncodeFontAlias(const CFX_ByteString& sFontName, |
| 100 | int32_t nCharset); |
| 101 | CFX_ByteString EncodeFontAlias(const CFX_ByteString& sFontName); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 102 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 103 | private: |
| 104 | CFX_ByteString GetFontName(int32_t nFontIndex); |
| 105 | int32_t FindFont(const CFX_ByteString& sFontName, |
| 106 | int32_t nCharset = DEFAULT_CHARSET); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 107 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 108 | CFX_ByteString GetNativeFont(int32_t nCharset); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 109 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 110 | public: |
| 111 | using CharsetFontMap = FPDF_CharsetFontMap; |
| 112 | static const CharsetFontMap defaultTTFMap[]; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 113 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 114 | protected: |
| 115 | CFX_ArrayTemplate<CPWL_FontMap_Data*> m_aData; |
| 116 | CFX_ArrayTemplate<CPWL_FontMap_Native*> m_aNativeFont; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 117 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 118 | private: |
| 119 | CPDF_Document* m_pPDFDoc; |
| 120 | IFX_SystemHandler* m_pSystemHandler; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 123 | class CPWL_DocFontMap : public CPWL_FontMap { |
| 124 | public: |
| 125 | CPWL_DocFontMap(IFX_SystemHandler* pSystemHandler, |
| 126 | CPDF_Document* pAttachedDoc); |
Lei Zhang | 2b1a2d5 | 2015-08-14 22:16:22 -0700 | [diff] [blame] | 127 | ~CPWL_DocFontMap() override; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 128 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 129 | virtual CPDF_Document* GetDocument(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 130 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 131 | private: |
| 132 | CPDF_Document* m_pAttachedDoc; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
Tom Sepez | 19922bb | 2015-05-28 13:23:12 -0700 | [diff] [blame] | 135 | #endif // FPDFSDK_INCLUDE_PDFWINDOW_PWL_FONTMAP_H_ |