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

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 848073003: PDF: Yet another stab at getting WriteInto() buffer sizes correct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years, 11 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
« no previous file with comments | « pdf/pdfium/pdfium_api_string_buffer_adapter.cc ('k') | pdf/pdfium/pdfium_page.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "pdf/draw_utils.h" 18 #include "pdf/draw_utils.h"
19 #include "pdf/pdfium/pdfium_api_string_buffer_adapter.h"
19 #include "pdf/pdfium/pdfium_mem_buffer_file_read.h" 20 #include "pdf/pdfium/pdfium_mem_buffer_file_read.h"
20 #include "pdf/pdfium/pdfium_mem_buffer_file_write.h" 21 #include "pdf/pdfium/pdfium_mem_buffer_file_write.h"
21 #include "ppapi/c/pp_errors.h" 22 #include "ppapi/c/pp_errors.h"
22 #include "ppapi/c/pp_input_event.h" 23 #include "ppapi/c/pp_input_event.h"
23 #include "ppapi/c/ppb_core.h" 24 #include "ppapi/c/ppb_core.h"
24 #include "ppapi/c/private/ppb_pdf.h" 25 #include "ppapi/c/private/ppb_pdf.h"
25 #include "ppapi/cpp/dev/memory_dev.h" 26 #include "ppapi/cpp/dev/memory_dev.h"
26 #include "ppapi/cpp/input_event.h" 27 #include "ppapi/cpp/input_event.h"
27 #include "ppapi/cpp/instance.h" 28 #include "ppapi/cpp/instance.h"
28 #include "ppapi/cpp/module.h" 29 #include "ppapi/cpp/module.h"
(...skipping 2032 matching lines...) Expand 10 before | Expand all | Expand 10 after
2061 if (character_to_start_searching_from) { 2062 if (character_to_start_searching_from) {
2062 text_length -= character_to_start_searching_from; 2063 text_length -= character_to_start_searching_from;
2063 } else if (!first_search && 2064 } else if (!first_search &&
2064 last_character_index_to_search_ != -1 && 2065 last_character_index_to_search_ != -1 &&
2065 current_page == last_page_to_search_) { 2066 current_page == last_page_to_search_) {
2066 text_length = last_character_index_to_search_; 2067 text_length = last_character_index_to_search_;
2067 } 2068 }
2068 if (text_length <= 0) 2069 if (text_length <= 0)
2069 return; 2070 return;
2070 2071
2072 PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter(&page_text,
2073 text_length,
2074 false);
2071 unsigned short* data = 2075 unsigned short* data =
2072 reinterpret_cast<unsigned short*>(WriteInto(&page_text, text_length + 1)); 2076 reinterpret_cast<unsigned short*>(api_string_adapter.GetData());
2073 // |written| includes the trailing terminator, so get rid of the trailing
2074 // NUL character by calling resize().
2075 int written = FPDFText_GetText(pages_[current_page]->GetTextPage(), 2077 int written = FPDFText_GetText(pages_[current_page]->GetTextPage(),
2076 character_to_start_searching_from, 2078 character_to_start_searching_from,
2077 text_length, 2079 text_length,
2078 data); 2080 data);
2079 if (written < 1) 2081 api_string_adapter.Close(written);
2080 page_text.resize(0);
2081 else
2082 page_text.resize(written - 1);
2083 2082
2084 std::vector<PDFEngine::Client::SearchStringResult> results; 2083 std::vector<PDFEngine::Client::SearchStringResult> results;
2085 client_->SearchString( 2084 client_->SearchString(
2086 page_text.c_str(), term.c_str(), case_sensitive, &results); 2085 page_text.c_str(), term.c_str(), case_sensitive, &results);
2087 for (size_t i = 0; i < results.size(); ++i) { 2086 for (size_t i = 0; i < results.size(); ++i) {
2088 // Need to map the indexes from the page text, which may have generated 2087 // Need to map the indexes from the page text, which may have generated
2089 // characters like space etc, to character indices from the page. 2088 // characters like space etc, to character indices from the page.
2090 int temp_start = results[i].start_index + character_to_start_searching_from; 2089 int temp_start = results[i].start_index + character_to_start_searching_from;
2091 int start = FPDFText_GetCharIndexFromTextIndex( 2090 int start = FPDFText_GetCharIndexFromTextIndex(
2092 pages_[current_page]->GetTextPage(), temp_start); 2091 pages_[current_page]->GetTextPage(), temp_start);
(...skipping 1823 matching lines...) Expand 10 before | Expand all | Expand 10 after
3916 double* height) { 3915 double* height) {
3917 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 3916 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
3918 if (!doc) 3917 if (!doc)
3919 return false; 3918 return false;
3920 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3919 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3921 FPDF_CloseDocument(doc); 3920 FPDF_CloseDocument(doc);
3922 return success; 3921 return success;
3923 } 3922 }
3924 3923
3925 } // namespace chrome_pdf 3924 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « pdf/pdfium/pdfium_api_string_buffer_adapter.cc ('k') | pdf/pdfium/pdfium_page.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698