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
|
/*
This file is part of Konsole, an X terminal.
Copyright (C) 2005 by Maksim Orlovich <maksim@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
#include <tqfile.h>
#include <tqtextstream.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
using namespace std;
static TQ_UINT32 charVal(TQChar val)
{
if (val == ' ')
return 0;
else
return 1;
}
static TQ_UINT32 readGlyphLine(TQTextStream& input)
{
TQString line = input.readLine();
while (line.length() < 5)
line += ' ';
TQ_UINT32 val = charVal(line[0]) |
(charVal(line[1]) << 1) |
(charVal(line[2]) << 2) |
(charVal(line[3]) << 3) |
(charVal(line[4]) << 4);
return val;
}
static TQ_UINT32 readGlyph(TQTextStream& input)
{
return readGlyphLine(input) |
(readGlyphLine(input) << 5) |
(readGlyphLine(input) << 10) |
(readGlyphLine(input) << 15) |
(readGlyphLine(input) << 20);
}
int main(int argc, char **argv)
{
if (argc < 1)
{
tqWarning("usage: fontembedder font.src > font.h");
exit(1);
}
TQFile inFile(argv[1]);
if (!inFile.open(IO_ReadOnly))
{
tqFatal("Can not open %s", argv[1]);
}
TQTextStream input(&inFile);
TQ_UINT32 glyphStates[128];
for (int i = 0; i < 128; ++i)
glyphStates[i] = 0; //nothing..
while (!input.atEnd())
{
TQString line = input.readLine();
line = line.stripWhiteSpace();
if (line.isEmpty())
continue; //Skip empty lines
if (line[0] == '#')
continue; //Skip comments
//Must be a glyph ID.
int glyph = line.toInt(0, 16);
if ((glyph < 0x2500) || (glyph > 0x257f))
tqFatal("Invalid glyph number");
glyph = glyph - 0x2500;
glyphStates[glyph] = readGlyph(input);
}
//Output.
cout<<"// WARNING: Autogenerated by \"fontembedder " << argv[1] << "\".\n";
cout<<"// You probably do not want to hand-edit this!\n\n";
cout<<"static const TQ_UINT32 LineChars[] = {\n";
//Nicely formatted: 8 per line, 16 lines
for (int line = 0; line < 128; line += 8)
{
cout<<"\t";
for (int col = line; col < line + 8; ++col)
{
cout<<"0x"<<hex<<setw(8)<<setfill('0')<<glyphStates[col];
if (col != 127)
cout<<", ";
}
cout<<"\n";
}
cout<<"};\n";
return 0;
}
|