49 #include <QtCore/qsettings.h> 50 #if !defined(QT_NO_FREETYPE) 54 #include FT_FREETYPE_H 58 #include "private/qfactoryloader_p.h" 59 #include "private/qcore_unix_p.h" 63 #include "qplatformdefs.h" 68 #include <sys/types.h> 74 #ifdef QT_FONTS_ARE_RESOURCES 80 # define QT_NO_QWS_SHARE_FONTS 90 const quint8 DatabaseVersion = 4;
94 #ifndef QT_NO_QWS_QPF2 97 #ifndef QT_FONTS_ARE_RESOURCES 105 const int dataSize = st.
st_size;
109 const int dataSize = res.
size();
123 fontWeight = weight.
toInt();
128 for (
int i = 0; i < writingSystemBits.
count(); ++i) {
129 uchar currentByte = writingSystemBits.
at(i);
130 for (
int j = 0; j < 8; ++j) {
137 addFont(fontName,
"prerendered", fontWeight, italic,
139 true, writingSystems);
142 qDebug() <<
"header verification of QPF2 font" << file <<
"failed. maybe it is corrupt?";
144 #ifndef QT_FONTS_ARE_RESOURCES 145 munmap((
void *)data, st.
st_size);
148 #ifndef QT_FONTS_ARE_RESOURCES 152 #endif // QT_NO_QWS_QPF2 160 #ifndef QT_FONTS_ARE_RESOURCES 166 const bool weAreTheServer =
true;
173 if (weAreTheServer) {
177 if (dbTimeStamp < fontPathTimeStamp)
182 if (dbTimeStamp < fontDirTimeStamp)
190 qFatal(
"QFontDatabase::loadFromCache: Could not open font database cache!");
195 quint8 dataStreamVersion = 0;
196 stream >> version >> dataStreamVersion;
197 if (version != DatabaseVersion || dataStreamVersion != stream.
version()) {
200 qFatal(
"QFontDatabase::loadFromCache: Wrong version of the font database cache detected. Found %d/%d expected %d/%d",
201 version, dataStreamVersion, DatabaseVersion, stream.
version());
205 stream >> originalFontPath;
206 if (originalFontPath != fontPath) {
209 qFatal(
"QFontDatabase::loadFromCache: Font path doesn't match. Found %s in database, expected %s",
qPrintable(originalFontPath),
qPrintable(fontPath));
213 stream >> familyname;
215 while (!familyname.isEmpty() && !stream.
atEnd()) {
223 quint8 writingSystemCount;
227 stream >> foundryname >> weight >> italic >> pixelSize
228 >> file >> fileIndex >> antialiased >> writingSystemCount;
230 for (
quint8 i = 0; i < writingSystemCount; ++i) {
239 stream >> familyname;
246 #endif // QT_FONTS_ARE_RESOURCES 256 #ifdef QT_FONTS_ARE_RESOURCES 259 #ifndef QT_NO_SETTINGS 265 #endif //QT_FONTS_ARE_RESOURCES 271 #if defined(QFONTDATABASE_DEBUG) && defined(QT_FONTS_ARE_RESOURCES) 272 class FriendlyResource :
public QResource 286 if (!db || db->
count)
290 #ifndef QT_FONTS_ARE_RESOURCES 294 qFatal(
"QFontDatabase: Cannot find font directory %s - is Qt installed correctly?",
326 char isitalic[10]=
"";
329 fgets(buf,200,fontdef);
333 sscanf(buf,
"%s %s %s %s %d %d %s",name,file,render,isitalic,&weight,&size,flags);
338 bool italic = isitalic[0] ==
'y';
343 }
while (!feof(fontdef));
349 for (
int i=0; i<int(dir.
count()); i++) {
356 QString familyname = dir[i].left(u0);
357 int pixelSize = dir[i].mid(u0+1,u1-u0-1).toInt()/10;
359 int weight = dir[i].mid(u1+1,u2-u1-1-(italic?1:0)).toInt();
365 #ifndef QT_NO_FREETYPE 370 for (
int i = 0; i < int(dir.
count()); ++i) {
377 #ifndef QT_NO_QWS_QPF2 380 for (
int i = 0; i < int(dir.
count()); ++i) {
387 #else //QT_FONTS_ARE_RESOURCES 388 #ifdef QFONTDATABASE_DEBUG 391 FriendlyResource *fr =
static_cast<FriendlyResource*
>(&fontdir);
392 qDebug() <<
"fontdir" << fr->isValid() << fr->isDir() << fr->children();
396 #ifndef QT_NO_QWS_QPF2 398 for (
int i = 0; i < int(dir.
count()); ++i) {
404 #endif //QT_FONTS_ARE_RESOURCES 407 #ifdef QFONTDATABASE_DEBUG 409 for (
int f = 0; f < db->
count; f++) {
413 for (
int i = 0; i < QFont::LastPrivateScript; ++i) {
416 (family->scripts[i] & QtFontFamily::UnSupported) == QtFontFamily::UnSupported ?
417 "UnSupported" :
"Unknown"));
421 for (
int fd = 0; fd < family->
count; fd++) {
424 for (
int s = 0; s < foundry->
count; s++) {
426 FD_DEBUG(
"\t\t\tstyle: style=%d weight=%d\n" 431 FD_DEBUG(
"\t\t\t\tsmooth scalable");
433 FD_DEBUG(
"\t\t\t\tbitmap scalable");
436 for (
int z = 0; z < style->
count; ++z) {
445 #endif // QFONTDATABASE_DEBUG 447 #ifndef QT_NO_LIBRARY 450 for (
int i = 0; i < pluginFoundries.
count(); ++i) {
451 const QString foundry(pluginFoundries.
at(i));
455 qDebug() <<
"Could not load plugin for foundry" << foundry;
460 for (
int i = 0; i < fonts.
count(); ++i) {
463 int weight = info.
weight();
476 #ifndef QT_FONTS_ARE_RESOURCES 485 for (
int i = 0; i < db->
count; ++i) {
488 if (family->
count == 0)
493 if (coveredWritingSystems[
ws])
496 coveredWritingSystems[
ws] =
true;
504 #ifndef QT_FONTS_ARE_RESOURCES 508 #ifndef QT_FONTS_ARE_RESOURCES 512 binaryDb.
rename(dbFileName);
522 #ifndef QT_NO_SETTINGS 528 for (
int i = 0; i < db->
count; ++i) {
537 #endif // QT_NO_SETTINGS 544 #ifndef QT_NO_FREETYPE 546 #if (FREETYPE_MAJOR*10000+FREETYPE_MINOR*100+FREETYPE_PATCH) >= 20105 547 #define X_SIZE(face,i) ((face)->available_sizes[i].x_ppem) 548 #define Y_SIZE(face,i) ((face)->available_sizes[i].y_ppem) 550 #define X_SIZE(face,i) ((face)->available_sizes[i].width << 6) 551 #define Y_SIZE(face,i) ((face)->available_sizes[i].height << 6) 554 #endif // QT_NO_FREETYPE 564 #ifdef QT_NO_FREETYPE 576 #ifndef QT_NO_QWS_QPF2 578 #ifdef QT_FONTS_ARE_RESOURCES 596 qDebug() <<
"fontengine is not valid!";
607 #ifdef QT_NO_QWS_SHARE_FONTS 608 bool shareFonts =
false;
610 static bool dontShareFonts = !
qgetenv(
"QWS_NO_SHARE_FONTS").
isEmpty();
611 bool shareFonts = !dontShareFonts;
616 #ifndef QT_NO_LIBRARY 633 shareFonts = hint.
toBool();
635 shareFonts = (pixelSize < 64);
639 #endif // QT_NO_LIBRARY 645 #ifndef QT_NO_FREETYPE 649 if (fte->
init(faceId, antialias,
651 #ifdef QT_NO_QWS_QPF2 656 shareFonts = shareFonts
662 #endif // QT_NO_FREETYPE 665 #if !defined(QT_NO_QWS_QPF2) && !defined(QT_FONTS_ARE_RESOURCES) 675 return engine.
take();
679 #ifndef QT_NO_QWS_QPF 691 #endif // QT_NO_QWS_QPF 704 #ifndef QT_NO_QWS_QPF 709 QStringList fallbacks = privateDb()->fallbackFamilies;
719 return engine.
take();
725 #ifdef QT_NO_FREETYPE 773 const int force_encoding_id = -1;
775 if (!privateDb()->
count)
795 QString family_name, foundry_name;
804 FM_DEBUG(
"QFontDatabase::findFont\n" 806 " family: %s [%s], script: %d\n" 807 " weight: %d, style: %d\n" 823 match(script, request, family_name, foundry_name, force_encoding_id, &desc);
829 " weight: %d, style: %d\n" 847 initFontDef(desc, request, &fe->
fontDef);
850 #ifndef QT_NO_FREETYPE 854 if (!hbFace || !hbFace->supported_scripts[script]) {
855 FM_DEBUG(
" OpenType support missing for script\n");
888 if (fp && fp->
dpi > 0) {
941 for (; it !=
end; ++
it)
943 family_list += subs_list;
950 if (! family_list.
contains(defaultFamily))
951 family_list << defaultFamily;
964 for (; !engine && it !=
end; ++
it) {
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QVariant class acts like a union for the most common Qt data types.
bool isNull() const
Returns true if this object is holding a pointer that is null.
The QDir class provides access to directory structures and their contents.
T qobject_cast(QObject *object)
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,(QFontEngineFactoryInterface_iid, QLatin1String("/fontengines"), Qt::CaseInsensitive)) const quint8 DatabaseVersion
#define QFontEngineFactoryInterface_iid
static bool removeAllApplicationFonts()
Removes all application-local fonts previously added using addApplicationFont() and addApplicationFon...
QString fileName() const
Returns the name set by setFileName() or to the QFile constructors.
bool loadFromCache(const QString &fontPath)
bool rename(const QString &newName)
Renames the file currently specified by fileName() to newName.
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for setting key.
static mach_timebase_info_data_t info
#define QT_END_NAMESPACE
This macro expands to.
Q_CORE_EXPORT QTextStream & ws(QTextStream &s)
QFontEngine * takeRenderingEngine()
QString absoluteFilePath(const QString &fileName) const
Returns the absolute path name of a file in the directory.
static QWSServer * instance()
T * data() const
Returns the value of the pointer referenced by this object.
#define it(className, varName)
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
The QSettings class provides persistent platform-independent application settings.
bool atEnd() const
Returns true if the I/O device has reached the end position (end of the stream or file) or if there i...
The QByteArray class provides an array of bytes.
static QStringList fontPath()
T * take()
Returns the value of the pointer referenced by this object.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
void insertEngine(const Key &key, QFontEngine *engine)
static bool match(const uchar *found, const char *target, uint len)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
QString qws_fontCacheDir()
QStringList fallbackFamilies
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
int count(const T &t) const
Returns the number of occurrences of value in the list.
bool ref()
Atomically increments the value of this QAtomicInt.
The QString class provides a Unicode character string.
qint64 size() const
Returns the size of the data backing the resource.
uint count() const
Returns the total number of directories and files in the directory.
static void load(const QFontPrivate *d, int script)
Loads a QFontEngine for the specified script that matches the QFontDef request member variable...
static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
virtual Type type() const =0
virtual QAbstractFontEngine * create(const QFontEngineInfo &info)=0
static void parseFontName(const QString &name, QString &foundry, QString &family)
This makes sense of the font family name:
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
QStringList addTTFile(const QByteArray &file, const QByteArray &fontData=QByteArray())
void setNameFilters(const QStringList &nameFilters)
Sets the name filters used by entryList() and entryInfoList() to the list of filters specified by nam...
QString family() const
the family name of the font
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
static QFontCache * instance()
void setStyle(QFont::Style style)
static QFont font()
Returns the default application font.
static QFontEngine * loadSingleEngine(int script, const QFontPrivate *fp, const QFontDef &request, QtFontFamily *family, QtFontFoundry *foundry, QtFontStyle *style, QtFontSize *size)
virtual QVariant fontProperty(FontProperty property) const =0
Implemented in subclasses to return the value of the font attribute property.
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
bool init(FaceId faceId, bool antiaalias, GlyphFormat defaultFormat=Format_None, const QByteArray &fontData=QByteArray())
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
void refresh() const
Refreshes the directory information.
#define MAKE_TAG(ch1, ch2, ch3, ch4)
Q_CORE_EXPORT void qDebug(const char *,...)
void setWeight(int weight)
QStringList toStringList() const
Returns the variant as a QStringList if the variant has type() StringList, String ...
void append(const T &t)
Inserts value at the end of the list.
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool isValid() const
Returns true if the resource really exists in the resource hierarchy, false otherwise.
QStringList fallbackFamilies
The QResource class provides an interface for reading directly from resources.
static float pixelSize(const QFontDef &request, int dpi)
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
QList< QFontDatabase::WritingSystem > writingSystems() const
An empty list means that any writing system is supported.
The QFontEngineInfo class describes a specific font provided by a font engine plugin.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void insertEngineData(const Key &key, QFontEngineData *engineData)
const T & at(int i) const
Returns the item at index position i in the list.
The QStringList class provides a list of strings.
const uchar * data() const
Returns direct access to a read only segment of data that this resource represents.
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
void qt_qws_init_fontdb()
Q_CORE_EXPORT void qWarning(const char *,...)
QGlyphSet * defaultGlyphs()
static QFontEngine * loadEngine(int script, const QFontPrivate *fp, const QFontDef &request, QtFontFamily *family, QtFontFoundry *foundry, QtFontStyle *style, QtFontSize *size)
static const char * data(const QByteArray &arr)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static bool supportsThreadedFontRendering()
Returns true if font rendering is supported outside the GUI thread, false otherwise.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
void setPixelSize(qreal size)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
void clear()
Removes all items from the list.
bool isDir() const
Returns true if the resource represents a directory and thus may have children() in it...
void setFamily(const QString &name)
static void initializeDb()
QtFontFoundry ** foundries
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Style
This enum describes the different styles of glyphs that are used to display text. ...
static bool removeApplicationFont(int id)
Removes the previously loaded application font identified by id.
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
QtFontFamily * family(const QString &f, bool=false)
int version() const
Returns the version number of the data serialization format.
const char * constData() const
Returns a pointer to the data stored in the byte array.
void addFont(const QString &familyname, const char *foundryname, int weight, bool italic, int pixelSize, const QByteArray &file, int fileIndex, bool antialiased, const QList< QFontDatabase::WritingSystem > &writingSystems=QList< QFontDatabase::WritingSystem >())
QFont::Style style() const
the style of the font
Q_CORE_EXPORT void qFatal(const char *,...)
static QString qwsFontPath()
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
static QStringList substitutes(const QString &)
Returns a list of family names to be used whenever familyName is specified.
QString & append(QChar c)
The QDateTime class provides date and time functions.
The QFile class provides an interface for reading from and writing to files.
int count(char c) const
Returns the number of occurrences of character ch in the byte array.
static bool scriptRequiresOpenType(int script)
unsigned char writingSystems[QFontDatabase::WritingSystemsCount]
QString family() const
Returns the requested font family name, i.e.
Type type() const
Returns the storage type of the value stored in the variant.
static QString location(LibraryLocation)
Returns the location specified by loc.
#define st(var, type, card)
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
bool contains(const QString &key) const
Returns true if there exists a setting called key; returns false otherwise.
static bool verifyHeader(const uchar *data, int size)
void qt_applyFontDatabaseSettings(const QSettings &settings)
bool remove()
Removes the file specified by fileName().
QString defaultFamily() const
Returns the family name that corresponds to the current style hint.
qreal pixelSize() const
A pixel size of 0 represents a freely scalable font.
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user's loca...
int weight() const
The value should be from the QFont::Weight enumeration.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
QFontEngineData * findEngineData(const Key &key) const
The QDataStream class provides serialization of binary data to a QIODevice.
QStringList children() const
Returns a list of all resources in this directory, if the resource represents a file the list will be...
QVector< ApplicationFont > applicationFonts
char at(int i) const
Returns the character at index position i in the byte array.
The QFileInfo class provides system-independent file information.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
static const KeyPair *const end
QFontEngineData * engineData
#define qPrintable(string)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
void addQPF2File(const QByteArray &file)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
The QAbstractFontEngine class is the base class for font engine plugins in Qt for Embedded Linux...
Q_DECL_CONSTEXPR int qRound(qreal d)
int open(const char *, int,...)
static void load(const QString &=QString(), int=-1)
QBool contains(char c) const
Returns true if the byte array contains the character ch; otherwise returns false.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
bool isFile() const
Returns true if the resource represents a file and thus has data backing it, false if it represents a...
QByteArray getSfntTable(uint) const
static QVariant extractHeaderField(const uchar *data, HeaderTag tag)
static QFontEngine * findFont(int script, const QFontPrivate *fp, const QFontDef &request)
QDateTime lastModified() const
Returns the date and time when the file was last modified.