Upload upstream chromium 67.0.3396
[platform/framework/web/chromium-efl.git] / printing / pdf_metafile_cg_mac.h
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.
4
5 #ifndef PRINTING_PDF_METAFILE_CG_MAC_H_
6 #define PRINTING_PDF_METAFILE_CG_MAC_H_
7
8 #include <ApplicationServices/ApplicationServices.h>
9 #include <CoreFoundation/CoreFoundation.h>
10 #include <stdint.h>
11
12 #include "base/mac/scoped_cftyperef.h"
13 #include "base/macros.h"
14 #include "printing/metafile.h"
15
16 namespace gfx {
17 class Rect;
18 class Size;
19 }
20
21 namespace printing {
22
23 // This class creates a graphics context that renders into a PDF data stream.
24 class PRINTING_EXPORT PdfMetafileCg : public Metafile {
25  public:
26   PdfMetafileCg();
27   ~PdfMetafileCg() override;
28
29   // Metafile methods.
30   bool Init() override;
31   bool InitFromData(const void* src_buffer, size_t src_buffer_size) override;
32   void StartPage(const gfx::Size& page_size,
33                  const gfx::Rect& content_area,
34                  const float& scale_factor) override;
35   bool FinishPage() override;
36   bool FinishDocument() override;
37
38   uint32_t GetDataSize() const override;
39   bool GetData(void* dst_buffer, uint32_t dst_buffer_size) const override;
40
41   gfx::Rect GetPageBounds(unsigned int page_number) const override;
42   unsigned int GetPageCount() const override;
43
44   // Note: The returned context *must not be retained* past Close(). If it is,
45   // the data returned from GetData will not be valid PDF data.
46   CGContextRef context() const override;
47
48   bool RenderPage(unsigned int page_number,
49                   printing::NativeDrawingContext context,
50                   const CGRect rect,
51                   const MacRenderPageParams& params) const override;
52
53  private:
54   // Returns a CGPDFDocumentRef version of |pdf_data_|.
55   CGPDFDocumentRef GetPDFDocument() const;
56
57   // Context for rendering to the pdf.
58   base::ScopedCFTypeRef<CGContextRef> context_;
59
60   // PDF backing store.
61   base::ScopedCFTypeRef<CFMutableDataRef> pdf_data_;
62
63   // Lazily-created CGPDFDocument representation of |pdf_data_|.
64   mutable base::ScopedCFTypeRef<CGPDFDocumentRef> pdf_doc_;
65
66   // Whether or not a page is currently open.
67   bool page_is_open_;
68
69   DISALLOW_COPY_AND_ASSIGN(PdfMetafileCg);
70 };
71
72 }  // namespace printing
73
74 #endif  // PRINTING_PDF_METAFILE_CG_MAC_H_