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_SKIA_H_
6 #define PRINTING_PDF_METAFILE_SKIA_H_
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"
18 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
20 struct FileDescriptor
;
26 struct PdfMetafileSkiaData
;
28 // This class uses Skia graphics library to generate a PDF document.
29 class PRINTING_EXPORT PdfMetafileSkia
: public Metafile
{
32 virtual ~PdfMetafileSkia();
35 virtual bool Init() OVERRIDE
;
36 virtual bool InitFromData(const void* src_buffer
,
37 uint32 src_buffer_size
) OVERRIDE
;
39 virtual SkBaseDevice
* StartPageForVectorCanvas(
40 const gfx::Size
& page_size
,
41 const gfx::Rect
& content_area
,
42 const float& scale_factor
) OVERRIDE
;
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
;
50 virtual uint32
GetDataSize() const OVERRIDE
;
51 virtual bool GetData(void* dst_buffer
, uint32 dst_buffer_size
) const OVERRIDE
;
53 virtual gfx::Rect
GetPageBounds(unsigned int page_number
) const OVERRIDE
;
54 virtual unsigned int GetPageCount() const OVERRIDE
;
56 virtual gfx::NativeDrawingContext
context() const OVERRIDE
;
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
,
66 const MacRenderPageParams
& params
) const OVERRIDE
;
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)
74 // Return a new metafile containing just the current page in draft mode.
75 scoped_ptr
<PdfMetafileSkia
> GetMetafileForCurrentPage();
78 scoped_ptr
<PdfMetafileSkiaData
> data_
;
80 // True when finish page is outstanding for current page.
81 bool page_outstanding_
;
83 DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia
);
86 } // namespace printing
88 #endif // PRINTING_PDF_METAFILE_SKIA_H_