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

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

Issue 7065011: Change printing of PDFs for preview on Windows to not rasterize. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 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 | « chrome/renderer/print_web_view_helper_linux.cc ('k') | printing/printing.gyp » ('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/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "chrome/common/print_messages.h" 11 #include "chrome/common/print_messages.h"
12 #include "printing/metafile.h" 12 #include "printing/metafile.h"
13 #include "printing/metafile_impl.h" 13 #include "printing/metafile_impl.h"
14 #include "printing/metafile_skia_wrapper.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_emf_win.h" 17 #include "skia/ext/vector_platform_device_emf_win.h"
18 #include "third_party/skia/include/core/SkRefCnt.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
18 #include "ui/gfx/gdi_util.h" 20 #include "ui/gfx/gdi_util.h"
19 #include "ui/gfx/point.h" 21 #include "ui/gfx/point.h"
20 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
21 #include "ui/gfx/size.h" 23 #include "ui/gfx/size.h"
22 24
23 using printing::ConvertUnit; 25 using printing::ConvertUnit;
24 using printing::ConvertUnitDouble; 26 using printing::ConvertUnitDouble;
25 using printing::kPointsPerInch; 27 using printing::kPointsPerInch;
26 using printing::Metafile; 28 using printing::Metafile;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 for (int i = 0; i < page_count; ++i) { 149 for (int i = 0; i < page_count; ++i) {
148 float scale_factor = shrink; 150 float scale_factor = shrink;
149 RenderPage(print_params, &scale_factor, i, true, frame, &metafile); 151 RenderPage(print_params, &scale_factor, i, true, frame, &metafile);
150 } 152 }
151 } else { 153 } else {
152 for (size_t i = 0; i < params.pages.size(); ++i) { 154 for (size_t i = 0; i < params.pages.size(); ++i) {
153 if (params.pages[i] >= page_count) 155 if (params.pages[i] >= page_count)
154 break; 156 break;
155 float scale_factor = shrink; 157 float scale_factor = shrink;
156 RenderPage(print_params, &scale_factor, 158 RenderPage(print_params, &scale_factor,
157 static_cast<int>(params.pages[i]), true, frame, &metafile); 159 static_cast<int>(params.pages[i]), true, frame, &metafile);
158 } 160 }
159 } 161 }
160 162
163 // Ensure that printing has finished before we start cleaning up and
164 // allocating buffers; this causes prep_frame_view to flush anything pending
165 // into the metafile. Then we can get the final size and copy it into a
166 // shared segment.
167 prep_frame_view.FinishPrinting();
168
169 if (!metafile->FinishDocument())
170 NOTREACHED();
171
161 // Calculate the time taken to render the requested page for preview and add 172 // Calculate the time taken to render the requested page for preview and add
162 // the net time in the histogram. 173 // the net time in the histogram.
163 UMA_HISTOGRAM_TIMES("PrintPreview.RenderTime", 174 UMA_HISTOGRAM_TIMES("PrintPreview.RenderTime",
164 base::TimeTicks::Now() - begin_time); 175 base::TimeTicks::Now() - begin_time);
165 176
166 if (!metafile->FinishDocument())
167 NOTREACHED();
168
169 // Get the size of the compiled metafile. 177 // Get the size of the compiled metafile.
170 uint32 buf_size = metafile->GetDataSize(); 178 uint32 buf_size = metafile->GetDataSize();
171 DCHECK_GT(buf_size, 128u); 179 DCHECK_GT(buf_size, 128u);
172 180
173 PrintHostMsg_DidPreviewDocument_Params preview_params; 181 PrintHostMsg_DidPreviewDocument_Params preview_params;
174 preview_params.data_size = buf_size; 182 preview_params.data_size = buf_size;
175 preview_params.document_cookie = params.params.document_cookie; 183 preview_params.document_cookie = params.params.document_cookie;
176 preview_params.expected_pages_count = page_count; 184 preview_params.expected_pages_count = page_count;
177 preview_params.modifiable = IsModifiable(frame, node); 185 preview_params.modifiable = IsModifiable(frame, node);
178 186
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 } 224 }
217 225
218 gfx::Size page_size(width, height); 226 gfx::Size page_size(width, height);
219 gfx::Rect content_area(static_cast<int>(margin_left_in_points), 227 gfx::Rect content_area(static_cast<int>(margin_left_in_points),
220 static_cast<int>(margin_top_in_points), 228 static_cast<int>(margin_top_in_points),
221 static_cast<int>(content_width_in_points), 229 static_cast<int>(content_width_in_points),
222 static_cast<int>(content_height_in_points)); 230 static_cast<int>(content_height_in_points));
223 skia::PlatformDevice* device = (*metafile)->StartPageForVectorCanvas( 231 skia::PlatformDevice* device = (*metafile)->StartPageForVectorCanvas(
224 page_size, content_area, frame->getPrintPageShrink(page_number)); 232 page_size, content_area, frame->getPrintPageShrink(page_number));
225 DCHECK(device); 233 DCHECK(device);
226 skia::VectorCanvas canvas(device); 234 // The printPage method may take a reference to the canvas we pass down, so it
235 // can't be a stack object.
236 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device);
237 canvas->unref(); // SkRefPtr and new both took a reference.
238 if (is_preview) {
239 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(),
240 metafile->get());
241 }
227 242
228 float webkit_scale_factor = frame->printPage(page_number, &canvas); 243 float webkit_scale_factor = frame->printPage(page_number, canvas.get());
229 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { 244 if (*scale_factor <= 0 || webkit_scale_factor <= 0) {
230 NOTREACHED() << "Printing page " << page_number << " failed."; 245 NOTREACHED() << "Printing page " << page_number << " failed.";
231 } else { 246 } else {
232 // Update the dpi adjustment with the "page |scale_factor|" calculated in 247 // Update the dpi adjustment with the "page |scale_factor|" calculated in
233 // webkit. 248 // webkit.
234 *scale_factor /= webkit_scale_factor; 249 *scale_factor /= webkit_scale_factor;
235 } 250 }
236 251
237 bool result = (*metafile)->FinishPage(); 252 bool result = (*metafile)->FinishPage();
238 DCHECK(result); 253 DCHECK(result);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // Copy the bits into shared memory. 330 // Copy the bits into shared memory.
316 if (!metafile->GetData(shared_buf.memory(), buf_size)) { 331 if (!metafile->GetData(shared_buf.memory(), buf_size)) {
317 NOTREACHED() << "GetData() failed"; 332 NOTREACHED() << "GetData() failed";
318 shared_buf.Unmap(); 333 shared_buf.Unmap();
319 return false; 334 return false;
320 } 335 }
321 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); 336 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
322 shared_buf.Unmap(); 337 shared_buf.Unmap();
323 return true; 338 return true;
324 } 339 }
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper_linux.cc ('k') | printing/printing.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698