Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1002)

Unified Diff: printing/native_metafile_linux.h

Issue 6544028: Create a Factory for NativeMetafile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: printing/native_metafile_linux.h
diff --git a/printing/native_metafile_linux.h b/printing/native_metafile_linux.h
new file mode 100644
index 0000000000000000000000000000000000000000..71b752600479df60002fe2ff324338ceea539138
--- /dev/null
+++ b/printing/native_metafile_linux.h
@@ -0,0 +1,89 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NATIVE_METAFILE_LINUX_H_
+#define NATIVE_METAFILE_LINUX_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+
+typedef struct _cairo_surface cairo_surface_t;
+typedef struct _cairo cairo_t;
+
+namespace base {
+struct FileDescriptor;
+}
+
+class FilePath;
+
+namespace printing {
+
+// This class uses Cairo graphics library to generate PostScript/PDF stream
+// and stores rendering results in a string buffer.
+class NativeMetafile {
+ public:
+ enum FileFormat {
+ PDF,
+ PS,
+ };
+
+ virtual ~NativeMetafile() {};
+
+ // Initializes to a fresh new metafile. Returns true on success.
+ // Note: Only call in the renderer to allocate rendering resources.
+ virtual bool Init() = 0;
+
+ // Initializes a copy of metafile from PDF/PS stream data.
+ // Returns true on success.
+ // |src_buffer| should point to the shared memory which stores PDF/PS
+ // contents generated in the renderer.
+ // Note: Only call in the browser to initialize |data_|.
+ virtual bool Init(const void* src_buffer, uint32 src_buffer_size) = 0;
+
+ // Sets raw PS/PDF data for the document. This is used when a cairo drawing
+ // surface has already been created. This method will cause all subsequent
+ // drawing on the surface to be discarded (in Close()). If Init() has not yet
+ // been called this method simply calls the second version of Init.
+ virtual bool SetRawData(const void* src_buffer, uint32 src_buffer_size) = 0;
+
+ virtual FileFormat GetFileFormat() const = 0;
+
+ // Prepares a new cairo surface/context for rendering a new page.
+ // The unit is in point (=1/72 in).
+ // Returns NULL when failed.
+ virtual cairo_t* StartPage(double width_in_points,
+ double height_in_points,
+ double margin_top_in_points,
+ double margin_right_in_points,
+ double margin_bottom_in_points,
+ double margin_left_in_points) = 0;
+
+ // Destroys the surface and the context used in rendering current page.
+ // The results of current page will be appended into buffer |data_|.
+ // Returns true on success.
+ virtual bool FinishPage() = 0;
+
+ // Closes resulting PDF/PS file. No further rendering is allowed.
+ virtual void Close() = 0;
+
+ // Returns size of PDF/PS contents stored in buffer |data_|.
+ // This function should ONLY be called after PDF/PS file is closed.
+ virtual uint32 GetDataSize() const = 0;
+
+ // Copies PDF/PS contents stored in buffer |data_| into |dst_buffer|.
+ // This function should ONLY be called after PDF/PS file is closed.
+ // Returns true only when success.
+ virtual bool GetData(void* dst_buffer, uint32 dst_buffer_size) const = 0;
+
+ // Saves PDF/PS contents stored in buffer |data_| into the file
+ // associated with |fd|.
+ // This function should ONLY be called after PDF/PS file is closed.
+ virtual bool SaveTo(const base::FileDescriptor& fd) const = 0;
+
+};
+
+} // namespace printing
+
+#endif /* NATIVE_METAFILE_LINUX_H_ */

Powered by Google App Engine
This is Rietveld 408576698