SVN_SILENT made messages (.desktop file)
[kdegraphics.git] / okular / generators / dvi / fontEncoding.cpp
blob615cd6d43837c73b4a5f0a89de573b5fe1aaa902
1 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-
2 // fontEncoding.cpp
3 //
4 // Part of KDVI - A DVI previewer for the KDE desktop environment
5 //
6 // (C) 2003 Stefan Kebekus
7 // Distributed under the GPL
9 #include <config.h>
11 #ifdef HAVE_FREETYPE
13 #include "fontEncoding.h"
14 #include "kvs_debug.h"
16 #include <QFile>
17 #include <QProcess>
18 #include <QTextStream>
20 //#define DEBUG_FONTENC
23 fontEncoding::fontEncoding(const QString &encName)
25 #ifdef DEBUG_FONTENC
26 kDebug(kvs::dvi) << "fontEncoding( " << encName << " )";
27 #endif
29 _isValid = false;
30 // Use kpsewhich to find the encoding file.
31 QProcess kpsewhich;
32 kpsewhich.setReadChannelMode(QProcess::MergedChannels);
34 kpsewhich.start("kpsewhich",
35 QStringList() << encName,
36 QIODevice::ReadOnly|QIODevice::Text);
38 if (!kpsewhich.waitForStarted()) {
39 kError(kvs::dvi) << "fontEncoding::fontEncoding(...): kpsewhich could not be started." << endl;
40 return;
43 // We wait here while the external program runs concurrently.
44 kpsewhich.waitForFinished(-1);
46 const QString encFileName = QString(kpsewhich.readAll()).trimmed();
47 if (encFileName.isEmpty()) {
48 kError(kvs::dvi) << QString("fontEncoding::fontEncoding(...): The file '%1' could not be found by kpsewhich.").arg(encName) << endl;
49 return;
52 #ifdef DEBUG_FONTENC
53 kDebug(kvs::dvi) << "FileName of the encoding: " << encFileName;
54 #endif
56 QFile file( encFileName );
57 if ( file.open( QIODevice::ReadOnly ) ) {
58 // Read the file (excluding comments) into the QString variable
59 // 'fileContent'
60 QTextStream stream( &file );
61 QString fileContent;
62 while ( !stream.atEnd() )
63 fileContent += stream.readLine().section('%', 0, 0); // line of text excluding '\n' until first '%'-sign
64 file.close();
66 fileContent = fileContent.trimmed();
68 // Find the name of the encoding
69 encodingFullName = fileContent.section('[', 0, 0).simplified().mid(1);
70 #ifdef DEBUG_FONTENC
71 kDebug(kvs::dvi) << "encodingFullName: " << encodingFullName;
72 #endif
74 fileContent = fileContent.section('[', 1, 1).section(']',0,0).simplified();
75 const QStringList glyphNameList = fileContent.split('/', QString::SkipEmptyParts);
77 int i = 0;
78 for ( QStringList::ConstIterator it = glyphNameList.constBegin(); (it != glyphNameList.constEnd())&&(i<256); ++it ) {
79 glyphNameVector[i] = (*it).simplified();
80 #ifdef DEBUG_FONTENC
81 kDebug(kvs::dvi) << i << ": " << glyphNameVector[i];
82 #endif
83 i++;
85 for(; i<256; i++)
86 glyphNameVector[i] = ".notdef";
87 } else {
88 kError(kvs::dvi) << QString("fontEncoding::fontEncoding(...): The file '%1' could not be opened.").arg(encFileName) << endl;
89 return;
92 _isValid = true;
95 #endif // HAVE_FREETYPE