| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_range.h" | 5 #include "pdf/pdfium/pdfium_range.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "pdf/pdfium/pdfium_api_string_buffer_adapter.h" |
| 9 | 10 |
| 10 namespace chrome_pdf { | 11 namespace chrome_pdf { |
| 11 | 12 |
| 12 PDFiumRange::PDFiumRange(PDFiumPage* page, int char_index, int char_count) | 13 PDFiumRange::PDFiumRange(PDFiumPage* page, int char_index, int char_count) |
| 13 : page_(page), | 14 : page_(page), |
| 14 char_index_(char_index), | 15 char_index_(char_index), |
| 15 char_count_(char_count), | 16 char_count_(char_count), |
| 16 cached_screen_rects_zoom_(0) { | 17 cached_screen_rects_zoom_(0) { |
| 17 } | 18 } |
| 18 | 19 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 base::string16 PDFiumRange::GetText() { | 60 base::string16 PDFiumRange::GetText() { |
| 60 int index = char_index_; | 61 int index = char_index_; |
| 61 int count = char_count_; | 62 int count = char_count_; |
| 62 base::string16 rv; | 63 base::string16 rv; |
| 63 if (count < 0) { | 64 if (count < 0) { |
| 64 count *= -1; | 65 count *= -1; |
| 65 index -= count - 1; | 66 index -= count - 1; |
| 66 } | 67 } |
| 67 | 68 |
| 68 if (count > 0) { | 69 if (count > 0) { |
| 70 PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter(&rv, |
| 71 count, |
| 72 false); |
| 69 unsigned short* data = | 73 unsigned short* data = |
| 70 reinterpret_cast<unsigned short*>(WriteInto(&rv, count + 1)); | 74 reinterpret_cast<unsigned short*>(api_string_adapter.GetData()); |
| 71 // |written| includes the trailing terminator, so get rid of the trailing | |
| 72 // NUL character by calling resize(). | |
| 73 int written = FPDFText_GetText(page_->GetTextPage(), index, count, data); | 75 int written = FPDFText_GetText(page_->GetTextPage(), index, count, data); |
| 74 if (written < 1) | 76 api_string_adapter.Close(written); |
| 75 rv.resize(0); | |
| 76 else | |
| 77 rv.resize(written - 1); | |
| 78 } | 77 } |
| 79 | 78 |
| 80 return rv; | 79 return rv; |
| 81 } | 80 } |
| 82 | 81 |
| 83 } // namespace chrome_pdf | 82 } // namespace chrome_pdf |
| OLD | NEW |