Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / widget / windows / WindowsEMF.h
blob3a7a20173c01222a19ab2dc95f9096c4d972c7c3
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef MOZILLA_WIDGET_WINDOWSEMF_H
7 #define MOZILLA_WIDGET_WINDOWSEMF_H
9 /* include windows.h for the HDC definitions that we need. */
10 #include <windows.h>
12 namespace mozilla {
13 namespace widget {
15 /**
16 * Windows Enhance Metafile: https://en.wikipedia.org/wiki/Windows_Metafile
17 * A metafile, also called a vector image, is an image that is stored as a
18 * sequence of drawing commands and settings. The commands and settings
19 * recorded in a Metafile object can be stored in memory or saved to a file.
21 * The metafile device context is used for all drawing operations required to
22 * create the picture. When the system processes a GDI function associated with
23 * a metafile DC, it converts the function into the appropriate data and stores
24 * this data in a record appended to the metafile.
26 class WindowsEMF {
27 public:
28 WindowsEMF();
29 ~WindowsEMF();
31 /**
32 * Initializes the object with the path of a file where the EMF data stream
33 * should be stored. Callers are then expected to call GetDC() to draw output
34 * before going on to call Playback() or SaveToFile() to generate the EMF
35 * output.
37 bool InitForDrawing(const wchar_t* aMetafilePath = nullptr);
39 /**
40 * Initializes the object with an existing EMF file. Consumers cannot use
41 * GetDC() to obtain an HDC to modify the file. They can only use Playback().
43 bool InitFromFileContents(const wchar_t* aMetafilePath);
45 /**
46 * Creates the EMF from the specified data
48 * @param aByte Pointer to a buffer that contains EMF data.
49 * @param aSize Specifies the size, in bytes, of aByte.
51 bool InitFromFileContents(PBYTE aBytes, UINT aSize);
53 /**
54 * If this object was initiaziled using InitForDrawing() then this function
55 * returns an HDC that can be drawn to generate the EMF output. Otherwise it
56 * returns null. After finishing with the HDC, consumers could call Playback()
57 * to draw EMF onto the given DC or call SaveToFile() to finish writing the
58 * EMF file.
60 HDC GetDC() const {
61 MOZ_ASSERT(mDC,
62 "GetDC can be used only after "
63 "InitForDrawing/ InitFromFileContents and before"
64 "Playback/ SaveToFile");
65 return mDC;
68 /**
69 * Play the EMF's drawing commands onto the given DC.
71 bool Playback(HDC aDeviceContext, const RECT& aRect);
73 /**
74 * Called to generate the EMF file once a consumer has finished drawing to
75 * the HDC returned by GetDC(), if initializes the object with the path of a
76 * file.
78 bool SaveToFile();
80 /**
81 * Return the size of the enhanced metafile, in bytes.
83 UINT GetEMFContentSize();
85 /**
86 * Retrieves the contents of the EMF and copies them into a buffer.
88 * @param aByte the buffer to receive the data.
90 bool GetEMFContentBits(PBYTE aBytes);
92 private:
93 WindowsEMF(const WindowsEMF& aEMF) = delete;
94 bool FinishDocument();
95 void ReleaseEMFHandle();
96 void ReleaseAllResource();
98 /* Compiled EMF data handle. */
99 HENHMETAFILE mEmf;
100 HDC mDC;
103 } // namespace widget
104 } // namespace mozilla
106 #endif /* MOZILLA_WIDGET_WINDOWSEMF_H */