| 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/print_messages.h" | 9 #include "chrome/common/print_messages.h" |
| 10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 void PrintWebViewHelper::PrintPage(const PrintMsg_PrintPage_Params& params, | 70 void PrintWebViewHelper::PrintPage(const PrintMsg_PrintPage_Params& params, |
| 71 const gfx::Size& canvas_size, | 71 const gfx::Size& canvas_size, |
| 72 WebFrame* frame) { | 72 WebFrame* frame) { |
| 73 // Generate a memory-based metafile. It will use the current screen's DPI. | 73 // Generate a memory-based metafile. It will use the current screen's DPI. |
| 74 // Each metafile contains a single page. | 74 // Each metafile contains a single page. |
| 75 scoped_ptr<printing::NativeMetafile> metafile( | 75 scoped_ptr<printing::NativeMetafile> metafile( |
| 76 printing::NativeMetafileFactory::Create()); | 76 printing::NativeMetafileFactory::Create()); |
| 77 metafile->Init(); | |
| 78 DCHECK(metafile->context()); | 77 DCHECK(metafile->context()); |
| 79 skia::PlatformDevice::InitializeDC(metafile->context()); | 78 skia::PlatformDevice::InitializeDC(metafile->context()); |
| 80 | 79 |
| 81 int page_number = params.page_number; | 80 int page_number = params.page_number; |
| 82 | 81 |
| 83 // Calculate the dpi adjustment. | 82 // Calculate the dpi adjustment. |
| 84 float scale_factor = static_cast<float>(params.params.desired_dpi / | 83 float scale_factor = static_cast<float>(params.params.desired_dpi / |
| 85 params.params.dpi); | 84 params.params.dpi); |
| 86 | 85 |
| 87 // Render page for printing. | 86 // Render page for printing. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 133 |
| 135 // NOTE: This is an enhanced-format metafile(EMF) which has an appearance of | 134 // NOTE: This is an enhanced-format metafile(EMF) which has an appearance of |
| 136 // single page metafile. For print preview, we need a metafile with multiple | 135 // single page metafile. For print preview, we need a metafile with multiple |
| 137 // pages. | 136 // pages. |
| 138 // TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia | 137 // TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia |
| 139 // PDF backend" work is completed for windows, make changes to replace this | 138 // PDF backend" work is completed for windows, make changes to replace this |
| 140 // EMF with PDF metafile. | 139 // EMF with PDF metafile. |
| 141 // http://code.google.com/p/chromium/issues/detail?id=62889 | 140 // http://code.google.com/p/chromium/issues/detail?id=62889 |
| 142 scoped_ptr<printing::NativeMetafile> metafile( | 141 scoped_ptr<printing::NativeMetafile> metafile( |
| 143 printing::NativeMetafileFactory::Create()); | 142 printing::NativeMetafileFactory::Create()); |
| 144 metafile->Init(); | |
| 145 DCHECK(metafile->context()); | 143 DCHECK(metafile->context()); |
| 146 skia::PlatformDevice::InitializeDC(metafile->context()); | 144 skia::PlatformDevice::InitializeDC(metafile->context()); |
| 147 | 145 |
| 148 // Calculate the dpi adjustment. | 146 // Calculate the dpi adjustment. |
| 149 float shrink = static_cast<float>(params.params.desired_dpi / | 147 float shrink = static_cast<float>(params.params.desired_dpi / |
| 150 params.params.dpi); | 148 params.params.dpi); |
| 151 | 149 |
| 152 if (params.pages.empty()) { | 150 if (params.pages.empty()) { |
| 153 for (int i = 0; i < page_count; ++i) { | 151 for (int i = 0; i < page_count; ++i) { |
| 154 float scale_factor = shrink; | 152 float scale_factor = shrink; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 HBITMAP hbitmap = CreateDIBSection( | 252 HBITMAP hbitmap = CreateDIBSection( |
| 255 bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0); | 253 bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0); |
| 256 if (!hbitmap) | 254 if (!hbitmap) |
| 257 NOTREACHED() << "Raster bitmap creation for printing failed"; | 255 NOTREACHED() << "Raster bitmap creation for printing failed"; |
| 258 | 256 |
| 259 HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap); | 257 HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap); |
| 260 RECT rect = {0, 0, width, height }; | 258 RECT rect = {0, 0, width, height }; |
| 261 HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); | 259 HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); |
| 262 FillRect(bitmap_dc, &rect, whiteBrush); | 260 FillRect(bitmap_dc, &rect, whiteBrush); |
| 263 | 261 |
| 264 metafile2->Init(); | |
| 265 HDC hdc = metafile2->context(); | 262 HDC hdc = metafile2->context(); |
| 266 DCHECK(hdc); | 263 DCHECK(hdc); |
| 267 skia::PlatformDevice::InitializeDC(hdc); | 264 skia::PlatformDevice::InitializeDC(hdc); |
| 268 | 265 |
| 269 RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT(); | 266 RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT(); |
| 270 // Process the old metafile, placing all non-AlphaBlend calls into the | 267 // Process the old metafile, placing all non-AlphaBlend calls into the |
| 271 // new metafile, and copying the results of all the AlphaBlend calls | 268 // new metafile, and copying the results of all the AlphaBlend calls |
| 272 // from the bitmap DC. | 269 // from the bitmap DC. |
| 273 EnumEnhMetaFile(hdc, | 270 EnumEnhMetaFile(hdc, |
| 274 (*metafile)->emf(), | 271 (*metafile)->emf(), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 304 // Copy the bits into shared memory. | 301 // Copy the bits into shared memory. |
| 305 if (!metafile->GetData(shared_buf.memory(), buf_size)) { | 302 if (!metafile->GetData(shared_buf.memory(), buf_size)) { |
| 306 NOTREACHED() << "GetData() failed"; | 303 NOTREACHED() << "GetData() failed"; |
| 307 shared_buf.Unmap(); | 304 shared_buf.Unmap(); |
| 308 return false; | 305 return false; |
| 309 } | 306 } |
| 310 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 307 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
| 311 shared_buf.Unmap(); | 308 shared_buf.Unmap(); |
| 312 return true; | 309 return true; |
| 313 } | 310 } |
| OLD | NEW |