• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TEXTOBJECT_H_
8 #define CORE_FPDFAPI_PAGE_CPDF_TEXTOBJECT_H_
9 
10 #include <stddef.h>
11 #include <stdint.h>
12 
13 #include <memory>
14 #include <vector>
15 
16 #include "core/fpdfapi/page/cpdf_pageobject.h"
17 #include "core/fxcrt/fx_coordinates.h"
18 #include "core/fxcrt/fx_string.h"
19 #include "core/fxcrt/retain_ptr.h"
20 #include "core/fxcrt/span.h"
21 
22 class CPDF_TextObject final : public CPDF_PageObject {
23  public:
24   struct Item {
25     Item();
26     Item(const Item& that);
27     ~Item();
28 
29     uint32_t m_CharCode = 0;
30     CFX_PointF m_Origin;
31   };
32 
33   explicit CPDF_TextObject(int32_t content_stream);
34   CPDF_TextObject();
35   ~CPDF_TextObject() override;
36 
37   // CPDF_PageObject:
38   Type GetType() const override;
39   void Transform(const CFX_Matrix& matrix) override;
40   bool IsText() const override;
41   CPDF_TextObject* AsText() override;
42   const CPDF_TextObject* AsText() const override;
43 
44   std::unique_ptr<CPDF_TextObject> Clone() const;
45 
46   size_t CountItems() const;
47   Item GetItemInfo(size_t index) const;
48 
49   size_t CountChars() const;
50   uint32_t GetCharCode(size_t index) const;
51   Item GetCharInfo(size_t index) const;
52   float GetCharWidth(uint32_t charcode) const;
53   int CountWords() const;
54   WideString GetWordString(int nWordIndex) const;
55 
GetPos()56   CFX_PointF GetPos() const { return m_Pos; }
57   CFX_Matrix GetTextMatrix() const;
58 
59   RetainPtr<CPDF_Font> GetFont() const;
60   float GetFontSize() const;
61 
62   TextRenderingMode GetTextRenderMode() const;
63   void SetTextRenderMode(TextRenderingMode mode);
64 
65   void SetText(const ByteString& str);
SetPosition(const CFX_PointF & pos)66   void SetPosition(const CFX_PointF& pos) { m_Pos = pos; }
67 
GetCharCodes()68   const std::vector<uint32_t>& GetCharCodes() const { return m_CharCodes; }
GetCharPositions()69   const std::vector<float>& GetCharPositions() const { return m_CharPos; }
70 
71   // Caller is expected to call SetDirty(true) when done changing the object.
72   void SetTextMatrix(const CFX_Matrix& matrix);
73 
74   void SetSegments(pdfium::span<const ByteString> strings,
75                    pdfium::span<const float> kernings);
76 
77   CFX_PointF CalcPositionData(float horz_scale);
78 
79  private:
80   float CalcPositionDataInternal(const RetainPtr<CPDF_Font>& pFont);
81 
82   CFX_PointF m_Pos;
83   std::vector<uint32_t> m_CharCodes;
84   std::vector<float> m_CharPos;
85 };
86 
87 #endif  // CORE_FPDFAPI_PAGE_CPDF_TEXTOBJECT_H_
88