blob: cab518accd7a433e1b767fe4fb23088ebc510d8f [file] [log] [blame]
[email protected]b5cf844c2012-06-18 21:49:201// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]8f879292011-04-08 00:21:202// 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"
[email protected]7226b33c2011-08-18 08:44:2210#include "base/memory/scoped_ptr.h"
[email protected]8f879292011-04-08 00:21:2011#include "build/build_config.h"
[email protected]7d7489902011-04-11 21:54:0612#include "printing/metafile.h"
vitalybukaa73fc372015-02-06 18:40:3713#include "skia/ext/platform_canvas.h"
[email protected]8f879292011-04-08 00:21:2014
15#if defined(OS_WIN)
16#include <windows.h>
17#endif
18
vitalybuka9de71ea2014-11-05 09:22:3419class SkBaseDevice;
20
vitalybuka5d1290582014-09-12 09:19:5921#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
22namespace base {
23struct FileDescriptor;
24}
25#endif
26
[email protected]8f879292011-04-08 00:21:2027namespace printing {
28
29struct PdfMetafileSkiaData;
30
31// This class uses Skia graphics library to generate a PDF document.
[email protected]69f5b1e62011-09-01 06:34:0432class PRINTING_EXPORT PdfMetafileSkia : public Metafile {
[email protected]8f879292011-04-08 00:21:2033 public:
[email protected]7d7489902011-04-11 21:54:0634 PdfMetafileSkia();
dchengd5a0f182014-10-22 00:04:3435 ~PdfMetafileSkia() override;
[email protected]8f879292011-04-08 00:21:2036
[email protected]7d7489902011-04-11 21:54:0637 // Metafile methods.
dchengd5a0f182014-10-22 00:04:3438 bool Init() override;
39 bool InitFromData(const void* src_buffer, uint32 src_buffer_size) override;
[email protected]8f879292011-04-08 00:21:2040
dchengd5a0f182014-10-22 00:04:3441 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;
[email protected]8f879292011-04-08 00:21:2046
dchengd5a0f182014-10-22 00:04:3447 uint32 GetDataSize() const override;
48 bool GetData(void* dst_buffer, uint32 dst_buffer_size) const override;
[email protected]8f879292011-04-08 00:21:2049
dchengd5a0f182014-10-22 00:04:3450 gfx::Rect GetPageBounds(unsigned int page_number) const override;
51 unsigned int GetPageCount() const override;
[email protected]8f879292011-04-08 00:21:2052
dchengd5a0f182014-10-22 00:04:3453 gfx::NativeDrawingContext context() const override;
[email protected]8f879292011-04-08 00:21:2054
55#if defined(OS_WIN)
nickbc761612015-04-27 23:30:4656 bool Playback(gfx::NativeDrawingContext hdc,
57 const RECT* rect) const override;
58 bool SafePlayback(gfx::NativeDrawingContext hdc) const override;
[email protected]b8d85bc2011-06-22 13:34:5759#elif defined(OS_MACOSX)
dchengd5a0f182014-10-22 00:04:3460 bool RenderPage(unsigned int page_number,
61 gfx::NativeDrawingContext context,
62 const CGRect rect,
63 const MacRenderPageParams& params) const override;
[email protected]b8d85bc2011-06-22 13:34:5764#endif
[email protected]8f879292011-04-08 00:21:2065
halcanary5be808e2014-11-10 22:20:0566 bool SaveTo(base::File* file) const override;
67
[email protected]b25f0032013-08-19 22:26:2568#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
vitalybuka5d1290582014-09-12 09:19:5969 // TODO(vitalybuka): replace with SaveTo().
70 bool SaveToFD(const base::FileDescriptor& fd) const;
[email protected]b25f0032013-08-19 22:26:2571#endif // if defined(OS_CHROMEOS) || defined(OS_ANDROID)
[email protected]c797a192011-06-15 16:25:0972
[email protected]597516372011-07-01 05:10:4473 // Return a new metafile containing just the current page in draft mode.
vitalybuka5d1290582014-09-12 09:19:5974 scoped_ptr<PdfMetafileSkia> GetMetafileForCurrentPage();
[email protected]597516372011-07-01 05:10:4475
vitalybuka9de71ea2014-11-05 09:22:3476 // This method calls StartPage and then returns an appropriate
vitalybukaa73fc372015-02-06 18:40:3777 // PlatformCanvas implementation bound to the context created by
78 // StartPage or NULL on error. The skia::PlatformCanvas pointer that
halcanary5be808e2014-11-10 22:20:0579 // 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.
vitalybukaa73fc372015-02-06 18:40:3782 skia::PlatformCanvas* GetVectorCanvasForNewPage(const gfx::Size& page_size,
83 const gfx::Rect& content_area,
84 const float& scale_factor);
halcanary5be808e2014-11-10 22:20:0585
[email protected]8f879292011-04-08 00:21:2086 private:
[email protected]8f879292011-04-08 00:21:2087 scoped_ptr<PdfMetafileSkiaData> data_;
88
89 DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia);
90};
91
92} // namespace printing
93
[email protected]39892b92011-04-30 02:24:4494#endif // PRINTING_PDF_METAFILE_SKIA_H_