• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
40   size_t CountItems() const;
41   void GetItemInfo(size_t index, CPDF_TextObjectItem* pInfo) const;
42 
43   size_t CountChars() const;
44   void GetCharInfo(size_t index, uint32_t* charcode, float* kerning) const;
45   void GetCharInfo(size_t index, CPDF_TextObjectItem* pInfo) const;
46   float GetCharWidth(uint32_t charcode) const;
47 
GetPos()48   CFX_PointF GetPos() const { return m_Pos; }
49   CFX_Matrix GetTextMatrix() const;
50   CPDF_Font* GetFont() const;
51   float GetFontSize() const;
52 
53   void SetText(const ByteString& text);
SetPosition(CFX_PointF pos)54   void SetPosition(CFX_PointF pos) { m_Pos = pos; }
55   void SetPosition(float x, float y);
56 
57   void RecalcPositionData();
58 
GetCharCodes()59   const std::vector<uint32_t>& GetCharCodes() const { return m_CharCodes; }
GetCharPositions()60   const std::vector<float>& GetCharPositions() const { return m_CharPos; }
61 
62   void SetSegments(const ByteString* pStrs, const float* pKerning, int nSegs);
63   CFX_PointF CalcPositionData(float horz_scale);
64 
65  private:
66   CFX_PointF m_Pos;
67   std::vector<uint32_t> m_CharCodes;
68   std::vector<float> m_CharPos;
69 };
70 
71 #endif  // CORE_FPDFAPI_PAGE_CPDF_TEXTOBJECT_H_
72