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

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

Issue 10387022: A better fix for scaling issue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 | « no previous file | printing/custom_scaling.h » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
11 #include "base/win/scoped_gdi_object.h" 11 #include "base/win/scoped_gdi_object.h"
12 #include "base/win/scoped_hdc.h" 12 #include "base/win/scoped_hdc.h"
13 #include "base/win/scoped_select_object.h" 13 #include "base/win/scoped_select_object.h"
14 #include "chrome/common/print_messages.h" 14 #include "chrome/common/print_messages.h"
15 #include "printing/custom_scaling.h"
16 #include "printing/metafile.h" 15 #include "printing/metafile.h"
17 #include "printing/metafile_impl.h" 16 #include "printing/metafile_impl.h"
18 #include "printing/metafile_skia_wrapper.h" 17 #include "printing/metafile_skia_wrapper.h"
19 #include "printing/page_size_margins.h" 18 #include "printing/page_size_margins.h"
20 #include "printing/units.h" 19 #include "printing/units.h"
21 #include "skia/ext/vector_canvas.h" 20 #include "skia/ext/vector_canvas.h"
22 #include "skia/ext/platform_device.h" 21 #include "skia/ext/platform_device.h"
23 #include "third_party/skia/include/core/SkRefCnt.h" 22 #include "third_party/skia/include/core/SkRefCnt.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
25 #include "ui/gfx/gdi_util.h" 24 #include "ui/gfx/gdi_util.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 110
112 // Calculate the dpi adjustment. 111 // Calculate the dpi adjustment.
113 // Browser will render context using desired_dpi, so we need to calculate 112 // Browser will render context using desired_dpi, so we need to calculate
114 // adjustment factor to play content on the printer DC later during the 113 // adjustment factor to play content on the printer DC later during the
115 // actual printing. 114 // actual printing.
116 double actual_shrink = static_cast<float>(params.params.desired_dpi / 115 double actual_shrink = static_cast<float>(params.params.desired_dpi /
117 params.params.dpi); 116 params.params.dpi);
118 gfx::Size page_size_in_dpi; 117 gfx::Size page_size_in_dpi;
119 gfx::Rect content_area_in_dpi; 118 gfx::Rect content_area_in_dpi;
120 119
121 // If we are printing PDF, it may not fit into metafile using 72dpi.
122 // (Metafile is based on screen resolution here.)
123 // (See http://code.google.com/p/chromium-os/issues/detail?id=16088)
124 // If PDF plugin encounter this issue it will save custom scale in TLS,
125 // so we can apply the same scaling factor here.
126 // If will do so ONLY if default scaling does not work.
127 // TODO(gene): We should revisit this solution for the next versions.
vandebo (ex-Chrome) 2012/05/08 18:25:01 It might be good to leave this TODO. Making the s
gene 2012/05/08 18:34:52 Done. Moved next to the code where we retrieve sca
128 // Two possible solutions:
129 // We can create metafile of the right size (or resizable)
130 // https://code.google.com/p/chromium/issues/detail?id=126037
131 // or
132 // We should return scale factor all the way from the plugin:
133 // webkit::ppapi::PluginInstance::PrintPDFOutput - scale calculated here
134 // webkit::ppapi::PluginInstance::PrintPageHelper
135 // webkit::ppapi::PluginInstance::PrintPage
136 // webkit::ppapi::WebPluginImpl::printPage
137 // WebKit::WebPluginContainerImpl::printPage
138 // WebKit::ChromePluginPrintContext::spoolPage - always return 1.0 scale
139 // WebKit::WebFrameImpl::printPage
140 // PrintWebViewHelper::RenderPage
141 // PrintWebViewHelper::PrintPageInternal
142
143 printing::ClearCustomPrintingPageScale();
144
145 // Render page for printing. 120 // Render page for printing.
146 metafile.reset(RenderPage(params.params, page_number, frame, false, 121 metafile.reset(RenderPage(params.params, page_number, frame, false,
147 metafile.get(), &actual_shrink, &page_size_in_dpi, 122 metafile.get(), &actual_shrink, &page_size_in_dpi,
148 &content_area_in_dpi)); 123 &content_area_in_dpi));
149 124
150 double custom_scale;
151 if (printing::GetCustomPrintingPageScale(&custom_scale)) {
152 actual_shrink = custom_scale;
153 printing::ClearCustomPrintingPageScale();
154 }
155
156 // Close the device context to retrieve the compiled metafile. 125 // Close the device context to retrieve the compiled metafile.
157 if (!metafile->FinishDocument()) 126 if (!metafile->FinishDocument())
158 NOTREACHED(); 127 NOTREACHED();
159 128
160 // Get the size of the compiled metafile. 129 // Get the size of the compiled metafile.
161 uint32 buf_size = metafile->GetDataSize(); 130 uint32 buf_size = metafile->GetDataSize();
162 DCHECK_GT(buf_size, 128u); 131 DCHECK_GT(buf_size, 128u);
163 132
164 PrintHostMsg_DidPrintPage_Params page_params; 133 PrintHostMsg_DidPrintPage_Params page_params;
165 page_params.data_size = buf_size; 134 page_params.data_size = buf_size;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 PrintHeaderAndFooter(canvas.get(), page_number + 1, 248 PrintHeaderAndFooter(canvas.get(), page_number + 1,
280 print_preview_context_.total_page_count(), 249 print_preview_context_.total_page_count(),
281 css_scale_factor * webkit_page_shrink_factor, 250 css_scale_factor * webkit_page_shrink_factor,
282 page_layout_in_points, 251 page_layout_in_points,
283 *header_footer_info_); 252 *header_footer_info_);
284 } 253 }
285 254
286 if (*actual_shrink <= 0 || webkit_scale_factor <= 0) { 255 if (*actual_shrink <= 0 || webkit_scale_factor <= 0) {
287 NOTREACHED() << "Printing page " << page_number << " failed."; 256 NOTREACHED() << "Printing page " << page_number << " failed.";
288 } else { 257 } else {
289 // Update the dpi adjustment with the "page |actual_shrink|" calculated in 258 // While rendering certain plugins (PDF) to metafile, we might need to
290 // webkit. 259 // set custom scale factor. Update |actual_shrink| with custom scale
291 *actual_shrink /= (webkit_scale_factor * css_scale_factor); 260 // if it is set on canvas.
261 if (!printing::MetafileSkiaWrapper::GetCustomScaleOnCanvas(*canvas,
262 actual_shrink)) {
vandebo (ex-Chrome) 2012/05/08 18:25:01 nit: argument alignment
gene 2012/05/08 18:34:52 Moved both on the next line. Aligning |actual_shri
263 // Update the dpi adjustment with the "page |actual_shrink|" calculated in
264 // webkit.
265 *actual_shrink /= (webkit_scale_factor * css_scale_factor);
266 }
292 } 267 }
293 268
294 bool result = metafile->FinishPage(); 269 bool result = metafile->FinishPage();
295 DCHECK(result); 270 DCHECK(result);
296 271
297 if (!params.supports_alpha_blend) { 272 if (!params.supports_alpha_blend) {
298 // PreviewMetafile (PDF) supports alpha blend, so we only hit this case 273 // PreviewMetafile (PDF) supports alpha blend, so we only hit this case
299 // for NativeMetafile. 274 // for NativeMetafile.
300 DCHECK(!is_preview); 275 DCHECK(!is_preview);
301 skia::PlatformDevice* platform_device = skia::GetPlatformDevice(device); 276 skia::PlatformDevice* platform_device = skia::GetPlatformDevice(device);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 shared_buf.Unmap(); 349 shared_buf.Unmap();
375 return false; 350 return false;
376 } 351 }
377 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); 352 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
378 shared_buf.Unmap(); 353 shared_buf.Unmap();
379 354
380 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, 355 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle,
381 shared_mem_handle)); 356 shared_mem_handle));
382 return true; 357 return true;
383 } 358 }
OLDNEW
« no previous file with comments | « no previous file | printing/custom_scaling.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698