| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 #include "pdf/pdfium/pdfium_engine.h" | 5 #include "pdf/pdfium/pdfium_engine.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 2032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2043 int text_length = pages_[current_page]->GetCharCount(); | 2043 int text_length = pages_[current_page]->GetCharCount(); |
| 2044 if (character_to_start_searching_from) { | 2044 if (character_to_start_searching_from) { |
| 2045 text_length -= character_to_start_searching_from; | 2045 text_length -= character_to_start_searching_from; |
| 2046 } else if (!first_search && | 2046 } else if (!first_search && |
| 2047 last_character_index_to_search_ != -1 && | 2047 last_character_index_to_search_ != -1 && |
| 2048 current_page == last_page_to_search_) { | 2048 current_page == last_page_to_search_) { |
| 2049 text_length = last_character_index_to_search_; | 2049 text_length = last_character_index_to_search_; |
| 2050 } | 2050 } |
| 2051 if (text_length <= 0) | 2051 if (text_length <= 0) |
| 2052 return; | 2052 return; |
| 2053 |
| 2053 unsigned short* data = | 2054 unsigned short* data = |
| 2054 reinterpret_cast<unsigned short*>(WriteInto(&page_text, text_length + 1)); | 2055 reinterpret_cast<unsigned short*>(WriteInto(&page_text, text_length + 1)); |
| 2055 FPDFText_GetText(pages_[current_page]->GetTextPage(), | 2056 int written = FPDFText_GetText(pages_[current_page]->GetTextPage(), |
| 2056 character_to_start_searching_from, | 2057 character_to_start_searching_from, |
| 2057 text_length, | 2058 text_length, |
| 2058 data); | 2059 data); |
| 2060 if (written < 1) |
| 2061 page_text.resize(0); |
| 2062 else |
| 2063 page_text.resize(written - 1); |
| 2064 |
| 2059 std::vector<PDFEngine::Client::SearchStringResult> results; | 2065 std::vector<PDFEngine::Client::SearchStringResult> results; |
| 2060 client_->SearchString( | 2066 client_->SearchString( |
| 2061 page_text.c_str(), term.c_str(), case_sensitive, &results); | 2067 page_text.c_str(), term.c_str(), case_sensitive, &results); |
| 2062 for (size_t i = 0; i < results.size(); ++i) { | 2068 for (size_t i = 0; i < results.size(); ++i) { |
| 2063 // Need to map the indexes from the page text, which may have generated | 2069 // Need to map the indexes from the page text, which may have generated |
| 2064 // characters like space etc, to character indices from the page. | 2070 // characters like space etc, to character indices from the page. |
| 2065 int temp_start = results[i].start_index + character_to_start_searching_from; | 2071 int temp_start = results[i].start_index + character_to_start_searching_from; |
| 2066 int start = FPDFText_GetCharIndexFromTextIndex( | 2072 int start = FPDFText_GetCharIndexFromTextIndex( |
| 2067 pages_[current_page]->GetTextPage(), temp_start); | 2073 pages_[current_page]->GetTextPage(), temp_start); |
| 2068 int end = FPDFText_GetCharIndexFromTextIndex( | 2074 int end = FPDFText_GetCharIndexFromTextIndex( |
| (...skipping 1812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3881 double* height) { | 3887 double* height) { |
| 3882 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3888 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
| 3883 if (!doc) | 3889 if (!doc) |
| 3884 return false; | 3890 return false; |
| 3885 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3891 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 3886 FPDF_CloseDocument(doc); | 3892 FPDF_CloseDocument(doc); |
| 3887 return success; | 3893 return success; |
| 3888 } | 3894 } |
| 3889 | 3895 |
| 3890 } // namespace chrome_pdf | 3896 } // namespace chrome_pdf |
| OLD | NEW |