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