| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PRINTING_PDF_METAFILE_CAIRO_LINUX_H_ | 5 #ifndef PRINTING_PDF_METAFILE_CAIRO_LINUX_H_ |
| 6 #define PRINTING_PDF_METAFILE_CAIRO_LINUX_H_ | 6 #define PRINTING_PDF_METAFILE_CAIRO_LINUX_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "printing/native_metafile.h" | 12 #include "printing/metafile.h" |
| 13 | 13 |
| 14 namespace gfx { | 14 namespace gfx { |
| 15 class Point; | 15 class Point; |
| 16 class Rect; | 16 class Rect; |
| 17 class Size; | 17 class Size; |
| 18 } | 18 } |
| 19 | 19 |
| 20 typedef struct _cairo_surface cairo_surface_t; | 20 typedef struct _cairo_surface cairo_surface_t; |
| 21 | 21 |
| 22 namespace printing { | 22 namespace printing { |
| 23 | 23 |
| 24 // This class uses Cairo graphics library to generate PDF stream and stores | 24 // This class uses Cairo graphics library to generate PDF stream and stores |
| 25 // rendering results in a string buffer. | 25 // rendering results in a string buffer. |
| 26 class PdfMetafileCairo : public NativeMetafile { | 26 class PdfMetafileCairo : public Metafile { |
| 27 public: | 27 public: |
| 28 PdfMetafileCairo(); |
| 28 virtual ~PdfMetafileCairo(); | 29 virtual ~PdfMetafileCairo(); |
| 29 | 30 |
| 30 // NativeMetafile methods. | 31 // Metafile methods. |
| 31 virtual bool Init(); | 32 virtual bool Init(); |
| 32 | 33 |
| 33 // Calling InitFromData() sets the data for this metafile and masks data | 34 // Calling InitFromData() sets the data for this metafile and masks data |
| 34 // induced by previous calls to Init() or InitFromData(), even if drawing | 35 // induced by previous calls to Init() or InitFromData(), even if drawing |
| 35 // continues on the surface returned by a previous call to Init(). | 36 // continues on the surface returned by a previous call to Init(). |
| 36 virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size); | 37 virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size); |
| 37 | 38 |
| 38 virtual skia::PlatformDevice* StartPageForVectorCanvas( | 39 virtual skia::PlatformDevice* StartPageForVectorCanvas( |
| 39 const gfx::Size& page_size, const gfx::Point& content_origin, | 40 const gfx::Size& page_size, const gfx::Point& content_origin, |
| 40 const float& scale_factor); | 41 const float& scale_factor); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 51 | 52 |
| 52 virtual gfx::Rect GetPageBounds(unsigned int page_number) const; | 53 virtual gfx::Rect GetPageBounds(unsigned int page_number) const; |
| 53 virtual unsigned int GetPageCount() const; | 54 virtual unsigned int GetPageCount() const; |
| 54 | 55 |
| 55 virtual cairo_t* context() const; | 56 virtual cairo_t* context() const; |
| 56 | 57 |
| 57 #if defined(OS_CHROMEOS) | 58 #if defined(OS_CHROMEOS) |
| 58 virtual bool SaveToFD(const base::FileDescriptor& fd) const; | 59 virtual bool SaveToFD(const base::FileDescriptor& fd) const; |
| 59 #endif // if defined(OS_CHROMEOS) | 60 #endif // if defined(OS_CHROMEOS) |
| 60 | 61 |
| 61 protected: | |
| 62 PdfMetafileCairo(); | |
| 63 | |
| 64 private: | 62 private: |
| 65 friend class NativeMetafileFactory; | |
| 66 FRIEND_TEST_ALL_PREFIXES(PdfMetafileCairoTest, Pdf); | |
| 67 | |
| 68 // Cleans up all resources. | 63 // Cleans up all resources. |
| 69 void CleanUpAll(); | 64 void CleanUpAll(); |
| 70 | 65 |
| 71 // Cairo surface and context for entire PDF file. | 66 // Cairo surface and context for entire PDF file. |
| 72 cairo_surface_t* surface_; | 67 cairo_surface_t* surface_; |
| 73 cairo_t* context_; | 68 cairo_t* context_; |
| 74 | 69 |
| 75 // Buffer stores PDF contents for entire PDF file. | 70 // Buffer stores PDF contents for entire PDF file. |
| 76 std::string cairo_data_; | 71 std::string cairo_data_; |
| 77 // Buffer stores PDF contents. It can only be populated from InitFromData(). | 72 // Buffer stores PDF contents. It can only be populated from InitFromData(). |
| 78 // Any calls to StartPage(), FinishPage(), FinishDocument() do not affect | 73 // Any calls to StartPage(), FinishPage(), FinishDocument() do not affect |
| 79 // this buffer. | 74 // this buffer. |
| 80 // Note: Such calls will result in DCHECK errors if Init() has not been called | 75 // Note: Such calls will result in DCHECK errors if Init() has not been called |
| 81 // first. | 76 // first. |
| 82 std::string raw_data_; | 77 std::string raw_data_; |
| 83 // Points to the appropriate buffer depending on the way the object was | 78 // Points to the appropriate buffer depending on the way the object was |
| 84 // initialized (Init() vs InitFromData()). | 79 // initialized (Init() vs InitFromData()). |
| 85 std::string* current_data_; | 80 std::string* current_data_; |
| 86 | 81 |
| 87 DISALLOW_COPY_AND_ASSIGN(PdfMetafileCairo); | 82 DISALLOW_COPY_AND_ASSIGN(PdfMetafileCairo); |
| 88 }; | 83 }; |
| 89 | 84 |
| 90 } // namespace printing | 85 } // namespace printing |
| 91 | 86 |
| 92 #endif // PRINTING_PDF_METAFILE_CAIRO_LINUX_H_ | 87 #endif // PRINTING_PDF_METAFILE_CAIRO_LINUX_H_ |
| OLD | NEW |