Support QRawFont from raw data with basic unix font db
Add support for making a QFontEngine in QPA with the basic unix font database. The code is copy-pasted from qrawfont_ft.cpp. Task-number: QTBUG-20780 Change-Id: Id5492efe634fe90805fbca43356ec428d4d73117 Reviewed-on: http://codereview.qt.nokia.com/3511 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
This commit is contained in:
parent
17f3451daa
commit
b2c4c4fc2a
@ -47,6 +47,7 @@
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QLibraryInfo>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QUuid>
|
||||
|
||||
#undef QT_NO_FREETYPE
|
||||
#include <QtGui/private/qfontengine_ft_p.h>
|
||||
@ -237,6 +238,71 @@ QFontEngine *QBasicUnixFontDatabase::fontEngine(const QFontDef &fontDef, QUnicod
|
||||
return engine;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class QFontEngineFTRawData: public QFontEngineFT
|
||||
{
|
||||
public:
|
||||
QFontEngineFTRawData(const QFontDef &fontDef) : QFontEngineFT(fontDef)
|
||||
{
|
||||
}
|
||||
|
||||
void updateFamilyNameAndStyle()
|
||||
{
|
||||
fontDef.family = QString::fromAscii(freetype->face->family_name);
|
||||
|
||||
if (freetype->face->style_flags & FT_STYLE_FLAG_ITALIC)
|
||||
fontDef.style = QFont::StyleItalic;
|
||||
|
||||
if (freetype->face->style_flags & FT_STYLE_FLAG_BOLD)
|
||||
fontDef.weight = QFont::Bold;
|
||||
}
|
||||
|
||||
bool initFromData(const QByteArray &fontData)
|
||||
{
|
||||
FaceId faceId;
|
||||
faceId.filename = "";
|
||||
faceId.index = 0;
|
||||
faceId.uuid = QUuid::createUuid().toByteArray();
|
||||
|
||||
return init(faceId, true, Format_None, fontData);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
QFontEngine *QBasicUnixFontDatabase::fontEngine(const QByteArray &fontData, qreal pixelSize,
|
||||
QFont::HintingPreference hintingPreference)
|
||||
{
|
||||
QFontDef fontDef;
|
||||
fontDef.pixelSize = pixelSize;
|
||||
|
||||
QFontEngineFTRawData *fe = new QFontEngineFTRawData(fontDef);
|
||||
if (!fe->initFromData(fontData)) {
|
||||
delete fe;
|
||||
return 0;
|
||||
}
|
||||
|
||||
fe->updateFamilyNameAndStyle();
|
||||
|
||||
switch (hintingPreference) {
|
||||
case QFont::PreferNoHinting:
|
||||
fe->setDefaultHintStyle(QFontEngineFT::HintNone);
|
||||
break;
|
||||
case QFont::PreferFullHinting:
|
||||
fe->setDefaultHintStyle(QFontEngineFT::HintFull);
|
||||
break;
|
||||
case QFont::PreferVerticalHinting:
|
||||
fe->setDefaultHintStyle(QFontEngineFT::HintLight);
|
||||
break;
|
||||
default:
|
||||
// Leave it as it is
|
||||
break;
|
||||
}
|
||||
|
||||
return fe;
|
||||
}
|
||||
|
||||
QStringList QBasicUnixFontDatabase::fallbacksForFamily(const QString family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script) const
|
||||
{
|
||||
Q_UNUSED(family);
|
||||
|
@ -61,6 +61,7 @@ class QBasicUnixFontDatabase : public QPlatformFontDatabase
|
||||
public:
|
||||
void populateFontDatabase();
|
||||
QFontEngine *fontEngine(const QFontDef &fontDef, QUnicodeTables::Script script, void *handle);
|
||||
QFontEngine *fontEngine(const QByteArray &fontData, qreal pixelSize, QFont::HintingPreference hintingPreference);
|
||||
QStringList fallbacksForFamily(const QString family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script) const;
|
||||
QStringList addApplicationFont(const QByteArray &fontData, const QString &fileName);
|
||||
void releaseHandle(void *handle);
|
||||
|
Loading…
Reference in New Issue
Block a user