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_FPDFDOC_CPVT_SECTION_H_ 8 #define CORE_FPDFDOC_CPVT_SECTION_H_ 9 10 #include <stdint.h> 11 12 #include <memory> 13 #include <vector> 14 15 #include "core/fpdfdoc/cpvt_floatrect.h" 16 #include "core/fpdfdoc/cpvt_lineinfo.h" 17 #include "core/fpdfdoc/cpvt_wordinfo.h" 18 #include "core/fpdfdoc/cpvt_wordrange.h" 19 #include "core/fxcrt/fx_coordinates.h" 20 #include "core/fxcrt/unowned_ptr.h" 21 22 class CPVT_VariableText; 23 struct CPVT_LineInfo; 24 struct CPVT_WordPlace; 25 26 class CPVT_Section final { 27 public: 28 class Line { 29 public: 30 explicit Line(const CPVT_LineInfo& lineinfo); 31 ~Line(); 32 33 CPVT_WordPlace GetBeginWordPlace() const; 34 CPVT_WordPlace GetEndWordPlace() const; 35 CPVT_WordPlace GetPrevWordPlace(const CPVT_WordPlace& place) const; 36 CPVT_WordPlace GetNextWordPlace(const CPVT_WordPlace& place) const; 37 CPVT_WordPlace m_LinePlace; 38 CPVT_LineInfo m_LineInfo; 39 }; 40 41 explicit CPVT_Section(CPVT_VariableText* pVT); 42 ~CPVT_Section(); 43 44 void ResetLinePlace(); 45 CPVT_WordPlace AddWord(const CPVT_WordPlace& place, 46 const CPVT_WordInfo& wordinfo); 47 CPVT_WordPlace AddLine(const CPVT_LineInfo& lineinfo); 48 void ClearWords(const CPVT_WordRange& PlaceRange); 49 void ClearWord(const CPVT_WordPlace& place); 50 CPVT_FloatRect Rearrange(); 51 CFX_SizeF GetSectionSize(float fFontSize); 52 CPVT_WordPlace GetBeginWordPlace() const; 53 CPVT_WordPlace GetEndWordPlace() const; 54 CPVT_WordPlace GetPrevWordPlace(const CPVT_WordPlace& place) const; 55 CPVT_WordPlace GetNextWordPlace(const CPVT_WordPlace& place) const; 56 void UpdateWordPlace(CPVT_WordPlace& place) const; 57 CPVT_WordPlace SearchWordPlace(const CFX_PointF& point) const; 58 CPVT_WordPlace SearchWordPlace(float fx, 59 const CPVT_WordPlace& lineplace) const; 60 CPVT_WordPlace SearchWordPlace(float fx, const CPVT_WordRange& range) const; 61 SetPlace(const CPVT_WordPlace & place)62 void SetPlace(const CPVT_WordPlace& place) { m_SecPlace = place; } SetPlaceIndex(int32_t index)63 void SetPlaceIndex(int32_t index) { m_SecPlace.nSecIndex = index; } GetRect()64 const CPVT_FloatRect& GetRect() const { return m_Rect; } SetRect(const CPVT_FloatRect & rect)65 void SetRect(const CPVT_FloatRect& rect) { m_Rect = rect; } 66 67 int32_t GetLineArraySize() const; 68 const Line* GetLineFromArray(int32_t index) const; 69 int32_t GetWordArraySize() const; 70 const CPVT_WordInfo* GetWordFromArray(int32_t index) const; 71 void EraseWordsFrom(int32_t index); 72 73 private: 74 CPVT_FloatRect RearrangeCharArray() const; 75 CPVT_FloatRect RearrangeTypeset(); 76 CPVT_FloatRect SplitLines(bool bTypeset, float fFontSize); 77 CPVT_FloatRect OutputLines(const CPVT_FloatRect& rect) const; 78 79 void ClearLeftWords(int32_t nWordIndex); 80 void ClearRightWords(int32_t nWordIndex); 81 void ClearMidWords(int32_t nBeginIndex, int32_t nEndIndex); 82 83 CPVT_WordPlace m_SecPlace; 84 CPVT_FloatRect m_Rect; 85 std::vector<std::unique_ptr<Line>> m_LineArray; 86 std::vector<std::unique_ptr<CPVT_WordInfo>> m_WordArray; 87 UnownedPtr<CPVT_VariableText> const m_pVT; 88 }; 89 90 #endif // CORE_FPDFDOC_CPVT_SECTION_H_ 91