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"
13 #include "skia/ext/platform_canvas.h"
21 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
23 struct FileDescriptor
;
29 struct PdfMetafileSkiaData
;
31 // This class uses Skia graphics library to generate a PDF document.
32 class PRINTING_EXPORT PdfMetafileSkia
: public Metafile
{
35 ~PdfMetafileSkia() override
;
39 bool InitFromData(const void* src_buffer
, uint32 src_buffer_size
) override
;
41 bool StartPage(const gfx::Size
& page_size
,
42 const gfx::Rect
& content_area
,
43 const float& scale_factor
) override
;
44 bool FinishPage() override
;
45 bool FinishDocument() override
;
47 uint32
GetDataSize() const override
;
48 bool GetData(void* dst_buffer
, uint32 dst_buffer_size
) const override
;
50 gfx::Rect
GetPageBounds(unsigned int page_number
) const override
;
51 unsigned int GetPageCount() const override
;
53 gfx::NativeDrawingContext
context() const override
;
56 virtual bool Playback(gfx::NativeDrawingContext hdc
,
57 const RECT
* rect
) const override
;
58 virtual bool SafePlayback(gfx::NativeDrawingContext hdc
) const override
;
59 #elif defined(OS_MACOSX)
60 bool RenderPage(unsigned int page_number
,
61 gfx::NativeDrawingContext context
,
63 const MacRenderPageParams
& params
) const override
;
66 bool SaveTo(base::File
* file
) const override
;
68 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
69 // TODO(vitalybuka): replace with SaveTo().
70 bool SaveToFD(const base::FileDescriptor
& fd
) const;
71 #endif // if defined(OS_CHROMEOS) || defined(OS_ANDROID)
73 // Return a new metafile containing just the current page in draft mode.
74 scoped_ptr
<PdfMetafileSkia
> GetMetafileForCurrentPage();
76 // This method calls StartPage and then returns an appropriate
77 // PlatformCanvas implementation bound to the context created by
78 // StartPage or NULL on error. The skia::PlatformCanvas pointer that
79 // is returned is owned by this PdfMetafileSkia object and does not
80 // need to be ref()ed or unref()ed. The canvas will remain valid
81 // until FinishPage() or FinishDocument() is called.
82 skia::PlatformCanvas
* GetVectorCanvasForNewPage(const gfx::Size
& page_size
,
83 const gfx::Rect
& content_area
,
84 const float& scale_factor
);
87 scoped_ptr
<PdfMetafileSkiaData
> data_
;
89 DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia
);
92 } // namespace printing
94 #endif // PRINTING_PDF_METAFILE_SKIA_H_