summaryrefslogtreecommitdiff
path: root/xfa_test/pdf/pdfium/pdfium_range.cc
diff options
context:
space:
mode:
authorBo Xu <bo_xu@foxitsoftware.com>2014-10-28 23:03:33 -0700
committerBo Xu <bo_xu@foxitsoftware.com>2014-11-03 11:10:11 -0800
commitfdc00a7042d912aafaabddae4d9c84199921ef23 (patch)
tree32ab8ac91cc68d2cd15b9168782a71b3f3f5e7b9 /xfa_test/pdf/pdfium/pdfium_range.cc
parente9b38fa38de2c95d8260be31c57d9272c4d127ed (diff)
downloadpdfium-fdc00a7042d912aafaabddae4d9c84199921ef23.tar.xz
Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
Diffstat (limited to 'xfa_test/pdf/pdfium/pdfium_range.cc')
-rw-r--r--xfa_test/pdf/pdfium/pdfium_range.cc79
1 files changed, 79 insertions, 0 deletions
diff --git a/xfa_test/pdf/pdfium/pdfium_range.cc b/xfa_test/pdf/pdfium/pdfium_range.cc
new file mode 100644
index 0000000000..c77d5906dd
--- /dev/null
+++ b/xfa_test/pdf/pdfium/pdfium_range.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "pdf/pdfium/pdfium_range.h"
+
+#include "base/logging.h"
+#include "base/strings/string_util.h"
+
+namespace chrome_pdf {
+
+PDFiumRange::PDFiumRange(PDFiumPage* page, int char_index, int char_count)
+ : page_(page),
+ char_index_(char_index),
+ char_count_(char_count),
+ cached_screen_rects_zoom_(0) {
+}
+
+PDFiumRange::~PDFiumRange() {
+}
+
+void PDFiumRange::SetCharCount(int char_count) {
+ char_count_ = char_count;
+
+ cached_screen_rects_offset_ = pp::Point();
+ cached_screen_rects_zoom_ = 0;
+}
+
+std::vector<pp::Rect> PDFiumRange::GetScreenRects(const pp::Point& offset,
+ double zoom,
+ int rotation) {
+ if (offset == cached_screen_rects_offset_ &&
+ zoom == cached_screen_rects_zoom_) {
+ return cached_screen_rects_;
+ }
+
+ cached_screen_rects_.clear();
+ cached_screen_rects_offset_ = offset;
+ cached_screen_rects_zoom_ = zoom;
+
+ int char_index = char_index_;
+ int char_count = char_count_;
+ if (char_count < 0) {
+ char_count *= -1;
+ char_index -= char_count - 1;
+ }
+
+ int count = FPDFText_CountRects(page_->GetTextPage(), char_index, char_count);
+ for (int i = 0; i < count; ++i) {
+ double left, top, right, bottom;
+ FPDFText_GetRect(page_->GetTextPage(), i, &left, &top, &right, &bottom);
+ cached_screen_rects_.push_back(
+ page_->PageToScreen(offset, zoom, left, top, right, bottom, rotation));
+ }
+
+ return cached_screen_rects_;
+}
+
+base::string16 PDFiumRange::GetText() {
+ int index = char_index_;
+ int count = char_count_;
+ if (!count)
+ return base::string16();
+ if (count < 0) {
+ count *= -1;
+ index -= count - 1;
+ }
+
+ base::string16 rv;
+ unsigned short* data =
+ reinterpret_cast<unsigned short*>(WriteInto(&rv, count + 1));
+ if (data) {
+ int written = FPDFText_GetText(page_->GetTextPage(), index, count, data);
+ rv.reserve(written);
+ }
+ return rv;
+}
+
+} // namespace chrome_pdf