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

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: Nits 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
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.
Lei Zhang 2011/05/24 00:24:16 please just make this comment a bit clearer.
vandebo (ex-Chrome) 2011/05/24 05:48:38 Done.
165 prep_frame_view.FinishPrinting();
166
167 if (!metafile->FinishDocument())
168 NOTREACHED();
169
161 // Calculate the time taken to render the requested page for preview and add 170 // Calculate the time taken to render the requested page for preview and add
162 // the net time in the histogram. 171 // the net time in the histogram.
163 UMA_HISTOGRAM_TIMES("PrintPreview.RenderTime", 172 UMA_HISTOGRAM_TIMES("PrintPreview.RenderTime",
164 base::TimeTicks::Now() - begin_time); 173 base::TimeTicks::Now() - begin_time);
165 174
166 if (!metafile->FinishDocument())
167 NOTREACHED();
168
169 // Get the size of the compiled metafile. 175 // Get the size of the compiled metafile.
170 uint32 buf_size = metafile->GetDataSize(); 176 uint32 buf_size = metafile->GetDataSize();
171 DCHECK_GT(buf_size, 128u); 177 DCHECK_GT(buf_size, 128u);
172 178
173 PrintHostMsg_DidPreviewDocument_Params preview_params; 179 PrintHostMsg_DidPreviewDocument_Params preview_params;
174 preview_params.data_size = buf_size; 180 preview_params.data_size = buf_size;
175 preview_params.document_cookie = params.params.document_cookie; 181 preview_params.document_cookie = params.params.document_cookie;
176 preview_params.expected_pages_count = page_count; 182 preview_params.expected_pages_count = page_count;
177 preview_params.modifiable = IsModifiable(frame, node); 183 preview_params.modifiable = IsModifiable(frame, node);
178 184
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 } 222 }
217 223
218 gfx::Size page_size(width, height); 224 gfx::Size page_size(width, height);
219 gfx::Rect content_area(static_cast<int>(margin_left_in_points), 225 gfx::Rect content_area(static_cast<int>(margin_left_in_points),
220 static_cast<int>(margin_top_in_points), 226 static_cast<int>(margin_top_in_points),
221 static_cast<int>(content_width_in_points), 227 static_cast<int>(content_width_in_points),
222 static_cast<int>(content_height_in_points)); 228 static_cast<int>(content_height_in_points));
223 skia::PlatformDevice* device = (*metafile)->StartPageForVectorCanvas( 229 skia::PlatformDevice* device = (*metafile)->StartPageForVectorCanvas(
224 page_size, content_area, frame->getPrintPageShrink(page_number)); 230 page_size, content_area, frame->getPrintPageShrink(page_number));
225 DCHECK(device); 231 DCHECK(device);
226 skia::VectorCanvas canvas(device); 232 // The printPage method may take a reference to the canvas we pass down, so it
233 // can't be a stack object.
234 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device);
235 canvas->unref(); // SkRefPtr and new both took a reference.
236 if (is_preview) {
237 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(),
238 metafile->get());
239 }
227 240
228 float webkit_scale_factor = frame->printPage(page_number, &canvas); 241 float webkit_scale_factor = frame->printPage(page_number, canvas.get());
229 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { 242 if (*scale_factor <= 0 || webkit_scale_factor <= 0) {
230 NOTREACHED() << "Printing page " << page_number << " failed."; 243 NOTREACHED() << "Printing page " << page_number << " failed.";
231 } else { 244 } else {
232 // Update the dpi adjustment with the "page |scale_factor|" calculated in 245 // Update the dpi adjustment with the "page |scale_factor|" calculated in
233 // webkit. 246 // webkit.
234 *scale_factor /= webkit_scale_factor; 247 *scale_factor /= webkit_scale_factor;
235 } 248 }
236 249
237 bool result = (*metafile)->FinishPage(); 250 bool result = (*metafile)->FinishPage();
238 DCHECK(result); 251 DCHECK(result);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // Copy the bits into shared memory. 328 // Copy the bits into shared memory.
316 if (!metafile->GetData(shared_buf.memory(), buf_size)) { 329 if (!metafile->GetData(shared_buf.memory(), buf_size)) {
317 NOTREACHED() << "GetData() failed"; 330 NOTREACHED() << "GetData() failed";
318 shared_buf.Unmap(); 331 shared_buf.Unmap();
319 return false; 332 return false;
320 } 333 }
321 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); 334 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle);
322 shared_buf.Unmap(); 335 shared_buf.Unmap();
323 return true; 336 return true;
324 } 337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698