| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef PRINTING_PDF_METAFILE_CAIRO_LINUX_H_ | |
| 6 #define PRINTING_PDF_METAFILE_CAIRO_LINUX_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/gtest_prod_util.h" | |
| 12 #include "printing/metafile.h" | |
| 13 | |
| 14 namespace gfx { | |
| 15 class Point; | |
| 16 class Rect; | |
| 17 class Size; | |
| 18 } | |
| 19 | |
| 20 typedef struct _cairo_surface cairo_surface_t; | |
| 21 | |
| 22 namespace printing { | |
| 23 | |
| 24 // This class uses Cairo graphics library to generate PDF stream and stores | |
| 25 // rendering results in a string buffer. | |
| 26 class PRINTING_EXPORT PdfMetafileCairo : public Metafile { | |
| 27 public: | |
| 28 PdfMetafileCairo(); | |
| 29 virtual ~PdfMetafileCairo(); | |
| 30 | |
| 31 // Metafile methods. | |
| 32 virtual bool Init(); | |
| 33 | |
| 34 // Calling InitFromData() sets the data for this metafile and masks data | |
| 35 // induced by previous calls to Init() or InitFromData(), even if drawing | |
| 36 // continues on the surface returned by a previous call to Init(). | |
| 37 virtual bool InitFromData(const void* src_buffer, uint32 src_buffer_size); | |
| 38 | |
| 39 virtual SkDevice* StartPageForVectorCanvas( | |
| 40 const gfx::Size& page_size, const gfx::Rect& content_area, | |
| 41 const float& scale_factor); | |
| 42 | |
| 43 virtual bool StartPage(const gfx::Size& page_size, | |
| 44 const gfx::Rect& content_area, | |
| 45 const float& scale_factor); | |
| 46 virtual bool FinishPage(); | |
| 47 virtual bool FinishDocument(); | |
| 48 | |
| 49 virtual uint32 GetDataSize() const; | |
| 50 virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const; | |
| 51 | |
| 52 virtual bool SaveTo(const FilePath& file_path) const; | |
| 53 | |
| 54 virtual gfx::Rect GetPageBounds(unsigned int page_number) const; | |
| 55 virtual unsigned int GetPageCount() const; | |
| 56 | |
| 57 virtual cairo_t* context() const; | |
| 58 | |
| 59 #if defined(OS_CHROMEOS) | |
| 60 virtual bool SaveToFD(const base::FileDescriptor& fd) const; | |
| 61 #endif // if defined(OS_CHROMEOS) | |
| 62 | |
| 63 private: | |
| 64 // Cleans up all resources. | |
| 65 void CleanUpAll(); | |
| 66 | |
| 67 // Cairo surface and context for entire PDF file. | |
| 68 cairo_surface_t* surface_; | |
| 69 cairo_t* context_; | |
| 70 | |
| 71 // Buffer stores PDF contents for entire PDF file. | |
| 72 std::string cairo_data_; | |
| 73 // Buffer stores PDF contents. It can only be populated from InitFromData(). | |
| 74 // Any calls to StartPage(), FinishPage(), FinishDocument() do not affect | |
| 75 // this buffer. | |
| 76 // Note: Such calls will result in DCHECK errors if Init() has not been called | |
| 77 // first. | |
| 78 std::string raw_data_; | |
| 79 // Points to the appropriate buffer depending on the way the object was | |
| 80 // initialized (Init() vs InitFromData()). | |
| 81 std::string* current_data_; | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(PdfMetafileCairo); | |
| 84 }; | |
| 85 | |
| 86 } // namespace printing | |
| 87 | |
| 88 #endif // PRINTING_PDF_METAFILE_CAIRO_LINUX_H_ | |
| OLD | NEW |