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_TEXTOBJECT_H_ 8 #define CORE_FPDFAPI_PAGE_CPDF_TEXTOBJECT_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "core/fpdfapi/page/cpdf_pageobject.h" 14 #include "core/fxcrt/fx_string.h" 15 #include "core/fxcrt/fx_system.h" 16 17 class CPDF_TextObjectItem { 18 public: 19 CPDF_TextObjectItem(); 20 ~CPDF_TextObjectItem(); 21 22 uint32_t m_CharCode; 23 CFX_PointF m_Origin; 24 }; 25 26 class CPDF_TextObject : public CPDF_PageObject { 27 public: 28 CPDF_TextObject(); 29 ~CPDF_TextObject() override; 30 31 // CPDF_PageObject 32 Type GetType() const override; 33 void Transform(const CFX_Matrix& matrix) override; 34 bool IsText() const override; 35 CPDF_TextObject* AsText() override; 36 const CPDF_TextObject* AsText() const override; 37 38 std::unique_ptr<CPDF_TextObject> Clone() const; 39 int CountItems() const; 40 void GetItemInfo(int index, CPDF_TextObjectItem* pInfo) const; 41 int CountChars() const; 42 void GetCharInfo(int index, uint32_t* charcode, FX_FLOAT* kerning) const; 43 void GetCharInfo(int index, CPDF_TextObjectItem* pInfo) const; 44 FX_FLOAT GetCharWidth(uint32_t charcode) const; 45 CFX_PointF GetPos() const { return m_Pos; } 46 CFX_Matrix GetTextMatrix() const; 47 CPDF_Font* GetFont() const; 48 FX_FLOAT GetFontSize() const; 49 50 void SetText(const CFX_ByteString& text); 51 void SetPosition(FX_FLOAT x, FX_FLOAT y); 52 53 void RecalcPositionData(); 54 55 private: 56 friend class CPDF_RenderStatus; 57 friend class CPDF_StreamContentParser; 58 friend class CPDF_TextRenderer; 59 friend class CPDF_PageContentGenerator; 60 61 void SetSegments(const CFX_ByteString* pStrs, 62 const FX_FLOAT* pKerning, 63 int nSegs); 64 65 CFX_PointF CalcPositionData(FX_FLOAT horz_scale); 66 67 CFX_PointF m_Pos; 68 std::vector<uint32_t> m_CharCodes; 69 std::vector<FX_FLOAT> m_CharPos; 70 }; 71 72 #endif // CORE_FPDFAPI_PAGE_CPDF_TEXTOBJECT_H_ 73