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_NATIVE_METAFILE_WIN_H_ |
| 6 #define PRINTING_NATIVE_METAFILE_WIN_H_ |
| 7 |
| 8 #include <windows.h> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 |
| 13 class FilePath; |
| 14 |
| 15 namespace gfx { |
| 16 class Rect; |
| 17 } |
| 18 |
| 19 namespace printing { |
| 20 |
| 21 // Simple wrapper class that manage an EMF data stream and its virtual HDC. |
| 22 class NativeMetafile { |
| 23 public: |
| 24 virtual ~NativeMetafile() {}; |
| 25 |
| 26 // Initializes the Emf with the data in |src_buffer|. Returns true on success. |
| 27 virtual bool Init(const void* src_buffer, uint32 src_buffer_size) = 0; |
| 28 |
| 29 // Generates a virtual HDC that will record every GDI commands and compile it |
| 30 // in a EMF data stream. |
| 31 // hdc is used to setup the default DPI and color settings. hdc is optional. |
| 32 // rect specifies the dimensions (in .01-millimeter units) of the EMF. rect is |
| 33 // optional. |
| 34 virtual bool CreateDc(HDC sibling, const RECT* rect) = 0; |
| 35 |
| 36 // Similar to the above method but the metafile is backed by a file. |
| 37 virtual bool CreateFileBackedDc(HDC sibling, |
| 38 const RECT* rect, |
| 39 const FilePath& path) = 0; |
| 40 |
| 41 // Load an EMF file. |
| 42 virtual bool CreateFromFile(const FilePath& metafile_path) = 0; |
| 43 |
| 44 // TODO(maruel): CreateFromFile(). If ever used. Maybe users would like to |
| 45 // have the ability to save web pages to an EMF file? Afterward, it is easy to |
| 46 // convert to PDF or PS. |
| 47 |
| 48 // Closes the HDC created by CreateDc() and generates the compiled EMF |
| 49 // data. |
| 50 virtual bool CloseDc() = 0; |
| 51 |
| 52 // Closes the EMF data handle when it is not needed anymore. |
| 53 virtual void CloseEmf() = 0; |
| 54 |
| 55 // "Plays" the EMF buffer in a HDC. It is the same effect as calling the |
| 56 // original GDI function that were called when recording the EMF. |rect| is in |
| 57 // "logical units" and is optional. If |rect| is NULL, the natural EMF bounds |
| 58 // are used. |
| 59 // Note: Windows has been known to have stack buffer overflow in its GDI |
| 60 // functions, whether used directly or indirectly through precompiled EMF |
| 61 // data. We have to accept the risk here. Since it is used only for printing, |
| 62 // it requires user intervention. |
| 63 virtual bool Playback(HDC hdc, const RECT* rect) const = 0; |
| 64 |
| 65 // The slow version of Playback(). It enumerates all the records and play them |
| 66 // back in the HDC. The trick is that it skip over the records known to have |
| 67 // issue with some printers. See Emf::Record::SafePlayback implementation for |
| 68 // details. |
| 69 virtual bool SafePlayback(HDC hdc) const = 0; |
| 70 |
| 71 // Retrieves the bounds of the painted area by this EMF buffer. This value |
| 72 // should be passed to Playback to keep the exact same size. |
| 73 virtual gfx::Rect GetBounds() const = 0; |
| 74 |
| 75 // Retrieves the EMF stream size. |
| 76 virtual uint32 GetDataSize() const = 0; |
| 77 |
| 78 // Retrieves the EMF stream. |
| 79 virtual bool GetData(void* buffer, uint32 size) const = 0; |
| 80 |
| 81 // Retrieves the EMF stream. It is an helper function. |
| 82 virtual bool GetData(std::vector<uint8>* buffer) const = 0; |
| 83 |
| 84 virtual HENHMETAFILE emf() const = 0; |
| 85 |
| 86 virtual HDC hdc() const = 0; |
| 87 |
| 88 // Inserts a custom GDICOMMENT records indicating StartPage/EndPage calls |
| 89 // (since StartPage and EndPage do not work in a metafile DC). Only valid |
| 90 // when hdc_ is non-NULL. |
| 91 virtual bool StartPage() = 0; |
| 92 virtual bool EndPage() = 0; |
| 93 |
| 94 // Saves the EMF data to a file as-is. It is recommended to use the .emf file |
| 95 // extension but it is not enforced. This function synchronously writes to the |
| 96 // file. For testing only. |
| 97 virtual bool SaveTo(const std::wstring& filename) const = 0; |
| 98 }; |
| 99 |
| 100 } // namespace printing |
| 101 |
| 102 #endif // PRINTING_NATIVE_METAFILE_WIN_H_ |
OLD | NEW |