Add debug operators for font database structs for easier debugging

Change-Id: Ice1b27ff93de2d369dc6b66c72a64eb05da5639c
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
bb10
Tor Arne Vestbø 2017-03-03 14:20:42 +01:00
parent 18934bcb0c
commit 46976eea18
3 changed files with 46 additions and 0 deletions

View File

@ -45,6 +45,7 @@
#include <qpa/qplatformscreen.h>
#include <QtCore/QLibraryInfo>
#include <QtCore/QDir>
#include <QtCore/QMetaEnum>
#include <algorithm>
#include <iterator>
@ -201,6 +202,26 @@ QSupportedWritingSystems &QSupportedWritingSystems::operator=(const QSupportedWr
return *this;
}
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, const QSupportedWritingSystems &sws)
{
QMetaObject mo = QFontDatabase::staticMetaObject;
QMetaEnum me = mo.enumerator(mo.indexOfEnumerator("WritingSystem"));
QDebugStateSaver saver(debug);
debug.nospace() << "QSupportedWritingSystems(";
int i = sws.d->vector.indexOf(true);
while (i > 0) {
debug << me.valueToKey(i);
i = sws.d->vector.indexOf(true, i + 1);
if (i > 0)
debug << ", ";
}
debug << ")";
return debug;
}
#endif
/*!
Destroys the supported writing systems object.
*/

View File

@ -84,11 +84,18 @@ private:
friend Q_GUI_EXPORT bool operator==(const QSupportedWritingSystems &, const QSupportedWritingSystems &);
friend Q_GUI_EXPORT bool operator!=(const QSupportedWritingSystems &, const QSupportedWritingSystems &);
#ifndef QT_NO_DEBUG_STREAM
friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QSupportedWritingSystems &);
#endif
};
Q_GUI_EXPORT bool operator==(const QSupportedWritingSystems &, const QSupportedWritingSystems &);
Q_GUI_EXPORT bool operator!=(const QSupportedWritingSystems &, const QSupportedWritingSystems &);
#ifndef QT_NO_DEBUG_STREAM
Q_GUI_EXPORT QDebug operator<<(QDebug, const QSupportedWritingSystems &);
#endif
class QFontRequestPrivate;
class QFontEngineMulti;

View File

@ -251,6 +251,24 @@ struct FontDescription {
QSupportedWritingSystems writingSystems;
};
#ifndef QT_NO_DEBUG_STREAM
Q_DECL_UNUSED static inline QDebug operator<<(QDebug debug, const FontDescription &fd)
{
QDebugStateSaver saver(debug);
return debug.nospace() << "FontDescription("
<< "familyName=" << QString(fd.familyName)
<< ", styleName=" << QString(fd.styleName)
<< ", foundry=" << fd.foundryName
<< ", weight=" << fd.weight
<< ", style=" << fd.style
<< ", stretch=" << fd.stretch
<< ", pixelSize=" << fd.pixelSize
<< ", fixedPitch=" << fd.fixedPitch
<< ", writingSystems=" << fd.writingSystems
<< ")";
}
#endif
static void getFontDescription(CTFontDescriptorRef font, FontDescription *fd)
{
QCFType<CFDictionaryRef> styles = (CFDictionaryRef) CTFontDescriptorCopyAttribute(font, kCTFontTraitsAttribute);