-
Notifications
You must be signed in to change notification settings - Fork 5
/
LxSrcFontFactory.cpp
57 lines (52 loc) · 1.46 KB
/
LxSrcFontFactory.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
#include "stdafx.h"
#include "LxCommon.h"
#include "LxSrcFontFactory.h"
SrcFontFactory* SrcFontFactory::lpViewWindowInstance = nullptr;
void SrcFontFactory::store_stream_logfont(FILE* file, LOGFONT& logfont)
{
fwrite(&logfont, 1, sizeof(LOGFONT), file);
}
void SrcFontFactory::build_stream_logfont(FILE* file, LOGFONT& logfont)
{
fread(&logfont, 1, sizeof(LOGFONT), file);
}
void SrcFontFactory::store_stream(FILE* file, std::set<size_t>& font_list_still_using)
{
store_stream_int(file, font_list_still_using.size());
LOGFONT logfont;
for (auto _index : font_list_still_using)
{
store_stream_int(file, _index);
get_src_font(_index)->GetLogFont(&logfont);
SrcFontFactory::store_stream_logfont(file, logfont);
}
}
void SrcFontFactory::build_from_stream(FILE* file)
{
int font_cnt = read_stream_int(file);
int index;
LOGFONT logfont;
int max_index = 0;
for (int i = 0; i < font_cnt; i++)
{
index = read_stream_int(file);
if (index > max_index)
max_index = index;
SrcFontFactory::build_stream_logfont(file, logfont);
CFont* font_t = new CFont();
font_t->CreateFontIndirect(&logfont);
if (index > font_list.size())
font_list.resize(index + index / 2);
font_list[index - 1] = font_t;
font_map.insert(std::make_pair(logfont, index));
}
if (max_index > 0)
font_list.resize(max_index);
}
void SrcFontFactory::clear()
{
for (auto font : font_list)
delete font;
font_list.clear();
font_map.clear();
}