Upload upstream chromium 76.0.3809.146
[platform/framework/web/chromium-efl.git] / pdf / pdf.h
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.
4
5 #ifndef PDF_PDF_H_
6 #define PDF_PDF_H_
7
8 #include <vector>
9
10 #include "base/containers/span.h"
11 #include "build/build_config.h"
12
13 #if defined(OS_WIN)
14 #include <windows.h>
15 #endif
16
17 #if defined(OS_WIN)
18 typedef void (*PDFEnsureTypefaceCharactersAccessible)(const LOGFONT* font,
19                                                       const wchar_t* text,
20                                                       size_t text_length);
21 #endif
22
23 namespace gfx {
24 class Rect;
25 class Size;
26 }
27
28 namespace chrome_pdf {
29
30 #if defined(OS_WIN)
31 // Printing modes - type to convert PDF to for printing
32 enum PrintingMode {
33   kEmf = 0,
34   kTextOnly = 1,
35   kPostScript2 = 2,
36   kPostScript3 = 3,
37 };
38
39 // |pdf_buffer| is the buffer that contains the entire PDF document to be
40 //     rendered.
41 // |page_number| is the 0-based index of the page to be rendered.
42 // |dc| is the device context to render into.
43 // |dpi_x| and |dpi_y| is the resolution.
44 // |bounds_origin_x|, |bounds_origin_y|, |bounds_width| and |bounds_height|
45 //     specify a bounds rectangle within the DC in which to render the PDF
46 //     page.
47 // |fit_to_bounds| specifies whether the output should be shrunk to fit the
48 //     supplied bounds if the page size is larger than the bounds in any
49 //     dimension. If this is false, parts of the PDF page that lie outside
50 //     the bounds will be clipped.
51 // |stretch_to_bounds| specifies whether the output should be stretched to fit
52 //     the supplied bounds if the page size is smaller than the bounds in any
53 //     dimension.
54 // If both |fit_to_bounds| and |stretch_to_bounds| are true, then
55 //     |fit_to_bounds| is honored first.
56 // |keep_aspect_ratio| If any scaling is to be done is true, this flag
57 //     specifies whether the original aspect ratio of the page should be
58 //     preserved while scaling.
59 // |center_in_bounds| specifies whether the final image (after any scaling is
60 //     done) should be centered within the given bounds.
61 // |autorotate| specifies whether the final image should be rotated to match
62 //     the output bound.
63 // |use_color| specifies color or grayscale.
64 // Returns false if the document or the page number are not valid.
65 bool RenderPDFPageToDC(base::span<const uint8_t> pdf_buffer,
66                        int page_number,
67                        HDC dc,
68                        int dpi_x,
69                        int dpi_y,
70                        int bounds_origin_x,
71                        int bounds_origin_y,
72                        int bounds_width,
73                        int bounds_height,
74                        bool fit_to_bounds,
75                        bool stretch_to_bounds,
76                        bool keep_aspect_ratio,
77                        bool center_in_bounds,
78                        bool autorotate,
79                        bool use_color);
80
81 void SetPDFEnsureTypefaceCharactersAccessible(
82     PDFEnsureTypefaceCharactersAccessible func);
83
84 void SetPDFUseGDIPrinting(bool enable);
85
86 void SetPDFUsePrintMode(int mode);
87 #endif  // defined(OS_WIN)
88
89 // |page_count| and |max_page_width| are optional and can be NULL.
90 // Returns false if the document is not valid.
91 bool GetPDFDocInfo(base::span<const uint8_t> pdf_buffer,
92                    int* page_count,
93                    double* max_page_width);
94
95 // Gets the dimensions of a specific page in a document.
96 // |pdf_buffer| is the buffer that contains the entire PDF document to be
97 //     rendered.
98 // |page_number| is the page number that the function will get the dimensions
99 //     of.
100 // |width| is the output for the width of the page in points.
101 // |height| is the output for the height of the page in points.
102 // Returns false if the document or the page number are not valid.
103 bool GetPDFPageSizeByIndex(base::span<const uint8_t> pdf_buffer,
104                            int page_number,
105                            double* width,
106                            double* height);
107
108 // Renders PDF page into 4-byte per pixel BGRA color bitmap.
109 // |pdf_buffer| is the buffer that contains the entire PDF document to be
110 //     rendered.
111 // |page_number| is the 0-based index of the page to be rendered.
112 // |bitmap_buffer| is the output buffer for bitmap.
113 // |bitmap_width| is the width of the output bitmap.
114 // |bitmap_height| is the height of the output bitmap.
115 // |dpi_x| and |dpi_y| is the resolution.
116 // |autorotate| specifies whether the final image should be rotated to match
117 //     the output bound.
118 // |use_color| specifies color or grayscale.
119 // Returns false if the document or the page number are not valid.
120 bool RenderPDFPageToBitmap(base::span<const uint8_t> pdf_buffer,
121                            int page_number,
122                            void* bitmap_buffer,
123                            int bitmap_width,
124                            int bitmap_height,
125                            int dpi_x,
126                            int dpi_y,
127                            bool autorotate,
128                            bool use_color);
129
130 // Convert multiple PDF pages into a N-up PDF.
131 // |input_buffers| is the vector of buffers with each buffer contains a PDF.
132 //     If any of the PDFs contains multiple pages, only the first page of the
133 //     document is used.
134 // |pages_per_sheet| is the number of pages to put on one sheet.
135 // |page_size| is the output page size, measured in PDF "user space" units.
136 // |printable_area| is the output page printable area, measured in PDF
137 //     "user space" units.  Should be smaller than |page_size|.
138 //
139 // |page_size| is the print media size.  The page size of the output N-up PDF is
140 // determined by the |pages_per_sheet|, the orientation of the PDF pages
141 // contained in the |input_buffers|, and the media page size |page_size|. For
142 // example, when |page_size| = 512x792, |pages_per_sheet| = 2, and the
143 // orientation of |input_buffers| = portrait, the output N-up PDF will be
144 // 792x512.
145 // See printing::NupParameters for more details on how the output page
146 // orientation is determined, to understand why |page_size| may be swapped in
147 // some cases.
148 std::vector<uint8_t> ConvertPdfPagesToNupPdf(
149     std::vector<base::span<const uint8_t>> input_buffers,
150     size_t pages_per_sheet,
151     const gfx::Size& page_size,
152     const gfx::Rect& printable_area);
153
154 // Convert a PDF document to a N-up PDF document.
155 // |input_buffer| is the buffer that contains the entire PDF document to be
156 //     converted to a N-up PDF document.
157 // |pages_per_sheet| is the number of pages to put on one sheet.
158 // |page_size| is the output page size, measured in PDF "user space" units.
159 // |printable_area| is the output page printable area, measured in PDF
160 //     "user space" units.  Should be smaller than |page_size|.
161 //
162 // Refer to the description of ConvertPdfPagesToNupPdf to understand how the
163 // output page size will be calculated.
164 // The algorithm used to determine the output page size is the same.
165 std::vector<uint8_t> ConvertPdfDocumentToNupPdf(
166     base::span<const uint8_t> input_buffer,
167     size_t pages_per_sheet,
168     const gfx::Size& page_size,
169     const gfx::Rect& printable_area);
170
171 }  // namespace chrome_pdf
172
173 #endif  // PDF_PDF_H_