QStringList ScFace_postscript::findFontMetrics(const QString& fontPath) const { QStringList metricsFiles; QFileInfo fi(fontPath); QString fontDir = fi.absolutePath(); QString fontFile = fi.completeBaseName(); metricsFiles += findFontMetrics(fontDir, fontFile); //if no metrics found look in afm and pfm subdirs if ( metricsFiles.empty() ) { QDir dir; if (dir.exists(fontDir + "/AFMs")) metricsFiles += findFontMetrics(fontDir + "/AFMs", fontFile); if (dir.exists(fontDir + "/afm") && metricsFiles.empty()) metricsFiles += findFontMetrics(fontDir + "/afm", fontFile); if (dir.exists(fontDir + "/Pfm") && metricsFiles.empty()) metricsFiles += findFontMetrics(fontDir + "/Pfm", fontFile); if (dir.exists(fontDir + "/pfm") && metricsFiles.empty()) metricsFiles += findFontMetrics(fontDir + "/pfm", fontFile); } return metricsFiles; }
bool ScFace_postscript::loadFontMetrics(FT_Face face, const QString& fontPath) const { bool metricsFound = false; QStringList fontMetrics = findFontMetrics(fontPath); if (!fontMetrics.empty()) { 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, metricsFile); brokenMetric = true; } else { if (brokenMetric) qDebug() << QObject::tr("Valid metrics were found for font %1, using metrics in file %2").arg(fontFile, metricsFile); metricsFound = true; break; } } } else qDebug() << QObject::tr("No metrics found for font %1, ignoring font").arg(fontPath); return metricsFound; }
bool CollectForOutput::collectFonts() { PrefsManager *prefsManager = PrefsManager::instance(); QMap<QString,int>::Iterator it3; QMap<QString,int>::Iterator it3end = m_Doc->UsedFonts.end(); int c=0; for (it3 = m_Doc->UsedFonts.begin(); it3 != it3end; ++it3) { QFileInfo itf(prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].fontFilePath()); QString oldFileITF(prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].fontFilePath()); QString outFileITF(m_outputDirectory + "fonts/" + itf.fileName()); bool success = copyFileAtomic(oldFileITF, outFileITF); if (!success) qDebug()<<"CollectForOutput::collectFile copyFileAtomic failed for"<<oldFileITF<<"to"<<outFileITF; #ifndef Q_OS_WIN32 else { QFile of(outFileITF); if (of.exists()) { bool permsSet=of.setPermissions(QFile::permissions(oldFileITF)); if (!permsSet) qDebug()<<"Unable to set permissions successfully while collecting for output on"<<outFileITF; } else qDebug()<<"Unable to set permissions successfully while collecting for output on"<<outFileITF<<"as the file does not exist"; } #endif if (prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].type() == ScFace::TYPE1) { QStringList metrics; QString fontDir = itf.absolutePath(); QString fontFile = itf.fileName(); metrics += findFontMetrics(fontDir, fontFile); if ( metrics.size() <= 0 ) { QDir dir; if (dir.exists(fontDir + "/AFMs")) metrics += findFontMetrics(fontDir + "/AFMs", fontFile); if (dir.exists(fontDir + "/afm") && metrics.size() <= 0) metrics += findFontMetrics(fontDir + "/afm", fontFile); if (dir.exists(fontDir + "/Pfm") && metrics.size() <= 0) metrics += findFontMetrics(fontDir + "/Pfm", fontFile); if (dir.exists(fontDir + "/pfm") && metrics.size() <= 0) metrics += findFontMetrics(fontDir + "/pfm", fontFile); } for (int a = 0; a < metrics.size(); a++) { QString origAFM = metrics[a]; QFileInfo fi(origAFM); QString outFileAFM(m_outputDirectory + "fonts/" + fi.fileName()); bool success = copyFileAtomic(origAFM, outFileAFM); if (!success) qDebug()<<"CollectForOutput::collectFile copyFileAtomic failed for"<<origAFM<<"to"<<outFileAFM; #ifndef Q_OS_WIN32 else { QFile of(outFileAFM); if (of.exists()) { bool permsSet=of.setPermissions(QFile::permissions(origAFM)); if (!permsSet) qDebug()<<"Unable to set permissions successfully while collecting for output on"<<outFileAFM; } else qDebug()<<"Unable to set permissions successfully while collecting for output on"<<outFileAFM<<"as the file does not exist"; } #endif } } if (uiCollect) emit fontsCollected(c++); } return true; }