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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | 115 // |pdf_buffer| is the buffer that contains the entire PDF document to be |
116 // rendered. | 116 // rendered. |
117 // |buffer_size| is the size of pdf_buffer in bytes. | 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. | 118 // |page_number| is the 0-based index of the page to be rendered. |
119 // |dc| is the device context to render into. | 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 | 120 // |dpi_x| and |dpi_y| are the x and y resolutions respectively. If either |
121 // is -1, the dpi from the DC will be used. | 121 // value is -1, the dpi from the DC will be used. |
Dan Beam
2014/07/10 02:19:58
revert
| |
122 // |bounds_origin_x|, |bounds_origin_y|, |bounds_width| and |bounds_height| | 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. | 123 // specify a bounds rectangle within the DC in which to render the PDF |
124 // page. | |
Dan Beam
2014/07/10 02:19:58
revert
| |
124 // |fit_to_bounds| specifies whether the output should be shrunk to fit the | 125 // |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 // 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 // dimension. If this is false, parts of the PDF page that lie outside |
127 // bounds will be clipped. | 128 // the bounds will be clipped. |
Dan Beam
2014/07/10 02:19:58
revert
| |
128 // |stretch_to_bounds| specifies whether the output should be stretched to fit | 129 // |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 // the supplied bounds if the page size is smaller than the bounds in any |
130 // dimension. | 131 // dimension. |
131 // If both |fit_to_bounds| and |stretch_to_bounds| are true, then | 132 // If both |fit_to_bounds| and |stretch_to_bounds| are true, then |
132 // |fit_to_bounds| is honored first. | 133 // |fit_to_bounds| is honored first. |
133 // |keep_aspect_ratio| If any scaling is to be done is true, this flag specifies | 134 // |keep_aspect_ratio| If any scaling is to be done is true, this flag |
134 // whether the original aspect ratio of the page should be preserved while | 135 // specifies whether the original aspect ratio of the page should be |
135 // scaling. | 136 // preserved while scaling. |
Dan Beam
2014/07/10 02:19:58
revert
| |
136 // |center_in_bounds| specifies whether the final image (after any scaling is | 137 // |center_in_bounds| specifies whether the final image (after any scaling is |
137 // done) should be centered within the given bounds. | 138 // done) should be centered within the given bounds. |
138 // |autorotate| specifies whether the final image should be rotated to match | 139 // |autorotate| specifies whether the final image should be rotated to match |
139 // the output bound. | 140 // the output bound. |
140 // Returns false if the document or the page number are not valid. | 141 // Returns false if the document or the page number are not valid. |
141 PP_EXPORT bool RenderPDFPageToDC(const void* pdf_buffer, | 142 PP_EXPORT bool RenderPDFPageToDC(const void* pdf_buffer, |
142 int buffer_size, | 143 int buffer_size, |
143 int page_number, | 144 int page_number, |
144 HDC dc, | 145 HDC dc, |
145 int dpi_x, | 146 int dpi_x, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( | 193 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( |
193 chrome_pdf::PDFEngineExports::Create()); | 194 chrome_pdf::PDFEngineExports::Create()); |
194 bool ret = engine_exports->GetPDFDocInfo( | 195 bool ret = engine_exports->GetPDFDocInfo( |
195 pdf_buffer, buffer_size, page_count, max_page_width); | 196 pdf_buffer, buffer_size, page_count, max_page_width); |
196 if (!g_sdk_initialized_via_pepper) { | 197 if (!g_sdk_initialized_via_pepper) { |
197 chrome_pdf::ShutdownSDK(); | 198 chrome_pdf::ShutdownSDK(); |
198 } | 199 } |
199 return ret; | 200 return ret; |
200 } | 201 } |
201 | 202 |
203 // Gets the dimensions of a specific page in a document. | |
204 // |pdf_buffer| is the buffer that contains the entire PDF document to be | |
205 // rendered. | |
206 // |pdf_buffer_size| is the size of |pdf_buffer| in bytes. | |
207 // |page_number| is the page number that the function will get the dimensions | |
208 // of. | |
209 // |width| is the output for the width of the page in points. | |
210 // |height| is the output for the height of the page in points. | |
211 // Returns false if the document or the page number are not valid. | |
Dan Beam
2014/07/10 02:19:59
this is also a local pattern (i've never seen), wh
| |
212 PDF_USED PP_EXPORT | |
213 bool GetPDFPageSizeByIndex(const void* pdf_buffer, | |
214 int pdf_buffer_size, int page_number, | |
215 double* width, double* height) { | |
216 if (!g_sdk_initialized_via_pepper) { | |
217 void* data = NULL; | |
218 #if defined(OS_WIN) | |
219 data = g_hmodule; | |
220 #endif | |
221 if (!chrome_pdf::InitializeSDK(data)) | |
222 return false; | |
223 } | |
224 scoped_ptr<chrome_pdf::PDFEngineExports> engine_exports( | |
225 chrome_pdf::PDFEngineExports::Create()); | |
226 bool ret = engine_exports->GetPDFPageSizeByIndex( | |
227 pdf_buffer, pdf_buffer_size, page_number, width, height); | |
228 if (!g_sdk_initialized_via_pepper) | |
229 chrome_pdf::ShutdownSDK(); | |
230 return ret; | |
231 } | |
232 | |
202 // Renders PDF page into 4-byte per pixel BGRA color bitmap. | 233 // Renders PDF page into 4-byte per pixel BGRA color bitmap. |
203 // |pdf_buffer| is the buffer that contains the entire PDF document to be | 234 // |pdf_buffer| is the buffer that contains the entire PDF document to be |
204 // rendered. | 235 // rendered. |
205 // |pdf_buffer_size| is the size of pdf_buffer in bytes. | 236 // |pdf_buffer_size| is the size of |pdf_buffer| in bytes. |
206 // |page_number| is the 0-based index of the page to be rendered. | 237 // |page_number| is the 0-based index of the page to be rendered. |
207 // |bitmap_buffer| is the output buffer for bitmap. | 238 // |bitmap_buffer| is the output buffer for bitmap. |
208 // |bitmap_width| is the width of the output bitmap. | 239 // |bitmap_width| is the width of the output bitmap. |
209 // |bitmap_height| is the height of the output bitmap. | 240 // |bitmap_height| is the height of the output bitmap. |
210 // |dpi| is the resolutions. | 241 // |dpi| is the resolutions. |
211 // |autorotate| specifies whether the final image should be rotated to match | 242 // |autorotate| specifies whether the final image should be rotated to match |
212 // the output bound. | 243 // the output bound. |
213 // Returns false if the document or the page number are not valid. | 244 // Returns false if the document or the page number are not valid. |
214 PDF_USED PP_EXPORT | 245 PDF_USED PP_EXPORT |
215 bool RenderPDFPageToBitmap(const void* pdf_buffer, | 246 bool RenderPDFPageToBitmap(const void* pdf_buffer, |
(...skipping 19 matching lines...) Expand all Loading... | |
235 autorotate); | 266 autorotate); |
236 bool ret = engine_exports->RenderPDFPageToBitmap( | 267 bool ret = engine_exports->RenderPDFPageToBitmap( |
237 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer); | 268 pdf_buffer, pdf_buffer_size, page_number, settings, bitmap_buffer); |
238 if (!g_sdk_initialized_via_pepper) { | 269 if (!g_sdk_initialized_via_pepper) { |
239 chrome_pdf::ShutdownSDK(); | 270 chrome_pdf::ShutdownSDK(); |
240 } | 271 } |
241 return ret; | 272 return ret; |
242 } | 273 } |
243 | 274 |
244 } // extern "C" | 275 } // extern "C" |
OLD | NEW |