-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFontDoc.cpp
242 lines (209 loc) · 5.06 KB
/
FontDoc.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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// EditViewDoc.cpp : implementation file
//
#include "stdafx.h"
#include "SCIPicEditor.h"
#include "FontDoc.h"
#include "FontResource.h"
#include "NonViewClient.h"
#include "ResourceDocument.h"
EGACOLOR g_egaFontPalette[] =
{
{ 0, 0 },
{ 15, 15 },
};
// CFontDoc
IMPLEMENT_DYNCREATE(CFontDoc, CResourceDocument)
CFontDoc::CFontDoc()
{
_nChar = 65; // Letter A
_color.color1 = 0xf; // white
_color.color2 = 0x0; // black
// Default letters with which to preview:
_strLetters = DEFAULT_FONTPREVIEWLETTERS;
}
BOOL CFontDoc::QueryCapability(const GUID guid, void **ppv)
{
BOOL fRet = FALSE;
if (IsEqualGUID(guid, __uuidof(ICelResourceDoc)))
{
fRet = TRUE;
*ppv = static_cast<ICelResourceDoc*>(this);
}
else if (IsEqualGUID(guid, __uuidof(IFontResourceDoc)))
{
fRet = TRUE;
*ppv = static_cast<IFontResourceDoc*>(this);
}
else
{
fRet = __super::QueryCapability(guid, ppv);
}
return fRet;
}
//
// Ensures the selected char exists in the current resource.
//
void CFontDoc::_ValidateCelIndex()
{
const CFontResource *pEVR = GetFontResource();
if (pEVR)
{
int cChars = pEVR->GetCelCount();
ASSERT(cChars > 0);
_nChar = min(_nChar, cChars - 1);
_nChar = max(_nChar, 0);
}
}
void CFontDoc::_OnSuccessfulSave(const IResourceBase *pDoc)
{
SetLastSaved(pDoc);
}
void CFontDoc::SetFontResource(std::auto_ptr<CFontResource> pFont, int id)
{
SetResource(pFont.get(), id);
pFont.release();
}
void CFontDoc::SetSelectedCel(int nChar)
{
// It is essential to check this, otherwise we'll end up in an infinite loop!
if (_nChar != nChar)
{
_nChar = nChar;
_ValidateCelIndex();
UpdateAllViewsAndNonViews(NULL, VIEWUPDATEHINT_CELSELECTIONCHANGED);
}
}
void CFontDoc::GetLabelString(PTSTR pszLabel, size_t cch, int nCel) const
{
if (nCel < 32)
{
StringCchPrintf(pszLabel, cch, TEXT("(%d)"), nCel);
}
else
{
StringCchPrintf(pszLabel, cch, TEXT("%c (%d)"), nCel, nCel);
}
}
//
// Allows the callers to move "selection"
//
void CFontDoc::MoveSelectedCel(CPoint point)
{
// if the y changed, that indicates a loop change.
if (point.y != 0)
{
int nChar = _nChar + point.y;
SetSelectedCel(nChar);
}
if (point.x != 0)
{
int nChar = _nChar + point.x;
SetSelectedCel(nChar);
}
}
void CFontDoc::SetLineHeight(WORD cyLine)
{
const CFontResource *pEVR = GetFontResource();
if (pEVR)
{
// Take the current resource and clone it, then apply the changes.
CFontResource *pEVRClone = static_cast<CFontResource*>(pEVR->Clone());
if (pEVRClone)
{
pEVRClone->SetLineHeight(cyLine);
_NewResource(pEVRClone, VIEWUPDATEHINT_CELCHANGED);
}
}
}
void CFontDoc::SetPreviewLetters(PCTSTR pszLetters)
{
_strLetters = pszLetters;
UpdateAllViewsAndNonViews(NULL, VIEWUPDATEHINT_SAMPLETEXTCHANGED);
}
void CFontDoc::RemoveCel(DWORD dwIndex)
{
// Can't do this for fonts
}
int CFontDoc::GetDefaultZoom() const
{
return theApp._iDefaultZoomFont;
}
void CFontDoc::SetDefaultZoom(int iZoom) const
{
theApp._iDefaultZoomFont = iZoom;
}
int CFontDoc::GetSelectedGroup(DWORD *rgGroups, size_t ceGroup)
{
int iRet = 0;
if (_fApplyToAllCels)
{
// Just use indices 0 to 127
ASSERT(ceGroup >= 128);
for (DWORD i = 0; i < 128; i++)
{
rgGroups[i] = i;
}
iRet = 128;
}
else
{
iRet = __super::GetSelectedGroup(rgGroups, ceGroup);
}
return iRet;
}
void CFontDoc::MakeFont()
{
CFontDialog fontDialog;
if (IDOK == fontDialog.DoModal())
{
LOGFONT *pLogFont = fontDialog.m_cf.lpLogFont;
if (pLogFont)
{
CFontResource *pEFR = new CFontResource();
if (pEFR)
{
if (SUCCEEDED(pEFR->InitFromLOGFONT(pLogFont)))
{
// Give it the same package and resource number as the current resource
const CFontResource *pEFRCurrent = GetFontResource();
if (pEFRCurrent)
{
pEFR->SetResourceNumber(pEFRCurrent->GetResourceNumber());
pEFR->SetPackageNumber(pEFRCurrent->GetPackageNumber());
}
_NewResource(pEFR, VIEWUPDATEHINT_CELCHANGED | VIEWUPDATEHINT_NEWVIEW);
}
else
{
delete pEFR;
}
}
}
}
}
BEGIN_MESSAGE_MAP(CFontDoc, CRasterResourceDocument)
END_MESSAGE_MAP()
// CFontDoc diagnostics
#ifdef _DEBUG
void CFontDoc::AssertValid() const
{
__super::AssertValid();
}
void CFontDoc::Dump(CDumpContext& dc) const
{
__super::Dump(dc);
}
#endif //_DEBUG
// CFontDoc serialization
void CFontDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
// CFontDoc commands