From 7c90f65659a934be0ab6073698db1418dc9a3a1b Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Mon, 8 Apr 2013 17:29:26 +0300 Subject: [PATCH] Gfx: Tweaks --- Common/Gfx/TextFormatD2D.cpp | 28 ++++++++++++++-------------- Common/Gfx/TextFormatD2D.h | 3 ++- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Common/Gfx/TextFormatD2D.cpp b/Common/Gfx/TextFormatD2D.cpp index dc6681d4..c283051e 100644 --- a/Common/Gfx/TextFormatD2D.cpp +++ b/Common/Gfx/TextFormatD2D.cpp @@ -101,7 +101,7 @@ void TextFormatD2D::SetProperties(const WCHAR* fontFamily, int size, bool bold, if (dwFont) { WCHAR buffer[LF_FACESIZE]; - if (GetDWFontFamilyName(dwFont, buffer, _countof(buffer))) + if (GetFamilyNameFromDWFont(dwFont, buffer, _countof(buffer))) { // TODO: If |fontFamily| is e.g. 'Segoe UI Semibold' and |bold| is true, we might want // to make the weight heaver to match GDI+. @@ -222,24 +222,24 @@ IDWriteFont* TextFormatD2D::CreateDWFontFromGDIFamilyName(const WCHAR* fontFamil return nullptr; } -bool TextFormatD2D::GetDWFontFamilyName(IDWriteFont* font, WCHAR* buffer, const UINT bufferSize) +bool TextFormatD2D::GetFamilyNameFromDWFont(IDWriteFont* font, WCHAR* buffer, const UINT bufferSize) { - bool result = false; IDWriteFontFamily* dwFontFamily; HRESULT hr = font->GetFontFamily(&dwFontFamily); + return SUCCEEDED(hr) ? GetFamilyNameFromDWFontFamily(dwFontFamily, buffer, bufferSize) : false; +} + +bool TextFormatD2D::GetFamilyNameFromDWFontFamily(IDWriteFontFamily* fontFamily, WCHAR* buffer, const UINT bufferSize) +{ + bool result = false; + IDWriteLocalizedStrings* dwFamilyNames; + HRESULT hr = fontFamily->GetFamilyNames(&dwFamilyNames); if (SUCCEEDED(hr)) { - IDWriteLocalizedStrings* dwFamilyNames; - hr = dwFontFamily->GetFamilyNames(&dwFamilyNames); - if (SUCCEEDED(hr)) - { - // TODO: Determine the best index? - hr = dwFamilyNames->GetString(0, buffer, bufferSize); - result = SUCCEEDED(hr); - dwFamilyNames->Release(); - } - - dwFontFamily->Release(); + // TODO: Determine the best index? + hr = dwFamilyNames->GetString(0, buffer, bufferSize); + result = SUCCEEDED(hr); + dwFamilyNames->Release(); } return result; diff --git a/Common/Gfx/TextFormatD2D.h b/Common/Gfx/TextFormatD2D.h index c6a9ecc9..3cee7b3c 100644 --- a/Common/Gfx/TextFormatD2D.h +++ b/Common/Gfx/TextFormatD2D.h @@ -56,7 +56,8 @@ private: // style. static IDWriteFont* CreateDWFontFromGDIFamilyName(const WCHAR* fontFamily, bool bold, bool italic); - static bool GetDWFontFamilyName(IDWriteFont* font, WCHAR* buffer, UINT bufferSize); + static bool GetFamilyNameFromDWFont(IDWriteFont* font, WCHAR* buffer, UINT bufferSize); + static bool GetFamilyNameFromDWFontFamily(IDWriteFontFamily* fontFamily, WCHAR* buffer, UINT bufferSize); IDWriteTextFormat* m_TextFormat; IDWriteTextLayout* m_TextLayout;