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_SKIA_H_
6#define PRINTING_PDF_METAFILE_SKIA_H_
7
8#include "base/basictypes.h"
9#include "base/logging.h"
10#include "base/memory/scoped_ptr.h"
11#include "build/build_config.h"
12#include "printing/metafile.h"
13
14#if defined(OS_WIN)
15#include <windows.h>
16#endif
17
18#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
19namespace base {
20struct FileDescriptor;
21}
22#endif
23
24namespace printing {
25
26struct PdfMetafileSkiaData;
27
28// This class uses Skia graphics library to generate a PDF document.
29class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
30 public:
31  PdfMetafileSkia();
32  virtual ~PdfMetafileSkia();
33
34  // Metafile methods.
35  virtual bool Init() OVERRIDE;
36  virtual bool InitFromData(const void* src_buffer,
37                            uint32 src_buffer_size) OVERRIDE;
38
39  virtual SkBaseDevice* StartPageForVectorCanvas(
40      const gfx::Size& page_size,
41      const gfx::Rect& content_area,
42      const float& scale_factor) OVERRIDE;
43
44  virtual bool StartPage(const gfx::Size& page_size,
45                         const gfx::Rect& content_area,
46                         const float& scale_factor) OVERRIDE;
47  virtual bool FinishPage() OVERRIDE;
48  virtual bool FinishDocument() OVERRIDE;
49
50  virtual uint32 GetDataSize() const OVERRIDE;
51  virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const OVERRIDE;
52
53  virtual gfx::Rect GetPageBounds(unsigned int page_number) const OVERRIDE;
54  virtual unsigned int GetPageCount() const OVERRIDE;
55
56  virtual gfx::NativeDrawingContext context() const OVERRIDE;
57
58#if defined(OS_WIN)
59  virtual bool Playback(gfx::NativeDrawingContext hdc,
60                        const RECT* rect) const OVERRIDE;
61  virtual bool SafePlayback(gfx::NativeDrawingContext hdc) const OVERRIDE;
62#elif defined(OS_MACOSX)
63  virtual bool RenderPage(unsigned int page_number,
64                          gfx::NativeDrawingContext context,
65                          const CGRect rect,
66                          const MacRenderPageParams& params) const OVERRIDE;
67#endif
68
69#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
70  // TODO(vitalybuka): replace with SaveTo().
71  bool SaveToFD(const base::FileDescriptor& fd) const;
72#endif  // if defined(OS_CHROMEOS) || defined(OS_ANDROID)
73
74  // Return a new metafile containing just the current page in draft mode.
75  scoped_ptr<PdfMetafileSkia> GetMetafileForCurrentPage();
76
77 private:
78  scoped_ptr<PdfMetafileSkiaData> data_;
79
80  // True when finish page is outstanding for current page.
81  bool page_outstanding_;
82
83  DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia);
84};
85
86}  // namespace printing
87
88#endif  // PRINTING_PDF_METAFILE_SKIA_H_
89