1 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-
4 // Part of KDVI - A DVI previewer for the KDE desktop environment
6 // (C) 2003 Stefan Kebekus
7 // Distributed under the GPL
13 #include "fontEncoding.h"
14 #include "kvs_debug.h"
18 #include <QTextStream>
20 //#define DEBUG_FONTENC
23 fontEncoding::fontEncoding(const QString
&encName
)
26 kDebug(kvs::dvi
) << "fontEncoding( " << encName
<< " )";
30 // Use kpsewhich to find the encoding file.
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
;
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
;
53 kDebug(kvs::dvi
) << "FileName of the encoding: " << encFileName
;
56 QFile
file( encFileName
);
57 if ( file
.open( QIODevice::ReadOnly
) ) {
58 // Read the file (excluding comments) into the QString variable
60 QTextStream
stream( &file
);
62 while ( !stream
.atEnd() )
63 fileContent
+= stream
.readLine().section('%', 0, 0); // line of text excluding '\n' until first '%'-sign
66 fileContent
= fileContent
.trimmed();
68 // Find the name of the encoding
69 encodingFullName
= fileContent
.section('[', 0, 0).simplified().mid(1);
71 kDebug(kvs::dvi
) << "encodingFullName: " << encodingFullName
;
74 fileContent
= fileContent
.section('[', 1, 1).section(']',0,0).simplified();
75 const QStringList glyphNameList
= fileContent
.split('/', QString::SkipEmptyParts
);
78 for ( QStringList::ConstIterator it
= glyphNameList
.constBegin(); (it
!= glyphNameList
.constEnd())&&(i
<256); ++it
) {
79 glyphNameVector
[i
] = (*it
).simplified();
81 kDebug(kvs::dvi
) << i
<< ": " << glyphNameVector
[i
];
86 glyphNameVector
[i
] = ".notdef";
88 kError(kvs::dvi
) << QString("fontEncoding::fontEncoding(...): The file '%1' could not be opened.").arg(encFileName
) << endl
;
95 #endif // HAVE_FREETYPE