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

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: Fix accessibility code that can no longer occur 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 | « no previous file | pdf/pdfium/pdfium_page.cc » ('j') | pdf/pdfium/pdfium_page.cc » ('J')
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"
(...skipping 2058 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW
« no previous file with comments | « no previous file | pdf/pdfium/pdfium_page.cc » ('j') | pdf/pdfium/pdfium_page.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698