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