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

Unified Diff: printing/native_metafile_win.h

Issue 6544028: Create a Factory for NativeMetafile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed NativeMetafileFactory class comments 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_win.h
diff --git a/printing/native_metafile_win.h b/printing/native_metafile_win.h
new file mode 100644
index 0000000000000000000000000000000000000000..4b754db4adbd0715fed7411b4832d95a355af39f
--- /dev/null
+++ b/printing/native_metafile_win.h
@@ -0,0 +1,104 @@
+// Copyright (c) 2011 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 PRINTING_NATIVE_METAFILE_WIN_H_
+#define PRINTING_NATIVE_METAFILE_WIN_H_
+
+#include <windows.h>
+#include <vector>
+
+#include "base/basictypes.h"
+
+class FilePath;
+
+namespace gfx {
+class Rect;
+}
+
+namespace printing {
+
+// Simple wrapper class that manage an EMF data stream and its virtual HDC.
+class NativeMetafile {
+ public:
+
vandebo (ex-Chrome) 2011/02/23 02:01:41 extra line.
dpapad 2011/02/24 20:56:59 Done.
+ virtual ~NativeMetafile() {};
+
+ // Initializes the Emf with the data in |src_buffer|. Returns true on success.
+ virtual bool Init(const void* src_buffer, uint32 src_buffer_size) = 0;
+
+ // Generates a virtual HDC that will record every GDI commands and compile it
+ // in a EMF data stream.
+ // hdc is used to setup the default DPI and color settings. hdc is optional.
+ // rect specifies the dimensions (in .01-millimeter units) of the EMF. rect is
+ // optional.
+ virtual bool CreateDc(HDC sibling, const RECT* rect) = 0;
+
+ // Similar to the above method but the metafile is backed by a file.
+ virtual bool CreateFileBackedDc(HDC sibling,
+ const RECT* rect,
+ const FilePath& path) = 0;
+
+ // Load an EMF file.
vandebo (ex-Chrome) 2011/02/23 02:01:41 extra spaces
dpapad 2011/02/24 20:56:59 Done.
+ virtual bool CreateFromFile(const FilePath& metafile_path) = 0;
+
+ // TODO(maruel): CreateFromFile(). If ever used. Maybe users would like to
+ // have the ability to save web pages to an EMF file? Afterward, it is easy to
+ // convert to PDF or PS.
+
+ // Closes the HDC created by CreateDc() and generates the compiled EMF
+ // data.
+ virtual bool CloseDc() = 0;
+
+ // Closes the EMF data handle when it is not needed anymore.
+ virtual void CloseEmf() = 0;
+
+ // "Plays" the EMF buffer in a HDC. It is the same effect as calling the
+ // original GDI function that were called when recording the EMF. |rect| is in
+ // "logical units" and is optional. If |rect| is NULL, the natural EMF bounds
+ // are used.
+ // Note: Windows has been known to have stack buffer overflow in its GDI
+ // functions, whether used directly or indirectly through precompiled EMF
+ // data. We have to accept the risk here. Since it is used only for printing,
+ // it requires user intervention.
+ virtual bool Playback(HDC hdc, const RECT* rect) const = 0;
+
+ // The slow version of Playback(). It enumerates all the records and play them
+ // back in the HDC. The trick is that it skip over the records known to have
+ // issue with some printers. See Emf::Record::SafePlayback implementation for
+ // details.
+ virtual bool SafePlayback(HDC hdc) const = 0;
+
+ // Retrieves the bounds of the painted area by this EMF buffer. This value
+ // should be passed to Playback to keep the exact same size.
+ virtual gfx::Rect GetBounds() const = 0;
+
+ // Retrieves the EMF stream size.
+ virtual uint32 GetDataSize() const = 0;
+
+ // Retrieves the EMF stream.
+ virtual bool GetData(void* buffer, uint32 size) const = 0;
+
+ // Retrieves the EMF stream. It is an helper function.
+ virtual bool GetData(std::vector<uint8>* buffer) const = 0;
+
+ virtual HENHMETAFILE emf() const = 0;
+
+ virtual HDC hdc() const = 0;
+
+ // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls
+ // (since StartPage and EndPage do not work in a metafile DC). Only valid
+ // when hdc_ is non-NULL.
+ virtual bool StartPage() = 0;
+ virtual bool EndPage() = 0;
+
+ // Saves the EMF data to a file as-is. It is recommended to use the .emf file
+ // extension but it is not enforced. This function synchronously writes to the
+ // file. For testing only.
+ virtual bool SaveTo(const std::wstring& filename) const = 0;
+
+};
+
+} // namespace printing
+
+#endif /* PRINTING_NATIVE_METAFILE_WIN_H_ */
vandebo (ex-Chrome) 2011/02/23 02:01:41 style
dpapad 2011/02/24 20:56:59 Done.

Powered by Google App Engine
This is Rietveld 408576698