Merge to XFA: Make CFX_StockFontArray more robust.
[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 
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     CFX_MapByteStringToPtr      m_CMaps;
23     CPDF_CID2UnicodeMap*        m_CID2UnicodeMaps[6];
24 };
25 class CPDF_FontGlobals 
26 {
27 public:
28     CPDF_FontGlobals();
29     ~CPDF_FontGlobals();
30     void                                ClearAll();
31     void                                Clear(void* key);
32     CPDF_Font*                  Find(void* key, int index);
33     void                                Set(void* key, int index, CPDF_Font* pFont);
34     CPDF_CMapManager    m_CMapManager;
35     struct {
36         const struct FXCMAP_CMap*       m_pMapList;
37         int                             m_Count;
38     } m_EmbeddedCharsets[NUMBER_OF_CIDSETS];
39     struct {
40         const FX_WORD*  m_pMap;
41         int                             m_Count;
42     } m_EmbeddedToUnicodes[NUMBER_OF_CIDSETS];
43 private:
44     CFX_MapPtrToPtr             m_pStockMap;
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 
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 
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(FX_LPCSTR pString, int nStrLen, int& offset) const;
100     int                                         CountChar(FX_LPCSTR 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_CID2UnicodeMap 
143 {
144 public:
145     CPDF_CID2UnicodeMap();
146     ~CPDF_CID2UnicodeMap();
147     FX_BOOL             Initialize();
148     FX_BOOL             IsLoaded();
149     void                Load(CPDF_CMapManager* pMgr, int charset, FX_BOOL bPromptCJK);
150     FX_WCHAR    UnicodeFromCID(FX_WORD CID);
151 protected:
152     int                 m_Charset;
153     const FX_WORD*      m_pEmbeddedMap;
154     FX_DWORD    m_EmbeddedCount;
155 };
156 class CPDF_ToUnicodeMap 
157 {
158 public:
159     void                                        Load(CPDF_Stream* pStream);
160     CFX_WideString                      Lookup(FX_DWORD charcode);
161     FX_DWORD                            ReverseLookup(FX_WCHAR unicode);
162 protected:
163     CFX_CMapDWordToDWord        m_Map;
164     CPDF_CID2UnicodeMap*        m_pBaseMap;
165     CFX_WideTextBuf                     m_MultiCharBuf;
166 };
167 class CPDF_FontCharMap : public CFX_CharMap
168 {
169 public:
170     CPDF_FontCharMap(CPDF_Font* pFont);
171     CPDF_Font*          m_pFont;
172 };