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 | 9 |
10 namespace chrome_pdf { | 10 namespace chrome_pdf { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 cached_screen_rects_.push_back( | 52 cached_screen_rects_.push_back( |
53 page_->PageToScreen(offset, zoom, left, top, right, bottom, rotation)); | 53 page_->PageToScreen(offset, zoom, left, top, right, bottom, rotation)); |
54 } | 54 } |
55 | 55 |
56 return cached_screen_rects_; | 56 return cached_screen_rects_; |
57 } | 57 } |
58 | 58 |
59 base::string16 PDFiumRange::GetText() { | 59 base::string16 PDFiumRange::GetText() { |
60 int index = char_index_; | 60 int index = char_index_; |
61 int count = char_count_; | 61 int count = char_count_; |
62 if (!count) | 62 base::string16 rv; |
63 return base::string16(); | |
64 if (count < 0) { | 63 if (count < 0) { |
65 count *= -1; | 64 count *= -1; |
66 index -= count - 1; | 65 index -= count - 1; |
67 } | 66 } |
68 | 67 |
69 base::string16 rv; | 68 if (count > 0) { |
70 unsigned short* data = | 69 unsigned short* data = |
71 reinterpret_cast<unsigned short*>(WriteInto(&rv, count + 1)); | 70 reinterpret_cast<unsigned short*>(WriteInto(&rv, count + 1)); |
72 if (data) { | 71 // |written| includes the trailing terminator, so get rid of the trailing |
72 // NUL character by calling resize(). | |
raymes
2015/01/06 05:43:24
Not sure if you want to put this comment above you
Lei Zhang
2015/01/06 22:53:03
Comment added. Some places call len = Foo(NULL_buf
| |
73 int written = FPDFText_GetText(page_->GetTextPage(), index, count, data); | 73 int written = FPDFText_GetText(page_->GetTextPage(), index, count, data); |
74 rv.reserve(written); | 74 if (written < 1) |
75 rv.resize(0); | |
76 else | |
77 rv.resize(written - 1); | |
75 } | 78 } |
79 | |
76 return rv; | 80 return rv; |
77 } | 81 } |
78 | 82 |
79 } // namespace chrome_pdf | 83 } // namespace chrome_pdf |
OLD | NEW |