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


C++ IDWriteFontFamily::GetFamilyNames方法代码示例

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


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

示例1: initFontInfo

void QWindowsFontEngineDirectWrite::initFontInfo(const QFontDef &request,
        int dpi, IDWriteFont *font)
{
    fontDef = request;

    IDWriteFontFamily *fontFamily = NULL;
    HRESULT hr = font->GetFontFamily(&fontFamily);

    IDWriteLocalizedStrings *familyNames = NULL;
    if (SUCCEEDED(hr))
        hr = fontFamily->GetFamilyNames(&familyNames);

    UINT32 index = 0;

    if (SUCCEEDED(hr)) {
        BOOL exists = false;

        wchar_t localeName[LOCALE_NAME_MAX_LENGTH];
        int defaultLocaleSuccess = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH);
        if (defaultLocaleSuccess)
            hr = familyNames->FindLocaleName(localeName, &index, &exists);

        if (SUCCEEDED(hr) && !exists)
            hr = familyNames->FindLocaleName(L"en-us", &index, &exists);

        if (!exists)
            index = 0;
    }

    // Get the family name.
    if (SUCCEEDED(hr)) {
        UINT32 length = 0;

        hr = familyNames->GetStringLength(index, &length);

        if (SUCCEEDED(hr)) {
            QVarLengthArray<wchar_t, 128> name(length+1);

            hr = familyNames->GetString(index, name.data(), name.size());

            if (SUCCEEDED(hr))
                fontDef.family = QString::fromWCharArray(name.constData());
        }
    }

    if (familyNames != NULL)
        familyNames->Release();
    if (fontFamily)
        fontFamily->Release();

    if (FAILED(hr))
        qErrnoWarning(hr, "initFontInfo: Failed to get family name");

    if (fontDef.pointSize < 0)
        fontDef.pointSize = fontDef.pixelSize * 72. / dpi;
    else if (fontDef.pixelSize == -1)
        fontDef.pixelSize = qRound(fontDef.pointSize * dpi / 72.);
}
开发者ID:ballock,项目名称:qtbase,代码行数:58,代码来源:qwindowsfontenginedirectwrite.cpp

示例2: initFontInfo

static void initFontInfo(QFontEngineDirectWrite *fe, const QFontDef &request,
                         int dpi, IDWriteFont *font)
{
    fe->fontDef = request;

    IDWriteFontFamily *fontFamily = NULL;
    HRESULT hr = font->GetFontFamily(&fontFamily);

    IDWriteLocalizedStrings *familyNames = NULL;
    if (SUCCEEDED(hr))
        hr = fontFamily->GetFamilyNames(&familyNames);

    UINT32 index = 0;
    BOOL exists = false;

    wchar_t localeName[LOCALE_NAME_MAX_LENGTH];

    if (SUCCEEDED(hr)) {
        int defaultLocaleSuccess = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH);

        if (defaultLocaleSuccess)
            hr = familyNames->FindLocaleName(localeName, &index, &exists);

        if (SUCCEEDED(hr) && !exists)
            hr = familyNames->FindLocaleName(L"en-us", &index, &exists);
    }

    if (!exists)
        index = 0;

    UINT32 length = 0;
    if (SUCCEEDED(hr))
        hr = familyNames->GetStringLength(index, &length);

    wchar_t *name = new (std::nothrow) wchar_t[length+1];
    if (name == NULL)
        hr = E_OUTOFMEMORY;

    // Get the family name.
    if (SUCCEEDED(hr))
        hr = familyNames->GetString(index, name, length + 1);

    if (SUCCEEDED(hr))
        fe->fontDef.family = QString::fromWCharArray(name);

    delete[] name;
    if (familyNames != NULL)
        familyNames->Release();

    if (FAILED(hr))
        qErrnoWarning(hr, "initFontInfo: Failed to get family name");

    if (fe->fontDef.pointSize < 0)
        fe->fontDef.pointSize = fe->fontDef.pixelSize * 72. / dpi;
    else if (fe->fontDef.pixelSize == -1)
        fe->fontDef.pixelSize = qRound(fe->fontDef.pointSize * dpi / 72.);
}
开发者ID:13W,项目名称:phantomjs,代码行数:57,代码来源:qfontdatabase_win.cpp

示例3: DWriteCreateResources

HRESULT DWriteCreateResources(HDC hdc, wchar_t *text, HFONT hfont)
{
    HRESULT hr = S_OK;

    // If the DirectWrite factory doesn't exist, create the resources,
    // only create these resources once.
    if (!g_pDWriteFactory)
    {
        HWND hwnd;
        RECT r;

        // DirectWrite variables.
        IDWriteFontFamily* pFontFamily = NULL;
        IDWriteFont* pFont = NULL;
        IDWriteLocalizedStrings* pFamilyNames = NULL;
        
        // Logical (GDI) font.
        LOGFONT lf = {};

        UINT32 length = 0;
        UINT32 index = 0;
        float fontSize = 0;

        // length of the string
        UINT32 textLength = 0;

        wchar_t *name = NULL;

        // Get a handle to the DC and the window rect.
        hwnd = WindowFromDC(hdc);
        GetClientRect(hwnd, &r);

        // Calculate the string length.
        textLength = UINT32(wcslen(text));

        // Create the DirectWrite factory.
        hr = DWriteCreateFactory(
            DWRITE_FACTORY_TYPE_SHARED,
            __uuidof(IDWriteFactory),
            reinterpret_cast<IUnknown**>(&g_pDWriteFactory)
            );

        // Create a GDI interop interface.
        if (SUCCEEDED(hr))
        {
            hr = g_pDWriteFactory->GetGdiInterop(&g_pGdiInterop);
        }
        
        if (SUCCEEDED(hr))
        {
            // Get a logical font from the font handle.
            GetObject(hfont, sizeof(LOGFONT), &lf);
        }

        // Convert to a DirectWrite font.
        if (SUCCEEDED(hr))
        {
            hr = g_pGdiInterop->CreateFontFromLOGFONT(&lf, &pFont);
        }
        
        // Get the font family.
        if (SUCCEEDED(hr))
        {
            hr = pFont->GetFontFamily(&pFontFamily);
        }

        // Get a list of localized family names.
        if (SUCCEEDED(hr))
        {
            hr = pFontFamily->GetFamilyNames(&pFamilyNames);
        }

        // Select the first locale.  This is OK, because we are not displaying the family name.
        index = 0;
        
        // Get the length of the family name.
        if (SUCCEEDED(hr))
        {
            hr = pFamilyNames->GetStringLength(index, &length);
        }

        if (SUCCEEDED(hr))
        {
            // Allocate a new string.
            name = new (std::nothrow) wchar_t[length+1];
		    if (name == NULL)
            {
			    hr = E_OUTOFMEMORY;
            }
        }

        // Get the actual family name.
        if (SUCCEEDED(hr))
        {
            hr = pFamilyNames->GetString(index, name, length+1);
        }

        if (SUCCEEDED(hr))
        {
            // Calculate the font size.
//.........这里部分代码省略.........
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:101,代码来源:GdiInterop.cpp

示例4: PixelsToDipsY

    HRESULT
DWriteContext::SetLOGFONT(const LOGFONTW &logFont, float fontSize)
{
    // Most of this function is copy from: http://msdn.microsoft.com/en-us/library/windows/desktop/dd941783(v=vs.85).aspx
    HRESULT hr = S_OK;

    IDWriteFont *font = NULL;
    IDWriteFontFamily *fontFamily = NULL;
    IDWriteLocalizedStrings *localizedFamilyNames = NULL;

    if (SUCCEEDED(hr))
    {
	hr = mGdiInterop->CreateFontFromLOGFONT(&logFont, &font);
    }

    // Get the font family to which this font belongs.
    if (SUCCEEDED(hr))
    {
	hr = font->GetFontFamily(&fontFamily);
    }

    // Get the family names. This returns an object that encapsulates one or
    // more names with the same meaning but in different languages.
    if (SUCCEEDED(hr))
    {
	hr = fontFamily->GetFamilyNames(&localizedFamilyNames);
    }

    // Get the family name at index zero. If we were going to display the name
    // we'd want to try to find one that matched the use locale, but for
    // purposes of creating a text format object any language will do.

    wchar_t familyName[100];
    if (SUCCEEDED(hr))
    {
	hr = localizedFamilyNames->GetString(0, familyName,
		ARRAYSIZE(familyName));
    }

    if (SUCCEEDED(hr))
    {
	// If no font size was passed in use the lfHeight of the LOGFONT.
	if (fontSize == 0)
	{
	    // Convert from pixels to DIPs.
	    fontSize = PixelsToDipsY(logFont.lfHeight);
	    if (fontSize < 0)
	    {
		// Negative lfHeight represents the size of the em unit.
		fontSize = -fontSize;
	    }
	    else
	    {
		// Positive lfHeight represents the cell height (ascent +
		// descent).
		DWRITE_FONT_METRICS fontMetrics;
		font->GetMetrics(&fontMetrics);

		// Convert the cell height (ascent + descent) from design units
		// to ems.
		float cellHeight = static_cast<float>(
			fontMetrics.ascent + fontMetrics.descent)
					       / fontMetrics.designUnitsPerEm;

		// Divide the font size by the cell height to get the font em
		// size.
		fontSize /= cellHeight;
	    }
	}
    }

    // The text format includes a locale name. Ideally, this would be the
    // language of the text, which may or may not be the same as the primary
    // language of the user. However, for our purposes the user locale will do.
    wchar_t localeName[LOCALE_NAME_MAX_LENGTH];
    if (SUCCEEDED(hr))
    {
	if (GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH) == 0)
	    hr = HRESULT_FROM_WIN32(GetLastError());
    }

    if (SUCCEEDED(hr))
    {
	// Create the text format object.
	hr = mDWriteFactory->CreateTextFormat(
		familyName,
		NULL, // no custom font collection
		font->GetWeight(),
		font->GetStyle(),
		font->GetStretch(),
		fontSize,
		localeName,
		&mTextFormat);
    }

    if (SUCCEEDED(hr))
    {
	mFontWeight = static_cast<DWRITE_FONT_WEIGHT>(logFont.lfWeight);
	mFontStyle = logFont.lfItalic ? DWRITE_FONT_STYLE_ITALIC
	    : DWRITE_FONT_STYLE_NORMAL;
//.........这里部分代码省略.........
开发者ID:Qubit0-1,项目名称:vim,代码行数:101,代码来源:gui_dwrite.cpp

示例5: wmain

void wmain()
{
    IDWriteFactory* pDWriteFactory = NULL;

    HRESULT hr = DWriteCreateFactory(
            DWRITE_FACTORY_TYPE_SHARED,
            __uuidof(IDWriteFactory),
            reinterpret_cast<IUnknown**>(&pDWriteFactory)
            );

    IDWriteFontCollection* pFontCollection = NULL;

    // Get the system font collection.
    if (SUCCEEDED(hr))
    {
        hr = pDWriteFactory->GetSystemFontCollection(&pFontCollection);
    }

    UINT32 familyCount = 0;

    // Get the number of font families in the collection.
    if (SUCCEEDED(hr))
    {
        familyCount = pFontCollection->GetFontFamilyCount();
    }

    for (UINT32 i = 0; i < familyCount; ++i)
    {
        IDWriteFontFamily* pFontFamily = NULL;

        // Get the font family.
        if (SUCCEEDED(hr))
        {
            hr = pFontCollection->GetFontFamily(i, &pFontFamily);
        }

        IDWriteLocalizedStrings* pFamilyNames = NULL;
        
        // Get a list of localized strings for the family name.
        if (SUCCEEDED(hr))
        {
            hr = pFontFamily->GetFamilyNames(&pFamilyNames);
        }

        UINT32 index = 0;
        BOOL exists = false;
        
        wchar_t localeName[LOCALE_NAME_MAX_LENGTH];

        if (SUCCEEDED(hr))
        {
            // Get the default locale for this user.
            int defaultLocaleSuccess = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH);

            // If the default locale is returned, find that locale name, otherwise use "en-us".
            if (defaultLocaleSuccess)
            {
                hr = pFamilyNames->FindLocaleName(localeName, &index, &exists);
            }
            else
            {
                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 == NULL)
        {
			hr = E_OUTOFMEMORY;
        }

        // Get the family name.
        if (SUCCEEDED(hr))
        {
            hr = pFamilyNames->GetString(index, name, length+1);
        }
        if (SUCCEEDED(hr))
        {
            // Print out the family name.
            wprintf(L"%s\n", name);
        }

		SafeRelease(&pFontFamily);
		SafeRelease(&pFamilyNames);

        delete [] name;
    }
//.........这里部分代码省略.........
开发者ID:AbdoSalem95,项目名称:WindowsSDK7-Samples,代码行数:101,代码来源:FontEnumeration.cpp


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