Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 11126 → Rev 11127

/trunk/Scribus/scribus/fonts/scface_ps.cpp
0,0 → 1,113
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include <QDir>
#include <QFileInfo>
 
#include "ftface.h"
#include "scface_ps.h"
 
 
 
QStringList ScFace_postscript::findFontMetrics(const QString& fontPath) const
{
QStringList metricsFiles;
QFileInfo fi(fontPath);
 
QString fontDir = fi.absolutePath();
QString fontFile = fi.fileName();
 
metricsFiles += findFontMetrics(fontDir, fontFile);
 
//if no metrics found look in afm and pfm subdirs
if ( metricsFiles.size() <= 0 )
{
QDir dir;
if (dir.exists(fontDir + "/AFMs"))
metricsFiles += findFontMetrics(fontDir + "/AFMs", fontFile);
if (dir.exists(fontDir + "/afm") && metricsFiles.size() <= 0)
metricsFiles += findFontMetrics(fontDir + "/afm", fontFile);
if (dir.exists(fontDir + "/Pfm") && metricsFiles.size() <= 0)
metricsFiles += findFontMetrics(fontDir + "/Pfm", fontFile);
if (dir.exists(fontDir + "/pfm") && metricsFiles.size() <= 0)
metricsFiles += findFontMetrics(fontDir + "/pfm", fontFile);
}
 
return metricsFiles;
}
 
QStringList ScFace_postscript::findFontMetrics(const QString& baseDir, const QString& baseName) const
{
QStringList metricsFiles;
QString basePath = baseDir + "/" + baseName;
QString afnm = basePath.left(basePath.length()-3);
 
// Look for afm files
QString afmName(afnm+"afm");
if(QFile::exists(afmName))
metricsFiles.append(afmName);
else
{
afmName = afnm+"Afm";
if(QFile::exists(afmName))
metricsFiles.append(afmName);
else
{
afmName = afnm+"AFM";
if(QFile::exists(afmName))
metricsFiles.append(afmName);
}
}
 
// Look for pfm files
QString pfmName(afnm+"pfm");
if(QFile::exists(pfmName))
metricsFiles.append(pfmName);
else
{
pfmName = afnm+"Pfm";
if(QFile::exists(pfmName))
metricsFiles.append(pfmName);
else
{
afmName = afnm+"PFM";
if(QFile::exists(pfmName))
metricsFiles.append(pfmName);
}
}
 
return metricsFiles;
}
 
bool ScFace_postscript::loadFontMetrics(FT_Face face, const QString& fontPath) const
{
bool metricsFound = false;
QStringList fontMetrics = findFontMetrics(fontPath);
if (fontMetrics.size() > 0)
{
bool brokenMetric = false;
QString metricsFile;
for (int i = 0; i < fontMetrics.size(); ++i)
{
metricsFile = fontMetrics.at(i);
if (FT_Attach_File(face, metricsFile.toLocal8Bit().constData()))
{
qDebug(QObject::tr("Font %1 has broken metrics in file %2, ignoring metrics").arg(fontPath).arg(metricsFile).toLatin1().constData());
brokenMetric = true;
}
else
{
if (brokenMetric)
qDebug(QObject::tr("Valid metrics were found for font %1, using metrics in file %2").arg(fontFile).arg(metricsFile).toLatin1().constData());
metricsFound = true;
break;
}
}
}
else
qDebug(QObject::tr("No metrics found for font %1, ignoring font").arg(fontPath).toLatin1().constData());
return metricsFound;
}
/trunk/Scribus/scribus/fonts/scface_ps.h
38,6 → 38,10
typeCode = ScFace::TYPE1;
}
 
virtual QStringList findFontMetrics(const QString& fontPath) const;
virtual QStringList findFontMetrics(const QString& baseDir, const QString& baseName) const;
virtual bool loadFontMetrics(FT_Face face, const QString& fontPath) const;
 
virtual void load() const // routine by Franz Schmid - modified by Alastair M. Robinson
{
FtFace::load();
49,37 → 53,13
qDebug(QObject::tr("Font %1 is broken (no Face), discarding it").arg(fontFile).toLatin1().constData());
return;
}
QString afnm = fontFile.left(fontFile.length()-3);
QFile afm(afnm+"afm");
if(!(afm.exists()))
if (loadFontMetrics(face, fontFile))
{
afm.setFileName(afnm+"Afm");
// re-initialize: ScFaceData::load() just clears caches,
// FtFace::load() skips FT_New_Face if m_face is already defined.
// dont mind checking glyphs again for now (PS files have only 255 glyphs max, anyway)
FtFace::load();
}
if(!(afm.exists()))
{
afm.setFileName(afnm+"AFM");
}
if(!(afm.exists()))
{
afm.setFileName(afnm+"pfm");
}
if(!(afm.exists()))
{
afm.setFileName(afnm+"Pfm");
}
if(!(afm.exists())) {
afm.setFileName(afnm+"PFM");
}
if (afm.exists())
{
if (FT_Attach_File(face, afm.fileName().toLocal8Bit().constData()))
qDebug(QObject::tr("Font %1 has broken metrics in file %2, ignoring metrics").arg(fontFile).arg(afm.fileName()).toLatin1().constData());
else
// re-initialize: ScFaceData::load() just clears caches,
// FtFace::load() skips FT_New_Face if m_face is already defined.
// dont mind checking glyphs again for now (PS files have only 255 glyphs max, anyway)
FtFace::load();
}
// Ascent = tmp.setNum(face->ascender);
// Descender = tmp.setNum(face->descender);
// CapHeight = Ascent;