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 2058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2069 return; | 2069 return; |
2070 | 2070 |
2071 unsigned short* data = | 2071 unsigned short* data = |
2072 reinterpret_cast<unsigned short*>(WriteInto(&page_text, text_length + 1)); | 2072 reinterpret_cast<unsigned short*>(WriteInto(&page_text, text_length + 1)); |
2073 // |written| includes the trailing terminator, so get rid of the trailing | 2073 // |written| includes the trailing terminator, so get rid of the trailing |
2074 // NUL character by calling resize(). | 2074 // NUL character by calling resize(). |
2075 int written = FPDFText_GetText(pages_[current_page]->GetTextPage(), | 2075 int written = FPDFText_GetText(pages_[current_page]->GetTextPage(), |
2076 character_to_start_searching_from, | 2076 character_to_start_searching_from, |
2077 text_length, | 2077 text_length, |
2078 data); | 2078 data); |
2079 if (written < 1) | 2079 if (written > 0) { |
2080 page_text.resize(0); | 2080 DCHECK_EQ(L'\0', page_text[written - 1]); |
2081 else | |
2082 page_text.resize(written - 1); | 2081 page_text.resize(written - 1); |
| 2082 } else { |
| 2083 page_text.clear(); |
| 2084 } |
2083 | 2085 |
2084 std::vector<PDFEngine::Client::SearchStringResult> results; | 2086 std::vector<PDFEngine::Client::SearchStringResult> results; |
2085 client_->SearchString( | 2087 client_->SearchString( |
2086 page_text.c_str(), term.c_str(), case_sensitive, &results); | 2088 page_text.c_str(), term.c_str(), case_sensitive, &results); |
2087 for (size_t i = 0; i < results.size(); ++i) { | 2089 for (size_t i = 0; i < results.size(); ++i) { |
2088 // Need to map the indexes from the page text, which may have generated | 2090 // Need to map the indexes from the page text, which may have generated |
2089 // characters like space etc, to character indices from the page. | 2091 // characters like space etc, to character indices from the page. |
2090 int temp_start = results[i].start_index + character_to_start_searching_from; | 2092 int temp_start = results[i].start_index + character_to_start_searching_from; |
2091 int start = FPDFText_GetCharIndexFromTextIndex( | 2093 int start = FPDFText_GetCharIndexFromTextIndex( |
2092 pages_[current_page]->GetTextPage(), temp_start); | 2094 pages_[current_page]->GetTextPage(), temp_start); |
(...skipping 1823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3916 double* height) { | 3918 double* height) { |
3917 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3919 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
3918 if (!doc) | 3920 if (!doc) |
3919 return false; | 3921 return false; |
3920 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3922 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
3921 FPDF_CloseDocument(doc); | 3923 FPDF_CloseDocument(doc); |
3922 return success; | 3924 return success; |
3923 } | 3925 } |
3924 | 3926 |
3925 } // namespace chrome_pdf | 3927 } // namespace chrome_pdf |
OLD | NEW |