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

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

Issue 1886263003: Rename CFX_ByteTextBuf::GetByteString() to AsStringC(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdftext/fpdf_text_int.h" 7 #include "core/fpdftext/fpdf_text_int.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cctype> 10 #include <cctype>
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 505
506 CFX_WideString CPDF_TextPage::GetPageText(int start, int nCount) const { 506 CFX_WideString CPDF_TextPage::GetPageText(int start, int nCount) const {
507 if (!m_bIsParsed || nCount == 0) 507 if (!m_bIsParsed || nCount == 0)
508 return L""; 508 return L"";
509 509
510 if (start < 0) 510 if (start < 0)
511 start = 0; 511 start = 0;
512 512
513 if (nCount == -1) { 513 if (nCount == -1) {
514 nCount = pdfium::CollectionSize<int>(m_CharList) - start; 514 nCount = pdfium::CollectionSize<int>(m_CharList) - start;
515 return m_TextBuf.GetWideString().Mid(start, 515 return m_TextBuf.AsStringC().Mid(start, m_TextBuf.AsStringC().GetLength());
516 m_TextBuf.GetWideString().GetLength());
517 } 516 }
518 if (nCount <= 0 || m_CharList.empty()) { 517 if (nCount <= 0 || m_CharList.empty()) {
519 return L""; 518 return L"";
520 } 519 }
521 if (nCount + start > pdfium::CollectionSize<int>(m_CharList) - 1) { 520 if (nCount + start > pdfium::CollectionSize<int>(m_CharList) - 1) {
522 nCount = pdfium::CollectionSize<int>(m_CharList) - start; 521 nCount = pdfium::CollectionSize<int>(m_CharList) - start;
523 } 522 }
524 if (nCount <= 0) { 523 if (nCount <= 0) {
525 return L""; 524 return L"";
526 } 525 }
(...skipping 16 matching lines...) Expand all
543 nCountOffset++; 542 nCountOffset++;
544 if (nCountOffset >= nCount) { 543 if (nCountOffset >= nCount) {
545 return L""; 544 return L"";
546 } 545 }
547 charinfo = m_CharList[start + nCount - nCountOffset - 1]; 546 charinfo = m_CharList[start + nCount - nCountOffset - 1];
548 } 547 }
549 nCount = start + nCount - nCountOffset - startindex; 548 nCount = start + nCount - nCountOffset - startindex;
550 if (nCount <= 0) { 549 if (nCount <= 0) {
551 return L""; 550 return L"";
552 } 551 }
553 return m_TextBuf.GetWideString().Mid(startindex, nCount); 552 return m_TextBuf.AsStringC().Mid(startindex, nCount);
554 } 553 }
555 554
556 int CPDF_TextPage::CountRects(int start, int nCount) { 555 int CPDF_TextPage::CountRects(int start, int nCount) {
557 if (!m_bIsParsed || start < 0) 556 if (!m_bIsParsed || start < 0)
558 return -1; 557 return -1;
559 558
560 if (nCount == -1 || 559 if (nCount == -1 ||
561 nCount + start > pdfium::CollectionSize<int>(m_CharList)) { 560 nCount + start > pdfium::CollectionSize<int>(m_CharList)) {
562 nCount = pdfium::CollectionSize<int>(m_CharList) - start; 561 nCount = pdfium::CollectionSize<int>(m_CharList) - start;
563 } 562 }
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 } else { 979 } else {
981 info.m_Index = -1; 980 info.m_Index = -1;
982 } 981 }
983 m_CharList.push_back(info); 982 m_CharList.push_back(info);
984 } 983 }
985 984
986 void CPDF_TextPage::CloseTempLine() { 985 void CPDF_TextPage::CloseTempLine() {
987 if (m_TempCharList.empty()) 986 if (m_TempCharList.empty())
988 return; 987 return;
989 988
990 CFX_WideString str = m_TempTextBuf.GetWideString(); 989 CFX_WideString str = m_TempTextBuf.AsStringC();
991 FX_BOOL bPrevSpace = FALSE; 990 FX_BOOL bPrevSpace = FALSE;
992 for (int i = 0; i < str.GetLength(); i++) { 991 for (int i = 0; i < str.GetLength(); i++) {
993 if (str.GetAt(i) != ' ') { 992 if (str.GetAt(i) != ' ') {
994 bPrevSpace = FALSE; 993 bPrevSpace = FALSE;
995 continue; 994 continue;
996 } 995 }
997 if (bPrevSpace) { 996 if (bPrevSpace) {
998 m_TempTextBuf.Delete(i, 1); 997 m_TempTextBuf.Delete(i, 1);
999 m_TempCharList.erase(m_TempCharList.begin() + i); 998 m_TempCharList.erase(m_TempCharList.begin() + i);
1000 str.Delete(i); 999 str.Delete(i);
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 pTextObj->GetFont()->UnicodeFromCharCode(item.m_CharCode); 1345 pTextObj->GetFont()->UnicodeFromCharCode(item.m_CharCode);
1347 if (wstrItem.IsEmpty()) { 1346 if (wstrItem.IsEmpty()) {
1348 wstrItem += (FX_WCHAR)item.m_CharCode; 1347 wstrItem += (FX_WCHAR)item.m_CharCode;
1349 } 1348 }
1350 FX_WCHAR curChar = wstrItem.GetAt(0); 1349 FX_WCHAR curChar = wstrItem.GetAt(0);
1351 if (0x2D == curChar || 0xAD == curChar) { 1350 if (0x2D == curChar || 0xAD == curChar) {
1352 return; 1351 return;
1353 } 1352 }
1354 } 1353 }
1355 while (m_TempTextBuf.GetSize() > 0 && 1354 while (m_TempTextBuf.GetSize() > 0 &&
1356 m_TempTextBuf.GetWideString().GetAt(m_TempTextBuf.GetLength() - 1355 m_TempTextBuf.AsStringC().GetAt(m_TempTextBuf.GetLength() - 1) ==
1357 1) == 0x20) { 1356 0x20) {
1358 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); 1357 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1);
1359 m_TempCharList.pop_back(); 1358 m_TempCharList.pop_back();
1360 } 1359 }
1361 PAGECHAR_INFO* charinfo = &m_TempCharList.back(); 1360 PAGECHAR_INFO* charinfo = &m_TempCharList.back();
1362 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); 1361 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1);
1363 charinfo->m_Unicode = 0x2; 1362 charinfo->m_Unicode = 0x2;
1364 charinfo->m_Flag = FPDFTEXT_CHAR_HYPHEN; 1363 charinfo->m_Flag = FPDFTEXT_CHAR_HYPHEN;
1365 m_TempTextBuf.AppendChar(0xfffe); 1364 m_TempTextBuf.AppendChar(0xfffe);
1366 } 1365 }
1367 } else { 1366 } else {
(...skipping 20 matching lines...) Expand all
1388 pdfium::CollectionSize<int32_t>(m_TempCharList); 1387 pdfium::CollectionSize<int32_t>(m_TempCharList);
1389 1388
1390 FX_FLOAT spacing = 0; 1389 FX_FLOAT spacing = 0;
1391 for (int i = 0; i < nItems; i++) { 1390 for (int i = 0; i < nItems; i++) {
1392 CPDF_TextObjectItem item; 1391 CPDF_TextObjectItem item;
1393 PAGECHAR_INFO charinfo; 1392 PAGECHAR_INFO charinfo;
1394 charinfo.m_OriginX = 0; 1393 charinfo.m_OriginX = 0;
1395 charinfo.m_OriginY = 0; 1394 charinfo.m_OriginY = 0;
1396 pTextObj->GetItemInfo(i, &item); 1395 pTextObj->GetItemInfo(i, &item);
1397 if (item.m_CharCode == (uint32_t)-1) { 1396 if (item.m_CharCode == (uint32_t)-1) {
1398 CFX_WideString str = m_TempTextBuf.GetWideString(); 1397 CFX_WideString str = m_TempTextBuf.AsStringC();
1399 if (str.IsEmpty()) { 1398 if (str.IsEmpty()) {
1400 str = m_TextBuf.GetWideString(); 1399 str = m_TextBuf.AsStringC();
1401 } 1400 }
1402 if (str.IsEmpty() || str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) { 1401 if (str.IsEmpty() || str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) {
1403 continue; 1402 continue;
1404 } 1403 }
1405 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH(); 1404 FX_FLOAT fontsize_h = pTextObj->m_TextState.GetFontSizeH();
1406 spacing = -fontsize_h * item.m_OriginX / 1000; 1405 spacing = -fontsize_h * item.m_OriginX / 1000;
1407 continue; 1406 continue;
1408 } 1407 }
1409 FX_FLOAT charSpace = pTextObj->m_TextState.GetObject()->m_CharSpace; 1408 FX_FLOAT charSpace = pTextObj->m_TextState.GetObject()->m_CharSpace;
1410 if (charSpace > 0.001) { 1409 if (charSpace > 0.001) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 charinfo.m_Unicode = wstrItem.GetAt(nIndex); 1523 charinfo.m_Unicode = wstrItem.GetAt(nIndex);
1525 if (charinfo.m_Unicode) { 1524 if (charinfo.m_Unicode) {
1526 charinfo.m_Index = m_TextBuf.GetLength(); 1525 charinfo.m_Index = m_TextBuf.GetLength();
1527 m_TempTextBuf.AppendChar(charinfo.m_Unicode); 1526 m_TempTextBuf.AppendChar(charinfo.m_Unicode);
1528 } else { 1527 } else {
1529 m_TempTextBuf.AppendChar(0xfffe); 1528 m_TempTextBuf.AppendChar(0xfffe);
1530 } 1529 }
1531 m_TempCharList.push_back(charinfo); 1530 m_TempCharList.push_back(charinfo);
1532 } 1531 }
1533 } else if (i == 0) { 1532 } else if (i == 0) {
1534 CFX_WideString str = m_TempTextBuf.GetWideString(); 1533 CFX_WideString str = m_TempTextBuf.AsStringC();
1535 if (!str.IsEmpty() && 1534 if (!str.IsEmpty() &&
1536 str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) { 1535 str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) {
1537 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); 1536 m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1);
1538 m_TempCharList.pop_back(); 1537 m_TempCharList.pop_back();
1539 } 1538 }
1540 } 1539 }
1541 } 1540 }
1542 } 1541 }
1543 if (bIsBidiAndMirrorInverse) { 1542 if (bIsBidiAndMirrorInverse) {
1544 SwapTempTextBuf(iCharListStartAppend, iBufStartAppend); 1543 SwapTempTextBuf(iCharListStartAppend, iBufStartAppend);
(...skipping 22 matching lines...) Expand all
1567 v.Normalize(); 1566 v.Normalize();
1568 if (v.y <= 0.0872f) { 1567 if (v.y <= 0.0872f) {
1569 return v.x <= 0.0872f ? m_TextlineDir : 0; 1568 return v.x <= 0.0872f ? m_TextlineDir : 0;
1570 } 1569 }
1571 if (v.x <= 0.0872f) { 1570 if (v.x <= 0.0872f) {
1572 return 1; 1571 return 1;
1573 } 1572 }
1574 return m_TextlineDir; 1573 return m_TextlineDir;
1575 } 1574 }
1576 FX_BOOL CPDF_TextPage::IsHyphen(FX_WCHAR curChar) { 1575 FX_BOOL CPDF_TextPage::IsHyphen(FX_WCHAR curChar) {
1577 CFX_WideString strCurText = m_TempTextBuf.GetWideString(); 1576 CFX_WideString strCurText = m_TempTextBuf.AsStringC();
1578 if (strCurText.GetLength() == 0) { 1577 if (strCurText.GetLength() == 0) {
1579 strCurText = m_TextBuf.GetWideString(); 1578 strCurText = m_TextBuf.AsStringC();
1580 } 1579 }
1581 FX_STRSIZE nCount = strCurText.GetLength(); 1580 FX_STRSIZE nCount = strCurText.GetLength();
1582 int nIndex = nCount - 1; 1581 int nIndex = nCount - 1;
1583 FX_WCHAR wcTmp = strCurText.GetAt(nIndex); 1582 FX_WCHAR wcTmp = strCurText.GetAt(nIndex);
1584 while (wcTmp == 0x20 && nIndex <= nCount - 1 && nIndex >= 0) { 1583 while (wcTmp == 0x20 && nIndex <= nCount - 1 && nIndex >= 0) {
1585 wcTmp = strCurText.GetAt(--nIndex); 1584 wcTmp = strCurText.GetAt(--nIndex);
1586 } 1585 }
1587 if (0x2D == wcTmp || 0xAD == wcTmp) { 1586 if (0x2D == wcTmp || 0xAD == wcTmp) {
1588 if (--nIndex > 0) { 1587 if (--nIndex > 0) {
1589 FX_WCHAR preChar = strCurText.GetAt((nIndex)); 1588 FX_WCHAR preChar = strCurText.GetAt((nIndex));
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
2511 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { 2510 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) {
2512 return; 2511 return;
2513 } 2512 }
2514 CPDF_LinkExt* link = NULL; 2513 CPDF_LinkExt* link = NULL;
2515 link = m_LinkList.GetAt(index); 2514 link = m_LinkList.GetAt(index);
2516 if (!link) { 2515 if (!link) {
2517 return; 2516 return;
2518 } 2517 }
2519 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); 2518 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects);
2520 } 2519 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698