OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/renderer/print_web_view_helper.h" | 5 #include "chrome/renderer/print_web_view_helper.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/process_util.h" | 8 #include "base/process_util.h" |
9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
10 #include "chrome/common/render_messages_params.h" | 10 #include "chrome/common/render_messages_params.h" |
| 11 #include "printing/native_metafile_factory.h" |
| 12 #include "printing/native_metafile.h" |
11 #include "printing/units.h" | 13 #include "printing/units.h" |
12 #include "skia/ext/vector_canvas.h" | 14 #include "skia/ext/vector_canvas.h" |
13 #include "skia/ext/vector_platform_device.h" | 15 #include "skia/ext/vector_platform_device.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
15 #include "ui/gfx/gdi_util.h" | 17 #include "ui/gfx/gdi_util.h" |
16 | 18 |
17 using printing::ConvertUnitDouble; | 19 using printing::ConvertUnitDouble; |
18 using printing::kPointsPerInch; | 20 using printing::kPointsPerInch; |
19 using WebKit::WebFrame; | 21 using WebKit::WebFrame; |
20 | 22 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 return 1; // Continue enumeration | 62 return 1; // Continue enumeration |
61 } | 63 } |
62 | 64 |
63 } // namespace | 65 } // namespace |
64 | 66 |
65 void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, | 67 void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, |
66 const gfx::Size& canvas_size, | 68 const gfx::Size& canvas_size, |
67 WebFrame* frame) { | 69 WebFrame* frame) { |
68 // Generate a memory-based metafile. It will use the current screen's DPI. | 70 // Generate a memory-based metafile. It will use the current screen's DPI. |
69 // Each metafile contains a single page. | 71 // Each metafile contains a single page. |
70 scoped_ptr<printing::NativeMetafile> metafile(new printing::NativeMetafile); | 72 scoped_ptr<printing::NativeMetafile> metafile( |
| 73 printing::NativeMetafileFactory::CreateMetafile()); |
71 metafile->CreateDc(NULL, NULL); | 74 metafile->CreateDc(NULL, NULL); |
72 DCHECK(metafile->hdc()); | 75 DCHECK(metafile->hdc()); |
73 skia::PlatformDevice::InitializeDC(metafile->hdc()); | 76 skia::PlatformDevice::InitializeDC(metafile->hdc()); |
74 | 77 |
75 int page_number = params.page_number; | 78 int page_number = params.page_number; |
76 | 79 |
77 // Calculate the dpi adjustment. | 80 // Calculate the dpi adjustment. |
78 float scale_factor = static_cast<float>(params.params.desired_dpi / | 81 float scale_factor = static_cast<float>(params.params.desired_dpi / |
79 params.params.dpi); | 82 params.params.dpi); |
80 | 83 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 if (!page_count) | 129 if (!page_count) |
127 return; | 130 return; |
128 | 131 |
129 // NOTE: This is an enhanced-format metafile(EMF) which has an appearance of | 132 // NOTE: This is an enhanced-format metafile(EMF) which has an appearance of |
130 // single page metafile. For print preview, we need a metafile with multiple | 133 // single page metafile. For print preview, we need a metafile with multiple |
131 // pages. | 134 // pages. |
132 // TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia | 135 // TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia |
133 // PDF backend" work is completed for windows, make changes to replace this | 136 // PDF backend" work is completed for windows, make changes to replace this |
134 // EMF with PDF metafile. | 137 // EMF with PDF metafile. |
135 // http://code.google.com/p/chromium/issues/detail?id=62889 | 138 // http://code.google.com/p/chromium/issues/detail?id=62889 |
136 scoped_ptr<printing::NativeMetafile> metafile(new printing::NativeMetafile); | 139 scoped_ptr<printing::NativeMetafile> metafile( |
| 140 printing::NativeMetafileFactory::CreateMetafile()); |
137 metafile->CreateDc(NULL, NULL); | 141 metafile->CreateDc(NULL, NULL); |
138 DCHECK(metafile->hdc()); | 142 DCHECK(metafile->hdc()); |
139 skia::PlatformDevice::InitializeDC(metafile->hdc()); | 143 skia::PlatformDevice::InitializeDC(metafile->hdc()); |
140 | 144 |
141 // Calculate the dpi adjustment. | 145 // Calculate the dpi adjustment. |
142 float shrink = static_cast<float>(params.params.desired_dpi / | 146 float shrink = static_cast<float>(params.params.desired_dpi / |
143 params.params.dpi); | 147 params.params.dpi); |
144 | 148 |
145 if (params.pages.empty()) { | 149 if (params.pages.empty()) { |
146 for (int i = 0; i < page_count; ++i) { | 150 for (int i = 0; i < page_count; ++i) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 #endif | 255 #endif |
252 | 256 |
253 skia::VectorPlatformDevice* platform_device = | 257 skia::VectorPlatformDevice* platform_device = |
254 static_cast<skia::VectorPlatformDevice*>(canvas.getDevice()); | 258 static_cast<skia::VectorPlatformDevice*>(canvas.getDevice()); |
255 if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) { | 259 if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) { |
256 // Close the device context to retrieve the compiled metafile. | 260 // Close the device context to retrieve the compiled metafile. |
257 if (!(*metafile)->CloseDc()) | 261 if (!(*metafile)->CloseDc()) |
258 NOTREACHED(); | 262 NOTREACHED(); |
259 | 263 |
260 scoped_ptr<printing::NativeMetafile> metafile2( | 264 scoped_ptr<printing::NativeMetafile> metafile2( |
261 new printing::NativeMetafile); | 265 printing::NativeMetafileFactory::CreateMetafile()); |
262 // Page used alpha blend, but printer doesn't support it. Rewrite the | 266 // Page used alpha blend, but printer doesn't support it. Rewrite the |
263 // metafile and flatten out the transparency. | 267 // metafile and flatten out the transparency. |
264 HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL)); | 268 HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL)); |
265 if (!bitmap_dc) | 269 if (!bitmap_dc) |
266 NOTREACHED() << "Bitmap DC creation failed"; | 270 NOTREACHED() << "Bitmap DC creation failed"; |
267 SetGraphicsMode(bitmap_dc, GM_ADVANCED); | 271 SetGraphicsMode(bitmap_dc, GM_ADVANCED); |
268 void* bits = NULL; | 272 void* bits = NULL; |
269 BITMAPINFO hdr; | 273 BITMAPINFO hdr; |
270 gfx::CreateBitmapHeader(width, height, &hdr.bmiHeader); | 274 gfx::CreateBitmapHeader(width, height, &hdr.bmiHeader); |
271 HBITMAP hbitmap = CreateDIBSection( | 275 HBITMAP hbitmap = CreateDIBSection( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // Copy the bits into shared memory. | 325 // Copy the bits into shared memory. |
322 if (!metafile->GetData(shared_buf.memory(), buf_size)) { | 326 if (!metafile->GetData(shared_buf.memory(), buf_size)) { |
323 NOTREACHED() << "GetData() failed"; | 327 NOTREACHED() << "GetData() failed"; |
324 shared_buf.Unmap(); | 328 shared_buf.Unmap(); |
325 return false; | 329 return false; |
326 } | 330 } |
327 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 331 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
328 shared_buf.Unmap(); | 332 shared_buf.Unmap(); |
329 return true; | 333 return true; |
330 } | 334 } |
OLD | NEW |