Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
| OLD | NEW |