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"
20 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
22 struct FileDescriptor;
28 struct PdfMetafileSkiaData;
30 // This class uses Skia graphics library to generate a PDF document.
31 class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
34 ~PdfMetafileSkia() override;
38 bool InitFromData(const void* src_buffer, uint32 src_buffer_size) override;
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;
46 uint32 GetDataSize() const override;
47 bool GetData(void* dst_buffer, uint32 dst_buffer_size) const override;
49 gfx::Rect GetPageBounds(unsigned int page_number) const override;
50 unsigned int GetPageCount() const override;
52 gfx::NativeDrawingContext context() const override;
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,
62 const MacRenderPageParams& params) const override;
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)
70 // Return a new metafile containing just the current page in draft mode.
71 scoped_ptr<PdfMetafileSkia> GetMetafileForCurrentPage();
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);
80 scoped_ptr<PdfMetafileSkiaData> data_;
82 // True when finish page is outstanding for current page.
83 bool page_outstanding_;
85 DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia);
88 } // namespace printing
90 #endif // PRINTING_PDF_METAFILE_SKIA_H_