blob: f91d7e823f9052442e30520dae9fbd0744ec7887 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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 Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez19922bb2015-05-28 13:23:12 -07007#ifndef FPDFSDK_INCLUDE_PDFWINDOW_PWL_FONTMAP_H_
8#define FPDFSDK_INCLUDE_PDFWINDOW_PWL_FONTMAP_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Tom Sepez2a0bb3b2015-05-12 12:37:14 -070010#include "../../../public/fpdf_sysfontinfo.h"
Tom Sepez870292c2015-04-07 16:12:46 -070011#include "../fxedit/fx_edit.h"
12
13class CPDF_Document;
14class IFX_SystemHandler;
15
Nico Weber9d8ec5a2015-08-04 13:00:21 -070016struct CPWL_FontMap_Data {
17 CPDF_Font* pFont;
18 int32_t nCharset;
19 CFX_ByteString sFontName;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020};
21
Nico Weber9d8ec5a2015-08-04 13:00:21 -070022struct CPWL_FontMap_Native {
23 int32_t nCharset;
24 CFX_ByteString sFontName;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025};
26
27#ifndef ANSI_CHARSET
28
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029#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-Malek3f3b45c2014-05-23 17:28:10 -070048
49#endif
50
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051class CPWL_FontMap : public IFX_Edit_FontMap {
52 public:
53 CPWL_FontMap(IFX_SystemHandler* pSystemHandler);
Lei Zhang2b1a2d52015-08-14 22:16:22 -070054 ~CPWL_FontMap() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070055
Lei Zhang2b1a2d52015-08-14 22:16:22 -070056 // 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-Malek3f3b45c2014-05-23 17:28:10 -070064
Nico Weber9d8ec5a2015-08-04 13:00:21 -070065 void SetSystemHandler(IFX_SystemHandler* pSystemHandler);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066 int32_t GetFontMapCount() const;
67 const CPWL_FontMap_Data* GetFontMapData(int32_t nIndex) const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 static int32_t GetNativeCharset();
69 CFX_ByteString GetNativeFontName(int32_t nCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070070
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071 static CFX_ByteString GetDefaultFontByCharset(int32_t nCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073 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-Malek3f3b45c2014-05-23 17:28:10 -070081
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082 protected:
Lei Zhang2b1a2d52015-08-14 22:16:22 -070083 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-Malek3f3b45c2014-05-23 17:28:10 -070087
Lei Zhang2b1a2d52015-08-14 22:16:22 -070088 FX_BOOL KnowWord(int32_t nFontIndex, FX_WORD word);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070089
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 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-Malek3f3b45c2014-05-23 17:28:10 -070098
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099 CFX_ByteString EncodeFontAlias(const CFX_ByteString& sFontName,
100 int32_t nCharset);
101 CFX_ByteString EncodeFontAlias(const CFX_ByteString& sFontName);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700102
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103 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-Malek3f3b45c2014-05-23 17:28:10 -0700107
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 CFX_ByteString GetNativeFont(int32_t nCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 public:
111 using CharsetFontMap = FPDF_CharsetFontMap;
112 static const CharsetFontMap defaultTTFMap[];
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114 protected:
115 CFX_ArrayTemplate<CPWL_FontMap_Data*> m_aData;
116 CFX_ArrayTemplate<CPWL_FontMap_Native*> m_aNativeFont;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700117
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700118 private:
119 CPDF_Document* m_pPDFDoc;
120 IFX_SystemHandler* m_pSystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700121};
122
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123class CPWL_DocFontMap : public CPWL_FontMap {
124 public:
125 CPWL_DocFontMap(IFX_SystemHandler* pSystemHandler,
126 CPDF_Document* pAttachedDoc);
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700127 ~CPWL_DocFontMap() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700128
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129 virtual CPDF_Document* GetDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 private:
132 CPDF_Document* m_pAttachedDoc;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700133};
134
Tom Sepez19922bb2015-05-28 13:23:12 -0700135#endif // FPDFSDK_INCLUDE_PDFWINDOW_PWL_FONTMAP_H_