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