QT_BEGIN_NAMESPACE void QBasicFontDatabase::populateFontDatabase() { QString fontpath = fontDir(); QDir dir(fontpath); if (!dir.exists()) { qWarning("QFontDatabase: Cannot find font directory %s - is Qt installed correctly?", qPrintable(fontpath)); return; } QStringList nameFilters; nameFilters << QLatin1String("*.ttf") << QLatin1String("*.ttc") << QLatin1String("*.pfa") << QLatin1String("*.pfb") << QLatin1String("*.otf"); foreach (const QFileInfo &fi, dir.entryInfoList(nameFilters, QDir::Files)) { const QByteArray file = QFile::encodeName(fi.absoluteFilePath()); QBasicFontDatabase::addTTFile(QByteArray(), file); } }
bool QWebOSFontDatabase::createFileWithFontData(QString& fileName, const QByteArray &fontData) { QDir fontDir(appFontDir()); if (!fontDir.mkpath(fontDir.path())) { qDebug("Couldn't make directory (%s) to hold application fonts", qPrintable(fontDir.path())); return false; } QByteArray fontDataHash = QCryptographicHash::hash(fontData, QCryptographicHash::Sha1); fileName = appFontDir() + "/" + QString(fontDataHash.toHex()) + ".fnt"; QFile fontFile(fileName); if (!fontFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { qDebug("Couldn't open font file (%s) to store the font data", qPrintable(fileName)); return false; } qint64 bytesWritten = fontFile.write(fontData.constData(), fontData.size()); fontFile.close(); if (bytesWritten < 0) { qDebug("Error writing font data to %s", qPrintable(fileName)); return false; } else if (bytesWritten < fontData.size()) { qDebug("Wrote %d bytes to %s. Expected %d.", bytesWritten, qPrintable(fileName), fontData.size()); return false; } return true; }
void KNFontManager::loadCustomFontFolder(const QString &folderPath) { QDir fontDir(folderPath); //Check the folder is exsist or not, if not exsist, create one. if(fontDir.exists()) { //Get all the files, load all the fonts. QFileInfoList fontFiles=fontDir.entryInfoList(); for(QFileInfoList::const_iterator i=fontFiles.constBegin(); i!=fontFiles.constEnd(); ++i) { //Ignore the dot(.) and dot-dot(..). if((*i).fileName()=="." || (*i).fileName()=="..") { continue; } //If the type of current file is File, then try to load the font. if((*i).isFile()) { loadCustomFont(*i); } } } else { fontDir.mkpath(folderPath); } }
/*! Returns a list of names of all the available font families. */ QStringList FontDatabase::families() const { #ifndef QT_NO_FONTDATABASE return QFontDatabase::families(); #else #ifndef QWS QStringList list; return list; #else QStringList list; QDict<void> familyDict; QDiskFont *qdf; for ( qdf=qt_fontmanager->diskfonts.first(); qdf!=0; qdf=qt_fontmanager->diskfonts.next()) { QString familyname = qdf->name; if ( !familyDict.find( familyname ) ) { familyDict.insert( familyname, (void *)1 ); list.append( familyname ); } } QDir dir(fontDir(),"*.qpf"); for (int i=0; i<(int)dir.count(); i++) { QString familyname = fontFamily(dir[i]); if ( !familyDict.find( familyname ) ) { familyDict.insert( familyname, (void *)1 ); list.append( familyname ); } } return list; #endif #endif }
/*! \internal */ void FontDatabase::readFonts( QFontFactory *factory ) { #ifndef QWS return; #else // Load in font definition file QString fn = fontDir() + "fontdir"; FILE* fontdef=fopen(fn.local8Bit(),"r"); if(!fontdef) { QCString temp=fn.local8Bit(); qWarning("Cannot find font definition file %s - is $QTDIR set correctly?", temp.data()); return; } char buf[200]=""; char name[200]=""; char render[200]=""; char file[200]=""; char flags[200]=""; char isitalic[10]=""; fgets(buf,200,fontdef); while(!feof(fontdef)) { if ( buf[0] != '#' ) { int weight=50; int size=0; flags[0]=0; sscanf(buf,"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags); QString filename; if ( file[0] != '/' ) filename = fontDir(); filename += file; if ( QFile::exists(filename) ) { if( factory->name() == render ) { QDiskFont * qdf=new QDiskFont(factory,name,isitalic[0]=='y', weight,size,flags,filename); qt_fontmanager->diskfonts.append(qdf); #if QT_VERSION >= 232 QFontDatabase::qwsAddDiskFont( qdf ); #endif } } } fgets(buf,200,fontdef); } fclose(fontdef); #endif }
QFont Theme::font(const QString& name) { if(!d->fontsAdded) { QDir fontDir(d->basePath + '/' + d->fontPath); QStringList entries = fontDir.entryList(QDir::Files); QFontDatabase db; Q_FOREACH(const QString &entry, entries) { d->addedFonts.append(db.addApplicationFont(fontDir.absoluteFilePath(entry))); }
QString QWebOSFontDatabase::resolvePath(const QString& fontFile) { QString path; if (fontFile.indexOf('/')== 0) { // This is an absolute path, return as it is path = fontFile; } else { // We will treat it in relation to what is defined by 'fontDir()' // see gui/text/qplatformfontdatabase_qpa.cpp for that path = fontDir() + "/" + fontFile; } return path; }
void QBasicFontDatabase::populateFontDatabase() { QString fontpath = fontDir(); if(!QFile::exists(fontpath)) { qFatal("QFontDatabase: Cannot find font directory %s - is Qt installed correctly?", qPrintable(fontpath)); } #ifndef NO_FREETYPE_ARPHIC_MBF { QDir dir(fontpath, QLatin1String("*.mbf")); for (int i = 0; i < int(dir.count()); ++i) { const QByteArray file = QFile::encodeName(dir.absoluteFilePath(dir[i])); //qDebug() << "looking at " << file; addMBFile(QByteArray(), file); } } #endif /*add by T1*/ #ifndef NO_FREETYPE_ARPHIC_MMF { QDir dir(fontpath, QLatin1String("*.mmf")); for (int i = 0; i < int(dir.count()); ++i) { const QByteArray file = QFile::encodeName(dir.absoluteFilePath(dir[i])); qDebug() << "looking MMF at " << file; addMMFile(QByteArray(), file); } } #endif /*******************/ QDir dir(fontpath); dir.setNameFilters(QStringList() << QLatin1String("*.ttf") << QLatin1String("*.ttc") << QLatin1String("*.pfa") << QLatin1String("*.pfb")); dir.refresh(); for (int i = 0; i < int(dir.count()); ++i) { const QByteArray file = QFile::encodeName(dir.absoluteFilePath(dir[i])); // qDebug() << "looking at" << file; addTTFile(QByteArray(), file); } }
void QBasicUnixFontDatabase::populateFontDatabase() { QPlatformFontDatabase::populateFontDatabase(); QString fontpath = fontDir(); if(!QFile::exists(fontpath)) { qFatal("QFontDatabase: Cannot find font directory %s - is Qt installed correctly?", qPrintable(fontpath)); } QDir dir(fontpath); dir.setNameFilters(QStringList() << QLatin1String("*.ttf") << QLatin1String("*.ttc") << QLatin1String("*.pfa") << QLatin1String("*.pfb")); dir.refresh(); for (int i = 0; i < int(dir.count()); ++i) { const QByteArray file = QFile::encodeName(dir.absoluteFilePath(dir[i])); addTTFile(QByteArray(), file); } }
void QAndroidPlatformFontDatabase::populateFontDatabase() { QString fontpath = fontDir(); QDir dir(fontpath); if (Q_UNLIKELY(!dir.exists())) { qFatal("QFontDatabase: Cannot find font directory %s - is Qt installed correctly?", qPrintable(fontpath)); } QStringList nameFilters; nameFilters << QLatin1String("*.ttf") << QLatin1String("*.otf") << QLatin1String("*.ttc"); const auto entries = dir.entryInfoList(nameFilters, QDir::Files); for (const QFileInfo &fi : entries) { const QByteArray file = QFile::encodeName(fi.absoluteFilePath()); QFreeTypeFontDatabase::addTTFile(QByteArray(), file); } }
void ConfigDialog::on_tabWidget_currentChanged(int tab) { if (!m_fontsInited && ui->tabWidget->tabText(tab) == tr("OSD")) { ui->tabWidget->setCursor(QCursor(Qt::WaitCursor)); QMap<QString, QStringList> internalFontList; QDir fontDir(QStandardPaths::locate(QStandardPaths::FontsLocation, QString(), QStandardPaths::LocateDirectory)); QStringList fontFilter; fontFilter << "*.ttf"; fontDir.setNameFilters(fontFilter); QFileInfoList fontList = fontDir.entryInfoList(); for (int i = 0; i < fontList.size(); ++i) { int id = QFontDatabase::addApplicationFont(fontList.at(i).absoluteFilePath()); QString fontListFamily = QFontDatabase::applicationFontFamilies(id).at(0); internalFontList[fontListFamily].append(fontList.at(i).fileName()); } QMap<QString, QStringList>::const_iterator i; for (i = internalFontList.constBegin(); i != internalFontList.constEnd(); ++i) { QTreeWidgetItem *fontFamily = new QTreeWidgetItem(ui->fontTreeWidget); fontFamily->setText(0, i.key()); for (int j = 0; j < i.value().size(); ++j) { QTreeWidgetItem *fontFile = new QTreeWidgetItem(fontFamily); fontFile->setText(0, i.value()[j]); if (i.value()[j] == ui->fontLineEdit->text()) { fontFamily->setExpanded(true); fontFile->setSelected(true); ui->fontTreeWidget->scrollToItem(fontFile); m_font.setFamily(i.key()); ui->fontPreviewLabel->setFont(m_font); } } } ui->tabWidget->setCursor(QCursor(Qt::ArrowCursor)); m_fontsInited = true; } }