• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • kde-4.14
  • applications
  • konsole
  • src
fontembedder.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Konsole, an X terminal.
3  Copyright 2005 by Maksim Orlovich <maksim@kde.org>
4 
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.
9 
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.
14 
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.
19 */
20 
21 // Standard
22 #include <stdlib.h>
23 #include <iostream>
24 #include <iomanip>
25 
26 // Qt
27 #include <QtCore/QFile>
28 #include <QtCore/QTextStream>
29 
30 #include <KDebug>
31 
32 using namespace std;
33 
34 static quint32 charVal(QChar val)
35 {
36  if (val == ' ')
37  return 0;
38  else
39  return 1;
40 }
41 
42 static quint32 readGlyphLine(QTextStream& input)
43 {
44  QString line = input.readLine();
45  while (line.length() < 5)
46  line += ' ';
47 
48  quint32 val = charVal(line[0]) |
49  (charVal(line[1]) << 1) |
50  (charVal(line[2]) << 2) |
51  (charVal(line[3]) << 3) |
52  (charVal(line[4]) << 4);
53  return val;
54 }
55 
56 static quint32 readGlyph(QTextStream& input)
57 {
58  return readGlyphLine(input) |
59  (readGlyphLine(input) << 5) |
60  (readGlyphLine(input) << 10) |
61  (readGlyphLine(input) << 15) |
62  (readGlyphLine(input) << 20);
63 }
64 
65 int main(int argc, char **argv)
66 {
67  if (argc != 2) {
68  qWarning("usage: fontembedder LineFont.src > LineFont.h");
69  exit(1);
70  }
71  QFile inFile(argv[1]);
72  if (!inFile.open(QIODevice::ReadOnly)) {
73  qWarning("Can not open %s", argv[1]);
74  exit(1);
75  }
76 
77  QTextStream input(&inFile);
78 
79  // Currently, for Konsole, the input glyphs file ranges from 0x2500
80  // (9472) to x257f (9599) so this 128 will handle it. However, if
81  // more glyphs are added to the input file, this will be an issue.
82  quint32 glyphStates[128];
83  QMap<quint32, int> glyphMap;
84 
85  for (int i = 0; i < 128; ++i)
86  glyphStates[i] = 0; //nothing..
87 
88  while (!input.atEnd()) {
89  QString line = input.readLine();
90  line = line.trimmed();
91  if (line.isEmpty())
92  continue; //Skip empty lines
93  if (line[0] == '#')
94  continue; //Skip comments
95 
96  //Must be a glyph ID.
97  int glyph = line.toInt(0, 16);
98  if ((glyph < 0x2500) || (glyph > 0x257f)) {
99  qWarning("Invalid glyph number: %d aborting...", glyph);
100  exit(1);
101  } else {
102  glyph = glyph - 0x2500;
103 
104  glyphStates[glyph] = readGlyph(input);
105  // kWarning()<<glyph<<";"<<glyphStates[glyph];
106 
107  if (glyphMap.contains(glyphStates[glyph])) {
108  kWarning()<<"Code "<<glyph<<" and "<<glyphMap.value(glyphStates[glyph])<<"have the same glyph state"<<glyphStates[glyph];
109  }
110  glyphMap[glyphStates[glyph]] = glyph;
111  }
112  }
113 
114  //Output.
115  cout << "// WARNING: Autogenerated by \"fontembedder " << argv[1] << "\".\n";
116  cout << "// You probably do not want to hand-edit this!\n\n";
117  cout << "static const quint32 LineChars[] = {\n";
118 
119  //Nicely formatted: 8 per line, 16 lines
120  for (int line = 0; line < 128; line += 8) {
121  cout << " ";
122  for (int col = line; col < line + 8; ++col) {
123  cout << "0x" << hex << setw(8) << setfill('0') << glyphStates[col];
124  if (col != line + 7)
125  cout << ", ";
126  else if (col != 127)
127  cout << ",";
128  }
129  cout << "\n";
130  }
131  cout << "};\n";
132  return 0;
133 }
134 
main
int main(int argc, char **argv)
Definition: fontembedder.cpp:65
readGlyph
static quint32 readGlyph(QTextStream &input)
Definition: fontembedder.cpp:56
charVal
static quint32 charVal(QChar val)
Definition: fontembedder.cpp:34
QMap::contains
bool contains(const Key &key) const
QTextStream::readLine
QString readLine(qint64 maxlen)
QChar
QMap
QFile
QTextStream
readGlyphLine
static quint32 readGlyphLine(QTextStream &input)
Definition: fontembedder.cpp:42
QTextStream::atEnd
bool atEnd() const
QString::toInt
int toInt(bool *ok, int base) const
QString::isEmpty
bool isEmpty() const
QString::trimmed
QString trimmed() const
QString
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QString::length
int length() const
QMap::value
const T value(const Key &key) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal