forked from microsoft/Xbox-ATG-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGGO_Glyph.cpp
98 lines (83 loc) · 2.52 KB
/
GGO_Glyph.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
//--------------------------------------------------------------------------------------
// GGO_Glyph.cpp
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "GGO_Glyph.h"
using namespace ATG;
ATG::GGO_Glyph::GGO_Glyph()
: m_ggoFormat(0)
, m_character(0)
, m_glyphMetrics{}
, m_bufferSize(0)
{
}
ATG::GGO_Glyph::GGO_Glyph(HDC hdc, wchar_t wc, uint32_t ggoFormat)
: m_ggoFormat(ggoFormat)
, m_character(wc)
, m_glyphMetrics{}
, m_bufferSize(0)
{
switch (m_ggoFormat)
{
case GGO_BITMAP:
case GGO_GRAY2_BITMAP:
case GGO_GRAY4_BITMAP:
case GGO_GRAY8_BITMAP:
break;
default:
throw DX::exception_fmt<64>("Unsupported GGO format (%i). Must use a bitmap format see docs for GetGlyphOutline", m_ggoFormat);
}
MAT2 matrix = {};
matrix.eM11.value = 1;
matrix.eM12.value = 0;
matrix.eM21.value = 0;
matrix.eM22.value = 1;
uint32_t result = GetGlyphOutline(
hdc,
wc,
m_ggoFormat,
&m_glyphMetrics,
0,
nullptr,
&matrix);
if (result != GDI_ERROR)
{
m_bufferSize = result;
m_spritePixels = std::make_unique<uint8_t[]>(result);
// GGO_BITMAP:
// Returns the glyph bitmap.When the function returns, the buffer pointed to by lpBuffer
// contains a 1 - bit - per - pixel bitmap whose rows start on double-word boundaries.
result = GetGlyphOutline(
hdc,
wc,
m_ggoFormat,
&m_glyphMetrics,
result,
m_spritePixels.get(),
&matrix);
}
if (result == GDI_ERROR)
{
throw DX::exception_fmt<128>("Not able to get the glyph bitmap for character code: %i", wc);
}
}
ATG::GGO_Glyph::GGO_Glyph(GGO_Glyph && moveFrom)
: m_ggoFormat(moveFrom.m_ggoFormat)
, m_character(moveFrom.m_character)
, m_bufferSize(moveFrom.m_bufferSize)
{
memcpy(&m_glyphMetrics, &moveFrom.m_glyphMetrics, sizeof(GLYPHMETRICS));
m_spritePixels = std::move(moveFrom.m_spritePixels);
}
GGO_Glyph & ATG::GGO_Glyph::operator=(GGO_Glyph && moveFrom)
{
m_ggoFormat = moveFrom.m_ggoFormat;
m_character = moveFrom.m_character;
m_bufferSize = moveFrom.m_bufferSize;
memcpy(&m_glyphMetrics, &moveFrom.m_glyphMetrics, sizeof(GLYPHMETRICS));
m_spritePixels = std::move(moveFrom.m_spritePixels);
return *this;
}