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