From b73735251eadf1489e981b3008eb81c603b61cbb Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Fri, 12 Apr 2013 19:18:56 +0300 Subject: [PATCH] Gfx: Cosmetics --- Common/Gfx/TextFormatD2D.cpp | 25 ++++++++++++------------- Common/Gfx/Util/DWriteHelpers.cpp | 20 ++++++++------------ Common/Gfx/Util/DWriteHelpers.h | 6 +++--- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/Common/Gfx/TextFormatD2D.cpp b/Common/Gfx/TextFormatD2D.cpp index f44f6469..a9618a8c 100644 --- a/Common/Gfx/TextFormatD2D.cpp +++ b/Common/Gfx/TextFormatD2D.cpp @@ -95,25 +95,24 @@ void TextFormatD2D::SetProperties( { Dispose(); - HRESULT hr = E_FAIL; - // |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 // obtained from it. - WCHAR dwFamilyName[LF_FACESIZE]; - DWRITE_FONT_WEIGHT dwFontWeight; - DWRITE_FONT_STYLE dwFontStyle; - DWRITE_FONT_STRETCH dwFontStretch; - if (Util::GetDWritePropertiesFromGDIProperties( - CanvasD2D::c_DWFactory, fontFamily, bold, italic, dwFontWeight, dwFontStyle, dwFontStretch, - dwFamilyName, _countof(dwFamilyName))) + WCHAR dwriteFamilyName[LF_FACESIZE]; + DWRITE_FONT_WEIGHT dwriteFontWeight; + DWRITE_FONT_STYLE dwriteFontStyle; + DWRITE_FONT_STRETCH dwriteFontStretch; + HRESULT hr = Util::GetDWritePropertiesFromGDIProperties( + CanvasD2D::c_DWFactory, fontFamily, bold, italic, dwriteFontWeight, dwriteFontStyle, + dwriteFontStretch, dwriteFamilyName, _countof(dwriteFamilyName)); + if (SUCCEEDED(hr)) { hr = CanvasD2D::c_DWFactory->CreateTextFormat( - dwFamilyName, + dwriteFamilyName, nullptr, - dwFontWeight, - dwFontStyle, - dwFontStretch, + dwriteFontWeight, + dwriteFontStyle, + dwriteFontStretch, size * (4.0f / 3.0f), L"", &m_TextFormat); diff --git a/Common/Gfx/Util/DWriteHelpers.cpp b/Common/Gfx/Util/DWriteHelpers.cpp index 5c80b9d9..dbd55808 100644 --- a/Common/Gfx/Util/DWriteHelpers.cpp +++ b/Common/Gfx/Util/DWriteHelpers.cpp @@ -21,12 +21,12 @@ namespace Gfx { namespace Util { -bool GetDWritePropertiesFromGDIProperties( +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) { - bool result = false; + HRESULT hr = E_FAIL; IDWriteFont* dwriteFont = CreateDWriteFontFromGDIFamilyName(factory, gdiFamilyName); if (dwriteFont) { @@ -57,13 +57,13 @@ bool GetDWritePropertiesFromGDIProperties( dwriteFontStretch = dwriteFont->GetStretch(); - result = true; + hr = S_OK; } dwriteFont->Release(); } - return result; + return hr; } IDWriteFont* CreateDWriteFontFromGDIFamilyName(IDWriteFactory* factory, const WCHAR* gdiFamilyName) @@ -95,7 +95,7 @@ IDWriteFont* CreateDWriteFontFromGDIFamilyName(IDWriteFactory* factory, const WC return nullptr; } -bool GetFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, const UINT bufferSize) +HRESULT GetFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, const UINT bufferSize) { IDWriteFontFamily* dwriteFontFamily; HRESULT hr = font->GetFontFamily(&dwriteFontFamily); @@ -103,33 +103,29 @@ bool GetFamilyNameFromDWriteFont(IDWriteFont* font, WCHAR* buffer, const UINT bu { GetFamilyNameFromDWriteFontFamily(dwriteFontFamily, buffer, bufferSize); dwriteFontFamily->Release(); - return true; } - return false; + return hr; } -bool GetFamilyNameFromDWriteFontFamily( +HRESULT GetFamilyNameFromDWriteFontFamily( IDWriteFontFamily* fontFamily, WCHAR* buffer, const UINT bufferSize) { - bool result = false; IDWriteLocalizedStrings* dwFamilyNames; HRESULT hr = fontFamily->GetFamilyNames(&dwFamilyNames); if (SUCCEEDED(hr)) { // TODO: Determine the best index? hr = dwFamilyNames->GetString(0, buffer, bufferSize); - result = SUCCEEDED(hr); dwFamilyNames->Release(); } - return result; + return hr; } bool IsFamilyInSystemFontCollection(IDWriteFactory* factory, const WCHAR* familyName) { bool result = false; - IDWriteFontCollection* systemFontCollection; HRESULT hr = factory->GetSystemFontCollection(&systemFontCollection); if (SUCCEEDED(hr)) diff --git a/Common/Gfx/Util/DWriteHelpers.h b/Common/Gfx/Util/DWriteHelpers.h index 7c21d827..2dbd579d 100644 --- a/Common/Gfx/Util/DWriteHelpers.h +++ b/Common/Gfx/Util/DWriteHelpers.h @@ -26,7 +26,7 @@ namespace Util { // Maps the GDI family name and italic/bold flags to the DirectWrite family name, weight, style, // and stretch. -bool GetDWritePropertiesFromGDIProperties( +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); @@ -37,9 +37,9 @@ bool GetDWritePropertiesFromGDIProperties( // style. 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); bool IsFamilyInSystemFontCollection(IDWriteFactory* factory, const WCHAR* familyName);