积极答复者
Metro 如何获得系统字体库的列表?

问题
答案
-
http://msdn.microsoft.com/en-us/library/windows/desktop/dd368214(v=vs.85).aspx
Metro 版:
void ArtFontBuilderPanel::GetFontFaces() { vector<wstring> vs; HRESULT hr; ComPtr<IDWriteFontCollection> pFontCollection; hr = ArtCanvas::DWriteFactory->GetSystemFontCollection(&pFontCollection); UINT32 familyCount = 0; if (SUCCEEDED(hr)) { familyCount = pFontCollection->GetFontFamilyCount(); } uint32 index = 0; BOOL exists = false; wchar_t localeName[LOCALE_NAME_MAX_LENGTH]; // Get the default locale for this user. int defaultLocaleSuccess = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH); for (UINT32 i = 0; i < familyCount; ++i) { ComPtr<IDWriteFontFamily> pFontFamily; // Get the font family. if (SUCCEEDED(hr)) { hr = pFontCollection->GetFontFamily(i, &pFontFamily); } ComPtr<IDWriteLocalizedStrings> pFamilyNames; // Get a list of localized strings for the family name. if (SUCCEEDED(hr)) { hr = pFontFamily->GetFamilyNames(&pFamilyNames); } if (SUCCEEDED(hr)) { // If the default locale is returned, find that locale name. if (defaultLocaleSuccess) { hr = pFamilyNames->FindLocaleName(localeName, &index, &exists); } if (SUCCEEDED(hr) && !exists) // if the above find did not find a match, retry with US English { hr = pFamilyNames->FindLocaleName(L"en-us", &index, &exists); } } // If the specified locale doesn't exist, select the first on the list. if (!exists) { index = 0; } UINT32 length = 0; // Get the string length. if (SUCCEEDED(hr)) { hr = pFamilyNames->GetStringLength(index, &length); } // Allocate a string big enough to hold the name. wchar_t* name = new (std::nothrow) wchar_t[length+1]; if (name == nullptr) { hr = E_OUTOFMEMORY; } // Get the family name. if (SUCCEEDED(hr)) { hr = pFamilyNames->GetString(index, name, length+1); } // Add the family name to the String Array. if (SUCCEEDED(hr)) { vs.push_back(name); } delete [] name; } mFontFaceComboBox->iListBoxWidth=mFontFaceComboBox->getWidth()*2; std::sort(vs.begin(),vs.end()); for (wstring s:vs) { mFontFaceComboBox->addItem(s); } }
C++ DX11
- 已标记为答案 清风梧桐 2012年9月10日 1:35
全部回复
-
http://msdn.microsoft.com/en-us/library/windows/desktop/dd368214(v=vs.85).aspx
Metro 版:
void ArtFontBuilderPanel::GetFontFaces() { vector<wstring> vs; HRESULT hr; ComPtr<IDWriteFontCollection> pFontCollection; hr = ArtCanvas::DWriteFactory->GetSystemFontCollection(&pFontCollection); UINT32 familyCount = 0; if (SUCCEEDED(hr)) { familyCount = pFontCollection->GetFontFamilyCount(); } uint32 index = 0; BOOL exists = false; wchar_t localeName[LOCALE_NAME_MAX_LENGTH]; // Get the default locale for this user. int defaultLocaleSuccess = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH); for (UINT32 i = 0; i < familyCount; ++i) { ComPtr<IDWriteFontFamily> pFontFamily; // Get the font family. if (SUCCEEDED(hr)) { hr = pFontCollection->GetFontFamily(i, &pFontFamily); } ComPtr<IDWriteLocalizedStrings> pFamilyNames; // Get a list of localized strings for the family name. if (SUCCEEDED(hr)) { hr = pFontFamily->GetFamilyNames(&pFamilyNames); } if (SUCCEEDED(hr)) { // If the default locale is returned, find that locale name. if (defaultLocaleSuccess) { hr = pFamilyNames->FindLocaleName(localeName, &index, &exists); } if (SUCCEEDED(hr) && !exists) // if the above find did not find a match, retry with US English { hr = pFamilyNames->FindLocaleName(L"en-us", &index, &exists); } } // If the specified locale doesn't exist, select the first on the list. if (!exists) { index = 0; } UINT32 length = 0; // Get the string length. if (SUCCEEDED(hr)) { hr = pFamilyNames->GetStringLength(index, &length); } // Allocate a string big enough to hold the name. wchar_t* name = new (std::nothrow) wchar_t[length+1]; if (name == nullptr) { hr = E_OUTOFMEMORY; } // Get the family name. if (SUCCEEDED(hr)) { hr = pFamilyNames->GetString(index, name, length+1); } // Add the family name to the String Array. if (SUCCEEDED(hr)) { vs.push_back(name); } delete [] name; } mFontFaceComboBox->iListBoxWidth=mFontFaceComboBox->getWidth()*2; std::sort(vs.begin(),vs.end()); for (wstring s:vs) { mFontFaceComboBox->addItem(s); } }
C++ DX11
- 已标记为答案 清风梧桐 2012年9月10日 1:35