Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Side by Side Diff: chrome/renderer/print_web_view_helper_win.cc

Issue 6696076: Adding CreateFromData to NativeMetafileFactory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebasing Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/print_web_view_helper_mac.mm ('k') | printing/image.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "printing/native_metafile_factory.h" 10 #include "printing/native_metafile_factory.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 } // namespace 67 } // namespace
68 68
69 void PrintWebViewHelper::PrintPage(const PrintMsg_PrintPage_Params& params, 69 void PrintWebViewHelper::PrintPage(const PrintMsg_PrintPage_Params& params,
70 const gfx::Size& canvas_size, 70 const gfx::Size& canvas_size,
71 WebFrame* frame) { 71 WebFrame* frame) {
72 // Generate a memory-based metafile. It will use the current screen's DPI. 72 // Generate a memory-based metafile. It will use the current screen's DPI.
73 // Each metafile contains a single page. 73 // Each metafile contains a single page.
74 scoped_ptr<printing::NativeMetafile> metafile( 74 scoped_ptr<printing::NativeMetafile> metafile(
75 printing::NativeMetafileFactory::Create()); 75 printing::NativeMetafileFactory::Create());
76 metafile->Init();
77 DCHECK(metafile->context()); 76 DCHECK(metafile->context());
78 skia::PlatformDevice::InitializeDC(metafile->context()); 77 skia::PlatformDevice::InitializeDC(metafile->context());
79 78
80 int page_number = params.page_number; 79 int page_number = params.page_number;
81 80
82 // Calculate the dpi adjustment. 81 // Calculate the dpi adjustment.
83 float scale_factor = static_cast<float>(params.params.desired_dpi / 82 float scale_factor = static_cast<float>(params.params.desired_dpi /
84 params.params.dpi); 83 params.params.dpi);
85 84
86 // Render page for printing. 85 // Render page for printing.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 132
134 // NOTE: This is an enhanced-format metafile(EMF) which has an appearance of 133 // NOTE: This is an enhanced-format metafile(EMF) which has an appearance of
135 // single page metafile. For print preview, we need a metafile with multiple 134 // single page metafile. For print preview, we need a metafile with multiple
136 // pages. 135 // pages.
137 // TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia 136 // TODO(kmadhusu): Use a PDF metafile to support multiple pages. After "Skia
138 // PDF backend" work is completed for windows, make changes to replace this 137 // PDF backend" work is completed for windows, make changes to replace this
139 // EMF with PDF metafile. 138 // EMF with PDF metafile.
140 // http://code.google.com/p/chromium/issues/detail?id=62889 139 // http://code.google.com/p/chromium/issues/detail?id=62889
141 scoped_ptr<printing::NativeMetafile> metafile( 140 scoped_ptr<printing::NativeMetafile> metafile(
142 printing::NativeMetafileFactory::Create()); 141 printing::NativeMetafileFactory::Create());
143 metafile->Init();
144 DCHECK(metafile->context()); 142 DCHECK(metafile->context());
145 skia::PlatformDevice::InitializeDC(metafile->context()); 143 skia::PlatformDevice::InitializeDC(metafile->context());
146 144
147 // Calculate the dpi adjustment. 145 // Calculate the dpi adjustment.
148 float shrink = static_cast<float>(params.params.desired_dpi / 146 float shrink = static_cast<float>(params.params.desired_dpi /
149 params.params.dpi); 147 params.params.dpi);
150 148
151 if (params.pages.empty()) { 149 if (params.pages.empty()) {
152 for (int i = 0; i < page_count; ++i) { 150 for (int i = 0; i < page_count; ++i) {
153 float scale_factor = shrink; 151 float scale_factor = shrink;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 HBITMAP hbitmap = CreateDIBSection( 251 HBITMAP hbitmap = CreateDIBSection(
254 bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0); 252 bitmap_dc, &hdr, DIB_RGB_COLORS, &bits, NULL, 0);
255 if (!hbitmap) 253 if (!hbitmap)
256 NOTREACHED() << "Raster bitmap creation for printing failed"; 254 NOTREACHED() << "Raster bitmap creation for printing failed";
257 255
258 HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap); 256 HGDIOBJ old_bitmap = SelectObject(bitmap_dc, hbitmap);
259 RECT rect = {0, 0, width, height }; 257 RECT rect = {0, 0, width, height };
260 HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); 258 HBRUSH whiteBrush = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
261 FillRect(bitmap_dc, &rect, whiteBrush); 259 FillRect(bitmap_dc, &rect, whiteBrush);
262 260
263 metafile2->Init();
264 HDC hdc = metafile2->context(); 261 HDC hdc = metafile2->context();
265 DCHECK(hdc); 262 DCHECK(hdc);
266 skia::PlatformDevice::InitializeDC(hdc); 263 skia::PlatformDevice::InitializeDC(hdc);
267 264
268 RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT(); 265 RECT metafile_bounds = (*metafile)->GetPageBounds(1).ToRECT();
269 // Process the old metafile, placing all non-AlphaBlend calls into the 266 // Process the old metafile, placing all non-AlphaBlend calls into the
270 // new metafile, and copying the results of all the AlphaBlend calls 267 // new metafile, and copying the results of all the AlphaBlend calls
271 // from the bitmap DC. 268 // from the bitmap DC.
272 EnumEnhMetaFile(hdc, 269 EnumEnhMetaFile(hdc,
273 (*metafile)->emf(), 270 (*metafile)->emf(),
(...skipping 29 matching lines...) Expand all
303 // Copy the bits into shared memory. 300 // Copy the bits into shared memory.
304 if (!metafile->GetData(shared_buf.memory(), buf_size)) { 301 if (!metafile->GetData(shared_buf.memory(), buf_size)) {
305 NOTREACHED() << "GetData() failed"; 302 NOTREACHED() << "GetData() failed";
306 shared_buf.Unmap(); 303 shared_buf.Unmap();
307 return false; 304 return false;
308 } 305 }
309 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); 306 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
310 shared_buf.Unmap(); 307 shared_buf.Unmap();
311 return true; 308 return true;
312 } 309 }
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper_mac.mm ('k') | printing/image.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698