• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The PDFium Authors
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_FPDFAPI_PAGE_CPDF_TEXTSTATE_H_
8 #define CORE_FPDFAPI_PAGE_CPDF_TEXTSTATE_H_
9 
10 #include <array>
11 
12 #include "core/fxcrt/retain_ptr.h"
13 #include "core/fxcrt/shared_copy_on_write.h"
14 #include "core/fxcrt/span.h"
15 #include "core/fxcrt/unowned_ptr.h"
16 
17 class CPDF_Document;
18 class CPDF_Font;
19 
20 // See PDF Reference 1.7, page 402, table 5.3.
21 enum class TextRenderingMode {
22   MODE_UNKNOWN = -1,
23   MODE_FILL = 0,
24   MODE_STROKE = 1,
25   MODE_FILL_STROKE = 2,
26   MODE_INVISIBLE = 3,
27   MODE_FILL_CLIP = 4,
28   MODE_STROKE_CLIP = 5,
29   MODE_FILL_STROKE_CLIP = 6,
30   MODE_CLIP = 7,
31   MODE_LAST = MODE_CLIP,
32 };
33 
34 class CPDF_TextState {
35  public:
36   CPDF_TextState();
37   CPDF_TextState(const CPDF_TextState& that);
38   CPDF_TextState& operator=(const CPDF_TextState& that);
39   ~CPDF_TextState();
40 
41   void Emplace();
42 
43   RetainPtr<CPDF_Font> GetFont() const;
44   void SetFont(RetainPtr<CPDF_Font> pFont);
45 
46   float GetFontSize() const;
47   void SetFontSize(float size);
48 
49   pdfium::span<const float> GetMatrix() const;
50   pdfium::span<float> GetMutableMatrix();
51 
52   float GetCharSpace() const;
53   void SetCharSpace(float sp);
54 
55   float GetWordSpace() const;
56   void SetWordSpace(float sp);
57 
58   float GetFontSizeH() const;
59 
60   TextRenderingMode GetTextMode() const;
61   void SetTextMode(TextRenderingMode mode);
62 
63   pdfium::span<const float> GetCTM() const;
64   pdfium::span<float> GetMutableCTM();
65 
66  private:
67   class TextData final : public Retainable {
68    public:
69     CONSTRUCT_VIA_MAKE_RETAIN;
70 
71     RetainPtr<TextData> Clone() const;
72 
73     void SetFont(RetainPtr<CPDF_Font> pFont);
74     float GetFontSizeV() const;
75     float GetFontSizeH() const;
76 
77     RetainPtr<CPDF_Font> font_;
78     UnownedPtr<const CPDF_Document> document_;
79     float font_size_ = 1.0f;
80     float char_space_ = 0.0f;
81     float word_space_ = 0.0f;
82     TextRenderingMode text_rendering_mode_ = TextRenderingMode::MODE_FILL;
83     std::array<float, 4> matrix_ = {1.0f, 0.0f, 0.0f, 1.0f};
84     std::array<float, 4> ctm_ = {1.0f, 0.0f, 0.0f, 1.0f};
85 
86    private:
87     TextData();
88     TextData(const TextData& that);
89     ~TextData() override;
90   };
91 
92   SharedCopyOnWrite<TextData> m_Ref;
93 };
94 
95 bool SetTextRenderingModeFromInt(int iMode, TextRenderingMode* mode);
96 bool TextRenderingModeIsClipMode(const TextRenderingMode& mode);
97 bool TextRenderingModeIsStrokeMode(const TextRenderingMode& mode);
98 
99 #endif  // CORE_FPDFAPI_PAGE_CPDF_TEXTSTATE_H_
100