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 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 | 530 |
531 CFX_WideString CPDF_TextPage::GetPageText(int start, int nCount) const { | 531 CFX_WideString CPDF_TextPage::GetPageText(int start, int nCount) const { |
532 if (!m_bIsParsed || nCount == 0) | 532 if (!m_bIsParsed || nCount == 0) |
533 return L""; | 533 return L""; |
534 | 534 |
535 if (start < 0) | 535 if (start < 0) |
536 start = 0; | 536 start = 0; |
537 | 537 |
538 if (nCount == -1) { | 538 if (nCount == -1) { |
539 nCount = pdfium::CollectionSize<int>(m_CharList) - start; | 539 nCount = pdfium::CollectionSize<int>(m_CharList) - start; |
540 return m_TextBuf.AsStringC().Mid(start, m_TextBuf.AsStringC().GetLength()); | 540 return CFX_WideString( |
| 541 m_TextBuf.AsStringC().Mid(start, m_TextBuf.AsStringC().GetLength())); |
541 } | 542 } |
542 if (nCount <= 0 || m_CharList.empty()) { | 543 if (nCount <= 0 || m_CharList.empty()) { |
543 return L""; | 544 return L""; |
544 } | 545 } |
545 if (nCount + start > pdfium::CollectionSize<int>(m_CharList) - 1) { | 546 if (nCount + start > pdfium::CollectionSize<int>(m_CharList) - 1) { |
546 nCount = pdfium::CollectionSize<int>(m_CharList) - start; | 547 nCount = pdfium::CollectionSize<int>(m_CharList) - start; |
547 } | 548 } |
548 if (nCount <= 0) { | 549 if (nCount <= 0) { |
549 return L""; | 550 return L""; |
550 } | 551 } |
(...skipping 16 matching lines...) Expand all Loading... |
567 nCountOffset++; | 568 nCountOffset++; |
568 if (nCountOffset >= nCount) { | 569 if (nCountOffset >= nCount) { |
569 return L""; | 570 return L""; |
570 } | 571 } |
571 charinfo = m_CharList[start + nCount - nCountOffset - 1]; | 572 charinfo = m_CharList[start + nCount - nCountOffset - 1]; |
572 } | 573 } |
573 nCount = start + nCount - nCountOffset - startindex; | 574 nCount = start + nCount - nCountOffset - startindex; |
574 if (nCount <= 0) { | 575 if (nCount <= 0) { |
575 return L""; | 576 return L""; |
576 } | 577 } |
577 return m_TextBuf.AsStringC().Mid(startindex, nCount); | 578 return CFX_WideString(m_TextBuf.AsStringC().Mid(startindex, nCount)); |
578 } | 579 } |
579 | 580 |
580 int CPDF_TextPage::CountRects(int start, int nCount) { | 581 int CPDF_TextPage::CountRects(int start, int nCount) { |
581 if (!m_bIsParsed || start < 0) | 582 if (!m_bIsParsed || start < 0) |
582 return -1; | 583 return -1; |
583 | 584 |
584 if (nCount == -1 || | 585 if (nCount == -1 || |
585 nCount + start > pdfium::CollectionSize<int>(m_CharList)) { | 586 nCount + start > pdfium::CollectionSize<int>(m_CharList)) { |
586 nCount = pdfium::CollectionSize<int>(m_CharList) - start; | 587 nCount = pdfium::CollectionSize<int>(m_CharList) - start; |
587 } | 588 } |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 } else { | 884 } else { |
884 info.m_Index = -1; | 885 info.m_Index = -1; |
885 } | 886 } |
886 m_CharList.push_back(info); | 887 m_CharList.push_back(info); |
887 } | 888 } |
888 | 889 |
889 void CPDF_TextPage::CloseTempLine() { | 890 void CPDF_TextPage::CloseTempLine() { |
890 if (m_TempCharList.empty()) | 891 if (m_TempCharList.empty()) |
891 return; | 892 return; |
892 | 893 |
893 CFX_WideString str = m_TempTextBuf.AsStringC(); | 894 CFX_WideString str = m_TempTextBuf.MakeString(); |
894 FX_BOOL bPrevSpace = FALSE; | 895 FX_BOOL bPrevSpace = FALSE; |
895 for (int i = 0; i < str.GetLength(); i++) { | 896 for (int i = 0; i < str.GetLength(); i++) { |
896 if (str.GetAt(i) != ' ') { | 897 if (str.GetAt(i) != ' ') { |
897 bPrevSpace = FALSE; | 898 bPrevSpace = FALSE; |
898 continue; | 899 continue; |
899 } | 900 } |
900 if (bPrevSpace) { | 901 if (bPrevSpace) { |
901 m_TempTextBuf.Delete(i, 1); | 902 m_TempTextBuf.Delete(i, 1); |
902 m_TempCharList.erase(m_TempCharList.begin() + i); | 903 m_TempCharList.erase(m_TempCharList.begin() + i); |
903 str.Delete(i); | 904 str.Delete(i); |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 pdfium::CollectionSize<int32_t>(m_TempCharList); | 1293 pdfium::CollectionSize<int32_t>(m_TempCharList); |
1293 | 1294 |
1294 FX_FLOAT spacing = 0; | 1295 FX_FLOAT spacing = 0; |
1295 for (int i = 0; i < nItems; i++) { | 1296 for (int i = 0; i < nItems; i++) { |
1296 CPDF_TextObjectItem item; | 1297 CPDF_TextObjectItem item; |
1297 PAGECHAR_INFO charinfo; | 1298 PAGECHAR_INFO charinfo; |
1298 charinfo.m_OriginX = 0; | 1299 charinfo.m_OriginX = 0; |
1299 charinfo.m_OriginY = 0; | 1300 charinfo.m_OriginY = 0; |
1300 pTextObj->GetItemInfo(i, &item); | 1301 pTextObj->GetItemInfo(i, &item); |
1301 if (item.m_CharCode == (uint32_t)-1) { | 1302 if (item.m_CharCode == (uint32_t)-1) { |
1302 CFX_WideString str = m_TempTextBuf.AsStringC(); | 1303 CFX_WideString str = m_TempTextBuf.MakeString(); |
1303 if (str.IsEmpty()) { | 1304 if (str.IsEmpty()) { |
1304 str = m_TextBuf.AsStringC(); | 1305 str = m_TextBuf.AsStringC(); |
1305 } | 1306 } |
1306 if (str.IsEmpty() || str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) { | 1307 if (str.IsEmpty() || str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) { |
1307 continue; | 1308 continue; |
1308 } | 1309 } |
1309 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); | 1310 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); |
1310 spacing = -fontsize_h * item.m_OriginX / 1000; | 1311 spacing = -fontsize_h * item.m_OriginX / 1000; |
1311 continue; | 1312 continue; |
1312 } | 1313 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1428 charinfo.m_Unicode = wstrItem.GetAt(nIndex); | 1429 charinfo.m_Unicode = wstrItem.GetAt(nIndex); |
1429 if (charinfo.m_Unicode) { | 1430 if (charinfo.m_Unicode) { |
1430 charinfo.m_Index = m_TextBuf.GetLength(); | 1431 charinfo.m_Index = m_TextBuf.GetLength(); |
1431 m_TempTextBuf.AppendChar(charinfo.m_Unicode); | 1432 m_TempTextBuf.AppendChar(charinfo.m_Unicode); |
1432 } else { | 1433 } else { |
1433 m_TempTextBuf.AppendChar(0xfffe); | 1434 m_TempTextBuf.AppendChar(0xfffe); |
1434 } | 1435 } |
1435 m_TempCharList.push_back(charinfo); | 1436 m_TempCharList.push_back(charinfo); |
1436 } | 1437 } |
1437 } else if (i == 0) { | 1438 } else if (i == 0) { |
1438 CFX_WideString str = m_TempTextBuf.AsStringC(); | 1439 CFX_WideString str = m_TempTextBuf.MakeString(); |
1439 if (!str.IsEmpty() && | 1440 if (!str.IsEmpty() && |
1440 str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) { | 1441 str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) { |
1441 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); | 1442 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); |
1442 m_TempCharList.pop_back(); | 1443 m_TempCharList.pop_back(); |
1443 } | 1444 } |
1444 } | 1445 } |
1445 } | 1446 } |
1446 } | 1447 } |
1447 if (bIsBidiAndMirrorInverse) { | 1448 if (bIsBidiAndMirrorInverse) { |
1448 SwapTempTextBuf(iCharListStartAppend, iBufStartAppend); | 1449 SwapTempTextBuf(iCharListStartAppend, iBufStartAppend); |
(...skipping 22 matching lines...) Expand all Loading... |
1471 v.Normalize(); | 1472 v.Normalize(); |
1472 if (v.y <= 0.0872f) { | 1473 if (v.y <= 0.0872f) { |
1473 return v.x <= 0.0872f ? m_TextlineDir : 0; | 1474 return v.x <= 0.0872f ? m_TextlineDir : 0; |
1474 } | 1475 } |
1475 if (v.x <= 0.0872f) { | 1476 if (v.x <= 0.0872f) { |
1476 return 1; | 1477 return 1; |
1477 } | 1478 } |
1478 return m_TextlineDir; | 1479 return m_TextlineDir; |
1479 } | 1480 } |
1480 FX_BOOL CPDF_TextPage::IsHyphen(FX_WCHAR curChar) { | 1481 FX_BOOL CPDF_TextPage::IsHyphen(FX_WCHAR curChar) { |
1481 CFX_WideString strCurText = m_TempTextBuf.AsStringC(); | 1482 CFX_WideString strCurText = m_TempTextBuf.MakeString(); |
1482 if (strCurText.GetLength() == 0) { | 1483 if (strCurText.GetLength() == 0) { |
1483 strCurText = m_TextBuf.AsStringC(); | 1484 strCurText = m_TextBuf.AsStringC(); |
1484 } | 1485 } |
1485 FX_STRSIZE nCount = strCurText.GetLength(); | 1486 FX_STRSIZE nCount = strCurText.GetLength(); |
1486 int nIndex = nCount - 1; | 1487 int nIndex = nCount - 1; |
1487 FX_WCHAR wcTmp = strCurText.GetAt(nIndex); | 1488 FX_WCHAR wcTmp = strCurText.GetAt(nIndex); |
1488 while (wcTmp == 0x20 && nIndex <= nCount - 1 && nIndex >= 0) { | 1489 while (wcTmp == 0x20 && nIndex <= nCount - 1 && nIndex >= 0) { |
1489 wcTmp = strCurText.GetAt(--nIndex); | 1490 wcTmp = strCurText.GetAt(--nIndex); |
1490 } | 1491 } |
1491 if (0x2D == wcTmp || 0xAD == wcTmp) { | 1492 if (0x2D == wcTmp || 0xAD == wcTmp) { |
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2340 return index < m_LinkArray.size() ? m_LinkArray[index].m_strUrl : L""; | 2341 return index < m_LinkArray.size() ? m_LinkArray[index].m_strUrl : L""; |
2341 } | 2342 } |
2342 | 2343 |
2343 std::vector<CFX_FloatRect> CPDF_LinkExtract::GetRects(size_t index) const { | 2344 std::vector<CFX_FloatRect> CPDF_LinkExtract::GetRects(size_t index) const { |
2344 if (index >= m_LinkArray.size()) | 2345 if (index >= m_LinkArray.size()) |
2345 return std::vector<CFX_FloatRect>(); | 2346 return std::vector<CFX_FloatRect>(); |
2346 | 2347 |
2347 return m_pTextPage->GetRectArray(m_LinkArray[index].m_Start, | 2348 return m_pTextPage->GetRectArray(m_LinkArray[index].m_Start, |
2348 m_LinkArray[index].m_Count); | 2349 m_LinkArray[index].m_Count); |
2349 } | 2350 } |
OLD | NEW |