Commit f036e475 authored by David Faure's avatar David Faure
Browse files

From the code, QFontDatabase::families() can still return foundries in Qt4,

even though for me it doesn't use foundries for the fonts that kformula installs.

svn path=/trunk/koffice/; revision=547675
parent cf64996f
......@@ -21,6 +21,7 @@
#include <QPen>
#include <QFontDatabase>
#include <QChar>
#include <kstaticdeleter.h>
#include "fontstyle.h"
......@@ -36,23 +37,42 @@ void FontStyle::fillNameTable( SymbolTable::NameTable& names )
}
}
static bool fontAvailable( const QString& fontName )
{
#if 0 // slloooww
if ( QFontInfo( QFont( fontName ) ).family().lower() == fontName.lower() )
#endif
QFontDatabase db;
if ( db.families().contains( fontName ) ) // ## TODO remove foundry from families list?
return true;
else {
kWarning(39001) << "Font '" << fontName << "' not found" << endl;
return false;
}
}
// Cache the family list from QFontDatabase after fixing it up (no foundry, lowercase)
class FontList {
public:
FontList() {
QFontDatabase db;
const QStringList lst = db.families();
for ( QStringList::const_iterator it = lst.begin(), end = lst.end() ; it != end ; ++it ) {
const QString name = *it;
int i = name.indexOf('[');
QString family = name;
// Remove foundry
if ( i > -1 ) {
const int li = name.lastIndexOf(']');
if (i < li) {
if (name[i - 1] == ' ')
i--;
family = name.left(i);
}
}
m_fontNames.append( family.toLower() );
}
}
bool hasFont( const QString& fontName ) const {
return m_fontNames.contains( fontName );
}
QStringList m_fontNames;
};
static FontList* s_fontList = 0;
static KStaticDeleter<FontList> s_fontList_sd;
void FontStyle::testFont( QStringList& missing, const QString& fontName ) {
if ( !fontAvailable( fontName ) ) {
if ( !s_fontList )
s_fontList_sd.setObject( s_fontList, new FontList() );
if ( !s_fontList->hasFont( fontName ) ) {
kWarning(39001) << "Font '" << fontName << "' not found" << endl;
missing.append( fontName );
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment