WinString CustomFontManager::GetAbsolutePathFromUri(IUriRuntimeClass* uri) { auto storageFileStatics = m_adapter->GetStorageFileStatics(); ComPtr<IAsyncOperation<StorageFile*>> operation; HRESULT hr = storageFileStatics->GetFileFromApplicationUriAsync(uri, &operation); if (FAILED(hr)) { ThrowHR(hr, HStringReference(Strings::InvalidFontFamilyUri).Get()); } Event operationCompleted(CreateEventEx(nullptr, nullptr, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS)); auto handler = Callback<AddFtmBase<IAsyncOperationCompletedHandler<StorageFile*>>::Type>( [&](IAsyncOperation<StorageFile*>*, AsyncStatus) { SetEvent(operationCompleted.Get()); return S_OK; }); CheckMakeResult(handler); ThrowIfFailed(operation->put_Completed(handler.Get())); auto res = WaitForSingleObjectEx(operationCompleted.Get(), INFINITE, false); if (res != WAIT_OBJECT_0) ThrowHR(E_UNEXPECTED); ComPtr<IStorageFile> storageFile; ThrowIfFailed(operation->GetResults(&storageFile)); WinString path; ThrowIfFailed(As<IStorageItem>(storageFile)->get_Path(path.GetAddressOf())); return path; }
void CustomFontManager::ValidateUri(WinString const& uriString) { if (uriString == WinString()) return; ComPtr<IUriRuntimeClass> uri; ThrowIfFailed(m_uriFactory->CreateWithRelativeUri(WinString(L"ms-appx://"), uriString, &uri)); WinString schemeName; ThrowIfFailed(uri->get_SchemeName(schemeName.GetAddressOf())); if (!schemeName.Equals(HStringReference(L"ms-appx").Get()) && !schemeName.Equals(HStringReference(L"ms-appdata").Get())) { ThrowHR(E_INVALIDARG, Strings::InvalidFontFamilyUriScheme); } }
static bool TryGetLocalizedNameUsingLocaleList( IVectorView<HSTRING>* localeList, ComPtr<IDWriteLocalizedStrings> const& familyNames, WinString* nameIfFound) { if (!localeList) return false; uint32_t localeListSize; ThrowIfFailed(localeList->get_Size(&localeListSize)); for (uint32_t localeIndex = 0; localeIndex < localeListSize; ++localeIndex) { WinString locale; ThrowIfFailed(localeList->GetAt(localeIndex, locale.GetAddressOf())); if (TryGetLocalizedName(static_cast<wchar_t const*>(locale), familyNames, nameIfFound)) return true; } return false; }