예제 #1
0
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;
}
예제 #2
0
IFACEMETHODIMP CanvasTextFormatFactory::GetSystemFontFamiliesFromLocaleList(
    IVectorView<HSTRING>* localeList,
    uint32_t* valueCount,
    HSTRING** valueElements)
{
    return ExceptionBoundary(
        [&]
        {
            CheckInPointer(valueCount);
            CheckAndClearOutPointer(valueElements);
            
            auto factory = CustomFontManager::GetInstance()->GetSharedFactory();

            ComPtr<IDWriteFontCollection> systemFontCollection;
            ThrowIfFailed(factory->GetSystemFontCollection(&systemFontCollection));

            uint32_t familyCount = systemFontCollection->GetFontFamilyCount();

            ComArray<HSTRING> stringArray(familyCount);

            for (uint32_t i = 0; i < familyCount; ++i)
            {
                ComPtr<IDWriteFontFamily> fontFamily;
                ThrowIfFailed(systemFontCollection->GetFontFamily(i, &fontFamily));

                ComPtr<IDWriteLocalizedStrings> familyNames;
                ThrowIfFailed(fontFamily->GetFamilyNames(&familyNames));

                WinString familyName = GetFamilyName(familyNames, localeList);
                familyName.CopyTo(&stringArray[i]);
            }

            stringArray.Detach(valueCount, valueElements);
        });
}
예제 #3
0
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);
    }
}
예제 #4
0
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;
}
예제 #5
0
static void SetFrom(HSTRING* outputValue, WinString const& value)
{
    value.CopyTo(outputValue);
}
예제 #6
0
static bool IsSame(HSTRING* outputValue, WinString const& value)
{
    return value.Equals(*outputValue);
}