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. */
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.
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
37 bool InitForDrawing(const wchar_t* aMetafilePath
= nullptr);
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
);
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
);
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
62 "GetDC can be used only after "
63 "InitForDrawing/ InitFromFileContents and before"
64 "Playback/ SaveToFile");
69 * Play the EMF's drawing commands onto the given DC.
71 bool Playback(HDC aDeviceContext
, const RECT
& aRect
);
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
81 * Return the size of the enhanced metafile, in bytes.
83 UINT
GetEMFContentSize();
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
);
93 WindowsEMF(const WindowsEMF
& aEMF
) = delete;
94 bool FinishDocument();
95 void ReleaseEMFHandle();
96 void ReleaseAllResource();
98 /* Compiled EMF data handle. */
103 } // namespace widget
104 } // namespace mozilla
106 #endif /* MOZILLA_WIDGET_WINDOWSEMF_H */