| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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_FPDFDOC_DOC_VT_H_ | |
| 8 #define CORE_FPDFDOC_DOC_VT_H_ | |
| 9 | |
| 10 #include "core/fpdfdoc/cpvt_floatrect.h" | |
| 11 #include "core/fpdfdoc/cpvt_lineinfo.h" | |
| 12 #include "core/fpdfdoc/include/cpvt_wordrange.h" | |
| 13 | |
| 14 class CPDF_VariableText; | |
| 15 | |
| 16 struct CPVT_WordInfo; | |
| 17 | |
| 18 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) | |
| 19 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) | |
| 20 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) | |
| 21 #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) | |
| 22 | |
| 23 class CLine { | |
| 24 public: | |
| 25 CLine(); | |
| 26 ~CLine(); | |
| 27 | |
| 28 CPVT_WordPlace GetBeginWordPlace() const; | |
| 29 CPVT_WordPlace GetEndWordPlace() const; | |
| 30 CPVT_WordPlace GetPrevWordPlace(const CPVT_WordPlace& place) const; | |
| 31 CPVT_WordPlace GetNextWordPlace(const CPVT_WordPlace& place) const; | |
| 32 CPVT_WordPlace LinePlace; | |
| 33 CPVT_LineInfo m_LineInfo; | |
| 34 }; | |
| 35 | |
| 36 class CLines { | |
| 37 public: | |
| 38 CLines() : m_nTotal(0) {} | |
| 39 ~CLines() { RemoveAll(); } | |
| 40 | |
| 41 int32_t GetSize() const { return m_Lines.GetSize(); } | |
| 42 CLine* GetAt(int32_t nIndex) const { return m_Lines.GetAt(nIndex); } | |
| 43 void Empty() { m_nTotal = 0; } | |
| 44 void RemoveAll() { | |
| 45 for (int32_t i = 0, sz = GetSize(); i < sz; i++) { | |
| 46 delete GetAt(i); | |
| 47 } | |
| 48 m_Lines.RemoveAll(); | |
| 49 m_nTotal = 0; | |
| 50 } | |
| 51 int32_t Add(const CPVT_LineInfo& lineinfo) { | |
| 52 if (m_nTotal >= GetSize()) { | |
| 53 CLine* pLine = new CLine; | |
| 54 pLine->m_LineInfo = lineinfo; | |
| 55 m_Lines.Add(pLine); | |
| 56 } else if (CLine* pLine = GetAt(m_nTotal)) { | |
| 57 pLine->m_LineInfo = lineinfo; | |
| 58 } | |
| 59 return m_nTotal++; | |
| 60 } | |
| 61 void Clear() { | |
| 62 for (int32_t i = GetSize() - 1; i >= m_nTotal; i--) { | |
| 63 delete GetAt(i); | |
| 64 m_Lines.RemoveAt(i); | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 private: | |
| 69 CFX_ArrayTemplate<CLine*> m_Lines; | |
| 70 int32_t m_nTotal; | |
| 71 }; | |
| 72 | |
| 73 class CPDF_EditContainer { | |
| 74 public: | |
| 75 CPDF_EditContainer(); | |
| 76 virtual ~CPDF_EditContainer(); | |
| 77 | |
| 78 virtual const CFX_FloatRect& GetPlateRect() const { return m_rcPlate; } | |
| 79 virtual void SetPlateRect(const CFX_FloatRect& rect) { m_rcPlate = rect; } | |
| 80 virtual CFX_FloatRect GetContentRect() const { return m_rcContent; } | |
| 81 virtual void SetContentRect(const CPVT_FloatRect& rect) { | |
| 82 m_rcContent = rect; | |
| 83 } | |
| 84 | |
| 85 FX_FLOAT GetPlateWidth() const { return m_rcPlate.right - m_rcPlate.left; } | |
| 86 FX_FLOAT GetPlateHeight() const { return m_rcPlate.top - m_rcPlate.bottom; } | |
| 87 CFX_FloatPoint GetBTPoint() const { | |
| 88 return CFX_FloatPoint(m_rcPlate.left, m_rcPlate.top); | |
| 89 } | |
| 90 CFX_FloatPoint InToOut(const CFX_FloatPoint& point) const { | |
| 91 return CFX_FloatPoint(point.x + GetBTPoint().x, GetBTPoint().y - point.y); | |
| 92 } | |
| 93 CFX_FloatPoint OutToIn(const CFX_FloatPoint& point) const { | |
| 94 return CFX_FloatPoint(point.x - GetBTPoint().x, GetBTPoint().y - point.y); | |
| 95 } | |
| 96 CFX_FloatRect InToOut(const CPVT_FloatRect& rect) const; | |
| 97 | |
| 98 private: | |
| 99 CFX_FloatRect m_rcPlate; | |
| 100 CPVT_FloatRect m_rcContent; | |
| 101 }; | |
| 102 | |
| 103 #endif // CORE_FPDFDOC_DOC_VT_H_ | |
| OLD | NEW |