Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / pdf / pdfium / pdfium_range.cc
blobb0474fc7d679351c70ce25cf6d068264d061b4ce
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"
9 #include "pdf/pdfium/pdfium_api_string_buffer_adapter.h"
11 namespace chrome_pdf {
13 PDFiumRange::PDFiumRange(PDFiumPage* page, int char_index, int char_count)
14 : page_(page),
15 char_index_(char_index),
16 char_count_(char_count),
17 cached_screen_rects_zoom_(0) {
20 PDFiumRange::~PDFiumRange() {
23 void PDFiumRange::SetCharCount(int char_count) {
24 char_count_ = char_count;
26 cached_screen_rects_offset_ = pp::Point();
27 cached_screen_rects_zoom_ = 0;
30 std::vector<pp::Rect> PDFiumRange::GetScreenRects(const pp::Point& offset,
31 double zoom,
32 int rotation) {
33 if (offset == cached_screen_rects_offset_ &&
34 zoom == cached_screen_rects_zoom_) {
35 return cached_screen_rects_;
38 cached_screen_rects_.clear();
39 cached_screen_rects_offset_ = offset;
40 cached_screen_rects_zoom_ = zoom;
42 int char_index = char_index_;
43 int char_count = char_count_;
44 if (char_count < 0) {
45 char_count *= -1;
46 char_index -= char_count - 1;
49 int count = FPDFText_CountRects(page_->GetTextPage(), char_index, char_count);
50 for (int i = 0; i < count; ++i) {
51 double left, top, right, bottom;
52 FPDFText_GetRect(page_->GetTextPage(), i, &left, &top, &right, &bottom);
53 cached_screen_rects_.push_back(
54 page_->PageToScreen(offset, zoom, left, top, right, bottom, rotation));
57 return cached_screen_rects_;
60 base::string16 PDFiumRange::GetText() {
61 int index = char_index_;
62 int count = char_count_;
63 base::string16 rv;
64 if (count < 0) {
65 count *= -1;
66 index -= count - 1;
69 if (count > 0) {
70 PDFiumAPIStringBufferAdapter<base::string16> api_string_adapter(&rv,
71 count,
72 false);
73 unsigned short* data =
74 reinterpret_cast<unsigned short*>(api_string_adapter.GetData());
75 int written = FPDFText_GetText(page_->GetTextPage(), index, count, data);
76 api_string_adapter.Close(written);
79 return rv;
82 } // namespace chrome_pdf