| 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 2232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2243 } | 2243 } |
| 2244 | 2244 |
| 2245 void PDFiumEngine::InvalidateAllPages() { | 2245 void PDFiumEngine::InvalidateAllPages() { |
| 2246 CancelPaints(); | 2246 CancelPaints(); |
| 2247 StopFind(); | 2247 StopFind(); |
| 2248 LoadPageInfo(true); | 2248 LoadPageInfo(true); |
| 2249 client_->Invalidate(pp::Rect(plugin_size_)); | 2249 client_->Invalidate(pp::Rect(plugin_size_)); |
| 2250 } | 2250 } |
| 2251 | 2251 |
| 2252 std::string PDFiumEngine::GetSelectedText() { | 2252 std::string PDFiumEngine::GetSelectedText() { |
| 2253 if (!HasPermission(PDFEngine::PERMISSION_COPY)) |
| 2254 return std::string(); |
| 2255 |
| 2253 base::string16 result; | 2256 base::string16 result; |
| 2254 base::string16 new_line_char = base::UTF8ToUTF16("\n"); | 2257 base::string16 new_line_char = base::UTF8ToUTF16("\n"); |
| 2255 for (size_t i = 0; i < selection_.size(); ++i) { | 2258 for (size_t i = 0; i < selection_.size(); ++i) { |
| 2256 if (i > 0 && | 2259 if (i > 0 && |
| 2257 selection_[i - 1].page_index() > selection_[i].page_index()) { | 2260 selection_[i - 1].page_index() > selection_[i].page_index()) { |
| 2258 result = selection_[i].GetText() + new_line_char + result; | 2261 result = selection_[i].GetText() + new_line_char + result; |
| 2259 } else { | 2262 } else { |
| 2260 if (i > 0) | 2263 if (i > 0) |
| 2261 result.append(new_line_char); | 2264 result.append(new_line_char); |
| 2262 result.append(selection_[i].GetText()); | 2265 result.append(selection_[i].GetText()); |
| (...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3337 *region = NULL; | 3340 *region = NULL; |
| 3338 return; | 3341 return; |
| 3339 } | 3342 } |
| 3340 | 3343 |
| 3341 buffer += location.y() * (*stride); | 3344 buffer += location.y() * (*stride); |
| 3342 buffer += (location.x() + page_offset_.x()) * 4; | 3345 buffer += (location.x() + page_offset_.x()) * 4; |
| 3343 *region = buffer; | 3346 *region = buffer; |
| 3344 } | 3347 } |
| 3345 | 3348 |
| 3346 void PDFiumEngine::OnSelectionChanged() { | 3349 void PDFiumEngine::OnSelectionChanged() { |
| 3347 if (HasPermission(PDFEngine::PERMISSION_COPY)) | 3350 pp::PDF::SetSelectedText(GetPluginInstance(), GetSelectedText().c_str()); |
| 3348 pp::PDF::SetSelectedText(GetPluginInstance(), GetSelectedText().c_str()); | |
| 3349 } | 3351 } |
| 3350 | 3352 |
| 3351 void PDFiumEngine::RotateInternal() { | 3353 void PDFiumEngine::RotateInternal() { |
| 3352 // Store the current find index so that we can resume finding at that | 3354 // Store the current find index so that we can resume finding at that |
| 3353 // particular index after we have recomputed the find results. | 3355 // particular index after we have recomputed the find results. |
| 3354 std::string current_find_text = current_find_text_; | 3356 std::string current_find_text = current_find_text_; |
| 3355 if (current_find_index_.valid()) | 3357 if (current_find_index_.valid()) |
| 3356 resume_find_index_.SetIndex(current_find_index_.GetIndex()); | 3358 resume_find_index_.SetIndex(current_find_index_.GetIndex()); |
| 3357 else | 3359 else |
| 3358 resume_find_index_.Invalidate(); | 3360 resume_find_index_.Invalidate(); |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3914 double* height) { | 3916 double* height) { |
| 3915 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); | 3917 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); |
| 3916 if (!doc) | 3918 if (!doc) |
| 3917 return false; | 3919 return false; |
| 3918 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; | 3920 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; |
| 3919 FPDF_CloseDocument(doc); | 3921 FPDF_CloseDocument(doc); |
| 3920 return success; | 3922 return success; |
| 3921 } | 3923 } |
| 3922 | 3924 |
| 3923 } // namespace chrome_pdf | 3925 } // namespace chrome_pdf |
| OLD | NEW |