-
Notifications
You must be signed in to change notification settings - Fork 226
/
main.cpp
167 lines (135 loc) · 4.18 KB
/
main.cpp
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
//--------------------------------------------------------------------------------------
// main.cpp
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "pch.h"
#include <conio.h>
#include <fstream>
#include "FrontPanel\RasterFont.h"
#include "CommandLineHelpers.h"
#include "TestWindow.h"
#include "Visualization.h"
using namespace ATG;
namespace
{
enum OPTIONS : uint64_t
{
OPT_CHARACTER_REGION = 1,
OPT_MAX
};
static_assert(OPT_MAX <= 64, "Options must fit into a uint64_t bitfield");
const SValue g_Options[] =
{
{ L"cr", OPT_CHARACTER_REGION },
};
void PrintLogo()
{
wprintf(L"Microsoft (R) Raster Font Viewer for for Xbox One\n");
wprintf(L"Copyright (C) Microsoft Corp. All rights reserved.\n");
#ifdef _DEBUG
wprintf(L"*** Debug build ***\n");
#endif
wprintf(L"\n");
}
void PrintUsage()
{
PrintLogo();
wprintf(L"Usage: rasterfontgen [options] <filename>\n\n");
wprintf(L" -cr:<range> Character region. Specifies a range of unicode code points to include in the output.\n");
wprintf(L" Examples: -cr:a-z -cr:0x1200-0x1250 -cr:0x1234\n");
}
} // ANONYMOUS namespace
int wmain(int argc, wchar_t *argv[])
{
// Parameters and defaults
const wchar_t *outputFilename = nullptr;
std::vector<WCRANGE> regions;
unsigned individualOptions = 0;
for (int argIdx = 1; argIdx < argc; ++argIdx)
{
wchar_t *arg = argv[argIdx];
if (('-' == arg[0]) || ('/' == arg[0]))
{
arg++;
wchar_t *value = nullptr;
for (value = arg; *value && (':' != *value); ++value);
if (*value)
*value++ = 0;
unsigned option = 0;
if (!LookupByName(arg, g_Options, option) || (individualOptions & (1 << option)))
{
PrintUsage();
return 1;
}
if (option != OPT_CHARACTER_REGION)
{
individualOptions |= (1 << option);
}
// Handle options with an additional value parameter
switch (option)
{
case OPT_CHARACTER_REGION:
if (!*value)
{
if (argIdx + 1 >= argc)
{
PrintUsage();
return 1;
}
++argIdx;
value = argv[argIdx];
}
break;
}
switch (option)
{
case OPT_CHARACTER_REGION:
if (!ParseCharacterRegion(value, regions))
{
wprintf(L"Invalid character region value specified with -%ls: (%ls)\n", LookupByValue(OPT_CHARACTER_REGION, g_Options), value);
wprintf(L"\n");
PrintUsage();
return 1;
}
break;
}
}
else if(outputFilename)
{
wprintf(L"Output file already specified: %ls.\n(Found something else: %ls\n", outputFilename, arg);
PrintUsage();
return 1;
}
else
{
outputFilename = arg;
}
}
if (!outputFilename)
{
PrintUsage();
return 1;
}
try
{
RasterFont rf(outputFilename);
HBITMAP fontBitmap = DrawRasterGlyphSheet(rf.GetGlyphs(), regions);
TestWindow([&fontBitmap](HDC hDC)
{
BITMAP bmData = {};
GetObject(fontBitmap, sizeof(BITMAP), &bmData);
HDC memDC = CreateCompatibleDC(hDC);
SelectObject(memDC, fontBitmap);
BitBlt(hDC, 0, 0, bmData.bmWidth, bmData.bmHeight, memDC, 0, 0, SRCCOPY);
DeleteObject(memDC);
});
DeleteObject(fontBitmap);
}
catch (std::exception &exn)
{
printf("Encountered an excption when trying to load the font: \n%s", exn.what());
}
return 0;
}