mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Gfx: Cosmetics
This commit is contained in:
parent
73adaffe43
commit
b73735251e
@ -95,25 +95,24 @@ void TextFormatD2D::SetProperties(
|
|||||||
{
|
{
|
||||||
Dispose();
|
Dispose();
|
||||||
|
|
||||||
HRESULT hr = E_FAIL;
|
|
||||||
|
|
||||||
// |fontFamily| uses the GDI/GDI+ font naming convention so try to create DirectWrite font
|
// |fontFamily| uses the GDI/GDI+ font naming convention so try to create DirectWrite font
|
||||||
// using the GDI family name and then create a text format using the DirectWrite family name
|
// using the GDI family name and then create a text format using the DirectWrite family name
|
||||||
// obtained from it.
|
// obtained from it.
|
||||||
WCHAR dwFamilyName[LF_FACESIZE];
|
WCHAR dwriteFamilyName[LF_FACESIZE];
|
||||||
DWRITE_FONT_WEIGHT dwFontWeight;
|
DWRITE_FONT_WEIGHT dwriteFontWeight;
|
||||||
DWRITE_FONT_STYLE dwFontStyle;
|
DWRITE_FONT_STYLE dwriteFontStyle;
|
||||||
DWRITE_FONT_STRETCH dwFontStretch;
|
DWRITE_FONT_STRETCH dwriteFontStretch;
|
||||||
if (Util::GetDWritePropertiesFromGDIProperties(
|
HRESULT hr = Util::GetDWritePropertiesFromGDIProperties(
|
||||||
CanvasD2D::c_DWFactory, fontFamily, bold, italic, dwFontWeight, dwFontStyle, dwFontStretch,
|
CanvasD2D::c_DWFactory, fontFamily, bold, italic, dwriteFontWeight, dwriteFontStyle,
|
||||||
dwFamilyName, _countof(dwFamilyName)))
|
dwriteFontStretch, dwriteFamilyName, _countof(dwriteFamilyName));
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
hr = CanvasD2D::c_DWFactory->CreateTextFormat(
|
hr = CanvasD2D::c_DWFactory->CreateTextFormat(
|
||||||
dwFamilyName,
|
dwriteFamilyName,
|
||||||
nullptr,
|
nullptr,
|
||||||
dwFontWeight,
|
dwriteFontWeight,
|
||||||
dwFontStyle,
|
dwriteFontStyle,
|
||||||
dwFontStretch,
|
dwriteFontStretch,
|
||||||
size * (4.0f / 3.0f),
|
size * (4.0f / 3.0f),
|
||||||
L"",
|
L"",
|
||||||
&m_TextFormat);
|
&m_TextFormat);
|
||||||
|
@ -21,12 +21,12 @@
|
|||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
namespace Util {
|
namespace Util {
|
||||||
|
|
||||||
bool GetDWritePropertiesFromGDIProperties(
|
HRESULT GetDWritePropertiesFromGDIProperties(
|
||||||
IDWriteFactory* factory, const WCHAR* gdiFamilyName, const bool gdiBold, const bool gdiItalic,
|
IDWriteFactory* factory, const WCHAR* gdiFamilyName, const bool gdiBold, const bool gdiItalic,
|
||||||
DWRITE_FONT_WEIGHT& dwriteFontWeight, DWRITE_FONT_STYLE& dwriteFontStyle,
|
DWRITE_FONT_WEIGHT& dwriteFontWeight, DWRITE_FONT_STYLE& dwriteFontStyle,
|
||||||
DWRITE_FONT_STRETCH& dwriteFontStretch, WCHAR* dwriteFamilyName, UINT dwriteFamilyNameSize)
|
DWRITE_FONT_STRETCH& dwriteFontStretch, WCHAR* dwriteFamilyName, UINT dwriteFamilyNameSize)
|
||||||
{
|
{
|
||||||
bool result = false;
|
HRESULT hr = E_FAIL;
|
||||||
IDWriteFont* dwriteFont = CreateDWriteFontFromGDIFamilyName(factory, gdiFamilyName);
|
IDWriteFont* dwriteFont = CreateDWriteFontFromGDIFamilyName(factory, gdiFamilyName);
|
||||||
if (dwriteFont)
|
if (dwriteFont)
|
||||||
{
|
{
|
||||||
@ -57,13 +57,13 @@ bool GetDWritePropertiesFromGDIProperties(
|
|||||||
|
|
||||||
dwriteFontStretch = dwriteFont->GetStretch();
|
dwriteFontStretch = dwriteFont->GetStretch();
|
||||||
|
|
||||||
result = true;
|
hr = S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
dwriteFont->Release();
|
dwriteFont->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
IDWriteFont* CreateDWriteFontFromGDIFamilyName(IDWriteFactory* factory, const WCHAR* gdiFamilyName)
|
IDWriteFont* CreateDWriteFontFromGDIFamilyName(IDWriteFactory* factory, const WCHAR* gdiFamilyName)
|
||||||
@ -95,7 +95,7 @@ IDWriteFont* CreateDWriteFontFromGDIFamilyName(IDWriteFactory* factory, const WC
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, const UINT bufferSize)
|
HRESULT GetFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, const UINT bufferSize)
|
||||||
{
|
{
|
||||||
IDWriteFontFamily* dwriteFontFamily;
|
IDWriteFontFamily* dwriteFontFamily;
|
||||||
HRESULT hr = font->GetFontFamily(&dwriteFontFamily);
|
HRESULT hr = font->GetFontFamily(&dwriteFontFamily);
|
||||||
@ -103,33 +103,29 @@ bool GetFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, const UINT bu
|
|||||||
{
|
{
|
||||||
GetFamilyNameFromDWriteFontFamily(dwriteFontFamily, buffer, bufferSize);
|
GetFamilyNameFromDWriteFontFamily(dwriteFontFamily, buffer, bufferSize);
|
||||||
dwriteFontFamily->Release();
|
dwriteFontFamily->Release();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetFamilyNameFromDWriteFontFamily(
|
HRESULT GetFamilyNameFromDWriteFontFamily(
|
||||||
IDWriteFontFamily* fontFamily, WCHAR* buffer, const UINT bufferSize)
|
IDWriteFontFamily* fontFamily, WCHAR* buffer, const UINT bufferSize)
|
||||||
{
|
{
|
||||||
bool result = false;
|
|
||||||
IDWriteLocalizedStrings* dwFamilyNames;
|
IDWriteLocalizedStrings* dwFamilyNames;
|
||||||
HRESULT hr = fontFamily->GetFamilyNames(&dwFamilyNames);
|
HRESULT hr = fontFamily->GetFamilyNames(&dwFamilyNames);
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
// TODO: Determine the best index?
|
// TODO: Determine the best index?
|
||||||
hr = dwFamilyNames->GetString(0, buffer, bufferSize);
|
hr = dwFamilyNames->GetString(0, buffer, bufferSize);
|
||||||
result = SUCCEEDED(hr);
|
|
||||||
dwFamilyNames->Release();
|
dwFamilyNames->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsFamilyInSystemFontCollection(IDWriteFactory* factory, const WCHAR* familyName)
|
bool IsFamilyInSystemFontCollection(IDWriteFactory* factory, const WCHAR* familyName)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
IDWriteFontCollection* systemFontCollection;
|
IDWriteFontCollection* systemFontCollection;
|
||||||
HRESULT hr = factory->GetSystemFontCollection(&systemFontCollection);
|
HRESULT hr = factory->GetSystemFontCollection(&systemFontCollection);
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
|
@ -26,7 +26,7 @@ namespace Util {
|
|||||||
|
|
||||||
// Maps the GDI family name and italic/bold flags to the DirectWrite family name, weight, style,
|
// Maps the GDI family name and italic/bold flags to the DirectWrite family name, weight, style,
|
||||||
// and stretch.
|
// and stretch.
|
||||||
bool GetDWritePropertiesFromGDIProperties(
|
HRESULT GetDWritePropertiesFromGDIProperties(
|
||||||
IDWriteFactory* factory, const WCHAR* gdiFamilyName, const bool gdiBold, const bool gdiItalic,
|
IDWriteFactory* factory, const WCHAR* gdiFamilyName, const bool gdiBold, const bool gdiItalic,
|
||||||
DWRITE_FONT_WEIGHT& dwriteFontWeight, DWRITE_FONT_STYLE& dwriteFontStyle,
|
DWRITE_FONT_WEIGHT& dwriteFontWeight, DWRITE_FONT_STYLE& dwriteFontStyle,
|
||||||
DWRITE_FONT_STRETCH& dwriteFontStretch, WCHAR* dwriteFamilyName, UINT dwriteFamilyNameSize);
|
DWRITE_FONT_STRETCH& dwriteFontStretch, WCHAR* dwriteFamilyName, UINT dwriteFamilyNameSize);
|
||||||
@ -37,9 +37,9 @@ bool GetDWritePropertiesFromGDIProperties(
|
|||||||
// style.
|
// style.
|
||||||
IDWriteFont* CreateDWriteFontFromGDIFamilyName(IDWriteFactory* factory, const WCHAR* fontFamily);
|
IDWriteFont* CreateDWriteFontFromGDIFamilyName(IDWriteFactory* factory, const WCHAR* fontFamily);
|
||||||
|
|
||||||
bool GetFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, UINT bufferSize);
|
HRESULT GetFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, UINT bufferSize);
|
||||||
|
|
||||||
bool GetFamilyNameFromDWriteFontFamily(
|
HRESULT GetFamilyNameFromDWriteFontFamily(
|
||||||
IDWriteFontFamily* fontFamily, WCHAR* buffer, UINT bufferSize);
|
IDWriteFontFamily* fontFamily, WCHAR* buffer, UINT bufferSize);
|
||||||
|
|
||||||
bool IsFamilyInSystemFontCollection(IDWriteFactory* factory, const WCHAR* familyName);
|
bool IsFamilyInSystemFontCollection(IDWriteFactory* factory, const WCHAR* familyName);
|
||||||
|
Loading…
Reference in New Issue
Block a user