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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « printing/printed_document_linux.cc ('k') | printing/printed_document_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: printing/printed_document_mac.cc
diff --git a/printing/printed_document_mac.cc b/printing/printed_document_mac.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ace57f3b57fc0a7a15465b6f8aff58bac384e10f
--- /dev/null
+++ b/printing/printed_document_mac.cc
@@ -0,0 +1,53 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "printing/printed_document.h"
+
+#import <ApplicationServices/ApplicationServices.h>
+#import <CoreFoundation/CoreFoundation.h>
+
+#include "base/logging.h"
+#include "base/scoped_cftyperef.h"
+#include "printing/page_number.h"
+#include "printing/printed_page.h"
+
+namespace printing {
+
+void PrintedDocument::RenderPrintedPage(
+ const PrintedPage& page, gfx::NativeDrawingContext context) const {
+#ifndef NDEBUG
+ {
+ // Make sure the page is from our list.
+ AutoLock lock(lock_);
+ DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get());
+ }
+#endif
+
+ const printing::NativeMetafile* metafile = page.native_metafile();
+ unsigned int data_length = metafile->GetDataSize();
+ scoped_cftyperef<CFMutableDataRef> pdf_data(
+ CFDataCreateMutable(kCFAllocatorDefault, data_length));
+ CFDataIncreaseLength(pdf_data, data_length);
+ metafile->GetData(CFDataGetMutableBytePtr(pdf_data), data_length);
+ scoped_cftyperef<CGDataProviderRef> pdf_data_provider(
+ CGDataProviderCreateWithCFData(pdf_data));
+ scoped_cftyperef<CGPDFDocumentRef> pdf_doc(
+ CGPDFDocumentCreateWithProvider(pdf_data_provider));
+ if (!pdf_doc.get()) {
+ NOTREACHED() << "Unable to create PDF document from print data";
+ return;
+ }
+
+ const printing::PageSetup& page_setup(
+ immutable_.settings_.page_setup_pixels());
+ CGRect target_rect = page_setup.content_area().ToCGRect();
+
+ // Each NativeMetafile is a one-page PDF.
+ const int page_number = 1;
+ CGContextDrawPDFDocument(context, target_rect, pdf_doc, page_number);
Mark Mentovai 2009/10/13 21:13:24 Deprecated. The replacement is CGContextDrawPDFPa
+
+ // TODO(stuartmorgan): Print the header and footer.
+}
+
+} // namespace printing
« 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