OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "pdf/pdf.h" | 5 #include "pdf/pdf.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } // namespace chrome_pdf | 105 } // namespace chrome_pdf |
106 | 106 |
107 extern "C" { | 107 extern "C" { |
108 | 108 |
109 // TODO(sanjeevr): It might make sense to provide more stateful wrappers over | 109 // TODO(sanjeevr): It might make sense to provide more stateful wrappers over |
110 // the internal PDF SDK (such as LoadDocument, LoadPage etc). Determine if we | 110 // the internal PDF SDK (such as LoadDocument, LoadPage etc). Determine if we |
111 // need to provide this. | 111 // need to provide this. |
112 // Wrapper exports over the PDF engine that can be used by an external module | 112 // Wrapper exports over the PDF engine that can be used by an external module |
113 // such as Chrome (since Chrome cannot directly pull in PDFium sources). | 113 // such as Chrome (since Chrome cannot directly pull in PDFium sources). |
114 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
115 // |pdf_buffer| is the buffer that contains the entire PDF document to be | |
116 // rendered. | |
117 // |buffer_size| is the size of pdf_buffer in bytes. | |
118 // |page_number| is the 0-based index of the page to be rendered. | |
119 // |dc| is the device context to render into. | |
120 // |dpi_x| and |dpi_y| are the x and y resolutions respectively. If either value | |
121 // is -1, the dpi from the DC will be used. | |
122 // |bounds_origin_x|, |bounds_origin_y|, |bounds_width| and |bounds_height| | |
123 // specify a bounds rectangle within the DC in which to render the PDF page. | |
124 // |fit_to_bounds| specifies whether the output should be shrunk to fit the | |
125 // supplied bounds if the page size is larger than the bounds in any | |
126 // dimension. If this is false, parts of the PDF page that lie outside the | |
127 // bounds will be clipped. | |
128 // |stretch_to_bounds| specifies whether the output should be stretched to fit | |
129 // the supplied bounds if the page size is smaller than the bounds in any | |
130 // dimension. | |
131 // If both |fit_to_bounds| and |stretch_to_bounds| are true, then | |
132 // |fit_to_bounds| is honored first. | |
133 // |keep_aspect_ratio| If any scaling is to be done is true, this flag specifies | |
134 // whether the original aspect ratio of the page should be preserved while | |
135 // scaling. | |
136 // |center_in_bounds| specifies whether the final image (after any scaling is | |
137 // done) should be centered within the given bounds. | |
138 // |autorotate| specifies whether the final image should be rotated to match | |
139 // the output bound. | |
140 // Returns false if the document or the page number are not valid. | |
141 PP_EXPORT bool RenderPDFPageToDC(const void* pdf_buffer, | 115 PP_EXPORT bool RenderPDFPageToDC(const void* pdf_buffer, |
142 int buffer_size, | 116 int buffer_size, |
143 int page_number, | 117 int page_number, |
144 HDC dc, | 118 HDC dc, |
145 int dpi_x, | 119 int dpi_x, |
146 int dpi_y, | 120 int dpi_y, |
147 int bounds_origin_x, | 121 int bounds_origin_x, |
148 int bounds_origin_y, | 122 int bounds_origin_y, |
149 int bounds_width, | 123 int bounds_width, |
150 int bounds_height, | 124 int bounds_height, |
(...skipping 17 matching lines...) Expand all Loading... |
168 bool ret = engine_exports->RenderPDFPageToDC(pdf_buffer, buffer_size, | 142 bool ret = engine_exports->RenderPDFPageToDC(pdf_buffer, buffer_size, |
169 page_number, settings, dc); | 143 page_number, settings, dc); |
170 if (!g_sdk_initialized_via_pepper) { | 144 if (!g_sdk_initialized_via_pepper) { |
171 chrome_pdf::ShutdownSDK(); | 145 chrome_pdf::ShutdownSDK(); |
172 } | 146 } |
173 return ret; | 147 return ret; |
174 } | 148 } |
175 | 149 |
176 #endif // OS_WIN | 150 #endif // OS_WIN |
177 | 151 |
178 // |page_count| and |max_page_width| are optional and can be NULL. | |
179 // Returns false if the document is not valid. | |
180 PDF_USED PP_EXPORT | 152 PDF_USED PP_EXPORT |
181 bool GetPDFDocInfo(const void* pdf_buffer, | 153 bool GetPDFDocInfo(const void* pdf_buffer, |
182 int buffer_size, int* page_count, | 154 int buffer_size, int* page_count, |
183 double* max_page_width) { | 155 double* max_page_width) { |
184 if (!g_sdk_initialized_via_pepper) { | 156 if (!g_sdk_initialized_via_pepper) { |
185 void* data = NULL; | 157 void* data = NULL; |
186 #if defined(OS_WIN) | 158 #if defined(OS_WIN) |
187 data = g_hmodule; | 159 data = g_hmodule; |
188 #endif | 160 #endif |
189 if (!chrome_pdf::InitializeSDK(data)) | 161 if (!chrome_pdf::InitializeSDK(data)) |
190 return false; | 162 return false; |
191 } | 163 } |
192 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( | 164 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( |
193 chrome_pdf::PDFEngineExports::Create()); | 165 chrome_pdf::PDFEngineExports::Create()); |
194 bool ret = engine_exports->GetPDFDocInfo( | 166 bool ret = engine_exports->GetPDFDocInfo( |
195 pdf_buffer, buffer_size, page_count, max_page_width); | 167 pdf_buffer, buffer_size, page_count, max_page_width); |
196 if (!g_sdk_initialized_via_pepper) { | 168 if (!g_sdk_initialized_via_pepper) { |
197 chrome_pdf::ShutdownSDK(); | 169 chrome_pdf::ShutdownSDK(); |
198 } | 170 } |
199 return ret; | 171 return ret; |
200 } | 172 } |
201 | 173 |
202 // Renders PDF page into 4-byte per pixel BGRA color bitmap. | 174 PDF_USED PP_EXPORT |
203 // |pdf_buffer| is the buffer that contains the entire PDF document to be | 175 bool GetPDFPageSizeByIndex(const void* pdf_buffer, |
204 // rendered. | 176 int pdf_buffer_size, int page_number, |
205 // |pdf_buffer_size| is the size of pdf_buffer in bytes. | 177 double* width, double* height) { |
206 // |page_number| is the 0-based index of the page to be rendered. | 178 if (!g_sdk_initialized_via_pepper) { |
207 // |bitmap_buffer| is the output buffer for bitmap. | 179 void* data = NULL; |
208 // |bitmap_width| is the width of the output bitmap. | 180 #if defined(OS_WIN) |
209 // |bitmap_height| is the height of the output bitmap. | 181 data = g_hmodule; |
210 // |dpi| is the resolutions. | 182 #endif |
211 // |autorotate| specifies whether the final image should be rotated to match | 183 if (!chrome_pdf::InitializeSDK(data)) |
212 // the output bound. | 184 return false; |
213 // Returns false if the document or the page number are not valid. | 185 } |
| 186 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( |
| 187 chrome_pdf::PDFEngineExports::Create()); |
| 188 bool ret = engine_exports->GetPDFPageSizeByIndex( |
| 189 pdf_buffer, pdf_buffer_size, page_number, width, height); |
| 190 if (!g_sdk_initialized_via_pepper) |
| 191 chrome_pdf::ShutdownSDK(); |
| 192 return ret; |
| 193 } |
| 194 |
214 PDF_USED PP_EXPORT | 195 PDF_USED PP_EXPORT |
215 bool RenderPDFPageToBitmap(const void* pdf_buffer, | 196 bool RenderPDFPageToBitmap(const void* pdf_buffer, |
216 int pdf_buffer_size, | 197 int pdf_buffer_size, |
217 int page_number, | 198 int page_number, |
218 void* bitmap_buffer, | 199 void* bitmap_buffer, |
219 int bitmap_width, | 200 int bitmap_width, |
220 int bitmap_height, | 201 int bitmap_height, |
221 int dpi, | 202 int dpi, |
222 bool autorotate) { | 203 bool autorotate) { |
223 if (!g_sdk_initialized_via_pepper) { | 204 if (!g_sdk_initialized_via_pepper) { |
(...skipping 11 matching lines...) Expand all Loading... |
235 autorotate); | 216 autorotate); |
236 bool ret = engine_exports->RenderPDFPageToBitmap( | 217 bool ret = engine_exports->RenderPDFPageToBitmap( |
237 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer); | 218 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer); |
238 if (!g_sdk_initialized_via_pepper) { | 219 if (!g_sdk_initialized_via_pepper) { |
239 chrome_pdf::ShutdownSDK(); | 220 chrome_pdf::ShutdownSDK(); |
240 } | 221 } |
241 return ret; | 222 return ret; |
242 } | 223 } |
243 | 224 |
244 } // extern "C" | 225 } // extern "C" |
OLD | NEW |