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 "core/fxcrt/retain_ptr.h" 11 #include "core/fxcrt/shared_copy_on_write.h" 12 #include "core/fxcrt/unowned_ptr.h" 13 #include "third_party/base/span.h" 14 15 class CPDF_Document; 16 class CPDF_Font; 17 18 // See PDF Reference 1.7, page 402, table 5.3. 19 enum class TextRenderingMode { 20 MODE_UNKNOWN = -1, 21 MODE_FILL = 0, 22 MODE_STROKE = 1, 23 MODE_FILL_STROKE = 2, 24 MODE_INVISIBLE = 3, 25 MODE_FILL_CLIP = 4, 26 MODE_STROKE_CLIP = 5, 27 MODE_FILL_STROKE_CLIP = 6, 28 MODE_CLIP = 7, 29 MODE_LAST = MODE_CLIP, 30 }; 31 32 class CPDF_TextState { 33 public: 34 CPDF_TextState(); 35 ~CPDF_TextState(); 36 37 void Emplace(); 38 39 RetainPtr<CPDF_Font> GetFont() const; 40 void SetFont(RetainPtr<CPDF_Font> pFont); 41 42 float GetFontSize() const; 43 void SetFontSize(float size); 44 45 pdfium::span<const float> GetMatrix() const; 46 pdfium::span<float> GetMutableMatrix(); 47 48 float GetCharSpace() const; 49 void SetCharSpace(float sp); 50 51 float GetWordSpace() const; 52 void SetWordSpace(float sp); 53 54 float GetFontSizeH() const; 55 56 TextRenderingMode GetTextMode() const; 57 void SetTextMode(TextRenderingMode mode); 58 59 pdfium::span<const float> GetCTM() const; 60 pdfium::span<float> GetMutableCTM(); 61 62 private: 63 class TextData final : public Retainable { 64 public: 65 CONSTRUCT_VIA_MAKE_RETAIN; 66 67 RetainPtr<TextData> Clone() const; 68 69 void SetFont(RetainPtr<CPDF_Font> pFont); 70 float GetFontSizeV() const; 71 float GetFontSizeH() const; 72 73 RetainPtr<CPDF_Font> m_pFont; 74 UnownedPtr<const CPDF_Document> m_pDocument; 75 float m_FontSize = 1.0f; 76 float m_CharSpace = 0.0f; 77 float m_WordSpace = 0.0f; 78 TextRenderingMode m_TextMode = TextRenderingMode::MODE_FILL; 79 float m_Matrix[4] = {1.0f, 0.0f, 0.0f, 1.0f}; 80 float m_CTM[4] = {1.0f, 0.0f, 0.0f, 1.0f}; 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