Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: core/fpdfdoc/pdf_vt.h

Issue 1919283008: Remove unneeded CPVT classes. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfdoc/include/cpdf_variabletext.h ('k') | pdfium.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_PDF_VT_H_
8 #define CORE_FPDFDOC_PDF_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 CPVT_Size {
24 public:
25 CPVT_Size() : x(0.0f), y(0.0f) {}
26 CPVT_Size(FX_FLOAT other_x, FX_FLOAT other_y) {
27 x = other_x;
28 y = other_y;
29 }
30 FX_FLOAT x, y;
31 };
32
33 struct CPVT_FloatRange {
34 CPVT_FloatRange() : fMin(0.0f), fMax(0.0f) {}
35 CPVT_FloatRange(FX_FLOAT min, FX_FLOAT max) : fMin(min), fMax(max) {}
36 FX_FLOAT Range() const { return fMax - fMin; }
37 FX_FLOAT fMin, fMax;
38 };
39 template <class TYPE>
40 class CPVT_ArrayTemplate : public CFX_ArrayTemplate<TYPE> {
41 public:
42 FX_BOOL IsEmpty() { return CFX_ArrayTemplate<TYPE>::GetSize() <= 0; }
43 TYPE GetAt(int nIndex) const {
44 if (nIndex >= 0 && nIndex < CFX_ArrayTemplate<TYPE>::GetSize()) {
45 return CFX_ArrayTemplate<TYPE>::GetAt(nIndex);
46 }
47 return NULL;
48 }
49 void RemoveAt(int nIndex) {
50 if (nIndex >= 0 && nIndex < CFX_ArrayTemplate<TYPE>::GetSize()) {
51 CFX_ArrayTemplate<TYPE>::RemoveAt(nIndex);
52 }
53 }
54 };
55 class CLine {
56 public:
57 CLine();
58 virtual ~CLine();
59 CPVT_WordPlace GetBeginWordPlace() const;
60 CPVT_WordPlace GetEndWordPlace() const;
61 CPVT_WordPlace GetPrevWordPlace(const CPVT_WordPlace& place) const;
62 CPVT_WordPlace GetNextWordPlace(const CPVT_WordPlace& place) const;
63 CPVT_WordPlace LinePlace;
64 CPVT_LineInfo m_LineInfo;
65 };
66 class CLines {
67 public:
68 CLines() : m_nTotal(0) {}
69 virtual ~CLines() { RemoveAll(); }
70 int32_t GetSize() const { return m_Lines.GetSize(); }
71 CLine* GetAt(int32_t nIndex) const { return m_Lines.GetAt(nIndex); }
72 void Empty() { m_nTotal = 0; }
73 void RemoveAll() {
74 for (int32_t i = 0, sz = GetSize(); i < sz; i++) {
75 delete GetAt(i);
76 }
77 m_Lines.RemoveAll();
78 m_nTotal = 0;
79 }
80 int32_t Add(const CPVT_LineInfo& lineinfo) {
81 if (m_nTotal >= GetSize()) {
82 CLine* pLine = new CLine;
83 pLine->m_LineInfo = lineinfo;
84 m_Lines.Add(pLine);
85 } else if (CLine* pLine = GetAt(m_nTotal)) {
86 pLine->m_LineInfo = lineinfo;
87 }
88 return m_nTotal++;
89 }
90 void Clear() {
91 for (int32_t i = GetSize() - 1; i >= m_nTotal; i--) {
92 delete GetAt(i);
93 m_Lines.RemoveAt(i);
94 }
95 }
96
97 private:
98 CPVT_ArrayTemplate<CLine*> m_Lines;
99 int32_t m_nTotal;
100 };
101
102 class CPDF_EditContainer {
103 public:
104 CPDF_EditContainer() : m_rcPlate(0, 0, 0, 0), m_rcContent(0, 0, 0, 0) {}
105 virtual ~CPDF_EditContainer() {}
106 virtual void SetPlateRect(const CFX_FloatRect& rect) { m_rcPlate = rect; }
107 virtual const CFX_FloatRect& GetPlateRect() const { return m_rcPlate; }
108 virtual void SetContentRect(const CPVT_FloatRect& rect) {
109 m_rcContent = rect;
110 }
111 virtual CFX_FloatRect GetContentRect() const { return m_rcContent; }
112 FX_FLOAT GetPlateWidth() const { return m_rcPlate.right - m_rcPlate.left; }
113 FX_FLOAT GetPlateHeight() const { return m_rcPlate.top - m_rcPlate.bottom; }
114 CPVT_Size GetPlateSize() const {
115 return CPVT_Size(GetPlateWidth(), GetPlateHeight());
116 }
117 CFX_FloatPoint GetBTPoint() const {
118 return CFX_FloatPoint(m_rcPlate.left, m_rcPlate.top);
119 }
120 CFX_FloatPoint GetETPoint() const {
121 return CFX_FloatPoint(m_rcPlate.right, m_rcPlate.bottom);
122 }
123 inline CFX_FloatPoint InToOut(const CFX_FloatPoint& point) const {
124 return CFX_FloatPoint(point.x + GetBTPoint().x, GetBTPoint().y - point.y);
125 }
126 inline CFX_FloatPoint OutToIn(const CFX_FloatPoint& point) const {
127 return CFX_FloatPoint(point.x - GetBTPoint().x, GetBTPoint().y - point.y);
128 }
129 inline CFX_FloatRect InToOut(const CPVT_FloatRect& rect) const {
130 CFX_FloatPoint ptLeftTop = InToOut(CFX_FloatPoint(rect.left, rect.top));
131 CFX_FloatPoint ptRightBottom =
132 InToOut(CFX_FloatPoint(rect.right, rect.bottom));
133 return CFX_FloatRect(ptLeftTop.x, ptRightBottom.y, ptRightBottom.x,
134 ptLeftTop.y);
135 }
136 inline CPVT_FloatRect OutToIn(const CFX_FloatRect& rect) const {
137 CFX_FloatPoint ptLeftTop = OutToIn(CFX_FloatPoint(rect.left, rect.top));
138 CFX_FloatPoint ptRightBottom =
139 OutToIn(CFX_FloatPoint(rect.right, rect.bottom));
140 return CPVT_FloatRect(ptLeftTop.x, ptLeftTop.y, ptRightBottom.x,
141 ptRightBottom.y);
142 }
143
144 private:
145 CFX_FloatRect m_rcPlate;
146 CPVT_FloatRect m_rcContent;
147 };
148
149 #endif // CORE_FPDFDOC_PDF_VT_H_
OLDNEW
« no previous file with comments | « core/fpdfdoc/include/cpdf_variabletext.h ('k') | pdfium.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698