-
Notifications
You must be signed in to change notification settings - Fork 0
/
Glyph.cpp
89 lines (77 loc) · 1.55 KB
/
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
#include "Glyph.hpp"
#include <QDebug>
Glyph::Glyph(){}
Glyph::Glyph(uint32_t c, uint32_t w, uint32_t h)
{
_code = c;
offset = 0;
resize(w, h);
}
uint8_t& Glyph::pixel(uint32_t x, uint32_t y)
{
return _bitmap[x][y];
}
bool Glyph::check(uint32_t x, uint32_t y) const
{
return _bitmap[x][y];
}
void Glyph::resize(uint32_t w, uint32_t h)
{
_bitmap.resize(w);
for(uint32_t i = 0; i < w; ++i)
{
_bitmap[i].resize(h);
}
}
uint32_t Glyph::code() const
{
return _code;
}
uint32_t Glyph::width() const
{
return _bitmap.size();
}
uint32_t Glyph::height() const
{
if(_bitmap.isEmpty())
return 0;
return _bitmap[0].size();
}
QTextStream& operator >> (QTextStream& str, Glyph& g)
{
QIODevice* dev = str.device();
dev->read((char*)(&g._code), 4);
dev->read((char*)(&g.offset), 4);
uint32_t i, j;
char raw = 0;
for(i = 0; i < g.height(); ++i)
{
for(j = 0; j < g.width(); ++j)
{
dev->read(&raw, 1);
g._bitmap[j][i] = raw;
}
}
return str;
}
QTextStream& operator << (QTextStream& str, const Glyph& g)
{
QIODevice* dev = str.device();
dev->write((char*)(&g._code), 4);
dev->write((char*)(&g.offset), 4);
uint32_t i, j;
char raw = 0;
for(i = 0; i < g.height(); ++i)
{
for(j = 0; j < g.width(); ++j)
{
raw = g._bitmap[j][i] ? 255 : 0;
dev->write(&raw, 1);
}
}
return str;
}
bool operator < (const Glyph& a, const Glyph& b)
{
return a._code < b._code;
}