mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-25 10:55:37 +00:00
79 lines
2 KiB
C++
79 lines
2 KiB
C++
// fontMap.cpp
|
|
//
|
|
// Part of KDVI - A DVI previewer for the KDE desktop environemt
|
|
//
|
|
// (C) 2003 Stefan Kebekus
|
|
// Distributed under the GPL
|
|
|
|
#include <../config.h>
|
|
#ifdef HAVE_FREETYPE
|
|
|
|
#include <kprocio.h>
|
|
#include <kstringhandler.h>
|
|
#include <qfile.h>
|
|
|
|
#include "fontMap.h"
|
|
|
|
fontMap::fontMap()
|
|
{
|
|
// Read the map file of ps2pk which will provide us with a
|
|
// dictionary "TeX Font names" <-> "Name of font files, Font Names
|
|
// and Encodings" (example: the font "Times-Roman" is called
|
|
// "ptmr8y" in the DVI file, but the Type1 font file name is
|
|
// "utmr8a.pfb". We use the map file of "ps2pk" because that progam
|
|
// has, like kdvi (and unlike dvips), no built-in fonts.
|
|
|
|
KProcIO proc;
|
|
proc << "kpsewhich" << "--format=dvips config" << "ps2pk.map";
|
|
proc.start(KProcess::Block);
|
|
QString map_fileName;
|
|
proc.readln(map_fileName);
|
|
map_fileName = map_fileName.stripWhiteSpace();
|
|
|
|
QFile file( map_fileName );
|
|
if ( file.open( IO_ReadOnly ) ) {
|
|
QTextStream stream( &file );
|
|
QString line;
|
|
while ( !stream.atEnd() ) {
|
|
line = stream.readLine().stripWhiteSpace();
|
|
if (line.at(0) == '%')
|
|
continue;
|
|
|
|
QString TeXName = KStringHandler::word(line, (unsigned int)0);
|
|
QString fontFileName = line.section('<', -1);
|
|
QString encodingName = line.section('<', -2, -2).stripWhiteSpace();
|
|
|
|
fontMapEntry &entry = fontMapEntries[TeXName];
|
|
|
|
entry.fontFileName = fontFileName;
|
|
if (encodingName.endsWith(".enc"))
|
|
entry.fontEncoding = encodingName;
|
|
}
|
|
file.close();
|
|
}
|
|
}
|
|
|
|
|
|
const QString &fontMap::findFileName(const QString &TeXName)
|
|
{
|
|
QMap<QString, fontMapEntry>::Iterator it = fontMapEntries.find(TeXName);
|
|
|
|
if (it != fontMapEntries.end())
|
|
return it.data().fontFileName;
|
|
else
|
|
return QString::null;
|
|
}
|
|
|
|
|
|
const QString &fontMap::findEncoding(const QString &TeXName)
|
|
{
|
|
QMap<QString, fontMapEntry>::Iterator it = fontMapEntries.find(TeXName);
|
|
|
|
if (it != fontMapEntries.end())
|
|
return it.data().fontEncoding;
|
|
else
|
|
return QString::null;
|
|
}
|
|
|
|
#endif // HAVE_FREETYPE
|