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
)
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
,
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_
;
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_
;
63 return base::string16();
70 unsigned short* data
=
71 reinterpret_cast<unsigned short*>(WriteInto(&rv
, count
+ 1));
73 int written
= FPDFText_GetText(page_
->GetTextPage(), index
, count
, data
);
79 } // namespace chrome_pdf