Qt 4.8
Functions
qfontdatabase_qpa.cpp File Reference
#include "qlibraryinfo.h"
#include <QtCore/qsettings.h>
#include "qfontengine_qpa_p.h"
#include "qplatformdefs.h"
#include <QtGui/private/qapplication_p.h>
#include <QtGui/qplatformfontdatabase_qpa.h>
#include <QtCore/qmath.h>

Go to the source code of this file.

Functions

static QStringList fallbackFamilies (const QString &family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script)
 
static void initializeDb ()
 
static void load (const QString &=QString(), int=-1)
 
static QFontEngineloadEngine (int script, const QFontDef &request, QtFontFamily *family, QtFontFoundry *foundry, QtFontStyle *style, QtFontSize *size)
 
static QFontEngineloadSingleEngine (int script, const QFontDef &request, QtFontFoundry *foundry, QtFontStyle *style, QtFontSize *size)
 
void qt_applyFontDatabaseSettings (const QSettings &settings)
 
Q_GUI_EXPORT void qt_registerFont (const QString &familyName, const QString &foundryname, int weight, QFont::Style style, int stretch, bool antialiased, bool scalable, int pixelSize, const QSupportedWritingSystems &writingSystems, void *handle)
 
static void registerFont (QFontDatabasePrivate::ApplicationFont *fnt)
 

Function Documentation

◆ fallbackFamilies()

static QStringList fallbackFamilies ( const QString family,
const QFont::Style style,
const QFont::StyleHint styleHint,
const QUnicodeTables::Script script 
)
static

Definition at line 83 of file qfontdatabase_qpa.cpp.

Referenced by QFontconfigDatabase::fallbacksForFamily(), QFontDatabase::findFont(), and loadEngine().

84 {
85  QStringList retList = QApplicationPrivate::platformIntegration()->fontDatabase()->fallbacksForFamily(family,style,styleHint,script);
86  QFontDatabasePrivate *db = privateDb();
87 
89  for (i = retList.begin(); i != retList.end(); ++i) {
90  bool contains = false;
91  for (int j = 0; j < db->count; j++) {
92  QtFontFamily *qtFamily = db->families[j];
93  if (!(i->compare(qtFamily->name,Qt::CaseInsensitive))) {
94  contains = true;
95  break;
96  }
97  }
98  if (!contains) {
99  i = retList.erase(i);
100  i--;
101  }
102  }
103  return retList;
104 }
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
QtFontFamily ** families
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
const char * styleHint(const QFontDef &request)
friend class iterator
Definition: qlist.h:226
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
iterator erase(iterator pos)
Removes the item associated with the iterator pos from the list, and returns an iterator to the next ...
Definition: qlist.h:464

◆ initializeDb()

static void initializeDb ( )
static

Definition at line 108 of file qfontdatabase_qpa.cpp.

Referenced by QFontDatabase::findFont(), load(), and qt_applyFontDatabaseSettings().

109 {
110  QFontDatabasePrivate *db = privateDb();
111 
112  // init by asking for the platformfontdb for the first time or after invalidation
113  if (!db->count)
114  QApplicationPrivate::platformIntegration()->fontDatabase()->populateFontDatabase();
115 
116  if (db->reregisterAppFonts) {
117  for (int i = 0; i < db->applicationFonts.count(); i++) {
118  if (!db->applicationFonts.at(i).families.isEmpty())
120  }
121  db->reregisterAppFonts = false;
122  }
123 }
static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
QVector< ApplicationFont > applicationFonts

◆ load()

static void load ( const QString = QString(),
int  = -1 
)
inlinestatic

Definition at line 142 of file qfontdatabase_qpa.cpp.

143 {
144  // Only initialize the database if it has been cleared or not initialized yet
145  if (!privateDb()->count)
146  initializeDb();
147 }
static void initializeDb()

◆ loadEngine()

static QFontEngine* loadEngine ( int  script,
const QFontDef request,
QtFontFamily family,
QtFontFoundry foundry,
QtFontStyle style,
QtFontSize size 
)
static

Definition at line 179 of file qfontdatabase_qpa.cpp.

Referenced by QFontDatabase::findFont(), QCoreTextFontEngineMulti::macFontID(), QFontEngineMacMulti::macFontID(), and QFontEngineMulti::stringToCMap().

182 {
183 
184  QFontEngine *engine = loadSingleEngine(script, request, foundry, style, size);
185  //make sure that the db has all fallback families
186  if (engine
187  && !(request.styleStrategy & QFont::NoFontMerging) && !engine->symbol ) {
188 
189  if (family && !family->askedForFallback) {
190  QFont::Style fontStyle = QFont::Style(style->key.style);
192  if (styleHint == QFont::AnyStyle && request.fixedPitch)
193  styleHint = QFont::TypeWriter;
194  family->fallbackFamilies = fallbackFamilies(family->name,fontStyle,styleHint,QUnicodeTables::Script(script));
195 
196  family->askedForFallback = true;
197  }
198 
199  QStringList fallbacks = privateDb()->fallbackFamilies;
200  if (family && !family->fallbackFamilies.isEmpty())
201  fallbacks = family->fallbackFamilies;
202 
203  engine = new QFontEngineMultiQPA(engine, script, fallbacks);
204  }
205 
206  return engine;
207 }
uint fixedPitch
Definition: qfont_p.h:96
QStringList fallbackFamilies
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
const char * styleHint(const QFontDef &request)
static QFontEngine * loadSingleEngine(int script, const QFontDef &request, QtFontFoundry *foundry, QtFontStyle *style, QtFontSize *size)
Style
This enum describes the different styles of glyphs that are used to display text. ...
Definition: qfont.h:111
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
StyleHint
Style hints are used by the font matching algorithm to find an appropriate default family if a select...
Definition: qfont.h:69
uint styleHint
Definition: qfont_p.h:93
uint styleStrategy
Definition: qfont_p.h:92
static QStringList fallbackFamilies(const QString &family, const QFont::Style &style, const QFont::StyleHint &styleHint, const QUnicodeTables::Script &script)

◆ loadSingleEngine()

static QFontEngine* loadSingleEngine ( int  script,
const QFontDef request,
QtFontFoundry foundry,
QtFontStyle style,
QtFontSize size 
)
static

Definition at line 150 of file qfontdatabase_qpa.cpp.

Referenced by loadEngine().

154 {
155  Q_UNUSED(foundry);
156 
157  Q_ASSERT(size);
158  int pixelSize = size->pixelSize;
159  if (!pixelSize || (style->smoothScalable && pixelSize == SMOOTH_SCALABLE))
160  pixelSize = request.pixelSize;
161 
162  QFontDef def = request;
163  def.pixelSize = pixelSize;
164 
167  if (!engine) {
168  QPlatformFontDatabase *pfdb = QApplicationPrivate::platformIntegration()->fontDatabase();
169  engine = pfdb->fontEngine(def,QUnicodeTables::Script(script),size->handle);
170  if (engine) {
173  }
174  }
175  return engine;
176 }
unsigned short pixelSize
void insertEngine(const Key &key, QFontEngine *engine)
Definition: qfont.cpp:3073
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QFontCache * instance()
Definition: qfont.cpp:2919
#define SMOOTH_SCALABLE
static float pixelSize(const QFontDef &request, int dpi)
Definition: qfont_win.cpp:80
virtual QFontEngine * fontEngine(const QFontDef &fontDef, QUnicodeTables::Script script, void *handle)
Returns the font engine that can be used to render the font described by the font definition...
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
qreal pixelSize
Definition: qfont_p.h:90
int key
The QPlatformFontDatabase class makes it possible to customize how fonts are discovered and how they ...
QFontEngine * findEngine(const Key &key)
Definition: qfont.cpp:3054
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ qt_applyFontDatabaseSettings()

void qt_applyFontDatabaseSettings ( const QSettings settings)

Definition at line 127 of file qfontdatabase_qpa.cpp.

128 {
129  initializeDb();
130  QFontDatabasePrivate *db = privateDb();
131  for (int i = 0; i < db->count; ++i) {
132  QtFontFamily *family = db->families[i];
133  if (settings.contains(family->name))
134  family->fallbackFamilies = settings.value(family->name).toStringList();
135  }
136 
137  if (settings.contains(QLatin1String("Global Fallbacks")))
138  db->fallbackFamilies = settings.value(QLatin1String("Global Fallbacks")).toStringList();
139 }
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for setting key.
Definition: qsettings.cpp:3460
static void initializeDb()
QStringList fallbackFamilies
QStringList toStringList() const
Returns the variant as a QStringList if the variant has type() StringList, String ...
Definition: qvariant.cpp:2259
QStringList fallbackFamilies
QtFontFamily ** families
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
bool contains(const QString &key) const
Returns true if there exists a setting called key; returns false otherwise.
Definition: qsettings.cpp:3394

◆ qt_registerFont()

Q_GUI_EXPORT void qt_registerFont ( const QString familyName,
const QString foundryname,
int  weight,
QFont::Style  style,
int  stretch,
bool  antialiased,
bool  scalable,
int  pixelSize,
const QSupportedWritingSystems writingSystems,
void *  handle 
)

Definition at line 55 of file qfontdatabase_qpa.cpp.

Referenced by QPlatformFontDatabase::registerFont().

58 {
59  QFontDatabasePrivate *d = privateDb();
60  // qDebug() << "Adding font" << familyname << weight << italic << pixelSize << file << fileIndex << antialiased;
61  QtFontStyle::Key styleKey;
62  styleKey.style = style;
63  styleKey.weight = weight;
64  styleKey.stretch = stretch;
65  QtFontFamily *f = d->family(familyName, true);
66 
67  for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) {
68  if (writingSystems.supported(QFontDatabase::WritingSystem(i))) {
70  } else {
72  }
73  }
74 
75  QtFontFoundry *foundry = f->foundry(foundryname, true);
76  QtFontStyle *fontStyle = foundry->style(styleKey, QString(), true);
77  fontStyle->smoothScalable = scalable;
78  fontStyle->antialiased = antialiased;
79  QtFontSize *size = fontStyle->pixelSize(pixelSize?pixelSize:SMOOTH_SCALABLE, true);
80  size->handle = handle;
81 }
double d
Definition: qnumeric_p.h:62
QtFontStyle * style(const QtFontStyle::Key &, const QString &=QString(), bool=false)
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool supported(QFontDatabase::WritingSystem) const
Returns true if the writing system given by writingSystem is supported; otherwise returns false...
#define SMOOTH_SCALABLE
static float pixelSize(const QFontDef &request, int dpi)
Definition: qfont_win.cpp:80
QtFontFamily * family(const QString &f, bool=false)
unsigned char writingSystems[QFontDatabase::WritingSystemsCount]
QtFontSize * pixelSize(unsigned short size, bool=false)
QtFontFoundry * foundry(const QString &f, bool=false)

◆ registerFont()

static void registerFont ( QFontDatabasePrivate::ApplicationFont fnt)
static

Definition at line 209 of file qfontdatabase_qpa.cpp.

Referenced by fallbackFamilies(), and initializeDb().

210 {
211  QFontDatabasePrivate *db = privateDb();
212 
213  fnt->families = QApplicationPrivate::platformIntegration()->fontDatabase()->addApplicationFont(fnt->data,fnt->fileName);
214 
215  db->reregisterAppFonts = true;
216 }