-
Notifications
You must be signed in to change notification settings - Fork 1
/
FontSetViewer.h
223 lines (190 loc) · 8.08 KB
/
FontSetViewer.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// 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
//
// Contents: Main user interface window.
//
//----------------------------------------------------------------------------
#pragma once
class MainWindow
{
public:
MainWindow(HWND hwnd);
HRESULT Initialize();
static WPARAM RunMessageLoop();
static ATOM RegisterWindowClass();
static INT_PTR CALLBACK StaticDialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
DialogProcResult CALLBACK DialogProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
STDMETHODIMP ApplyLogFontFilter(const LOGFONT& logFont);
public:
const static wchar_t* g_windowClassName;
enum class FontCollectionFilterMode
{
None, // Display all font face references without any grouping.
// Modes that have a 1:1 correspondence with DWRITE_FONT_PROPERTY_ID.
WssFamilyName,
TypographicFamilyName,
WssFaceName,
FullName,
Win32FamilyName,
PostscriptName,
DesignedScriptTag,
SupportedScriptTag,
SemanticTag,
Weight,
Stretch,
Style,
TypographicFaceName,
Total,
};
protected:
struct FontCollectionEntry
{
std::wstring name; // Name of the entry, depending on the property type (current filter mode).
uint32_t firstFontIndex; // Index of the first font for this entry.
uint32_t fontCount; // number of fonts this entry contains.
// Cached information about the font to use for this entry
// (which corresponds to firstFontIndex).
std::wstring familyName;
DWRITE_FONT_WEIGHT fontWeight; // = DWRITE_FONT_WEIGHT_NORMAL;
DWRITE_FONT_STRETCH fontStretch;// = DWRITE_FONT_STRETCH_NORMAL;
DWRITE_FONT_STYLE fontStyle; // = DWRITE_FONT_STYLE_NORMAL;
std::vector<DWRITE_FONT_AXIS_VALUE> fontAxisValues;
std::vector<DWRITE_FONT_AXIS_RANGE> fontAxisRanges;
std::wstring filePath;
uint32_t fontFaceIndex; // Within an OpenType collection.
DWRITE_FONT_SIMULATIONS fontSimulations;
int CompareStrings(const std::wstring& a, const std::wstring& b) const
{
return ::CompareStringW(
LOCALE_INVARIANT,
NORM_IGNORECASE,
a.c_str(),
static_cast<int32_t>(a.length()),
b.c_str(),
static_cast<int32_t>(b.length())
);
}
bool operator < (const FontCollectionEntry& other)
{
int comparison;
comparison = CompareStrings(name, other.name);
if (comparison != CSTR_EQUAL ) return comparison == CSTR_LESS_THAN;
if (fontWeight != other.fontWeight ) return fontWeight < other.fontWeight;
if (fontStretch != other.fontStretch ) return fontStretch < other.fontStretch;
if (fontStyle != other.fontStyle ) return fontStyle < other.fontStyle;
comparison = CompareStrings(familyName, other.familyName);
if (comparison != CSTR_EQUAL ) return comparison == CSTR_LESS_THAN;
return false;
}
};
struct FontCollectionFilter
{
FontCollectionFilterMode mode;
uint32_t selectedFontIndex; // Previous font collection index used when applying this filter.
std::wstring parameter;
};
protected:
void OnSize();
void OnMove();
DialogProcResult CALLBACK OnCommand(HWND hwnd, WPARAM wParam, LPARAM lParam);
DialogProcResult CALLBACK OnNotification(HWND hwnd, WPARAM wParam, LPARAM lParam);
DialogProcResult CALLBACK OnDragAndDrop(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
void OnKeyDown(UINT keyCode);
void OnMenuPopup(HMENU menu, UINT position, BOOL isSystemWindowMenu);
void MarkNeedsRepaint();
bool ProcessCommandLine(_In_z_ const wchar_t* commandLine);
static void ShowHelp();
STDMETHODIMP ParseCommandLine(_In_z_ const wchar_t* commandLine);
STDMETHODIMP OnChooseFont();
STDMETHODIMP OpenFontFiles();
STDMETHODIMP ReloadSystemFontSet();
STDMETHODIMP ChooseColor(IN OUT uint32_t& color);
STDMETHODIMP CopyToClipboard(bool copyPlainText = false);
STDMETHODIMP CopyImageToClipboard();
STDMETHODIMP PasteFromClipboard();
STDMETHODIMP InitializeLanguageMenu();
STDMETHODIMP InitializeFontCollectionListUI();
STDMETHODIMP InitializeFontCollectionFilterUI();
STDMETHODIMP UpdateFontCollectionListUI(uint32_t newSelectedItem = 0);
STDMETHODIMP UpdateFontCollectionFilterUI();
STDMETHODIMP RebuildFontCollectionList();
STDMETHODIMP DrawFontCollectionIconPreview(const NMLVCUSTOMDRAW* customDraw);
STDMETHODIMP RebuildFontCollectionListFromFileNames(_In_opt_z_ wchar_t const* baseFilePath, array_ref<wchar_t const> fileNames);
STDMETHODIMP InitializeBlankFontCollection();
void ResetFontList();
STDMETHODIMP GetFontProperty(
IDWriteFont* font,
FontCollectionFilterMode filterMode,
wchar_t const* languageName,
_Out_ std::wstring& fontPropertyValue,
_Out_ std::vector<std::pair<uint32_t,uint32_t> >& fontPropertyValueTokens
);
STDMETHODIMP AddFontToFontCollectionList(
IDWriteFont* font,
uint32_t firstFontIndex,
_In_z_ wchar_t const* languageName,
const std::wstring& name
);
bool DoesFontFilterApply(
FontCollectionFilterMode filterMode,
const std::wstring& filterParameter,
const std::wstring& fontPropertyValue,
const std::vector<std::pair<uint32_t, uint32_t> > fontPropertyValueTokens
);
bool SplitFontProperty(
FontCollectionFilterMode filterMode,
const std::wstring& fontPropertyValue,
OUT std::vector<std::wstring>& fontPropertyValueArray
);
HRESULT SetCurrentFilter(
FontCollectionFilterMode filterMode_ = FontCollectionFilterMode::None
);
HRESULT PushFilter(
uint32_t selectedFontIndex // Must be < fontCollectionList_.size()
);
HRESULT PopFilter(
uint32_t newFilterLevel
);
HRESULT CreateDefaultFontSet();
enum AppendLogMode
{
AppendLogModeImmediate,
AppendLogModeCached,
AppendLogModeMessageBox,
};
void AppendLog(AppendLogMode appendLogMode, const wchar_t* logMessage, ...);
protected:
HWND hwnd_ = nullptr;
HMONITOR hmonitor_ = nullptr;
HMODULE dwriteModule_ = nullptr;
HIMAGELIST fontCollectionImageList_ = nullptr;
ComPtr<IDWriteFactory> dwriteFactory_;
ComPtr<IDWriteRenderingParams> renderingParams_;
ComPtr<IDWriteBitmapRenderTarget> renderTarget_;
ComPtr<IDWriteFontSet> fontSet_;
ComPtr<IDWriteFontCollection> fontCollection_;
uint32_t fontColor_ = 0xFF000000;
uint32_t backgroundColor_ = 0xFFFFFFFF;
uint32_t highlightColor_ = 0xFFFFFFFF;
uint32_t highlightBackgroundColor_ = 0xFFFF0000;
uint32_t faintSelectionColor_ = 0xFF808080;
uint32_t currentLanguageIndex_ = 0; // English US
bool includeRemoteFonts_ = false;
bool wantSortedFontList_ = true;
bool showFontPreview_ = true;
std::vector<FontCollectionEntry> fontCollectionList_;
std::vector<FontCollectionFilter> fontCollectionFilters_;
std::wstring cachedLog_;
std::map<std::wstring, uint32_t> fontCollectionListStringMap_;
FontCollectionFilterMode filterMode_ = FontCollectionFilterMode::TypographicFamilyName;
private:
// No copy construction allowed.
MainWindow(const MainWindow& b);
MainWindow& operator=(const MainWindow&);
public:
~MainWindow();
};