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 "chrome/renderer/render_view.h" | 11 #include "chrome/renderer/render_view.h" |
12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
13 #include "printing/native_metafile_factory.h" | |
13 #include "printing/native_metafile.h" | 14 #include "printing/native_metafile.h" |
14 #include "printing/units.h" | 15 #include "printing/units.h" |
15 #include "skia/ext/vector_canvas.h" | 16 #include "skia/ext/vector_canvas.h" |
16 #include "skia/ext/vector_platform_device.h" | 17 #include "skia/ext/vector_platform_device.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
18 #include "ui/gfx/gdi_util.h" | 19 #include "ui/gfx/gdi_util.h" |
19 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
20 | 21 |
21 using printing::ConvertUnitDouble; | 22 using printing::ConvertUnitDouble; |
22 using printing::kPointsPerInch; | 23 using printing::kPointsPerInch; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 PlayEnhMetaFileRecord(dc, handle_table, record, num_objects); | 62 PlayEnhMetaFileRecord(dc, handle_table, record, num_objects); |
62 } | 63 } |
63 return 1; // Continue enumeration | 64 return 1; // Continue enumeration |
64 } | 65 } |
65 | 66 |
66 void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, | 67 void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, |
67 const gfx::Size& canvas_size, | 68 const gfx::Size& canvas_size, |
68 WebFrame* frame) { | 69 WebFrame* frame) { |
69 // 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. |
70 // Each metafile contains a single page. | 71 // Each metafile contains a single page. |
71 scoped_ptr<printing::NativeMetafile> metafile(new printing::NativeMetafile); | 72 scoped_ptr<printing::NativeMetafile> metafile( |
73 printing::NativeMetafileFactory::CreateMetafile()); | |
72 metafile->CreateDc(NULL, NULL); | 74 metafile->CreateDc(NULL, NULL); |
73 DCHECK(metafile->hdc()); | 75 DCHECK(metafile->hdc()); |
74 skia::PlatformDevice::InitializeDC(metafile->hdc()); | 76 skia::PlatformDevice::InitializeDC(metafile->hdc()); |
75 | 77 |
76 int page_number = params.page_number; | 78 int page_number = params.page_number; |
77 | 79 |
78 // Calculate the dpi adjustment. | 80 // Calculate the dpi adjustment. |
79 float scale_factor = static_cast<float>(params.params.desired_dpi / | 81 float scale_factor = static_cast<float>(params.params.desired_dpi / |
80 params.params.dpi); | 82 params.params.dpi); |
81 | 83 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 if (!page_count) | 129 if (!page_count) |
128 return; | 130 return; |
129 | 131 |
130 // 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 |
131 // 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 |
132 // pages. | 134 // pages. |
133 // 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 |
134 // 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 |
135 // EMF with PDF metafile. | 137 // EMF with PDF metafile. |
136 // http://code.google.com/p/chromium/issues/detail?id=62889 | 138 // http://code.google.com/p/chromium/issues/detail?id=62889 |
137 scoped_ptr<printing::NativeMetafile> metafile(new printing::NativeMetafile); | 139 scoped_ptr<printing::NativeMetafile> metafile( |
140 printing::NativeMetafileFactory::CreateMetafile()); | |
vandebo (ex-Chrome)
2011/02/23 02:01:41
indention.
dpapad
2011/02/24 20:56:59
Done.
| |
138 metafile->CreateDc(NULL, NULL); | 141 metafile->CreateDc(NULL, NULL); |
139 DCHECK(metafile->hdc()); | 142 DCHECK(metafile->hdc()); |
140 skia::PlatformDevice::InitializeDC(metafile->hdc()); | 143 skia::PlatformDevice::InitializeDC(metafile->hdc()); |
141 | 144 |
142 // Calculate the dpi adjustment. | 145 // Calculate the dpi adjustment. |
143 float shrink = static_cast<float>(params.params.desired_dpi / | 146 float shrink = static_cast<float>(params.params.desired_dpi / |
144 params.params.dpi); | 147 params.params.dpi); |
145 | 148 |
146 if (params.pages.empty()) { | 149 if (params.pages.empty()) { |
147 for (int i = 0; i < page_count; ++i) { | 150 for (int i = 0; i < page_count; ++i) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 #endif | 253 #endif |
251 | 254 |
252 skia::VectorPlatformDevice* platform_device = | 255 skia::VectorPlatformDevice* platform_device = |
253 static_cast<skia::VectorPlatformDevice*>(canvas.getDevice()); | 256 static_cast<skia::VectorPlatformDevice*>(canvas.getDevice()); |
254 if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) { | 257 if (platform_device->alpha_blend_used() && !params.supports_alpha_blend) { |
255 // Close the device context to retrieve the compiled metafile. | 258 // Close the device context to retrieve the compiled metafile. |
256 if (!(*metafile)->CloseDc()) | 259 if (!(*metafile)->CloseDc()) |
257 NOTREACHED(); | 260 NOTREACHED(); |
258 | 261 |
259 scoped_ptr<printing::NativeMetafile> metafile2( | 262 scoped_ptr<printing::NativeMetafile> metafile2( |
260 new printing::NativeMetafile); | 263 printing::NativeMetafileFactory::CreateMetafile()); |
vandebo (ex-Chrome)
2011/02/23 02:01:41
indention.
dpapad
2011/02/24 20:56:59
Done.
| |
261 // Page used alpha blend, but printer doesn't support it. Rewrite the | 264 // Page used alpha blend, but printer doesn't support it. Rewrite the |
262 // metafile and flatten out the transparency. | 265 // metafile and flatten out the transparency. |
263 HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL)); | 266 HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL)); |
264 if (!bitmap_dc) { | 267 if (!bitmap_dc) { |
265 NOTREACHED() << "Bitmap DC creation failed"; | 268 NOTREACHED() << "Bitmap DC creation failed"; |
266 } | 269 } |
267 SetGraphicsMode(bitmap_dc, GM_ADVANCED); | 270 SetGraphicsMode(bitmap_dc, GM_ADVANCED); |
268 void* bits = NULL; | 271 void* bits = NULL; |
269 BITMAPINFO hdr; | 272 BITMAPINFO hdr; |
270 gfx::CreateBitmapHeader(width, height, &hdr.bmiHeader); | 273 gfx::CreateBitmapHeader(width, height, &hdr.bmiHeader); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 // Copy the bits into shared memory. | 325 // Copy the bits into shared memory. |
323 if (!metafile->GetData(shared_buf.memory(), buf_size)) { | 326 if (!metafile->GetData(shared_buf.memory(), buf_size)) { |
324 NOTREACHED() << "GetData() failed"; | 327 NOTREACHED() << "GetData() failed"; |
325 shared_buf.Unmap(); | 328 shared_buf.Unmap(); |
326 return false; | 329 return false; |
327 } | 330 } |
328 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 331 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
329 shared_buf.Unmap(); | 332 shared_buf.Unmap(); |
330 return true; | 333 return true; |
331 } | 334 } |
OLD | NEW |