OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/utility/printing_handler.h" | 5 #include "chrome/utility/printing_handler.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/scoped_native_library.h" | 10 #include "base/scoped_native_library.h" |
11 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
12 #include "chrome/common/chrome_utility_printing_messages.h" | 12 #include "chrome/common/chrome_utility_printing_messages.h" |
| 13 #include "chrome/installer/util/util_constants.h" |
13 #include "chrome/utility/cloud_print/bitmap_image.h" | 14 #include "chrome/utility/cloud_print/bitmap_image.h" |
14 #include "chrome/utility/cloud_print/pwg_encoder.h" | 15 #include "chrome/utility/cloud_print/pwg_encoder.h" |
15 #include "content/public/utility/utility_thread.h" | 16 #include "content/public/utility/utility_thread.h" |
| 17 #include "pdf/pdf.h" |
16 #include "printing/page_range.h" | 18 #include "printing/page_range.h" |
17 #include "printing/pdf_render_settings.h" | 19 #include "printing/pdf_render_settings.h" |
18 | 20 |
19 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
20 #include "base/win/iat_patch_function.h" | 22 #include "base/win/iat_patch_function.h" |
21 #include "printing/emf_win.h" | 23 #include "printing/emf_win.h" |
22 #include "ui/gfx/gdi_util.h" | 24 #include "ui/gfx/gdi_util.h" |
23 #endif | 25 #endif |
24 | 26 |
25 #if defined(ENABLE_PRINT_PREVIEW) | 27 #if defined(ENABLE_PRINT_PREVIEW) |
26 #include "chrome/common/crash_keys.h" | 28 #include "chrome/common/crash_keys.h" |
27 #include "printing/backend/print_backend.h" | 29 #include "printing/backend/print_backend.h" |
28 #endif | 30 #endif |
29 | 31 |
30 namespace { | 32 namespace { |
31 | 33 |
32 bool Send(IPC::Message* message) { | 34 bool Send(IPC::Message* message) { |
33 return content::UtilityThread::Get()->Send(message); | 35 return content::UtilityThread::Get()->Send(message); |
34 } | 36 } |
35 | 37 |
36 void ReleaseProcessIfNeeded() { | 38 void ReleaseProcessIfNeeded() { |
37 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | 39 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
38 } | 40 } |
39 | 41 |
40 class PdfFunctionsBase { | |
41 public: | |
42 PdfFunctionsBase() : render_pdf_to_bitmap_func_(NULL), | |
43 get_pdf_doc_info_func_(NULL) {} | |
44 | |
45 bool Init() { | |
46 base::FilePath pdf_module_path; | |
47 if (!PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_module_path) || | |
48 !base::PathExists(pdf_module_path)) { | |
49 return false; | |
50 } | |
51 | |
52 pdf_lib_.Reset(base::LoadNativeLibrary(pdf_module_path, NULL)); | |
53 if (!pdf_lib_.is_valid()) { | |
54 LOG(WARNING) << "Couldn't load PDF plugin"; | |
55 return false; | |
56 } | |
57 | |
58 render_pdf_to_bitmap_func_ = | |
59 reinterpret_cast<RenderPDFPageToBitmapProc>( | |
60 pdf_lib_.GetFunctionPointer("RenderPDFPageToBitmap")); | |
61 LOG_IF(WARNING, !render_pdf_to_bitmap_func_) << | |
62 "Missing RenderPDFPageToBitmap"; | |
63 | |
64 get_pdf_doc_info_func_ = | |
65 reinterpret_cast<GetPDFDocInfoProc>( | |
66 pdf_lib_.GetFunctionPointer("GetPDFDocInfo")); | |
67 LOG_IF(WARNING, !get_pdf_doc_info_func_) << "Missing GetPDFDocInfo"; | |
68 | |
69 if (!render_pdf_to_bitmap_func_ || !get_pdf_doc_info_func_ || | |
70 !PlatformInit(pdf_module_path, pdf_lib_)) { | |
71 Reset(); | |
72 } | |
73 | |
74 return IsValid(); | |
75 } | |
76 | |
77 bool IsValid() const { | |
78 return pdf_lib_.is_valid(); | |
79 } | |
80 | |
81 void Reset() { | |
82 pdf_lib_.Reset(NULL); | |
83 } | |
84 | |
85 bool RenderPDFPageToBitmap(const void* pdf_buffer, | |
86 int pdf_buffer_size, | |
87 int page_number, | |
88 void* bitmap_buffer, | |
89 int bitmap_width, | |
90 int bitmap_height, | |
91 int dpi_x, | |
92 int dpi_y, | |
93 bool autorotate) { | |
94 if (!render_pdf_to_bitmap_func_) | |
95 return false; | |
96 return render_pdf_to_bitmap_func_(pdf_buffer, pdf_buffer_size, page_number, | |
97 bitmap_buffer, bitmap_width, | |
98 bitmap_height, dpi_x, dpi_y, autorotate); | |
99 } | |
100 | |
101 bool GetPDFDocInfo(const void* pdf_buffer, | |
102 int buffer_size, | |
103 int* page_count, | |
104 double* max_page_width) { | |
105 if (!get_pdf_doc_info_func_) | |
106 return false; | |
107 return get_pdf_doc_info_func_(pdf_buffer, buffer_size, page_count, | |
108 max_page_width); | |
109 } | |
110 | |
111 protected: | |
112 virtual bool PlatformInit( | |
113 const base::FilePath& pdf_module_path, | |
114 const base::ScopedNativeLibrary& pdf_lib) { | |
115 return true; | |
116 } | |
117 | |
118 private: | |
119 // Exported by PDF plugin. | |
120 typedef bool (*RenderPDFPageToBitmapProc)(const void* pdf_buffer, | |
121 int pdf_buffer_size, | |
122 int page_number, | |
123 void* bitmap_buffer, | |
124 int bitmap_width, | |
125 int bitmap_height, | |
126 int dpi_x, | |
127 int dpi_y, | |
128 bool autorotate); | |
129 typedef bool (*GetPDFDocInfoProc)(const void* pdf_buffer, | |
130 int buffer_size, int* page_count, | |
131 double* max_page_width); | |
132 | |
133 RenderPDFPageToBitmapProc render_pdf_to_bitmap_func_; | |
134 GetPDFDocInfoProc get_pdf_doc_info_func_; | |
135 | |
136 base::ScopedNativeLibrary pdf_lib_; | |
137 DISALLOW_COPY_AND_ASSIGN(PdfFunctionsBase); | |
138 }; | |
139 | |
140 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
141 // The 2 below IAT patch functions are almost identical to the code in | 43 // The 2 below IAT patch functions are almost identical to the code in |
142 // render_process_impl.cc. This is needed to work around specific Windows APIs | 44 // render_process_impl.cc. This is needed to work around specific Windows APIs |
143 // used by the Chrome PDF plugin that will fail in the sandbox. | 45 // used by the Chrome PDF plugin that will fail in the sandbox. |
144 static base::win::IATPatchFunction g_iat_patch_createdca; | 46 static base::win::IATPatchFunction g_iat_patch_createdca; |
145 HDC WINAPI UtilityProcess_CreateDCAPatch(LPCSTR driver_name, | 47 HDC WINAPI UtilityProcess_CreateDCAPatch(LPCSTR driver_name, |
146 LPCSTR device_name, | 48 LPCSTR device_name, |
147 LPCSTR output, | 49 LPCSTR output, |
148 const DEVMODEA* init_data) { | 50 const DEVMODEA* init_data) { |
149 if (driver_name && (std::string("DISPLAY") == driver_name)) { | 51 if (driver_name && (std::string("DISPLAY") == driver_name)) { |
(...skipping 14 matching lines...) Expand all Loading... |
164 | 66 |
165 LOGFONT logfont; | 67 LOGFONT logfont; |
166 if (GetObject(font, sizeof(LOGFONT), &logfont)) { | 68 if (GetObject(font, sizeof(LOGFONT), &logfont)) { |
167 content::UtilityThread::Get()->PreCacheFont(logfont); | 69 content::UtilityThread::Get()->PreCacheFont(logfont); |
168 rv = GetFontData(hdc, table, offset, buffer, length); | 70 rv = GetFontData(hdc, table, offset, buffer, length); |
169 content::UtilityThread::Get()->ReleaseCachedFonts(); | 71 content::UtilityThread::Get()->ReleaseCachedFonts(); |
170 } | 72 } |
171 } | 73 } |
172 return rv; | 74 return rv; |
173 } | 75 } |
174 | |
175 class PdfFunctionsWin : public PdfFunctionsBase { | |
176 public: | |
177 PdfFunctionsWin() : render_pdf_to_dc_func_(NULL) { | |
178 } | |
179 | |
180 bool PlatformInit( | |
181 const base::FilePath& pdf_module_path, | |
182 const base::ScopedNativeLibrary& pdf_lib) override { | |
183 // Patch the IAT for handling specific APIs known to fail in the sandbox. | |
184 if (!g_iat_patch_createdca.is_patched()) { | |
185 g_iat_patch_createdca.Patch(pdf_module_path.value().c_str(), | |
186 "gdi32.dll", "CreateDCA", | |
187 UtilityProcess_CreateDCAPatch); | |
188 } | |
189 | |
190 if (!g_iat_patch_get_font_data.is_patched()) { | |
191 g_iat_patch_get_font_data.Patch(pdf_module_path.value().c_str(), | |
192 "gdi32.dll", "GetFontData", | |
193 UtilityProcess_GetFontDataPatch); | |
194 } | |
195 render_pdf_to_dc_func_ = | |
196 reinterpret_cast<RenderPDFPageToDCProc>( | |
197 pdf_lib.GetFunctionPointer("RenderPDFPageToDC")); | |
198 LOG_IF(WARNING, !render_pdf_to_dc_func_) << "Missing RenderPDFPageToDC"; | |
199 | |
200 return render_pdf_to_dc_func_ != NULL; | |
201 } | |
202 | |
203 bool RenderPDFPageToDC(const void* pdf_buffer, | |
204 int buffer_size, | |
205 int page_number, | |
206 HDC dc, | |
207 int dpi_x, | |
208 int dpi_y, | |
209 int bounds_origin_x, | |
210 int bounds_origin_y, | |
211 int bounds_width, | |
212 int bounds_height, | |
213 bool fit_to_bounds, | |
214 bool stretch_to_bounds, | |
215 bool keep_aspect_ratio, | |
216 bool center_in_bounds, | |
217 bool autorotate) { | |
218 if (!render_pdf_to_dc_func_) | |
219 return false; | |
220 return render_pdf_to_dc_func_(pdf_buffer, buffer_size, page_number, | |
221 dc, dpi_x, dpi_y, bounds_origin_x, | |
222 bounds_origin_y, bounds_width, bounds_height, | |
223 fit_to_bounds, stretch_to_bounds, | |
224 keep_aspect_ratio, center_in_bounds, | |
225 autorotate); | |
226 } | |
227 | |
228 private: | |
229 // Exported by PDF plugin. | |
230 typedef bool (*RenderPDFPageToDCProc)( | |
231 const void* pdf_buffer, int buffer_size, int page_number, HDC dc, | |
232 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, | |
233 int bounds_width, int bounds_height, bool fit_to_bounds, | |
234 bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds, | |
235 bool autorotate); | |
236 RenderPDFPageToDCProc render_pdf_to_dc_func_; | |
237 | |
238 DISALLOW_COPY_AND_ASSIGN(PdfFunctionsWin); | |
239 }; | |
240 | |
241 typedef PdfFunctionsWin PdfFunctions; | |
242 #else // OS_WIN | |
243 typedef PdfFunctionsBase PdfFunctions; | |
244 #endif // OS_WIN | 76 #endif // OS_WIN |
245 | 77 |
246 base::LazyInstance<PdfFunctions> g_pdf_lib = LAZY_INSTANCE_INITIALIZER; | |
247 | |
248 } // namespace | 78 } // namespace |
249 | 79 |
250 PrintingHandler::PrintingHandler() {} | 80 PrintingHandler::PrintingHandler() {} |
251 | 81 |
252 PrintingHandler::~PrintingHandler() {} | 82 PrintingHandler::~PrintingHandler() {} |
253 | 83 |
254 // static | 84 // static |
255 void PrintingHandler::PreSandboxStartup() { | 85 void PrintingHandler::PreSandboxStartup() { |
256 g_pdf_lib.Get().Init(); | 86 #if defined(OS_WIN) |
| 87 // Patch the IAT for handling specific APIs known to fail in the sandbox. |
| 88 const wchar_t* chrome_dll_name = |
| 89 #if defined(CHROME_MULTIPLE_DLL_CHILD) |
| 90 installer::kChromeChildDll; |
| 91 #else |
| 92 installer::kChromeDll; |
| 93 #endif |
| 94 if (!g_iat_patch_createdca.is_patched()) { |
| 95 g_iat_patch_createdca.Patch(chrome_dll_name, |
| 96 "gdi32.dll", "CreateDCA", |
| 97 UtilityProcess_CreateDCAPatch); |
| 98 } |
| 99 |
| 100 if (!g_iat_patch_get_font_data.is_patched()) { |
| 101 g_iat_patch_get_font_data.Patch(chrome_dll_name, |
| 102 "gdi32.dll", "GetFontData", |
| 103 UtilityProcess_GetFontDataPatch); |
| 104 } |
| 105 #endif |
257 } | 106 } |
258 | 107 |
259 bool PrintingHandler::OnMessageReceived(const IPC::Message& message) { | 108 bool PrintingHandler::OnMessageReceived(const IPC::Message& message) { |
260 bool handled = true; | 109 bool handled = true; |
261 IPC_BEGIN_MESSAGE_MAP(PrintingHandler, message) | 110 IPC_BEGIN_MESSAGE_MAP(PrintingHandler, message) |
262 #if defined(OS_WIN) | 111 #if defined(OS_WIN) |
263 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles, | 112 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles, |
264 OnRenderPDFPagesToMetafile) | 113 OnRenderPDFPagesToMetafile) |
265 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage, | 114 IPC_MESSAGE_HANDLER(ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage, |
266 OnRenderPDFPagesToMetafileGetPage) | 115 OnRenderPDFPagesToMetafileGetPage) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 Send(new ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Succeeded()); | 170 Send(new ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Succeeded()); |
322 } else { | 171 } else { |
323 Send(new ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Failed()); | 172 Send(new ChromeUtilityHostMsg_RenderPDFPagesToPWGRaster_Failed()); |
324 } | 173 } |
325 ReleaseProcessIfNeeded(); | 174 ReleaseProcessIfNeeded(); |
326 } | 175 } |
327 #endif // ENABLE_PRINT_PREVIEW | 176 #endif // ENABLE_PRINT_PREVIEW |
328 | 177 |
329 #if defined(OS_WIN) | 178 #if defined(OS_WIN) |
330 int PrintingHandler::LoadPDF(base::File pdf_file) { | 179 int PrintingHandler::LoadPDF(base::File pdf_file) { |
331 if (!g_pdf_lib.Get().IsValid()) | |
332 return 0; | |
333 | |
334 int64 length64 = pdf_file.GetLength(); | 180 int64 length64 = pdf_file.GetLength(); |
335 if (length64 <= 0 || length64 > std::numeric_limits<int>::max()) | 181 if (length64 <= 0 || length64 > std::numeric_limits<int>::max()) |
336 return 0; | 182 return 0; |
337 int length = static_cast<int>(length64); | 183 int length = static_cast<int>(length64); |
338 | 184 |
339 pdf_data_.resize(length); | 185 pdf_data_.resize(length); |
340 if (length != pdf_file.Read(0, pdf_data_.data(), pdf_data_.size())) | 186 if (length != pdf_file.Read(0, pdf_data_.data(), pdf_data_.size())) |
341 return 0; | 187 return 0; |
342 | 188 |
343 int total_page_count = 0; | 189 int total_page_count = 0; |
344 if (!g_pdf_lib.Get().GetPDFDocInfo( | 190 if (!chrome_pdf::GetPDFDocInfo( |
345 &pdf_data_.front(), pdf_data_.size(), &total_page_count, NULL)) { | 191 &pdf_data_.front(), pdf_data_.size(), &total_page_count, NULL)) { |
346 return 0; | 192 return 0; |
347 } | 193 } |
348 return total_page_count; | 194 return total_page_count; |
349 } | 195 } |
350 | 196 |
351 bool PrintingHandler::RenderPdfPageToMetafile(int page_number, | 197 bool PrintingHandler::RenderPdfPageToMetafile(int page_number, |
352 base::File output_file, | 198 base::File output_file, |
353 float* scale_factor) { | 199 float* scale_factor) { |
354 printing::Emf metafile; | 200 printing::Emf metafile; |
355 metafile.Init(); | 201 metafile.Init(); |
356 | 202 |
357 // We need to scale down DC to fit an entire page into DC available area. | 203 // We need to scale down DC to fit an entire page into DC available area. |
358 // Current metafile is based on screen DC and have current screen size. | 204 // Current metafile is based on screen DC and have current screen size. |
359 // Writing outside of those boundaries will result in the cut-off output. | 205 // Writing outside of those boundaries will result in the cut-off output. |
360 // On metafiles (this is the case here), scaling down will still record | 206 // On metafiles (this is the case here), scaling down will still record |
361 // original coordinates and we'll be able to print in full resolution. | 207 // original coordinates and we'll be able to print in full resolution. |
362 // Before playback we'll need to counter the scaling up that will happen | 208 // Before playback we'll need to counter the scaling up that will happen |
363 // in the service (print_system_win.cc). | 209 // in the service (print_system_win.cc). |
364 *scale_factor = | 210 *scale_factor = |
365 gfx::CalculatePageScale(metafile.context(), | 211 gfx::CalculatePageScale(metafile.context(), |
366 pdf_rendering_settings_.area().right(), | 212 pdf_rendering_settings_.area().right(), |
367 pdf_rendering_settings_.area().bottom()); | 213 pdf_rendering_settings_.area().bottom()); |
368 gfx::ScaleDC(metafile.context(), *scale_factor); | 214 gfx::ScaleDC(metafile.context(), *scale_factor); |
369 | 215 |
370 // The underlying metafile is of type Emf and ignores the arguments passed | 216 // The underlying metafile is of type Emf and ignores the arguments passed |
371 // to StartPage. | 217 // to StartPage. |
372 metafile.StartPage(gfx::Size(), gfx::Rect(), 1); | 218 metafile.StartPage(gfx::Size(), gfx::Rect(), 1); |
373 if (!g_pdf_lib.Get().RenderPDFPageToDC( | 219 if (!chrome_pdf::RenderPDFPageToDC( |
374 &pdf_data_.front(), | 220 &pdf_data_.front(), |
375 pdf_data_.size(), | 221 pdf_data_.size(), |
376 page_number, | 222 page_number, |
377 metafile.context(), | 223 metafile.context(), |
378 pdf_rendering_settings_.dpi(), | 224 pdf_rendering_settings_.dpi(), |
379 pdf_rendering_settings_.dpi(), | |
380 pdf_rendering_settings_.area().x(), | 225 pdf_rendering_settings_.area().x(), |
381 pdf_rendering_settings_.area().y(), | 226 pdf_rendering_settings_.area().y(), |
382 pdf_rendering_settings_.area().width(), | 227 pdf_rendering_settings_.area().width(), |
383 pdf_rendering_settings_.area().height(), | 228 pdf_rendering_settings_.area().height(), |
384 true, | 229 true, |
385 false, | 230 false, |
386 true, | 231 true, |
387 true, | 232 true, |
388 pdf_rendering_settings_.autorotate())) { | 233 pdf_rendering_settings_.autorotate())) { |
389 return false; | 234 return false; |
390 } | 235 } |
391 metafile.FinishPage(); | 236 metafile.FinishPage(); |
392 metafile.FinishDocument(); | 237 metafile.FinishDocument(); |
393 return metafile.SaveTo(&output_file); | 238 return metafile.SaveTo(&output_file); |
394 } | 239 } |
395 | 240 |
396 #endif // OS_WIN | 241 #endif // OS_WIN |
397 | 242 |
398 #if defined(ENABLE_PRINT_PREVIEW) | 243 #if defined(ENABLE_PRINT_PREVIEW) |
399 bool PrintingHandler::RenderPDFPagesToPWGRaster( | 244 bool PrintingHandler::RenderPDFPagesToPWGRaster( |
400 base::File pdf_file, | 245 base::File pdf_file, |
401 const printing::PdfRenderSettings& settings, | 246 const printing::PdfRenderSettings& settings, |
402 const printing::PwgRasterSettings& bitmap_settings, | 247 const printing::PwgRasterSettings& bitmap_settings, |
403 base::File bitmap_file) { | 248 base::File bitmap_file) { |
404 bool autoupdate = true; | 249 bool autoupdate = true; |
405 if (!g_pdf_lib.Get().IsValid()) | |
406 return false; | |
407 | |
408 base::File::Info info; | 250 base::File::Info info; |
409 if (!pdf_file.GetInfo(&info) || info.size <= 0 || | 251 if (!pdf_file.GetInfo(&info) || info.size <= 0 || |
410 info.size > std::numeric_limits<int>::max()) | 252 info.size > std::numeric_limits<int>::max()) |
411 return false; | 253 return false; |
412 int data_size = static_cast<int>(info.size); | 254 int data_size = static_cast<int>(info.size); |
413 | 255 |
414 std::string data(data_size, 0); | 256 std::string data(data_size, 0); |
415 if (pdf_file.Read(0, &data[0], data_size) != data_size) | 257 if (pdf_file.Read(0, &data[0], data_size) != data_size) |
416 return false; | 258 return false; |
417 | 259 |
418 int total_page_count = 0; | 260 int total_page_count = 0; |
419 if (!g_pdf_lib.Get().GetPDFDocInfo(data.data(), data_size, | 261 if (!chrome_pdf::GetPDFDocInfo(data.data(), data_size, |
420 &total_page_count, NULL)) { | 262 &total_page_count, NULL)) { |
421 return false; | 263 return false; |
422 } | 264 } |
423 | 265 |
424 cloud_print::PwgEncoder encoder; | 266 cloud_print::PwgEncoder encoder; |
425 std::string pwg_header; | 267 std::string pwg_header; |
426 encoder.EncodeDocumentHeader(&pwg_header); | 268 encoder.EncodeDocumentHeader(&pwg_header); |
427 int bytes_written = bitmap_file.WriteAtCurrentPos(pwg_header.data(), | 269 int bytes_written = bitmap_file.WriteAtCurrentPos(pwg_header.data(), |
428 pwg_header.size()); | 270 pwg_header.size()); |
429 if (bytes_written != static_cast<int>(pwg_header.size())) | 271 if (bytes_written != static_cast<int>(pwg_header.size())) |
430 return false; | 272 return false; |
431 | 273 |
432 cloud_print::BitmapImage image(settings.area().size(), | 274 cloud_print::BitmapImage image(settings.area().size(), |
433 cloud_print::BitmapImage::BGRA); | 275 cloud_print::BitmapImage::BGRA); |
434 for (int i = 0; i < total_page_count; ++i) { | 276 for (int i = 0; i < total_page_count; ++i) { |
435 int page_number = i; | 277 int page_number = i; |
436 | 278 |
437 if (bitmap_settings.reverse_page_order) { | 279 if (bitmap_settings.reverse_page_order) { |
438 page_number = total_page_count - 1 - page_number; | 280 page_number = total_page_count - 1 - page_number; |
439 } | 281 } |
440 | 282 |
441 if (!g_pdf_lib.Get().RenderPDFPageToBitmap(data.data(), | 283 if (!chrome_pdf::RenderPDFPageToBitmap(data.data(), |
442 data_size, | 284 data_size, |
443 page_number, | 285 page_number, |
444 image.pixel_data(), | 286 image.pixel_data(), |
445 image.size().width(), | 287 image.size().width(), |
446 image.size().height(), | 288 image.size().height(), |
447 settings.dpi(), | 289 settings.dpi(), |
448 settings.dpi(), | 290 autoupdate)) { |
449 autoupdate)) { | |
450 return false; | 291 return false; |
451 } | 292 } |
452 | 293 |
453 cloud_print::PwgHeaderInfo header_info; | 294 cloud_print::PwgHeaderInfo header_info; |
454 header_info.dpi = settings.dpi(); | 295 header_info.dpi = settings.dpi(); |
455 header_info.total_pages = total_page_count; | 296 header_info.total_pages = total_page_count; |
456 | 297 |
457 // Transform odd pages. | 298 // Transform odd pages. |
458 if (page_number % 2) { | 299 if (page_number % 2) { |
459 switch (bitmap_settings.odd_page_transform) { | 300 switch (bitmap_settings.odd_page_transform) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 &printer_info)) { | 361 &printer_info)) { |
521 Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded( | 362 Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded( |
522 printer_name, printer_info)); | 363 printer_name, printer_info)); |
523 } else { | 364 } else { |
524 Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed( | 365 Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed( |
525 printer_name)); | 366 printer_name)); |
526 } | 367 } |
527 ReleaseProcessIfNeeded(); | 368 ReleaseProcessIfNeeded(); |
528 } | 369 } |
529 #endif // ENABLE_PRINT_PREVIEW | 370 #endif // ENABLE_PRINT_PREVIEW |
OLD | NEW |