summaryrefslogtreecommitdiff
path: root/core/include/fpdfdoc/fpdf_ap.h
blob: 510b39cb9b9cd82ca81bca34674a585033dab3fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef CORE_INCLUDE_FPDFDOC_FPDF_AP_H_
#define CORE_INCLUDE_FPDFDOC_FPDF_AP_H_

#include "core/include/fpdfapi/fpdf_parser.h"
#include "fpdf_vt.h"

class IPVT_FontMap {
 public:
  virtual ~IPVT_FontMap() {}
  virtual CPDF_Font* GetPDFFont(int32_t nFontIndex) = 0;
  virtual CFX_ByteString GetPDFFontAlias(int32_t nFontIndex) = 0;
};

struct CPVT_Dash {
  CPVT_Dash(int32_t dash, int32_t gap, int32_t phase)
      : nDash(dash), nGap(gap), nPhase(phase) {}

  int32_t nDash;
  int32_t nGap;
  int32_t nPhase;
};

struct CPVT_Color {
  enum Type { kTransparent = 0, kGray, kRGB, kCMYK };

  CPVT_Color(Type type = kTransparent,
             FX_FLOAT color1 = 0.0f,
             FX_FLOAT color2 = 0.0f,
             FX_FLOAT color3 = 0.0f,
             FX_FLOAT color4 = 0.0f)
      : nColorType(type),
        fColor1(color1),
        fColor2(color2),
        fColor3(color3),
        fColor4(color4) {}

  Type nColorType;
  FX_FLOAT fColor1;
  FX_FLOAT fColor2;
  FX_FLOAT fColor3;
  FX_FLOAT fColor4;
};

class CPVT_Provider : public IPDF_VariableText_Provider {
 public:
  CPVT_Provider(IPVT_FontMap* pFontMap);
  ~CPVT_Provider() override;

  // IPDF_VariableText_Provider
  int32_t GetCharWidth(int32_t nFontIndex,
                       FX_WORD word,
                       int32_t nWordStyle) override;
  int32_t GetTypeAscent(int32_t nFontIndex) override;
  int32_t GetTypeDescent(int32_t nFontIndex) override;
  int32_t GetWordFontIndex(FX_WORD word,
                           int32_t charset,
                           int32_t nFontIndex) override;
  FX_BOOL IsLatinWord(FX_WORD word) override;
  int32_t GetDefaultFontIndex() override;

 private:
  IPVT_FontMap* m_pFontMap;
};

class CPVT_GenerateAP {
 public:
  static FX_BOOL GenerateTextFieldAP(CPDF_Document* pDoc,
                                     CPDF_Dictionary* pAnnotDict);

  static FX_BOOL GenerateComboBoxAP(CPDF_Document* pDoc,
                                    CPDF_Dictionary* pAnnotDict);

  static FX_BOOL GenerateListBoxAP(CPDF_Document* pDoc,
                                   CPDF_Dictionary* pAnnotDict);

  static CFX_ByteString GenerateEditAP(IPVT_FontMap* pFontMap,
                                       IPDF_VariableText_Iterator* pIterator,
                                       const CPDF_Point& ptOffset,
                                       FX_BOOL bContinuous,
                                       FX_WORD SubWord = 0,
                                       const CPVT_WordRange* pVisible = NULL);

  static CFX_ByteString GenerateBorderAP(const CPDF_Rect& rect,
                                         FX_FLOAT fWidth,
                                         const CPVT_Color& color,
                                         const CPVT_Color& crLeftTop,
                                         const CPVT_Color& crRightBottom,
                                         int32_t nStyle,
                                         const CPVT_Dash& dash);

  static CFX_ByteString GenerateColorAP(const CPVT_Color& color,
                                        const FX_BOOL& bFillOrStroke);
};

#endif  // CORE_INCLUDE_FPDFDOC_FPDF_AP_H_