mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-02 06:22:20 +00:00

WindowsEMF could be initialized with the path of a file where the EMF data should be stored. If pass null point to the constructor that means the EMF data are store in memory. Consumers can call GetDC() to get a HDC. It can be drawn to generate the EMF output. After finishing with the HDC, call FinishDocument() to finish writing the EMF output. Then consumers can call Playback() to play the EMF's drawing commands onto the given DC. Once consumers don't use WindowsEMF anymore, call ReleaseEMFHandle() to release object's handle. If the EMF output is in memory, it is deleted. If it is on disk, it is not. Consumers also can initialize WindowsEMF with an existing EMF file. They can only use Playback(). MozReview-Commit-ID: 8hUsx8b2CXz --HG-- extra : rebase_source : 99e38e61a00bfae45ec9102b3b23a095a7f3af1e
86 lines
1.7 KiB
C++
86 lines
1.7 KiB
C++
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "WindowsEMF.h"
|
|
|
|
|
|
namespace mozilla {
|
|
namespace widget {
|
|
|
|
WindowsEMF::WindowsEMF()
|
|
: mDC(nullptr)
|
|
, mEmf(nullptr)
|
|
{
|
|
}
|
|
|
|
WindowsEMF::~WindowsEMF()
|
|
{
|
|
FinishDocument();
|
|
ReleaseEMFHandle();
|
|
}
|
|
|
|
bool
|
|
WindowsEMF::InitForDrawing(const wchar_t* aMetafilePath /* = nullptr */)
|
|
{
|
|
MOZ_ASSERT(!mDC && !mEmf, "InitForDrawing and InitFromFileContents is"
|
|
" designed to be used either one at once.");
|
|
|
|
mDC = ::CreateEnhMetaFile(nullptr, aMetafilePath, nullptr, nullptr);
|
|
return !!mDC;
|
|
}
|
|
|
|
bool
|
|
WindowsEMF::InitFromFileContents(const wchar_t* aMetafilePath)
|
|
{
|
|
MOZ_ASSERT(aMetafilePath);
|
|
MOZ_ASSERT(!mDC && !mEmf, "InitForDrawing and InitFromFileContents is"
|
|
" designed to be used either one at once.");
|
|
|
|
mEmf = ::GetEnhMetaFileW(aMetafilePath);
|
|
return !!mEmf;
|
|
}
|
|
|
|
bool
|
|
WindowsEMF::FinishDocument()
|
|
{
|
|
if (mDC) {
|
|
mEmf = ::CloseEnhMetaFile(mDC);
|
|
mDC = nullptr;
|
|
}
|
|
return !!mEmf;
|
|
}
|
|
|
|
void
|
|
WindowsEMF::ReleaseEMFHandle()
|
|
{
|
|
if (mEmf) {
|
|
::DeleteEnhMetaFile(mEmf);
|
|
mEmf = nullptr;
|
|
}
|
|
}
|
|
|
|
bool
|
|
WindowsEMF::Playback(HDC aDeviceContext, const RECT* aRect)
|
|
{
|
|
MOZ_ASSERT(aRect);
|
|
if (!FinishDocument()) {
|
|
return false;
|
|
}
|
|
|
|
return ::PlayEnhMetaFile(aDeviceContext, mEmf, aRect) != 0;
|
|
}
|
|
|
|
bool
|
|
WindowsEMF::SaveToFile()
|
|
{
|
|
if (!FinishDocument()) {
|
|
return false;
|
|
}
|
|
ReleaseEMFHandle();
|
|
return true;
|
|
}
|
|
|
|
} // namespace widget
|
|
} // namespace mozilla
|