Chromium Code Reviews| Index: core/src/fpdftext/fpdf_text_int.cpp |
| diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp |
| index 3b633a623f6361fdf52c630513489e23e38ff43d..dae6b9f52697a35846ebdc1abf62dd35183f6d29 100644 |
| --- a/core/src/fpdftext/fpdf_text_int.cpp |
| +++ b/core/src/fpdftext/fpdf_text_int.cpp |
| @@ -4,6 +4,8 @@ |
| // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| +#include "core/src/fpdftext/text_int.h" |
| + |
| #include <algorithm> |
| #include <cctype> |
| #include <cwctype> |
| @@ -17,7 +19,7 @@ |
| #include "core/include/fxcrt/fx_bidi.h" |
| #include "core/include/fxcrt/fx_ext.h" |
| #include "core/include/fxcrt/fx_ucd.h" |
| -#include "text_int.h" |
| +#include "third_party/base/stl_util.h" |
| namespace { |
| @@ -111,8 +113,6 @@ IPDF_LinkExtract* IPDF_LinkExtract::CreateLinkExtract() { |
| CPDF_TextPage::CPDF_TextPage(const CPDF_Page* pPage, int flags) |
| : m_pPage(pPage), |
| - m_charList(512), |
| - m_TempCharList(50), |
| m_parserflag(flags), |
| m_pPreTextObj(nullptr), |
| m_bIsParsed(false), |
| @@ -147,20 +147,20 @@ FX_BOOL CPDF_TextPage::ParseTextPage() { |
| return FALSE; |
| m_TextBuf.Clear(); |
| - m_charList.RemoveAll(); |
| + m_CharList.clear(); |
| m_pPreTextObj = NULL; |
| ProcessObject(); |
| m_bIsParsed = true; |
| if (!m_ParseOptions.m_bGetCharCodeOnly) { |
| m_CharIndex.RemoveAll(); |
| - int nCount = m_charList.GetSize(); |
| + int nCount = pdfium::CollectionSize<int>(m_CharList); |
| if (nCount) { |
| m_CharIndex.Add(0); |
| } |
| for (int i = 0; i < nCount; i++) { |
| int indexSize = m_CharIndex.GetSize(); |
| FX_BOOL bNormal = FALSE; |
| - PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(i); |
| + PAGECHAR_INFO charinfo = m_CharList[i]; |
|
Lei Zhang
2016/01/25 22:11:16
improvement over original code: const ref?
Tom Sepez
2016/01/25 23:04:47
Done.
|
| if (charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) { |
| bNormal = TRUE; |
| } else if (charinfo.m_Unicode == 0 || IsControlChar(charinfo)) { |
| @@ -200,7 +200,7 @@ int CPDF_TextPage::CountChars() const { |
| if (m_ParseOptions.m_bGetCharCodeOnly) { |
| return m_TextBuf.GetSize(); |
| } |
| - return m_charList.GetSize(); |
| + return pdfium::CollectionSize<int>(m_CharList); |
| } |
| int CPDF_TextPage::CharIndexFromTextIndex(int TextIndex) const { |
| int indexSize = m_CharIndex.GetSize(); |
| @@ -241,16 +241,16 @@ void CPDF_TextPage::GetRectArray(int start, |
| if (!m_bIsParsed) { |
| return; |
| } |
| - PAGECHAR_INFO info_curchar; |
| CPDF_TextObject* pCurObj = NULL; |
| CFX_FloatRect rect; |
| int curPos = start; |
| FX_BOOL flagNewRect = TRUE; |
| - if (nCount + start > m_charList.GetSize() || nCount == -1) { |
| - nCount = m_charList.GetSize() - start; |
| + if (nCount + start > pdfium::CollectionSize<int>(m_CharList) || |
| + nCount == -1) { |
| + nCount = pdfium::CollectionSize<int>(m_CharList) - start; |
| } |
| while (nCount--) { |
| - info_curchar = *(PAGECHAR_INFO*)m_charList.GetAt(curPos++); |
| + PAGECHAR_INFO info_curchar = m_CharList[curPos++]; |
| if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED) { |
| continue; |
| } |
| @@ -316,7 +316,6 @@ void CPDF_TextPage::GetRectArray(int start, |
| } |
| } |
| rectArray.Add(rect); |
| - return; |
| } |
| int CPDF_TextPage::GetIndexAtPos(CPDF_Point point, |
| FX_FLOAT xTolerance, |
| @@ -326,9 +325,10 @@ int CPDF_TextPage::GetIndexAtPos(CPDF_Point point, |
| int pos = 0; |
| int NearPos = -1; |
| - double xdif = 5000, ydif = 5000; |
| - while (pos < m_charList.GetSize()) { |
| - PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)(m_charList.GetAt(pos)); |
| + double xdif = 5000; |
| + double ydif = 5000; |
| + while (pos < pdfium::CollectionSize<int>(m_CharList)) { |
| + PAGECHAR_INFO charinfo = m_CharList[pos]; |
| CFX_FloatRect charrect = charinfo.m_CharBox; |
| if (charrect.Contains(point.x, point.y)) { |
| break; |
| @@ -359,45 +359,40 @@ int CPDF_TextPage::GetIndexAtPos(CPDF_Point point, |
| } |
| ++pos; |
| } |
| - if (pos >= m_charList.GetSize()) { |
| - pos = NearPos; |
| - } |
| - return pos; |
| + return pos < pdfium::CollectionSize<int>(m_CharList) ? pos : NearPos; |
| } |
| + |
| CFX_WideString CPDF_TextPage::GetTextByRect(const CFX_FloatRect& rect) const { |
| - CFX_WideString strText; |
| if (m_ParseOptions.m_bGetCharCodeOnly || !m_bIsParsed) |
| - return strText; |
| + return CFX_WideString(); |
| - int nCount = m_charList.GetSize(); |
| - int pos = 0; |
| FX_FLOAT posy = 0; |
| - FX_BOOL IsContainPreChar = FALSE; |
| - FX_BOOL ISAddLineFeed = FALSE; |
| - while (pos < nCount) { |
| - PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(pos++); |
| + bool IsContainPreChar = false; |
| + bool IsAddLineFeed = false; |
| + CFX_WideString strText; |
| + for (const auto& charinfo : m_CharList) { |
| if (IsRectIntersect(rect, charinfo.m_CharBox)) { |
| if (FXSYS_fabs(posy - charinfo.m_OriginY) > 0 && !IsContainPreChar && |
| - ISAddLineFeed) { |
| + IsAddLineFeed) { |
| posy = charinfo.m_OriginY; |
| if (strText.GetLength() > 0) { |
| strText += L"\r\n"; |
| } |
| } |
| - IsContainPreChar = TRUE; |
| - ISAddLineFeed = FALSE; |
| + IsContainPreChar = true; |
| + IsAddLineFeed = false; |
| if (charinfo.m_Unicode) { |
| strText += charinfo.m_Unicode; |
| } |
| } else if (charinfo.m_Unicode == 32) { |
| if (IsContainPreChar && charinfo.m_Unicode) { |
| strText += charinfo.m_Unicode; |
| - IsContainPreChar = FALSE; |
| - ISAddLineFeed = FALSE; |
| + IsContainPreChar = false; |
| + IsAddLineFeed = false; |
| } |
| } else { |
| - IsContainPreChar = FALSE; |
| - ISAddLineFeed = TRUE; |
| + IsContainPreChar = false; |
| + IsAddLineFeed = true; |
| } |
| } |
| return strText; |
| @@ -408,47 +403,36 @@ void CPDF_TextPage::GetRectsArrayByRect(const CFX_FloatRect& rect, |
| return; |
| CFX_FloatRect curRect; |
| - FX_BOOL flagNewRect = TRUE; |
| - CPDF_TextObject* pCurObj = NULL; |
| - int nCount = m_charList.GetSize(); |
| - int pos = 0; |
| - while (pos < nCount) { |
| - PAGECHAR_INFO info_curchar = *(PAGECHAR_INFO*)m_charList.GetAt(pos++); |
| + bool flagNewRect = true; |
| + CPDF_TextObject* pCurObj = nullptr; |
| + for (auto info_curchar : m_CharList) { |
| if (info_curchar.m_Flag == FPDFTEXT_CHAR_GENERATED) { |
| continue; |
| } |
| - if (IsRectIntersect(rect, info_curchar.m_CharBox)) { |
| - if (!pCurObj) { |
| - pCurObj = info_curchar.m_pTextObj; |
| - } |
| - if (pCurObj != info_curchar.m_pTextObj) { |
| - resRectArray.Add(curRect); |
| - pCurObj = info_curchar.m_pTextObj; |
| - flagNewRect = TRUE; |
| - } |
| - if (flagNewRect) { |
| - curRect = info_curchar.m_CharBox; |
| - flagNewRect = FALSE; |
| - curRect.Normalize(); |
| - } else { |
| - info_curchar.m_CharBox.Normalize(); |
| - if (curRect.left > info_curchar.m_CharBox.left) { |
| - curRect.left = info_curchar.m_CharBox.left; |
| - } |
| - if (curRect.right < info_curchar.m_CharBox.right) { |
| - curRect.right = info_curchar.m_CharBox.right; |
| - } |
| - if (curRect.top < info_curchar.m_CharBox.top) { |
| - curRect.top = info_curchar.m_CharBox.top; |
| - } |
| - if (curRect.bottom > info_curchar.m_CharBox.bottom) { |
| - curRect.bottom = info_curchar.m_CharBox.bottom; |
| - } |
| - } |
| + if (!IsRectIntersect(rect, info_curchar.m_CharBox)) { |
| + continue; |
| + } |
| + if (!pCurObj) { |
| + pCurObj = info_curchar.m_pTextObj; |
| + } |
| + if (pCurObj != info_curchar.m_pTextObj) { |
| + resRectArray.Add(curRect); |
| + pCurObj = info_curchar.m_pTextObj; |
| + flagNewRect = true; |
| + } |
| + if (flagNewRect) { |
| + curRect = info_curchar.m_CharBox; |
| + curRect.Normalize(); |
| + flagNewRect = false; |
| + } else { |
| + info_curchar.m_CharBox.Normalize(); |
| + curRect.left = std::min(curRect.left, info_curchar.m_CharBox.left); |
| + curRect.bottom = std::min(curRect.bottom, info_curchar.m_CharBox.bottom); |
| + curRect.right = std::max(curRect.right, info_curchar.m_CharBox.right); |
| + curRect.top = std::max(curRect.top, info_curchar.m_CharBox.top); |
| } |
| } |
| resRectArray.Add(curRect); |
| - return; |
| } |
| int CPDF_TextPage::GetIndexAtPos(FX_FLOAT x, |
| FX_FLOAT y, |
| @@ -465,11 +449,10 @@ void CPDF_TextPage::GetCharInfo(int index, FPDF_CHAR_INFO* info) const { |
| if (m_ParseOptions.m_bGetCharCodeOnly || !m_bIsParsed) |
| return; |
| - if (index < 0 || index >= m_charList.GetSize()) |
| + if (index < 0 || index >= pdfium::CollectionSize<int>(m_CharList)) |
| return; |
| - const PAGECHAR_INFO* charinfo = |
| - static_cast<PAGECHAR_INFO*>(m_charList.GetAt(index)); |
| + const PAGECHAR_INFO* charinfo = &m_CharList[index]; |
|
Lei Zhang
2016/01/25 22:11:16
Also const ref?
Tom Sepez
2016/01/25 23:04:47
Done.
|
| info->m_Charcode = charinfo->m_CharCode; |
| info->m_OriginX = charinfo->m_OriginX; |
| info->m_OriginY = charinfo->m_OriginY; |
| @@ -487,9 +470,8 @@ void CPDF_TextPage::GetCharInfo(int index, FPDF_CHAR_INFO* info) const { |
| void CPDF_TextPage::CheckMarkedContentObject(int32_t& start, |
| int32_t& nCount) const { |
| - PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(start); |
| - PAGECHAR_INFO charinfo2 = |
| - *(PAGECHAR_INFO*)m_charList.GetAt(start + nCount - 1); |
| + PAGECHAR_INFO charinfo = m_CharList[start]; |
| + PAGECHAR_INFO charinfo2 = m_CharList[start + nCount - 1]; |
| if (FPDFTEXT_CHAR_PIECE != charinfo.m_Flag && |
| FPDFTEXT_CHAR_PIECE != charinfo2.m_Flag) { |
| return; |
| @@ -503,7 +485,7 @@ void CPDF_TextPage::CheckMarkedContentObject(int32_t& start, |
| if (startIndex < 0) { |
| break; |
| } |
| - charinfo1 = *(PAGECHAR_INFO*)m_charList.GetAt(startIndex); |
| + charinfo1 = m_CharList[startIndex]; |
| } |
| startIndex++; |
|
Tom Sepez
2016/01/23 00:07:56
nit: uh huh, postincrement then assign then never
|
| start = startIndex; |
| @@ -514,10 +496,10 @@ void CPDF_TextPage::CheckMarkedContentObject(int32_t& start, |
| while (FPDFTEXT_CHAR_PIECE == charinfo3.m_Flag && |
| charinfo3.m_Index == charinfo2.m_Index) { |
| endIndex++; |
| - if (endIndex >= m_charList.GetSize()) { |
| + if (endIndex >= pdfium::CollectionSize<int>(m_CharList)) { |
| break; |
| } |
| - charinfo3 = *(PAGECHAR_INFO*)m_charList.GetAt(endIndex); |
| + charinfo3 = m_CharList[endIndex]; |
| } |
| endIndex--; |
|
Tom Sepez
2016/01/23 00:07:56
nit: then postdecrement, then add 1 on the next li
|
| nCount = endIndex - start + 1; |
| @@ -531,40 +513,40 @@ CFX_WideString CPDF_TextPage::GetPageText(int start, int nCount) const { |
| start = 0; |
| if (nCount == -1) { |
| - nCount = m_charList.GetSize() - start; |
| + nCount = pdfium::CollectionSize<int>(m_CharList) - start; |
| return m_TextBuf.GetWideString().Mid(start, |
| m_TextBuf.GetWideString().GetLength()); |
| } |
| - if (nCount <= 0 || m_charList.GetSize() <= 0) { |
| + if (nCount <= 0 || m_CharList.empty()) { |
| return L""; |
| } |
| - if (nCount + start > m_charList.GetSize() - 1) { |
| - nCount = m_charList.GetSize() - start; |
| + if (nCount + start > pdfium::CollectionSize<int>(m_CharList) - 1) { |
| + nCount = pdfium::CollectionSize<int>(m_CharList) - start; |
| } |
| if (nCount <= 0) { |
| return L""; |
| } |
| CheckMarkedContentObject(start, nCount); |
| int startindex = 0; |
| - PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(start); |
| + PAGECHAR_INFO charinfo = m_CharList[start]; |
| int startOffset = 0; |
| while (charinfo.m_Index == -1) { |
| startOffset++; |
| - if (startOffset > nCount || start + startOffset >= m_charList.GetSize()) { |
| + if (startOffset > nCount || |
| + start + startOffset >= pdfium::CollectionSize<int>(m_CharList)) { |
| return L""; |
| } |
| - charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(start + startOffset); |
| + charinfo = m_CharList[start + startOffset]; |
| } |
| startindex = charinfo.m_Index; |
| - charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(start + nCount - 1); |
| + charinfo = m_CharList[start + nCount - 1]; |
| int nCountOffset = 0; |
| while (charinfo.m_Index == -1) { |
| nCountOffset++; |
| if (nCountOffset >= nCount) { |
| return L""; |
| } |
| - charinfo = |
| - *(PAGECHAR_INFO*)m_charList.GetAt(start + nCount - nCountOffset - 1); |
| + charinfo = m_CharList[start + nCount - nCountOffset - 1]; |
| } |
| nCount = start + nCount - nCountOffset - startindex; |
| if (nCount <= 0) { |
| @@ -576,8 +558,9 @@ int CPDF_TextPage::CountRects(int start, int nCount) { |
| if (m_ParseOptions.m_bGetCharCodeOnly || !m_bIsParsed || start < 0) |
| return -1; |
| - if (nCount == -1 || nCount + start > m_charList.GetSize()) { |
| - nCount = m_charList.GetSize() - start; |
| + if (nCount == -1 || |
| + nCount + start > pdfium::CollectionSize<int>(m_CharList)) { |
| + nCount = pdfium::CollectionSize<int>(m_CharList) - start; |
| } |
| m_SelRects.RemoveAll(); |
| GetRectArray(start, nCount, m_SelRects); |
| @@ -678,21 +661,21 @@ int CPDF_TextPage::CountBoundedSegments(FX_FLOAT left, |
| if (m_ParseOptions.m_bGetCharCodeOnly) |
| return -1; |
| - m_Segment.RemoveAll(); |
| + m_Segments.RemoveAll(); |
| if (!m_bIsParsed) |
| return -1; |
| CFX_FloatRect rect(left, bottom, right, top); |
| rect.Normalize(); |
| - int nCount = m_charList.GetSize(); |
| - int pos = 0; |
| + |
| FPDF_SEGMENT segment; |
| segment.m_Start = 0; |
| segment.m_nCount = 0; |
| + |
| + int pos = 0; |
| int segmentStatus = 0; |
| FX_BOOL IsContainPreChar = FALSE; |
| - while (pos < nCount) { |
| - PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(pos); |
| + for (const auto& charinfo : m_CharList) { |
| if (bContains && rect.Contains(charinfo.m_CharBox)) { |
| if (segmentStatus == 0 || segmentStatus == 2) { |
| segment.m_Start = pos; |
| @@ -726,7 +709,7 @@ int CPDF_TextPage::CountBoundedSegments(FX_FLOAT left, |
| } else { |
| if (segmentStatus == 1) { |
| segmentStatus = 2; |
| - m_Segment.Add(segment); |
| + m_Segments.Add(segment); |
| segment.m_Start = 0; |
| segment.m_nCount = 0; |
| } |
| @@ -734,7 +717,7 @@ int CPDF_TextPage::CountBoundedSegments(FX_FLOAT left, |
| } else { |
| if (segmentStatus == 1) { |
| segmentStatus = 2; |
| - m_Segment.Add(segment); |
| + m_Segments.Add(segment); |
| segment.m_Start = 0; |
| segment.m_nCount = 0; |
| } |
| @@ -744,21 +727,21 @@ int CPDF_TextPage::CountBoundedSegments(FX_FLOAT left, |
| } |
| if (segmentStatus == 1) { |
| segmentStatus = 2; |
| - m_Segment.Add(segment); |
| + m_Segments.Add(segment); |
| segment.m_Start = 0; |
| segment.m_nCount = 0; |
| } |
| - return m_Segment.GetSize(); |
| + return m_Segments.GetSize(); |
| } |
| void CPDF_TextPage::GetBoundedSegment(int index, int& start, int& count) const { |
| if (m_ParseOptions.m_bGetCharCodeOnly) { |
| return; |
| } |
| - if (index < 0 || index >= m_Segment.GetSize()) { |
| + if (index < 0 || index >= m_Segments.GetSize()) { |
| return; |
| } |
| - start = m_Segment.GetAt(index).m_Start; |
| - count = m_Segment.GetAt(index).m_nCount; |
| + start = m_Segments.GetAt(index).m_Start; |
| + count = m_Segments.GetAt(index).m_nCount; |
| } |
| int CPDF_TextPage::GetWordBreak(int index, int direction) const { |
| if (m_ParseOptions.m_bGetCharCodeOnly || !m_bIsParsed) |
| @@ -767,11 +750,10 @@ int CPDF_TextPage::GetWordBreak(int index, int direction) const { |
| if (direction != FPDFTEXT_LEFT && direction != FPDFTEXT_RIGHT) |
| return -1; |
| - if (index < 0 || index >= m_charList.GetSize()) |
| + if (index < 0 || index >= pdfium::CollectionSize<int>(m_CharList)) |
| return -1; |
| - PAGECHAR_INFO charinfo; |
| - charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(index); |
| + PAGECHAR_INFO charinfo = m_CharList[index]; |
|
Lei Zhang
2016/01/25 22:11:15
const ref
Tom Sepez
2016/01/25 23:04:47
Done.
|
| if (charinfo.m_Index == -1 || charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) { |
| return index; |
| } |
| @@ -781,17 +763,13 @@ int CPDF_TextPage::GetWordBreak(int index, int direction) const { |
| int breakPos = index; |
| if (direction == FPDFTEXT_LEFT) { |
| while (--breakPos > 0) { |
| - charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(breakPos); |
| - if (!IsLetter(charinfo.m_Unicode)) { |
| - return breakPos; |
| - } |
| + if (!IsLetter(m_CharList[breakPos].m_Unicode)) |
| + break; |
| } |
| } else if (direction == FPDFTEXT_RIGHT) { |
| - while (++breakPos < m_charList.GetSize()) { |
| - charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(breakPos); |
| - if (!IsLetter(charinfo.m_Unicode)) { |
| - return breakPos; |
| - } |
| + while (++breakPos < pdfium::CollectionSize<int>(m_CharList)) { |
| + if (!IsLetter(m_CharList[breakPos].m_Unicode)) |
| + break; |
| } |
| } |
| return breakPos; |
| @@ -981,18 +959,18 @@ void CPDF_TextPage::OnPiece(CFX_BidiChar* pBidi, CFX_WideString& str) { |
| if (ret == CFX_BidiChar::RIGHT) { |
| for (int i = start + count - 1; i >= start; i--) { |
| m_TextBuf.AppendChar(str.GetAt(i)); |
| - m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); |
| + m_CharList.push_back(m_TempCharList[i]); |
| } |
| } else { |
| int end = start + count; |
| for (int i = start; i < end; i++) { |
| m_TextBuf.AppendChar(str.GetAt(i)); |
| - m_charList.Add(*(PAGECHAR_INFO*)m_TempCharList.GetAt(i)); |
| + m_CharList.push_back(m_TempCharList[i]); |
| } |
| } |
| } |
| void CPDF_TextPage::AddCharInfoByLRDirection(CFX_WideString& str, int i) { |
| - PAGECHAR_INFO Info = *(PAGECHAR_INFO*)m_TempCharList.GetAt(i); |
| + PAGECHAR_INFO Info = m_TempCharList[i]; |
|
Lei Zhang
2016/01/25 22:11:15
Would you mind renaming |Info| and |Info2| while y
Tom Sepez
2016/01/25 23:04:47
As in starts with lower case? sure.
|
| FX_WCHAR wChar = str.GetAt(i); |
| if (!IsControlChar(Info)) { |
| Info.m_Index = m_TextBuf.GetLength(); |
| @@ -1008,7 +986,7 @@ void CPDF_TextPage::AddCharInfoByLRDirection(CFX_WideString& str, int i) { |
| Info2.m_Flag = FPDFTEXT_CHAR_PIECE; |
| m_TextBuf.AppendChar(Info2.m_Unicode); |
| if (!m_ParseOptions.m_bGetCharCodeOnly) { |
| - m_charList.Add(Info2); |
| + m_CharList.push_back(Info2); |
| } |
| } |
| FX_Free(pDst); |
| @@ -1020,11 +998,11 @@ void CPDF_TextPage::AddCharInfoByLRDirection(CFX_WideString& str, int i) { |
| Info.m_Index = -1; |
| } |
| if (!m_ParseOptions.m_bGetCharCodeOnly) { |
| - m_charList.Add(Info); |
| + m_CharList.push_back(Info); |
| } |
| } |
| void CPDF_TextPage::AddCharInfoByRLDirection(CFX_WideString& str, int i) { |
| - PAGECHAR_INFO Info = *(PAGECHAR_INFO*)m_TempCharList.GetAt(i); |
| + PAGECHAR_INFO Info = m_TempCharList[i]; |
|
Lei Zhang
2016/01/25 22:11:16
Ditto.
|
| if (!IsControlChar(Info)) { |
| Info.m_Index = m_TextBuf.GetLength(); |
| FX_WCHAR wChar = FX_GetMirrorChar(str.GetAt(i), TRUE, FALSE); |
| @@ -1039,7 +1017,7 @@ void CPDF_TextPage::AddCharInfoByRLDirection(CFX_WideString& str, int i) { |
| Info2.m_Flag = FPDFTEXT_CHAR_PIECE; |
| m_TextBuf.AppendChar(Info2.m_Unicode); |
| if (!m_ParseOptions.m_bGetCharCodeOnly) { |
| - m_charList.Add(Info2); |
| + m_CharList.push_back(Info2); |
| } |
| } |
| FX_Free(pDst); |
| @@ -1051,12 +1029,11 @@ void CPDF_TextPage::AddCharInfoByRLDirection(CFX_WideString& str, int i) { |
| Info.m_Index = -1; |
| } |
| if (!m_ParseOptions.m_bGetCharCodeOnly) { |
| - m_charList.Add(Info); |
| + m_CharList.push_back(Info); |
| } |
| } |
| void CPDF_TextPage::CloseTempLine() { |
| - int count1 = m_TempCharList.GetSize(); |
| - if (count1 <= 0) { |
| + if (m_TempCharList.empty()) { |
| return; |
| } |
| std::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar); |
| @@ -1070,9 +1047,8 @@ void CPDF_TextPage::CloseTempLine() { |
| if (str.GetAt(i) == 32) { |
| if (bPrevSpace) { |
| m_TempTextBuf.Delete(i, 1); |
| - m_TempCharList.Delete(i); |
| + m_TempCharList.erase(m_TempCharList.begin() + i); |
| str.Delete(i); |
| - count1--; |
| i--; |
| continue; |
| } |
| @@ -1173,7 +1149,7 @@ void CPDF_TextPage::CloseTempLine() { |
| bL2R = TRUE; |
| continue; |
| } |
| - int end = m_TempCharList.GetSize() - 1; |
| + int end = pdfium::CollectionSize<int>(m_TempCharList) - 1; |
| if (j < count) { |
| end = order.GetAt(j) - 1; |
| } |
| @@ -1190,7 +1166,7 @@ void CPDF_TextPage::CloseTempLine() { |
| } |
| } |
| order.RemoveAll(); |
| - m_TempCharList.RemoveAll(); |
| + m_TempCharList.clear(); |
| m_TempTextBuf.Delete(0, m_TempTextBuf.GetLength()); |
| } |
| void CPDF_TextPage::ProcessTextObject(CPDF_TextObject* pTextObj, |
| @@ -1410,29 +1386,23 @@ void CPDF_TextPage::ProcessMarkedContent(PDFTEXT_Obj Obj) { |
| charinfo.m_CharBox.bottom = charBox.bottom; |
| charinfo.m_Matrix.Copy(matrix); |
| m_TempTextBuf.AppendChar(wChar); |
| - m_TempCharList.Add(charinfo); |
| + m_TempCharList.push_back(charinfo); |
| } |
| } |
| -void CPDF_TextPage::FindPreviousTextObject(void) { |
| - if (m_TempCharList.GetSize() < 1 && m_charList.GetSize() < 1) { |
| +void CPDF_TextPage::FindPreviousTextObject() { |
| + if (m_TempCharList.empty() && m_CharList.empty()) |
| return; |
| - } |
| - PAGECHAR_INFO preChar; |
| - if (m_TempCharList.GetSize() >= 1) { |
| - preChar = |
| - *(PAGECHAR_INFO*)m_TempCharList.GetAt(m_TempCharList.GetSize() - 1); |
| - } else { |
| - preChar = *(PAGECHAR_INFO*)m_charList.GetAt(m_charList.GetSize() - 1); |
| - } |
| - if (preChar.m_pTextObj) { |
| + |
| + PAGECHAR_INFO preChar = |
| + m_TempCharList.empty() ? m_CharList.back() : m_TempCharList.back(); |
| + |
| + if (preChar.m_pTextObj) |
| m_pPreTextObj = preChar.m_pTextObj; |
| - } |
| } |
| void CPDF_TextPage::SwapTempTextBuf(int32_t iCharListStartAppend, |
| int32_t iBufStartAppend) { |
| - int32_t i, j; |
| - i = iCharListStartAppend; |
| - j = m_TempCharList.GetSize() - 1; |
| + int32_t i = iCharListStartAppend; |
| + int32_t j = pdfium::CollectionSize<int32_t>(m_TempCharList) - 1; |
| for (; i < j; i++, j--) { |
| std::swap(m_TempCharList[i], m_TempCharList[j]); |
| std::swap(m_TempCharList[i].m_Index, m_TempCharList[j].m_Index); |
| @@ -1519,7 +1489,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { |
| generateChar.m_Matrix.Copy(formMatrix); |
| } |
| m_TempTextBuf.AppendChar(TEXT_BLANK_CHAR); |
| - m_TempCharList.Add(generateChar); |
| + m_TempCharList.push_back(generateChar); |
| } |
| } else if (result == 2) { |
| CloseTempLine(); |
| @@ -1533,14 +1503,14 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { |
| if (!formMatrix.IsIdentity()) { |
| generateChar.m_Matrix.Copy(formMatrix); |
| } |
| - m_charList.Add(generateChar); |
| + m_CharList.push_back(generateChar); |
| } |
| if (GenerateCharInfo(TEXT_LINEFEED_CHAR, generateChar)) { |
| m_TextBuf.AppendChar(TEXT_LINEFEED_CHAR); |
| if (!formMatrix.IsIdentity()) { |
| generateChar.m_Matrix.Copy(formMatrix); |
| } |
| - m_charList.Add(generateChar); |
| + m_CharList.push_back(generateChar); |
| } |
| } |
| } |
| @@ -1563,10 +1533,9 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { |
| m_TempTextBuf.GetWideString().GetAt(m_TempTextBuf.GetLength() - |
| 1) == 0x20) { |
| m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); |
| - m_TempCharList.Delete(m_TempCharList.GetSize() - 1); |
| + m_TempCharList.pop_back(); |
| } |
| - PAGECHAR_INFO* cha = |
| - (PAGECHAR_INFO*)m_TempCharList.GetAt(m_TempCharList.GetSize() - 1); |
| + PAGECHAR_INFO* cha = &m_TempCharList.back(); |
|
Lei Zhang
2016/01/25 22:11:16
rename |cha| ?
Tom Sepez
2016/01/25 23:04:47
Done.
|
| m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); |
| cha->m_Unicode = 0x2; |
| cha->m_Flag = FPDFTEXT_CHAR_HYPHEN; |
| @@ -1592,7 +1561,8 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { |
| const FX_BOOL bIsBidiAndMirrorInverse = |
| bR2L && (matrix.a * matrix.d - matrix.b * matrix.c) < 0; |
| int32_t iBufStartAppend = m_TempTextBuf.GetLength(); |
| - int32_t iCharListStartAppend = m_TempCharList.GetSize(); |
| + int32_t iCharListStartAppend = |
| + pdfium::CollectionSize<int32_t>(m_TempCharList); |
| FX_FLOAT spacing = 0; |
| for (int i = 0; i < nItems; i++) { |
| @@ -1654,7 +1624,7 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { |
| charinfo.m_CharBox = |
| CFX_FloatRect(charinfo.m_OriginX, charinfo.m_OriginY, |
| charinfo.m_OriginX, charinfo.m_OriginY); |
| - m_TempCharList.Add(charinfo); |
| + m_TempCharList.push_back(charinfo); |
| } |
| if (item.m_CharCode == (FX_DWORD)-1) { |
| continue; |
| @@ -1706,18 +1676,19 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { |
| charinfo.m_Matrix.Copy(matrix); |
| if (wstrItem.IsEmpty()) { |
| charinfo.m_Unicode = 0; |
| - m_TempCharList.Add(charinfo); |
| + m_TempCharList.push_back(charinfo); |
| m_TempTextBuf.AppendChar(0xfffe); |
| continue; |
| } else { |
| int nTotal = wstrItem.GetLength(); |
| FX_BOOL bDel = FALSE; |
| - const int count = std::min(m_TempCharList.GetSize(), 7); |
| + const int count = |
| + std::min(pdfium::CollectionSize<int>(m_TempCharList), 7); |
| FX_FLOAT threshold = charinfo.m_Matrix.TransformXDistance( |
| (FX_FLOAT)TEXT_CHARRATIO_GAPDELTA * pTextObj->GetFontSize()); |
| - for (int n = m_TempCharList.GetSize(); |
| - n > m_TempCharList.GetSize() - count; n--) { |
| - PAGECHAR_INFO* charinfo1 = (PAGECHAR_INFO*)m_TempCharList.GetAt(n - 1); |
| + for (int n = pdfium::CollectionSize<int>(m_TempCharList); |
| + n > pdfium::CollectionSize<int>(m_TempCharList) - count; n--) { |
| + PAGECHAR_INFO* charinfo1 = &m_TempCharList[n - 1]; |
|
Lei Zhang
2016/01/25 22:11:15
const ref instead?
Tom Sepez
2016/01/25 23:04:47
Done.
|
| if (charinfo1->m_CharCode == charinfo.m_CharCode && |
| charinfo1->m_pTextObj->GetFont() == |
| charinfo.m_pTextObj->GetFont() && |
| @@ -1736,14 +1707,14 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { |
| } else { |
| m_TempTextBuf.AppendChar(0xfffe); |
| } |
| - m_TempCharList.Add(charinfo); |
| + m_TempCharList.push_back(charinfo); |
| } |
| } else if (i == 0) { |
| CFX_WideString str = m_TempTextBuf.GetWideString(); |
| if (!str.IsEmpty() && |
| str.GetAt(str.GetLength() - 1) == TEXT_BLANK_CHAR) { |
| m_TempTextBuf.Delete(m_TempTextBuf.GetLength() - 1, 1); |
| - m_TempCharList.Delete(m_TempCharList.GetSize() - 1); |
| + m_TempCharList.pop_back(); |
| } |
| } |
| } |
| @@ -1802,16 +1773,13 @@ FX_BOOL CPDF_TextPage::IsHyphen(FX_WCHAR curChar) { |
| return TRUE; |
| } |
| } |
| - int size = m_TempCharList.GetSize(); |
| PAGECHAR_INFO preChar; |
|
Lei Zhang
2016/01/25 22:11:16
cosnt PAGECHAR_INFO* ?
Tom Sepez
2016/01/25 23:04:47
Const ptr, also renamed since preChar is also a wc
|
| - if (size) { |
| - preChar = (PAGECHAR_INFO)m_TempCharList[size - 1]; |
| + if (!m_TempCharList.empty()) { |
| + preChar = m_TempCharList.back(); |
| + } else if (!m_CharList.empty()) { |
| + preChar = m_CharList.back(); |
| } else { |
| - size = m_charList.GetSize(); |
| - if (size == 0) { |
| - return FALSE; |
| - } |
| - preChar = (PAGECHAR_INFO)m_charList[size - 1]; |
| + return FALSE; |
| } |
| if (FPDFTEXT_CHAR_PIECE == preChar.m_Flag && |
| (0xAD == preChar.m_Unicode || 0x2D == preChar.m_Unicode)) { |
| @@ -1988,9 +1956,9 @@ FX_BOOL CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1, |
| if (rcPreObj.IsEmpty() && rcCurObj.IsEmpty() && |
| !m_ParseOptions.m_bGetCharCodeOnly) { |
| FX_FLOAT dbXdif = FXSYS_fabs(rcPreObj.left - rcCurObj.left); |
| - int nCount = m_charList.GetSize(); |
| + size_t nCount = m_CharList.size(); |
| if (nCount >= 2) { |
| - PAGECHAR_INFO perCharTemp = (PAGECHAR_INFO)m_charList[nCount - 2]; |
| + PAGECHAR_INFO perCharTemp = m_CharList[nCount - 2]; |
| FX_FLOAT dbSpace = perCharTemp.m_CharBox.Width(); |
| if (dbXdif > dbSpace) { |
| return FALSE; |
| @@ -2061,16 +2029,13 @@ FX_BOOL CPDF_TextPage::IsSameAsPreTextObject(CPDF_TextObject* pTextObj, |
| } |
| FX_BOOL CPDF_TextPage::GenerateCharInfo(FX_WCHAR unicode, PAGECHAR_INFO& info) { |
| - int size = m_TempCharList.GetSize(); |
| PAGECHAR_INFO preChar; |
|
Lei Zhang
2016/01/25 22:11:15
Ditto, const PAGECHAR_INFO*
|
| - if (size) { |
| - preChar = (PAGECHAR_INFO)m_TempCharList[size - 1]; |
| + if (!m_TempCharList.empty()) { |
| + preChar = m_TempCharList.back(); |
| + } else if (!m_CharList.empty()) { |
| + preChar = m_CharList.back(); |
| } else { |
| - size = m_charList.GetSize(); |
| - if (size == 0) { |
| - return FALSE; |
| - } |
| - preChar = (PAGECHAR_INFO)m_charList[size - 1]; |
| + return FALSE; |
| } |
| info.m_Index = m_TextBuf.GetLength(); |
| info.m_Unicode = unicode; |