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

Side by Side Diff: core/src/fpdftext/fpdf_text_int.cpp

Issue 1618273004: Remove CFX_SegmentedArray use from master (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Nits. Created 4 years, 11 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/include/fxcrt/fx_basic.h ('k') | core/src/fpdftext/text_int.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/src/fpdftext/text_int.h"
8
7 #include <algorithm> 9 #include <algorithm>
8 #include <cctype> 10 #include <cctype>
9 #include <cwctype> 11 #include <cwctype>
10 #include <memory> 12 #include <memory>
11 13
12 #include "core/include/fpdfapi/fpdf_module.h" 14 #include "core/include/fpdfapi/fpdf_module.h"
13 #include "core/include/fpdfapi/fpdf_page.h" 15 #include "core/include/fpdfapi/fpdf_page.h"
14 #include "core/include/fpdfapi/fpdf_pageobj.h" 16 #include "core/include/fpdfapi/fpdf_pageobj.h"
15 #include "core/include/fpdfapi/fpdf_resource.h" 17 #include "core/include/fpdfapi/fpdf_resource.h"
16 #include "core/include/fpdftext/fpdf_text.h" 18 #include "core/include/fpdftext/fpdf_text.h"
17 #include "core/include/fxcrt/fx_bidi.h" 19 #include "core/include/fxcrt/fx_bidi.h"
18 #include "core/include/fxcrt/fx_ext.h" 20 #include "core/include/fxcrt/fx_ext.h"
19 #include "core/include/fxcrt/fx_ucd.h" 21 #include "core/include/fxcrt/fx_ucd.h"
20 #include "text_int.h" 22 #include "third_party/base/stl_util.h"
21 23
22 namespace { 24 namespace {
23 25
24 FX_BOOL _IsIgnoreSpaceCharacter(FX_WCHAR curChar) { 26 FX_BOOL _IsIgnoreSpaceCharacter(FX_WCHAR curChar) {
25 if (curChar < 255) { 27 if (curChar < 255) {
26 return FALSE; 28 return FALSE;
27 } 29 }
28 if ((curChar >= 0x0600 && curChar <= 0x06FF) || 30 if ((curChar >= 0x0600 && curChar <= 0x06FF) ||
29 (curChar >= 0xFE70 && curChar <= 0xFEFF) || 31 (curChar >= 0xFE70 && curChar <= 0xFEFF) ||
30 (curChar >= 0xFB50 && curChar <= 0xFDFF) || 32 (curChar >= 0xFB50 && curChar <= 0xFDFF) ||
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 #define TEXT_LINEFEED_CHAR L'\n' 101 #define TEXT_LINEFEED_CHAR L'\n'
100 #define TEXT_RETURN_CHAR L'\r' 102 #define TEXT_RETURN_CHAR L'\r'
101 #define TEXT_EMPTY L"" 103 #define TEXT_EMPTY L""
102 #define TEXT_BLANK L" " 104 #define TEXT_BLANK L" "
103 #define TEXT_RETURN_LINEFEED L"\r\n" 105 #define TEXT_RETURN_LINEFEED L"\r\n"
104 #define TEXT_LINEFEED L"\n" 106 #define TEXT_LINEFEED L"\n"
105 #define TEXT_CHARRATIO_GAPDELTA 0.070 107 #define TEXT_CHARRATIO_GAPDELTA 0.070
106 108
107 CPDF_TextPage::CPDF_TextPage(const CPDF_Page* pPage, int flags) 109 CPDF_TextPage::CPDF_TextPage(const CPDF_Page* pPage, int flags)
108 : m_pPage(pPage), 110 : m_pPage(pPage),
109 m_charList(512),
110 m_TempCharList(50),
111 m_parserflag(flags), 111 m_parserflag(flags),
112 m_pPreTextObj(nullptr), 112 m_pPreTextObj(nullptr),
113 m_bIsParsed(false), 113 m_bIsParsed(false),
114 m_TextlineDir(-1), 114 m_TextlineDir(-1),
115 m_CurlineRect(0, 0, 0, 0) { 115 m_CurlineRect(0, 0, 0, 0) {
116 m_TextBuf.EstimateSize(0, 10240); 116 m_TextBuf.EstimateSize(0, 10240);
117 pPage->GetDisplayMatrix(m_DisplayMatrix, 0, 0, (int)pPage->GetPageWidth(), 117 pPage->GetDisplayMatrix(m_DisplayMatrix, 0, 0, (int)pPage->GetPageWidth(),
118 (int)pPage->GetPageHeight(), 0); 118 (int)pPage->GetPageHeight(), 0);
119 } 119 }
120 120
(...skipping 11 matching lines...) Expand all
132 default: 132 default:
133 return false; 133 return false;
134 } 134 }
135 } 135 }
136 FX_BOOL CPDF_TextPage::ParseTextPage() { 136 FX_BOOL CPDF_TextPage::ParseTextPage() {
137 m_bIsParsed = false; 137 m_bIsParsed = false;
138 if (!m_pPage) 138 if (!m_pPage)
139 return FALSE; 139 return FALSE;
140 140
141 m_TextBuf.Clear(); 141 m_TextBuf.Clear();
142 m_charList.RemoveAll(); 142 m_CharList.clear();
143 m_pPreTextObj = NULL; 143 m_pPreTextObj = NULL;
144 ProcessObject(); 144 ProcessObject();
145 m_bIsParsed = true; 145 m_bIsParsed = true;
146 m_CharIndex.RemoveAll(); 146 m_CharIndex.RemoveAll();
147 int nCount = m_charList.GetSize(); 147 int nCount = pdfium::CollectionSize<int>(m_CharList);
148 if (nCount) { 148 if (nCount) {
149 m_CharIndex.Add(0); 149 m_CharIndex.Add(0);
150 } 150 }
151 for (int i = 0; i < nCount; i++) { 151 for (int i = 0; i < nCount; i++) {
152 int indexSize = m_CharIndex.GetSize(); 152 int indexSize = m_CharIndex.GetSize();
153 FX_BOOL bNormal = FALSE; 153 FX_BOOL bNormal = FALSE;
154 PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(i); 154 const PAGECHAR_INFO& charinfo = m_CharList[i];
155 if (charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) { 155 if (charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) {
156 bNormal = TRUE; 156 bNormal = TRUE;
157 } else if (charinfo.m_Unicode == 0 || IsControlChar(charinfo)) { 157 } else if (charinfo.m_Unicode == 0 || IsControlChar(charinfo)) {
158 bNormal = FALSE; 158 bNormal = FALSE;
159 } else { 159 } else {
160 bNormal = TRUE; 160 bNormal = TRUE;
161 } 161 }
162 if (bNormal) { 162 if (bNormal) {
163 if (indexSize % 2) { 163 if (indexSize % 2) {
164 m_CharIndex.Add(1); 164 m_CharIndex.Add(1);
(...skipping 14 matching lines...) Expand all
179 } 179 }
180 } 180 }
181 } 181 }
182 int indexSize = m_CharIndex.GetSize(); 182 int indexSize = m_CharIndex.GetSize();
183 if (indexSize % 2) { 183 if (indexSize % 2) {
184 m_CharIndex.RemoveAt(indexSize - 1); 184 m_CharIndex.RemoveAt(indexSize - 1);
185 } 185 }
186 return TRUE; 186 return TRUE;
187 } 187 }
188 int CPDF_TextPage::CountChars() const { 188 int CPDF_TextPage::CountChars() const {
189 return m_charList.GetSize(); 189 return pdfium::CollectionSize<int>(m_CharList);
190 } 190 }
191 int CPDF_TextPage::CharIndexFromTextIndex(int TextIndex) const { 191 int CPDF_TextPage::CharIndexFromTextIndex(int TextIndex) const {
192 int indexSize = m_CharIndex.GetSize(); 192 int indexSize = m_CharIndex.GetSize();
193 int count = 0; 193 int count = 0;
194 for (int i = 0; i < indexSize; i += 2) { 194 for (int i = 0; i < indexSize; i += 2) {
195 count += m_CharIndex.GetAt(i + 1); 195 count += m_CharIndex.GetAt(i + 1);
196 if (count > TextIndex) { 196 if (count > TextIndex) {
197 return TextIndex - count + m_CharIndex.GetAt(i + 1) + 197 return TextIndex - count + m_CharIndex.GetAt(i + 1) +
198 m_CharIndex.GetAt(i); 198 m_CharIndex.GetAt(i);
199 } 199 }
(...skipping 17 matching lines...) Expand all
217 } 217 }
218 void CPDF_TextPage::GetRectArray(int start, 218 void CPDF_TextPage::GetRectArray(int start,
219 int nCount, 219 int nCount,
220 CFX_RectArray& rectArray) const { 220 CFX_RectArray& rectArray) const {
221 if (start < 0 || nCount == 0) { 221 if (start < 0 || nCount == 0) {
222 return; 222 return;
223 } 223 }
224 if (!m_bIsParsed) { 224 if (!m_bIsParsed) {
225 return; 225 return;
226 } 226 }
227 PAGECHAR_INFO info_curchar;
228 CPDF_TextObject* pCurObj = NULL; 227 CPDF_TextObject* pCurObj = NULL;
229 CFX_FloatRect rect; 228 CFX_FloatRect rect;
230 int curPos = start; 229 int curPos = start;
231 FX_BOOL flagNewRect = TRUE; 230 FX_BOOL flagNewRect = TRUE;
232 if (nCount + start > m_charList.GetSize() || nCount == -1) { 231 if (nCount + start > pdfium::CollectionSize<int>(m_CharList) ||
233 nCount = m_charList.GetSize() - start; 232 nCount == -1) {
233 nCount = pdfium::CollectionSize<int>(m_CharList) - start;
234 } 234 }
235 while (nCount--) { 235 while (nCount--) {
236 info_curchar = *(PAGECHAR_INFO*)m_charList.GetAt(curPos++); 236 PAGECHAR_INFO info_curchar = m_CharList[curPos++];
237 if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED) { 237 if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED) {
238 continue; 238 continue;
239 } 239 }
240 if (info_curchar.m_CharBox.Width() < 0.01 || 240 if (info_curchar.m_CharBox.Width() < 0.01 ||
241 info_curchar.m_CharBox.Height() < 0.01) { 241 info_curchar.m_CharBox.Height() < 0.01) {
242 continue; 242 continue;
243 } 243 }
244 if (!pCurObj) { 244 if (!pCurObj) {
245 pCurObj = info_curchar.m_pTextObj; 245 pCurObj = info_curchar.m_pTextObj;
246 } 246 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } 292 }
293 if (rect.top < info_curchar.m_CharBox.top) { 293 if (rect.top < info_curchar.m_CharBox.top) {
294 rect.top = info_curchar.m_CharBox.top; 294 rect.top = info_curchar.m_CharBox.top;
295 } 295 }
296 if (rect.bottom > info_curchar.m_CharBox.bottom) { 296 if (rect.bottom > info_curchar.m_CharBox.bottom) {
297 rect.bottom = info_curchar.m_CharBox.bottom; 297 rect.bottom = info_curchar.m_CharBox.bottom;
298 } 298 }
299 } 299 }
300 } 300 }
301 rectArray.Add(rect); 301 rectArray.Add(rect);
302 return;
303 } 302 }
304 int CPDF_TextPage::GetIndexAtPos(CPDF_Point point, 303 int CPDF_TextPage::GetIndexAtPos(CPDF_Point point,
305 FX_FLOAT xTolerance, 304 FX_FLOAT xTolerance,
306 FX_FLOAT yTolerance) const { 305 FX_FLOAT yTolerance) const {
307 if (!m_bIsParsed) 306 if (!m_bIsParsed)
308 return -3; 307 return -3;
309 308
310 int pos = 0; 309 int pos = 0;
311 int NearPos = -1; 310 int NearPos = -1;
312 double xdif = 5000, ydif = 5000; 311 double xdif = 5000;
313 while (pos < m_charList.GetSize()) { 312 double ydif = 5000;
314 PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)(m_charList.GetAt(pos)); 313 while (pos < pdfium::CollectionSize<int>(m_CharList)) {
314 PAGECHAR_INFO charinfo = m_CharList[pos];
315 CFX_FloatRect charrect = charinfo.m_CharBox; 315 CFX_FloatRect charrect = charinfo.m_CharBox;
316 if (charrect.Contains(point.x, point.y)) { 316 if (charrect.Contains(point.x, point.y)) {
317 break; 317 break;
318 } 318 }
319 if (xTolerance > 0 || yTolerance > 0) { 319 if (xTolerance > 0 || yTolerance > 0) {
320 CFX_FloatRect charRectExt; 320 CFX_FloatRect charRectExt;
321 charrect.Normalize(); 321 charrect.Normalize();
322 charRectExt.left = charrect.left - xTolerance / 2; 322 charRectExt.left = charrect.left - xTolerance / 2;
323 charRectExt.right = charrect.right + xTolerance / 2; 323 charRectExt.right = charrect.right + xTolerance / 2;
324 charRectExt.top = charrect.top + yTolerance / 2; 324 charRectExt.top = charrect.top + yTolerance / 2;
(...skipping 10 matching lines...) Expand all
335 : FXSYS_fabs(point.y - charrect.top); 335 : FXSYS_fabs(point.y - charrect.top);
336 if (curYdif + curXdif < xdif + ydif) { 336 if (curYdif + curXdif < xdif + ydif) {
337 ydif = curYdif; 337 ydif = curYdif;
338 xdif = curXdif; 338 xdif = curXdif;
339 NearPos = pos; 339 NearPos = pos;
340 } 340 }
341 } 341 }
342 } 342 }
343 ++pos; 343 ++pos;
344 } 344 }
345 if (pos >= m_charList.GetSize()) { 345 return pos < pdfium::CollectionSize<int>(m_CharList) ? pos : NearPos;
346 pos = NearPos;
347 }
348 return pos;
349 } 346 }
347
350 CFX_WideString CPDF_TextPage::GetTextByRect(const CFX_FloatRect& rect) const { 348 CFX_WideString CPDF_TextPage::GetTextByRect(const CFX_FloatRect& rect) const {
349 if (!m_bIsParsed)
350 return CFX_WideString();
351
352 FX_FLOAT posy = 0;
353 bool IsContainPreChar = false;
354 bool IsAddLineFeed = false;
351 CFX_WideString strText; 355 CFX_WideString strText;
352 if (!m_bIsParsed) 356 for (const auto& charinfo : m_CharList) {
353 return strText;
354
355 int nCount = m_charList.GetSize();
356 int pos = 0;
357 FX_FLOAT posy = 0;
358 FX_BOOL IsContainPreChar = FALSE;
359 FX_BOOL ISAddLineFeed = FALSE;
360 while (pos < nCount) {
361 PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(pos++);
362 if (IsRectIntersect(rect, charinfo.m_CharBox)) { 357 if (IsRectIntersect(rect, charinfo.m_CharBox)) {
363 if (FXSYS_fabs(posy - charinfo.m_OriginY) > 0 && !IsContainPreChar && 358 if (FXSYS_fabs(posy - charinfo.m_OriginY) > 0 && !IsContainPreChar &&
364 ISAddLineFeed) { 359 IsAddLineFeed) {
365 posy = charinfo.m_OriginY; 360 posy = charinfo.m_OriginY;
366 if (strText.GetLength() > 0) { 361 if (strText.GetLength() > 0) {
367 strText += L"\r\n"; 362 strText += L"\r\n";
368 } 363 }
369 } 364 }
370 IsContainPreChar = TRUE; 365 IsContainPreChar = true;
371 ISAddLineFeed = FALSE; 366 IsAddLineFeed = false;
372 if (charinfo.m_Unicode) { 367 if (charinfo.m_Unicode) {
373 strText += charinfo.m_Unicode; 368 strText += charinfo.m_Unicode;
374 } 369 }
375 } else if (charinfo.m_Unicode == 32) { 370 } else if (charinfo.m_Unicode == 32) {
376 if (IsContainPreChar && charinfo.m_Unicode) { 371 if (IsContainPreChar && charinfo.m_Unicode) {
377 strText += charinfo.m_Unicode; 372 strText += charinfo.m_Unicode;
378 IsContainPreChar = FALSE; 373 IsContainPreChar = false;
379 ISAddLineFeed = FALSE; 374 IsAddLineFeed = false;
380 } 375 }
381 } else { 376 } else {
382 IsContainPreChar = FALSE; 377 IsContainPreChar = false;
383 ISAddLineFeed = TRUE; 378 IsAddLineFeed = true;
384 } 379 }
385 } 380 }
386 return strText; 381 return strText;
387 } 382 }
388 void CPDF_TextPage::GetRectsArrayByRect(const CFX_FloatRect& rect, 383 void CPDF_TextPage::GetRectsArrayByRect(const CFX_FloatRect& rect,
389 CFX_RectArray& resRectArray) const { 384 CFX_RectArray& resRectArray) const {
390 if (!m_bIsParsed) 385 if (!m_bIsParsed)
391 return; 386 return;
392 387
393 CFX_FloatRect curRect; 388 CFX_FloatRect curRect;
394 FX_BOOL flagNewRect = TRUE; 389 bool flagNewRect = true;
395 CPDF_TextObject* pCurObj = NULL; 390 CPDF_TextObject* pCurObj = nullptr;
396 int nCount = m_charList.GetSize(); 391 for (auto info_curchar : m_CharList) {
397 int pos = 0;
398 while (pos < nCount) {
399 PAGECHAR_INFO info_curchar = *(PAGECHAR_INFO*)m_charList.GetAt(pos++);
400 if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED) { 392 if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED) {
401 continue; 393 continue;
402 } 394 }
403 if (IsRectIntersect(rect, info_curchar.m_CharBox)) { 395 if (!IsRectIntersect(rect, info_curchar.m_CharBox)) {
404 if (!pCurObj) { 396 continue;
405 pCurObj = info_curchar.m_pTextObj; 397 }
406 } 398 if (!pCurObj) {
407 if (pCurObj != info_curchar.m_pTextObj) { 399 pCurObj = info_curchar.m_pTextObj;
408 resRectArray.Add(curRect); 400 }
409 pCurObj = info_curchar.m_pTextObj; 401 if (pCurObj != info_curchar.m_pTextObj) {
410 flagNewRect = TRUE; 402 resRectArray.Add(curRect);
411 } 403 pCurObj = info_curchar.m_pTextObj;
412 if (flagNewRect) { 404 flagNewRect = true;
413 curRect = info_curchar.m_CharBox; 405 }
414 flagNewRect = FALSE; 406 if (flagNewRect) {
415 curRect.Normalize(); 407 curRect = info_curchar.m_CharBox;
416 } else { 408 curRect.Normalize();
417 info_curchar.m_CharBox.Normalize(); 409 flagNewRect = false;
418 if (curRect.left > info_curchar.m_CharBox.left) { 410 } else {
419 curRect.left = info_curchar.m_CharBox.left; 411 info_curchar.m_CharBox.Normalize();
420 } 412 curRect.left = std::min(curRect.left, info_curchar.m_CharBox.left);
421 if (curRect.right < info_curchar.m_CharBox.right) { 413 curRect.bottom = std::min(curRect.bottom, info_curchar.m_CharBox.bottom);
422 curRect.right = info_curchar.m_CharBox.right; 414 curRect.right = std::max(curRect.right, info_curchar.m_CharBox.right);
423 } 415 curRect.top = std::max(curRect.top, info_curchar.m_CharBox.top);
424 if (curRect.top < info_curchar.m_CharBox.top) {
425 curRect.top = info_curchar.m_CharBox.top;
426 }
427 if (curRect.bottom > info_curchar.m_CharBox.bottom) {
428 curRect.bottom = info_curchar.m_CharBox.bottom;
429 }
430 }
431 } 416 }
432 } 417 }
433 resRectArray.Add(curRect); 418 resRectArray.Add(curRect);
434 return;
435 } 419 }
436 int CPDF_TextPage::GetIndexAtPos(FX_FLOAT x, 420 int CPDF_TextPage::GetIndexAtPos(FX_FLOAT x,
437 FX_FLOAT y, 421 FX_FLOAT y,
438 FX_FLOAT xTolerance, 422 FX_FLOAT xTolerance,
439 FX_FLOAT yTolerance) const { 423 FX_FLOAT yTolerance) const {
440 CPDF_Point point(x, y); 424 CPDF_Point point(x, y);
441 return GetIndexAtPos(point, xTolerance, yTolerance); 425 return GetIndexAtPos(point, xTolerance, yTolerance);
442 } 426 }
443 427
444 void CPDF_TextPage::GetCharInfo(int index, FPDF_CHAR_INFO* info) const { 428 void CPDF_TextPage::GetCharInfo(int index, FPDF_CHAR_INFO* info) const {
445 if (!m_bIsParsed) 429 if (!m_bIsParsed)
446 return; 430 return;
447 431
448 if (index < 0 || index >= m_charList.GetSize()) 432 if (index < 0 || index >= pdfium::CollectionSize<int>(m_CharList))
449 return; 433 return;
450 434
451 const PAGECHAR_INFO* charinfo = 435 const PAGECHAR_INFO& charinfo = m_CharList[index];
452 static_cast<PAGECHAR_INFO*>(m_charList.GetAt(index)); 436 info->m_Charcode = charinfo.m_CharCode;
453 info->m_Charcode = charinfo->m_CharCode; 437 info->m_OriginX = charinfo.m_OriginX;
454 info->m_OriginX = charinfo->m_OriginX; 438 info->m_OriginY = charinfo.m_OriginY;
455 info->m_OriginY = charinfo->m_OriginY; 439 info->m_Unicode = charinfo.m_Unicode;
456 info->m_Unicode = charinfo->m_Unicode; 440 info->m_Flag = charinfo.m_Flag;
457 info->m_Flag = charinfo->m_Flag; 441 info->m_CharBox = charinfo.m_CharBox;
458 info->m_CharBox = charinfo->m_CharBox; 442 info->m_pTextObj = charinfo.m_pTextObj;
459 info->m_pTextObj = charinfo->m_pTextObj; 443 if (charinfo.m_pTextObj && charinfo.m_pTextObj->GetFont()) {
460 if (charinfo->m_pTextObj && charinfo->m_pTextObj->GetFont()) { 444 info->m_FontSize = charinfo.m_pTextObj->GetFontSize();
461 info->m_FontSize = charinfo->m_pTextObj->GetFontSize();
462 } else { 445 } else {
463 info->m_FontSize = kDefaultFontSize; 446 info->m_FontSize = kDefaultFontSize;
464 } 447 }
465 info->m_Matrix.Copy(charinfo->m_Matrix); 448 info->m_Matrix.Copy(charinfo.m_Matrix);
466 } 449 }
467 450
468 void CPDF_TextPage::CheckMarkedContentObject(int32_t& start, 451 void CPDF_TextPage::CheckMarkedContentObject(int32_t& start,
469 int32_t& nCount) const { 452 int32_t& nCount) const {
470 PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(start); 453 PAGECHAR_INFO charinfo = m_CharList[start];
471 PAGECHAR_INFO charinfo2 = 454 PAGECHAR_INFO charinfo2 = m_CharList[start + nCount - 1];
472 *(PAGECHAR_INFO*)m_charList.GetAt(start + nCount - 1);
473 if (FPDFTEXT_CHAR_PIECE != charinfo.m_Flag && 455 if (FPDFTEXT_CHAR_PIECE != charinfo.m_Flag &&
474 FPDFTEXT_CHAR_PIECE != charinfo2.m_Flag) { 456 FPDFTEXT_CHAR_PIECE != charinfo2.m_Flag) {
475 return; 457 return;
476 } 458 }
477 if (FPDFTEXT_CHAR_PIECE == charinfo.m_Flag) { 459 if (FPDFTEXT_CHAR_PIECE == charinfo.m_Flag) {
478 PAGECHAR_INFO charinfo1 = charinfo; 460 PAGECHAR_INFO charinfo1 = charinfo;
479 int startIndex = start; 461 int startIndex = start;
480 while (FPDFTEXT_CHAR_PIECE == charinfo1.m_Flag && 462 while (FPDFTEXT_CHAR_PIECE == charinfo1.m_Flag &&
481 charinfo1.m_Index == charinfo.m_Index) { 463 charinfo1.m_Index == charinfo.m_Index) {
482 startIndex--; 464 startIndex--;
483 if (startIndex < 0) { 465 if (startIndex < 0) {
484 break; 466 break;
485 } 467 }
486 charinfo1 = *(PAGECHAR_INFO*)m_charList.GetAt(startIndex); 468 charinfo1 = m_CharList[startIndex];
487 } 469 }
488 startIndex++; 470 startIndex++;
489 start = startIndex; 471 start = startIndex;
490 } 472 }
491 if (FPDFTEXT_CHAR_PIECE == charinfo2.m_Flag) { 473 if (FPDFTEXT_CHAR_PIECE == charinfo2.m_Flag) {
492 PAGECHAR_INFO charinfo3 = charinfo2; 474 PAGECHAR_INFO charinfo3 = charinfo2;
493 int endIndex = start + nCount - 1; 475 int endIndex = start + nCount - 1;
494 while (FPDFTEXT_CHAR_PIECE == charinfo3.m_Flag && 476 while (FPDFTEXT_CHAR_PIECE == charinfo3.m_Flag &&
495 charinfo3.m_Index == charinfo2.m_Index) { 477 charinfo3.m_Index == charinfo2.m_Index) {
496 endIndex++; 478 endIndex++;
497 if (endIndex >= m_charList.GetSize()) { 479 if (endIndex >= pdfium::CollectionSize<int>(m_CharList)) {
498 break; 480 break;
499 } 481 }
500 charinfo3 = *(PAGECHAR_INFO*)m_charList.GetAt(endIndex); 482 charinfo3 = m_CharList[endIndex];
501 } 483 }
502 endIndex--; 484 endIndex--;
503 nCount = endIndex - start + 1; 485 nCount = endIndex - start + 1;
504 } 486 }
505 } 487 }
506 CFX_WideString CPDF_TextPage::GetPageText(int start, int nCount) const { 488 CFX_WideString CPDF_TextPage::GetPageText(int start, int nCount) const {
507 if (!m_bIsParsed || nCount == 0) 489 if (!m_bIsParsed || nCount == 0)
508 return L""; 490 return L"";
509 491
510 if (start < 0) 492 if (start < 0)
511 start = 0; 493 start = 0;
512 494
513 if (nCount == -1) { 495 if (nCount == -1) {
514 nCount = m_charList.GetSize() - start; 496 nCount = pdfium::CollectionSize<int>(m_CharList) - start;
515 return m_TextBuf.GetWideString().Mid(start, 497 return m_TextBuf.GetWideString().Mid(start,
516 m_TextBuf.GetWideString().GetLength()); 498 m_TextBuf.GetWideString().GetLength());
517 } 499 }
518 if (nCount <= 0 || m_charList.GetSize() <= 0) { 500 if (nCount <= 0 || m_CharList.empty()) {
519 return L""; 501 return L"";
520 } 502 }
521 if (nCount + start > m_charList.GetSize() - 1) { 503 if (nCount + start > pdfium::CollectionSize<int>(m_CharList) - 1) {
522 nCount = m_charList.GetSize() - start; 504 nCount = pdfium::CollectionSize<int>(m_CharList) - start;
523 } 505 }
524 if (nCount <= 0) { 506 if (nCount <= 0) {
525 return L""; 507 return L"";
526 } 508 }
527 CheckMarkedContentObject(start, nCount); 509 CheckMarkedContentObject(start, nCount);
528 int startindex = 0; 510 int startindex = 0;
529 PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(start); 511 PAGECHAR_INFO charinfo = m_CharList[start];
530 int startOffset = 0; 512 int startOffset = 0;
531 while (charinfo.m_Index == -1) { 513 while (charinfo.m_Index == -1) {
532 startOffset++; 514 startOffset++;
533 if (startOffset > nCount || start + startOffset >= m_charList.GetSize()) { 515 if (startOffset > nCount ||
516 start + startOffset >= pdfium::CollectionSize<int>(m_CharList)) {
534 return L""; 517 return L"";
535 } 518 }
536 charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(start + startOffset); 519 charinfo = m_CharList[start + startOffset];
537 } 520 }
538 startindex = charinfo.m_Index; 521 startindex = charinfo.m_Index;
539 charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(start + nCount - 1); 522 charinfo = m_CharList[start + nCount - 1];
540 int nCountOffset = 0; 523 int nCountOffset = 0;
541 while (charinfo.m_Index == -1) { 524 while (charinfo.m_Index == -1) {
542 nCountOffset++; 525 nCountOffset++;
543 if (nCountOffset >= nCount) { 526 if (nCountOffset >= nCount) {
544 return L""; 527 return L"";
545 } 528 }
546 charinfo = 529 charinfo = m_CharList[start + nCount - nCountOffset - 1];
547 *(PAGECHAR_INFO*)m_charList.GetAt(start + nCount - nCountOffset - 1);
548 } 530 }
549 nCount = start + nCount - nCountOffset - startindex; 531 nCount = start + nCount - nCountOffset - startindex;
550 if (nCount <= 0) { 532 if (nCount <= 0) {
551 return L""; 533 return L"";
552 } 534 }
553 return m_TextBuf.GetWideString().Mid(startindex, nCount); 535 return m_TextBuf.GetWideString().Mid(startindex, nCount);
554 } 536 }
555 int CPDF_TextPage::CountRects(int start, int nCount) { 537 int CPDF_TextPage::CountRects(int start, int nCount) {
556 if (!m_bIsParsed || start < 0) 538 if (!m_bIsParsed || start < 0)
557 return -1; 539 return -1;
558 540
559 if (nCount == -1 || nCount + start > m_charList.GetSize()) { 541 if (nCount == -1 ||
560 nCount = m_charList.GetSize() - start; 542 nCount + start > pdfium::CollectionSize<int>(m_CharList)) {
543 nCount = pdfium::CollectionSize<int>(m_CharList) - start;
561 } 544 }
562 m_SelRects.RemoveAll(); 545 m_SelRects.RemoveAll();
563 GetRectArray(start, nCount, m_SelRects); 546 GetRectArray(start, nCount, m_SelRects);
564 return m_SelRects.GetSize(); 547 return m_SelRects.GetSize();
565 } 548 }
566 void CPDF_TextPage::GetRect(int rectIndex, 549 void CPDF_TextPage::GetRect(int rectIndex,
567 FX_FLOAT& left, 550 FX_FLOAT& left,
568 FX_FLOAT& top, 551 FX_FLOAT& top,
569 FX_FLOAT& right, 552 FX_FLOAT& right,
570 FX_FLOAT& bottom) const { 553 FX_FLOAT& bottom) const {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 return FALSE; 625 return FALSE;
643 626
644 CFX_FloatRect rect = m_SelRects.GetAt(rectIndex); 627 CFX_FloatRect rect = m_SelRects.GetAt(rectIndex);
645 return GetBaselineRotate(rect, Rotate); 628 return GetBaselineRotate(rect, Rotate);
646 } 629 }
647 int CPDF_TextPage::CountBoundedSegments(FX_FLOAT left, 630 int CPDF_TextPage::CountBoundedSegments(FX_FLOAT left,
648 FX_FLOAT top, 631 FX_FLOAT top,
649 FX_FLOAT right, 632 FX_FLOAT right,
650 FX_FLOAT bottom, 633 FX_FLOAT bottom,
651 FX_BOOL bContains) { 634 FX_BOOL bContains) {
652 m_Segment.RemoveAll(); 635 m_Segments.RemoveAll();
653 if (!m_bIsParsed) 636 if (!m_bIsParsed)
654 return -1; 637 return -1;
655 638
656 CFX_FloatRect rect(left, bottom, right, top); 639 CFX_FloatRect rect(left, bottom, right, top);
657 rect.Normalize(); 640 rect.Normalize();
658 int nCount = m_charList.GetSize(); 641
659 int pos = 0;
660 FPDF_SEGMENT segment; 642 FPDF_SEGMENT segment;
661 segment.m_Start = 0; 643 segment.m_Start = 0;
662 segment.m_nCount = 0; 644 segment.m_nCount = 0;
645
646 int pos = 0;
663 int segmentStatus = 0; 647 int segmentStatus = 0;
664 FX_BOOL IsContainPreChar = FALSE; 648 FX_BOOL IsContainPreChar = FALSE;
665 while (pos < nCount) { 649 for (const auto& charinfo : m_CharList) {
666 PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(pos);
667 if (bContains && rect.Contains(charinfo.m_CharBox)) { 650 if (bContains && rect.Contains(charinfo.m_CharBox)) {
668 if (segmentStatus == 0 || segmentStatus == 2) { 651 if (segmentStatus == 0 || segmentStatus == 2) {
669 segment.m_Start = pos; 652 segment.m_Start = pos;
670 segment.m_nCount = 1; 653 segment.m_nCount = 1;
671 segmentStatus = 1; 654 segmentStatus = 1;
672 } else if (segmentStatus == 1) { 655 } else if (segmentStatus == 1) {
673 segment.m_nCount++; 656 segment.m_nCount++;
674 } 657 }
675 IsContainPreChar = TRUE; 658 IsContainPreChar = TRUE;
676 } else if (!bContains && 659 } else if (!bContains &&
(...skipping 13 matching lines...) Expand all
690 segment.m_Start = pos; 673 segment.m_Start = pos;
691 segment.m_nCount = 1; 674 segment.m_nCount = 1;
692 segmentStatus = 1; 675 segmentStatus = 1;
693 } else if (segmentStatus == 1) { 676 } else if (segmentStatus == 1) {
694 segment.m_nCount++; 677 segment.m_nCount++;
695 } 678 }
696 IsContainPreChar = FALSE; 679 IsContainPreChar = FALSE;
697 } else { 680 } else {
698 if (segmentStatus == 1) { 681 if (segmentStatus == 1) {
699 segmentStatus = 2; 682 segmentStatus = 2;
700 m_Segment.Add(segment); 683 m_Segments.Add(segment);
701 segment.m_Start = 0; 684 segment.m_Start = 0;
702 segment.m_nCount = 0; 685 segment.m_nCount = 0;
703 } 686 }
704 } 687 }
705 } else { 688 } else {
706 if (segmentStatus == 1) { 689 if (segmentStatus == 1) {
707 segmentStatus = 2; 690 segmentStatus = 2;
708 m_Segment.Add(segment); 691 m_Segments.Add(segment);
709 segment.m_Start = 0; 692 segment.m_Start = 0;
710 segment.m_nCount = 0; 693 segment.m_nCount = 0;
711 } 694 }
712 IsContainPreChar = FALSE; 695 IsContainPreChar = FALSE;
713 } 696 }
714 pos++; 697 pos++;
715 } 698 }
716 if (segmentStatus == 1) { 699 if (segmentStatus == 1) {
717 segmentStatus = 2; 700 segmentStatus = 2;
718 m_Segment.Add(segment); 701 m_Segments.Add(segment);
719 segment.m_Start = 0; 702 segment.m_Start = 0;
720 segment.m_nCount = 0; 703 segment.m_nCount = 0;
721 } 704 }
722 return m_Segment.GetSize(); 705 return m_Segments.GetSize();
723 } 706 }
724 void CPDF_TextPage::GetBoundedSegment(int index, int& start, int& count) const { 707 void CPDF_TextPage::GetBoundedSegment(int index, int& start, int& count) const {
725 if (index < 0 || index >= m_Segment.GetSize()) { 708 if (index < 0 || index >= m_Segments.GetSize()) {
726 return; 709 return;
727 } 710 }
728 start = m_Segment.GetAt(index).m_Start; 711 start = m_Segments.GetAt(index).m_Start;
729 count = m_Segment.GetAt(index).m_nCount; 712 count = m_Segments.GetAt(index).m_nCount;
730 } 713 }
731 int CPDF_TextPage::GetWordBreak(int index, int direction) const { 714 int CPDF_TextPage::GetWordBreak(int index, int direction) const {
732 if (!m_bIsParsed) 715 if (!m_bIsParsed)
733 return -1; 716 return -1;
734 717
735 if (direction != FPDFTEXT_LEFT && direction != FPDFTEXT_RIGHT) 718 if (direction != FPDFTEXT_LEFT && direction != FPDFTEXT_RIGHT)
736 return -1; 719 return -1;
737 720
738 if (index < 0 || index >= m_charList.GetSize()) 721 if (index < 0 || index >= pdfium::CollectionSize<int>(m_CharList))
739 return -1; 722 return -1;
740 723
741 PAGECHAR_INFO charinfo; 724 const PAGECHAR_INFO& charinfo = m_CharList[index];
742 charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(index);
743 if (charinfo.m_Index == -1 || charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) { 725 if (charinfo.m_Index == -1 || charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) {
744 return index; 726 return index;
745 } 727 }
746 if (!IsLetter(charinfo.m_Unicode)) { 728 if (!IsLetter(charinfo.m_Unicode)) {
747 return index; 729 return index;
748 } 730 }
749 int breakPos = index; 731 int breakPos = index;
750 if (direction == FPDFTEXT_LEFT) { 732 if (direction == FPDFTEXT_LEFT) {
751 while (--breakPos > 0) { 733 while (--breakPos > 0) {
752 charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(breakPos); 734 if (!IsLetter(m_CharList[breakPos].m_Unicode))
753 if (!IsLetter(charinfo.m_Unicode)) { 735 break;
754 return breakPos;
755 }
756 } 736 }
757 } else if (direction == FPDFTEXT_RIGHT) { 737 } else if (direction == FPDFTEXT_RIGHT) {
758 while (++breakPos < m_charList.GetSize()) { 738 while (++breakPos < pdfium::CollectionSize<int>(m_CharList)) {
759 charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(breakPos); 739 if (!IsLetter(m_CharList[breakPos].m_Unicode))
760 if (!IsLetter(charinfo.m_Unicode)) { 740 break;
761 return breakPos;
762 }
763 } 741 }
764 } 742 }
765 return breakPos; 743 return breakPos;
766 } 744 }
767 int32_t CPDF_TextPage::FindTextlineFlowDirection() { 745 int32_t CPDF_TextPage::FindTextlineFlowDirection() {
768 if (!m_pPage) { 746 if (!m_pPage) {
769 return -1; 747 return -1;
770 } 748 }
771 const int32_t nPageWidth = (int32_t)((CPDF_Page*)m_pPage)->GetPageWidth(); 749 const int32_t nPageWidth = (int32_t)((CPDF_Page*)m_pPage)->GetPageWidth();
772 const int32_t nPageHeight = (int32_t)((CPDF_Page*)m_pPage)->GetPageHeight(); 750 const int32_t nPageHeight = (int32_t)((CPDF_Page*)m_pPage)->GetPageHeight();
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 } 920 }
943 } 921 }
944 return w; 922 return w;
945 } 923 }
946 void CPDF_TextPage::OnPiece(CFX_BidiChar* pBidi, CFX_WideString& str) { 924 void CPDF_TextPage::OnPiece(CFX_BidiChar* pBidi, CFX_WideString& str) {
947 int32_t start, count; 925 int32_t start, count;
948 CFX_BidiChar::Direction ret = pBidi->GetBidiInfo(&start, &count); 926 CFX_BidiChar::Direction ret = pBidi->GetBidiInfo(&start, &count);
949 if (ret == CFX_BidiChar::RIGHT) { 927 if (ret == CFX_BidiChar::RIGHT) {
950 for (int i = start + count - 1; i >= start; i--) { 928 for (int i = start + count - 1; i >= start; i--) {
951 m_TextBuf.AppendChar(str.GetAt(i)); 929 m_TextBuf.AppendChar(str.GetAt(i));
952 m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); 930 m_CharList.push_back(m_TempCharList[i]);
953 } 931 }
954 } else { 932 } else {
955 int end = start + count; 933 int end = start + count;
956 for (int i = start; i < end; i++) { 934 for (int i = start; i < end; i++) {
957 m_TextBuf.AppendChar(str.GetAt(i)); 935 m_TextBuf.AppendChar(str.GetAt(i));
958 m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); 936 m_CharList.push_back(m_TempCharList[i]);
959 } 937 }
960 } 938 }
961 } 939 }
962 void CPDF_TextPage::AddCharInfoByLRDirection(CFX_WideString& str, int i) { 940 void CPDF_TextPage::AddCharInfoByLRDirection(CFX_WideString& str, int i) {
963 PAGECHAR_INFO Info = *(PAGECHAR_INFO*)m_TempCharList.GetAt(i); 941 PAGECHAR_INFO info = m_TempCharList[i];
964 FX_WCHAR wChar = str.GetAt(i); 942 FX_WCHAR wChar = str.GetAt(i);
965 if (!IsControlChar(Info)) { 943 if (!IsControlChar(info)) {
966 Info.m_Index = m_TextBuf.GetLength(); 944 info.m_Index = m_TextBuf.GetLength();
967 if (wChar >= 0xFB00 && wChar <= 0xFB06) { 945 if (wChar >= 0xFB00 && wChar <= 0xFB06) {
968 FX_WCHAR* pDst = NULL; 946 FX_WCHAR* pDst = NULL;
969 FX_STRSIZE nCount = FX_Unicode_GetNormalization(wChar, pDst); 947 FX_STRSIZE nCount = FX_Unicode_GetNormalization(wChar, pDst);
970 if (nCount >= 1) { 948 if (nCount >= 1) {
971 pDst = FX_Alloc(FX_WCHAR, nCount); 949 pDst = FX_Alloc(FX_WCHAR, nCount);
972 FX_Unicode_GetNormalization(wChar, pDst); 950 FX_Unicode_GetNormalization(wChar, pDst);
973 for (int nIndex = 0; nIndex < nCount; nIndex++) { 951 for (int nIndex = 0; nIndex < nCount; nIndex++) {
974 PAGECHAR_INFO Info2 = Info; 952 PAGECHAR_INFO info2 = info;
975 Info2.m_Unicode = pDst[nIndex]; 953 info2.m_Unicode = pDst[nIndex];
976 Info2.m_Flag = FPDFTEXT_CHAR_PIECE; 954 info2.m_Flag = FPDFTEXT_CHAR_PIECE;
977 m_TextBuf.AppendChar(Info2.m_Unicode); 955 m_TextBuf.AppendChar(info2.m_Unicode);
978 m_charList.Add(Info2); 956 m_CharList.push_back(info2);
979 } 957 }
980 FX_Free(pDst); 958 FX_Free(pDst);
981 return; 959 return;
982 } 960 }
983 } 961 }
984 m_TextBuf.AppendChar(wChar); 962 m_TextBuf.AppendChar(wChar);
985 } else { 963 } else {
986 Info.m_Index = -1; 964 info.m_Index = -1;
987 } 965 }
988 m_charList.Add(Info); 966 m_CharList.push_back(info);
989 } 967 }
990 void CPDF_TextPage::AddCharInfoByRLDirection(CFX_WideString& str, int i) { 968 void CPDF_TextPage::AddCharInfoByRLDirection(CFX_WideString& str, int i) {
991 PAGECHAR_INFO Info = *(PAGECHAR_INFO*)m_TempCharList.GetAt(i); 969 PAGECHAR_INFO info = m_TempCharList[i];
992 if (!IsControlChar(Info)) { 970 if (!IsControlChar(info)) {
993 Info.m_Index = m_TextBuf.GetLength(); 971 info.m_Index = m_TextBuf.GetLength();
994 FX_WCHAR wChar = FX_GetMirrorChar(str.GetAt(i), TRUE, FALSE); 972 FX_WCHAR wChar = FX_GetMirrorChar(str.GetAt(i), TRUE, FALSE);
995 FX_WCHAR* pDst = NULL; 973 FX_WCHAR* pDst = NULL;
996 FX_STRSIZE nCount = FX_Unicode_GetNormalization(wChar, pDst); 974 FX_STRSIZE nCount = FX_Unicode_GetNormalization(wChar, pDst);
997 if (nCount >= 1) { 975 if (nCount >= 1) {
998 pDst = FX_Alloc(FX_WCHAR, nCount); 976 pDst = FX_Alloc(FX_WCHAR, nCount);
999 FX_Unicode_GetNormalization(wChar, pDst); 977 FX_Unicode_GetNormalization(wChar, pDst);
1000 for (int nIndex = 0; nIndex < nCount; nIndex++) { 978 for (int nIndex = 0; nIndex < nCount; nIndex++) {
1001 PAGECHAR_INFO Info2 = Info; 979 PAGECHAR_INFO info2 = info;
1002 Info2.m_Unicode = pDst[nIndex]; 980 info2.m_Unicode = pDst[nIndex];
1003 Info2.m_Flag = FPDFTEXT_CHAR_PIECE; 981 info2.m_Flag = FPDFTEXT_CHAR_PIECE;
1004 m_TextBuf.AppendChar(Info2.m_Unicode); 982 m_TextBuf.AppendChar(info2.m_Unicode);
1005 m_charList.Add(Info2); 983 m_CharList.push_back(info2);
1006 } 984 }
1007 FX_Free(pDst); 985 FX_Free(pDst);
1008 return; 986 return;
1009 } 987 }
1010 Info.m_Unicode = wChar; 988 info.m_Unicode = wChar;
1011 m_TextBuf.AppendChar(Info.m_Unicode); 989 m_TextBuf.AppendChar(info.m_Unicode);
1012 } else { 990 } else {
1013 Info.m_Index = -1; 991 info.m_Index = -1;
1014 } 992 }
1015 m_charList.Add(Info); 993 m_CharList.push_back(info);
1016 } 994 }
1017 void CPDF_TextPage::CloseTempLine() { 995 void CPDF_TextPage::CloseTempLine() {
1018 int count1 = m_TempCharList.GetSize(); 996 if (m_TempCharList.empty()) {
1019 if (count1 <= 0) {
1020 return; 997 return;
1021 } 998 }
1022 std::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar); 999 std::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar);
1023 CFX_WideString str = m_TempTextBuf.GetWideString(); 1000 CFX_WideString str = m_TempTextBuf.GetWideString();
1024 CFX_WordArray order; 1001 CFX_WordArray order;
1025 FX_BOOL bR2L = FALSE; 1002 FX_BOOL bR2L = FALSE;
1026 int32_t start = 0, count = 0; 1003 int32_t start = 0, count = 0;
1027 int nR2L = 0, nL2R = 0; 1004 int nR2L = 0, nL2R = 0;
1028 FX_BOOL bPrevSpace = FALSE; 1005 FX_BOOL bPrevSpace = FALSE;
1029 for (int i = 0; i < str.GetLength(); i++) { 1006 for (int i = 0; i < str.GetLength(); i++) {
1030 if (str.GetAt(i) == 32) { 1007 if (str.GetAt(i) == 32) {
1031 if (bPrevSpace) { 1008 if (bPrevSpace) {
1032 m_TempTextBuf.Delete(i, 1); 1009 m_TempTextBuf.Delete(i, 1);
1033 m_TempCharList.Delete(i); 1010 m_TempCharList.erase(m_TempCharList.begin() + i);
1034 str.Delete(i); 1011 str.Delete(i);
1035 count1--;
1036 i--; 1012 i--;
1037 continue; 1013 continue;
1038 } 1014 }
1039 bPrevSpace = TRUE; 1015 bPrevSpace = TRUE;
1040 } else { 1016 } else {
1041 bPrevSpace = FALSE; 1017 bPrevSpace = FALSE;
1042 } 1018 }
1043 if (pBidiChar->AppendChar(str.GetAt(i))) { 1019 if (pBidiChar->AppendChar(str.GetAt(i))) {
1044 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count); 1020 CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count);
1045 order.Add(start); 1021 order.Add(start);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 break; 1102 break;
1127 } else { 1103 } else {
1128 j += 3; 1104 j += 3;
1129 } 1105 }
1130 } 1106 }
1131 if (j == 3) { 1107 if (j == 3) {
1132 i = -3; 1108 i = -3;
1133 bL2R = TRUE; 1109 bL2R = TRUE;
1134 continue; 1110 continue;
1135 } 1111 }
1136 int end = m_TempCharList.GetSize() - 1; 1112 int end = pdfium::CollectionSize<int>(m_TempCharList) - 1;
1137 if (j < count) { 1113 if (j < count) {
1138 end = order.GetAt(j) - 1; 1114 end = order.GetAt(j) - 1;
1139 } 1115 }
1140 i = j - 3; 1116 i = j - 3;
1141 for (int n = end; n >= start; n--) { 1117 for (int n = end; n >= start; n--) {
1142 AddCharInfoByRLDirection(str, n); 1118 AddCharInfoByRLDirection(str, n);
1143 } 1119 }
1144 } else { 1120 } else {
1145 int end = start + count1; 1121 int end = start + count1;
1146 for (int n = start; n < end; n++) { 1122 for (int n = start; n < end; n++) {
1147 AddCharInfoByLRDirection(str, n); 1123 AddCharInfoByLRDirection(str, n);
1148 } 1124 }
1149 } 1125 }
1150 } 1126 }
1151 } 1127 }
1152 order.RemoveAll(); 1128 order.RemoveAll();
1153 m_TempCharList.RemoveAll(); 1129 m_TempCharList.clear();
1154 m_TempTextBuf.Delete(0, m_TempTextBuf.GetLength()); 1130 m_TempTextBuf.Delete(0, m_TempTextBuf.GetLength());
1155 } 1131 }
1156 void CPDF_TextPage::ProcessTextObject(CPDF_TextObject* pTextObj, 1132 void CPDF_TextPage::ProcessTextObject(CPDF_TextObject* pTextObj,
1157 const CFX_Matrix& formMatrix, 1133 const CFX_Matrix& formMatrix,
1158 FX_POSITION ObjPos) { 1134 FX_POSITION ObjPos) {
1159 CFX_FloatRect re(pTextObj->m_Left, pTextObj->m_Bottom, pTextObj->m_Right, 1135 CFX_FloatRect re(pTextObj->m_Left, pTextObj->m_Bottom, pTextObj->m_Right,
1160 pTextObj->m_Top); 1136 pTextObj->m_Top);
1161 if (FXSYS_fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f) { 1137 if (FXSYS_fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f) {
1162 return; 1138 return;
1163 } 1139 }
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 charinfo.m_Unicode = wChar; 1336 charinfo.m_Unicode = wChar;
1361 charinfo.m_CharCode = pFont->CharCodeFromUnicode(wChar); 1337 charinfo.m_CharCode = pFont->CharCodeFromUnicode(wChar);
1362 charinfo.m_Flag = FPDFTEXT_CHAR_PIECE; 1338 charinfo.m_Flag = FPDFTEXT_CHAR_PIECE;
1363 charinfo.m_pTextObj = pTextObj; 1339 charinfo.m_pTextObj = pTextObj;
1364 charinfo.m_CharBox.top = charBox.top; 1340 charinfo.m_CharBox.top = charBox.top;
1365 charinfo.m_CharBox.left = charBox.left; 1341 charinfo.m_CharBox.left = charBox.left;
1366 charinfo.m_CharBox.right = charBox.right; 1342 charinfo.m_CharBox.right = charBox.right;
1367 charinfo.m_CharBox.bottom = charBox.bottom; 1343 charinfo.m_CharBox.bottom = charBox.bottom;
1368 charinfo.m_Matrix.Copy(matrix); 1344 charinfo.m_Matrix.Copy(matrix);
1369 m_TempTextBuf.AppendChar(wChar); 1345 m_TempTextBuf.AppendChar(wChar);
1370 m_TempCharList.Add(charinfo); 1346 m_TempCharList.push_back(charinfo);
1371 } 1347 }
1372 } 1348 }
1373 void CPDF_TextPage::FindPreviousTextObject(void) { 1349 void CPDF_TextPage::FindPreviousTextObject() {
1374 if (m_TempCharList.GetSize() < 1 && m_charList.GetSize() < 1) { 1350 if (m_TempCharList.empty() && m_CharList.empty())
1375 return; 1351 return;
1376 } 1352
1377 PAGECHAR_INFO preChar; 1353 PAGECHAR_INFO preChar =
1378 if (m_TempCharList.GetSize() >= 1) { 1354 m_TempCharList.empty() ? m_CharList.back() : m_TempCharList.back();
1379 preChar = 1355
1380 *(PAGECHAR_INFO*)m_TempCharList.GetAt(m_TempCharList.GetSize() - 1); 1356 if (preChar.m_pTextObj)
1381 } else {
1382 preChar = *(PAGECHAR_INFO*)m_charList.GetAt(m_charList.GetSize() - 1);
1383 }
1384 if (preChar.m_pTextObj) {
1385 m_pPreTextObj = preChar.m_pTextObj; 1357 m_pPreTextObj = preChar.m_pTextObj;
1386 }
1387 } 1358 }
1388 void CPDF_TextPage::SwapTempTextBuf(int32_t iCharListStartAppend, 1359 void CPDF_TextPage::SwapTempTextBuf(int32_t iCharListStartAppend,
1389 int32_t iBufStartAppend) { 1360 int32_t iBufStartAppend) {
1390 int32_t i, j; 1361 int32_t i = iCharListStartAppend;
1391 i = iCharListStartAppend; 1362 int32_t j = pdfium::CollectionSize<int32_t>(m_TempCharList) - 1;
1392 j = m_TempCharList.GetSize() - 1;
1393 for (; i < j; i++, j--) { 1363 for (; i < j; i++, j--) {
1394 std::swap(m_TempCharList[i], m_TempCharList[j]); 1364 std::swap(m_TempCharList[i], m_TempCharList[j]);
1395 std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index); 1365 std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index);
1396 } 1366 }
1397 FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer(); 1367 FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer();
1398 i = iBufStartAppend; 1368 i = iBufStartAppend;
1399 j = m_TempTextBuf.GetLength() - 1; 1369 j = m_TempTextBuf.GetLength() - 1;
1400 for (; i < j; i++, j--) { 1370 for (; i < j; i++, j--) {
1401 std::swap(pTempBuffer[i], pTempBuffer[j]); 1371 std::swap(pTempBuffer[i], pTempBuffer[j]);
1402 } 1372 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, 1439 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom,
1470 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top)); 1440 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top));
1471 } 1441 }
1472 PAGECHAR_INFO generateChar; 1442 PAGECHAR_INFO generateChar;
1473 if (result == 1) { 1443 if (result == 1) {
1474 if (GenerateCharInfo(TEXT_BLANK_CHAR, generateChar)) { 1444 if (GenerateCharInfo(TEXT_BLANK_CHAR, generateChar)) {
1475 if (!formMatrix.IsIdentity()) { 1445 if (!formMatrix.IsIdentity()) {
1476 generateChar.m_Matrix.Copy(formMatrix); 1446 generateChar.m_Matrix.Copy(formMatrix);
1477 } 1447 }
1478 m_TempTextBuf.AppendChar(TEXT_BLANK_CHAR); 1448 m_TempTextBuf.AppendChar(TEXT_BLANK_CHAR);
1479 m_TempCharList.Add(generateChar); 1449 m_TempCharList.push_back(generateChar);
1480 } 1450 }
1481 } else if (result == 2) { 1451 } else if (result == 2) {
1482 CloseTempLine(); 1452 CloseTempLine();
1483 if (m_TextBuf.GetSize()) { 1453 if (m_TextBuf.GetSize()) {
1484 if (GenerateCharInfo(TEXT_RETURN_CHAR, generateChar)) { 1454 if (GenerateCharInfo(TEXT_RETURN_CHAR, generateChar)) {
1485 m_TextBuf.AppendChar(TEXT_RETURN_CHAR); 1455 m_TextBuf.AppendChar(TEXT_RETURN_CHAR);
1486 if (!formMatrix.IsIdentity()) { 1456 if (!formMatrix.IsIdentity()) {
1487 generateChar.m_Matrix.Copy(formMatrix); 1457 generateChar.m_Matrix.Copy(formMatrix);
1488 } 1458 }
1489 m_charList.Add(generateChar); 1459 m_CharList.push_back(generateChar);
1490 } 1460 }
1491 if (GenerateCharInfo(TEXT_LINEFEED_CHAR, generateChar)) { 1461 if (GenerateCharInfo(TEXT_LINEFEED_CHAR, generateChar)) {
1492 m_TextBuf.AppendChar(TEXT_LINEFEED_CHAR); 1462 m_TextBuf.AppendChar(TEXT_LINEFEED_CHAR);
1493 if (!formMatrix.IsIdentity()) { 1463 if (!formMatrix.IsIdentity()) {
1494 generateChar.m_Matrix.Copy(formMatrix); 1464 generateChar.m_Matrix.Copy(formMatrix);
1495 } 1465 }
1496 m_charList.Add(generateChar); 1466 m_CharList.push_back(generateChar);
1497 } 1467 }
1498 } 1468 }
1499 } else if (result == 3) { 1469 } else if (result == 3) {
1500 int32_t nChars = pTextObj->CountChars(); 1470 int32_t nChars = pTextObj->CountChars();
1501 if (nChars == 1) { 1471 if (nChars == 1) {
1502 CPDF_TextObjectItem item; 1472 CPDF_TextObjectItem item;
1503 pTextObj->GetCharInfo(0, &item); 1473 pTextObj->GetCharInfo(0, &item);
1504 CFX_WideString wstrItem = 1474 CFX_WideString wstrItem =
1505 pTextObj->GetFont()->UnicodeFromCharCode(item.m_CharCode); 1475 pTextObj->GetFont()->UnicodeFromCharCode(item.m_CharCode);
1506 if (wstrItem.IsEmpty()) { 1476 if (wstrItem.IsEmpty()) {
1507 wstrItem += (FX_WCHAR)item.m_CharCode; 1477 wstrItem += (FX_WCHAR)item.m_CharCode;
1508 } 1478 }
1509 FX_WCHAR curChar = wstrItem.GetAt(0); 1479 FX_WCHAR curChar = wstrItem.GetAt(0);
1510 if (0x2D == curChar || 0xAD == curChar) { 1480 if (0x2D == curChar || 0xAD == curChar) {
1511 return; 1481 return;
1512 } 1482 }
1513 } 1483 }
1514 while (m_TempTextBuf.GetSize() > 0 && 1484 while (m_TempTextBuf.GetSize() > 0 &&
1515 m_TempTextBuf.GetWideString().GetAt(m_TempTextBuf.GetLength() - 1485 m_TempTextBuf.GetWideString().GetAt(m_TempTextBuf.GetLength() -
1516 1) == 0x20) { 1486 1) == 0x20) {
1517 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); 1487 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1);
1518 m_TempCharList.Delete(m_TempCharList.GetSize() - 1); 1488 m_TempCharList.pop_back();
1519 } 1489 }
1520 PAGECHAR_INFO* cha = 1490 PAGECHAR_INFO* charinfo = &m_TempCharList.back();
1521 (PAGECHAR_INFO*)m_TempCharList.GetAt(m_TempCharList.GetSize() - 1);
1522 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); 1491 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1);
1523 cha->m_Unicode = 0x2; 1492 charinfo->m_Unicode = 0x2;
1524 cha->m_Flag = FPDFTEXT_CHAR_HYPHEN; 1493 charinfo->m_Flag = FPDFTEXT_CHAR_HYPHEN;
1525 m_TempTextBuf.AppendChar(0xfffe); 1494 m_TempTextBuf.AppendChar(0xfffe);
1526 } 1495 }
1527 } else { 1496 } else {
1528 m_CurlineRect = 1497 m_CurlineRect =
1529 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom, 1498 CFX_FloatRect(Obj.m_pTextObj->m_Left, Obj.m_pTextObj->m_Bottom,
1530 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top); 1499 Obj.m_pTextObj->m_Right, Obj.m_pTextObj->m_Top);
1531 } 1500 }
1532 if (FPDFTEXT_MC_DELAY == bPreMKC) { 1501 if (FPDFTEXT_MC_DELAY == bPreMKC) {
1533 ProcessMarkedContent(Obj); 1502 ProcessMarkedContent(Obj);
1534 m_pPreTextObj = pTextObj; 1503 m_pPreTextObj = pTextObj;
1535 m_perMatrix.Copy(formMatrix); 1504 m_perMatrix.Copy(formMatrix);
1536 return; 1505 return;
1537 } 1506 }
1538 m_pPreTextObj = pTextObj; 1507 m_pPreTextObj = pTextObj;
1539 m_perMatrix.Copy(formMatrix); 1508 m_perMatrix.Copy(formMatrix);
1540 int nItems = pTextObj->CountItems(); 1509 int nItems = pTextObj->CountItems();
1541 FX_FLOAT baseSpace = _CalculateBaseSpace(pTextObj, matrix); 1510 FX_FLOAT baseSpace = _CalculateBaseSpace(pTextObj, matrix);
1542 1511
1543 const FX_BOOL bR2L = IsRightToLeft(pTextObj, pFont, nItems); 1512 const FX_BOOL bR2L = IsRightToLeft(pTextObj, pFont, nItems);
1544 const FX_BOOL bIsBidiAndMirrorInverse = 1513 const FX_BOOL bIsBidiAndMirrorInverse =
1545 bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0; 1514 bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0;
1546 int32_t iBufStartAppend = m_TempTextBuf.GetLength(); 1515 int32_t iBufStartAppend = m_TempTextBuf.GetLength();
1547 int32_t iCharListStartAppend = m_TempCharList.GetSize(); 1516 int32_t iCharListStartAppend =
1517 pdfium::CollectionSize<int32_t>(m_TempCharList);
1548 1518
1549 FX_FLOAT spacing = 0; 1519 FX_FLOAT spacing = 0;
1550 for (int i = 0; i < nItems; i++) { 1520 for (int i = 0; i < nItems; i++) {
1551 CPDF_TextObjectItem item; 1521 CPDF_TextObjectItem item;
1552 PAGECHAR_INFO charinfo; 1522 PAGECHAR_INFO charinfo;
1553 charinfo.m_OriginX = 0; 1523 charinfo.m_OriginX = 0;
1554 charinfo.m_OriginY = 0; 1524 charinfo.m_OriginY = 0;
1555 pTextObj->GetItemInfo(i, &item); 1525 pTextObj->GetItemInfo(i, &item);
1556 if (item.m_CharCode == (FX_DWORD)-1) { 1526 if (item.m_CharCode == (FX_DWORD)-1) {
1557 CFX_WideString str = m_TempTextBuf.GetWideString(); 1527 CFX_WideString str = m_TempTextBuf.GetWideString();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 charinfo.m_pTextObj = pTextObj; 1569 charinfo.m_pTextObj = pTextObj;
1600 charinfo.m_Index = m_TextBuf.GetLength(); 1570 charinfo.m_Index = m_TextBuf.GetLength();
1601 m_TempTextBuf.AppendChar(TEXT_BLANK_CHAR); 1571 m_TempTextBuf.AppendChar(TEXT_BLANK_CHAR);
1602 charinfo.m_CharCode = -1; 1572 charinfo.m_CharCode = -1;
1603 charinfo.m_Matrix.Copy(formMatrix); 1573 charinfo.m_Matrix.Copy(formMatrix);
1604 matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX, 1574 matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX,
1605 charinfo.m_OriginY); 1575 charinfo.m_OriginY);
1606 charinfo.m_CharBox = 1576 charinfo.m_CharBox =
1607 CFX_FloatRect(charinfo.m_OriginX, charinfo.m_OriginY, 1577 CFX_FloatRect(charinfo.m_OriginX, charinfo.m_OriginY,
1608 charinfo.m_OriginX, charinfo.m_OriginY); 1578 charinfo.m_OriginX, charinfo.m_OriginY);
1609 m_TempCharList.Add(charinfo); 1579 m_TempCharList.push_back(charinfo);
1610 } 1580 }
1611 if (item.m_CharCode == (FX_DWORD)-1) { 1581 if (item.m_CharCode == (FX_DWORD)-1) {
1612 continue; 1582 continue;
1613 } 1583 }
1614 } 1584 }
1615 spacing = 0; 1585 spacing = 0;
1616 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); 1586 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode);
1617 FX_BOOL bNoUnicode = FALSE; 1587 FX_BOOL bNoUnicode = FALSE;
1618 FX_WCHAR wChar = wstrItem.GetAt(0); 1588 FX_WCHAR wChar = wstrItem.GetAt(0);
1619 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { 1589 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 charinfo.m_CharBox.bottom + pTextObj->GetFontSize(); 1621 charinfo.m_CharBox.bottom + pTextObj->GetFontSize();
1652 } 1622 }
1653 if (fabsf(charinfo.m_CharBox.right - charinfo.m_CharBox.left) < 0.01f) { 1623 if (fabsf(charinfo.m_CharBox.right - charinfo.m_CharBox.left) < 0.01f) {
1654 charinfo.m_CharBox.right = 1624 charinfo.m_CharBox.right =
1655 charinfo.m_CharBox.left + pTextObj->GetCharWidth(charinfo.m_CharCode); 1625 charinfo.m_CharBox.left + pTextObj->GetCharWidth(charinfo.m_CharCode);
1656 } 1626 }
1657 matrix.TransformRect(charinfo.m_CharBox); 1627 matrix.TransformRect(charinfo.m_CharBox);
1658 charinfo.m_Matrix.Copy(matrix); 1628 charinfo.m_Matrix.Copy(matrix);
1659 if (wstrItem.IsEmpty()) { 1629 if (wstrItem.IsEmpty()) {
1660 charinfo.m_Unicode = 0; 1630 charinfo.m_Unicode = 0;
1661 m_TempCharList.Add(charinfo); 1631 m_TempCharList.push_back(charinfo);
1662 m_TempTextBuf.AppendChar(0xfffe); 1632 m_TempTextBuf.AppendChar(0xfffe);
1663 continue; 1633 continue;
1664 } else { 1634 } else {
1665 int nTotal = wstrItem.GetLength(); 1635 int nTotal = wstrItem.GetLength();
1666 FX_BOOL bDel = FALSE; 1636 FX_BOOL bDel = FALSE;
1667 const int count = std::min(m_TempCharList.GetSize(), 7); 1637 const int count =
1638 std::min(pdfium::CollectionSize<int>(m_TempCharList), 7);
1668 FX_FLOAT threshold = charinfo.m_Matrix.TransformXDistance( 1639 FX_FLOAT threshold = charinfo.m_Matrix.TransformXDistance(
1669 (FX_FLOAT)TEXT_CHARRATIO_GAPDELTA * pTextObj->GetFontSize()); 1640 (FX_FLOAT)TEXT_CHARRATIO_GAPDELTA * pTextObj->GetFontSize());
1670 for (int n = m_TempCharList.GetSize(); 1641 for (int n = pdfium::CollectionSize<int>(m_TempCharList);
1671 n > m_TempCharList.GetSize() - count; n--) { 1642 n > pdfium::CollectionSize<int>(m_TempCharList) - count; n--) {
1672 PAGECHAR_INFO* charinfo1 = (PAGECHAR_INFO*)m_TempCharList.GetAt(n - 1); 1643 const PAGECHAR_INFO& charinfo1 = m_TempCharList[n - 1];
1673 if (charinfo1->m_CharCode == charinfo.m_CharCode && 1644 if (charinfo1.m_CharCode == charinfo.m_CharCode &&
1674 charinfo1->m_pTextObj->GetFont() == 1645 charinfo1.m_pTextObj->GetFont() == charinfo.m_pTextObj->GetFont() &&
1675 charinfo.m_pTextObj->GetFont() && 1646 FXSYS_fabs(charinfo1.m_OriginX - charinfo.m_OriginX) < threshold &&
1676 FXSYS_fabs(charinfo1->m_OriginX - charinfo.m_OriginX) < threshold && 1647 FXSYS_fabs(charinfo1.m_OriginY - charinfo.m_OriginY) < threshold) {
1677 FXSYS_fabs(charinfo1->m_OriginY - charinfo.m_OriginY) < threshold) {
1678 bDel = TRUE; 1648 bDel = TRUE;
1679 break; 1649 break;
1680 } 1650 }
1681 } 1651 }
1682 if (!bDel) { 1652 if (!bDel) {
1683 for (int nIndex = 0; nIndex < nTotal; nIndex++) { 1653 for (int nIndex = 0; nIndex < nTotal; nIndex++) {
1684 charinfo.m_Unicode = wstrItem.GetAt(nIndex); 1654 charinfo.m_Unicode = wstrItem.GetAt(nIndex);
1685 if (charinfo.m_Unicode) { 1655 if (charinfo.m_Unicode) {
1686 charinfo.m_Index = m_TextBuf.GetLength(); 1656 charinfo.m_Index = m_TextBuf.GetLength();
1687 m_TempTextBuf.AppendChar(charinfo.m_Unicode); 1657 m_TempTextBuf.AppendChar(charinfo.m_Unicode);
1688 } else { 1658 } else {
1689 m_TempTextBuf.AppendChar(0xfffe); 1659 m_TempTextBuf.AppendChar(0xfffe);
1690 } 1660 }
1691 m_TempCharList.Add(charinfo); 1661 m_TempCharList.push_back(charinfo);
1692 } 1662 }
1693 } else if (i == 0) { 1663 } else if (i == 0) {
1694 CFX_WideString str = m_TempTextBuf.GetWideString(); 1664 CFX_WideString str = m_TempTextBuf.GetWideString();
1695 if (!str.IsEmpty() && 1665 if (!str.IsEmpty() &&
1696 str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) { 1666 str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) {
1697 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); 1667 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1);
1698 m_TempCharList.Delete(m_TempCharList.GetSize() - 1); 1668 m_TempCharList.pop_back();
1699 } 1669 }
1700 } 1670 }
1701 } 1671 }
1702 } 1672 }
1703 if (bIsBidiAndMirrorInverse) { 1673 if (bIsBidiAndMirrorInverse) {
1704 SwapTempTextBuf(iCharListStartAppend, iBufStartAppend); 1674 SwapTempTextBuf(iCharListStartAppend, iBufStartAppend);
1705 } 1675 }
1706 } 1676 }
1707 int32_t CPDF_TextPage::GetTextObjectWritingMode( 1677 int32_t CPDF_TextPage::GetTextObjectWritingMode(
1708 const CPDF_TextObject* pTextObj) { 1678 const CPDF_TextObject* pTextObj) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 if (0x2D == wcTmp || 0xAD == wcTmp) { 1717 if (0x2D == wcTmp || 0xAD == wcTmp) {
1748 if (--nIndex > 0) { 1718 if (--nIndex > 0) {
1749 FX_WCHAR preChar = strCurText.GetAt((nIndex)); 1719 FX_WCHAR preChar = strCurText.GetAt((nIndex));
1750 if (((preChar >= L'A' && preChar <= L'Z') || 1720 if (((preChar >= L'A' && preChar <= L'Z') ||
1751 (preChar >= L'a' && preChar <= L'z')) && 1721 (preChar >= L'a' && preChar <= L'z')) &&
1752 ((curChar >= L'A' && curChar <= L'Z') || 1722 ((curChar >= L'A' && curChar <= L'Z') ||
1753 (curChar >= L'a' && curChar <= L'z'))) { 1723 (curChar >= L'a' && curChar <= L'z'))) {
1754 return TRUE; 1724 return TRUE;
1755 } 1725 }
1756 } 1726 }
1757 int size = m_TempCharList.GetSize(); 1727 const PAGECHAR_INFO* preInfo;
1758 PAGECHAR_INFO preChar; 1728 if (!m_TempCharList.empty()) {
1759 if (size) { 1729 preInfo = &m_TempCharList.back();
1760 preChar = (PAGECHAR_INFO)m_TempCharList[size - 1]; 1730 } else if (!m_CharList.empty()) {
1731 preInfo = &m_CharList.back();
1761 } else { 1732 } else {
1762 size = m_charList.GetSize(); 1733 return FALSE;
1763 if (size == 0) {
1764 return FALSE;
1765 }
1766 preChar = (PAGECHAR_INFO)m_charList[size - 1];
1767 } 1734 }
1768 if (FPDFTEXT_CHAR_PIECE == preChar.m_Flag && 1735 if (FPDFTEXT_CHAR_PIECE == preInfo->m_Flag &&
1769 (0xAD == preChar.m_Unicode || 0x2D == preChar.m_Unicode)) { 1736 (0xAD == preInfo->m_Unicode || 0x2D == preInfo->m_Unicode)) {
1770 return TRUE; 1737 return TRUE;
1771 } 1738 }
1772 } 1739 }
1773 return FALSE; 1740 return FALSE;
1774 } 1741 }
1775 int CPDF_TextPage::ProcessInsertObject(const CPDF_TextObject* pObj, 1742 int CPDF_TextPage::ProcessInsertObject(const CPDF_TextObject* pObj,
1776 const CFX_Matrix& formMatrix) { 1743 const CFX_Matrix& formMatrix) {
1777 FindPreviousTextObject(); 1744 FindPreviousTextObject();
1778 FX_BOOL bNewline = FALSE; 1745 FX_BOOL bNewline = FALSE;
1779 int WritingMode = GetTextObjectWritingMode(pObj); 1746 int WritingMode = GetTextObjectWritingMode(pObj);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 CPDF_TextObject* pTextObj2) { 1899 CPDF_TextObject* pTextObj2) {
1933 if (!pTextObj1 || !pTextObj2) { 1900 if (!pTextObj1 || !pTextObj2) {
1934 return FALSE; 1901 return FALSE;
1935 } 1902 }
1936 CFX_FloatRect rcPreObj(pTextObj2->m_Left, pTextObj2->m_Bottom, 1903 CFX_FloatRect rcPreObj(pTextObj2->m_Left, pTextObj2->m_Bottom,
1937 pTextObj2->m_Right, pTextObj2->m_Top); 1904 pTextObj2->m_Right, pTextObj2->m_Top);
1938 CFX_FloatRect rcCurObj(pTextObj1->m_Left, pTextObj1->m_Bottom, 1905 CFX_FloatRect rcCurObj(pTextObj1->m_Left, pTextObj1->m_Bottom,
1939 pTextObj1->m_Right, pTextObj1->m_Top); 1906 pTextObj1->m_Right, pTextObj1->m_Top);
1940 if (rcPreObj.IsEmpty() && rcCurObj.IsEmpty()) { 1907 if (rcPreObj.IsEmpty() && rcCurObj.IsEmpty()) {
1941 FX_FLOAT dbXdif = FXSYS_fabs(rcPreObj.left - rcCurObj.left); 1908 FX_FLOAT dbXdif = FXSYS_fabs(rcPreObj.left - rcCurObj.left);
1942 int nCount = m_charList.GetSize(); 1909 size_t nCount = m_CharList.size();
1943 if (nCount >= 2) { 1910 if (nCount >= 2) {
1944 PAGECHAR_INFO perCharTemp = (PAGECHAR_INFO)m_charList[nCount - 2]; 1911 PAGECHAR_INFO perCharTemp = m_CharList[nCount - 2];
1945 FX_FLOAT dbSpace = perCharTemp.m_CharBox.Width(); 1912 FX_FLOAT dbSpace = perCharTemp.m_CharBox.Width();
1946 if (dbXdif > dbSpace) { 1913 if (dbXdif > dbSpace) {
1947 return FALSE; 1914 return FALSE;
1948 } 1915 }
1949 } 1916 }
1950 } 1917 }
1951 if (!rcPreObj.IsEmpty() || !rcCurObj.IsEmpty()) { 1918 if (!rcPreObj.IsEmpty() || !rcCurObj.IsEmpty()) {
1952 rcPreObj.Intersect(rcCurObj); 1919 rcPreObj.Intersect(rcCurObj);
1953 if (rcPreObj.IsEmpty()) { 1920 if (rcPreObj.IsEmpty()) {
1954 return FALSE; 1921 return FALSE;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
2005 } 1972 }
2006 if (IsSameTextObject((CPDF_TextObject*)pObj, pTextObj)) { 1973 if (IsSameTextObject((CPDF_TextObject*)pObj, pTextObj)) {
2007 return TRUE; 1974 return TRUE;
2008 } 1975 }
2009 i++; 1976 i++;
2010 } 1977 }
2011 return FALSE; 1978 return FALSE;
2012 } 1979 }
2013 1980
2014 FX_BOOL CPDF_TextPage::GenerateCharInfo(FX_WCHAR unicode, PAGECHAR_INFO& info) { 1981 FX_BOOL CPDF_TextPage::GenerateCharInfo(FX_WCHAR unicode, PAGECHAR_INFO& info) {
2015 int size = m_TempCharList.GetSize(); 1982 const PAGECHAR_INFO* preChar;
2016 PAGECHAR_INFO preChar; 1983 if (!m_TempCharList.empty()) {
2017 if (size) { 1984 preChar = &m_TempCharList.back();
2018 preChar = (PAGECHAR_INFO)m_TempCharList[size - 1]; 1985 } else if (!m_CharList.empty()) {
1986 preChar = &m_CharList.back();
2019 } else { 1987 } else {
2020 size = m_charList.GetSize(); 1988 return FALSE;
2021 if (size == 0) {
2022 return FALSE;
2023 }
2024 preChar = (PAGECHAR_INFO)m_charList[size - 1];
2025 } 1989 }
2026 info.m_Index = m_TextBuf.GetLength(); 1990 info.m_Index = m_TextBuf.GetLength();
2027 info.m_Unicode = unicode; 1991 info.m_Unicode = unicode;
2028 info.m_pTextObj = NULL; 1992 info.m_pTextObj = NULL;
2029 info.m_CharCode = -1; 1993 info.m_CharCode = -1;
2030 info.m_Flag = FPDFTEXT_CHAR_GENERATED; 1994 info.m_Flag = FPDFTEXT_CHAR_GENERATED;
2031 int preWidth = 0; 1995 int preWidth = 0;
2032 if (preChar.m_pTextObj && preChar.m_CharCode != (FX_DWORD)-1) 1996 if (preChar->m_pTextObj && preChar->m_CharCode != (FX_DWORD)-1)
2033 preWidth = GetCharWidth(preChar.m_CharCode, preChar.m_pTextObj->GetFont()); 1997 preWidth =
1998 GetCharWidth(preChar->m_CharCode, preChar->m_pTextObj->GetFont());
2034 1999
2035 FX_FLOAT fFontSize = preChar.m_pTextObj ? preChar.m_pTextObj->GetFontSize() 2000 FX_FLOAT fFontSize = preChar->m_pTextObj ? preChar->m_pTextObj->GetFontSize()
2036 : preChar.m_CharBox.Height(); 2001 : preChar->m_CharBox.Height();
2037 if (!fFontSize) 2002 if (!fFontSize)
2038 fFontSize = kDefaultFontSize; 2003 fFontSize = kDefaultFontSize;
2039 2004
2040 info.m_OriginX = preChar.m_OriginX + preWidth * (fFontSize) / 1000; 2005 info.m_OriginX = preChar->m_OriginX + preWidth * (fFontSize) / 1000;
2041 info.m_OriginY = preChar.m_OriginY; 2006 info.m_OriginY = preChar->m_OriginY;
2042 info.m_CharBox = CFX_FloatRect(info.m_OriginX, info.m_OriginY, info.m_OriginX, 2007 info.m_CharBox = CFX_FloatRect(info.m_OriginX, info.m_OriginY, info.m_OriginX,
2043 info.m_OriginY); 2008 info.m_OriginY);
2044 return TRUE; 2009 return TRUE;
2045 } 2010 }
2046 2011
2047 FX_BOOL CPDF_TextPage::IsRectIntersect(const CFX_FloatRect& rect1, 2012 FX_BOOL CPDF_TextPage::IsRectIntersect(const CFX_FloatRect& rect1,
2048 const CFX_FloatRect& rect2) { 2013 const CFX_FloatRect& rect2) {
2049 CFX_FloatRect rect = rect1; 2014 CFX_FloatRect rect = rect1;
2050 rect.Intersect(rect2); 2015 rect.Intersect(rect2);
2051 return !rect.IsEmpty(); 2016 return !rect.IsEmpty();
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
2669 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { 2634 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) {
2670 return; 2635 return;
2671 } 2636 }
2672 CPDF_LinkExt* link = NULL; 2637 CPDF_LinkExt* link = NULL;
2673 link = m_LinkList.GetAt(index); 2638 link = m_LinkList.GetAt(index);
2674 if (!link) { 2639 if (!link) {
2675 return; 2640 return;
2676 } 2641 }
2677 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); 2642 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects);
2678 } 2643 }
OLDNEW
« no previous file with comments | « core/include/fxcrt/fx_basic.h ('k') | core/src/fpdftext/text_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698