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 #include "pdf/pdfium/pdfium_api_string_buffer_adapter.h" |
10 | 10 |
11 namespace chrome_pdf { | 11 namespace chrome_pdf { |
12 | 12 |
13 PDFiumRange::PDFiumRange(PDFiumPage* page, int char_index, int char_count) | 13 PDFiumRange::PDFiumRange(PDFiumPage* page, int char_index, int char_count) |
14 : page_(page), | 14 : page_(page), |
15 char_index_(char_index), | 15 char_index_(char_index), |
16 char_count_(char_count), | 16 char_count_(char_count), |
17 cached_screen_rects_zoom_(0) { | 17 cached_screen_rects_zoom_(0) {} |
18 } | |
19 | 18 |
20 PDFiumRange::PDFiumRange(const PDFiumRange& that) = default; | 19 PDFiumRange::PDFiumRange(const PDFiumRange& that) = default; |
21 | 20 |
22 PDFiumRange::~PDFiumRange() = default; | 21 PDFiumRange::~PDFiumRange() = default; |
23 | 22 |
24 void PDFiumRange::SetCharCount(int char_count) { | 23 void PDFiumRange::SetCharCount(int char_count) { |
25 char_count_ = char_count; | 24 char_count_ = char_count; |
26 | 25 |
27 cached_screen_rects_offset_ = pp::Point(); | 26 cached_screen_rects_offset_ = pp::Point(); |
28 cached_screen_rects_zoom_ = 0; | 27 cached_screen_rects_zoom_ = 0; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 base::string16 PDFiumRange::GetText() const { | 60 base::string16 PDFiumRange::GetText() const { |
62 int index = char_index_; | 61 int index = char_index_; |
63 int count = char_count_; | 62 int count = char_count_; |
64 base::string16 rv; | 63 base::string16 rv; |
65 if (count < 0) { | 64 if (count < 0) { |
66 count *= -1; | 65 count *= -1; |
67 index -= count - 1; | 66 index -= count - 1; |
68 } | 67 } |
69 | 68 |
70 if (count > 0) { | 69 if (count > 0) { |
71 PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter(&rv, | 70 PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter(&rv, count, |
72 count, | |
73 false); | 71 false); |
74 unsigned short* data = | 72 unsigned short* data = |
75 reinterpret_cast<unsigned short*>(api_string_adapter.GetData()); | 73 reinterpret_cast<unsigned short*>(api_string_adapter.GetData()); |
76 int written = FPDFText_GetText(page_->GetTextPage(), index, count, data); | 74 int written = FPDFText_GetText(page_->GetTextPage(), index, count, data); |
77 api_string_adapter.Close(written); | 75 api_string_adapter.Close(written); |
78 } | 76 } |
79 | 77 |
80 return rv; | 78 return rv; |
81 } | 79 } |
82 | 80 |
83 } // namespace chrome_pdf | 81 } // namespace chrome_pdf |
OLD | NEW |