blob: 1cfa1eebfc1e2bf1be7c3ae0fb730629556afcb1 [file] [log] [blame]
thestig@chromium.orgb5cf844c2012-06-18 21:49:201// Copyright (c) 2012 The Chromium Authors. All rights reserved.
stuartmorgan@chromium.orgb75dca82009-10-13 18:46:212// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "printing/printed_document.h"
6
thestig99fc2132017-04-27 03:37:547#import <ApplicationServices/ApplicationServices.h>
8#import <CoreFoundation/CoreFoundation.h>
stuartmorgan@chromium.orgb75dca82009-10-13 18:46:219
10#include "base/logging.h"
rbpotter80cbe042017-12-08 07:00:5211#include "printing/metafile.h"
12#include "printing/printing_context.h"
stuartmorgan@chromium.orgb75dca82009-10-13 18:46:2113
14namespace printing {
15
rbpotter80cbe042017-12-08 07:00:5216bool PrintedDocument::RenderPrintedDocument(PrintingContext* context) {
jhawkins@chromium.org3b52c982010-09-27 20:40:3617 DCHECK(context);
18
Lei Zhang6213e592017-11-20 21:12:1719 const MetafilePlayer* metafile;
rbpotter80cbe042017-12-08 07:00:5220 gfx::Size page_size;
21 gfx::Rect page_content_rect;
Lei Zhang6213e592017-11-20 21:12:1722 {
23 base::AutoLock lock(lock_);
rbpotter80cbe042017-12-08 07:00:5224 metafile = GetMetafile();
25 page_size = mutable_.page_size_;
26 page_content_rect = mutable_.page_content_rect_;
Lei Zhang6213e592017-11-20 21:12:1727 }
28
rbpotter80cbe042017-12-08 07:00:5229 DCHECK(metafile);
Lei Zhang6213e592017-11-20 21:12:1730 const PageSetup& page_setup = immutable_.settings_.page_setup_device_units();
rbpotter80cbe042017-12-08 07:00:5231 gfx::Rect content_area = GetCenteredPageContentRect(
32 page_setup.physical_size(), page_size, page_content_rect);
stuartmorgan@chromium.orgb75dca82009-10-13 18:46:2133
thestig99fc2132017-04-27 03:37:5434 struct Metafile::MacRenderPageParams params;
thestig@chromium.orgb5cf844c2012-06-18 21:49:2035 params.autorotate = true;
rbpotter80cbe042017-12-08 07:00:5236 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)
40 return false;
41 metafile->RenderPage(metafile_page_number, context->context(),
42 content_area.ToCGRect(), params);
43 if (context->PageDone() != PrintingContext::OK)
44 return false;
45 }
46 return true;
jhawkins@chromium.orge0598782010-10-07 22:01:5247}
48
stuartmorgan@chromium.orgb75dca82009-10-13 18:46:2149} // namespace printing