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 #ifndef PDF_PDFIUM_PDFIUM_PAGE_H_
6 #define PDF_PDFIUM_PDFIUM_PAGE_H_
11 #include "base/strings/string16.h"
12 #include "ppapi/cpp/rect.h"
13 #include "third_party/pdfium/public/fpdf_doc.h"
14 #include "third_party/pdfium/public/fpdf_formfill.h"
15 #include "third_party/pdfium/public/fpdf_text.h"
21 namespace chrome_pdf
{
25 // Wrapper around a page from the document.
28 PDFiumPage(PDFiumEngine
* engine
,
33 // Unloads the PDFium data for this page from memory.
35 // Gets the FPDF_PAGE for this page, loading and parsing it if necessary.
37 // Get the FPDF_PAGE for printing.
38 FPDF_PAGE
GetPrintPage();
39 // Close the printing page.
40 void ClosePrintPage();
42 // Returns FPDF_TEXTPAGE for the page, loading and parsing it if necessary.
43 FPDF_TEXTPAGE
GetTextPage();
45 // Returns a DictionaryValue version of the page.
46 base::Value
* GetAccessibleContentAsValue(int rotation
);
51 WEBLINK_AREA
, // Area is a hyperlink.
52 DOCLINK_AREA
, // Area is a link to a different part of the same document.
56 // We are using std::string here which have a copy contructor.
57 // That prevents us from using union here.
58 std::string url
; // Valid for WEBLINK_AREA only.
59 int page
; // Valid for DOCLINK_AREA only.
62 // Given a point in the document that's in this page, returns its character
63 // index if it's near a character, and also the type of text.
64 // Target is optional. It will be filled in for WEBLINK_AREA or
66 Area
GetCharIndex(const pp::Point
& point
, int rotation
, int* char_index
,
67 int* form_type
, LinkTarget
* target
);
69 // Gets the character at the given index.
70 base::char16
GetCharAtIndex(int index
);
72 // Gets the number of characters in the page.
75 // Converts from page coordinates to screen coordinates.
76 pp::Rect
PageToScreen(const pp::Point
& offset
,
84 int index() const { return index_
; }
85 pp::Rect
rect() const { return rect_
; }
86 void set_rect(const pp::Rect
& r
) { rect_
= r
; }
87 bool available() const { return available_
; }
88 void set_available(bool available
) { available_
= available
; }
89 void set_calculated_links(bool calculated_links
) {
90 calculated_links_
= calculated_links
;
94 // Returns a link index if the given character index is over a link, or -1
96 int GetLink(int char_index
, LinkTarget
* target
);
97 // Returns the link indices if the given rect intersects a link rect, or an
98 // empty vector otherwise.
99 std::vector
<int> GetLinks(pp::Rect text_area
,
100 std::vector
<LinkTarget
>* targets
);
101 // Calculate the locations of any links on the page.
102 void CalculateLinks();
103 // Returns link type and target associated with a link. Returns
104 // NONSELECTABLE_AREA if link detection failed.
105 Area
GetLinkTarget(FPDF_LINK link
, LinkTarget
* target
);
106 // Returns target associated with a destination.
107 Area
GetDestinationTarget(FPDF_DEST destination
, LinkTarget
* target
);
108 // Returns the text in the supplied box as a Value Node
109 base::Value
* GetTextBoxAsValue(double page_height
, double left
, double top
,
110 double right
, double bottom
, int rotation
);
111 // Helper functions for JSON generation
112 base::Value
* CreateTextNode(std::string text
);
113 base::Value
* CreateURLNode(std::string text
, std::string url
);
115 class ScopedLoadCounter
{
117 explicit ScopedLoadCounter(PDFiumPage
* page
);
118 ~ScopedLoadCounter();
121 PDFiumPage
* const page_
;
129 // Bounding rectangles of characters.
130 std::vector
<pp::Rect
> rects
;
133 PDFiumEngine
* engine_
;
135 FPDF_TEXTPAGE text_page_
;
139 bool calculated_links_
;
140 std::vector
<Link
> links_
;
144 } // namespace chrome_pdf
146 #endif // PDF_PDFIUM_PDFIUM_PAGE_H_