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

Side by Side Diff: core/fpdfdoc/doc_vt.cpp

Issue 1947093002: Revert of Remove unneeded CPVT classes. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: 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/doc_vt.h ('k') | core/fpdfdoc/include/cpdf_variabletext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfdoc/doc_vt.h"
8
9 #include <algorithm> 7 #include <algorithm>
10 8
11 #include "core/fpdfdoc/cpvt_wordinfo.h" 9 #include "core/fpdfdoc/cpvt_wordinfo.h"
12 #include "core/fpdfdoc/csection.h" 10 #include "core/fpdfdoc/csection.h"
13 #include "core/fpdfdoc/include/cpdf_variabletext.h" 11 #include "core/fpdfdoc/include/cpdf_variabletext.h"
14 #include "core/fpdfdoc/include/fpdf_doc.h" 12 #include "core/fpdfdoc/include/fpdf_doc.h"
13 #include "core/fpdfdoc/pdf_vt.h"
15 14
16 CLine::CLine() {} 15 CLine::CLine() {}
17
18 CLine::~CLine() {} 16 CLine::~CLine() {}
19
20 CPVT_WordPlace CLine::GetBeginWordPlace() const { 17 CPVT_WordPlace CLine::GetBeginWordPlace() const {
21 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, -1); 18 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, -1);
22 } 19 }
23 CPVT_WordPlace CLine::GetEndWordPlace() const { 20 CPVT_WordPlace CLine::GetEndWordPlace() const {
24 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex, 21 return CPVT_WordPlace(LinePlace.nSecIndex, LinePlace.nLineIndex,
25 m_LineInfo.nEndWordIndex); 22 m_LineInfo.nEndWordIndex);
26 } 23 }
27 CPVT_WordPlace CLine::GetPrevWordPlace(const CPVT_WordPlace& place) const { 24 CPVT_WordPlace CLine::GetPrevWordPlace(const CPVT_WordPlace& place) const {
28 if (place.nWordIndex > m_LineInfo.nEndWordIndex) { 25 if (place.nWordIndex > m_LineInfo.nEndWordIndex) {
29 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, 26 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex,
(...skipping 27 matching lines...) Expand all
57 } 54 }
58 m_WordArray.RemoveAll(); 55 m_WordArray.RemoveAll();
59 } 56 }
60 void CSection::ResetLinePlace() { 57 void CSection::ResetLinePlace() {
61 for (int32_t i = 0, sz = m_LineArray.GetSize(); i < sz; i++) { 58 for (int32_t i = 0, sz = m_LineArray.GetSize(); i < sz; i++) {
62 if (CLine* pLine = m_LineArray.GetAt(i)) { 59 if (CLine* pLine = m_LineArray.GetAt(i)) {
63 pLine->LinePlace = CPVT_WordPlace(SecPlace.nSecIndex, i, -1); 60 pLine->LinePlace = CPVT_WordPlace(SecPlace.nSecIndex, i, -1);
64 } 61 }
65 } 62 }
66 } 63 }
67
68 CPVT_WordPlace CSection::AddWord(const CPVT_WordPlace& place, 64 CPVT_WordPlace CSection::AddWord(const CPVT_WordPlace& place,
69 const CPVT_WordInfo& wordinfo) { 65 const CPVT_WordInfo& wordinfo) {
70 CPVT_WordInfo* pWord = new CPVT_WordInfo(wordinfo); 66 CPVT_WordInfo* pWord = new CPVT_WordInfo(wordinfo);
71 int32_t nWordIndex = 67 int32_t nWordIndex =
72 std::max(std::min(place.nWordIndex, m_WordArray.GetSize()), 0); 68 std::max(std::min(place.nWordIndex, m_WordArray.GetSize()), 0);
73 if (nWordIndex == m_WordArray.GetSize()) 69 if (nWordIndex == m_WordArray.GetSize()) {
74 m_WordArray.Add(pWord); 70 m_WordArray.Add(pWord);
75 else 71 } else {
76 m_WordArray.InsertAt(nWordIndex, pWord); 72 m_WordArray.InsertAt(nWordIndex, pWord);
73 }
77 return place; 74 return place;
78 } 75 }
79
80 CPVT_WordPlace CSection::AddLine(const CPVT_LineInfo& lineinfo) { 76 CPVT_WordPlace CSection::AddLine(const CPVT_LineInfo& lineinfo) {
81 return CPVT_WordPlace(SecPlace.nSecIndex, m_LineArray.Add(lineinfo), -1); 77 return CPVT_WordPlace(SecPlace.nSecIndex, m_LineArray.Add(lineinfo), -1);
82 } 78 }
83
84 CPVT_FloatRect CSection::Rearrange() { 79 CPVT_FloatRect CSection::Rearrange() {
85 if (m_pVT->m_nCharArray > 0) 80 if (m_pVT->m_nCharArray > 0) {
86 return CTypeset(this).CharArray(); 81 return CTypeset(this).CharArray();
82 }
87 return CTypeset(this).Typeset(); 83 return CTypeset(this).Typeset();
88 } 84 }
89 85 CPVT_Size CSection::GetSectionSize(FX_FLOAT fFontSize) {
90 CFX_PointF CSection::GetSectionSize(FX_FLOAT fFontSize) {
91 return CTypeset(this).GetEditSize(fFontSize); 86 return CTypeset(this).GetEditSize(fFontSize);
92 } 87 }
93
94 CPVT_WordPlace CSection::GetBeginWordPlace() const { 88 CPVT_WordPlace CSection::GetBeginWordPlace() const {
95 if (CLine* pLine = m_LineArray.GetAt(0)) 89 if (CLine* pLine = m_LineArray.GetAt(0)) {
96 return pLine->GetBeginWordPlace(); 90 return pLine->GetBeginWordPlace();
91 }
97 return SecPlace; 92 return SecPlace;
98 } 93 }
99
100 CPVT_WordPlace CSection::GetEndWordPlace() const { 94 CPVT_WordPlace CSection::GetEndWordPlace() const {
101 if (CLine* pLine = m_LineArray.GetAt(m_LineArray.GetSize() - 1)) 95 if (CLine* pLine = m_LineArray.GetAt(m_LineArray.GetSize() - 1)) {
102 return pLine->GetEndWordPlace(); 96 return pLine->GetEndWordPlace();
97 }
103 return SecPlace; 98 return SecPlace;
104 } 99 }
105
106 CPVT_WordPlace CSection::GetPrevWordPlace(const CPVT_WordPlace& place) const { 100 CPVT_WordPlace CSection::GetPrevWordPlace(const CPVT_WordPlace& place) const {
107 if (place.nLineIndex < 0) 101 if (place.nLineIndex < 0) {
108 return GetBeginWordPlace(); 102 return GetBeginWordPlace();
109 103 }
110 if (place.nLineIndex >= m_LineArray.GetSize()) 104 if (place.nLineIndex >= m_LineArray.GetSize()) {
111 return GetEndWordPlace(); 105 return GetEndWordPlace();
112 106 }
113 if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) { 107 if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) {
114 if (place.nWordIndex == pLine->m_LineInfo.nBeginWordIndex) 108 if (place.nWordIndex == pLine->m_LineInfo.nBeginWordIndex) {
115 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1); 109 return CPVT_WordPlace(place.nSecIndex, place.nLineIndex, -1);
116 110 }
117 if (place.nWordIndex >= pLine->m_LineInfo.nBeginWordIndex) 111 if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) {
112 if (CLine* pPrevLine = m_LineArray.GetAt(place.nLineIndex - 1)) {
113 return pPrevLine->GetEndWordPlace();
114 }
115 } else {
118 return pLine->GetPrevWordPlace(place); 116 return pLine->GetPrevWordPlace(place);
119 117 }
120 if (CLine* pPrevLine = m_LineArray.GetAt(place.nLineIndex - 1))
121 return pPrevLine->GetEndWordPlace();
122 } 118 }
123 return place; 119 return place;
124 } 120 }
125
126 CPVT_WordPlace CSection::GetNextWordPlace(const CPVT_WordPlace& place) const { 121 CPVT_WordPlace CSection::GetNextWordPlace(const CPVT_WordPlace& place) const {
127 if (place.nLineIndex < 0) 122 if (place.nLineIndex < 0) {
128 return GetBeginWordPlace(); 123 return GetBeginWordPlace();
129 124 }
130 if (place.nLineIndex >= m_LineArray.GetSize()) 125 if (place.nLineIndex >= m_LineArray.GetSize()) {
131 return GetEndWordPlace(); 126 return GetEndWordPlace();
132 127 }
133 if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) { 128 if (CLine* pLine = m_LineArray.GetAt(place.nLineIndex)) {
134 if (place.nWordIndex < pLine->m_LineInfo.nEndWordIndex) 129 if (place.nWordIndex >= pLine->m_LineInfo.nEndWordIndex) {
130 if (CLine* pNextLine = m_LineArray.GetAt(place.nLineIndex + 1)) {
131 return pNextLine->GetBeginWordPlace();
132 }
133 } else {
135 return pLine->GetNextWordPlace(place); 134 return pLine->GetNextWordPlace(place);
136 135 }
137 if (CLine* pNextLine = m_LineArray.GetAt(place.nLineIndex + 1))
138 return pNextLine->GetBeginWordPlace();
139 } 136 }
140 return place; 137 return place;
141 } 138 }
142
143 void CSection::UpdateWordPlace(CPVT_WordPlace& place) const { 139 void CSection::UpdateWordPlace(CPVT_WordPlace& place) const {
144 int32_t nLeft = 0; 140 int32_t nLeft = 0;
145 int32_t nRight = m_LineArray.GetSize() - 1; 141 int32_t nRight = m_LineArray.GetSize() - 1;
146 int32_t nMid = (nLeft + nRight) / 2; 142 int32_t nMid = (nLeft + nRight) / 2;
147 while (nLeft <= nRight) { 143 while (nLeft <= nRight) {
148 CLine* pLine = m_LineArray.GetAt(nMid); 144 if (CLine* pLine = m_LineArray.GetAt(nMid)) {
149 if (!pLine) 145 if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) {
150 return; 146 nRight = nMid - 1;
151 147 nMid = (nLeft + nRight) / 2;
152 if (place.nWordIndex < pLine->m_LineInfo.nBeginWordIndex) { 148 } else if (place.nWordIndex > pLine->m_LineInfo.nEndWordIndex) {
153 nRight = nMid - 1; 149 nLeft = nMid + 1;
154 nMid = (nLeft + nRight) / 2; 150 nMid = (nLeft + nRight) / 2;
155 } else if (place.nWordIndex > pLine->m_LineInfo.nEndWordIndex) { 151 } else {
156 nLeft = nMid + 1; 152 place.nLineIndex = nMid;
157 nMid = (nLeft + nRight) / 2; 153 return;
154 }
158 } else { 155 } else {
159 place.nLineIndex = nMid; 156 break;
160 return;
161 } 157 }
162 } 158 }
163 } 159 }
164
165 CPVT_WordPlace CSection::SearchWordPlace(const CFX_FloatPoint& point) const { 160 CPVT_WordPlace CSection::SearchWordPlace(const CFX_FloatPoint& point) const {
166 ASSERT(m_pVT); 161 ASSERT(m_pVT);
167 CPVT_WordPlace place = GetBeginWordPlace(); 162 CPVT_WordPlace place = GetBeginWordPlace();
168 FX_BOOL bUp = TRUE; 163 FX_BOOL bUp = TRUE;
169 FX_BOOL bDown = TRUE; 164 FX_BOOL bDown = TRUE;
170 int32_t nLeft = 0; 165 int32_t nLeft = 0;
171 int32_t nRight = m_LineArray.GetSize() - 1; 166 int32_t nRight = m_LineArray.GetSize() - 1;
172 int32_t nMid = m_LineArray.GetSize() / 2; 167 int32_t nMid = m_LineArray.GetSize() / 2;
173 FX_FLOAT fTop = 0; 168 FX_FLOAT fTop = 0;
174 FX_FLOAT fBottom = 0; 169 FX_FLOAT fBottom = 0;
175 while (nLeft <= nRight) { 170 while (nLeft <= nRight) {
176 if (CLine* pLine = m_LineArray.GetAt(nMid)) { 171 if (CLine* pLine = m_LineArray.GetAt(nMid)) {
177 fTop = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineAscent - 172 fTop = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineAscent -
178 m_pVT->GetLineLeading(m_SecInfo); 173 m_pVT->GetLineLeading(m_SecInfo);
179 fBottom = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineDescent; 174 fBottom = pLine->m_LineInfo.fLineY - pLine->m_LineInfo.fLineDescent;
180 if (IsFloatBigger(point.y, fTop)) 175 if (IsFloatBigger(point.y, fTop)) {
181 bUp = FALSE; 176 bUp = FALSE;
182 177 }
183 if (IsFloatSmaller(point.y, fBottom)) 178 if (IsFloatSmaller(point.y, fBottom)) {
184 bDown = FALSE; 179 bDown = FALSE;
185 180 }
186 if (IsFloatSmaller(point.y, fTop)) { 181 if (IsFloatSmaller(point.y, fTop)) {
187 nRight = nMid - 1; 182 nRight = nMid - 1;
188 nMid = (nLeft + nRight) / 2; 183 nMid = (nLeft + nRight) / 2;
189 continue; 184 continue;
190 } 185 } else if (IsFloatBigger(point.y, fBottom)) {
191 if (IsFloatBigger(point.y, fBottom)) {
192 nLeft = nMid + 1; 186 nLeft = nMid + 1;
193 nMid = (nLeft + nRight) / 2; 187 nMid = (nLeft + nRight) / 2;
194 continue; 188 continue;
189 } else {
190 place = SearchWordPlace(
191 point.x,
192 CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()),
193 pLine->GetEndWordPlace()));
194 place.nLineIndex = nMid;
195 return place;
195 } 196 }
196
197 place = SearchWordPlace(
198 point.x,
199 CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()),
200 pLine->GetEndWordPlace()));
201 place.nLineIndex = nMid;
202 return place;
203 } 197 }
204 } 198 }
205 if (bUp) 199 if (bUp) {
206 place = GetBeginWordPlace(); 200 place = GetBeginWordPlace();
207 if (bDown) 201 }
202 if (bDown) {
208 place = GetEndWordPlace(); 203 place = GetEndWordPlace();
204 }
209 return place; 205 return place;
210 } 206 }
211
212 CPVT_WordPlace CSection::SearchWordPlace( 207 CPVT_WordPlace CSection::SearchWordPlace(
213 FX_FLOAT fx, 208 FX_FLOAT fx,
214 const CPVT_WordPlace& lineplace) const { 209 const CPVT_WordPlace& lineplace) const {
215 CLine* pLine = m_LineArray.GetAt(lineplace.nLineIndex); 210 if (CLine* pLine = m_LineArray.GetAt(lineplace.nLineIndex)) {
216 if (!pLine) 211 return SearchWordPlace(
217 return GetBeginWordPlace(); 212 fx - m_SecInfo.rcSection.left,
218 return SearchWordPlace( 213 CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()),
219 fx - m_SecInfo.rcSection.left, 214 pLine->GetEndWordPlace()));
220 CPVT_WordRange(pLine->GetNextWordPlace(pLine->GetBeginWordPlace()), 215 }
221 pLine->GetEndWordPlace())); 216 return GetBeginWordPlace();
222 } 217 }
223
224 CPVT_WordPlace CSection::SearchWordPlace(FX_FLOAT fx, 218 CPVT_WordPlace CSection::SearchWordPlace(FX_FLOAT fx,
225 const CPVT_WordRange& range) const { 219 const CPVT_WordRange& range) const {
226 CPVT_WordPlace wordplace = range.BeginPos; 220 CPVT_WordPlace wordplace = range.BeginPos;
227 wordplace.nWordIndex = -1; 221 wordplace.nWordIndex = -1;
228 if (!m_pVT) 222 if (!m_pVT) {
229 return wordplace; 223 return wordplace;
230 224 }
231 int32_t nLeft = range.BeginPos.nWordIndex; 225 int32_t nLeft = range.BeginPos.nWordIndex;
232 int32_t nRight = range.EndPos.nWordIndex + 1; 226 int32_t nRight = range.EndPos.nWordIndex + 1;
233 int32_t nMid = (nLeft + nRight) / 2; 227 int32_t nMid = (nLeft + nRight) / 2;
234 while (nLeft < nRight) { 228 while (nLeft < nRight) {
235 if (nMid == nLeft) 229 if (nMid == nLeft) {
236 break; 230 break;
237 231 }
238 if (nMid == nRight) { 232 if (nMid == nRight) {
239 nMid--; 233 nMid--;
240 break; 234 break;
241 } 235 }
242 236 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) {
243 CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid); 237 if (fx >
244 if (!pWord) 238 pWord->fWordX + m_pVT->GetWordWidth(*pWord) * VARIABLETEXT_HALF) {
239 nLeft = nMid;
240 nMid = (nLeft + nRight) / 2;
241 continue;
242 } else {
243 nRight = nMid;
244 nMid = (nLeft + nRight) / 2;
245 continue;
246 }
247 } else {
245 break; 248 break;
246 249 }
247 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * VARIABLETEXT_HALF)
248 nLeft = nMid;
249 else
250 nRight = nMid;
251 nMid = (nLeft + nRight) / 2;
252 } 250 }
253 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) { 251 if (CPVT_WordInfo* pWord = m_WordArray.GetAt(nMid)) {
254 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * VARIABLETEXT_HALF) { 252 if (fx > pWord->fWordX + m_pVT->GetWordWidth(*pWord) * VARIABLETEXT_HALF) {
255 wordplace.nWordIndex = nMid; 253 wordplace.nWordIndex = nMid;
256 } 254 }
257 } 255 }
258 return wordplace; 256 return wordplace;
259 } 257 }
260
261 void CSection::ClearLeftWords(int32_t nWordIndex) { 258 void CSection::ClearLeftWords(int32_t nWordIndex) {
262 for (int32_t i = nWordIndex; i >= 0; i--) { 259 for (int32_t i = nWordIndex; i >= 0; i--) {
263 delete m_WordArray.GetAt(i); 260 delete m_WordArray.GetAt(i);
264 m_WordArray.RemoveAt(i); 261 m_WordArray.RemoveAt(i);
265 } 262 }
266 } 263 }
267
268 void CSection::ClearRightWords(int32_t nWordIndex) { 264 void CSection::ClearRightWords(int32_t nWordIndex) {
269 for (int32_t i = m_WordArray.GetSize() - 1; i > nWordIndex; i--) { 265 for (int32_t i = m_WordArray.GetSize() - 1; i > nWordIndex; i--) {
270 delete m_WordArray.GetAt(i); 266 delete m_WordArray.GetAt(i);
271 m_WordArray.RemoveAt(i); 267 m_WordArray.RemoveAt(i);
272 } 268 }
273 } 269 }
274
275 void CSection::ClearMidWords(int32_t nBeginIndex, int32_t nEndIndex) { 270 void CSection::ClearMidWords(int32_t nBeginIndex, int32_t nEndIndex) {
276 for (int32_t i = nEndIndex; i > nBeginIndex; i--) { 271 for (int32_t i = nEndIndex; i > nBeginIndex; i--) {
277 delete m_WordArray.GetAt(i); 272 delete m_WordArray.GetAt(i);
278 m_WordArray.RemoveAt(i); 273 m_WordArray.RemoveAt(i);
279 } 274 }
280 } 275 }
281
282 void CSection::ClearWords(const CPVT_WordRange& PlaceRange) { 276 void CSection::ClearWords(const CPVT_WordRange& PlaceRange) {
283 CPVT_WordPlace SecBeginPos = GetBeginWordPlace(); 277 CPVT_WordPlace SecBeginPos = GetBeginWordPlace();
284 CPVT_WordPlace SecEndPos = GetEndWordPlace(); 278 CPVT_WordPlace SecEndPos = GetEndWordPlace();
285 if (PlaceRange.BeginPos.WordCmp(SecBeginPos) >= 0) { 279 if (PlaceRange.BeginPos.WordCmp(SecBeginPos) >= 0) {
286 if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) { 280 if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) {
287 ClearMidWords(PlaceRange.BeginPos.nWordIndex, 281 ClearMidWords(PlaceRange.BeginPos.nWordIndex,
288 PlaceRange.EndPos.nWordIndex); 282 PlaceRange.EndPos.nWordIndex);
289 } else { 283 } else {
290 ClearRightWords(PlaceRange.BeginPos.nWordIndex); 284 ClearRightWords(PlaceRange.BeginPos.nWordIndex);
291 } 285 }
292 } else if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) { 286 } else if (PlaceRange.EndPos.WordCmp(SecEndPos) <= 0) {
293 ClearLeftWords(PlaceRange.EndPos.nWordIndex); 287 ClearLeftWords(PlaceRange.EndPos.nWordIndex);
294 } else { 288 } else {
295 ResetWordArray(); 289 ResetWordArray();
296 } 290 }
297 } 291 }
298
299 void CSection::ClearWord(const CPVT_WordPlace& place) { 292 void CSection::ClearWord(const CPVT_WordPlace& place) {
300 delete m_WordArray.GetAt(place.nWordIndex); 293 delete m_WordArray.GetAt(place.nWordIndex);
301 m_WordArray.RemoveAt(place.nWordIndex); 294 m_WordArray.RemoveAt(place.nWordIndex);
302 } 295 }
303
304 CTypeset::CTypeset(CSection* pSection) 296 CTypeset::CTypeset(CSection* pSection)
305 : m_rcRet(0.0f, 0.0f, 0.0f, 0.0f), 297 : m_rcRet(0.0f, 0.0f, 0.0f, 0.0f),
306 m_pVT(pSection->m_pVT), 298 m_pVT(pSection->m_pVT),
307 m_pSection(pSection) {} 299 m_pSection(pSection) {}
308
309 CTypeset::~CTypeset() {} 300 CTypeset::~CTypeset() {}
310
311 CPVT_FloatRect CTypeset::CharArray() { 301 CPVT_FloatRect CTypeset::CharArray() {
312 ASSERT(m_pSection); 302 ASSERT(m_pSection);
313 FX_FLOAT fLineAscent = 303 FX_FLOAT fLineAscent =
314 m_pVT->GetFontAscent(m_pVT->GetDefaultFontIndex(), m_pVT->GetFontSize()); 304 m_pVT->GetFontAscent(m_pVT->GetDefaultFontIndex(), m_pVT->GetFontSize());
315 FX_FLOAT fLineDescent = 305 FX_FLOAT fLineDescent =
316 m_pVT->GetFontDescent(m_pVT->GetDefaultFontIndex(), m_pVT->GetFontSize()); 306 m_pVT->GetFontDescent(m_pVT->GetDefaultFontIndex(), m_pVT->GetFontSize());
317 m_rcRet.Default(); 307 m_rcRet.Default();
318 FX_FLOAT x = 0.0f, y = 0.0f; 308 FX_FLOAT x = 0.0f, y = 0.0f;
319 FX_FLOAT fNextWidth; 309 FX_FLOAT fNextWidth;
320 int32_t nStart = 0; 310 int32_t nStart = 0;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 pLine->m_LineInfo.nBeginWordIndex = 0; 369 pLine->m_LineInfo.nBeginWordIndex = 0;
380 pLine->m_LineInfo.nEndWordIndex = m_pSection->m_WordArray.GetSize() - 1; 370 pLine->m_LineInfo.nEndWordIndex = m_pSection->m_WordArray.GetSize() - 1;
381 pLine->m_LineInfo.fLineY = y; 371 pLine->m_LineInfo.fLineY = y;
382 pLine->m_LineInfo.fLineWidth = x - pLine->m_LineInfo.fLineX; 372 pLine->m_LineInfo.fLineWidth = x - pLine->m_LineInfo.fLineX;
383 pLine->m_LineInfo.fLineAscent = fLineAscent; 373 pLine->m_LineInfo.fLineAscent = fLineAscent;
384 pLine->m_LineInfo.fLineDescent = fLineDescent; 374 pLine->m_LineInfo.fLineDescent = fLineDescent;
385 y -= fLineDescent; 375 y -= fLineDescent;
386 } 376 }
387 return m_rcRet = CPVT_FloatRect(0, 0, x, y); 377 return m_rcRet = CPVT_FloatRect(0, 0, x, y);
388 } 378 }
389 379 CPVT_Size CTypeset::GetEditSize(FX_FLOAT fFontSize) {
390 CFX_PointF CTypeset::GetEditSize(FX_FLOAT fFontSize) {
391 ASSERT(m_pSection); 380 ASSERT(m_pSection);
392 ASSERT(m_pVT); 381 ASSERT(m_pVT);
393 SplitLines(FALSE, fFontSize); 382 SplitLines(FALSE, fFontSize);
394 return CFX_PointF(m_rcRet.Width(), m_rcRet.Height()); 383 return CPVT_Size(m_rcRet.Width(), m_rcRet.Height());
395 } 384 }
396
397 CPVT_FloatRect CTypeset::Typeset() { 385 CPVT_FloatRect CTypeset::Typeset() {
398 ASSERT(m_pVT); 386 ASSERT(m_pVT);
399 m_pSection->m_LineArray.Empty(); 387 m_pSection->m_LineArray.Empty();
400 SplitLines(TRUE, 0.0f); 388 SplitLines(TRUE, 0.0f);
401 m_pSection->m_LineArray.Clear(); 389 m_pSection->m_LineArray.Clear();
402 OutputLines(); 390 OutputLines();
403 return m_rcRet; 391 return m_rcRet;
404 } 392 }
405 393
406 static const uint8_t special_chars[128] = { 394 static const uint8_t special_chars[128] = {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 line.fLineWidth = 0; 686 line.fLineWidth = 0;
699 line.fLineAscent = fLineAscent; 687 line.fLineAscent = fLineAscent;
700 line.fLineDescent = fLineDescent; 688 line.fLineDescent = fLineDescent;
701 m_pSection->AddLine(line); 689 m_pSection->AddLine(line);
702 } 690 }
703 fMaxY += m_pVT->GetLineLeading(m_pSection->m_SecInfo) + fLineAscent - 691 fMaxY += m_pVT->GetLineLeading(m_pSection->m_SecInfo) + fLineAscent -
704 fLineDescent; 692 fLineDescent;
705 } 693 }
706 m_rcRet = CPVT_FloatRect(0, 0, fMaxX, fMaxY); 694 m_rcRet = CPVT_FloatRect(0, 0, fMaxX, fMaxY);
707 } 695 }
708
709 void CTypeset::OutputLines() { 696 void CTypeset::OutputLines() {
697 ASSERT(m_pVT);
698 ASSERT(m_pSection);
699 FX_FLOAT fMinX = 0.0f, fMinY = 0.0f, fMaxX = 0.0f, fMaxY = 0.0f;
700 FX_FLOAT fPosX = 0.0f, fPosY = 0.0f;
710 FX_FLOAT fLineIndent = m_pVT->GetLineIndent(m_pSection->m_SecInfo); 701 FX_FLOAT fLineIndent = m_pVT->GetLineIndent(m_pSection->m_SecInfo);
711 FX_FLOAT fTypesetWidth = std::max(m_pVT->GetPlateWidth() - fLineIndent, 0.0f); 702 FX_FLOAT fTypesetWidth = std::max(m_pVT->GetPlateWidth() - fLineIndent, 0.0f);
712 FX_FLOAT fMinX = GetXPosForAlignment(fTypesetWidth, m_rcRet.Width()); 703 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) {
713 FX_FLOAT fMinY = 0.0f; 704 default:
714 FX_FLOAT fMaxX = fMinX + m_rcRet.Width(); 705 case 0:
715 FX_FLOAT fMaxY = m_rcRet.Height(); 706 fMinX = 0.0f;
716 707 break;
708 case 1:
709 fMinX = (fTypesetWidth - m_rcRet.Width()) * VARIABLETEXT_HALF;
710 break;
711 case 2:
712 fMinX = fTypesetWidth - m_rcRet.Width();
713 break;
714 }
715 fMaxX = fMinX + m_rcRet.Width();
716 fMinY = 0.0f;
717 fMaxY = m_rcRet.Height();
717 int32_t nTotalLines = m_pSection->m_LineArray.GetSize(); 718 int32_t nTotalLines = m_pSection->m_LineArray.GetSize();
718 if (nTotalLines <= 0) { 719 if (nTotalLines > 0) {
719 m_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY); 720 m_pSection->m_SecInfo.nTotalLine = nTotalLines;
720 return; 721 for (int32_t l = 0; l < nTotalLines; l++) {
721 } 722 if (CLine* pLine = m_pSection->m_LineArray.GetAt(l)) {
722 723 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) {
723 FX_FLOAT fPosX = 0.0f;
724 FX_FLOAT fPosY = 0.0f;
725 m_pSection->m_SecInfo.nTotalLine = nTotalLines;
726 for (int32_t l = 0; l < nTotalLines; l++) {
727 CLine* pLine = m_pSection->m_LineArray.GetAt(l);
728 if (!pLine)
729 continue;
730
731 fPosX = GetXPosForAlignment(fTypesetWidth, pLine->m_LineInfo.fLineWidth);
732 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) {
733 default:
734 case 0:
735 fPosX = 0;
736 break;
737 case 1:
738 fPosX =
739 (fTypesetWidth - pLine->m_LineInfo.fLineWidth) * VARIABLETEXT_HALF;
740 break;
741 case 2:
742 fPosX = fTypesetWidth - pLine->m_LineInfo.fLineWidth;
743 break;
744 }
745 fPosX += fLineIndent;
746 fPosY += m_pVT->GetLineLeading(m_pSection->m_SecInfo);
747 fPosY += pLine->m_LineInfo.fLineAscent;
748 pLine->m_LineInfo.fLineX = fPosX - fMinX;
749 pLine->m_LineInfo.fLineY = fPosY - fMinY;
750 for (int32_t w = pLine->m_LineInfo.nBeginWordIndex;
751 w <= pLine->m_LineInfo.nEndWordIndex; w++) {
752 if (w < 0 || w >= m_pSection->m_WordArray.GetSize())
753 continue;
754
755 CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(w);
756 if (!pWord)
757 continue;
758
759 pWord->fWordX = fPosX - fMinX;
760 if (pWord->pWordProps) {
761 switch (pWord->pWordProps->nScriptType) {
762 default: 724 default:
763 case CPDF_VariableText::ScriptType::Normal: 725 case 0:
764 pWord->fWordY = fPosY - fMinY; 726 fPosX = 0;
765 break; 727 break;
766 case CPDF_VariableText::ScriptType::Super: 728 case 1:
767 pWord->fWordY = fPosY - m_pVT->GetWordAscent(*pWord) - fMinY; 729 fPosX = (fTypesetWidth - pLine->m_LineInfo.fLineWidth) *
730 VARIABLETEXT_HALF;
768 break; 731 break;
769 case CPDF_VariableText::ScriptType::Sub: 732 case 2:
770 pWord->fWordY = fPosY - m_pVT->GetWordDescent(*pWord) - fMinY; 733 fPosX = fTypesetWidth - pLine->m_LineInfo.fLineWidth;
771 break; 734 break;
772 } 735 }
773 } else { 736 fPosX += fLineIndent;
774 pWord->fWordY = fPosY - fMinY; 737 fPosY += m_pVT->GetLineLeading(m_pSection->m_SecInfo);
738 fPosY += pLine->m_LineInfo.fLineAscent;
739 pLine->m_LineInfo.fLineX = fPosX - fMinX;
740 pLine->m_LineInfo.fLineY = fPosY - fMinY;
741 for (int32_t w = pLine->m_LineInfo.nBeginWordIndex;
742 w <= pLine->m_LineInfo.nEndWordIndex; w++) {
743 if (CPVT_WordInfo* pWord = m_pSection->m_WordArray.GetAt(w)) {
744 pWord->fWordX = fPosX - fMinX;
745 if (pWord->pWordProps) {
746 switch (pWord->pWordProps->nScriptType) {
747 default:
748 case CPDF_VariableText::ScriptType::Normal:
749 pWord->fWordY = fPosY - fMinY;
750 break;
751 case CPDF_VariableText::ScriptType::Super:
752 pWord->fWordY = fPosY - m_pVT->GetWordAscent(*pWord) - fMinY;
753 break;
754 case CPDF_VariableText::ScriptType::Sub:
755 pWord->fWordY = fPosY - m_pVT->GetWordDescent(*pWord) - fMinY;
756 break;
757 }
758 } else {
759 pWord->fWordY = fPosY - fMinY;
760 }
761 fPosX += m_pVT->GetWordWidth(*pWord);
762 }
763 }
764 fPosY -= pLine->m_LineInfo.fLineDescent;
775 } 765 }
776 fPosX += m_pVT->GetWordWidth(*pWord);
777 } 766 }
778 fPosY -= pLine->m_LineInfo.fLineDescent;
779 } 767 }
780 m_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY); 768 m_rcRet = CPVT_FloatRect(fMinX, fMinY, fMaxX, fMaxY);
781 } 769 }
782
783 FX_FLOAT CTypeset::GetXPosForAlignment(FX_FLOAT fTypesetWidth,
784 FX_FLOAT fLineWidth) const {
785 switch (m_pVT->GetAlignment(m_pSection->m_SecInfo)) {
786 default:
787 case 0:
788 return 0;
789 case 1:
790 return (fTypesetWidth - fLineWidth) * VARIABLETEXT_HALF;
791 case 2:
792 return fTypesetWidth - fLineWidth;
793 }
794 }
795
796 CPDF_EditContainer::CPDF_EditContainer()
797 : m_rcPlate(0, 0, 0, 0), m_rcContent(0, 0, 0, 0) {}
798
799 CPDF_EditContainer::~CPDF_EditContainer() {}
800
801 CFX_FloatRect CPDF_EditContainer::InToOut(const CPVT_FloatRect& rect) const {
802 CFX_FloatPoint ptLeftTop = InToOut(CFX_FloatPoint(rect.left, rect.top));
803 CFX_FloatPoint ptRightBottom =
804 InToOut(CFX_FloatPoint(rect.right, rect.bottom));
805 return CFX_FloatRect(ptLeftTop.x, ptRightBottom.y, ptRightBottom.x,
806 ptLeftTop.y);
807 }
OLDNEW
« no previous file with comments | « core/fpdfdoc/doc_vt.h ('k') | core/fpdfdoc/include/cpdf_variabletext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698