XFA: merge patch from issue 801913002 and 804463003
[pdfium.git] / core / src / fpdfapi / fpdf_font / font_int.h
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 typedef void* FXFT_Library;
8 class CPDF_CMapManager : public CFX_Object
9 {
10 public:
11     CPDF_CMapManager();
12     ~CPDF_CMapManager();
13     FX_LPVOID                           GetPackage(FX_BOOL bPrompt);
14     CPDF_CMap*                          GetPredefinedCMap(const CFX_ByteString& name, FX_BOOL bPrompt);
15     CPDF_CID2UnicodeMap*        GetCID2UnicodeMap(int charset, FX_BOOL bPrompt);
16     void                                        ReloadAll();
17 private:
18     CPDF_CMap*                          LoadPredefinedCMap(const CFX_ByteString& name,  FX_BOOL bPrompt);
19     CPDF_CID2UnicodeMap*        LoadCID2UnicodeMap(int charset, FX_BOOL bPrompt);
20     void                                        DropAll(FX_BOOL bReload);
21     FX_BOOL                                     m_bPrompted;
22     FX_LPVOID                           m_pPackage;
23     CFX_MapByteStringToPtr      m_CMaps;
24     CPDF_CID2UnicodeMap*        m_CID2UnicodeMaps[6];
25 };
26 class CPDF_FontGlobals : public CFX_Object
27 {
28 public:
29     CPDF_FontGlobals();
30     ~CPDF_FontGlobals();
31     void                                ClearAll();
32     void                                Clear(void* key);
33     CPDF_Font*                  Find(void* key, int index);
34     void                                Set(void* key, int index, CPDF_Font* pFont);
35     CFX_MapPtrToPtr             m_pStockMap;
36     CPDF_CMapManager    m_CMapManager;
37     struct {
38         const struct FXCMAP_CMap*       m_pMapList;
39         int                             m_Count;
40     } m_EmbeddedCharsets[NUMBER_OF_CIDSETS];
41     struct {
42         const FX_WORD*  m_pMap;
43         int                             m_Count;
44     } m_EmbeddedToUnicodes[NUMBER_OF_CIDSETS];
45     FX_LPBYTE                   m_pContrastRamps;
46 };
47 struct _CMap_CodeRange {
48     int                 m_CharSize;
49     FX_BYTE             m_Lower[4];
50     FX_BYTE             m_Upper[4];
51 };
52 class CPDF_CMapParser : public CFX_Object
53 {
54 public:
55     CPDF_CMapParser();
56     ~CPDF_CMapParser() {}
57     FX_BOOL     Initialize(CPDF_CMap*);
58     void        ParseWord(FX_BSTR str);
59     CFX_BinaryBuf       m_AddMaps;
60 private:
61     CPDF_CMap*  m_pCMap;
62     int                         m_Status;
63     int                         m_CodeSeq;
64     FX_DWORD            m_CodePoints[4];
65     CFX_ArrayTemplate<_CMap_CodeRange>  m_CodeRanges;
66     CFX_ByteString      m_Registry, m_Ordering, m_Supplement;
67     CFX_ByteString      m_LastWord;
68 };
69 #define CIDCODING_UNKNOWN       0
70 #define CIDCODING_GB            1
71 #define CIDCODING_BIG5          2
72 #define CIDCODING_JIS           3
73 #define CIDCODING_KOREA         4
74 #define CIDCODING_UCS2          5
75 #define CIDCODING_CID           6
76 #define CIDCODING_UTF16         7
77 class CPDF_CMap : public CFX_Object
78 {
79 public:
80     CPDF_CMap();
81     FX_BOOL                                     LoadPredefined(CPDF_CMapManager* pMgr, const FX_CHAR* name, FX_BOOL bPromptCJK);
82     FX_BOOL                                     LoadEmbedded(FX_LPCBYTE pData, FX_DWORD dwSize);
83     void                                        Release();
84     FX_BOOL                                     IsLoaded() const
85     {
86         return m_bLoaded;
87     }
88     int                                         GetCharset()
89     {
90         return m_Charset;
91     }
92     FX_BOOL                                     IsVertWriting() const
93     {
94         return m_bVertical;
95     }
96     FX_WORD                                     CIDFromCharCode(FX_DWORD charcode) const;
97     FX_DWORD                            CharCodeFromCID(FX_WORD CID) const;
98     int                                         GetCharSize(FX_DWORD charcode) const;
99     FX_DWORD                            GetNextChar(const FX_CHAR* pString, int& offset) const;
100     int                                         CountChar(const FX_CHAR* pString, int size) const;
101     int                                         AppendChar(FX_LPSTR str, FX_DWORD charcode) const;
102     typedef enum {OneByte, TwoBytes, MixedTwoBytes, MixedFourBytes} CodingScheme;
103 protected:
104     ~CPDF_CMap();
105     friend class                        CPDF_CMapParser;
106     friend class                        CPDF_CMapManager;
107     friend class                        CPDF_CIDFont;
108 protected:
109     CFX_ByteString                      m_PredefinedCMap;
110     FX_BOOL                                     m_bVertical;
111     int                                         m_Charset, m_Coding;
112     CodingScheme                        m_CodingScheme;
113     int                                         m_nCodeRanges;
114     FX_BYTE*                            m_pLeadingBytes;
115     FX_WORD*                            m_pMapping;
116     FX_LPBYTE                           m_pAddMapping;
117     FX_BOOL                                     m_bLoaded;
118     const FXCMAP_CMap*          m_pEmbedMap;
119     CPDF_CMap*                          m_pUseMap;
120 };
121 class CPDF_PredefinedCMap
122 {
123 public:
124     FX_LPCSTR   m_pName;
125     int                 m_Charset;
126     int                 m_Coding;
127     CPDF_CMap::CodingScheme     m_CodingScheme;
128     FX_DWORD    m_LeadingSegCount;
129     FX_BYTE             m_LeadingSegs[4];
130 };
131 typedef struct _FileHeader {
132     FX_BYTE             btTag[4];
133     FX_BYTE             btVersion;
134     FX_BYTE             btFormat;
135     FX_BYTE             btReserved1[2];
136     FX_DWORD    dwStartIndex;
137     FX_DWORD    dwEndIndex;
138     FX_DWORD    dwDataSize;
139     FX_DWORD    dwDataOffset;
140     FX_DWORD    dwRecordSize;
141 } FXMP_FILEHEADER;
142 class CPDF_FXMP : public CFX_Object
143 {
144 public:
145     CPDF_FXMP()
146     {
147         m_pHeader = NULL;
148         m_pTable = NULL;
149     }
150     ~CPDF_FXMP()
151     {
152         if (m_pHeader) {
153             FX_Free(m_pHeader);
154         }
155     }
156     FX_BOOL             IsLoaded()
157     {
158         return m_pTable != NULL;
159     }
160     FX_BOOL             LoadFile(FX_LPVOID pPackage, FX_LPCSTR fileid);
161     FX_LPBYTE   GetRecord(FX_DWORD index);
162 private:
163     FXMP_FILEHEADER*    m_pHeader;
164     FX_LPBYTE   m_pTable;
165 };
166 class CPDF_CID2UnicodeMap : public CFX_Object
167 {
168 public:
169     CPDF_CID2UnicodeMap();
170     ~CPDF_CID2UnicodeMap();
171     FX_BOOL             Initialize();
172     FX_BOOL             IsLoaded();
173     void                Load(CPDF_CMapManager* pMgr, int charset, FX_BOOL bPromptCJK);
174     FX_WCHAR    UnicodeFromCID(FX_WORD CID);
175 protected:
176     int                 m_Charset;
177     const FX_WORD*      m_pEmbeddedMap;
178     FX_DWORD    m_EmbeddedCount;
179     CPDF_FXMP*  m_pExternalMap;
180 };
181 class CPDF_ToUnicodeMap : public CFX_Object
182 {
183 public:
184     void                                        Load(CPDF_Stream* pStream);
185     CFX_WideString                      Lookup(FX_DWORD charcode);
186     FX_DWORD                            ReverseLookup(FX_WCHAR unicode);
187 protected:
188     CFX_CMapDWordToDWord        m_Map;
189     CPDF_CID2UnicodeMap*        m_pBaseMap;
190     CFX_WideTextBuf                     m_MultiCharBuf;
191 };
192 class CPDF_FontCharMap : public CFX_CharMap, public CFX_Object
193 {
194 public:
195     CPDF_FontCharMap(CPDF_Font* pFont);
196     CPDF_Font*          m_pFont;
197 };