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 "core/src/fpdftext/text_int.h" | 7 #include "core/src/fpdftext/text_int.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cctype> | 10 #include <cctype> |
(...skipping 1981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 findwhatStr.MakeLower(); | 1992 findwhatStr.MakeLower(); |
1993 m_strText.MakeLower(); | 1993 m_strText.MakeLower(); |
1994 } | 1994 } |
1995 m_bMatchWholeWord = flags & FPDFTEXT_MATCHWHOLEWORD; | 1995 m_bMatchWholeWord = flags & FPDFTEXT_MATCHWHOLEWORD; |
1996 m_findNextStart = startPos; | 1996 m_findNextStart = startPos; |
1997 if (startPos == -1) { | 1997 if (startPos == -1) { |
1998 m_findPreStart = m_strText.GetLength() - 1; | 1998 m_findPreStart = m_strText.GetLength() - 1; |
1999 } else { | 1999 } else { |
2000 m_findPreStart = startPos; | 2000 m_findPreStart = startPos; |
2001 } | 2001 } |
2002 m_csFindWhatArray.RemoveAll(); | 2002 m_csFindWhatArray.clear(); |
2003 int i = 0; | 2003 int i = 0; |
2004 while (i < len) { | 2004 while (i < len) { |
2005 if (findwhatStr.GetAt(i) != ' ') { | 2005 if (findwhatStr.GetAt(i) != ' ') { |
2006 break; | 2006 break; |
2007 } | 2007 } |
2008 i++; | 2008 i++; |
2009 } | 2009 } |
2010 if (i < len) { | 2010 if (i < len) { |
2011 ExtractFindWhat(findwhatStr); | 2011 ExtractFindWhat(findwhatStr); |
2012 } else { | 2012 } else { |
2013 m_csFindWhatArray.Add(findwhatStr); | 2013 m_csFindWhatArray.push_back(findwhatStr); |
2014 } | 2014 } |
2015 if (m_csFindWhatArray.GetSize() <= 0) { | 2015 if (m_csFindWhatArray.empty()) { |
2016 return FALSE; | 2016 return FALSE; |
2017 } | 2017 } |
2018 m_IsFind = TRUE; | 2018 m_IsFind = TRUE; |
2019 m_resStart = 0; | 2019 m_resStart = 0; |
2020 m_resEnd = -1; | 2020 m_resEnd = -1; |
2021 return TRUE; | 2021 return TRUE; |
2022 } | 2022 } |
2023 | 2023 |
2024 FX_BOOL CPDF_TextPageFind::FindNext() { | 2024 FX_BOOL CPDF_TextPageFind::FindNext() { |
2025 if (!m_pTextPage) { | 2025 if (!m_pTextPage) { |
2026 return FALSE; | 2026 return FALSE; |
2027 } | 2027 } |
2028 m_resArray.RemoveAll(); | 2028 m_resArray.RemoveAll(); |
2029 if (m_findNextStart == -1) { | 2029 if (m_findNextStart == -1) { |
2030 return FALSE; | 2030 return FALSE; |
2031 } | 2031 } |
2032 if (m_strText.IsEmpty()) { | 2032 if (m_strText.IsEmpty()) { |
2033 m_IsFind = FALSE; | 2033 m_IsFind = FALSE; |
2034 return m_IsFind; | 2034 return m_IsFind; |
2035 } | 2035 } |
2036 int strLen = m_strText.GetLength(); | 2036 int strLen = m_strText.GetLength(); |
2037 if (m_findNextStart > strLen - 1) { | 2037 if (m_findNextStart > strLen - 1) { |
2038 m_IsFind = FALSE; | 2038 m_IsFind = FALSE; |
2039 return m_IsFind; | 2039 return m_IsFind; |
2040 } | 2040 } |
2041 int nCount = m_csFindWhatArray.GetSize(); | 2041 int nCount = pdfium::CollectionSize<int>(m_csFindWhatArray); |
2042 int nResultPos = 0; | 2042 int nResultPos = 0; |
2043 int nStartPos = 0; | 2043 int nStartPos = 0; |
2044 nStartPos = m_findNextStart; | 2044 nStartPos = m_findNextStart; |
2045 FX_BOOL bSpaceStart = FALSE; | 2045 FX_BOOL bSpaceStart = FALSE; |
2046 for (int iWord = 0; iWord < nCount; iWord++) { | 2046 for (int iWord = 0; iWord < nCount; iWord++) { |
2047 CFX_WideString csWord = m_csFindWhatArray[iWord]; | 2047 CFX_WideString csWord = m_csFindWhatArray[iWord]; |
2048 if (csWord.IsEmpty()) { | 2048 if (csWord.IsEmpty()) { |
2049 if (iWord == nCount - 1) { | 2049 if (iWord == nCount - 1) { |
2050 FX_WCHAR strInsert = m_strText.GetAt(nStartPos); | 2050 FX_WCHAR strInsert = m_strText.GetAt(nStartPos); |
2051 if (strInsert == TEXT_LINEFEED_CHAR || strInsert == TEXT_BLANK_CHAR || | 2051 if (strInsert == TEXT_LINEFEED_CHAR || strInsert == TEXT_BLANK_CHAR || |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2106 nStartPos = endIndex + 1; | 2106 nStartPos = endIndex + 1; |
2107 if (!bMatch) { | 2107 if (!bMatch) { |
2108 iWord = -1; | 2108 iWord = -1; |
2109 if (bSpaceStart) { | 2109 if (bSpaceStart) { |
2110 nStartPos = m_resStart + m_csFindWhatArray[1].GetLength(); | 2110 nStartPos = m_resStart + m_csFindWhatArray[1].GetLength(); |
2111 } else { | 2111 } else { |
2112 nStartPos = m_resStart + m_csFindWhatArray[0].GetLength(); | 2112 nStartPos = m_resStart + m_csFindWhatArray[0].GetLength(); |
2113 } | 2113 } |
2114 } | 2114 } |
2115 } | 2115 } |
2116 m_resEnd = nResultPos + | 2116 m_resEnd = nResultPos + m_csFindWhatArray.back().GetLength() - 1; |
2117 m_csFindWhatArray[m_csFindWhatArray.GetSize() - 1].GetLength() - 1; | |
2118 m_IsFind = TRUE; | 2117 m_IsFind = TRUE; |
2119 int resStart = GetCharIndex(m_resStart); | 2118 int resStart = GetCharIndex(m_resStart); |
2120 int resEnd = GetCharIndex(m_resEnd); | 2119 int resEnd = GetCharIndex(m_resEnd); |
2121 m_pTextPage->GetRectArray(resStart, resEnd - resStart + 1, m_resArray); | 2120 m_pTextPage->GetRectArray(resStart, resEnd - resStart + 1, m_resArray); |
2122 if (m_flags & FPDFTEXT_CONSECUTIVE) { | 2121 if (m_flags & FPDFTEXT_CONSECUTIVE) { |
2123 m_findNextStart = m_resStart + 1; | 2122 m_findNextStart = m_resStart + 1; |
2124 m_findPreStart = m_resEnd - 1; | 2123 m_findPreStart = m_resEnd - 1; |
2125 } else { | 2124 } else { |
2126 m_findNextStart = m_resEnd + 1; | 2125 m_findNextStart = m_resEnd + 1; |
2127 m_findPreStart = m_resStart - 1; | 2126 m_findPreStart = m_resStart - 1; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2179 if (findwhat.IsEmpty()) { | 2178 if (findwhat.IsEmpty()) { |
2180 return; | 2179 return; |
2181 } | 2180 } |
2182 int index = 0; | 2181 int index = 0; |
2183 while (1) { | 2182 while (1) { |
2184 CFX_WideString csWord = TEXT_EMPTY; | 2183 CFX_WideString csWord = TEXT_EMPTY; |
2185 int ret = | 2184 int ret = |
2186 ExtractSubString(csWord, findwhat.c_str(), index, TEXT_BLANK_CHAR); | 2185 ExtractSubString(csWord, findwhat.c_str(), index, TEXT_BLANK_CHAR); |
2187 if (csWord.IsEmpty()) { | 2186 if (csWord.IsEmpty()) { |
2188 if (ret) { | 2187 if (ret) { |
2189 m_csFindWhatArray.Add(CFX_WideString(L"")); | 2188 m_csFindWhatArray.push_back(L""); |
2190 index++; | 2189 index++; |
2191 continue; | 2190 continue; |
2192 } else { | 2191 } else { |
2193 break; | 2192 break; |
2194 } | 2193 } |
2195 } | 2194 } |
2196 int pos = 0; | 2195 int pos = 0; |
2197 while (pos < csWord.GetLength()) { | 2196 while (pos < csWord.GetLength()) { |
2198 CFX_WideString curStr = csWord.Mid(pos, 1); | 2197 CFX_WideString curStr = csWord.Mid(pos, 1); |
2199 FX_WCHAR curChar = csWord.GetAt(pos); | 2198 FX_WCHAR curChar = csWord.GetAt(pos); |
2200 if (_IsIgnoreSpaceCharacter(curChar)) { | 2199 if (_IsIgnoreSpaceCharacter(curChar)) { |
2201 if (pos > 0 && curChar == 0x2019) { | 2200 if (pos > 0 && curChar == 0x2019) { |
2202 pos++; | 2201 pos++; |
2203 continue; | 2202 continue; |
2204 } | 2203 } |
2205 if (pos > 0) { | 2204 if (pos > 0) { |
2206 CFX_WideString preStr = csWord.Mid(0, pos); | 2205 m_csFindWhatArray.push_back(csWord.Mid(0, pos)); |
2207 m_csFindWhatArray.Add(preStr); | |
2208 } | 2206 } |
2209 m_csFindWhatArray.Add(curStr); | 2207 m_csFindWhatArray.push_back(curStr); |
2210 if (pos == csWord.GetLength() - 1) { | 2208 if (pos == csWord.GetLength() - 1) { |
2211 csWord.Empty(); | 2209 csWord.Empty(); |
2212 break; | 2210 break; |
2213 } | 2211 } |
2214 csWord = csWord.Right(csWord.GetLength() - pos - 1); | 2212 csWord = csWord.Right(csWord.GetLength() - pos - 1); |
2215 pos = 0; | 2213 pos = 0; |
2216 continue; | 2214 continue; |
2217 } | 2215 } |
2218 pos++; | 2216 pos++; |
2219 } | 2217 } |
2220 if (!csWord.IsEmpty()) { | 2218 if (!csWord.IsEmpty()) { |
2221 m_csFindWhatArray.Add(csWord); | 2219 m_csFindWhatArray.push_back(csWord); |
2222 } | 2220 } |
2223 index++; | 2221 index++; |
2224 } | 2222 } |
2225 } | 2223 } |
2226 | 2224 |
2227 FX_BOOL CPDF_TextPageFind::IsMatchWholeWord(const CFX_WideString& csPageText, | 2225 FX_BOOL CPDF_TextPageFind::IsMatchWholeWord(const CFX_WideString& csPageText, |
2228 int startPos, | 2226 int startPos, |
2229 int endPos) { | 2227 int endPos) { |
2230 FX_WCHAR char_left = 0; | 2228 FX_WCHAR char_left = 0; |
2231 FX_WCHAR char_right = 0; | 2229 FX_WCHAR char_right = 0; |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2535 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { | 2533 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { |
2536 return; | 2534 return; |
2537 } | 2535 } |
2538 CPDF_LinkExt* link = NULL; | 2536 CPDF_LinkExt* link = NULL; |
2539 link = m_LinkList.GetAt(index); | 2537 link = m_LinkList.GetAt(index); |
2540 if (!link) { | 2538 if (!link) { |
2541 return; | 2539 return; |
2542 } | 2540 } |
2543 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); | 2541 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); |
2544 } | 2542 } |
OLD | NEW |