add more spacing
[personal-kdebase.git] / apps / konsole / src / fontembedder.cpp
blobd1dc6e0b1ee2b243d328928e6151fd3438ced356
1 /*
2 This file is part of Konsole, an X terminal.
3 Copyright 2005 by Maksim Orlovich <maksim@kde.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301 USA.
21 #include <QtCore/QFile>
22 #include <QtCore/QTextStream>
23 #include <stdlib.h>
24 #include <iostream>
25 #include <iomanip>
27 using namespace std;
29 static quint32 charVal(QChar val)
31 if (val == ' ')
32 return 0;
33 else
34 return 1;
37 static quint32 readGlyphLine(QTextStream& input)
39 QString line = input.readLine();
40 while (line.length() < 5)
41 line += ' ';
43 quint32 val = charVal(line[0]) |
44 (charVal(line[1]) << 1) |
45 (charVal(line[2]) << 2) |
46 (charVal(line[3]) << 3) |
47 (charVal(line[4]) << 4);
48 return val;
51 static quint32 readGlyph(QTextStream& input)
53 return readGlyphLine(input) |
54 (readGlyphLine(input) << 5) |
55 (readGlyphLine(input) << 10) |
56 (readGlyphLine(input) << 15) |
57 (readGlyphLine(input) << 20);
60 int main(int argc, char **argv)
62 if (argc < 1)
64 qWarning("usage: fontembedder font.src > font.h");
65 exit(1);
67 QFile inFile(argv[1]);
68 if (!inFile.open(QIODevice::ReadOnly))
70 qFatal("Can not open %s", argv[1]);
73 QTextStream input(&inFile);
75 quint32 glyphStates[128];
76 for (int i = 0; i < 128; ++i)
77 glyphStates[i] = 0; //nothing..
79 while (!input.atEnd())
81 QString line = input.readLine();
82 line = line.trimmed();
83 if (line.isEmpty())
84 continue; //Skip empty lines
85 if (line[0] == '#')
86 continue; //Skip comments
88 //Must be a glyph ID.
89 int glyph = line.toInt(0, 16);
90 if ((glyph < 0x2500) || (glyph > 0x257f))
91 qFatal("Invalid glyph number");
93 glyph = glyph - 0x2500;
95 glyphStates[glyph] = readGlyph(input);
98 //Output.
99 cout<<"// WARNING: Autogenerated by \"fontembedder " << argv[1] << "\".\n";
100 cout<<"// You probably do not want to hand-edit this!\n\n";
101 cout<<"static const quint32 LineChars[] = {\n";
103 //Nicely formatted: 8 per line, 16 lines
104 for (int line = 0; line < 128; line += 8)
106 cout<<"\t";
107 for (int col = line; col < line + 8; ++col)
109 cout<<"0x"<<hex<<setw(8)<<setfill('0')<<glyphStates[col];
110 if (col != 127)
111 cout<<", ";
113 cout<<"\n";
115 cout<<"};\n";
116 return 0;
119 //kate: indent-width 4; tab-width 4; space-indent on;