From fa9429801573e6663690b4c4734d22dec0f7044e Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 15 Apr 2016 10:14:23 -0400 Subject: [PATCH] Split the function to extract the correct string of an IDWriteLocalizedStrings instance out into its own function. I'm not sure if I'll need the informational strings out of a font (need to see what the strings actually say first), but in case I do, this will help. --- windows/dwrite.cpp | 18 +++++++++++++----- windows/uipriv_windows.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/windows/dwrite.cpp b/windows/dwrite.cpp index da9ddfa9..fc6feaa5 100644 --- a/windows/dwrite.cpp +++ b/windows/dwrite.cpp @@ -36,15 +36,24 @@ fontCollection *loadFontCollection(void) WCHAR *fontCollectionFamilyName(fontCollection *fc, IDWriteFontFamily *family) { IDWriteLocalizedStrings *names; - UINT32 index; - BOOL exists; - UINT32 length; - WCHAR *wname; + WCHAR *str; HRESULT hr; hr = family->GetFamilyNames(&names); if (hr != S_OK) logHRESULT("error getting names of font out in fontCollectionFamilyName()", hr); + str = fontCollectionCorrectString(fc, names); + names->Release(); + return str; +} + +WCHAR *fontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedStrings *names) +{ + UINT32 index; + BOOL exists; + UINT32 length; + WCHAR *wname; + HRESULT hr; // this is complex, but we ignore failure conditions to allow fallbacks // 1) If the user locale name was successfully retrieved, try it @@ -71,7 +80,6 @@ WCHAR *fontCollectionFamilyName(fontCollection *fc, IDWriteFontFamily *family) if (hr != S_OK) logHRESULT("error getting font name in fontCollectionFamilyName()", hr); - names->Release(); return wname; } diff --git a/windows/uipriv_windows.h b/windows/uipriv_windows.h index caa4c43e..48760c5c 100644 --- a/windows/uipriv_windows.h +++ b/windows/uipriv_windows.h @@ -150,6 +150,7 @@ struct fontCollection { extern fontCollection *loadFontCollection(void); extern WCHAR *fontCollectionFamilyName(fontCollection *fc, IDWriteFontFamily *family); extern void fontCollectionFree(fontCollection *fc); +extern WCHAR *fontCollectionCorrectString(fontCollection *fc, IDWriteLocalizedStrings *names); #endif // drawtext.cpp