当前位置: 首页>>代码示例>>C++>>正文


C++ ComPtr::GetFirstMatchingFont方法代码示例

本文整理汇总了C++中microsoft::wrl::ComPtr::GetFirstMatchingFont方法的典型用法代码示例。如果您正苦于以下问题:C++ ComPtr::GetFirstMatchingFont方法的具体用法?C++ ComPtr::GetFirstMatchingFont怎么用?C++ ComPtr::GetFirstMatchingFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在microsoft::wrl::ComPtr的用法示例。


在下文中一共展示了ComPtr::GetFirstMatchingFont方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DWriteOpenTypeEnumerationRenderer

// Loads and initializes application assets when the application is loaded.
DWriteOpenTypeEnumerationMain::DWriteOpenTypeEnumerationMain(const std::shared_ptr<DX::DeviceResources>& deviceResources) :
    m_deviceResources(deviceResources)
{
    // Register to be notified if the device is lost or recreated.
    m_deviceResources->RegisterDeviceNotify(this);

    m_sceneRenderer = std::unique_ptr<DWriteOpenTypeEnumerationRenderer>(new DWriteOpenTypeEnumerationRenderer(m_deviceResources));

    // Create variables to store the font family and index in the collection
    Microsoft::WRL::ComPtr<IDWriteFontFamily> tempFontFamily;
    Microsoft::WRL::ComPtr<IDWriteFont> tempFont;
    Microsoft::WRL::ComPtr<IDWriteFontFace> tempFontFace;
    Microsoft::WRL::ComPtr<IDWriteFontCollection> fontCollection;
    Microsoft::WRL::ComPtr<IDWriteTextAnalyzer> textAnalyzer;

    UINT32 fontIndex = 0;
    BOOL isPresent = false;

    // Get a copy of the system font collection
    m_deviceResources->GetDWriteFactory()->GetSystemFontCollection(&fontCollection);

    WCHAR* fontFaceNames[] = {L"Arial", L"Times New Roman", L"Meiryo", L"Gabriola"};
    Microsoft::WRL::ComPtr<IDWriteFontFace2>* fontFaces[4] = {&m_arial, &m_times, &m_meiryo, &m_gabriola};

    for (int i = 0; i < ARRAYSIZE(fontFaceNames); i++)
    {
        fontCollection->FindFamilyName(fontFaceNames[i], &fontIndex, &isPresent);
        if (isPresent)
        {
            DX::ThrowIfFailed(
                fontCollection->GetFontFamily(fontIndex, &tempFontFamily)
                );

            DX::ThrowIfFailed(
                tempFontFamily->GetFirstMatchingFont(
                    DWRITE_FONT_WEIGHT_NORMAL,
                    DWRITE_FONT_STRETCH_NORMAL,
                    DWRITE_FONT_STYLE_NORMAL,
                    &tempFont
                    )
                );

            DX::ThrowIfFailed(
                tempFont->CreateFontFace(&tempFontFace)
                );

            DX::ThrowIfFailed(
                tempFontFace.As(fontFaces[i])
                );
        }
    }

    // Create the IDWriteTextAnalyzer that we'll need to get OpenType feature coverage from
    m_deviceResources->GetDWriteFactory()->CreateTextAnalyzer(&textAnalyzer);

    textAnalyzer.As(&m_textAnalyzer);
}
开发者ID:mbin,项目名称:Win81App,代码行数:58,代码来源:DWriteOpenTypeEnumerationMain.cpp

示例2:

void TextFormatD2D::SetProperties(
	const WCHAR* fontFamily, int size, bool bold, bool italic,
	const FontCollection* fontCollection)
{
	auto fontCollectionD2D = (FontCollectionD2D*)fontCollection;

	Dispose();

	WCHAR dwriteFamilyName[LF_FACESIZE];
	DWRITE_FONT_WEIGHT dwriteFontWeight =
		bold ? DWRITE_FONT_WEIGHT_BOLD : DWRITE_FONT_WEIGHT_REGULAR;
	DWRITE_FONT_STYLE dwriteFontStyle =
		italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
	DWRITE_FONT_STRETCH dwriteFontStretch = DWRITE_FONT_STRETCH_NORMAL;
	const float dwriteFontSize = size * (4.0f / 3.0f);

	// |fontFamily| uses the GDI/GDI+ font naming convention so try to create DirectWrite font
	// using the GDI family name and then create a text format using the DirectWrite family name
	// obtained from it.
	HRESULT hr = Util::GetDWritePropertiesFromGDIProperties(
		CanvasD2D::c_DWFactory.Get(), fontFamily, bold, italic, dwriteFontWeight, dwriteFontStyle,
		dwriteFontStretch, dwriteFamilyName, _countof(dwriteFamilyName));
	if (SUCCEEDED(hr))
	{
		hr = CanvasD2D::c_DWFactory->CreateTextFormat(
			dwriteFamilyName,
			nullptr,
			dwriteFontWeight,
			dwriteFontStyle,
			dwriteFontStretch,
			dwriteFontSize,
			L"",
			&m_TextFormat);
	}

	if (FAILED(hr))
	{
		IDWriteFontCollection* dwriteFontCollection = nullptr;

		// If |fontFamily| is not in the system collection, use the font collection from
		// |fontCollectionD2D| if possible.
		if (!Util::IsFamilyInSystemFontCollection(CanvasD2D::c_DWFactory.Get(), fontFamily) &&
			(fontCollectionD2D && fontCollectionD2D->InitializeCollection()))
		{
			IDWriteFont* dwriteFont = Util::FindDWriteFontInFontCollectionByGDIFamilyName(
				fontCollectionD2D->m_Collection, fontFamily);
			if (dwriteFont)
			{
				hr = Util::GetFamilyNameFromDWriteFont(
					dwriteFont, dwriteFamilyName, _countof(dwriteFamilyName));
				if (SUCCEEDED(hr))
				{
					fontFamily = dwriteFamilyName;
					Util::GetPropertiesFromDWriteFont(
						dwriteFont, bold, italic, &dwriteFontWeight, &dwriteFontStyle,
						&dwriteFontStretch);
				}

				dwriteFont->Release();
			}

			dwriteFontCollection = fontCollectionD2D->m_Collection;
		}

		// Fallback in case above fails.
		hr = CanvasD2D::c_DWFactory->CreateTextFormat(
			fontFamily,
			dwriteFontCollection,
			dwriteFontWeight,
			dwriteFontStyle,
			dwriteFontStretch,
			dwriteFontSize,
			L"",
			&m_TextFormat);
	}

	if (SUCCEEDED(hr))
	{
		SetHorizontalAlignment(GetHorizontalAlignment());
		SetVerticalAlignment(GetVerticalAlignment());

		// Get the family name to in case CreateTextFormat() fallbacked on some other family name.
		hr = m_TextFormat->GetFontFamilyName(dwriteFamilyName, _countof(dwriteFamilyName));
		if (FAILED(hr)) return;

		Microsoft::WRL::ComPtr<IDWriteFontCollection> collection;
		Microsoft::WRL::ComPtr<IDWriteFontFamily> fontFamily;
		UINT32 familyNameIndex;
		BOOL exists;
		if (FAILED(m_TextFormat->GetFontCollection(collection.GetAddressOf())) ||
			FAILED(collection->FindFamilyName(dwriteFamilyName, &familyNameIndex, &exists)) ||
			FAILED(collection->GetFontFamily(familyNameIndex, fontFamily.GetAddressOf())))
		{
			return;
		}

		Microsoft::WRL::ComPtr<IDWriteFont> font;
		hr = fontFamily->GetFirstMatchingFont(
			m_TextFormat->GetFontWeight(),
			m_TextFormat->GetFontStretch(),
//.........这里部分代码省略.........
开发者ID:ATTRAYANTDESIGNS,项目名称:rainmeter,代码行数:101,代码来源:TextFormatD2D.cpp


注:本文中的microsoft::wrl::ComPtr::GetFirstMatchingFont方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。