Fix styleName support in QPA font database

Font styleName support was disconnected since Qt switched to QPA
fontdatabase. Now add the code from Qt 4.8 back to enable this in
QPA.

Change-Id: Iab2cbfd5468f87542183348c2123ca4b2c270692
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
This commit is contained in:
Jiang Jiang 2012-07-11 14:39:54 +02:00 committed by The Qt Project
parent 3c09f6bc9a
commit fa7661d8b2
9 changed files with 37 additions and 41 deletions

View File

@ -274,27 +274,15 @@ struct QtFontFoundry
QtFontStyle *QtFontFoundry::style(const QtFontStyle::Key &key, const QString &styleName, bool create) QtFontStyle *QtFontFoundry::style(const QtFontStyle::Key &key, const QString &styleName, bool create)
{ {
int pos = 0; int pos = 0;
if (count) { for (; pos < count; pos++) {
// if styleName for searching first if possible bool hasStyleName = !styleName.isEmpty(); // search styleName first if available
if (!styleName.isEmpty()) { if (hasStyleName && !styles[pos]->styleName.isEmpty()) {
for (; pos < count; pos++) { if (styles[pos]->styleName == styleName)
if (styles[pos]->styleName == styleName) return styles[pos];
return styles[pos]; } else {
}
}
int low = 0;
int high = count;
pos = count / 2;
while (high > low) {
if (styles[pos]->key == key) if (styles[pos]->key == key)
return styles[pos]; return styles[pos];
if (styles[pos]->key < key)
low = pos + 1;
else
high = pos;
pos = (high + low) / 2;
} }
pos = low;
} }
if (!create) if (!create)
return 0; return 0;
@ -309,7 +297,6 @@ QtFontStyle *QtFontFoundry::style(const QtFontStyle::Key &key, const QString &st
QtFontStyle *style = new QtFontStyle(key); QtFontStyle *style = new QtFontStyle(key);
style->styleName = styleName; style->styleName = styleName;
memmove(styles + pos + 1, styles + pos, (count-pos)*sizeof(QtFontStyle *));
styles[pos] = style; styles[pos] = style;
count++; count++;
return styles[pos]; return styles[pos];

View File

@ -52,7 +52,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
Q_GUI_EXPORT void qt_registerFont(const QString &familyName, const QString &foundryname, int weight, Q_GUI_EXPORT void qt_registerFont(const QString &familyName, const QString &stylename,
const QString &foundryname, int weight,
QFont::Style style, int stretch, bool antialiased, QFont::Style style, int stretch, bool antialiased,
bool scalable, int pixelSize, bool fixedPitch, bool scalable, int pixelSize, bool fixedPitch,
const QSupportedWritingSystems &writingSystems, void *handle) const QSupportedWritingSystems &writingSystems, void *handle)
@ -75,7 +76,7 @@ Q_GUI_EXPORT void qt_registerFont(const QString &familyName, const QString &fou
} }
QtFontFoundry *foundry = f->foundry(foundryname, true); QtFontFoundry *foundry = f->foundry(foundryname, true);
QtFontStyle *fontStyle = foundry->style(styleKey, QString(), true); QtFontStyle *fontStyle = foundry->style(styleKey, stylename, true);
fontStyle->smoothScalable = scalable; fontStyle->smoothScalable = scalable;
fontStyle->antialiased = antialiased; fontStyle->antialiased = antialiased;
QtFontSize *size = fontStyle->pixelSize(pixelSize ? pixelSize : SMOOTH_SCALABLE, true); QtFontSize *size = fontStyle->pixelSize(pixelSize ? pixelSize : SMOOTH_SCALABLE, true);

View File

@ -47,7 +47,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
extern void qt_registerFont(const QString &familyname, const QString &foundryname, int weight, extern void qt_registerFont(const QString &familyname, const QString &stylename,
const QString &foundryname, int weight,
QFont::Style style, int stretch, bool antialiased, QFont::Style style, int stretch, bool antialiased,
bool scalable, int pixelSize, bool fixedPitch, bool scalable, int pixelSize, bool fixedPitch,
const QSupportedWritingSystems &writingSystems, void *hanlde); const QSupportedWritingSystems &writingSystems, void *hanlde);
@ -89,7 +90,7 @@ void QPlatformFontDatabase::registerQPF2Font(const QByteArray &dataArray, void *
} }
} }
QFont::Stretch stretch = QFont::Unstretched; QFont::Stretch stretch = QFont::Unstretched;
registerFont(fontName,QString(),fontWeight,fontStyle,stretch,true,false,pixelSize,false,writingSystems,handle); registerFont(fontName,QString(),QString(),fontWeight,fontStyle,stretch,true,false,pixelSize,false,writingSystems,handle);
} }
} else { } else {
qDebug() << "header verification of QPF2 font failed. maybe it is corrupt?"; qDebug() << "header verification of QPF2 font failed. maybe it is corrupt?";
@ -117,7 +118,8 @@ void QPlatformFontDatabase::registerQPF2Font(const QByteArray &dataArray, void *
\sa registerQPF2Font() \sa registerQPF2Font()
*/ */
void QPlatformFontDatabase::registerFont(const QString &familyname, const QString &foundryname, QFont::Weight weight, void QPlatformFontDatabase::registerFont(const QString &familyname, const QString &stylename,
const QString &foundryname, QFont::Weight weight,
QFont::Style style, QFont::Stretch stretch, bool antialiased, QFont::Style style, QFont::Stretch stretch, bool antialiased,
bool scalable, int pixelSize, bool fixedPitch, bool scalable, int pixelSize, bool fixedPitch,
const QSupportedWritingSystems &writingSystems, void *usrPtr) const QSupportedWritingSystems &writingSystems, void *usrPtr)
@ -125,7 +127,7 @@ void QPlatformFontDatabase::registerFont(const QString &familyname, const QStrin
if (scalable) if (scalable)
pixelSize = 0; pixelSize = 0;
qt_registerFont(familyname, foundryname, weight, style, qt_registerFont(familyname, stylename, foundryname, weight, style,
stretch, antialiased, scalable, pixelSize, stretch, antialiased, scalable, pixelSize,
fixedPitch, writingSystems, usrPtr); fixedPitch, writingSystems, usrPtr);
} }

View File

@ -116,7 +116,8 @@ public:
//callback //callback
static void registerQPF2Font(const QByteArray &dataArray, void *handle); static void registerQPF2Font(const QByteArray &dataArray, void *handle);
static void registerFont(const QString &familyname, const QString &foundryname, QFont::Weight weight, static void registerFont(const QString &familyname, const QString &stylename,
const QString &foundryname, QFont::Weight weight,
QFont::Style style, QFont::Stretch stretch, bool antialiased, QFont::Style style, QFont::Stretch stretch, bool antialiased,
bool scalable, int pixelSize, bool fixedPitch, bool scalable, int pixelSize, bool fixedPitch,
const QSupportedWritingSystems &writingSystems, void *handle); const QSupportedWritingSystems &writingSystems, void *handle);

View File

@ -452,7 +452,7 @@ QStringList QBasicFontDatabase::addTTFile(const QByteArray &fontData, const QByt
QFont::Stretch stretch = QFont::Unstretched; QFont::Stretch stretch = QFont::Unstretched;
registerFont(family,QString(),weight,style,stretch,true,true,0,fixedPitch,writingSystems,fontFile); registerFont(family,QString::fromLatin1(face->style_name),QString(),weight,style,stretch,true,true,0,fixedPitch,writingSystems,fontFile);
families.append(family); families.append(family);

View File

@ -318,6 +318,7 @@ void QFontconfigDatabase::populateFontDatabase()
FcChar8 *file_value; FcChar8 *file_value;
int indexValue; int indexValue;
FcChar8 *foundry_value; FcChar8 *foundry_value;
FcChar8 *style_value;
FcBool scalable; FcBool scalable;
FcBool antialias; FcBool antialias;
@ -325,7 +326,7 @@ void QFontconfigDatabase::populateFontDatabase()
FcObjectSet *os = FcObjectSetCreate(); FcObjectSet *os = FcObjectSetCreate();
FcPattern *pattern = FcPatternCreate(); FcPattern *pattern = FcPatternCreate();
const char *properties [] = { const char *properties [] = {
FC_FAMILY, FC_WEIGHT, FC_SLANT, FC_FAMILY, FC_STYLE, FC_WEIGHT, FC_SLANT,
FC_SPACING, FC_FILE, FC_INDEX, FC_SPACING, FC_FILE, FC_INDEX,
FC_LANG, FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, FC_WEIGHT, FC_LANG, FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, FC_WEIGHT,
FC_WIDTH, FC_WIDTH,
@ -371,6 +372,8 @@ void QFontconfigDatabase::populateFontDatabase()
scalable = FcTrue; scalable = FcTrue;
if (FcPatternGetString(fonts->fonts[i], FC_FOUNDRY, 0, &foundry_value) != FcResultMatch) if (FcPatternGetString(fonts->fonts[i], FC_FOUNDRY, 0, &foundry_value) != FcResultMatch)
foundry_value = 0; foundry_value = 0;
if (FcPatternGetString(fonts->fonts[i], FC_STYLE, 0, &style_value) != FcResultMatch)
style_value = 0;
if(FcPatternGetBool(fonts->fonts[i],FC_ANTIALIAS,0,&antialias) != FcResultMatch) if(FcPatternGetBool(fonts->fonts[i],FC_ANTIALIAS,0,&antialias) != FcResultMatch)
antialias = true; antialias = true;
@ -438,7 +441,8 @@ void QFontconfigDatabase::populateFontDatabase()
bool fixedPitch = spacing_value >= FC_MONO; bool fixedPitch = spacing_value >= FC_MONO;
QFont::Stretch stretch = QFont::Unstretched; QFont::Stretch stretch = QFont::Unstretched;
QPlatformFontDatabase::registerFont(familyName,QLatin1String((const char *)foundry_value),weight,style,stretch,antialias,scalable,pixel_size,fixedPitch,writingSystems,fontFile); QString styleName = style_value ? QString::fromUtf8((const char *) style_value) : QString();
QPlatformFontDatabase::registerFont(familyName,styleName,QLatin1String((const char *)foundry_value),weight,style,stretch,antialias,scalable,pixel_size,fixedPitch,writingSystems,fontFile);
// qDebug() << familyName << (const char *)foundry_value << weight << style << &writingSystems << scalable << true << pixel_size; // qDebug() << familyName << (const char *)foundry_value << weight << style << &writingSystems << scalable << true << pixel_size;
} }
@ -462,9 +466,9 @@ void QFontconfigDatabase::populateFontDatabase()
while (f->qtname) { while (f->qtname) {
QString familyQtName = QString::fromLatin1(f->qtname); QString familyQtName = QString::fromLatin1(f->qtname);
registerFont(familyQtName,QString(),QFont::Normal,QFont::StyleNormal,QFont::Unstretched,true,true,0,f->fixed,ws,0); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleNormal,QFont::Unstretched,true,true,0,f->fixed,ws,0);
registerFont(familyQtName,QString(),QFont::Normal,QFont::StyleItalic,QFont::Unstretched,true,true,0,f->fixed,ws,0); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleItalic,QFont::Unstretched,true,true,0,f->fixed,ws,0);
registerFont(familyQtName,QString(),QFont::Normal,QFont::StyleOblique,QFont::Unstretched,true,true,0,f->fixed,ws,0); registerFont(familyQtName,QString(),QString(),QFont::Normal,QFont::StyleOblique,QFont::Unstretched,true,true,0,f->fixed,ws,0);
++f; ++f;
} }

View File

@ -227,6 +227,7 @@ void QCoreTextFontDatabase::populateFontDatabase()
for (int i = 0; i < numFonts; ++i) { for (int i = 0; i < numFonts; ++i) {
CTFontDescriptorRef font = (CTFontDescriptorRef) CFArrayGetValueAtIndex(fonts, i); CTFontDescriptorRef font = (CTFontDescriptorRef) CFArrayGetValueAtIndex(fonts, i);
QCFString familyName = (CFStringRef) CTFontDescriptorCopyLocalizedAttribute(font, kCTFontFamilyNameAttribute, NULL); QCFString familyName = (CFStringRef) CTFontDescriptorCopyLocalizedAttribute(font, kCTFontFamilyNameAttribute, NULL);
QCFString styleName = (CFStringRef)CTFontDescriptorCopyLocalizedAttribute(font, kCTFontStyleNameAttribute, NULL);
QCFType<CFDictionaryRef> styles = (CFDictionaryRef) CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute); QCFType<CFDictionaryRef> styles = (CFDictionaryRef) CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute);
QFont::Weight weight = QFont::Normal; QFont::Weight weight = QFont::Normal;
QFont::Style style = QFont::StyleNormal; QFont::Style style = QFont::StyleNormal;
@ -285,7 +286,7 @@ void QCoreTextFontDatabase::populateFontDatabase()
} }
CFRetain(font); CFRetain(font);
QPlatformFontDatabase::registerFont(familyName, foundryName, weight, style, stretch, QPlatformFontDatabase::registerFont(familyName, styleName, foundryName, weight, style, stretch,
true /* antialiased */, true /* scalable */, true /* antialiased */, true /* scalable */,
pixelSize, fixedPitch, writingSystems, (void *) font); pixelSize, fixedPitch, writingSystems, (void *) font);
CFStringRef psName = (CFStringRef) CTFontDescriptorCopyAttribute(font, kCTFontNameAttribute); CFStringRef psName = (CFStringRef) CTFontDescriptorCopyAttribute(font, kCTFontNameAttribute);

View File

@ -1033,17 +1033,17 @@ static bool addFontToDatabase(QString familyName, const QString &scriptName,
writingSystems.setSupported(ws); writingSystems.setSupported(ws);
} }
QPlatformFontDatabase::registerFont(familyName, foundryName, weight, QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, weight,
style, stretch, antialias, scalable, size, fixed, writingSystems, 0); style, stretch, antialias, scalable, size, fixed, writingSystems, 0);
// add fonts windows can generate for us: // add fonts windows can generate for us:
if (weight <= QFont::DemiBold) if (weight <= QFont::DemiBold)
QPlatformFontDatabase::registerFont(familyName, foundryName, QFont::Bold, QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, QFont::Bold,
style, stretch, antialias, scalable, size, fixed, writingSystems, 0); style, stretch, antialias, scalable, size, fixed, writingSystems, 0);
if (style != QFont::StyleItalic) if (style != QFont::StyleItalic)
QPlatformFontDatabase::registerFont(familyName, foundryName, weight, QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, weight,
QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, 0); QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, 0);
if (weight <= QFont::DemiBold && style != QFont::StyleItalic) if (weight <= QFont::DemiBold && style != QFont::StyleItalic)
QPlatformFontDatabase::registerFont(familyName, foundryName, QFont::Bold, QPlatformFontDatabase::registerFont(familyName, QString(), foundryName, QFont::Bold,
QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, 0); QFont::StyleItalic, stretch, antialias, scalable, size, fixed, writingSystems, 0);
if (!englishName.isEmpty()) if (!englishName.isEmpty())

View File

@ -279,20 +279,20 @@ static bool addFontToDatabase(QString familyName, const QString &scriptName,
if (!QDir::isAbsolutePath(value)) if (!QDir::isAbsolutePath(value))
value.prepend(QString::fromLocal8Bit(qgetenv("windir") + "\\Fonts\\")); value.prepend(QString::fromLocal8Bit(qgetenv("windir") + "\\Fonts\\"));
QPlatformFontDatabase::registerFont(faceName, foundryName, weight, style, stretch, QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, weight, style, stretch,
antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); antialias, scalable, size, fixed, writingSystems, createFontFile(value, index));
// add fonts windows can generate for us: // add fonts windows can generate for us:
if (weight <= QFont::DemiBold) if (weight <= QFont::DemiBold)
QPlatformFontDatabase::registerFont(faceName, foundryName, QFont::Bold, style, stretch, QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, QFont::Bold, style, stretch,
antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); antialias, scalable, size, fixed, writingSystems, createFontFile(value, index));
if (style != QFont::StyleItalic) if (style != QFont::StyleItalic)
QPlatformFontDatabase::registerFont(faceName, foundryName, weight, QFont::StyleItalic, stretch, QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, weight, QFont::StyleItalic, stretch,
antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); antialias, scalable, size, fixed, writingSystems, createFontFile(value, index));
if (weight <= QFont::DemiBold && style != QFont::StyleItalic) if (weight <= QFont::DemiBold && style != QFont::StyleItalic)
QPlatformFontDatabase::registerFont(faceName, foundryName, QFont::Bold, QFont::StyleItalic, stretch, QPlatformFontDatabase::registerFont(faceName, QString(), foundryName, QFont::Bold, QFont::StyleItalic, stretch,
antialias, scalable, size, fixed, writingSystems, createFontFile(value, index)); antialias, scalable, size, fixed, writingSystems, createFontFile(value, index));
if (!englishName.isEmpty()) if (!englishName.isEmpty())