mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Fixed line endings and applied gitignore
This commit is contained in:
@ -1,67 +1,67 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "DWriteFontCollectionLoader.h"
|
||||
#include "DWriteFontFileEnumerator.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
DWriteFontCollectionLoader* DWriteFontCollectionLoader::GetInstance()
|
||||
{
|
||||
static DWriteFontCollectionLoader s_Instance;
|
||||
return &s_Instance;
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE DWriteFontCollectionLoader::AddRef()
|
||||
{
|
||||
// This is a singleton class so return a dummy value.
|
||||
return 1;
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE DWriteFontCollectionLoader::Release()
|
||||
{
|
||||
// This is a singleton class so return a dummy value.
|
||||
return 1;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE DWriteFontCollectionLoader::QueryInterface(IID const& riid, void** ppvObject)
|
||||
{
|
||||
if (riid == IID_IUnknown ||
|
||||
riid == __uuidof(IDWriteFontCollectionLoader))
|
||||
{
|
||||
*ppvObject = this;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
*ppvObject = nullptr;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE DWriteFontCollectionLoader::CreateEnumeratorFromKey(
|
||||
IDWriteFactory* factory, void const* collectionKey, UINT32 collectionKeySize,
|
||||
IDWriteFontFileEnumerator** fontFileEnumerator)
|
||||
{
|
||||
*fontFileEnumerator = new DWriteFontFileEnumerator(
|
||||
*(const std::vector<IDWriteFontFile*>*)collectionKey);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "DWriteFontCollectionLoader.h"
|
||||
#include "DWriteFontFileEnumerator.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
DWriteFontCollectionLoader* DWriteFontCollectionLoader::GetInstance()
|
||||
{
|
||||
static DWriteFontCollectionLoader s_Instance;
|
||||
return &s_Instance;
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE DWriteFontCollectionLoader::AddRef()
|
||||
{
|
||||
// This is a singleton class so return a dummy value.
|
||||
return 1;
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE DWriteFontCollectionLoader::Release()
|
||||
{
|
||||
// This is a singleton class so return a dummy value.
|
||||
return 1;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE DWriteFontCollectionLoader::QueryInterface(IID const& riid, void** ppvObject)
|
||||
{
|
||||
if (riid == IID_IUnknown ||
|
||||
riid == __uuidof(IDWriteFontCollectionLoader))
|
||||
{
|
||||
*ppvObject = this;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
*ppvObject = nullptr;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE DWriteFontCollectionLoader::CreateEnumeratorFromKey(
|
||||
IDWriteFactory* factory, void const* collectionKey, UINT32 collectionKeySize,
|
||||
IDWriteFontFileEnumerator** fontFileEnumerator)
|
||||
{
|
||||
*fontFileEnumerator = new DWriteFontFileEnumerator(
|
||||
*(const std::vector<IDWriteFontFile*>*)collectionKey);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
@ -1,53 +1,53 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_UTIL_DWRITEFONTCOLLECTIONLOADER_H_
|
||||
#define RM_GFX_UTIL_DWRITEFONTCOLLECTIONLOADER_H_
|
||||
|
||||
#include <dwrite_1.h>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Implements the IDWriteFontCollectionLoader interface as a singleton object. When
|
||||
// CreateEnumeratorFromKey is called, a new DWriteFontFileEnumerator object is created using
|
||||
// |fontCollectionKey| (which is assumed to be a pointer to std::vector<IDWriteFontFile*>).
|
||||
class DWriteFontCollectionLoader : public IDWriteFontCollectionLoader
|
||||
{
|
||||
public:
|
||||
static DWriteFontCollectionLoader* GetInstance();
|
||||
|
||||
// IUnknown
|
||||
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID uuid, void** object) override;
|
||||
virtual ULONG STDMETHODCALLTYPE AddRef() override;
|
||||
virtual ULONG STDMETHODCALLTYPE Release() override;
|
||||
|
||||
// IFontCollectionLoader
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateEnumeratorFromKey(
|
||||
IDWriteFactory* factory, void const* fontCollectionKey, UINT32 fontCollectionKeySize,
|
||||
IDWriteFontFileEnumerator** fontFileEnumerator) override;
|
||||
|
||||
private:
|
||||
DWriteFontCollectionLoader() {}
|
||||
DWriteFontCollectionLoader(const DWriteFontCollectionLoader& other) {}
|
||||
};
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_UTIL_DWRITEFONTCOLLECTIONLOADER_H_
|
||||
#define RM_GFX_UTIL_DWRITEFONTCOLLECTIONLOADER_H_
|
||||
|
||||
#include <dwrite_1.h>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Implements the IDWriteFontCollectionLoader interface as a singleton object. When
|
||||
// CreateEnumeratorFromKey is called, a new DWriteFontFileEnumerator object is created using
|
||||
// |fontCollectionKey| (which is assumed to be a pointer to std::vector<IDWriteFontFile*>).
|
||||
class DWriteFontCollectionLoader : public IDWriteFontCollectionLoader
|
||||
{
|
||||
public:
|
||||
static DWriteFontCollectionLoader* GetInstance();
|
||||
|
||||
// IUnknown
|
||||
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID uuid, void** object) override;
|
||||
virtual ULONG STDMETHODCALLTYPE AddRef() override;
|
||||
virtual ULONG STDMETHODCALLTYPE Release() override;
|
||||
|
||||
// IFontCollectionLoader
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateEnumeratorFromKey(
|
||||
IDWriteFactory* factory, void const* fontCollectionKey, UINT32 fontCollectionKeySize,
|
||||
IDWriteFontFileEnumerator** fontFileEnumerator) override;
|
||||
|
||||
private:
|
||||
DWriteFontCollectionLoader() {}
|
||||
DWriteFontCollectionLoader(const DWriteFontCollectionLoader& other) {}
|
||||
};
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
#endif
|
@ -1,78 +1,78 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "DWriteFontFileEnumerator.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
DWriteFontFileEnumerator::DWriteFontFileEnumerator(const std::vector<IDWriteFontFile*>& fontFiles) :
|
||||
m_RefCount(1),
|
||||
m_FontFiles(fontFiles),
|
||||
m_CurrentFontFileIndex(-1)
|
||||
{
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE DWriteFontFileEnumerator::AddRef()
|
||||
{
|
||||
++m_RefCount;
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE DWriteFontFileEnumerator::Release()
|
||||
{
|
||||
--m_RefCount;
|
||||
if (m_RefCount == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE DWriteFontFileEnumerator::QueryInterface(IID const& riid, void** ppvObject)
|
||||
{
|
||||
if (riid == IID_IUnknown ||
|
||||
riid == __uuidof(IDWriteFontFileEnumerator))
|
||||
{
|
||||
*ppvObject = this;
|
||||
AddRef();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
*ppvObject = nullptr;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE DWriteFontFileEnumerator::MoveNext(BOOL* hasCurrentFile)
|
||||
{
|
||||
*hasCurrentFile = (++m_CurrentFontFileIndex < (int)m_FontFiles.size());
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE DWriteFontFileEnumerator::GetCurrentFontFile(IDWriteFontFile** fontFile)
|
||||
{
|
||||
IDWriteFontFile* currentFontFile = m_FontFiles[m_CurrentFontFileIndex];
|
||||
currentFontFile->AddRef();
|
||||
*fontFile = currentFontFile;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "DWriteFontFileEnumerator.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
DWriteFontFileEnumerator::DWriteFontFileEnumerator(const std::vector<IDWriteFontFile*>& fontFiles) :
|
||||
m_RefCount(1),
|
||||
m_FontFiles(fontFiles),
|
||||
m_CurrentFontFileIndex(-1)
|
||||
{
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE DWriteFontFileEnumerator::AddRef()
|
||||
{
|
||||
++m_RefCount;
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE DWriteFontFileEnumerator::Release()
|
||||
{
|
||||
--m_RefCount;
|
||||
if (m_RefCount == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE DWriteFontFileEnumerator::QueryInterface(IID const& riid, void** ppvObject)
|
||||
{
|
||||
if (riid == IID_IUnknown ||
|
||||
riid == __uuidof(IDWriteFontFileEnumerator))
|
||||
{
|
||||
*ppvObject = this;
|
||||
AddRef();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
*ppvObject = nullptr;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE DWriteFontFileEnumerator::MoveNext(BOOL* hasCurrentFile)
|
||||
{
|
||||
*hasCurrentFile = (++m_CurrentFontFileIndex < (int)m_FontFiles.size());
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE DWriteFontFileEnumerator::GetCurrentFontFile(IDWriteFontFile** fontFile)
|
||||
{
|
||||
IDWriteFontFile* currentFontFile = m_FontFiles[m_CurrentFontFileIndex];
|
||||
currentFontFile->AddRef();
|
||||
*fontFile = currentFontFile;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
@ -1,56 +1,56 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_UTIL_DWRITEFONTFILEENUMERATOR_H_
|
||||
#define RM_GFX_UTIL_DWRITEFONTFILEENUMERATOR_H_
|
||||
|
||||
#include <vector>
|
||||
#include <dwrite_1.h>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Implements IDWriteFontFileEnumerator by enumerating over std::vector<IDWriteFontFile*>.
|
||||
class DWriteFontFileEnumerator : public IDWriteFontFileEnumerator
|
||||
{
|
||||
public:
|
||||
DWriteFontFileEnumerator(const std::vector<IDWriteFontFile*>& fontFiles);
|
||||
|
||||
// IUnknown
|
||||
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID uuid, void** object) override;
|
||||
virtual ULONG STDMETHODCALLTYPE AddRef() override;
|
||||
virtual ULONG STDMETHODCALLTYPE Release() override;
|
||||
|
||||
// IDWriteFontFileEnumerator
|
||||
virtual HRESULT STDMETHODCALLTYPE MoveNext(BOOL* hasCurrentFile) override;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetCurrentFontFile(IDWriteFontFile** currentFontFile) override;
|
||||
|
||||
private:
|
||||
ULONG m_RefCount;
|
||||
|
||||
const std::vector<IDWriteFontFile*>& m_FontFiles;
|
||||
|
||||
// Current index of |m_FontFiles|. The type is int instead of size_t as it starts from -1 as
|
||||
// required by IDWriteFontFileEnumerator.
|
||||
int m_CurrentFontFileIndex;
|
||||
};
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_UTIL_DWRITEFONTFILEENUMERATOR_H_
|
||||
#define RM_GFX_UTIL_DWRITEFONTFILEENUMERATOR_H_
|
||||
|
||||
#include <vector>
|
||||
#include <dwrite_1.h>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Implements IDWriteFontFileEnumerator by enumerating over std::vector<IDWriteFontFile*>.
|
||||
class DWriteFontFileEnumerator : public IDWriteFontFileEnumerator
|
||||
{
|
||||
public:
|
||||
DWriteFontFileEnumerator(const std::vector<IDWriteFontFile*>& fontFiles);
|
||||
|
||||
// IUnknown
|
||||
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID uuid, void** object) override;
|
||||
virtual ULONG STDMETHODCALLTYPE AddRef() override;
|
||||
virtual ULONG STDMETHODCALLTYPE Release() override;
|
||||
|
||||
// IDWriteFontFileEnumerator
|
||||
virtual HRESULT STDMETHODCALLTYPE MoveNext(BOOL* hasCurrentFile) override;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetCurrentFontFile(IDWriteFontFile** currentFontFile) override;
|
||||
|
||||
private:
|
||||
ULONG m_RefCount;
|
||||
|
||||
const std::vector<IDWriteFontFile*>& m_FontFiles;
|
||||
|
||||
// Current index of |m_FontFiles|. The type is int instead of size_t as it starts from -1 as
|
||||
// required by IDWriteFontFileEnumerator.
|
||||
int m_CurrentFontFileIndex;
|
||||
};
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
#endif
|
@ -1,218 +1,218 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "DWriteHelpers.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
HRESULT GetDWritePropertiesFromGDIProperties(
|
||||
IDWriteFactory* factory, const WCHAR* gdiFamilyName, const bool gdiBold, const bool gdiItalic,
|
||||
DWRITE_FONT_WEIGHT& dwriteFontWeight, DWRITE_FONT_STYLE& dwriteFontStyle,
|
||||
DWRITE_FONT_STRETCH& dwriteFontStretch, WCHAR* dwriteFamilyName, UINT dwriteFamilyNameSize)
|
||||
{
|
||||
HRESULT hr = E_FAIL;
|
||||
IDWriteFont* dwriteFont = CreateDWriteFontFromGDIFamilyName(factory, gdiFamilyName);
|
||||
if (dwriteFont)
|
||||
{
|
||||
hr = GetFamilyNameFromDWriteFont(dwriteFont, dwriteFamilyName, dwriteFamilyNameSize);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
GetPropertiesFromDWriteFont(
|
||||
dwriteFont, gdiBold, gdiItalic, &dwriteFontWeight, &dwriteFontStyle, &dwriteFontStretch);
|
||||
}
|
||||
|
||||
dwriteFont->Release();
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
void GetPropertiesFromDWriteFont(
|
||||
IDWriteFont* dwriteFont, const bool bold, const bool italic,
|
||||
DWRITE_FONT_WEIGHT* dwriteFontWeight, DWRITE_FONT_STYLE* dwriteFontStyle,
|
||||
DWRITE_FONT_STRETCH* dwriteFontStretch)
|
||||
{
|
||||
*dwriteFontWeight = dwriteFont->GetWeight();
|
||||
if (bold)
|
||||
{
|
||||
if (*dwriteFontWeight == DWRITE_FONT_WEIGHT_NORMAL)
|
||||
{
|
||||
*dwriteFontWeight = DWRITE_FONT_WEIGHT_BOLD;
|
||||
}
|
||||
else if (*dwriteFontWeight < DWRITE_FONT_WEIGHT_ULTRA_BOLD)
|
||||
{
|
||||
// If 'gdiFamilyName' was e.g. 'Segoe UI Light', |dwFontWeight| wil be equal to
|
||||
// DWRITE_FONT_WEIGHT_LIGHT. If |gdiBold| is true in that case, we need to
|
||||
// increase the weight a little more for similar results with GDI+.
|
||||
// TODO: Is +100 enough?
|
||||
*dwriteFontWeight = (DWRITE_FONT_WEIGHT)(*dwriteFontWeight + 100);
|
||||
}
|
||||
}
|
||||
|
||||
*dwriteFontStyle = dwriteFont->GetStyle();
|
||||
if (italic && *dwriteFontStyle == DWRITE_FONT_STYLE_NORMAL)
|
||||
{
|
||||
*dwriteFontStyle = DWRITE_FONT_STYLE_ITALIC;
|
||||
}
|
||||
|
||||
*dwriteFontStretch = dwriteFont->GetStretch();
|
||||
}
|
||||
|
||||
IDWriteFont* CreateDWriteFontFromGDIFamilyName(IDWriteFactory* factory, const WCHAR* gdiFamilyName)
|
||||
{
|
||||
Microsoft::WRL::ComPtr<IDWriteGdiInterop> dwGdiInterop;
|
||||
HRESULT hr = factory->GetGdiInterop(dwGdiInterop.GetAddressOf());
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
LOGFONT lf = {};
|
||||
wcscpy_s(lf.lfFaceName, gdiFamilyName);
|
||||
lf.lfHeight = -12;
|
||||
lf.lfWeight = FW_DONTCARE;
|
||||
lf.lfCharSet = DEFAULT_CHARSET;
|
||||
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
|
||||
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
||||
lf.lfQuality = ANTIALIASED_QUALITY;
|
||||
lf.lfPitchAndFamily = VARIABLE_PITCH;
|
||||
|
||||
IDWriteFont* dwFont;
|
||||
hr = dwGdiInterop->CreateFontFromLOGFONT(&lf, &dwFont);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
return dwFont;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HRESULT GetFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, const UINT bufferSize)
|
||||
{
|
||||
IDWriteFontFamily* dwriteFontFamily;
|
||||
HRESULT hr = font->GetFontFamily(&dwriteFontFamily);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = GetFamilyNameFromDWriteFontFamily(dwriteFontFamily, buffer, bufferSize);
|
||||
dwriteFontFamily->Release();
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT GetFamilyNameFromDWriteFontFamily(
|
||||
IDWriteFontFamily* fontFamily, WCHAR* buffer, const UINT bufferSize)
|
||||
{
|
||||
IDWriteLocalizedStrings* dwFamilyNames;
|
||||
HRESULT hr = fontFamily->GetFamilyNames(&dwFamilyNames);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
// TODO: Determine the best index?
|
||||
hr = dwFamilyNames->GetString(0, buffer, bufferSize);
|
||||
dwFamilyNames->Release();
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
bool IsFamilyInSystemFontCollection(IDWriteFactory* factory, const WCHAR* familyName)
|
||||
{
|
||||
bool result = false;
|
||||
IDWriteFontCollection* systemFontCollection;
|
||||
HRESULT hr = factory->GetSystemFontCollection(&systemFontCollection);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
UINT32 familyNameIndex;
|
||||
BOOL familyNameFound;
|
||||
HRESULT hr = systemFontCollection->FindFamilyName(
|
||||
familyName, &familyNameIndex, &familyNameFound);
|
||||
if (SUCCEEDED(hr) && familyNameFound)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
systemFontCollection->Release();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
HRESULT GetGDIFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, UINT bufferSize)
|
||||
{
|
||||
Microsoft::WRL::ComPtr<IDWriteLocalizedStrings> strings;
|
||||
BOOL stringsExist;
|
||||
font->GetInformationalStrings(
|
||||
DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES, strings.GetAddressOf(), &stringsExist);
|
||||
if (strings && stringsExist)
|
||||
{
|
||||
return strings->GetString(0, buffer, bufferSize);
|
||||
}
|
||||
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
IDWriteFont* FindDWriteFontInFontFamilyByGDIFamilyName(
|
||||
IDWriteFontFamily* fontFamily, const WCHAR* gdiFamilyName)
|
||||
{
|
||||
const UINT32 fontFamilyFontCount = fontFamily->GetFontCount();
|
||||
for (UINT32 j = 0; j < fontFamilyFontCount; ++j)
|
||||
{
|
||||
IDWriteFont* font;
|
||||
HRESULT hr = fontFamily->GetFont(j, &font);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
WCHAR buffer[LF_FACESIZE];
|
||||
hr = GetGDIFamilyNameFromDWriteFont(font, buffer, _countof(buffer));
|
||||
if (SUCCEEDED(hr) && _wcsicmp(gdiFamilyName, buffer) == 0)
|
||||
{
|
||||
return font;
|
||||
}
|
||||
|
||||
font->Release();
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IDWriteFont* FindDWriteFontInFontCollectionByGDIFamilyName(
|
||||
IDWriteFontCollection* fontCollection, const WCHAR* gdiFamilyName)
|
||||
{
|
||||
const UINT32 fontCollectionFamilyCount = fontCollection->GetFontFamilyCount();
|
||||
for (UINT32 i = 0; i < fontCollectionFamilyCount; ++i)
|
||||
{
|
||||
IDWriteFontFamily* fontFamily;
|
||||
HRESULT hr = fontCollection->GetFontFamily(i, &fontFamily);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
IDWriteFont* font = FindDWriteFontInFontFamilyByGDIFamilyName(
|
||||
fontFamily, gdiFamilyName);
|
||||
fontFamily->Release();
|
||||
|
||||
if (font)
|
||||
{
|
||||
return font;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "DWriteHelpers.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
HRESULT GetDWritePropertiesFromGDIProperties(
|
||||
IDWriteFactory* factory, const WCHAR* gdiFamilyName, const bool gdiBold, const bool gdiItalic,
|
||||
DWRITE_FONT_WEIGHT& dwriteFontWeight, DWRITE_FONT_STYLE& dwriteFontStyle,
|
||||
DWRITE_FONT_STRETCH& dwriteFontStretch, WCHAR* dwriteFamilyName, UINT dwriteFamilyNameSize)
|
||||
{
|
||||
HRESULT hr = E_FAIL;
|
||||
IDWriteFont* dwriteFont = CreateDWriteFontFromGDIFamilyName(factory, gdiFamilyName);
|
||||
if (dwriteFont)
|
||||
{
|
||||
hr = GetFamilyNameFromDWriteFont(dwriteFont, dwriteFamilyName, dwriteFamilyNameSize);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
GetPropertiesFromDWriteFont(
|
||||
dwriteFont, gdiBold, gdiItalic, &dwriteFontWeight, &dwriteFontStyle, &dwriteFontStretch);
|
||||
}
|
||||
|
||||
dwriteFont->Release();
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
void GetPropertiesFromDWriteFont(
|
||||
IDWriteFont* dwriteFont, const bool bold, const bool italic,
|
||||
DWRITE_FONT_WEIGHT* dwriteFontWeight, DWRITE_FONT_STYLE* dwriteFontStyle,
|
||||
DWRITE_FONT_STRETCH* dwriteFontStretch)
|
||||
{
|
||||
*dwriteFontWeight = dwriteFont->GetWeight();
|
||||
if (bold)
|
||||
{
|
||||
if (*dwriteFontWeight == DWRITE_FONT_WEIGHT_NORMAL)
|
||||
{
|
||||
*dwriteFontWeight = DWRITE_FONT_WEIGHT_BOLD;
|
||||
}
|
||||
else if (*dwriteFontWeight < DWRITE_FONT_WEIGHT_ULTRA_BOLD)
|
||||
{
|
||||
// If 'gdiFamilyName' was e.g. 'Segoe UI Light', |dwFontWeight| wil be equal to
|
||||
// DWRITE_FONT_WEIGHT_LIGHT. If |gdiBold| is true in that case, we need to
|
||||
// increase the weight a little more for similar results with GDI+.
|
||||
// TODO: Is +100 enough?
|
||||
*dwriteFontWeight = (DWRITE_FONT_WEIGHT)(*dwriteFontWeight + 100);
|
||||
}
|
||||
}
|
||||
|
||||
*dwriteFontStyle = dwriteFont->GetStyle();
|
||||
if (italic && *dwriteFontStyle == DWRITE_FONT_STYLE_NORMAL)
|
||||
{
|
||||
*dwriteFontStyle = DWRITE_FONT_STYLE_ITALIC;
|
||||
}
|
||||
|
||||
*dwriteFontStretch = dwriteFont->GetStretch();
|
||||
}
|
||||
|
||||
IDWriteFont* CreateDWriteFontFromGDIFamilyName(IDWriteFactory* factory, const WCHAR* gdiFamilyName)
|
||||
{
|
||||
Microsoft::WRL::ComPtr<IDWriteGdiInterop> dwGdiInterop;
|
||||
HRESULT hr = factory->GetGdiInterop(dwGdiInterop.GetAddressOf());
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
LOGFONT lf = {};
|
||||
wcscpy_s(lf.lfFaceName, gdiFamilyName);
|
||||
lf.lfHeight = -12;
|
||||
lf.lfWeight = FW_DONTCARE;
|
||||
lf.lfCharSet = DEFAULT_CHARSET;
|
||||
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
|
||||
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
||||
lf.lfQuality = ANTIALIASED_QUALITY;
|
||||
lf.lfPitchAndFamily = VARIABLE_PITCH;
|
||||
|
||||
IDWriteFont* dwFont;
|
||||
hr = dwGdiInterop->CreateFontFromLOGFONT(&lf, &dwFont);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
return dwFont;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HRESULT GetFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, const UINT bufferSize)
|
||||
{
|
||||
IDWriteFontFamily* dwriteFontFamily;
|
||||
HRESULT hr = font->GetFontFamily(&dwriteFontFamily);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = GetFamilyNameFromDWriteFontFamily(dwriteFontFamily, buffer, bufferSize);
|
||||
dwriteFontFamily->Release();
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT GetFamilyNameFromDWriteFontFamily(
|
||||
IDWriteFontFamily* fontFamily, WCHAR* buffer, const UINT bufferSize)
|
||||
{
|
||||
IDWriteLocalizedStrings* dwFamilyNames;
|
||||
HRESULT hr = fontFamily->GetFamilyNames(&dwFamilyNames);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
// TODO: Determine the best index?
|
||||
hr = dwFamilyNames->GetString(0, buffer, bufferSize);
|
||||
dwFamilyNames->Release();
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
bool IsFamilyInSystemFontCollection(IDWriteFactory* factory, const WCHAR* familyName)
|
||||
{
|
||||
bool result = false;
|
||||
IDWriteFontCollection* systemFontCollection;
|
||||
HRESULT hr = factory->GetSystemFontCollection(&systemFontCollection);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
UINT32 familyNameIndex;
|
||||
BOOL familyNameFound;
|
||||
HRESULT hr = systemFontCollection->FindFamilyName(
|
||||
familyName, &familyNameIndex, &familyNameFound);
|
||||
if (SUCCEEDED(hr) && familyNameFound)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
systemFontCollection->Release();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
HRESULT GetGDIFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, UINT bufferSize)
|
||||
{
|
||||
Microsoft::WRL::ComPtr<IDWriteLocalizedStrings> strings;
|
||||
BOOL stringsExist;
|
||||
font->GetInformationalStrings(
|
||||
DWRITE_INFORMATIONAL_STRING_WIN32_FAMILY_NAMES, strings.GetAddressOf(), &stringsExist);
|
||||
if (strings && stringsExist)
|
||||
{
|
||||
return strings->GetString(0, buffer, bufferSize);
|
||||
}
|
||||
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
IDWriteFont* FindDWriteFontInFontFamilyByGDIFamilyName(
|
||||
IDWriteFontFamily* fontFamily, const WCHAR* gdiFamilyName)
|
||||
{
|
||||
const UINT32 fontFamilyFontCount = fontFamily->GetFontCount();
|
||||
for (UINT32 j = 0; j < fontFamilyFontCount; ++j)
|
||||
{
|
||||
IDWriteFont* font;
|
||||
HRESULT hr = fontFamily->GetFont(j, &font);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
WCHAR buffer[LF_FACESIZE];
|
||||
hr = GetGDIFamilyNameFromDWriteFont(font, buffer, _countof(buffer));
|
||||
if (SUCCEEDED(hr) && _wcsicmp(gdiFamilyName, buffer) == 0)
|
||||
{
|
||||
return font;
|
||||
}
|
||||
|
||||
font->Release();
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IDWriteFont* FindDWriteFontInFontCollectionByGDIFamilyName(
|
||||
IDWriteFontCollection* fontCollection, const WCHAR* gdiFamilyName)
|
||||
{
|
||||
const UINT32 fontCollectionFamilyCount = fontCollection->GetFontFamilyCount();
|
||||
for (UINT32 i = 0; i < fontCollectionFamilyCount; ++i)
|
||||
{
|
||||
IDWriteFontFamily* fontFamily;
|
||||
HRESULT hr = fontCollection->GetFontFamily(i, &fontFamily);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
IDWriteFont* font = FindDWriteFontInFontFamilyByGDIFamilyName(
|
||||
fontFamily, gdiFamilyName);
|
||||
fontFamily->Release();
|
||||
|
||||
if (font)
|
||||
{
|
||||
return font;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
@ -1,58 +1,58 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_UTIL_DWRITEHELPERS_H_
|
||||
#define RM_GFX_UTIL_DWRITEHELPERS_H_
|
||||
|
||||
#include <dwrite_1.h>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Maps the GDI family name and italic/bold flags to the DirectWrite family name, weight, style,
|
||||
// and stretch.
|
||||
HRESULT GetDWritePropertiesFromGDIProperties(
|
||||
IDWriteFactory* factory, const WCHAR* gdiFamilyName, const bool gdiBold, const bool gdiItalic,
|
||||
DWRITE_FONT_WEIGHT& dwriteFontWeight, DWRITE_FONT_STYLE& dwriteFontStyle,
|
||||
DWRITE_FONT_STRETCH& dwriteFontStretch, WCHAR* dwriteFamilyName, UINT dwriteFamilyNameSize);
|
||||
|
||||
void GetPropertiesFromDWriteFont(
|
||||
IDWriteFont* dwriteFont, const bool bold, const bool italic,
|
||||
DWRITE_FONT_WEIGHT* dwriteFontWeight, DWRITE_FONT_STYLE* dwriteFontStyle,
|
||||
DWRITE_FONT_STRETCH* dwriteFontStretch);
|
||||
|
||||
// Creates a IDWriteFont using the GDI family name instead of the DirectWrite family name. For
|
||||
// example, 'Segoe UI' and 'Segoe UI Semibold' are separate family names with GDI whereas
|
||||
// DirectWrite uses the family name 'Segoe UI' for both and differentiates them by the font
|
||||
// style.
|
||||
IDWriteFont* CreateDWriteFontFromGDIFamilyName(IDWriteFactory* factory, const WCHAR* fontFamily);
|
||||
|
||||
HRESULT GetFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, UINT bufferSize);
|
||||
|
||||
HRESULT GetFamilyNameFromDWriteFontFamily(
|
||||
IDWriteFontFamily* fontFamily, WCHAR* buffer, UINT bufferSize);
|
||||
|
||||
bool IsFamilyInSystemFontCollection(IDWriteFactory* factory, const WCHAR* familyName);
|
||||
|
||||
IDWriteFont* FindDWriteFontInFontCollectionByGDIFamilyName(
|
||||
IDWriteFontCollection* fontCollection, const WCHAR* gdiFamilyName);
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_UTIL_DWRITEHELPERS_H_
|
||||
#define RM_GFX_UTIL_DWRITEHELPERS_H_
|
||||
|
||||
#include <dwrite_1.h>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Maps the GDI family name and italic/bold flags to the DirectWrite family name, weight, style,
|
||||
// and stretch.
|
||||
HRESULT GetDWritePropertiesFromGDIProperties(
|
||||
IDWriteFactory* factory, const WCHAR* gdiFamilyName, const bool gdiBold, const bool gdiItalic,
|
||||
DWRITE_FONT_WEIGHT& dwriteFontWeight, DWRITE_FONT_STYLE& dwriteFontStyle,
|
||||
DWRITE_FONT_STRETCH& dwriteFontStretch, WCHAR* dwriteFamilyName, UINT dwriteFamilyNameSize);
|
||||
|
||||
void GetPropertiesFromDWriteFont(
|
||||
IDWriteFont* dwriteFont, const bool bold, const bool italic,
|
||||
DWRITE_FONT_WEIGHT* dwriteFontWeight, DWRITE_FONT_STYLE* dwriteFontStyle,
|
||||
DWRITE_FONT_STRETCH* dwriteFontStretch);
|
||||
|
||||
// Creates a IDWriteFont using the GDI family name instead of the DirectWrite family name. For
|
||||
// example, 'Segoe UI' and 'Segoe UI Semibold' are separate family names with GDI whereas
|
||||
// DirectWrite uses the family name 'Segoe UI' for both and differentiates them by the font
|
||||
// style.
|
||||
IDWriteFont* CreateDWriteFontFromGDIFamilyName(IDWriteFactory* factory, const WCHAR* fontFamily);
|
||||
|
||||
HRESULT GetFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, UINT bufferSize);
|
||||
|
||||
HRESULT GetFamilyNameFromDWriteFontFamily(
|
||||
IDWriteFontFamily* fontFamily, WCHAR* buffer, UINT bufferSize);
|
||||
|
||||
bool IsFamilyInSystemFontCollection(IDWriteFactory* factory, const WCHAR* familyName);
|
||||
|
||||
IDWriteFont* FindDWriteFontInFontCollectionByGDIFamilyName(
|
||||
IDWriteFontCollection* fontCollection, const WCHAR* gdiFamilyName);
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
#endif
|
@ -1,136 +1,136 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "WICBitmapDIB.h"
|
||||
#include "WICBitmapLockDIB.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
WICBitmapDIB::WICBitmapDIB() :
|
||||
m_DIBSectionBuffer(),
|
||||
m_DIBSectionBufferPixels(),
|
||||
m_W(0),
|
||||
m_H(0)
|
||||
{
|
||||
}
|
||||
|
||||
WICBitmapDIB::~WICBitmapDIB()
|
||||
{
|
||||
if (m_DIBSectionBuffer)
|
||||
{
|
||||
DeleteObject(m_DIBSectionBuffer);
|
||||
m_DIBSectionBufferPixels = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void WICBitmapDIB::Resize(UINT w, UINT h)
|
||||
{
|
||||
if (m_DIBSectionBuffer)
|
||||
{
|
||||
DeleteObject(m_DIBSectionBuffer);
|
||||
m_DIBSectionBufferPixels = nullptr;
|
||||
}
|
||||
|
||||
m_W = w;
|
||||
m_H = h;
|
||||
|
||||
BITMAPV4HEADER bh = {sizeof(BITMAPV4HEADER)};
|
||||
bh.bV4Width = (LONG)m_W;
|
||||
bh.bV4Height = -(LONG)m_H; // Top-down DIB
|
||||
bh.bV4Planes = 1;
|
||||
bh.bV4BitCount = 32;
|
||||
bh.bV4V4Compression = BI_BITFIELDS;
|
||||
bh.bV4RedMask = 0x00FF0000;
|
||||
bh.bV4GreenMask = 0x0000FF00;
|
||||
bh.bV4BlueMask = 0x000000FF;
|
||||
bh.bV4AlphaMask = 0xFF000000;
|
||||
|
||||
m_DIBSectionBuffer = CreateDIBSection(
|
||||
nullptr,
|
||||
(BITMAPINFO*)&bh,
|
||||
DIB_RGB_COLORS,
|
||||
(void**)&m_DIBSectionBufferPixels,
|
||||
nullptr,
|
||||
0);
|
||||
|
||||
assert(m_DIBSectionBufferPixels);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::QueryInterface(REFIID riid, void** ppvObject)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapDIB::AddRef()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapDIB::Release()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::GetSize(UINT* puiWidth, UINT* puiHeight)
|
||||
{
|
||||
if (puiWidth) *puiWidth = m_W;
|
||||
if (puiHeight) *puiHeight = m_H;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::GetPixelFormat(WICPixelFormatGUID* pPixelFormat)
|
||||
{
|
||||
*pPixelFormat = GUID_WICPixelFormat32bppPBGRA;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::GetResolution(double* pDpiX, double* pDpiY)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::CopyPalette(IWICPalette* pIPalette)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::CopyPixels(const WICRect* prc, UINT cbStride, UINT cbBufferSize, BYTE* pbBuffer)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::Lock(const WICRect* prcLock, DWORD flags, IWICBitmapLock** ppILock)
|
||||
{
|
||||
if (ppILock) *ppILock = (IWICBitmapLock*)new WICBitmapLockDIB(this, prcLock);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::SetPalette(IWICPalette* pIPalette)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::SetResolution(double dpiX, double dpiY)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "WICBitmapDIB.h"
|
||||
#include "WICBitmapLockDIB.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
WICBitmapDIB::WICBitmapDIB() :
|
||||
m_DIBSectionBuffer(),
|
||||
m_DIBSectionBufferPixels(),
|
||||
m_W(0),
|
||||
m_H(0)
|
||||
{
|
||||
}
|
||||
|
||||
WICBitmapDIB::~WICBitmapDIB()
|
||||
{
|
||||
if (m_DIBSectionBuffer)
|
||||
{
|
||||
DeleteObject(m_DIBSectionBuffer);
|
||||
m_DIBSectionBufferPixels = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void WICBitmapDIB::Resize(UINT w, UINT h)
|
||||
{
|
||||
if (m_DIBSectionBuffer)
|
||||
{
|
||||
DeleteObject(m_DIBSectionBuffer);
|
||||
m_DIBSectionBufferPixels = nullptr;
|
||||
}
|
||||
|
||||
m_W = w;
|
||||
m_H = h;
|
||||
|
||||
BITMAPV4HEADER bh = {sizeof(BITMAPV4HEADER)};
|
||||
bh.bV4Width = (LONG)m_W;
|
||||
bh.bV4Height = -(LONG)m_H; // Top-down DIB
|
||||
bh.bV4Planes = 1;
|
||||
bh.bV4BitCount = 32;
|
||||
bh.bV4V4Compression = BI_BITFIELDS;
|
||||
bh.bV4RedMask = 0x00FF0000;
|
||||
bh.bV4GreenMask = 0x0000FF00;
|
||||
bh.bV4BlueMask = 0x000000FF;
|
||||
bh.bV4AlphaMask = 0xFF000000;
|
||||
|
||||
m_DIBSectionBuffer = CreateDIBSection(
|
||||
nullptr,
|
||||
(BITMAPINFO*)&bh,
|
||||
DIB_RGB_COLORS,
|
||||
(void**)&m_DIBSectionBufferPixels,
|
||||
nullptr,
|
||||
0);
|
||||
|
||||
assert(m_DIBSectionBufferPixels);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::QueryInterface(REFIID riid, void** ppvObject)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapDIB::AddRef()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapDIB::Release()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::GetSize(UINT* puiWidth, UINT* puiHeight)
|
||||
{
|
||||
if (puiWidth) *puiWidth = m_W;
|
||||
if (puiHeight) *puiHeight = m_H;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::GetPixelFormat(WICPixelFormatGUID* pPixelFormat)
|
||||
{
|
||||
*pPixelFormat = GUID_WICPixelFormat32bppPBGRA;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::GetResolution(double* pDpiX, double* pDpiY)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::CopyPalette(IWICPalette* pIPalette)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::CopyPixels(const WICRect* prc, UINT cbStride, UINT cbBufferSize, BYTE* pbBuffer)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::Lock(const WICRect* prcLock, DWORD flags, IWICBitmapLock** ppILock)
|
||||
{
|
||||
if (ppILock) *ppILock = (IWICBitmapLock*)new WICBitmapLockDIB(this, prcLock);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::SetPalette(IWICPalette* pIPalette)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapDIB::SetResolution(double dpiX, double dpiY)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
@ -1,76 +1,76 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_UTIL_WICBITMAPDIB_H_
|
||||
#define RM_GFX_UTIL_WICBITMAPDIB_H_
|
||||
|
||||
#include <Windows.h>
|
||||
#include <wincodec.h>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Allows the use of a DIB section (HBITMAP) in Direct2D as a WIC bitmap. It is assumed that this
|
||||
// class is used only with 32bpp PARGB bitmaps and using a sigle thread.
|
||||
//
|
||||
// This class does not follow the COM reference count model. RTTI is used instead. This class
|
||||
// implements only the bare essentials in order to use a DIB section as a Direct2D render target.
|
||||
class WICBitmapDIB : public IWICBitmap
|
||||
{
|
||||
public:
|
||||
WICBitmapDIB();
|
||||
~WICBitmapDIB();
|
||||
|
||||
WICBitmapDIB(const WICBitmapDIB& other) = delete;
|
||||
WICBitmapDIB& operator=(WICBitmapDIB other) = delete;
|
||||
|
||||
void Resize(UINT w, UINT h);
|
||||
|
||||
HBITMAP GetHandle() const { return m_DIBSectionBuffer; }
|
||||
BYTE* GetData() const { return (BYTE*)m_DIBSectionBufferPixels; }
|
||||
|
||||
// IUnknown
|
||||
IFACEMETHOD(QueryInterface)(REFIID riid, void** ppvObject);
|
||||
IFACEMETHOD_(ULONG, AddRef)();
|
||||
IFACEMETHOD_(ULONG, Release)();
|
||||
|
||||
// IWICBitmapSource
|
||||
IFACEMETHOD(GetSize)(UINT* puiWidth, UINT* puiHeight);
|
||||
IFACEMETHOD(GetPixelFormat)(WICPixelFormatGUID* pPixelFormat);
|
||||
IFACEMETHOD(GetResolution)(double* pDpiX, double* pDpiY);
|
||||
IFACEMETHOD(CopyPalette)(IWICPalette* pIPalette);
|
||||
IFACEMETHOD(CopyPixels)(const WICRect* prc, UINT cbStride, UINT cbBufferSize, BYTE* pbBuffer);
|
||||
|
||||
// IWICBitmap
|
||||
IFACEMETHOD(Lock)(const WICRect* prcLock, DWORD flags, IWICBitmapLock** ppILock);
|
||||
IFACEMETHOD(SetPalette)(IWICPalette* pIPalette);
|
||||
IFACEMETHOD(SetResolution)(double dpiX, double dpiY);
|
||||
|
||||
private:
|
||||
friend class WICBitmapLockDIB;
|
||||
|
||||
HBITMAP m_DIBSectionBuffer;
|
||||
LPDWORD m_DIBSectionBufferPixels;
|
||||
UINT m_W;
|
||||
UINT m_H;
|
||||
};
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_UTIL_WICBITMAPDIB_H_
|
||||
#define RM_GFX_UTIL_WICBITMAPDIB_H_
|
||||
|
||||
#include <Windows.h>
|
||||
#include <wincodec.h>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Allows the use of a DIB section (HBITMAP) in Direct2D as a WIC bitmap. It is assumed that this
|
||||
// class is used only with 32bpp PARGB bitmaps and using a sigle thread.
|
||||
//
|
||||
// This class does not follow the COM reference count model. RTTI is used instead. This class
|
||||
// implements only the bare essentials in order to use a DIB section as a Direct2D render target.
|
||||
class WICBitmapDIB : public IWICBitmap
|
||||
{
|
||||
public:
|
||||
WICBitmapDIB();
|
||||
~WICBitmapDIB();
|
||||
|
||||
WICBitmapDIB(const WICBitmapDIB& other) = delete;
|
||||
WICBitmapDIB& operator=(WICBitmapDIB other) = delete;
|
||||
|
||||
void Resize(UINT w, UINT h);
|
||||
|
||||
HBITMAP GetHandle() const { return m_DIBSectionBuffer; }
|
||||
BYTE* GetData() const { return (BYTE*)m_DIBSectionBufferPixels; }
|
||||
|
||||
// IUnknown
|
||||
IFACEMETHOD(QueryInterface)(REFIID riid, void** ppvObject);
|
||||
IFACEMETHOD_(ULONG, AddRef)();
|
||||
IFACEMETHOD_(ULONG, Release)();
|
||||
|
||||
// IWICBitmapSource
|
||||
IFACEMETHOD(GetSize)(UINT* puiWidth, UINT* puiHeight);
|
||||
IFACEMETHOD(GetPixelFormat)(WICPixelFormatGUID* pPixelFormat);
|
||||
IFACEMETHOD(GetResolution)(double* pDpiX, double* pDpiY);
|
||||
IFACEMETHOD(CopyPalette)(IWICPalette* pIPalette);
|
||||
IFACEMETHOD(CopyPixels)(const WICRect* prc, UINT cbStride, UINT cbBufferSize, BYTE* pbBuffer);
|
||||
|
||||
// IWICBitmap
|
||||
IFACEMETHOD(Lock)(const WICRect* prcLock, DWORD flags, IWICBitmapLock** ppILock);
|
||||
IFACEMETHOD(SetPalette)(IWICPalette* pIPalette);
|
||||
IFACEMETHOD(SetResolution)(double dpiX, double dpiY);
|
||||
|
||||
private:
|
||||
friend class WICBitmapLockDIB;
|
||||
|
||||
HBITMAP m_DIBSectionBuffer;
|
||||
LPDWORD m_DIBSectionBufferPixels;
|
||||
UINT m_W;
|
||||
UINT m_H;
|
||||
};
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
#endif
|
@ -1,91 +1,91 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "WICBitmapLockDIB.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
WICBitmapLockDIB::WICBitmapLockDIB(WICBitmapDIB* bitmap, const WICRect* lockRect) :
|
||||
m_Bitmap(bitmap),
|
||||
m_Rect(lockRect),
|
||||
m_RefCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
WICBitmapLockDIB::~WICBitmapLockDIB()
|
||||
{
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::QueryInterface(REFIID riid, void** ppvObject)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapLockDIB::AddRef()
|
||||
{
|
||||
++m_RefCount;
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapLockDIB::Release()
|
||||
{
|
||||
--m_RefCount;
|
||||
if (m_RefCount == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::GetSize(UINT* puiWidth, UINT* puiHeight)
|
||||
{
|
||||
return m_Bitmap->GetSize(puiWidth, puiHeight);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::GetStride(UINT* pcbStride)
|
||||
{
|
||||
UINT width = 0;
|
||||
m_Bitmap->GetSize(&width, nullptr);
|
||||
|
||||
if (pcbStride) *pcbStride = (width * 32 + 31) / 32 * 4;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::GetDataPointer(UINT* pcbBufferSize, BYTE** ppbData)
|
||||
{
|
||||
UINT stride = 0;
|
||||
GetStride(&stride);
|
||||
|
||||
if (pcbBufferSize) *pcbBufferSize = stride * m_Rect->Height;
|
||||
if (ppbData) *ppbData = (BYTE*)&m_Bitmap->m_DIBSectionBufferPixels[m_Rect->Y * m_Rect->Width + m_Rect->X];
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::GetPixelFormat(WICPixelFormatGUID* pPixelFormat)
|
||||
{
|
||||
return m_Bitmap->GetPixelFormat(pPixelFormat);
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "WICBitmapLockDIB.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
WICBitmapLockDIB::WICBitmapLockDIB(WICBitmapDIB* bitmap, const WICRect* lockRect) :
|
||||
m_Bitmap(bitmap),
|
||||
m_Rect(lockRect),
|
||||
m_RefCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
WICBitmapLockDIB::~WICBitmapLockDIB()
|
||||
{
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::QueryInterface(REFIID riid, void** ppvObject)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapLockDIB::AddRef()
|
||||
{
|
||||
++m_RefCount;
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapLockDIB::Release()
|
||||
{
|
||||
--m_RefCount;
|
||||
if (m_RefCount == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::GetSize(UINT* puiWidth, UINT* puiHeight)
|
||||
{
|
||||
return m_Bitmap->GetSize(puiWidth, puiHeight);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::GetStride(UINT* pcbStride)
|
||||
{
|
||||
UINT width = 0;
|
||||
m_Bitmap->GetSize(&width, nullptr);
|
||||
|
||||
if (pcbStride) *pcbStride = (width * 32 + 31) / 32 * 4;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::GetDataPointer(UINT* pcbBufferSize, BYTE** ppbData)
|
||||
{
|
||||
UINT stride = 0;
|
||||
GetStride(&stride);
|
||||
|
||||
if (pcbBufferSize) *pcbBufferSize = stride * m_Rect->Height;
|
||||
if (ppbData) *ppbData = (BYTE*)&m_Bitmap->m_DIBSectionBufferPixels[m_Rect->Y * m_Rect->Width + m_Rect->X];
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockDIB::GetPixelFormat(WICPixelFormatGUID* pPixelFormat)
|
||||
{
|
||||
return m_Bitmap->GetPixelFormat(pPixelFormat);
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
@ -1,62 +1,62 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_UTIL_WICBITMAPLOCKDIB_H_
|
||||
#define RM_GFX_UTIL_WICBITMAPLOCKDIB_H_
|
||||
|
||||
#include <Windows.h>
|
||||
#include <wincodec.h>
|
||||
#include "WICBitmapDIB.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Implements the IWICBitmapLock interface for use with WICBitmapDIB. It is assumed that this
|
||||
// class is used only with 32bpp PARGB bitmaps and using a sigle thread.
|
||||
class WICBitmapLockDIB : public IWICBitmapLock
|
||||
{
|
||||
public:
|
||||
WICBitmapLockDIB(WICBitmapDIB* bitmap, const WICRect* lockRect);
|
||||
virtual ~WICBitmapLockDIB();
|
||||
|
||||
void Resize(UINT w, UINT h);
|
||||
|
||||
// IUnknown
|
||||
IFACEMETHOD(QueryInterface)(REFIID riid, void** ppvObject);
|
||||
IFACEMETHOD_(ULONG, AddRef)();
|
||||
IFACEMETHOD_(ULONG, Release)();
|
||||
|
||||
// IWICBitmapLock
|
||||
IFACEMETHOD(GetSize)(UINT* puiWidth, UINT* puiHeight);
|
||||
IFACEMETHOD(GetStride)(UINT* pcbStride);
|
||||
IFACEMETHOD(GetDataPointer)(UINT* pcbBufferSize, BYTE** ppbData);
|
||||
IFACEMETHOD(GetPixelFormat)(WICPixelFormatGUID* pPixelFormat);
|
||||
|
||||
private:
|
||||
WICBitmapLockDIB(const WICBitmapLockDIB& other) = delete;
|
||||
WICBitmapLockDIB& operator=(WICBitmapLockDIB other) = delete;
|
||||
|
||||
WICBitmapDIB* m_Bitmap;
|
||||
const WICRect* m_Rect;
|
||||
UINT m_RefCount;
|
||||
};
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_UTIL_WICBITMAPLOCKDIB_H_
|
||||
#define RM_GFX_UTIL_WICBITMAPLOCKDIB_H_
|
||||
|
||||
#include <Windows.h>
|
||||
#include <wincodec.h>
|
||||
#include "WICBitmapDIB.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Implements the IWICBitmapLock interface for use with WICBitmapDIB. It is assumed that this
|
||||
// class is used only with 32bpp PARGB bitmaps and using a sigle thread.
|
||||
class WICBitmapLockDIB : public IWICBitmapLock
|
||||
{
|
||||
public:
|
||||
WICBitmapLockDIB(WICBitmapDIB* bitmap, const WICRect* lockRect);
|
||||
virtual ~WICBitmapLockDIB();
|
||||
|
||||
void Resize(UINT w, UINT h);
|
||||
|
||||
// IUnknown
|
||||
IFACEMETHOD(QueryInterface)(REFIID riid, void** ppvObject);
|
||||
IFACEMETHOD_(ULONG, AddRef)();
|
||||
IFACEMETHOD_(ULONG, Release)();
|
||||
|
||||
// IWICBitmapLock
|
||||
IFACEMETHOD(GetSize)(UINT* puiWidth, UINT* puiHeight);
|
||||
IFACEMETHOD(GetStride)(UINT* pcbStride);
|
||||
IFACEMETHOD(GetDataPointer)(UINT* pcbBufferSize, BYTE** ppbData);
|
||||
IFACEMETHOD(GetPixelFormat)(WICPixelFormatGUID* pPixelFormat);
|
||||
|
||||
private:
|
||||
WICBitmapLockDIB(const WICBitmapLockDIB& other) = delete;
|
||||
WICBitmapLockDIB& operator=(WICBitmapLockDIB other) = delete;
|
||||
|
||||
WICBitmapDIB* m_Bitmap;
|
||||
const WICRect* m_Rect;
|
||||
UINT m_RefCount;
|
||||
};
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
#endif
|
@ -1,82 +1,82 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "WICBitmapLockGDIP.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
WICBitmapLockGDIP::WICBitmapLockGDIP() :
|
||||
m_RefCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::QueryInterface(REFIID riid, void** ppvObject)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapLockGDIP::AddRef()
|
||||
{
|
||||
++m_RefCount;
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapLockGDIP::Release()
|
||||
{
|
||||
--m_RefCount;
|
||||
if (m_RefCount == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::GetSize(UINT* puiWidth, UINT* puiHeight)
|
||||
{
|
||||
*puiWidth = m_BitmapData.Width;
|
||||
*puiHeight = m_BitmapData.Height;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::GetStride(UINT* pcbStride)
|
||||
{
|
||||
*pcbStride = m_BitmapData.Stride;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::GetDataPointer(UINT* pcbBufferSize, BYTE** ppbData)
|
||||
{
|
||||
assert(m_BitmapData.PixelFormat == PixelFormat32bppPARGB);
|
||||
*pcbBufferSize = m_BitmapData.Stride * m_BitmapData.Height;
|
||||
*ppbData = (BYTE*)m_BitmapData.Scan0;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::GetPixelFormat(WICPixelFormatGUID* pPixelFormat)
|
||||
{
|
||||
assert(m_BitmapData.PixelFormat == PixelFormat32bppPARGB);
|
||||
*pPixelFormat = GUID_WICPixelFormat32bppPBGRA;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "WICBitmapLockGDIP.h"
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
WICBitmapLockGDIP::WICBitmapLockGDIP() :
|
||||
m_RefCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::QueryInterface(REFIID riid, void** ppvObject)
|
||||
{
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapLockGDIP::AddRef()
|
||||
{
|
||||
++m_RefCount;
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) WICBitmapLockGDIP::Release()
|
||||
{
|
||||
--m_RefCount;
|
||||
if (m_RefCount == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_RefCount;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::GetSize(UINT* puiWidth, UINT* puiHeight)
|
||||
{
|
||||
*puiWidth = m_BitmapData.Width;
|
||||
*puiHeight = m_BitmapData.Height;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::GetStride(UINT* pcbStride)
|
||||
{
|
||||
*pcbStride = m_BitmapData.Stride;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::GetDataPointer(UINT* pcbBufferSize, BYTE** ppbData)
|
||||
{
|
||||
assert(m_BitmapData.PixelFormat == PixelFormat32bppPARGB);
|
||||
*pcbBufferSize = m_BitmapData.Stride * m_BitmapData.Height;
|
||||
*ppbData = (BYTE*)m_BitmapData.Scan0;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
IFACEMETHODIMP WICBitmapLockGDIP::GetPixelFormat(WICPixelFormatGUID* pPixelFormat)
|
||||
{
|
||||
assert(m_BitmapData.PixelFormat == PixelFormat32bppPARGB);
|
||||
*pPixelFormat = GUID_WICPixelFormat32bppPBGRA;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
@ -1,61 +1,61 @@
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_UTIL_WICBITMAPLOCKGDIP_H_
|
||||
#define RM_GFX_UTIL_WICBITMAPLOCKGDIP_H_
|
||||
|
||||
#include <Windows.h>
|
||||
#include <ole2.h> // For Gdiplus.h.
|
||||
#include <GdiPlus.h>
|
||||
#include <wincodec.h>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Allows the creation of a shared ID2D1Bitmap using pixel data in a Gdiplus::Bitmap. It is
|
||||
// assumed that this class is used only with 32bpp PARGB bitmaps and using a sigle thread.
|
||||
class WICBitmapLockGDIP : public IWICBitmapLock
|
||||
{
|
||||
public:
|
||||
WICBitmapLockGDIP();
|
||||
|
||||
Gdiplus::BitmapData* GetBitmapData() { return &m_BitmapData; }
|
||||
|
||||
// IUnknown
|
||||
IFACEMETHOD(QueryInterface)(REFIID riid, void** ppvObject);
|
||||
IFACEMETHOD_(ULONG, AddRef)();
|
||||
IFACEMETHOD_(ULONG, Release)();
|
||||
|
||||
// IWICBitmapLock
|
||||
IFACEMETHOD(GetSize)(UINT* puiWidth, UINT* puiHeight);
|
||||
IFACEMETHOD(GetStride)(UINT* pcbStride);
|
||||
IFACEMETHOD(GetDataPointer)(UINT* pcbBufferSize, BYTE** ppbData);
|
||||
IFACEMETHOD(GetPixelFormat)(WICPixelFormatGUID* pPixelFormat);
|
||||
|
||||
private:
|
||||
WICBitmapLockGDIP(const WICBitmapLockGDIP& other) = delete;
|
||||
WICBitmapLockGDIP& operator=(WICBitmapLockGDIP other) = delete;
|
||||
|
||||
Gdiplus::BitmapData m_BitmapData;
|
||||
UINT m_RefCount;
|
||||
};
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
/*
|
||||
Copyright (C) 2013 Birunthan Mohanathas
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef RM_GFX_UTIL_WICBITMAPLOCKGDIP_H_
|
||||
#define RM_GFX_UTIL_WICBITMAPLOCKGDIP_H_
|
||||
|
||||
#include <Windows.h>
|
||||
#include <ole2.h> // For Gdiplus.h.
|
||||
#include <GdiPlus.h>
|
||||
#include <wincodec.h>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// Allows the creation of a shared ID2D1Bitmap using pixel data in a Gdiplus::Bitmap. It is
|
||||
// assumed that this class is used only with 32bpp PARGB bitmaps and using a sigle thread.
|
||||
class WICBitmapLockGDIP : public IWICBitmapLock
|
||||
{
|
||||
public:
|
||||
WICBitmapLockGDIP();
|
||||
|
||||
Gdiplus::BitmapData* GetBitmapData() { return &m_BitmapData; }
|
||||
|
||||
// IUnknown
|
||||
IFACEMETHOD(QueryInterface)(REFIID riid, void** ppvObject);
|
||||
IFACEMETHOD_(ULONG, AddRef)();
|
||||
IFACEMETHOD_(ULONG, Release)();
|
||||
|
||||
// IWICBitmapLock
|
||||
IFACEMETHOD(GetSize)(UINT* puiWidth, UINT* puiHeight);
|
||||
IFACEMETHOD(GetStride)(UINT* pcbStride);
|
||||
IFACEMETHOD(GetDataPointer)(UINT* pcbBufferSize, BYTE** ppbData);
|
||||
IFACEMETHOD(GetPixelFormat)(WICPixelFormatGUID* pPixelFormat);
|
||||
|
||||
private:
|
||||
WICBitmapLockGDIP(const WICBitmapLockGDIP& other) = delete;
|
||||
WICBitmapLockGDIP& operator=(WICBitmapLockGDIP other) = delete;
|
||||
|
||||
Gdiplus::BitmapData m_BitmapData;
|
||||
UINT m_RefCount;
|
||||
};
|
||||
|
||||
} // namespace Util
|
||||
} // namespace Gfx
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user