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

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

Issue 1520014: Linux: fix printing somewhat.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 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/pdf_ps_metafile_cairo.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) 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 "base/file_descriptor_posix.h" 7 #include "base/file_descriptor_posix.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 "printing/native_metafile.h" 10 #include "printing/native_metafile.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 return; 96 return;
97 97
98 // Tell the browser we've finished writing the file. 98 // Tell the browser we've finished writing the file.
99 Send(new ViewHostMsg_TempFileForPrintingWritten(fd_in_browser)); 99 Send(new ViewHostMsg_TempFileForPrintingWritten(fd_in_browser));
100 } 100 }
101 101
102 void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params, 102 void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
103 const gfx::Size& canvas_size, 103 const gfx::Size& canvas_size,
104 WebFrame* frame, 104 WebFrame* frame,
105 printing::NativeMetafile* metafile) { 105 printing::NativeMetafile* metafile) {
106 // Since WebKit extends the page width depending on the magical shrink 106 cairo_t* cairo_context =
107 // factor we make sure the canvas covers the worst case scenario 107 metafile->StartPage(canvas_size.width(), canvas_size.height());
108 // (x2.0 currently). PrintContext will then set the correct clipping region. 108 if (!cairo_context)
109 int size_x = static_cast<int>(canvas_size.width() * params.params.max_shrink); 109 return;
110 int size_y = static_cast<int>(canvas_size.height() *
111 params.params.max_shrink);
112 // Calculate the dpi adjustment.
113 float shrink = static_cast<float>(canvas_size.width()) /
114 params.params.printable_size.width();
115 110
116 cairo_t* cairo_context = metafile->StartPage(size_x, size_y); 111 skia::VectorCanvas canvas(cairo_context,
117 if (!cairo_context) { 112 canvas_size.width(), canvas_size.height());
118 // TODO(myhuang): We should handle such kind of error further! 113 frame->printPage(params.page_number, &canvas);
119 // We already have had DLOG(ERROR) in NativeMetafile::StartPage(),
120 // log the error here, too?
121 return;
122 }
123
124 skia::VectorCanvas canvas(cairo_context, size_x, size_y);
125 float webkit_shrink = frame->printPage(params.page_number, &canvas);
126 if (webkit_shrink <= 0) {
127 NOTREACHED() << "Printing page " << params.page_number << " failed.";
128 } else {
129 // Update the dpi adjustment with the "page shrink" calculated in webkit.
130 shrink /= webkit_shrink;
131 }
132 114
133 // TODO(myhuang): We should handle transformation for paper margins. 115 // TODO(myhuang): We should handle transformation for paper margins.
134 // TODO(myhuang): We should render the header and the footer. 116 // TODO(myhuang): We should render the header and the footer.
135 117
136 // Done printing. Close the device context to retrieve the compiled metafile. 118 // Done printing. Close the device context to retrieve the compiled metafile.
137 if (!metafile->FinishPage(shrink)) { 119 if (!metafile->FinishPage())
138 NOTREACHED() << "metafile failed"; 120 NOTREACHED() << "metafile failed";
139 }
140 } 121 }
OLDNEW
« no previous file with comments | « no previous file | printing/pdf_ps_metafile_cairo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698