Upload upstream chromium 85.0.4183.84
[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 "printing/metafile.h"
14
15 namespace printing {
16
17 // This class creates a graphics context that renders into a PDF data stream.
18 class PRINTING_EXPORT PdfMetafileCg : public Metafile {
19  public:
20   PdfMetafileCg();
21   PdfMetafileCg(const PdfMetafileCg&) = delete;
22   PdfMetafileCg& operator=(const PdfMetafileCg&) = delete;
23   ~PdfMetafileCg() override;
24
25   // Metafile methods.
26   bool Init() override;
27   bool InitFromData(base::span<const uint8_t> data) override;
28   void StartPage(const gfx::Size& page_size,
29                  const gfx::Rect& content_area,
30                  float scale_factor,
31                  mojom::PageOrientation page_orientation) override;
32   bool FinishPage() override;
33   bool FinishDocument() override;
34
35   uint32_t GetDataSize() const override;
36   bool GetData(void* dst_buffer, uint32_t dst_buffer_size) const override;
37
38   gfx::Rect GetPageBounds(unsigned int page_number) const override;
39   unsigned int GetPageCount() const override;
40
41   // Note: The returned context *must not be retained* past Close(). If it is,
42   // the data returned from GetData will not be valid PDF data.
43   CGContextRef context() const override;
44
45   bool RenderPage(unsigned int page_number,
46                   printing::NativeDrawingContext context,
47                   const CGRect& rect,
48                   bool autorotate,
49                   bool fit_to_page) const override;
50
51  private:
52   // Returns a CGPDFDocumentRef version of |pdf_data_|.
53   CGPDFDocumentRef GetPDFDocument() const;
54
55   // Context for rendering to the pdf.
56   base::ScopedCFTypeRef<CGContextRef> context_;
57
58   // PDF backing store.
59   base::ScopedCFTypeRef<CFMutableDataRef> pdf_data_;
60
61   // Lazily-created CGPDFDocument representation of |pdf_data_|.
62   mutable base::ScopedCFTypeRef<CGPDFDocumentRef> pdf_doc_;
63
64   // Whether or not a page is currently open.
65   bool page_is_open_ = false;
66 };
67
68 }  // namespace printing
69
70 #endif  // PRINTING_PDF_METAFILE_CG_MAC_H_