[email protected] | b5cf844c | 2012-06-18 21:49:20 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 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" |
[email protected] | 7226b33c | 2011-08-18 08:44:22 | [diff] [blame] | 10 | #include "base/memory/scoped_ptr.h" |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 11 | #include "build/build_config.h" |
[email protected] | 7d748990 | 2011-04-11 21:54:06 | [diff] [blame] | 12 | #include "printing/metafile.h" |
vitalybuka | a73fc37 | 2015-02-06 18:40:37 | [diff] [blame] | 13 | #include "skia/ext/platform_canvas.h" |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 14 | |
| 15 | #if defined(OS_WIN) |
| 16 | #include <windows.h> |
| 17 | #endif |
| 18 | |
vitalybuka | 9de71ea | 2014-11-05 09:22:34 | [diff] [blame] | 19 | class SkBaseDevice; |
| 20 | |
vitalybuka | 5d129058 | 2014-09-12 09:19:59 | [diff] [blame] | 21 | #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
| 22 | namespace base { |
| 23 | struct FileDescriptor; |
| 24 | } |
| 25 | #endif |
| 26 | |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 27 | namespace printing { |
| 28 | |
| 29 | struct PdfMetafileSkiaData; |
| 30 | |
| 31 | // This class uses Skia graphics library to generate a PDF document. |
[email protected] | 69f5b1e6 | 2011-09-01 06:34:04 | [diff] [blame] | 32 | class PRINTING_EXPORT PdfMetafileSkia : public Metafile { |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 33 | public: |
[email protected] | 7d748990 | 2011-04-11 21:54:06 | [diff] [blame] | 34 | PdfMetafileSkia(); |
dcheng | d5a0f18 | 2014-10-22 00:04:34 | [diff] [blame] | 35 | ~PdfMetafileSkia() override; |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 36 | |
[email protected] | 7d748990 | 2011-04-11 21:54:06 | [diff] [blame] | 37 | // Metafile methods. |
dcheng | d5a0f18 | 2014-10-22 00:04:34 | [diff] [blame] | 38 | bool Init() override; |
| 39 | bool InitFromData(const void* src_buffer, uint32 src_buffer_size) override; |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 40 | |
dcheng | d5a0f18 | 2014-10-22 00:04:34 | [diff] [blame] | 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; |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 46 | |
dcheng | d5a0f18 | 2014-10-22 00:04:34 | [diff] [blame] | 47 | uint32 GetDataSize() const override; |
| 48 | bool GetData(void* dst_buffer, uint32 dst_buffer_size) const override; |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 49 | |
dcheng | d5a0f18 | 2014-10-22 00:04:34 | [diff] [blame] | 50 | gfx::Rect GetPageBounds(unsigned int page_number) const override; |
| 51 | unsigned int GetPageCount() const override; |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 52 | |
dcheng | d5a0f18 | 2014-10-22 00:04:34 | [diff] [blame] | 53 | gfx::NativeDrawingContext context() const override; |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 54 | |
| 55 | #if defined(OS_WIN) |
nick | bc76161 | 2015-04-27 23:30:46 | [diff] [blame] | 56 | bool Playback(gfx::NativeDrawingContext hdc, |
| 57 | const RECT* rect) const override; |
| 58 | bool SafePlayback(gfx::NativeDrawingContext hdc) const override; |
[email protected] | b8d85bc | 2011-06-22 13:34:57 | [diff] [blame] | 59 | #elif defined(OS_MACOSX) |
dcheng | d5a0f18 | 2014-10-22 00:04:34 | [diff] [blame] | 60 | bool RenderPage(unsigned int page_number, |
| 61 | gfx::NativeDrawingContext context, |
| 62 | const CGRect rect, |
| 63 | const MacRenderPageParams& params) const override; |
[email protected] | b8d85bc | 2011-06-22 13:34:57 | [diff] [blame] | 64 | #endif |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 65 | |
halcanary | 5be808e | 2014-11-10 22:20:05 | [diff] [blame] | 66 | bool SaveTo(base::File* file) const override; |
| 67 | |
[email protected] | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 68 | #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
vitalybuka | 5d129058 | 2014-09-12 09:19:59 | [diff] [blame] | 69 | // TODO(vitalybuka): replace with SaveTo(). |
| 70 | bool SaveToFD(const base::FileDescriptor& fd) const; |
[email protected] | b25f003 | 2013-08-19 22:26:25 | [diff] [blame] | 71 | #endif // if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
[email protected] | c797a19 | 2011-06-15 16:25:09 | [diff] [blame] | 72 | |
[email protected] | 59751637 | 2011-07-01 05:10:44 | [diff] [blame] | 73 | // Return a new metafile containing just the current page in draft mode. |
vitalybuka | 5d129058 | 2014-09-12 09:19:59 | [diff] [blame] | 74 | scoped_ptr<PdfMetafileSkia> GetMetafileForCurrentPage(); |
[email protected] | 59751637 | 2011-07-01 05:10:44 | [diff] [blame] | 75 | |
vitalybuka | 9de71ea | 2014-11-05 09:22:34 | [diff] [blame] | 76 | // This method calls StartPage and then returns an appropriate |
vitalybuka | a73fc37 | 2015-02-06 18:40:37 | [diff] [blame] | 77 | // PlatformCanvas implementation bound to the context created by |
| 78 | // StartPage or NULL on error. The skia::PlatformCanvas pointer that |
halcanary | 5be808e | 2014-11-10 22:20:05 | [diff] [blame] | 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. |
vitalybuka | a73fc37 | 2015-02-06 18:40:37 | [diff] [blame] | 82 | skia::PlatformCanvas* GetVectorCanvasForNewPage(const gfx::Size& page_size, |
| 83 | const gfx::Rect& content_area, |
| 84 | const float& scale_factor); |
halcanary | 5be808e | 2014-11-10 22:20:05 | [diff] [blame] | 85 | |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 86 | private: |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 87 | scoped_ptr<PdfMetafileSkiaData> data_; |
| 88 | |
| 89 | DISALLOW_COPY_AND_ASSIGN(PdfMetafileSkia); |
| 90 | }; |
| 91 | |
| 92 | } // namespace printing |
| 93 | |
[email protected] | 39892b9 | 2011-04-30 02:24:44 | [diff] [blame] | 94 | #endif // PRINTING_PDF_METAFILE_SKIA_H_ |