OLD | NEW |
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 "printing/printed_document.h" | 5 #include "printing/printed_document.h" |
6 | 6 |
7 #import <ApplicationServices/ApplicationServices.h> | 7 #import <ApplicationServices/ApplicationServices.h> |
8 #import <CoreFoundation/CoreFoundation.h> | 8 #import <CoreFoundation/CoreFoundation.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/scoped_cftyperef.h" | 11 #include "base/scoped_cftyperef.h" |
12 #include "printing/page_number.h" | 12 #include "printing/page_number.h" |
13 #include "printing/printed_page.h" | 13 #include "printing/printed_page.h" |
14 | 14 |
15 namespace printing { | 15 namespace printing { |
16 | 16 |
17 void PrintedDocument::RenderPrintedPage( | 17 void PrintedDocument::RenderPrintedPage( |
18 const PrintedPage& page, gfx::NativeDrawingContext context) const { | 18 const PrintedPage& page, gfx::NativeDrawingContext context) const { |
19 #ifndef NDEBUG | 19 #ifndef NDEBUG |
20 { | 20 { |
21 // Make sure the page is from our list. | 21 // Make sure the page is from our list. |
22 AutoLock lock(lock_); | 22 AutoLock lock(lock_); |
23 DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get()); | 23 DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get()); |
24 } | 24 } |
25 #endif | 25 #endif |
26 | 26 |
27 const printing::PageSetup& page_setup( | 27 const printing::PageSetup& page_setup( |
28 immutable_.settings_.page_setup_device_units()); | 28 immutable_.settings_.page_setup_device_units()); |
29 gfx::Rect target_rect = page.page_content_rect(); | 29 gfx::Rect content_area; |
30 const gfx::Rect& physical_size = page_setup.physical_size(); | 30 page.GetCenteredPageContentRect(page_setup.physical_size(), &content_area); |
31 // http://dev.w3.org/csswg/css3-page/#positioning-page-box | |
32 if (physical_size.width() > page.page_size().width()) { | |
33 int diff = physical_size.width() - page.page_size().width(); | |
34 target_rect.set_x(target_rect.x() + diff / 2); | |
35 } | |
36 if (physical_size.height() > page.page_size().height()) { | |
37 int diff = physical_size.height() - page.page_size().height(); | |
38 target_rect.set_y(target_rect.y() + diff / 2); | |
39 } | |
40 | 31 |
41 const printing::NativeMetafile* metafile = page.native_metafile(); | 32 const printing::NativeMetafile* metafile = page.native_metafile(); |
42 // Each NativeMetafile is a one-page PDF, and pages use 1-based indexing. | 33 // Each NativeMetafile is a one-page PDF, and pages use 1-based indexing. |
43 const int page_number = 1; | 34 const int page_number = 1; |
44 metafile->RenderPage(page_number, context, target_rect.ToCGRect(), | 35 metafile->RenderPage(page_number, context, content_area.ToCGRect(), |
45 true, false, false, false); | 36 true, false, false, false); |
46 | 37 |
47 // TODO(stuartmorgan): Print the header and footer. | 38 // TODO(stuartmorgan): Print the header and footer. |
48 } | 39 } |
49 | 40 |
50 } // namespace printing | 41 } // namespace printing |
OLD | NEW |