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

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

Issue 2859040: Implement limited paged media support for win. (Closed)
Patch Set: the comment fix Created 10 years, 5 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
« no previous file with comments | « chrome/renderer/print_web_view_helper.cc ('k') | printing/page_overlays_unittest.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/common/render_messages.h" 9 #include "chrome/common/render_messages.h"
10 #include "chrome/renderer/render_view.h" 10 #include "chrome/renderer/render_view.h"
11 #include "gfx/size.h" 11 #include "gfx/size.h"
12 #include "grit/generated_resources.h" 12 #include "grit/generated_resources.h"
13 #include "printing/native_metafile.h" 13 #include "printing/native_metafile.h"
14 #include "printing/units.h"
14 #include "skia/ext/vector_canvas.h" 15 #include "skia/ext/vector_canvas.h"
15 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" 16 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
16 17
18 using printing::ConvertUnitDouble;
19 using printing::kPointsPerInch;
17 using WebKit::WebFrame; 20 using WebKit::WebFrame;
18 using WebKit::WebString; 21 using WebKit::WebString;
19 22
20 void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, 23 void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
21 const gfx::Size& canvas_size, 24 const gfx::Size& canvas_size,
22 WebFrame* frame) { 25 WebFrame* frame) {
23 // Generate a memory-based metafile. It will use the current screen's DPI. 26 // Generate a memory-based metafile. It will use the current screen's DPI.
24 printing::NativeMetafile metafile; 27 printing::NativeMetafile metafile;
25 28
26 metafile.CreateDc(NULL, NULL); 29 metafile.CreateDc(NULL, NULL);
27 HDC hdc = metafile.hdc(); 30 HDC hdc = metafile.hdc();
28 DCHECK(hdc); 31 DCHECK(hdc);
29 skia::PlatformDevice::InitializeDC(hdc); 32 skia::PlatformDevice::InitializeDC(hdc);
33
34 double content_width_in_points;
35 double content_height_in_points;
36 double margin_top_in_points;
37 double margin_right_in_points;
38 double margin_bottom_in_points;
39 double margin_left_in_points;
40 GetPageSizeAndMarginsInPoints(frame,
41 params.page_number,
42 params.params,
43 &content_width_in_points,
44 &content_height_in_points,
45 &margin_top_in_points,
46 &margin_right_in_points,
47 &margin_bottom_in_points,
48 &margin_left_in_points);
49
30 // Since WebKit extends the page width depending on the magical shrink 50 // Since WebKit extends the page width depending on the magical shrink
31 // factor we make sure the canvas covers the worst case scenario 51 // factor we make sure the canvas covers the worst case scenario
32 // (x2.0 currently). PrintContext will then set the correct clipping region. 52 // (x2.0 currently). PrintContext will then set the correct clipping region.
33 int size_x = static_cast<int>(canvas_size.width() * params.params.max_shrink); 53 int size_x = static_cast<int>(content_width_in_points *
34 int size_y = static_cast<int>(canvas_size.height() * 54 params.params.max_shrink);
35 params.params.max_shrink); 55 int size_y = static_cast<int>(content_height_in_points *
56 params.params.max_shrink);
36 // Calculate the dpi adjustment. 57 // Calculate the dpi adjustment.
37 float shrink = static_cast<float>(canvas_size.width()) / 58 float shrink = static_cast<float>(canvas_size.width()) /
38 params.params.printable_size.width(); 59 params.params.printable_size.width();
39 #if 0 60 #if 0
40 // TODO(maruel): This code is kept for testing until the 100% GDI drawing 61 // TODO(maruel): This code is kept for testing until the 100% GDI drawing
41 // code is stable. maruels use this code's output as a reference when the 62 // code is stable. maruels use this code's output as a reference when the
42 // GDI drawing code fails. 63 // GDI drawing code fails.
43 64
44 // Mix of Skia and GDI based. 65 // Mix of Skia and GDI based.
45 skia::PlatformCanvas canvas(size_x, size_y, true); 66 skia::PlatformCanvas canvas(size_x, size_y, true);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 108
88 // Get the size of the compiled metafile. 109 // Get the size of the compiled metafile.
89 uint32 buf_size = metafile.GetDataSize(); 110 uint32 buf_size = metafile.GetDataSize();
90 DCHECK_GT(buf_size, 128u); 111 DCHECK_GT(buf_size, 128u);
91 ViewHostMsg_DidPrintPage_Params page_params; 112 ViewHostMsg_DidPrintPage_Params page_params;
92 page_params.data_size = 0; 113 page_params.data_size = 0;
93 page_params.metafile_data_handle = NULL; 114 page_params.metafile_data_handle = NULL;
94 page_params.page_number = params.page_number; 115 page_params.page_number = params.page_number;
95 page_params.document_cookie = params.params.document_cookie; 116 page_params.document_cookie = params.params.document_cookie;
96 page_params.actual_shrink = shrink; 117 page_params.actual_shrink = shrink;
118 page_params.page_size = gfx::Size(
119 static_cast<int>(ConvertUnitDouble(
120 content_width_in_points +
121 margin_left_in_points + margin_right_in_points,
122 kPointsPerInch, params.params.dpi)),
123 static_cast<int>(ConvertUnitDouble(
124 content_height_in_points +
125 margin_top_in_points + margin_bottom_in_points,
126 kPointsPerInch, params.params.dpi)));
127 page_params.content_area = gfx::Rect(
128 static_cast<int>(ConvertUnitDouble(
129 margin_left_in_points, kPointsPerInch, params.params.dpi)),
130 static_cast<int>(ConvertUnitDouble(
131 margin_top_in_points, kPointsPerInch, params.params.dpi)),
132 static_cast<int>(ConvertUnitDouble(
133 content_width_in_points, kPointsPerInch, params.params.dpi)),
134 static_cast<int>(ConvertUnitDouble(
135 content_height_in_points, kPointsPerInch, params.params.dpi)));
136 page_params.has_visible_overlays =
137 frame->isPageBoxVisible(params.page_number);
97 base::SharedMemory shared_buf; 138 base::SharedMemory shared_buf;
98 139
99 // http://msdn2.microsoft.com/en-us/library/ms535522.aspx 140 // http://msdn2.microsoft.com/en-us/library/ms535522.aspx
100 // Windows 2000/XP: When a page in a spooled file exceeds approximately 350 141 // Windows 2000/XP: When a page in a spooled file exceeds approximately 350
101 // MB, it can fail to print and not send an error message. 142 // MB, it can fail to print and not send an error message.
102 if (buf_size < 350*1024*1024) { 143 if (buf_size < 350*1024*1024) {
103 // Allocate a shared memory buffer to hold the generated metafile data. 144 // Allocate a shared memory buffer to hold the generated metafile data.
104 if (shared_buf.Create(L"", false, false, buf_size) && 145 if (shared_buf.Create(L"", false, false, buf_size) &&
105 shared_buf.Map(buf_size)) { 146 shared_buf.Map(buf_size)) {
106 // Copy the bits into shared memory. 147 // Copy the bits into shared memory.
(...skipping 11 matching lines...) Expand all
118 NOTREACHED() << "Buffer too large: " << buf_size; 159 NOTREACHED() << "Buffer too large: " << buf_size;
119 } 160 }
120 metafile.CloseEmf(); 161 metafile.CloseEmf();
121 if (Send(new ViewHostMsg_DuplicateSection( 162 if (Send(new ViewHostMsg_DuplicateSection(
122 routing_id(), 163 routing_id(),
123 page_params.metafile_data_handle, 164 page_params.metafile_data_handle,
124 &page_params.metafile_data_handle))) { 165 &page_params.metafile_data_handle))) {
125 Send(new ViewHostMsg_DidPrintPage(routing_id(), page_params)); 166 Send(new ViewHostMsg_DidPrintPage(routing_id(), page_params));
126 } 167 }
127 } 168 }
128
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper.cc ('k') | printing/page_overlays_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698