forked from rizonesoft/Notepad3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFontEnumeration.h
71 lines (62 loc) · 3.3 KB
/
FontEnumeration.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// encoding: UTF-8
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved
//
//----------------------------------------------------------------------------
#pragma once
/******************************************************************
* *
* FontFaceInfo *
* *
* Helper structure that wraps up the common font attributes into *
* single object. *
* *
******************************************************************/
struct FontFaceInfo
{
WCHAR fontFaceName[100];
DWRITE_FONT_WEIGHT fontWeight;
DWRITE_FONT_STYLE fontStyle;
DWRITE_FONT_STRETCH fontStretch;
FontFaceInfo(
const WCHAR* fontFaceName,
DWRITE_FONT_WEIGHT fontWeight,
DWRITE_FONT_STYLE fontStyle,
DWRITE_FONT_STRETCH fontStretch)
: fontWeight(fontWeight),
fontStyle(fontStyle),
fontStretch(fontStretch)
{
StringCchCopy(this->fontFaceName, ARRAYSIZE(this->fontFaceName), fontFaceName);
}
FontFaceInfo(
const WCHAR* fontFaceName,
ULONG packedAttributes)
: fontWeight(static_cast<DWRITE_FONT_WEIGHT>(LOWORD(packedAttributes))),
fontStyle(static_cast<DWRITE_FONT_STYLE>(LOBYTE(HIWORD(packedAttributes)))),
fontStretch(static_cast<DWRITE_FONT_STRETCH>(HIBYTE(HIWORD(packedAttributes))))
{
StringCchCopy(this->fontFaceName, ARRAYSIZE(this->fontFaceName), fontFaceName);
}
ULONG const PackedFontAttributes() const
{
return MAKELONG(fontWeight, MAKEWORD(fontStyle, fontStretch));
}
};
/******************************************************************
* *
* Support routines used by the UI code in ChooseFont.cpp to do *
* the actual enumeration and font information retrieval *
* *
******************************************************************/
HRESULT GetFontFamilyName(IDWriteFontFamily* fontFamily, const WCHAR* locale, OUT std::wstring& familyName);
HRESULT GetFontFamilyNames(IDWriteFontCollection* fontCollection, const WCHAR* localeName, IN OUT std::vector< std::wstring >& fontFamilyNames);
HRESULT GetFonts(IDWriteFontCollection* fontCollection, const WCHAR* fontFamilyName, IN OUT std::vector<IDWriteFont*>& fonts);
HRESULT GetFontFaceInfo(const std::vector<IDWriteFont*>& fonts, const WCHAR* locale, IN OUT std::vector<FontFaceInfo>& info);
HRESULT GetFontFamilyNameFromFormat(IDWriteTextFormat* textFormat, OUT std::wstring& fontFamilyName);
HRESULT GetFontFamily(IDWriteFontCollection* fontCollection, const WCHAR* fontFamilyName, OUT IDWriteFontFamily** fontFamily);
ULONG GetBestFontAttributes(IDWriteFontCollection* fontCollection, const WCHAR* fontFamilyName, const FontFaceInfo& desiredAttributes);