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