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 #ifndef PRINTING_PDF_METAFILE_CG_MAC_H_
6 #define PRINTING_PDF_METAFILE_CG_MAC_H_
8 #include <ApplicationServices/ApplicationServices.h>
9 #include <CoreFoundation/CoreFoundation.h>
11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/mac/scoped_cftyperef.h"
14 #include "base/threading/thread_checker.h"
15 #include "printing/metafile.h"
26 // This class creates a graphics context that renders into a PDF data stream.
27 class PRINTING_EXPORT PdfMetafileCg
: public Metafile
{
30 virtual ~PdfMetafileCg();
33 virtual bool Init() OVERRIDE
;
34 virtual bool InitFromData(const void* src_buffer
,
35 uint32 src_buffer_size
) OVERRIDE
;
37 // Not implemented on mac.
38 virtual SkDevice
* StartPageForVectorCanvas(
39 const gfx::Size
& page_size
, const gfx::Rect
& content_area
,
40 const float& scale_factor
) OVERRIDE
;
41 virtual bool StartPage(const gfx::Size
& page_size
,
42 const gfx::Rect
& content_area
,
43 const float& scale_factor
) OVERRIDE
;
44 virtual bool FinishPage() OVERRIDE
;
45 virtual bool FinishDocument() OVERRIDE
;
47 virtual uint32
GetDataSize() const OVERRIDE
;
48 virtual bool GetData(void* dst_buffer
, uint32 dst_buffer_size
) const OVERRIDE
;
50 // For testing purposes only.
51 virtual bool SaveTo(const FilePath
& file_path
) const OVERRIDE
;
53 virtual gfx::Rect
GetPageBounds(unsigned int page_number
) const OVERRIDE
;
54 virtual unsigned int GetPageCount() const OVERRIDE
;
56 // Note: The returned context *must not be retained* past Close(). If it is,
57 // the data returned from GetData will not be valid PDF data.
58 virtual CGContextRef
context() const OVERRIDE
;
60 virtual bool RenderPage(unsigned int page_number
,
61 gfx::NativeDrawingContext context
,
63 const MacRenderPageParams
& params
) const OVERRIDE
;
66 // Returns a CGPDFDocumentRef version of pdf_data_.
67 CGPDFDocumentRef
GetPDFDocument() const;
69 base::ThreadChecker thread_checker_
;
71 // Context for rendering to the pdf.
72 base::mac::ScopedCFTypeRef
<CGContextRef
> context_
;
75 base::mac::ScopedCFTypeRef
<CFMutableDataRef
> pdf_data_
;
77 // Lazily-created CGPDFDocument representation of pdf_data_.
78 mutable base::mac::ScopedCFTypeRef
<CGPDFDocumentRef
> pdf_doc_
;
80 // Whether or not a page is currently open.
83 // Whether this instantiation of the PdfMetafileCg owns the thread_pdf_docs.
84 bool thread_pdf_docs_owned_
;
86 DISALLOW_COPY_AND_ASSIGN(PdfMetafileCg
);
89 } // namespace printing
91 #endif // PRINTING_PDF_METAFILE_CG_MAC_H_