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

Side by Side Diff: printing/printed_document_mac.cc

Issue 268036: Implement the basic OS-level printing mechanics on Mac (Closed)
Patch Set: Address review comments Created 11 years, 2 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
« no previous file with comments | « printing/printed_document_linux.cc ('k') | printing/printed_document_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "printing/printed_document.h"
6
7 #import <ApplicationServices/ApplicationServices.h>
8 #import <CoreFoundation/CoreFoundation.h>
9
10 #include "base/logging.h"
11 #include "base/scoped_cftyperef.h"
12 #include "printing/page_number.h"
13 #include "printing/printed_page.h"
14
15 namespace printing {
16
17 void PrintedDocument::RenderPrintedPage(
18 const PrintedPage& page, gfx::NativeDrawingContext context) const {
19 #ifndef NDEBUG
20 {
21 // Make sure the page is from our list.
22 AutoLock lock(lock_);
23 DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get());
24 }
25 #endif
26
27 const printing::NativeMetafile* metafile = page.native_metafile();
28 unsigned int data_length = metafile->GetDataSize();
29 scoped_cftyperef<CFMutableDataRef> pdf_data(
30 CFDataCreateMutable(kCFAllocatorDefault, data_length));
31 CFDataIncreaseLength(pdf_data, data_length);
32 metafile->GetData(CFDataGetMutableBytePtr(pdf_data), data_length);
33 scoped_cftyperef<CGDataProviderRef> pdf_data_provider(
34 CGDataProviderCreateWithCFData(pdf_data));
35 scoped_cftyperef<CGPDFDocumentRef> pdf_doc(
36 CGPDFDocumentCreateWithProvider(pdf_data_provider));
37 if (!pdf_doc.get()) {
38 NOTREACHED() << "Unable to create PDF document from print data";
39 return;
40 }
41
42 const printing::PageSetup& page_setup(
43 immutable_.settings_.page_setup_pixels());
44 CGRect target_rect = page_setup.content_area().ToCGRect();
45
46 // Each NativeMetafile is a one-page PDF.
47 const int page_number = 1;
48 CGContextDrawPDFDocument(context, target_rect, pdf_doc, page_number);
Mark Mentovai 2009/10/13 21:13:24 Deprecated. The replacement is CGContextDrawPDFPa
49
50 // TODO(stuartmorgan): Print the header and footer.
51 }
52
53 } // namespace printing
OLDNEW
« no previous file with comments | « printing/printed_document_linux.cc ('k') | printing/printed_document_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698