Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / printing / pdf_metafile_skia.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_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 class SkBaseDevice;
19
20 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
21 namespace base {
22 struct FileDescriptor;
23 }
24 #endif
25
26 namespace printing {
27
28 struct PdfMetafileSkiaData;
29
30 // This class uses Skia graphics library to generate a PDF document.
31 class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
32  public:
33   PdfMetafileSkia();
34   ~PdfMetafileSkia() override;
35
36   // Metafile methods.
37   bool Init() override;
38   bool InitFromData(const void* src_buffer, uint32 src_buffer_size) override;
39
40   bool StartPage(const gfx::Size& page_size,
41                  const gfx::Rect& content_area,
42                  const float& scale_factor) override;
43   bool FinishPage() override;
44   bool FinishDocument() override;
45
46   uint32 GetDataSize() const override;
47   bool GetData(void* dst_buffer, uint32 dst_buffer_size) const override;
48
49   gfx::Rect GetPageBounds(unsigned int page_number) const override;
50   unsigned int GetPageCount() const override;
51
52   gfx::NativeDrawingContext context() const override;
53
54 #if defined(OS_WIN)
55   virtual bool Playback(gfx::NativeDrawingContext hdc,
56                         const RECT* rect) const override;
57   virtual bool SafePlayback(gfx::NativeDrawingContext hdc) const override;
58 #elif defined(OS_MACOSX)
59   bool RenderPage(unsigned int page_number,
60                   gfx::NativeDrawingContext context,
61                   const CGRect rect,
62                   const MacRenderPageParams& params) const override;
63 #endif
64
65 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
66   // TODO(vitalybuka): replace with SaveTo().
67   bool SaveToFD(const base::FileDescriptor& fd) const;
68 #endif  // if defined(OS_CHROMEOS) || defined(OS_ANDROID)
69
70   // Return a new metafile containing just the current page in draft mode.
71   scoped_ptr<PdfMetafileSkia> GetMetafileForCurrentPage();
72
73   // This method calls StartPage and then returns an appropriate
74   // VectorPlatformDevice implementation bound to the context created by
75   // StartPage or NULL on error.
76   SkBaseDevice* StartPageForVectorCanvas(const gfx::Size& page_size,
77                                          const gfx::Rect& content_area,
78                                          const float& scale_factor);
79  private:
80   scoped_ptr<PdfMetafileSkiaData> data_;
81
82   // True when finish page is outstanding for current page.
83   bool page_outstanding_;
84
85   DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia);
86 };
87
88 }  // namespace printing
89
90 #endif  // PRINTING_PDF_METAFILE_SKIA_H_