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

Side by Side Diff: printing/printed_document_win.cc

Issue 6673035: Move Start/EndPage() from NewPage/PageDone() to inside the metafile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 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 "printing/printed_document.h" 5 #include "printing/printed_document.h"
6 6
7 #include <winspool.h>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "base/string_util.h" 10 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
10 #include "printing/page_number.h" 12 #include "printing/page_number.h"
11 #include "printing/page_overlays.h" 13 #include "printing/page_overlays.h"
12 #include "printing/printed_pages_source.h" 14 #include "printing/printed_pages_source.h"
13 #include "printing/printed_page.h" 15 #include "printing/printed_page.h"
14 #include "printing/units.h" 16 #include "printing/units.h"
15 #include "skia/ext/platform_device.h" 17 #include "skia/ext/platform_device.h"
16 #include "ui/gfx/font.h" 18 #include "ui/gfx/font.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 GetDateFormat(LOCALE_USER_DEFAULT, NULL, &date, format_ptr, 72 GetDateFormat(LOCALE_USER_DEFAULT, NULL, &date, format_ptr,
71 WriteInto(&output, buffer_size), buffer_size); 73 WriteInto(&output, buffer_size), buffer_size);
72 74
73 return output; 75 return output;
74 } 76 }
75 77
76 } // namespace 78 } // namespace
77 79
78 namespace printing { 80 namespace printing {
79 81
80 void PrintedDocument::RenderPrintedPage( 82 bool PrintedDocument::RenderPrintedPage(
81 const PrintedPage& page, gfx::NativeDrawingContext context) const { 83 const PrintedPage& page, gfx::NativeDrawingContext context) const {
82 #ifndef NDEBUG 84 #ifndef NDEBUG
83 { 85 {
84 // Make sure the page is from our list. 86 // Make sure the page is from our list.
85 base::AutoLock lock(lock_); 87 base::AutoLock lock(lock_);
86 DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get()); 88 DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get());
87 } 89 }
88 #endif 90 #endif
89 91
90 DCHECK(context); 92 DCHECK(context);
91 93
92 const printing::PageSetup& page_setup( 94 const printing::PageSetup& page_setup(
93 immutable_.settings_.page_setup_device_units()); 95 immutable_.settings_.page_setup_device_units());
94 gfx::Rect content_area; 96 gfx::Rect content_area;
95 page.GetCenteredPageContentRect(page_setup.physical_size(), &content_area); 97 page.GetCenteredPageContentRect(page_setup.physical_size(), &content_area);
96 98
99 // Inform the driver that the application is about to begin sending data.
100 if (StartPage(context) <= 0)
vandebo (ex-Chrome) 2011/03/15 17:23:06 We wanted to move this to PrintWebViewHelper::Rend
dpapad 2011/03/15 20:32:32 Done.
101 return false;
102
97 // Save the state to make sure the context this function call does not modify 103 // Save the state to make sure the context this function call does not modify
98 // the device context. 104 // the device context.
99 int saved_state = SaveDC(context); 105 int saved_state = SaveDC(context);
100 DCHECK_NE(saved_state, 0); 106 DCHECK_NE(saved_state, 0);
101 skia::PlatformDevice::InitializeDC(context); 107 skia::PlatformDevice::InitializeDC(context);
102 { 108 {
103 // Save the state (again) to apply the necessary world transformation. 109 // Save the state (again) to apply the necessary world transformation.
104 int saved_state = SaveDC(context); 110 int saved_state = SaveDC(context);
105 DCHECK_NE(saved_state, 0); 111 DCHECK_NE(saved_state, 0);
106 112
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 PrintHeaderFooter(context, page, PageOverlays::RIGHT, PageOverlays::TOP, 152 PrintHeaderFooter(context, page, PageOverlays::RIGHT, PageOverlays::TOP,
147 font); 153 font);
148 PrintHeaderFooter(context, page, PageOverlays::LEFT, PageOverlays::BOTTOM, 154 PrintHeaderFooter(context, page, PageOverlays::LEFT, PageOverlays::BOTTOM,
149 font); 155 font);
150 PrintHeaderFooter(context, page, PageOverlays::CENTER, PageOverlays::BOTTOM, 156 PrintHeaderFooter(context, page, PageOverlays::CENTER, PageOverlays::BOTTOM,
151 font); 157 font);
152 PrintHeaderFooter(context, page, PageOverlays::RIGHT, PageOverlays::BOTTOM, 158 PrintHeaderFooter(context, page, PageOverlays::RIGHT, PageOverlays::BOTTOM,
153 font); 159 font);
154 int res = RestoreDC(context, saved_state); 160 int res = RestoreDC(context, saved_state);
155 DCHECK_NE(res, 0); 161 DCHECK_NE(res, 0);
162
163 if (EndPage(context) <= 0)
164 return false;
165 return true;
156 } 166 }
157 167
158 void PrintedDocument::Immutable::SetDocumentDate() { 168 void PrintedDocument::Immutable::SetDocumentDate() {
159 // Use the native time formatting for printing on Windows. 169 // Use the native time formatting for printing on Windows.
160 SYSTEMTIME systemtime; 170 SYSTEMTIME systemtime;
161 GetLocalTime(&systemtime); 171 GetLocalTime(&systemtime);
162 date_ = 172 date_ =
163 WideToUTF16Hack(FormatSystemDate(systemtime, std::wstring())); 173 WideToUTF16Hack(FormatSystemDate(systemtime, std::wstring()));
164 time_ = 174 time_ =
165 WideToUTF16Hack(FormatSystemTime(systemtime, std::wstring())); 175 WideToUTF16Hack(FormatSystemTime(systemtime, std::wstring()));
(...skipping 11 matching lines...) Expand all
177 DCHECK(result == SIMPLEREGION || result == COMPLEXREGION); 187 DCHECK(result == SIMPLEREGION || result == COMPLEXREGION);
178 TextOut(context, 188 TextOut(context,
179 bounds.x(), bounds.y(), 189 bounds.x(), bounds.y(),
180 text.c_str(), 190 text.c_str(),
181 static_cast<int>(text.size())); 191 static_cast<int>(text.size()));
182 int res = RestoreDC(context, saved_state); 192 int res = RestoreDC(context, saved_state);
183 DCHECK_NE(res, 0); 193 DCHECK_NE(res, 0);
184 } 194 }
185 195
186 } // namespace printing 196 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698