Adding a step to the check-in process that ensures the correct account information...
[chromium-blink-merge.git] / pdf / pdfium / pdfium_range.cc
blobc77d5906dd28b7e831bd746246d02e37abc5caf0
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
3 // found in the LICENSE file.
5 #include "pdf/pdfium/pdfium_range.h"
7 #include "base/logging.h"
8 #include "base/strings/string_util.h"
10 namespace chrome_pdf {
12 PDFiumRange::PDFiumRange(PDFiumPage* page, int char_index, int char_count)
13 : page_(page),
14 char_index_(char_index),
15 char_count_(char_count),
16 cached_screen_rects_zoom_(0) {
19 PDFiumRange::~PDFiumRange() {
22 void PDFiumRange::SetCharCount(int char_count) {
23 char_count_ = char_count;
25 cached_screen_rects_offset_ = pp::Point();
26 cached_screen_rects_zoom_ = 0;
29 std::vector<pp::Rect> PDFiumRange::GetScreenRects(const pp::Point& offset,
30 double zoom,
31 int rotation) {
32 if (offset == cached_screen_rects_offset_ &&
33 zoom == cached_screen_rects_zoom_) {
34 return cached_screen_rects_;
37 cached_screen_rects_.clear();
38 cached_screen_rects_offset_ = offset;
39 cached_screen_rects_zoom_ = zoom;
41 int char_index = char_index_;
42 int char_count = char_count_;
43 if (char_count < 0) {
44 char_count *= -1;
45 char_index -= char_count - 1;
48 int count = FPDFText_CountRects(page_->GetTextPage(), char_index, char_count);
49 for (int i = 0; i < count; ++i) {
50 double left, top, right, bottom;
51 FPDFText_GetRect(page_->GetTextPage(), i, &left, &top, &right, &bottom);
52 cached_screen_rects_.push_back(
53 page_->PageToScreen(offset, zoom, left, top, right, bottom, rotation));
56 return cached_screen_rects_;
59 base::string16 PDFiumRange::GetText() {
60 int index = char_index_;
61 int count = char_count_;
62 if (!count)
63 return base::string16();
64 if (count < 0) {
65 count *= -1;
66 index -= count - 1;
69 base::string16 rv;
70 unsigned short* data =
71 reinterpret_cast<unsigned short*>(WriteInto(&rv, count + 1));
72 if (data) {
73 int written = FPDFText_GetText(page_->GetTextPage(), index, count, data);
74 rv.reserve(written);
76 return rv;
79 } // namespace chrome_pdf