• 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 #include "core/fxcrt/retain_ptr.h"
17 
18 class CPDF_TextObjectItem {
19  public:
20   CPDF_TextObjectItem();
21   ~CPDF_TextObjectItem();
22 
23   uint32_t m_CharCode;
24   CFX_PointF m_Origin;
25 };
26 
27 class CPDF_TextObject final : public CPDF_PageObject {
28  public:
29   explicit CPDF_TextObject(int32_t content_stream);
30   CPDF_TextObject();
31   ~CPDF_TextObject() override;
32 
33   // CPDF_PageObject
34   Type GetType() const override;
35   void Transform(const CFX_Matrix& matrix) override;
36   bool IsText() const override;
37   CPDF_TextObject* AsText() override;
38   const CPDF_TextObject* AsText() const override;
39 
40   std::unique_ptr<CPDF_TextObject> Clone() const;
41 
42   size_t CountItems() const;
43   void GetItemInfo(size_t index, CPDF_TextObjectItem* pInfo) const;
44 
45   size_t CountChars() const;
46   void GetCharInfo(size_t index, uint32_t* charcode, float* kerning) const;
47   void GetCharInfo(size_t index, CPDF_TextObjectItem* pInfo) const;
48   float GetCharWidth(uint32_t charcode) const;
49   int CountWords() const;
50   WideString GetWordString(int nWordIndex) const;
51 
GetPos()52   CFX_PointF GetPos() const { return m_Pos; }
53   CFX_Matrix GetTextMatrix() const;
54 
55   RetainPtr<CPDF_Font> GetFont() const;
56   float GetFontSize() const;
57 
58   TextRenderingMode GetTextRenderMode() const;
59 
60   void SetText(const ByteString& str);
SetPosition(const CFX_PointF & pos)61   void SetPosition(const CFX_PointF& pos) { m_Pos = pos; }
62 
63   void RecalcPositionData();
64 
GetCharCodes()65   const std::vector<uint32_t>& GetCharCodes() const { return m_CharCodes; }
GetCharPositions()66   const std::vector<float>& GetCharPositions() const { return m_CharPos; }
67 
68   void SetSegments(const ByteString* pStrs,
69                    const std::vector<float>& kernings,
70                    size_t nSegs);
71   CFX_PointF CalcPositionData(float horz_scale);
72 
73  private:
74   CFX_PointF m_Pos;
75   std::vector<uint32_t> m_CharCodes;
76   std::vector<float> m_CharPos;
77 };
78 
79 #endif  // CORE_FPDFAPI_PAGE_CPDF_TEXTOBJECT_H_
80