1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "printing/printed_document.h"
7 #import <ApplicationServices/ApplicationServices.h>
8 #import <CoreFoundation/CoreFoundation.h>
10 #include "base/logging.h"
11 #include "printing/metafile.h"
12 #include "printing/printing_context.h"
16 bool PrintedDocument::RenderPrintedDocument(PrintingContext* context) {
19 const MetafilePlayer* metafile;
21 gfx::Rect page_content_rect;
23 base::AutoLock lock(lock_);
24 metafile = GetMetafile();
25 page_size = mutable_.page_size_;
26 page_content_rect = mutable_.page_content_rect_;
30 const PageSetup& page_setup = immutable_.settings_.page_setup_device_units();
31 gfx::Rect content_area = GetCenteredPageContentRect(
32 page_setup.physical_size(), page_size, page_content_rect);
34 struct Metafile::MacRenderPageParams params;
35 params.autorotate = true;
36 size_t num_pages = expected_page_count();
37 for (size_t metafile_page_number = 1; metafile_page_number <= num_pages;
38 metafile_page_number++) {
39 if (context->NewPage() != PrintingContext::OK)
41 metafile->RenderPage(metafile_page_number, context->context(),
42 content_area.ToCGRect(), params);
43 if (context->PageDone() != PrintingContext::OK)
49 } // namespace printing