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

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

Issue 2271973004: Clean up CPDF_TextPage (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 3 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 | « no previous file | core/fpdftext/include/cpdf_textpage.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 <algorithm> 7 #include <algorithm>
8 #include <cctype> 8 #include <cctype>
9 #include <cwctype> 9 #include <cwctype>
10 #include <memory> 10 #include <memory>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #define TEXT_CHARRATIO_GAPDELTA 0.070 49 #define TEXT_CHARRATIO_GAPDELTA 0.070
50 50
51 namespace { 51 namespace {
52 52
53 const FX_FLOAT kDefaultFontSize = 1.0f; 53 const FX_FLOAT kDefaultFontSize = 1.0f;
54 const uint16_t* const g_UnicodeData_Normalization_Maps[5] = { 54 const uint16_t* const g_UnicodeData_Normalization_Maps[5] = {
55 nullptr, g_UnicodeData_Normalization_Map1, g_UnicodeData_Normalization_Map2, 55 nullptr, g_UnicodeData_Normalization_Map1, g_UnicodeData_Normalization_Map2,
56 g_UnicodeData_Normalization_Map3, g_UnicodeData_Normalization_Map4}; 56 g_UnicodeData_Normalization_Map3, g_UnicodeData_Normalization_Map4};
57 57
58 FX_BOOL IsIgnoreSpaceCharacter(FX_WCHAR curChar) { 58 FX_BOOL IsIgnoreSpaceCharacter(FX_WCHAR curChar) {
59 if (curChar < 255) { 59 if (curChar < 255)
60 return FALSE; 60 return FALSE;
61 }
62 if ((curChar >= 0x0600 && curChar <= 0x06FF) || 61 if ((curChar >= 0x0600 && curChar <= 0x06FF) ||
63 (curChar >= 0xFE70 && curChar <= 0xFEFF) || 62 (curChar >= 0xFE70 && curChar <= 0xFEFF) ||
64 (curChar >= 0xFB50 && curChar <= 0xFDFF) || 63 (curChar >= 0xFB50 && curChar <= 0xFDFF) ||
65 (curChar >= 0x0400 && curChar <= 0x04FF) || 64 (curChar >= 0x0400 && curChar <= 0x04FF) ||
66 (curChar >= 0x0500 && curChar <= 0x052F) || 65 (curChar >= 0x0500 && curChar <= 0x052F) ||
67 (curChar >= 0xA640 && curChar <= 0xA69F) || 66 (curChar >= 0xA640 && curChar <= 0xA69F) ||
68 (curChar >= 0x2DE0 && curChar <= 0x2DFF) || curChar == 8467 || 67 (curChar >= 0x2DE0 && curChar <= 0x2DFF) || curChar == 8467 ||
69 (curChar >= 0x2000 && curChar <= 0x206F)) { 68 (curChar >= 0x2000 && curChar <= 0x206F)) {
70 return FALSE; 69 return FALSE;
71 } 70 }
72 return TRUE; 71 return TRUE;
73 } 72 }
74 73
75 FX_FLOAT NormalizeThreshold(FX_FLOAT threshold) { 74 FX_FLOAT NormalizeThreshold(FX_FLOAT threshold) {
76 if (threshold < 300) { 75 if (threshold < 300)
77 return threshold / 2.0f; 76 return threshold / 2.0f;
78 } 77 if (threshold < 500)
79 if (threshold < 500) {
80 return threshold / 4.0f; 78 return threshold / 4.0f;
81 } 79 if (threshold < 700)
82 if (threshold < 700) {
83 return threshold / 5.0f; 80 return threshold / 5.0f;
84 }
85 return threshold / 6.0f; 81 return threshold / 6.0f;
86 } 82 }
87 83
88 FX_FLOAT CalculateBaseSpace(const CPDF_TextObject* pTextObj, 84 FX_FLOAT CalculateBaseSpace(const CPDF_TextObject* pTextObj,
89 const CFX_Matrix& matrix) { 85 const CFX_Matrix& matrix) {
90 FX_FLOAT baseSpace = 0.0; 86 FX_FLOAT baseSpace = 0.0;
91 const int nItems = pTextObj->CountItems(); 87 const int nItems = pTextObj->CountItems();
92 if (pTextObj->m_TextState.GetObject()->m_CharSpace && nItems >= 3) { 88 if (pTextObj->m_TextState.GetObject()->m_CharSpace && nItems >= 3) {
93 FX_BOOL bAllChar = TRUE; 89 bool bAllChar = true;
94 FX_FLOAT spacing = matrix.TransformDistance( 90 FX_FLOAT spacing = matrix.TransformDistance(
95 pTextObj->m_TextState.GetObject()->m_CharSpace); 91 pTextObj->m_TextState.GetObject()->m_CharSpace);
96 baseSpace = spacing; 92 baseSpace = spacing;
97 for (int i = 0; i < nItems; i++) { 93 for (int i = 0; i < nItems; i++) {
98 CPDF_TextObjectItem item; 94 CPDF_TextObjectItem item;
99 pTextObj->GetItemInfo(i, &item); 95 pTextObj->GetItemInfo(i, &item);
100 if (item.m_CharCode == (uint32_t)-1) { 96 if (item.m_CharCode == static_cast<uint32_t>(-1)) {
101 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); 97 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH();
102 FX_FLOAT kerning = -fontsize_h * item.m_OriginX / 1000; 98 FX_FLOAT kerning = -fontsize_h * item.m_OriginX / 1000;
103 baseSpace = std::min(baseSpace, kerning + spacing); 99 baseSpace = std::min(baseSpace, kerning + spacing);
104 bAllChar = FALSE; 100 bAllChar = false;
105 } 101 }
106 } 102 }
107 if (baseSpace < 0.0 || (nItems == 3 && !bAllChar)) { 103 if (baseSpace < 0.0 || (nItems == 3 && !bAllChar))
108 baseSpace = 0.0; 104 baseSpace = 0.0;
109 }
110 } 105 }
111 return baseSpace; 106 return baseSpace;
112 } 107 }
113 108
114 FX_STRSIZE Unicode_GetNormalization(FX_WCHAR wch, FX_WCHAR* pDst) { 109 FX_STRSIZE Unicode_GetNormalization(FX_WCHAR wch, FX_WCHAR* pDst) {
115 wch = wch & 0xFFFF; 110 wch = wch & 0xFFFF;
116 FX_WCHAR wFind = g_UnicodeData_Normalization[wch]; 111 FX_WCHAR wFind = g_UnicodeData_Normalization[wch];
117 if (!wFind) { 112 if (!wFind) {
118 if (pDst) { 113 if (pDst)
119 *pDst = wch; 114 *pDst = wch;
120 }
121 return 1; 115 return 1;
122 } 116 }
123 if (wFind >= 0x8000) { 117 if (wFind >= 0x8000) {
124 wch = wFind - 0x8000; 118 wch = wFind - 0x8000;
125 wFind = 1; 119 wFind = 1;
126 } else { 120 } else {
127 wch = wFind & 0x0FFF; 121 wch = wFind & 0x0FFF;
128 wFind >>= 12; 122 wFind >>= 12;
129 } 123 }
130 const uint16_t* pMap = g_UnicodeData_Normalization_Maps[wFind]; 124 const uint16_t* pMap = g_UnicodeData_Normalization_Maps[wFind];
131 if (pMap == g_UnicodeData_Normalization_Map4) { 125 if (pMap == g_UnicodeData_Normalization_Map4) {
132 pMap = g_UnicodeData_Normalization_Map4 + wch; 126 pMap = g_UnicodeData_Normalization_Map4 + wch;
133 wFind = (FX_WCHAR)(*pMap++); 127 wFind = (FX_WCHAR)(*pMap++);
134 } else { 128 } else {
135 pMap += wch; 129 pMap += wch;
136 } 130 }
137 if (pDst) { 131 if (pDst) {
138 FX_WCHAR n = wFind; 132 FX_WCHAR n = wFind;
139 while (n--) { 133 while (n--)
140 *pDst++ = *pMap++; 134 *pDst++ = *pMap++;
141 }
142 } 135 }
143 return (FX_STRSIZE)wFind; 136 return (FX_STRSIZE)wFind;
144 } 137 }
145 138
146 float MaskPercentFilled(const std::vector<bool>& mask, 139 float MaskPercentFilled(const std::vector<bool>& mask,
147 int32_t start, 140 int32_t start,
148 int32_t end) { 141 int32_t end) {
149 if (start >= end) 142 if (start >= end)
150 return 0; 143 return 0;
151 float count = std::count_if(mask.begin() + start, mask.begin() + end, 144 float count = std::count_if(mask.begin() + start, mask.begin() + end,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 254
262 if (nCount + start > pdfium::CollectionSize<int>(m_CharList) || 255 if (nCount + start > pdfium::CollectionSize<int>(m_CharList) ||
263 nCount == -1) { 256 nCount == -1) {
264 nCount = pdfium::CollectionSize<int>(m_CharList) - start; 257 nCount = pdfium::CollectionSize<int>(m_CharList) - start;
265 } 258 }
266 259
267 std::vector<CFX_FloatRect> rectArray; 260 std::vector<CFX_FloatRect> rectArray;
268 CPDF_TextObject* pCurObj = nullptr; 261 CPDF_TextObject* pCurObj = nullptr;
269 CFX_FloatRect rect; 262 CFX_FloatRect rect;
270 int curPos = start; 263 int curPos = start;
271 FX_BOOL flagNewRect = TRUE; 264 bool flagNewRect = true;
Lei Zhang 2016/08/25 01:14:25 bFlagNewRect
npm 2016/08/25 14:13:26 Done.
272 while (nCount--) { 265 while (nCount--) {
273 PAGECHAR_INFO info_curchar = m_CharList[curPos++]; 266 PAGECHAR_INFO info_curchar = m_CharList[curPos++];
274 if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED) { 267 if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED)
275 continue; 268 continue;
276 }
277 if (info_curchar.m_CharBox.Width() < 0.01 || 269 if (info_curchar.m_CharBox.Width() < 0.01 ||
278 info_curchar.m_CharBox.Height() < 0.01) { 270 info_curchar.m_CharBox.Height() < 0.01) {
279 continue; 271 continue;
280 } 272 }
281 if (!pCurObj) { 273 if (!pCurObj)
282 pCurObj = info_curchar.m_pTextObj; 274 pCurObj = info_curchar.m_pTextObj;
283 }
284 if (pCurObj != info_curchar.m_pTextObj) { 275 if (pCurObj != info_curchar.m_pTextObj) {
285 rectArray.push_back(rect); 276 rectArray.push_back(rect);
286 pCurObj = info_curchar.m_pTextObj; 277 pCurObj = info_curchar.m_pTextObj;
287 flagNewRect = TRUE; 278 flagNewRect = true;
288 } 279 }
289 if (flagNewRect) { 280 if (flagNewRect) {
290 FX_FLOAT orgX = info_curchar.m_OriginX, orgY = info_curchar.m_OriginY; 281 FX_FLOAT orgX = info_curchar.m_OriginX, orgY = info_curchar.m_OriginY;
291 CFX_Matrix matrix, matrix_reverse; 282 CFX_Matrix matrix, matrix_reverse;
292 info_curchar.m_pTextObj->GetTextMatrix(&matrix); 283 info_curchar.m_pTextObj->GetTextMatrix(&matrix);
293 matrix.Concat(info_curchar.m_Matrix); 284 matrix.Concat(info_curchar.m_Matrix);
294 matrix_reverse.SetReverse(matrix); 285 matrix_reverse.SetReverse(matrix);
295 matrix_reverse.Transform(orgX, orgY); 286 matrix_reverse.Transform(orgX, orgY);
296 rect.left = info_curchar.m_CharBox.left; 287 rect.left = info_curchar.m_CharBox.left;
297 rect.right = info_curchar.m_CharBox.right; 288 rect.right = info_curchar.m_CharBox.right;
(...skipping 11 matching lines...) Expand all
309 orgY + 300 orgY +
310 pCurObj->GetFont()->GetTypeAscent() * pCurObj->GetFontSize() / 1000; 301 pCurObj->GetFont()->GetTypeAscent() * pCurObj->GetFontSize() / 1000;
311 FX_FLOAT xPosTemp = 302 FX_FLOAT xPosTemp =
312 orgX + 303 orgX +
313 GetCharWidth(info_curchar.m_CharCode, pCurObj->GetFont()) * 304 GetCharWidth(info_curchar.m_CharCode, pCurObj->GetFont()) *
314 pCurObj->GetFontSize() / 1000; 305 pCurObj->GetFontSize() / 1000;
315 matrix.Transform(xPosTemp, rect.top); 306 matrix.Transform(xPosTemp, rect.top);
316 } else { 307 } else {
317 rect.top = info_curchar.m_CharBox.top; 308 rect.top = info_curchar.m_CharBox.top;
318 } 309 }
319 flagNewRect = FALSE; 310 flagNewRect = false;
320 rect = info_curchar.m_CharBox; 311 rect = info_curchar.m_CharBox;
321 rect.Normalize(); 312 rect.Normalize();
322 } else { 313 } else {
323 info_curchar.m_CharBox.Normalize(); 314 info_curchar.m_CharBox.Normalize();
324 if (rect.left > info_curchar.m_CharBox.left) { 315 if (rect.left > info_curchar.m_CharBox.left)
Lei Zhang 2016/08/25 01:14:25 std::min/max?
npm 2016/08/25 14:13:26 Done.
325 rect.left = info_curchar.m_CharBox.left; 316 rect.left = info_curchar.m_CharBox.left;
326 } 317 if (rect.right < info_curchar.m_CharBox.right)
327 if (rect.right < info_curchar.m_CharBox.right) {
328 rect.right = info_curchar.m_CharBox.right; 318 rect.right = info_curchar.m_CharBox.right;
329 } 319 if (rect.top < info_curchar.m_CharBox.top)
330 if (rect.top < info_curchar.m_CharBox.top) {
331 rect.top = info_curchar.m_CharBox.top; 320 rect.top = info_curchar.m_CharBox.top;
332 } 321 if (rect.bottom > info_curchar.m_CharBox.bottom)
333 if (rect.bottom > info_curchar.m_CharBox.bottom) {
334 rect.bottom = info_curchar.m_CharBox.bottom; 322 rect.bottom = info_curchar.m_CharBox.bottom;
335 }
336 } 323 }
337 } 324 }
338 rectArray.push_back(rect); 325 rectArray.push_back(rect);
339 return rectArray; 326 return rectArray;
340 } 327 }
341 328
342 int CPDF_TextPage::GetIndexAtPos(CFX_FloatPoint point, 329 int CPDF_TextPage::GetIndexAtPos(CFX_FloatPoint point,
343 FX_FLOAT xTolerance, 330 FX_FLOAT xTolerance,
344 FX_FLOAT yTolerance) const { 331 FX_FLOAT yTolerance) const {
345 if (!m_bIsParsed) 332 if (!m_bIsParsed)
346 return -3; 333 return -3;
347 334
348 int pos = 0; 335 int pos = 0;
349 int NearPos = -1; 336 int NearPos = -1;
350 double xdif = 5000; 337 double xdif = 5000;
351 double ydif = 5000; 338 double ydif = 5000;
352 while (pos < pdfium::CollectionSize<int>(m_CharList)) { 339 while (pos < pdfium::CollectionSize<int>(m_CharList)) {
353 PAGECHAR_INFO charinfo = m_CharList[pos]; 340 PAGECHAR_INFO charinfo = m_CharList[pos];
354 CFX_FloatRect charrect = charinfo.m_CharBox; 341 CFX_FloatRect charrect = charinfo.m_CharBox;
355 if (charrect.Contains(point.x, point.y)) { 342 if (charrect.Contains(point.x, point.y))
356 break; 343 break;
357 }
358 if (xTolerance > 0 || yTolerance > 0) { 344 if (xTolerance > 0 || yTolerance > 0) {
359 CFX_FloatRect charRectExt; 345 CFX_FloatRect charRectExt;
360 charrect.Normalize(); 346 charrect.Normalize();
361 charRectExt.left = charrect.left - xTolerance / 2; 347 charRectExt.left = charrect.left - xTolerance / 2;
362 charRectExt.right = charrect.right + xTolerance / 2; 348 charRectExt.right = charrect.right + xTolerance / 2;
363 charRectExt.top = charrect.top + yTolerance / 2; 349 charRectExt.top = charrect.top + yTolerance / 2;
364 charRectExt.bottom = charrect.bottom - yTolerance / 2; 350 charRectExt.bottom = charrect.bottom - yTolerance / 2;
365 if (charRectExt.Contains(point.x, point.y)) { 351 if (charRectExt.Contains(point.x, point.y)) {
366 double curXdif, curYdif; 352 double curXdif, curYdif;
367 curXdif = FXSYS_fabs(point.x - charrect.left) < 353 curXdif = FXSYS_fabs(point.x - charrect.left) <
(...skipping 22 matching lines...) Expand all
390 376
391 FX_FLOAT posy = 0; 377 FX_FLOAT posy = 0;
392 bool IsContainPreChar = false; 378 bool IsContainPreChar = false;
393 bool IsAddLineFeed = false; 379 bool IsAddLineFeed = false;
394 CFX_WideString strText; 380 CFX_WideString strText;
395 for (const auto& charinfo : m_CharList) { 381 for (const auto& charinfo : m_CharList) {
396 if (IsRectIntersect(rect, charinfo.m_CharBox)) { 382 if (IsRectIntersect(rect, charinfo.m_CharBox)) {
397 if (FXSYS_fabs(posy - charinfo.m_OriginY) > 0 && !IsContainPreChar && 383 if (FXSYS_fabs(posy - charinfo.m_OriginY) > 0 && !IsContainPreChar &&
398 IsAddLineFeed) { 384 IsAddLineFeed) {
399 posy = charinfo.m_OriginY; 385 posy = charinfo.m_OriginY;
400 if (strText.GetLength() > 0) { 386 if (strText.GetLength() > 0)
Lei Zhang 2016/08/25 01:14:25 GetLength() > 0 -> !IsEmpty()
npm 2016/08/25 14:13:26 Done.
401 strText += L"\r\n"; 387 strText += L"\r\n";
402 }
403 } 388 }
404 IsContainPreChar = true; 389 IsContainPreChar = true;
405 IsAddLineFeed = false; 390 IsAddLineFeed = false;
406 if (charinfo.m_Unicode) { 391 if (charinfo.m_Unicode)
407 strText += charinfo.m_Unicode; 392 strText += charinfo.m_Unicode;
408 }
409 } else if (charinfo.m_Unicode == 32) { 393 } else if (charinfo.m_Unicode == 32) {
410 if (IsContainPreChar && charinfo.m_Unicode) { 394 if (IsContainPreChar && charinfo.m_Unicode) {
411 strText += charinfo.m_Unicode; 395 strText += charinfo.m_Unicode;
412 IsContainPreChar = false; 396 IsContainPreChar = false;
413 IsAddLineFeed = false; 397 IsAddLineFeed = false;
414 } 398 }
415 } else { 399 } else {
416 IsContainPreChar = false; 400 IsContainPreChar = false;
417 IsAddLineFeed = true; 401 IsAddLineFeed = true;
418 } 402 }
419 } 403 }
420 return strText; 404 return strText;
421 } 405 }
422 406
423 std::vector<CFX_FloatRect> CPDF_TextPage::GetRectsArrayByRect(
424 const CFX_FloatRect& rect) const {
425 if (!m_bIsParsed)
426 return std::vector<CFX_FloatRect>();
427
428 CFX_FloatRect curRect;
429 std::vector<CFX_FloatRect> result;
430 bool flagNewRect = true;
431 CPDF_TextObject* pCurObj = nullptr;
432 for (auto info_curchar : m_CharList) {
433 if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED) {
434 continue;
435 }
436 if (!IsRectIntersect(rect, info_curchar.m_CharBox)) {
437 continue;
438 }
439 if (!pCurObj) {
440 pCurObj = info_curchar.m_pTextObj;
441 }
442 if (pCurObj != info_curchar.m_pTextObj) {
443 result.push_back(curRect);
444 pCurObj = info_curchar.m_pTextObj;
445 flagNewRect = true;
446 }
447 if (flagNewRect) {
448 curRect = info_curchar.m_CharBox;
449 curRect.Normalize();
450 flagNewRect = false;
451 } else {
452 info_curchar.m_CharBox.Normalize();
453 curRect.left = std::min(curRect.left, info_curchar.m_CharBox.left);
454 curRect.bottom = std::min(curRect.bottom, info_curchar.m_CharBox.bottom);
455 curRect.right = std::max(curRect.right, info_curchar.m_CharBox.right);
456 curRect.top = std::max(curRect.top, info_curchar.m_CharBox.top);
457 }
458 }
459 result.push_back(curRect);
460 return result;
461 }
462
463 int CPDF_TextPage::GetIndexAtPos(FX_FLOAT x, 407 int CPDF_TextPage::GetIndexAtPos(FX_FLOAT x,
464 FX_FLOAT y, 408 FX_FLOAT y,
465 FX_FLOAT xTolerance, 409 FX_FLOAT xTolerance,
466 FX_FLOAT yTolerance) const { 410 FX_FLOAT yTolerance) const {
467 CFX_FloatPoint point(x, y); 411 CFX_FloatPoint point(x, y);
468 return GetIndexAtPos(point, xTolerance, yTolerance); 412 return GetIndexAtPos(point, xTolerance, yTolerance);
469 } 413 }
470 414
471 void CPDF_TextPage::GetCharInfo(int index, FPDF_CHAR_INFO* info) const { 415 void CPDF_TextPage::GetCharInfo(int index, FPDF_CHAR_INFO* info) const {
472 if (!m_bIsParsed) 416 if (!m_bIsParsed)
473 return; 417 return;
474 418
475 if (index < 0 || index >= pdfium::CollectionSize<int>(m_CharList)) 419 if (index < 0 || index >= pdfium::CollectionSize<int>(m_CharList))
476 return; 420 return;
477 421
478 const PAGECHAR_INFO& charinfo = m_CharList[index]; 422 const PAGECHAR_INFO& charinfo = m_CharList[index];
479 info->m_Charcode = charinfo.m_CharCode; 423 info->m_Charcode = charinfo.m_CharCode;
480 info->m_OriginX = charinfo.m_OriginX; 424 info->m_OriginX = charinfo.m_OriginX;
481 info->m_OriginY = charinfo.m_OriginY; 425 info->m_OriginY = charinfo.m_OriginY;
482 info->m_Unicode = charinfo.m_Unicode; 426 info->m_Unicode = charinfo.m_Unicode;
483 info->m_Flag = charinfo.m_Flag; 427 info->m_Flag = charinfo.m_Flag;
484 info->m_CharBox = charinfo.m_CharBox; 428 info->m_CharBox = charinfo.m_CharBox;
485 info->m_pTextObj = charinfo.m_pTextObj; 429 info->m_pTextObj = charinfo.m_pTextObj;
486 if (charinfo.m_pTextObj && charinfo.m_pTextObj->GetFont()) { 430 if (charinfo.m_pTextObj && charinfo.m_pTextObj->GetFont())
487 info->m_FontSize = charinfo.m_pTextObj->GetFontSize(); 431 info->m_FontSize = charinfo.m_pTextObj->GetFontSize();
488 } else { 432 else
489 info->m_FontSize = kDefaultFontSize; 433 info->m_FontSize = kDefaultFontSize;
490 }
491 info->m_Matrix.Copy(charinfo.m_Matrix); 434 info->m_Matrix.Copy(charinfo.m_Matrix);
492 } 435 }
493 436
494 void CPDF_TextPage::CheckMarkedContentObject(int32_t& start, 437 void CPDF_TextPage::CheckMarkedContentObject(int32_t& start,
495 int32_t& nCount) const { 438 int32_t& nCount) const {
496 PAGECHAR_INFO charinfo = m_CharList[start]; 439 PAGECHAR_INFO charinfo = m_CharList[start];
497 PAGECHAR_INFO charinfo2 = m_CharList[start + nCount - 1]; 440 PAGECHAR_INFO charinfo2 = m_CharList[start + nCount - 1];
498 if (FPDFTEXT_CHAR_PIECE != charinfo.m_Flag && 441 if (FPDFTEXT_CHAR_PIECE != charinfo.m_Flag &&
499 FPDFTEXT_CHAR_PIECE != charinfo2.m_Flag) { 442 FPDFTEXT_CHAR_PIECE != charinfo2.m_Flag) {
500 return; 443 return;
501 } 444 }
502 if (FPDFTEXT_CHAR_PIECE == charinfo.m_Flag) { 445 if (FPDFTEXT_CHAR_PIECE == charinfo.m_Flag) {
503 PAGECHAR_INFO charinfo1 = charinfo; 446 PAGECHAR_INFO charinfo1 = charinfo;
504 int startIndex = start; 447 int startIndex = start;
505 while (FPDFTEXT_CHAR_PIECE == charinfo1.m_Flag && 448 while (FPDFTEXT_CHAR_PIECE == charinfo1.m_Flag &&
506 charinfo1.m_Index == charinfo.m_Index) { 449 charinfo1.m_Index == charinfo.m_Index) {
507 startIndex--; 450 startIndex--;
508 if (startIndex < 0) { 451 if (startIndex < 0)
509 break; 452 break;
510 }
511 charinfo1 = m_CharList[startIndex]; 453 charinfo1 = m_CharList[startIndex];
512 } 454 }
513 startIndex++; 455 startIndex++;
514 start = startIndex; 456 start = startIndex;
515 } 457 }
516 if (FPDFTEXT_CHAR_PIECE == charinfo2.m_Flag) { 458 if (FPDFTEXT_CHAR_PIECE == charinfo2.m_Flag) {
517 PAGECHAR_INFO charinfo3 = charinfo2; 459 PAGECHAR_INFO charinfo3 = charinfo2;
518 int endIndex = start + nCount - 1; 460 int endIndex = start + nCount - 1;
519 while (FPDFTEXT_CHAR_PIECE == charinfo3.m_Flag && 461 while (FPDFTEXT_CHAR_PIECE == charinfo3.m_Flag &&
520 charinfo3.m_Index == charinfo2.m_Index) { 462 charinfo3.m_Index == charinfo2.m_Index) {
521 endIndex++; 463 endIndex++;
522 if (endIndex >= pdfium::CollectionSize<int>(m_CharList)) { 464 if (endIndex >= pdfium::CollectionSize<int>(m_CharList))
523 break; 465 break;
524 }
525 charinfo3 = m_CharList[endIndex]; 466 charinfo3 = m_CharList[endIndex];
526 } 467 }
527 endIndex--; 468 endIndex--;
528 nCount = endIndex - start + 1; 469 nCount = endIndex - start + 1;
529 } 470 }
530 } 471 }
531 472
532 CFX_WideString CPDF_TextPage::GetPageText(int start, int nCount) const { 473 CFX_WideString CPDF_TextPage::GetPageText(int start, int nCount) const {
533 if (!m_bIsParsed || nCount == 0) 474 if (!m_bIsParsed || nCount == 0)
534 return L""; 475 return L"";
535 476
536 if (start < 0) 477 if (start < 0)
537 start = 0; 478 start = 0;
538 479
539 if (nCount == -1) { 480 if (nCount == -1) {
540 nCount = pdfium::CollectionSize<int>(m_CharList) - start; 481 nCount = pdfium::CollectionSize<int>(m_CharList) - start;
541 return CFX_WideString( 482 return CFX_WideString(
542 m_TextBuf.AsStringC().Mid(start, m_TextBuf.AsStringC().GetLength())); 483 m_TextBuf.AsStringC().Mid(start, m_TextBuf.AsStringC().GetLength()));
543 } 484 }
544 if (nCount <= 0 || m_CharList.empty()) { 485 if (nCount <= 0 || m_CharList.empty())
545 return L""; 486 return L"";
546 } 487 if (nCount + start > pdfium::CollectionSize<int>(m_CharList) - 1)
547 if (nCount + start > pdfium::CollectionSize<int>(m_CharList) - 1) {
548 nCount = pdfium::CollectionSize<int>(m_CharList) - start; 488 nCount = pdfium::CollectionSize<int>(m_CharList) - start;
549 } 489 if (nCount <= 0)
550 if (nCount <= 0) {
551 return L""; 490 return L"";
552 }
553 CheckMarkedContentObject(start, nCount); 491 CheckMarkedContentObject(start, nCount);
554 int startindex = 0; 492 int startindex = 0;
555 PAGECHAR_INFO charinfo = m_CharList[start]; 493 PAGECHAR_INFO charinfo = m_CharList[start];
556 int startOffset = 0; 494 int startOffset = 0;
557 while (charinfo.m_Index == -1) { 495 while (charinfo.m_Index == -1) {
558 startOffset++; 496 startOffset++;
559 if (startOffset > nCount || 497 if (startOffset > nCount ||
560 start + startOffset >= pdfium::CollectionSize<int>(m_CharList)) { 498 start + startOffset >= pdfium::CollectionSize<int>(m_CharList)) {
561 return L""; 499 return L"";
562 } 500 }
563 charinfo = m_CharList[start + startOffset]; 501 charinfo = m_CharList[start + startOffset];
564 } 502 }
565 startindex = charinfo.m_Index; 503 startindex = charinfo.m_Index;
566 charinfo = m_CharList[start + nCount - 1]; 504 charinfo = m_CharList[start + nCount - 1];
567 int nCountOffset = 0; 505 int nCountOffset = 0;
568 while (charinfo.m_Index == -1) { 506 while (charinfo.m_Index == -1) {
569 nCountOffset++; 507 nCountOffset++;
570 if (nCountOffset >= nCount) { 508 if (nCountOffset >= nCount)
571 return L""; 509 return L"";
572 }
573 charinfo = m_CharList[start + nCount - nCountOffset - 1]; 510 charinfo = m_CharList[start + nCount - nCountOffset - 1];
574 } 511 }
575 nCount = start + nCount - nCountOffset - startindex; 512 nCount = start + nCount - nCountOffset - startindex;
576 if (nCount <= 0) { 513 if (nCount <= 0)
577 return L""; 514 return L"";
578 }
579 return CFX_WideString(m_TextBuf.AsStringC().Mid(startindex, nCount)); 515 return CFX_WideString(m_TextBuf.AsStringC().Mid(startindex, nCount));
580 } 516 }
581 517
582 int CPDF_TextPage::CountRects(int start, int nCount) { 518 int CPDF_TextPage::CountRects(int start, int nCount) {
583 if (!m_bIsParsed || start < 0) 519 if (!m_bIsParsed || start < 0)
584 return -1; 520 return -1;
585 521
586 if (nCount == -1 || 522 if (nCount == -1 ||
587 nCount + start > pdfium::CollectionSize<int>(m_CharList)) { 523 nCount + start > pdfium::CollectionSize<int>(m_CharList)) {
588 nCount = pdfium::CollectionSize<int>(m_CharList) - start; 524 nCount = pdfium::CollectionSize<int>(m_CharList) - start;
(...skipping 12 matching lines...) Expand all
601 537
602 if (rectIndex < 0 || rectIndex >= pdfium::CollectionSize<int>(m_SelRects)) 538 if (rectIndex < 0 || rectIndex >= pdfium::CollectionSize<int>(m_SelRects))
603 return; 539 return;
604 540
605 left = m_SelRects[rectIndex].left; 541 left = m_SelRects[rectIndex].left;
606 top = m_SelRects[rectIndex].top; 542 top = m_SelRects[rectIndex].top;
607 right = m_SelRects[rectIndex].right; 543 right = m_SelRects[rectIndex].right;
608 bottom = m_SelRects[rectIndex].bottom; 544 bottom = m_SelRects[rectIndex].bottom;
609 } 545 }
610 546
611 int CPDF_TextPage::CountBoundedSegments(FX_FLOAT left,
612 FX_FLOAT top,
613 FX_FLOAT right,
614 FX_FLOAT bottom,
615 FX_BOOL bContains) {
616 m_Segments.RemoveAll();
617 if (!m_bIsParsed)
618 return -1;
619
620 CFX_FloatRect rect(left, bottom, right, top);
621 rect.Normalize();
622
623 FPDF_SEGMENT segment;
624 segment.m_Start = 0;
625 segment.m_nCount = 0;
626
627 int pos = 0;
628 int segmentStatus = 0;
629 FX_BOOL IsContainPreChar = FALSE;
630 for (const auto& charinfo : m_CharList) {
631 if (bContains && rect.Contains(charinfo.m_CharBox)) {
632 if (segmentStatus == 0 || segmentStatus == 2) {
633 segment.m_Start = pos;
634 segment.m_nCount = 1;
635 segmentStatus = 1;
636 } else if (segmentStatus == 1) {
637 segment.m_nCount++;
638 }
639 IsContainPreChar = TRUE;
640 } else if (!bContains &&
641 (IsRectIntersect(rect, charinfo.m_CharBox) ||
642 rect.Contains(charinfo.m_OriginX, charinfo.m_OriginY))) {
643 if (segmentStatus == 0 || segmentStatus == 2) {
644 segment.m_Start = pos;
645 segment.m_nCount = 1;
646 segmentStatus = 1;
647 } else if (segmentStatus == 1) {
648 segment.m_nCount++;
649 }
650 IsContainPreChar = TRUE;
651 } else if (charinfo.m_Unicode == 32) {
652 if (IsContainPreChar == TRUE) {
653 if (segmentStatus == 0 || segmentStatus == 2) {
654 segment.m_Start = pos;
655 segment.m_nCount = 1;
656 segmentStatus = 1;
657 } else if (segmentStatus == 1) {
658 segment.m_nCount++;
659 }
660 IsContainPreChar = FALSE;
661 } else {
662 if (segmentStatus == 1) {
663 segmentStatus = 2;
664 m_Segments.Add(segment);
665 segment.m_Start = 0;
666 segment.m_nCount = 0;
667 }
668 }
669 } else {
670 if (segmentStatus == 1) {
671 segmentStatus = 2;
672 m_Segments.Add(segment);
673 segment.m_Start = 0;
674 segment.m_nCount = 0;
675 }
676 IsContainPreChar = FALSE;
677 }
678 pos++;
679 }
680 if (segmentStatus == 1) {
681 segmentStatus = 2;
682 m_Segments.Add(segment);
683 segment.m_Start = 0;
684 segment.m_nCount = 0;
685 }
686 return m_Segments.GetSize();
687 }
688
689 CPDF_TextPage::TextOrientation CPDF_TextPage::FindTextlineFlowOrientation() 547 CPDF_TextPage::TextOrientation CPDF_TextPage::FindTextlineFlowOrientation()
690 const { 548 const {
691 if (m_pPage->GetPageObjectList()->empty()) 549 if (m_pPage->GetPageObjectList()->empty())
692 return TextOrientation::Unknown; 550 return TextOrientation::Unknown;
693 551
694 const int32_t nPageWidth = static_cast<int32_t>(m_pPage->GetPageWidth()); 552 const int32_t nPageWidth = static_cast<int32_t>(m_pPage->GetPageWidth());
695 const int32_t nPageHeight = static_cast<int32_t>(m_pPage->GetPageHeight()); 553 const int32_t nPageHeight = static_cast<int32_t>(m_pPage->GetPageHeight());
696 std::vector<bool> nHorizontalMask(nPageWidth); 554 std::vector<bool> nHorizontalMask(nPageWidth);
697 std::vector<bool> nVerticalMask(nPageHeight); 555 std::vector<bool> nVerticalMask(nPageHeight);
698 FX_FLOAT fLineHeight = 0.0f; 556 FX_FLOAT fLineHeight = 0.0f;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 CPDF_PageObjectList* pObjectList = pFormObj->m_pForm->GetPageObjectList(); 642 CPDF_PageObjectList* pObjectList = pFormObj->m_pForm->GetPageObjectList();
785 if (pObjectList->empty()) 643 if (pObjectList->empty())
786 return; 644 return;
787 645
788 CFX_Matrix curFormMatrix; 646 CFX_Matrix curFormMatrix;
789 curFormMatrix.Copy(pFormObj->m_FormMatrix); 647 curFormMatrix.Copy(pFormObj->m_FormMatrix);
790 curFormMatrix.Concat(formMatrix); 648 curFormMatrix.Concat(formMatrix);
791 649
792 for (auto it = pObjectList->begin(); it != pObjectList->end(); ++it) { 650 for (auto it = pObjectList->begin(); it != pObjectList->end(); ++it) {
793 if (CPDF_PageObject* pPageObj = it->get()) { 651 if (CPDF_PageObject* pPageObj = it->get()) {
794 if (pPageObj->IsText()) { 652 if (pPageObj->IsText())
795 ProcessTextObject(pPageObj->AsText(), curFormMatrix, pObjectList, it); 653 ProcessTextObject(pPageObj->AsText(), curFormMatrix, pObjectList, it);
796 } else if (pPageObj->IsForm()) { 654 else if (pPageObj->IsForm())
797 ProcessFormObject(pPageObj->AsForm(), curFormMatrix); 655 ProcessFormObject(pPageObj->AsForm(), curFormMatrix);
798 }
799 } 656 }
800 } 657 }
801 } 658 }
802 659
803 int CPDF_TextPage::GetCharWidth(uint32_t charCode, CPDF_Font* pFont) const { 660 int CPDF_TextPage::GetCharWidth(uint32_t charCode, CPDF_Font* pFont) const {
804 if (charCode == CPDF_Font::kInvalidCharCode) 661 if (charCode == CPDF_Font::kInvalidCharCode)
805 return 0; 662 return 0;
806 663
807 if (int w = pFont->GetCharWidthF(charCode)) 664 if (int w = pFont->GetCharWidthF(charCode))
808 return w; 665 return w;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 info.m_Unicode = wChar; 730 info.m_Unicode = wChar;
874 m_TextBuf.AppendChar(info.m_Unicode); 731 m_TextBuf.AppendChar(info.m_Unicode);
875 m_CharList.push_back(info); 732 m_CharList.push_back(info);
876 } 733 }
877 734
878 void CPDF_TextPage::CloseTempLine() { 735 void CPDF_TextPage::CloseTempLine() {
879 if (m_TempCharList.empty()) 736 if (m_TempCharList.empty())
880 return; 737 return;
881 738
882 CFX_WideString str = m_TempTextBuf.MakeString(); 739 CFX_WideString str = m_TempTextBuf.MakeString();
883 FX_BOOL bPrevSpace = FALSE; 740 bool bPrevSpace = false;
884 for (int i = 0; i < str.GetLength(); i++) { 741 for (int i = 0; i < str.GetLength(); i++) {
885 if (str.GetAt(i) != ' ') { 742 if (str.GetAt(i) != ' ') {
886 bPrevSpace = FALSE; 743 bPrevSpace = false;
887 continue; 744 continue;
888 } 745 }
889 if (bPrevSpace) { 746 if (bPrevSpace) {
890 m_TempTextBuf.Delete(i, 1); 747 m_TempTextBuf.Delete(i, 1);
891 m_TempCharList.erase(m_TempCharList.begin() + i); 748 m_TempCharList.erase(m_TempCharList.begin() + i);
892 str.Delete(i); 749 str.Delete(i);
893 i--; 750 i--;
894 } 751 }
895 bPrevSpace = TRUE; 752 bPrevSpace = true;
896 } 753 }
897 CFX_BidiString bidi(str); 754 CFX_BidiString bidi(str);
898 if (m_parserflag == FPDFText_Direction::Right) 755 if (m_parserflag == FPDFText_Direction::Right)
899 bidi.SetOverallDirectionRight(); 756 bidi.SetOverallDirectionRight();
900 CFX_BidiChar::Direction eCurrentDirection = bidi.OverallDirection(); 757 CFX_BidiChar::Direction eCurrentDirection = bidi.OverallDirection();
901 for (const auto& segment : bidi) { 758 for (const auto& segment : bidi) {
902 if (segment.direction == CFX_BidiChar::RIGHT || 759 if (segment.direction == CFX_BidiChar::RIGHT ||
903 (segment.direction == CFX_BidiChar::NEUTRAL && 760 (segment.direction == CFX_BidiChar::NEUTRAL &&
904 eCurrentDirection == CFX_BidiChar::RIGHT)) { 761 eCurrentDirection == CFX_BidiChar::RIGHT)) {
905 eCurrentDirection = CFX_BidiChar::RIGHT; 762 eCurrentDirection = CFX_BidiChar::RIGHT;
906 for (int m = segment.start + segment.count; m > segment.start; --m) 763 for (int m = segment.start + segment.count; m > segment.start; --m)
907 AddCharInfoByRLDirection(bidi.CharAt(m - 1), m_TempCharList[m - 1]); 764 AddCharInfoByRLDirection(bidi.CharAt(m - 1), m_TempCharList[m - 1]);
908 } else { 765 } else {
909 eCurrentDirection = CFX_BidiChar::LEFT; 766 eCurrentDirection = CFX_BidiChar::LEFT;
910 for (int m = segment.start; m < segment.start + segment.count; m++) 767 for (int m = segment.start; m < segment.start + segment.count; m++)
911 AddCharInfoByLRDirection(bidi.CharAt(m), m_TempCharList[m]); 768 AddCharInfoByLRDirection(bidi.CharAt(m), m_TempCharList[m]);
912 } 769 }
913 } 770 }
914 m_TempCharList.clear(); 771 m_TempCharList.clear();
915 m_TempTextBuf.Delete(0, m_TempTextBuf.GetLength()); 772 m_TempTextBuf.Delete(0, m_TempTextBuf.GetLength());
916 } 773 }
917 774
918 void CPDF_TextPage::ProcessTextObject( 775 void CPDF_TextPage::ProcessTextObject(
919 CPDF_TextObject* pTextObj, 776 CPDF_TextObject* pTextObj,
920 const CFX_Matrix& formMatrix, 777 const CFX_Matrix& formMatrix,
921 const CPDF_PageObjectList* pObjList, 778 const CPDF_PageObjectList* pObjList,
922 CPDF_PageObjectList::const_iterator ObjPos) { 779 CPDF_PageObjectList::const_iterator ObjPos) {
923 CFX_FloatRect re(pTextObj->m_Left, pTextObj->m_Bottom, pTextObj->m_Right, 780 CFX_FloatRect re(pTextObj->m_Left, pTextObj->m_Bottom, pTextObj->m_Right,
924 pTextObj->m_Top); 781 pTextObj->m_Top);
925 if (FXSYS_fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f) { 782 if (FXSYS_fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f)
926 return; 783 return;
927 }
928 int count = m_LineObj.GetSize(); 784 int count = m_LineObj.GetSize();
929 PDFTEXT_Obj Obj; 785 PDFTEXT_Obj Obj;
930 Obj.m_pTextObj = pTextObj; 786 Obj.m_pTextObj = pTextObj;
931 Obj.m_formMatrix = formMatrix; 787 Obj.m_formMatrix = formMatrix;
932 if (count == 0) { 788 if (count == 0) {
933 m_LineObj.Add(Obj); 789 m_LineObj.Add(Obj);
934 return; 790 return;
935 } 791 }
936 if (IsSameAsPreTextObject(pTextObj, pObjList, ObjPos)) { 792 if (IsSameAsPreTextObject(pTextObj, pObjList, ObjPos))
937 return; 793 return;
938 }
939 PDFTEXT_Obj prev_Obj = m_LineObj.GetAt(count - 1); 794 PDFTEXT_Obj prev_Obj = m_LineObj.GetAt(count - 1);
940 CPDF_TextObjectItem item; 795 CPDF_TextObjectItem item;
941 int nItem = prev_Obj.m_pTextObj->CountItems(); 796 int nItem = prev_Obj.m_pTextObj->CountItems();
942 prev_Obj.m_pTextObj->GetItemInfo(nItem - 1, &item); 797 prev_Obj.m_pTextObj->GetItemInfo(nItem - 1, &item);
943 FX_FLOAT prev_width = 798 FX_FLOAT prev_width =
944 GetCharWidth(item.m_CharCode, prev_Obj.m_pTextObj->GetFont()) * 799 GetCharWidth(item.m_CharCode, prev_Obj.m_pTextObj->GetFont()) *
945 prev_Obj.m_pTextObj->GetFontSize() / 1000; 800 prev_Obj.m_pTextObj->GetFontSize() / 1000;
946 CFX_Matrix prev_matrix; 801 CFX_Matrix prev_matrix;
947 prev_Obj.m_pTextObj->GetTextMatrix(&prev_matrix); 802 prev_Obj.m_pTextObj->GetTextMatrix(&prev_matrix);
948 prev_width = FXSYS_fabs(prev_width); 803 prev_width = FXSYS_fabs(prev_width);
(...skipping 11 matching lines...) Expand all
960 FX_FLOAT threshold = 815 FX_FLOAT threshold =
961 prev_width > this_width ? prev_width / 4 : this_width / 4; 816 prev_width > this_width ? prev_width / 4 : this_width / 4;
962 FX_FLOAT prev_x = prev_Obj.m_pTextObj->GetPosX(), 817 FX_FLOAT prev_x = prev_Obj.m_pTextObj->GetPosX(),
963 prev_y = prev_Obj.m_pTextObj->GetPosY(); 818 prev_y = prev_Obj.m_pTextObj->GetPosY();
964 prev_Obj.m_formMatrix.Transform(prev_x, prev_y); 819 prev_Obj.m_formMatrix.Transform(prev_x, prev_y);
965 m_DisplayMatrix.Transform(prev_x, prev_y); 820 m_DisplayMatrix.Transform(prev_x, prev_y);
966 FX_FLOAT this_x = pTextObj->GetPosX(), this_y = pTextObj->GetPosY(); 821 FX_FLOAT this_x = pTextObj->GetPosX(), this_y = pTextObj->GetPosY();
967 formMatrix.Transform(this_x, this_y); 822 formMatrix.Transform(this_x, this_y);
968 m_DisplayMatrix.Transform(this_x, this_y); 823 m_DisplayMatrix.Transform(this_x, this_y);
969 if (FXSYS_fabs(this_y - prev_y) > threshold * 2) { 824 if (FXSYS_fabs(this_y - prev_y) > threshold * 2) {
970 for (int i = 0; i < count; i++) { 825 for (int i = 0; i < count; i++)
971 ProcessTextObject(m_LineObj.GetAt(i)); 826 ProcessTextObject(m_LineObj.GetAt(i));
972 }
973 m_LineObj.RemoveAll(); 827 m_LineObj.RemoveAll();
974 m_LineObj.Add(Obj); 828 m_LineObj.Add(Obj);
975 return; 829 return;
976 } 830 }
977 int i = 0; 831 int i = 0;
978 for (i = count - 1; i >= 0; i--) { 832 for (i = count - 1; i >= 0; i--) {
979 PDFTEXT_Obj prev_text_obj = m_LineObj.GetAt(i); 833 PDFTEXT_Obj prev_text_obj = m_LineObj.GetAt(i);
980 FX_FLOAT Prev_x = prev_text_obj.m_pTextObj->GetPosX(), 834 FX_FLOAT Prev_x = prev_text_obj.m_pTextObj->GetPosX(),
981 Prev_y = prev_text_obj.m_pTextObj->GetPosY(); 835 Prev_y = prev_text_obj.m_pTextObj->GetPosY();
982 prev_text_obj.m_formMatrix.Transform(Prev_x, Prev_y); 836 prev_text_obj.m_formMatrix.Transform(Prev_x, Prev_y);
983 m_DisplayMatrix.Transform(Prev_x, Prev_y); 837 m_DisplayMatrix.Transform(Prev_x, Prev_y);
984 if (this_x >= Prev_x) { 838 if (this_x >= Prev_x) {
985 if (i == count - 1) 839 if (i == count - 1)
986 m_LineObj.Add(Obj); 840 m_LineObj.Add(Obj);
987 else 841 else
988 m_LineObj.InsertAt(i + 1, Obj); 842 m_LineObj.InsertAt(i + 1, Obj);
989 break; 843 break;
990 } 844 }
991 } 845 }
992 if (i < 0) { 846 if (i < 0)
993 m_LineObj.InsertAt(0, Obj); 847 m_LineObj.InsertAt(0, Obj);
994 }
995 } 848 }
996 849
997 FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) { 850 FPDFText_MarkedContent CPDF_TextPage::PreMarkedContent(PDFTEXT_Obj Obj) {
998 CPDF_TextObject* pTextObj = Obj.m_pTextObj; 851 CPDF_TextObject* pTextObj = Obj.m_pTextObj;
999 const CPDF_ContentMarkData* pMarkData = pTextObj->m_ContentMark.GetObject(); 852 const CPDF_ContentMarkData* pMarkData = pTextObj->m_ContentMark.GetObject();
1000 if (!pMarkData) 853 if (!pMarkData)
1001 return FPDFText_MarkedContent::Pass; 854 return FPDFText_MarkedContent::Pass;
1002 855
1003 int nContentMark = pMarkData->CountItems(); 856 int nContentMark = pMarkData->CountItems();
1004 if (nContentMark < 1) 857 if (nContentMark < 1)
1005 return FPDFText_MarkedContent::Pass; 858 return FPDFText_MarkedContent::Pass;
1006 859
1007 CFX_WideString actText; 860 CFX_WideString actText;
1008 FX_BOOL bExist = FALSE; 861 bool bExist = false;
1009 CPDF_Dictionary* pDict = nullptr; 862 CPDF_Dictionary* pDict = nullptr;
1010 int n = 0; 863 int n = 0;
1011 for (n = 0; n < nContentMark; n++) { 864 for (n = 0; n < nContentMark; n++) {
1012 const CPDF_ContentMarkItem& item = pMarkData->GetItem(n); 865 const CPDF_ContentMarkItem& item = pMarkData->GetItem(n);
1013 if (item.GetParamType() == CPDF_ContentMarkItem::ParamType::None) 866 if (item.GetParamType() == CPDF_ContentMarkItem::ParamType::None)
1014 continue; 867 continue;
1015 pDict = item.GetParam(); 868 pDict = item.GetParam();
1016 CPDF_String* temp = 869 CPDF_String* temp =
1017 ToString(pDict ? pDict->GetObjectBy("ActualText") : nullptr); 870 ToString(pDict ? pDict->GetObjectBy("ActualText") : nullptr);
1018 if (temp) { 871 if (temp) {
1019 bExist = TRUE; 872 bExist = true;
1020 actText = temp->GetUnicodeText(); 873 actText = temp->GetUnicodeText();
1021 } 874 }
1022 } 875 }
1023 if (!bExist) 876 if (!bExist)
1024 return FPDFText_MarkedContent::Pass; 877 return FPDFText_MarkedContent::Pass;
1025 878
1026 if (m_pPreTextObj) { 879 if (m_pPreTextObj) {
1027 const CPDF_ContentMarkData* pPreMarkData = 880 const CPDF_ContentMarkData* pPreMarkData =
1028 m_pPreTextObj->m_ContentMark.GetObject(); 881 m_pPreTextObj->m_ContentMark.GetObject();
1029 if (pPreMarkData && pPreMarkData->CountItems() == n && 882 if (pPreMarkData && pPreMarkData->CountItems() == n &&
1030 pDict == pPreMarkData->GetItem(n - 1).GetParam()) { 883 pDict == pPreMarkData->GetItem(n - 1).GetParam()) {
1031 return FPDFText_MarkedContent::Done; 884 return FPDFText_MarkedContent::Done;
1032 } 885 }
1033 } 886 }
1034 FX_STRSIZE nItems = actText.GetLength(); 887 FX_STRSIZE nItems = actText.GetLength();
1035 if (nItems < 1) 888 if (nItems < 1)
1036 return FPDFText_MarkedContent::Pass; 889 return FPDFText_MarkedContent::Pass;
1037 890
1038 CPDF_Font* pFont = pTextObj->GetFont(); 891 CPDF_Font* pFont = pTextObj->GetFont();
1039 bExist = FALSE; 892 bExist = false;
1040 for (FX_STRSIZE i = 0; i < nItems; i++) { 893 for (FX_STRSIZE i = 0; i < nItems; i++) {
1041 if (pFont->CharCodeFromUnicode(actText.GetAt(i)) != 894 if (pFont->CharCodeFromUnicode(actText.GetAt(i)) !=
1042 CPDF_Font::kInvalidCharCode) { 895 CPDF_Font::kInvalidCharCode) {
1043 bExist = TRUE; 896 bExist = true;
1044 break; 897 break;
1045 } 898 }
1046 } 899 }
1047 if (!bExist) 900 if (!bExist)
1048 return FPDFText_MarkedContent::Pass; 901 return FPDFText_MarkedContent::Pass;
1049 902
1050 bExist = FALSE; 903 bExist = false;
1051 for (FX_STRSIZE i = 0; i < nItems; i++) { 904 for (FX_STRSIZE i = 0; i < nItems; i++) {
1052 FX_WCHAR wChar = actText.GetAt(i); 905 FX_WCHAR wChar = actText.GetAt(i);
1053 if ((wChar > 0x80 && wChar < 0xFFFD) || (wChar <= 0x80 && isprint(wChar))) { 906 if ((wChar > 0x80 && wChar < 0xFFFD) || (wChar <= 0x80 && isprint(wChar))) {
1054 bExist = TRUE; 907 bExist = true;
1055 break; 908 break;
1056 } 909 }
1057 } 910 }
1058 if (!bExist) 911 if (!bExist)
1059 return FPDFText_MarkedContent::Done; 912 return FPDFText_MarkedContent::Done;
1060 913
1061 return FPDFText_MarkedContent::Delay; 914 return FPDFText_MarkedContent::Delay;
1062 } 915 }
1063 916
1064 void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) { 917 void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) {
(...skipping 27 matching lines...) Expand all
1092 FX_FLOAT fPosX = pTextObj->GetPosX(); 945 FX_FLOAT fPosX = pTextObj->GetPosX();
1093 FX_FLOAT fPosY = pTextObj->GetPosY(); 946 FX_FLOAT fPosY = pTextObj->GetPosY();
1094 int nCharInfoIndex = m_TextBuf.GetLength(); 947 int nCharInfoIndex = m_TextBuf.GetLength();
1095 CFX_FloatRect charBox; 948 CFX_FloatRect charBox;
1096 charBox.top = pTextObj->m_Top; 949 charBox.top = pTextObj->m_Top;
1097 charBox.left = pTextObj->m_Left; 950 charBox.left = pTextObj->m_Left;
1098 charBox.right = pTextObj->m_Right; 951 charBox.right = pTextObj->m_Right;
1099 charBox.bottom = pTextObj->m_Bottom; 952 charBox.bottom = pTextObj->m_Bottom;
1100 for (FX_STRSIZE k = 0; k < nItems; k++) { 953 for (FX_STRSIZE k = 0; k < nItems; k++) {
1101 FX_WCHAR wChar = actText.GetAt(k); 954 FX_WCHAR wChar = actText.GetAt(k);
1102 if (wChar <= 0x80 && !isprint(wChar)) { 955 if (wChar <= 0x80 && !isprint(wChar))
1103 wChar = 0x20; 956 wChar = 0x20;
1104 } 957 if (wChar >= 0xFFFD)
1105 if (wChar >= 0xFFFD) {
1106 continue; 958 continue;
1107 }
1108 PAGECHAR_INFO charinfo; 959 PAGECHAR_INFO charinfo;
1109 charinfo.m_OriginX = fPosX; 960 charinfo.m_OriginX = fPosX;
1110 charinfo.m_OriginY = fPosY; 961 charinfo.m_OriginY = fPosY;
1111 charinfo.m_Index = nCharInfoIndex; 962 charinfo.m_Index = nCharInfoIndex;
1112 charinfo.m_Unicode = wChar; 963 charinfo.m_Unicode = wChar;
1113 charinfo.m_CharCode = pFont->CharCodeFromUnicode(wChar); 964 charinfo.m_CharCode = pFont->CharCodeFromUnicode(wChar);
1114 charinfo.m_Flag = FPDFTEXT_CHAR_PIECE; 965 charinfo.m_Flag = FPDFTEXT_CHAR_PIECE;
1115 charinfo.m_pTextObj = pTextObj; 966 charinfo.m_pTextObj = pTextObj;
1116 charinfo.m_CharBox.top = charBox.top; 967 charinfo.m_CharBox.top = charBox.top;
1117 charinfo.m_CharBox.left = charBox.left; 968 charinfo.m_CharBox.left = charBox.left;
(...skipping 20 matching lines...) Expand all
1138 int32_t iBufStartAppend) { 989 int32_t iBufStartAppend) {
1139 int32_t i = iCharListStartAppend; 990 int32_t i = iCharListStartAppend;
1140 int32_t j = pdfium::CollectionSize<int32_t>(m_TempCharList) - 1; 991 int32_t j = pdfium::CollectionSize<int32_t>(m_TempCharList) - 1;
1141 for (; i < j; i++, j--) { 992 for (; i < j; i++, j--) {
1142 std::swap(m_TempCharList[i], m_TempCharList[j]); 993 std::swap(m_TempCharList[i], m_TempCharList[j]);
1143 std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index); 994 std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index);
1144 } 995 }
1145 FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer(); 996 FX_WCHAR* pTempBuffer = m_TempTextBuf.GetBuffer();
1146 i = iBufStartAppend; 997 i = iBufStartAppend;
1147 j = m_TempTextBuf.GetLength() - 1; 998 j = m_TempTextBuf.GetLength() - 1;
1148 for (; i < j; i++, j--) { 999 for (; i < j; i++, j--)
1149 std::swap(pTempBuffer[i], pTempBuffer[j]); 1000 std::swap(pTempBuffer[i], pTempBuffer[j]);
1150 }
1151 } 1001 }
1152 1002
1153 FX_BOOL CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj, 1003 FX_BOOL CPDF_TextPage::IsRightToLeft(const CPDF_TextObject* pTextObj,
1154 const CPDF_Font* pFont, 1004 const CPDF_Font* pFont,
1155 int nItems) const { 1005 int nItems) const {
1156 CFX_WideString str; 1006 CFX_WideString str;
1157 for (int32_t i = 0; i < nItems; i++) { 1007 for (int32_t i = 0; i < nItems; i++) {
1158 CPDF_TextObjectItem item; 1008 CPDF_TextObjectItem item;
1159 pTextObj->GetItemInfo(i, &item); 1009 pTextObj->GetItemInfo(i, &item);
1160 if (item.m_CharCode == (uint32_t)-1) { 1010 if (item.m_CharCode == (uint32_t)-1)
Lei Zhang 2016/08/25 01:14:25 static_cast
npm 2016/08/25 14:13:26 Done.
1161 continue; 1011 continue;
1162 }
1163 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); 1012 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode);
1164 FX_WCHAR wChar = wstrItem.GetAt(0); 1013 FX_WCHAR wChar = wstrItem.GetAt(0);
1165 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { 1014 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode)
1166 wChar = (FX_WCHAR)item.m_CharCode; 1015 wChar = (FX_WCHAR)item.m_CharCode;
1167 }
1168 if (wChar) 1016 if (wChar)
1169 str += wChar; 1017 str += wChar;
1170 } 1018 }
1171 return CFX_BidiString(str).OverallDirection() == CFX_BidiChar::RIGHT; 1019 return CFX_BidiString(str).OverallDirection() == CFX_BidiChar::RIGHT;
1172 } 1020 }
1173 1021
1174 void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { 1022 void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) {
1175 CPDF_TextObject* pTextObj = Obj.m_pTextObj; 1023 CPDF_TextObject* pTextObj = Obj.m_pTextObj;
1176 if (FXSYS_fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f) { 1024 if (FXSYS_fabs(pTextObj->m_Right - pTextObj->m_Left) < 0.01f)
1177 return; 1025 return;
1178 }
1179 CFX_Matrix formMatrix = Obj.m_formMatrix; 1026 CFX_Matrix formMatrix = Obj.m_formMatrix;
1180 CPDF_Font* pFont = pTextObj->GetFont(); 1027 CPDF_Font* pFont = pTextObj->GetFont();
1181 CFX_Matrix matrix; 1028 CFX_Matrix matrix;
1182 pTextObj->GetTextMatrix(&matrix); 1029 pTextObj->GetTextMatrix(&matrix);
1183 matrix.Concat(formMatrix); 1030 matrix.Concat(formMatrix);
1184 FPDFText_MarkedContent ePreMKC = PreMarkedContent(Obj); 1031 FPDFText_MarkedContent ePreMKC = PreMarkedContent(Obj);
1185 if (ePreMKC == FPDFText_MarkedContent::Done) { 1032 if (ePreMKC == FPDFText_MarkedContent::Done) {
1186 m_pPreTextObj = pTextObj; 1033 m_pPreTextObj = pTextObj;
1187 m_perMatrix.Copy(formMatrix); 1034 m_perMatrix.Copy(formMatrix);
1188 return; 1035 return;
(...skipping 29 matching lines...) Expand all
1218 AppendGeneratedCharacter(TEXT_RETURN_CHAR, formMatrix); 1065 AppendGeneratedCharacter(TEXT_RETURN_CHAR, formMatrix);
1219 AppendGeneratedCharacter(TEXT_LINEFEED_CHAR, formMatrix); 1066 AppendGeneratedCharacter(TEXT_LINEFEED_CHAR, formMatrix);
1220 } 1067 }
1221 break; 1068 break;
1222 case GenerateCharacter::Hyphen: 1069 case GenerateCharacter::Hyphen:
1223 if (pTextObj->CountChars() == 1) { 1070 if (pTextObj->CountChars() == 1) {
1224 CPDF_TextObjectItem item; 1071 CPDF_TextObjectItem item;
1225 pTextObj->GetCharInfo(0, &item); 1072 pTextObj->GetCharInfo(0, &item);
1226 CFX_WideString wstrItem = 1073 CFX_WideString wstrItem =
1227 pTextObj->GetFont()->UnicodeFromCharCode(item.m_CharCode); 1074 pTextObj->GetFont()->UnicodeFromCharCode(item.m_CharCode);
1228 if (wstrItem.IsEmpty()) { 1075 if (wstrItem.IsEmpty())
1229 wstrItem += (FX_WCHAR)item.m_CharCode; 1076 wstrItem += (FX_WCHAR)item.m_CharCode;
1230 }
1231 FX_WCHAR curChar = wstrItem.GetAt(0); 1077 FX_WCHAR curChar = wstrItem.GetAt(0);
1232 if (curChar == 0x2D || curChar == 0xAD) 1078 if (curChar == 0x2D || curChar == 0xAD)
1233 return; 1079 return;
1234 } 1080 }
1235 while (m_TempTextBuf.GetSize() > 0 && 1081 while (m_TempTextBuf.GetSize() > 0 &&
1236 m_TempTextBuf.AsStringC().GetAt(m_TempTextBuf.GetLength() - 1) == 1082 m_TempTextBuf.AsStringC().GetAt(m_TempTextBuf.GetLength() - 1) ==
1237 0x20) { 1083 0x20) {
1238 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); 1084 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1);
1239 m_TempCharList.pop_back(); 1085 m_TempCharList.pop_back();
1240 } 1086 }
(...skipping 27 matching lines...) Expand all
1268 int32_t iCharListStartAppend = 1114 int32_t iCharListStartAppend =
1269 pdfium::CollectionSize<int32_t>(m_TempCharList); 1115 pdfium::CollectionSize<int32_t>(m_TempCharList);
1270 1116
1271 FX_FLOAT spacing = 0; 1117 FX_FLOAT spacing = 0;
1272 for (int i = 0; i < nItems; i++) { 1118 for (int i = 0; i < nItems; i++) {
1273 CPDF_TextObjectItem item; 1119 CPDF_TextObjectItem item;
1274 PAGECHAR_INFO charinfo; 1120 PAGECHAR_INFO charinfo;
1275 charinfo.m_OriginX = 0; 1121 charinfo.m_OriginX = 0;
1276 charinfo.m_OriginY = 0; 1122 charinfo.m_OriginY = 0;
1277 pTextObj->GetItemInfo(i, &item); 1123 pTextObj->GetItemInfo(i, &item);
1278 if (item.m_CharCode == (uint32_t)-1) { 1124 if (item.m_CharCode == static_cast<uint32_t>(-1)) {
1279 CFX_WideString str = m_TempTextBuf.MakeString(); 1125 CFX_WideString str = m_TempTextBuf.MakeString();
1280 if (str.IsEmpty()) { 1126 if (str.IsEmpty())
1281 str = m_TextBuf.AsStringC(); 1127 str = m_TextBuf.AsStringC();
1282 }
1283 if (str.IsEmpty() || str.GetAt(str.GetLength() - 1) == TEXT_SPACE_CHAR) 1128 if (str.IsEmpty() || str.GetAt(str.GetLength() - 1) == TEXT_SPACE_CHAR)
1284 continue; 1129 continue;
1285 1130
1286 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); 1131 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH();
1287 spacing = -fontsize_h * item.m_OriginX / 1000; 1132 spacing = -fontsize_h * item.m_OriginX / 1000;
1288 continue; 1133 continue;
1289 } 1134 }
1290 FX_FLOAT charSpace = pTextObj->m_TextState.GetObject()->m_CharSpace; 1135 FX_FLOAT charSpace = pTextObj->m_TextState.GetObject()->m_CharSpace;
1291 if (charSpace > 0.001) { 1136 if (charSpace > 0.001)
1292 spacing += matrix.TransformDistance(charSpace); 1137 spacing += matrix.TransformDistance(charSpace);
1293 } else if (charSpace < -0.001) { 1138 else if (charSpace < -0.001)
1294 spacing -= matrix.TransformDistance(FXSYS_fabs(charSpace)); 1139 spacing -= matrix.TransformDistance(FXSYS_fabs(charSpace));
1295 }
1296 spacing -= baseSpace; 1140 spacing -= baseSpace;
1297 if (spacing && i > 0) { 1141 if (spacing && i > 0) {
1298 int last_width = 0; 1142 int last_width = 0;
1299 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); 1143 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH();
1300 uint32_t space_charcode = pFont->CharCodeFromUnicode(' '); 1144 uint32_t space_charcode = pFont->CharCodeFromUnicode(' ');
1301 FX_FLOAT threshold = 0; 1145 FX_FLOAT threshold = 0;
1302 if (space_charcode != CPDF_Font::kInvalidCharCode) { 1146 if (space_charcode != CPDF_Font::kInvalidCharCode)
1303 threshold = fontsize_h * pFont->GetCharWidthF(space_charcode) / 1000; 1147 threshold = fontsize_h * pFont->GetCharWidthF(space_charcode) / 1000;
1304 } 1148 if (threshold > fontsize_h / 3)
1305 if (threshold > fontsize_h / 3) {
1306 threshold = 0; 1149 threshold = 0;
1307 } else { 1150 else
1308 threshold /= 2; 1151 threshold /= 2;
1309 }
1310 if (threshold == 0) { 1152 if (threshold == 0) {
1311 threshold = fontsize_h; 1153 threshold = fontsize_h;
1312 int this_width = FXSYS_abs(GetCharWidth(item.m_CharCode, pFont)); 1154 int this_width = FXSYS_abs(GetCharWidth(item.m_CharCode, pFont));
1313 threshold = this_width > last_width ? (FX_FLOAT)this_width 1155 threshold = this_width > last_width ? (FX_FLOAT)this_width
1314 : (FX_FLOAT)last_width; 1156 : (FX_FLOAT)last_width;
1315 threshold = NormalizeThreshold(threshold); 1157 threshold = NormalizeThreshold(threshold);
1316 threshold = fontsize_h * threshold / 1000; 1158 threshold = fontsize_h * threshold / 1000;
1317 } 1159 }
1318 if (threshold && (spacing && spacing >= threshold)) { 1160 if (threshold && (spacing && spacing >= threshold)) {
1319 charinfo.m_Unicode = TEXT_SPACE_CHAR; 1161 charinfo.m_Unicode = TEXT_SPACE_CHAR;
1320 charinfo.m_Flag = FPDFTEXT_CHAR_GENERATED; 1162 charinfo.m_Flag = FPDFTEXT_CHAR_GENERATED;
1321 charinfo.m_pTextObj = pTextObj; 1163 charinfo.m_pTextObj = pTextObj;
1322 charinfo.m_Index = m_TextBuf.GetLength(); 1164 charinfo.m_Index = m_TextBuf.GetLength();
1323 m_TempTextBuf.AppendChar(TEXT_SPACE_CHAR); 1165 m_TempTextBuf.AppendChar(TEXT_SPACE_CHAR);
1324 charinfo.m_CharCode = CPDF_Font::kInvalidCharCode; 1166 charinfo.m_CharCode = CPDF_Font::kInvalidCharCode;
1325 charinfo.m_Matrix.Copy(formMatrix); 1167 charinfo.m_Matrix.Copy(formMatrix);
1326 matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX, 1168 matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX,
1327 charinfo.m_OriginY); 1169 charinfo.m_OriginY);
1328 charinfo.m_CharBox = 1170 charinfo.m_CharBox =
1329 CFX_FloatRect(charinfo.m_OriginX, charinfo.m_OriginY, 1171 CFX_FloatRect(charinfo.m_OriginX, charinfo.m_OriginY,
1330 charinfo.m_OriginX, charinfo.m_OriginY); 1172 charinfo.m_OriginX, charinfo.m_OriginY);
1331 m_TempCharList.push_back(charinfo); 1173 m_TempCharList.push_back(charinfo);
1332 } 1174 }
1333 if (item.m_CharCode == CPDF_Font::kInvalidCharCode) { 1175 if (item.m_CharCode == CPDF_Font::kInvalidCharCode)
1334 continue; 1176 continue;
1335 }
1336 } 1177 }
1337 spacing = 0; 1178 spacing = 0;
1338 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode); 1179 CFX_WideString wstrItem = pFont->UnicodeFromCharCode(item.m_CharCode);
1339 FX_BOOL bNoUnicode = FALSE; 1180 bool bNoUnicode = false;
1340 FX_WCHAR wChar = wstrItem.GetAt(0); 1181 FX_WCHAR wChar = wstrItem.GetAt(0);
1341 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) { 1182 if ((wstrItem.IsEmpty() || wChar == 0) && item.m_CharCode) {
1342 if (wstrItem.IsEmpty()) { 1183 if (wstrItem.IsEmpty())
1343 wstrItem += (FX_WCHAR)item.m_CharCode; 1184 wstrItem += (FX_WCHAR)item.m_CharCode;
1344 } else { 1185 else
1345 wstrItem.SetAt(0, (FX_WCHAR)item.m_CharCode); 1186 wstrItem.SetAt(0, (FX_WCHAR)item.m_CharCode);
1346 } 1187 bNoUnicode = true;
1347 bNoUnicode = TRUE;
1348 } 1188 }
1349 charinfo.m_Index = -1; 1189 charinfo.m_Index = -1;
1350 charinfo.m_CharCode = item.m_CharCode; 1190 charinfo.m_CharCode = item.m_CharCode;
1351 if (bNoUnicode) { 1191 if (bNoUnicode)
1352 charinfo.m_Flag = FPDFTEXT_CHAR_UNUNICODE; 1192 charinfo.m_Flag = FPDFTEXT_CHAR_UNUNICODE;
1353 } else { 1193 else
1354 charinfo.m_Flag = FPDFTEXT_CHAR_NORMAL; 1194 charinfo.m_Flag = FPDFTEXT_CHAR_NORMAL;
1355 }
1356 charinfo.m_pTextObj = pTextObj; 1195 charinfo.m_pTextObj = pTextObj;
1357 charinfo.m_OriginX = 0, charinfo.m_OriginY = 0; 1196 charinfo.m_OriginX = 0, charinfo.m_OriginY = 0;
1358 matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX, 1197 matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX,
1359 charinfo.m_OriginY); 1198 charinfo.m_OriginY);
1360 FX_RECT rect = 1199 FX_RECT rect =
1361 charinfo.m_pTextObj->GetFont()->GetCharBBox(charinfo.m_CharCode); 1200 charinfo.m_pTextObj->GetFont()->GetCharBBox(charinfo.m_CharCode);
1362 charinfo.m_CharBox.top = 1201 charinfo.m_CharBox.top =
1363 rect.top * pTextObj->GetFontSize() / 1000 + item.m_OriginY; 1202 rect.top * pTextObj->GetFontSize() / 1000 + item.m_OriginY;
1364 charinfo.m_CharBox.left = 1203 charinfo.m_CharBox.left =
1365 rect.left * pTextObj->GetFontSize() / 1000 + item.m_OriginX; 1204 rect.left * pTextObj->GetFontSize() / 1000 + item.m_OriginX;
(...skipping 11 matching lines...) Expand all
1377 } 1216 }
1378 matrix.TransformRect(charinfo.m_CharBox); 1217 matrix.TransformRect(charinfo.m_CharBox);
1379 charinfo.m_Matrix.Copy(matrix); 1218 charinfo.m_Matrix.Copy(matrix);
1380 if (wstrItem.IsEmpty()) { 1219 if (wstrItem.IsEmpty()) {
1381 charinfo.m_Unicode = 0; 1220 charinfo.m_Unicode = 0;
1382 m_TempCharList.push_back(charinfo); 1221 m_TempCharList.push_back(charinfo);
1383 m_TempTextBuf.AppendChar(0xfffe); 1222 m_TempTextBuf.AppendChar(0xfffe);
1384 continue; 1223 continue;
1385 } else { 1224 } else {
1386 int nTotal = wstrItem.GetLength(); 1225 int nTotal = wstrItem.GetLength();
1387 FX_BOOL bDel = FALSE; 1226 bool bDel = false;
1388 const int count = 1227 const int count =
1389 std::min(pdfium::CollectionSize<int>(m_TempCharList), 7); 1228 std::min(pdfium::CollectionSize<int>(m_TempCharList), 7);
1390 FX_FLOAT threshold = charinfo.m_Matrix.TransformXDistance( 1229 FX_FLOAT threshold = charinfo.m_Matrix.TransformXDistance(
1391 (FX_FLOAT)TEXT_CHARRATIO_GAPDELTA * pTextObj->GetFontSize()); 1230 (FX_FLOAT)TEXT_CHARRATIO_GAPDELTA * pTextObj->GetFontSize());
1392 for (int n = pdfium::CollectionSize<int>(m_TempCharList); 1231 for (int n = pdfium::CollectionSize<int>(m_TempCharList);
1393 n > pdfium::CollectionSize<int>(m_TempCharList) - count; n--) { 1232 n > pdfium::CollectionSize<int>(m_TempCharList) - count; n--) {
1394 const PAGECHAR_INFO& charinfo1 = m_TempCharList[n - 1]; 1233 const PAGECHAR_INFO& charinfo1 = m_TempCharList[n - 1];
1395 if (charinfo1.m_CharCode == charinfo.m_CharCode && 1234 if (charinfo1.m_CharCode == charinfo.m_CharCode &&
1396 charinfo1.m_pTextObj->GetFont() == charinfo.m_pTextObj->GetFont() && 1235 charinfo1.m_pTextObj->GetFont() == charinfo.m_pTextObj->GetFont() &&
1397 FXSYS_fabs(charinfo1.m_OriginX - charinfo.m_OriginX) < threshold && 1236 FXSYS_fabs(charinfo1.m_OriginX - charinfo.m_OriginX) < threshold &&
1398 FXSYS_fabs(charinfo1.m_OriginY - charinfo.m_OriginY) < threshold) { 1237 FXSYS_fabs(charinfo1.m_OriginY - charinfo.m_OriginY) < threshold) {
1399 bDel = TRUE; 1238 bDel = true;
1400 break; 1239 break;
1401 } 1240 }
1402 } 1241 }
1403 if (!bDel) { 1242 if (!bDel) {
1404 for (int nIndex = 0; nIndex < nTotal; nIndex++) { 1243 for (int nIndex = 0; nIndex < nTotal; nIndex++) {
1405 charinfo.m_Unicode = wstrItem.GetAt(nIndex); 1244 charinfo.m_Unicode = wstrItem.GetAt(nIndex);
1406 if (charinfo.m_Unicode) { 1245 if (charinfo.m_Unicode) {
1407 charinfo.m_Index = m_TextBuf.GetLength(); 1246 charinfo.m_Index = m_TextBuf.GetLength();
1408 m_TempTextBuf.AppendChar(charinfo.m_Unicode); 1247 m_TempTextBuf.AppendChar(charinfo.m_Unicode);
1409 } else { 1248 } else {
1410 m_TempTextBuf.AppendChar(0xfffe); 1249 m_TempTextBuf.AppendChar(0xfffe);
1411 } 1250 }
1412 m_TempCharList.push_back(charinfo); 1251 m_TempCharList.push_back(charinfo);
1413 } 1252 }
1414 } else if (i == 0) { 1253 } else if (i == 0) {
1415 CFX_WideString str = m_TempTextBuf.MakeString(); 1254 CFX_WideString str = m_TempTextBuf.MakeString();
1416 if (!str.IsEmpty() && 1255 if (!str.IsEmpty() &&
1417 str.GetAt(str.GetLength() - 1) == TEXT_SPACE_CHAR) { 1256 str.GetAt(str.GetLength() - 1) == TEXT_SPACE_CHAR) {
1418 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); 1257 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1);
1419 m_TempCharList.pop_back(); 1258 m_TempCharList.pop_back();
1420 } 1259 }
1421 } 1260 }
1422 } 1261 }
1423 } 1262 }
1424 if (bIsBidiAndMirrorInverse) { 1263 if (bIsBidiAndMirrorInverse)
1425 SwapTempTextBuf(iCharListStartAppend, iBufStartAppend); 1264 SwapTempTextBuf(iCharListStartAppend, iBufStartAppend);
1426 }
1427 } 1265 }
1428 1266
1429 CPDF_TextPage::TextOrientation CPDF_TextPage::GetTextObjectWritingMode( 1267 CPDF_TextPage::TextOrientation CPDF_TextPage::GetTextObjectWritingMode(
1430 const CPDF_TextObject* pTextObj) const { 1268 const CPDF_TextObject* pTextObj) const {
1431 int32_t nChars = pTextObj->CountChars(); 1269 int32_t nChars = pTextObj->CountChars();
1432 if (nChars == 1) 1270 if (nChars == 1)
1433 return m_TextlineDir; 1271 return m_TextlineDir;
1434 1272
1435 CPDF_TextObjectItem first, last; 1273 CPDF_TextObjectItem first, last;
1436 pTextObj->GetCharInfo(0, &first); 1274 pTextObj->GetCharInfo(0, &first);
(...skipping 13 matching lines...) Expand all
1450 return v.x <= 0.0872f ? m_TextlineDir : TextOrientation::Horizontal; 1288 return v.x <= 0.0872f ? m_TextlineDir : TextOrientation::Horizontal;
1451 1289
1452 if (v.x <= 0.0872f) 1290 if (v.x <= 0.0872f)
1453 return TextOrientation::Vertical; 1291 return TextOrientation::Vertical;
1454 1292
1455 return m_TextlineDir; 1293 return m_TextlineDir;
1456 } 1294 }
1457 1295
1458 FX_BOOL CPDF_TextPage::IsHyphen(FX_WCHAR curChar) { 1296 FX_BOOL CPDF_TextPage::IsHyphen(FX_WCHAR curChar) {
1459 CFX_WideString strCurText = m_TempTextBuf.MakeString(); 1297 CFX_WideString strCurText = m_TempTextBuf.MakeString();
1460 if (strCurText.GetLength() == 0) { 1298 if (strCurText.GetLength() == 0)
Lei Zhang 2016/08/25 01:14:25 GetLength() == 0 -> IsEmpty()
npm 2016/08/25 14:13:26 Done.
1461 strCurText = m_TextBuf.AsStringC(); 1299 strCurText = m_TextBuf.AsStringC();
1462 }
1463 FX_STRSIZE nCount = strCurText.GetLength(); 1300 FX_STRSIZE nCount = strCurText.GetLength();
1464 int nIndex = nCount - 1; 1301 int nIndex = nCount - 1;
1465 FX_WCHAR wcTmp = strCurText.GetAt(nIndex); 1302 FX_WCHAR wcTmp = strCurText.GetAt(nIndex);
1466 while (wcTmp == 0x20 && nIndex <= nCount - 1 && nIndex >= 0) { 1303 while (wcTmp == 0x20 && nIndex <= nCount - 1 && nIndex >= 0)
1467 wcTmp = strCurText.GetAt(--nIndex); 1304 wcTmp = strCurText.GetAt(--nIndex);
1468 }
1469 if (0x2D == wcTmp || 0xAD == wcTmp) { 1305 if (0x2D == wcTmp || 0xAD == wcTmp) {
1470 if (--nIndex > 0) { 1306 if (--nIndex > 0) {
1471 FX_WCHAR preChar = strCurText.GetAt((nIndex)); 1307 FX_WCHAR preChar = strCurText.GetAt((nIndex));
1472 if (((preChar >= L'A' && preChar <= L'Z') || 1308 if (((preChar >= L'A' && preChar <= L'Z') ||
1473 (preChar >= L'a' && preChar <= L'z')) && 1309 (preChar >= L'a' && preChar <= L'z')) &&
1474 ((curChar >= L'A' && curChar <= L'Z') || 1310 ((curChar >= L'A' && curChar <= L'Z') ||
1475 (curChar >= L'a' && curChar <= L'z'))) { 1311 (curChar >= L'a' && curChar <= L'z'))) {
1476 return TRUE; 1312 return TRUE;
1477 } 1313 }
1478 } 1314 }
1479 const PAGECHAR_INFO* preInfo; 1315 const PAGECHAR_INFO* preInfo;
1480 if (!m_TempCharList.empty()) { 1316 if (!m_TempCharList.empty())
1481 preInfo = &m_TempCharList.back(); 1317 preInfo = &m_TempCharList.back();
1482 } else if (!m_CharList.empty()) { 1318 else if (!m_CharList.empty())
1483 preInfo = &m_CharList.back(); 1319 preInfo = &m_CharList.back();
1484 } else { 1320 else
1485 return FALSE; 1321 return FALSE;
1486 }
1487 if (FPDFTEXT_CHAR_PIECE == preInfo->m_Flag && 1322 if (FPDFTEXT_CHAR_PIECE == preInfo->m_Flag &&
1488 (0xAD == preInfo->m_Unicode || 0x2D == preInfo->m_Unicode)) { 1323 (0xAD == preInfo->m_Unicode || 0x2D == preInfo->m_Unicode)) {
1489 return TRUE; 1324 return TRUE;
1490 } 1325 }
1491 } 1326 }
1492 return FALSE; 1327 return FALSE;
1493 } 1328 }
1494 1329
1495 CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject( 1330 CPDF_TextPage::GenerateCharacter CPDF_TextPage::ProcessInsertObject(
1496 const CPDF_TextObject* pObj, 1331 const CPDF_TextObject* pObj,
1497 const CFX_Matrix& formMatrix) { 1332 const CFX_Matrix& formMatrix) {
1498 FindPreviousTextObject(); 1333 FindPreviousTextObject();
1499 TextOrientation WritingMode = GetTextObjectWritingMode(pObj); 1334 TextOrientation WritingMode = GetTextObjectWritingMode(pObj);
1500 if (WritingMode == TextOrientation::Unknown) 1335 if (WritingMode == TextOrientation::Unknown)
1501 WritingMode = GetTextObjectWritingMode(m_pPreTextObj); 1336 WritingMode = GetTextObjectWritingMode(m_pPreTextObj);
1502 1337
1503 CFX_FloatRect this_rect(pObj->m_Left, pObj->m_Bottom, pObj->m_Right, 1338 CFX_FloatRect this_rect(pObj->m_Left, pObj->m_Bottom, pObj->m_Right,
1504 pObj->m_Top); 1339 pObj->m_Top);
1505 CFX_FloatRect prev_rect(m_pPreTextObj->m_Left, m_pPreTextObj->m_Bottom, 1340 CFX_FloatRect prev_rect(m_pPreTextObj->m_Left, m_pPreTextObj->m_Bottom,
1506 m_pPreTextObj->m_Right, m_pPreTextObj->m_Top); 1341 m_pPreTextObj->m_Right, m_pPreTextObj->m_Top);
1507 CPDF_TextObjectItem PrevItem, item; 1342 CPDF_TextObjectItem PrevItem, item;
1508 int nItem = m_pPreTextObj->CountItems(); 1343 int nItem = m_pPreTextObj->CountItems();
1509 m_pPreTextObj->GetItemInfo(nItem - 1, &PrevItem); 1344 m_pPreTextObj->GetItemInfo(nItem - 1, &PrevItem);
1510 pObj->GetItemInfo(0, &item); 1345 pObj->GetItemInfo(0, &item);
1511 CFX_WideString wstrItem = 1346 CFX_WideString wstrItem =
1512 pObj->GetFont()->UnicodeFromCharCode(item.m_CharCode); 1347 pObj->GetFont()->UnicodeFromCharCode(item.m_CharCode);
1513 if (wstrItem.IsEmpty()) { 1348 if (wstrItem.IsEmpty())
1514 wstrItem += (FX_WCHAR)item.m_CharCode; 1349 wstrItem += (FX_WCHAR)item.m_CharCode;
Lei Zhang 2016/08/25 01:14:25 Remove C-cast.
npm 2016/08/25 14:13:26 Done.
1515 }
1516 FX_WCHAR curChar = wstrItem.GetAt(0); 1350 FX_WCHAR curChar = wstrItem.GetAt(0);
1517 if (WritingMode == TextOrientation::Horizontal) { 1351 if (WritingMode == TextOrientation::Horizontal) {
1518 if (this_rect.Height() > 4.5 && prev_rect.Height() > 4.5) { 1352 if (this_rect.Height() > 4.5 && prev_rect.Height() > 4.5) {
1519 FX_FLOAT top = 1353 FX_FLOAT top =
1520 this_rect.top < prev_rect.top ? this_rect.top : prev_rect.top; 1354 this_rect.top < prev_rect.top ? this_rect.top : prev_rect.top;
1521 FX_FLOAT bottom = this_rect.bottom > prev_rect.bottom ? this_rect.bottom 1355 FX_FLOAT bottom = this_rect.bottom > prev_rect.bottom ? this_rect.bottom
1522 : prev_rect.bottom; 1356 : prev_rect.bottom;
1523 if (bottom >= top) { 1357 if (bottom >= top) {
1524 return IsHyphen(curChar) ? GenerateCharacter::Hyphen 1358 return IsHyphen(curChar) ? GenerateCharacter::Hyphen
1525 : GenerateCharacter::LineBreak; 1359 : GenerateCharacter::LineBreak;
(...skipping 23 matching lines...) Expand all
1549 FX_FLOAT threshold = 1383 FX_FLOAT threshold =
1550 last_width > this_width ? last_width / 4 : this_width / 4; 1384 last_width > this_width ? last_width / 4 : this_width / 4;
1551 CFX_Matrix prev_matrix, prev_reverse; 1385 CFX_Matrix prev_matrix, prev_reverse;
1552 m_pPreTextObj->GetTextMatrix(&prev_matrix); 1386 m_pPreTextObj->GetTextMatrix(&prev_matrix);
1553 prev_matrix.Concat(m_perMatrix); 1387 prev_matrix.Concat(m_perMatrix);
1554 prev_reverse.SetReverse(prev_matrix); 1388 prev_reverse.SetReverse(prev_matrix);
1555 FX_FLOAT x = pObj->GetPosX(); 1389 FX_FLOAT x = pObj->GetPosX();
1556 FX_FLOAT y = pObj->GetPosY(); 1390 FX_FLOAT y = pObj->GetPosY();
1557 formMatrix.Transform(x, y); 1391 formMatrix.Transform(x, y);
1558 prev_reverse.Transform(x, y); 1392 prev_reverse.Transform(x, y);
1559 if (last_width < this_width) { 1393 if (last_width < this_width)
1560 threshold = prev_reverse.TransformDistance(threshold); 1394 threshold = prev_reverse.TransformDistance(threshold);
1561 }
1562 bool bNewline = false; 1395 bool bNewline = false;
1563 if (WritingMode == TextOrientation::Horizontal) { 1396 if (WritingMode == TextOrientation::Horizontal) {
1564 CFX_FloatRect rect1(m_pPreTextObj->m_Left, pObj->m_Bottom, 1397 CFX_FloatRect rect1(m_pPreTextObj->m_Left, pObj->m_Bottom,
1565 m_pPreTextObj->m_Right, pObj->m_Top); 1398 m_pPreTextObj->m_Right, pObj->m_Top);
1566 CFX_FloatRect rect2(m_pPreTextObj->m_Left, m_pPreTextObj->m_Bottom, 1399 CFX_FloatRect rect2(m_pPreTextObj->m_Left, m_pPreTextObj->m_Bottom,
1567 m_pPreTextObj->m_Right, m_pPreTextObj->m_Top); 1400 m_pPreTextObj->m_Right, m_pPreTextObj->m_Top);
1568 CFX_FloatRect rect3 = rect1; 1401 CFX_FloatRect rect3 = rect1;
1569 rect1.Intersect(rect2); 1402 rect1.Intersect(rect2);
1570 if ((rect1.IsEmpty() && rect2.Height() > 5 && rect3.Height() > 5) || 1403 if ((rect1.IsEmpty() && rect2.Height() > 5 && rect3.Height() > 5) ||
1571 ((y > threshold * 2 || y < threshold * -3) && 1404 ((y > threshold * 2 || y < threshold * -3) &&
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1629 (threshold < 1.39001 && threshold > 1.38999)) { 1462 (threshold < 1.39001 && threshold > 1.38999)) {
1630 threshold *= 1.5; 1463 threshold *= 1.5;
1631 } 1464 }
1632 if (FXSYS_fabs(last_pos + last_width - x) > threshold && curChar != L' ' && 1465 if (FXSYS_fabs(last_pos + last_width - x) > threshold && curChar != L' ' &&
1633 preChar != L' ') { 1466 preChar != L' ') {
1634 if (curChar != L' ' && preChar != L' ') { 1467 if (curChar != L' ' && preChar != L' ') {
1635 if ((x - last_pos - last_width) > threshold || 1468 if ((x - last_pos - last_width) > threshold ||
1636 (last_pos - x - last_width) > threshold) { 1469 (last_pos - x - last_width) > threshold) {
1637 return GenerateCharacter::Space; 1470 return GenerateCharacter::Space;
1638 } 1471 }
1639 if (x < 0 && (last_pos - x - last_width) > threshold) { 1472 if (x < 0 && (last_pos - x - last_width) > threshold)
1640 return GenerateCharacter::Space; 1473 return GenerateCharacter::Space;
1641 }
1642 if ((x - last_pos - last_width) > this_width || 1474 if ((x - last_pos - last_width) > this_width ||
1643 (x - last_pos - this_width) > last_width) { 1475 (x - last_pos - this_width) > last_width) {
1644 return GenerateCharacter::Space; 1476 return GenerateCharacter::Space;
1645 } 1477 }
1646 } 1478 }
1647 } 1479 }
1648 return GenerateCharacter::None; 1480 return GenerateCharacter::None;
1649 } 1481 }
1650 1482
1651 FX_BOOL CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1, 1483 FX_BOOL CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1,
1652 CPDF_TextObject* pTextObj2) { 1484 CPDF_TextObject* pTextObj2) {
1653 if (!pTextObj1 || !pTextObj2) { 1485 if (!pTextObj1 || !pTextObj2)
1654 return FALSE; 1486 return FALSE;
1655 }
1656 CFX_FloatRect rcPreObj(pTextObj2->m_Left, pTextObj2->m_Bottom, 1487 CFX_FloatRect rcPreObj(pTextObj2->m_Left, pTextObj2->m_Bottom,
1657 pTextObj2->m_Right, pTextObj2->m_Top); 1488 pTextObj2->m_Right, pTextObj2->m_Top);
1658 CFX_FloatRect rcCurObj(pTextObj1->m_Left, pTextObj1->m_Bottom, 1489 CFX_FloatRect rcCurObj(pTextObj1->m_Left, pTextObj1->m_Bottom,
1659 pTextObj1->m_Right, pTextObj1->m_Top); 1490 pTextObj1->m_Right, pTextObj1->m_Top);
1660 if (rcPreObj.IsEmpty() && rcCurObj.IsEmpty()) { 1491 if (rcPreObj.IsEmpty() && rcCurObj.IsEmpty()) {
1661 FX_FLOAT dbXdif = FXSYS_fabs(rcPreObj.left - rcCurObj.left); 1492 FX_FLOAT dbXdif = FXSYS_fabs(rcPreObj.left - rcCurObj.left);
1662 size_t nCount = m_CharList.size(); 1493 size_t nCount = m_CharList.size();
1663 if (nCount >= 2) { 1494 if (nCount >= 2) {
1664 PAGECHAR_INFO perCharTemp = m_CharList[nCount - 2]; 1495 PAGECHAR_INFO perCharTemp = m_CharList[nCount - 2];
1665 FX_FLOAT dbSpace = perCharTemp.m_CharBox.Width(); 1496 FX_FLOAT dbSpace = perCharTemp.m_CharBox.Width();
1666 if (dbXdif > dbSpace) { 1497 if (dbXdif > dbSpace)
1667 return FALSE; 1498 return FALSE;
1668 }
1669 } 1499 }
1670 } 1500 }
1671 if (!rcPreObj.IsEmpty() || !rcCurObj.IsEmpty()) { 1501 if (!rcPreObj.IsEmpty() || !rcCurObj.IsEmpty()) {
1672 rcPreObj.Intersect(rcCurObj); 1502 rcPreObj.Intersect(rcCurObj);
1673 if (rcPreObj.IsEmpty()) { 1503 if (rcPreObj.IsEmpty())
1674 return FALSE; 1504 return FALSE;
1675 }
1676 if (FXSYS_fabs(rcPreObj.Width() - rcCurObj.Width()) > 1505 if (FXSYS_fabs(rcPreObj.Width() - rcCurObj.Width()) >
1677 rcCurObj.Width() / 2) { 1506 rcCurObj.Width() / 2) {
1678 return FALSE; 1507 return FALSE;
1679 } 1508 }
1680 if (pTextObj2->GetFontSize() != pTextObj1->GetFontSize()) { 1509 if (pTextObj2->GetFontSize() != pTextObj1->GetFontSize())
1681 return FALSE; 1510 return FALSE;
1682 }
1683 } 1511 }
1684 int nPreCount = pTextObj2->CountItems(); 1512 int nPreCount = pTextObj2->CountItems();
1685 int nCurCount = pTextObj1->CountItems(); 1513 int nCurCount = pTextObj1->CountItems();
1686 if (nPreCount != nCurCount) { 1514 if (nPreCount != nCurCount)
1687 return FALSE; 1515 return FALSE;
1688 }
1689 // If both objects have no items, consider them same. 1516 // If both objects have no items, consider them same.
1690 if (!nPreCount) 1517 if (!nPreCount)
1691 return TRUE; 1518 return TRUE;
1692 1519
1693 CPDF_TextObjectItem itemPer = {0, 0.0f, 0.0f}; 1520 CPDF_TextObjectItem itemPer = {0, 0.0f, 0.0f};
1694 CPDF_TextObjectItem itemCur = {0, 0.0f, 0.0f}; 1521 CPDF_TextObjectItem itemCur = {0, 0.0f, 0.0f};
1695 for (int i = 0; i < nPreCount; i++) { 1522 for (int i = 0; i < nPreCount; i++) {
1696 pTextObj2->GetItemInfo(i, &itemPer); 1523 pTextObj2->GetItemInfo(i, &itemPer);
1697 pTextObj1->GetItemInfo(i, &itemCur); 1524 pTextObj1->GetItemInfo(i, &itemCur);
1698 if (itemCur.m_CharCode != itemPer.m_CharCode) { 1525 if (itemCur.m_CharCode != itemPer.m_CharCode)
1699 return FALSE; 1526 return FALSE;
1700 }
1701 } 1527 }
1702 if (FXSYS_fabs(pTextObj1->GetPosX() - pTextObj2->GetPosX()) > 1528 if (FXSYS_fabs(pTextObj1->GetPosX() - pTextObj2->GetPosX()) >
1703 GetCharWidth(itemPer.m_CharCode, pTextObj2->GetFont()) * 1529 GetCharWidth(itemPer.m_CharCode, pTextObj2->GetFont()) *
1704 pTextObj2->GetFontSize() / 1000 * 0.9 || 1530 pTextObj2->GetFontSize() / 1000 * 0.9 ||
1705 FXSYS_fabs(pTextObj1->GetPosY() - pTextObj2->GetPosY()) > 1531 FXSYS_fabs(pTextObj1->GetPosY() - pTextObj2->GetPosY()) >
1706 std::max(std::max(rcPreObj.Height(), rcPreObj.Width()), 1532 std::max(std::max(rcPreObj.Height(), rcPreObj.Width()),
1707 pTextObj2->GetFontSize()) / 1533 pTextObj2->GetFontSize()) /
1708 8) { 1534 8) {
1709 return FALSE; 1535 return FALSE;
1710 } 1536 }
(...skipping 12 matching lines...) Expand all
1723 continue; 1549 continue;
1724 if (IsSameTextObject(pOtherObj->AsText(), pTextObj)) 1550 if (IsSameTextObject(pOtherObj->AsText(), pTextObj))
1725 return TRUE; 1551 return TRUE;
1726 ++i; 1552 ++i;
1727 } 1553 }
1728 return FALSE; 1554 return FALSE;
1729 } 1555 }
1730 1556
1731 FX_BOOL CPDF_TextPage::GenerateCharInfo(FX_WCHAR unicode, PAGECHAR_INFO& info) { 1557 FX_BOOL CPDF_TextPage::GenerateCharInfo(FX_WCHAR unicode, PAGECHAR_INFO& info) {
1732 const PAGECHAR_INFO* preChar; 1558 const PAGECHAR_INFO* preChar;
1733 if (!m_TempCharList.empty()) { 1559 if (!m_TempCharList.empty())
1734 preChar = &m_TempCharList.back(); 1560 preChar = &m_TempCharList.back();
1735 } else if (!m_CharList.empty()) { 1561 else if (!m_CharList.empty())
1736 preChar = &m_CharList.back(); 1562 preChar = &m_CharList.back();
1737 } else { 1563 else
1738 return FALSE; 1564 return FALSE;
1739 }
1740 info.m_Index = m_TextBuf.GetLength(); 1565 info.m_Index = m_TextBuf.GetLength();
1741 info.m_Unicode = unicode; 1566 info.m_Unicode = unicode;
1742 info.m_pTextObj = nullptr; 1567 info.m_pTextObj = nullptr;
1743 info.m_CharCode = CPDF_Font::kInvalidCharCode; 1568 info.m_CharCode = CPDF_Font::kInvalidCharCode;
1744 info.m_Flag = FPDFTEXT_CHAR_GENERATED; 1569 info.m_Flag = FPDFTEXT_CHAR_GENERATED;
1745 int preWidth = 0; 1570 int preWidth = 0;
1746 if (preChar->m_pTextObj && preChar->m_CharCode != -1) { 1571 if (preChar->m_pTextObj && preChar->m_CharCode != -1) {
1747 preWidth = 1572 preWidth =
1748 GetCharWidth(preChar->m_CharCode, preChar->m_pTextObj->GetFont()); 1573 GetCharWidth(preChar->m_CharCode, preChar->m_pTextObj->GetFont());
1749 } 1574 }
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
2319 return index < m_LinkArray.size() ? m_LinkArray[index].m_strUrl : L""; 2144 return index < m_LinkArray.size() ? m_LinkArray[index].m_strUrl : L"";
2320 } 2145 }
2321 2146
2322 std::vector<CFX_FloatRect> CPDF_LinkExtract::GetRects(size_t index) const { 2147 std::vector<CFX_FloatRect> CPDF_LinkExtract::GetRects(size_t index) const {
2323 if (index >= m_LinkArray.size()) 2148 if (index >= m_LinkArray.size())
2324 return std::vector<CFX_FloatRect>(); 2149 return std::vector<CFX_FloatRect>();
2325 2150
2326 return m_pTextPage->GetRectArray(m_LinkArray[index].m_Start, 2151 return m_pTextPage->GetRectArray(m_LinkArray[index].m_Start,
2327 m_LinkArray[index].m_Count); 2152 m_LinkArray[index].m_Count);
2328 } 2153 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdftext/include/cpdf_textpage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698