43452fdb47b8f655c2effdfe1fab0aadf41ac371
[pdfium.git] / core / include / fpdfdoc / fpdf_ap.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 #ifndef CORE_INCLUDE_FPDFDOC_FPDF_AP_H_
8 #define CORE_INCLUDE_FPDFDOC_FPDF_AP_H_
9
10 #include "../fpdfapi/fpdf_parser.h"
11 #include "fpdf_vt.h"
12
13 class IPVT_FontMap {
14  public:
15   virtual ~IPVT_FontMap() {}
16   virtual CPDF_Font* GetPDFFont(int32_t nFontIndex) = 0;
17   virtual CFX_ByteString GetPDFFontAlias(int32_t nFontIndex) = 0;
18 };
19 struct CPVT_Dash {
20   CPVT_Dash(int32_t dash, int32_t gap, int32_t phase)
21       : nDash(dash), nGap(gap), nPhase(phase) {}
22
23   int32_t nDash;
24
25   int32_t nGap;
26
27   int32_t nPhase;
28 };
29 #define CT_TRANSPARENT 0
30 #define CT_GRAY 1
31 #define CT_RGB 2
32 #define CT_CMYK 3
33 struct CPVT_Color {
34   CPVT_Color(int32_t type = 0,
35              FX_FLOAT color1 = 0.0f,
36              FX_FLOAT color2 = 0.0f,
37              FX_FLOAT color3 = 0.0f,
38              FX_FLOAT color4 = 0.0f)
39       : nColorType(type),
40         fColor1(color1),
41         fColor2(color2),
42         fColor3(color3),
43         fColor4(color4) {}
44
45   int32_t nColorType;
46   FX_FLOAT fColor1;
47   FX_FLOAT fColor2;
48   FX_FLOAT fColor3;
49   FX_FLOAT fColor4;
50 };
51 class CPVT_Provider : public IPDF_VariableText_Provider {
52  public:
53   CPVT_Provider(IPVT_FontMap* pFontMap);
54
55   virtual ~CPVT_Provider();
56
57   int32_t GetCharWidth(int32_t nFontIndex, FX_WORD word, int32_t nWordStyle);
58
59   int32_t GetTypeAscent(int32_t nFontIndex);
60
61   int32_t GetTypeDescent(int32_t nFontIndex);
62
63   int32_t GetWordFontIndex(FX_WORD word, int32_t charset, int32_t nFontIndex);
64
65   FX_BOOL IsLatinWord(FX_WORD word);
66
67   int32_t GetDefaultFontIndex();
68
69  private:
70   IPVT_FontMap* m_pFontMap;
71 };
72 #define PBS_SOLID 0
73 #define PBS_DASH 1
74 #define PBS_BEVELED 2
75 #define PBS_INSET 3
76 #define PBS_UNDERLINED 4
77 class CPVT_GenerateAP {
78  public:
79   static FX_BOOL GenerateTextFieldAP(CPDF_Document* pDoc,
80                                      CPDF_Dictionary* pAnnotDict);
81
82   static FX_BOOL GenerateComboBoxAP(CPDF_Document* pDoc,
83                                     CPDF_Dictionary* pAnnotDict);
84
85   static FX_BOOL GenerateListBoxAP(CPDF_Document* pDoc,
86                                    CPDF_Dictionary* pAnnotDict);
87
88   static CFX_ByteString GenerateEditAP(IPVT_FontMap* pFontMap,
89                                        IPDF_VariableText_Iterator* pIterator,
90                                        const CPDF_Point& ptOffset,
91                                        FX_BOOL bContinuous,
92                                        FX_WORD SubWord = 0,
93                                        const CPVT_WordRange* pVisible = NULL);
94
95   static CFX_ByteString GenerateBorderAP(const CPDF_Rect& rect,
96                                          FX_FLOAT fWidth,
97                                          const CPVT_Color& color,
98                                          const CPVT_Color& crLeftTop,
99                                          const CPVT_Color& crRightBottom,
100                                          int32_t nStyle,
101                                          const CPVT_Dash& dash);
102
103   static CFX_ByteString GenerateColorAP(const CPVT_Color& color,
104                                         const FX_BOOL& bFillOrStroke);
105 };
106
107 #endif  // CORE_INCLUDE_FPDFDOC_FPDF_AP_H_