Konsole
fontembedder.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <QtCore/QFile>
00022 #include <QtCore/QTextStream>
00023 #include <stdlib.h>
00024 #include <iostream>
00025 #include <iomanip>
00026
00027 using namespace std;
00028
00029 static quint32 charVal(QChar val)
00030 {
00031 if (val == ' ')
00032 return 0;
00033 else
00034 return 1;
00035 }
00036
00037 static quint32 readGlyphLine(QTextStream& input)
00038 {
00039 QString line = input.readLine();
00040 while (line.length() < 5)
00041 line += ' ';
00042
00043 quint32 val = charVal(line[0]) |
00044 (charVal(line[1]) << 1) |
00045 (charVal(line[2]) << 2) |
00046 (charVal(line[3]) << 3) |
00047 (charVal(line[4]) << 4);
00048 return val;
00049 }
00050
00051 static quint32 readGlyph(QTextStream& input)
00052 {
00053 return readGlyphLine(input) |
00054 (readGlyphLine(input) << 5) |
00055 (readGlyphLine(input) << 10) |
00056 (readGlyphLine(input) << 15) |
00057 (readGlyphLine(input) << 20);
00058 }
00059
00060 int main(int argc, char **argv)
00061 {
00062 if (argc < 1)
00063 {
00064 qWarning("usage: fontembedder font.src > font.h");
00065 exit(1);
00066 }
00067 QFile inFile(argv[1]);
00068 if (!inFile.open(QIODevice::ReadOnly))
00069 {
00070 qFatal("Can not open %s", argv[1]);
00071 }
00072
00073 QTextStream input(&inFile);
00074
00075 quint32 glyphStates[128];
00076 for (int i = 0; i < 128; ++i)
00077 glyphStates[i] = 0;
00078
00079 while (!input.atEnd())
00080 {
00081 QString line = input.readLine();
00082 line = line.trimmed();
00083 if (line.isEmpty())
00084 continue;
00085 if (line[0] == '#')
00086 continue;
00087
00088
00089 int glyph = line.toInt(0, 16);
00090 if ((glyph < 0x2500) || (glyph > 0x257f))
00091 qFatal("Invalid glyph number");
00092
00093 glyph = glyph - 0x2500;
00094
00095 glyphStates[glyph] = readGlyph(input);
00096 }
00097
00098
00099 cout<<"// WARNING: Autogenerated by \"fontembedder " << argv[1] << "\".\n";
00100 cout<<"// You probably do not want to hand-edit this!\n\n";
00101 cout<<"static const quint32 LineChars[] = {\n";
00102
00103
00104 for (int line = 0; line < 128; line += 8)
00105 {
00106 cout<<"\t";
00107 for (int col = line; col < line + 8; ++col)
00108 {
00109 cout<<"0x"<<hex<<setw(8)<<setfill('0')<<glyphStates[col];
00110 if (col != 127)
00111 cout<<", ";
00112 }
00113 cout<<"\n";
00114 }
00115 cout<<"};\n";
00116 return 0;
00117 }
00118
00119