micro optimizations
use an inlined version of isValid() everywhere; don't detach where is non required; get rid of extra checks where possible Change-Id: I6815c1f7d7c03677d9c57dda2731ed2868ea92aa Merge-request: 1343 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> Reviewed-on: http://codereview.qt.nokia.com/4144
This commit is contained in:
parent
f63993272f
commit
10354d71ae
@ -46,7 +46,6 @@
|
|||||||
#include "qrawfont.h"
|
#include "qrawfont.h"
|
||||||
#include "qrawfont_p.h"
|
#include "qrawfont_p.h"
|
||||||
|
|
||||||
#include <QtCore/qthread.h>
|
|
||||||
#include <QtCore/qendian.h>
|
#include <QtCore/qendian.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -190,8 +189,7 @@ QRawFont &QRawFont::operator=(const QRawFont &other)
|
|||||||
*/
|
*/
|
||||||
bool QRawFont::isValid() const
|
bool QRawFont::isValid() const
|
||||||
{
|
{
|
||||||
Q_ASSERT(d->thread == 0 || d->thread == QThread::currentThread());
|
return d->isValid();
|
||||||
return d->fontEngine != 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -225,7 +223,7 @@ void QRawFont::loadFromData(const QByteArray &fontData,
|
|||||||
qreal pixelSize,
|
qreal pixelSize,
|
||||||
QFont::HintingPreference hintingPreference)
|
QFont::HintingPreference hintingPreference)
|
||||||
{
|
{
|
||||||
detach();
|
d.detach();
|
||||||
d->cleanUp();
|
d->cleanUp();
|
||||||
d->hintingPreference = hintingPreference;
|
d->hintingPreference = hintingPreference;
|
||||||
d->thread = QThread::currentThread();
|
d->thread = QThread::currentThread();
|
||||||
@ -247,13 +245,13 @@ void QRawFont::loadFromData(const QByteArray &fontData,
|
|||||||
QImage QRawFont::alphaMapForGlyph(quint32 glyphIndex, AntialiasingType antialiasingType,
|
QImage QRawFont::alphaMapForGlyph(quint32 glyphIndex, AntialiasingType antialiasingType,
|
||||||
const QTransform &transform) const
|
const QTransform &transform) const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
if (!d->isValid())
|
||||||
return QImage();
|
return QImage();
|
||||||
|
|
||||||
if (antialiasingType == SubPixelAntialiasing)
|
if (antialiasingType == SubPixelAntialiasing)
|
||||||
return d->fontEngine->alphaRGBMapForGlyph(glyphIndex, QFixed(), 0, transform);
|
return d->fontEngine->alphaRGBMapForGlyph(glyphIndex, QFixed(), 0, transform);
|
||||||
else
|
|
||||||
return d->fontEngine->alphaMapForGlyph(glyphIndex, QFixed(), transform);
|
return d->fontEngine->alphaMapForGlyph(glyphIndex, QFixed(), transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -266,7 +264,7 @@ QImage QRawFont::alphaMapForGlyph(quint32 glyphIndex, AntialiasingType antialias
|
|||||||
*/
|
*/
|
||||||
QPainterPath QRawFont::pathForGlyph(quint32 glyphIndex) const
|
QPainterPath QRawFont::pathForGlyph(quint32 glyphIndex) const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
if (!d->isValid())
|
||||||
return QPainterPath();
|
return QPainterPath();
|
||||||
|
|
||||||
QFixedPoint position;
|
QFixedPoint position;
|
||||||
@ -296,10 +294,7 @@ bool QRawFont::operator==(const QRawFont &other) const
|
|||||||
*/
|
*/
|
||||||
qreal QRawFont::ascent() const
|
qreal QRawFont::ascent() const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
return d->isValid() ? d->fontEngine->ascent().toReal() : 0.0;
|
||||||
return 0.0;
|
|
||||||
|
|
||||||
return d->fontEngine->ascent().toReal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -309,10 +304,7 @@ qreal QRawFont::ascent() const
|
|||||||
*/
|
*/
|
||||||
qreal QRawFont::descent() const
|
qreal QRawFont::descent() const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
return d->isValid() ? d->fontEngine->descent().toReal() : 0.0;
|
||||||
return 0.0;
|
|
||||||
|
|
||||||
return d->fontEngine->descent().toReal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -322,10 +314,7 @@ qreal QRawFont::descent() const
|
|||||||
*/
|
*/
|
||||||
qreal QRawFont::xHeight() const
|
qreal QRawFont::xHeight() const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
return d->isValid() ? d->fontEngine->xHeight().toReal() : 0.0;
|
||||||
return 0.0;
|
|
||||||
|
|
||||||
return d->fontEngine->xHeight().toReal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -335,10 +324,7 @@ qreal QRawFont::xHeight() const
|
|||||||
*/
|
*/
|
||||||
qreal QRawFont::leading() const
|
qreal QRawFont::leading() const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
return d->isValid() ? d->fontEngine->leading().toReal() : 0.0;
|
||||||
return 0.0;
|
|
||||||
|
|
||||||
return d->fontEngine->leading().toReal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -348,10 +334,7 @@ qreal QRawFont::leading() const
|
|||||||
*/
|
*/
|
||||||
qreal QRawFont::averageCharWidth() const
|
qreal QRawFont::averageCharWidth() const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
return d->isValid() ? d->fontEngine->averageCharWidth().toReal() : 0.0;
|
||||||
return 0.0;
|
|
||||||
|
|
||||||
return d->fontEngine->averageCharWidth().toReal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -361,10 +344,7 @@ qreal QRawFont::averageCharWidth() const
|
|||||||
*/
|
*/
|
||||||
qreal QRawFont::maxCharWidth() const
|
qreal QRawFont::maxCharWidth() const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
return d->isValid() ? d->fontEngine->maxCharWidth() : 0.0;
|
||||||
return 0.0;
|
|
||||||
|
|
||||||
return d->fontEngine->maxCharWidth();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -376,10 +356,7 @@ qreal QRawFont::maxCharWidth() const
|
|||||||
*/
|
*/
|
||||||
qreal QRawFont::pixelSize() const
|
qreal QRawFont::pixelSize() const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
return d->isValid() ? d->fontEngine->fontDef.pixelSize : 0.0;
|
||||||
return 0.0;
|
|
||||||
|
|
||||||
return d->fontEngine->fontDef.pixelSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -392,10 +369,7 @@ qreal QRawFont::pixelSize() const
|
|||||||
*/
|
*/
|
||||||
qreal QRawFont::unitsPerEm() const
|
qreal QRawFont::unitsPerEm() const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
return d->isValid() ? d->fontEngine->emSquareSize().toReal() : 0.0;
|
||||||
return 0.0;
|
|
||||||
|
|
||||||
return d->fontEngine->emSquareSize().toReal();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -427,10 +401,7 @@ qreal QRawFont::underlinePosition() const
|
|||||||
*/
|
*/
|
||||||
QString QRawFont::familyName() const
|
QString QRawFont::familyName() const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
return d->isValid() ? d->fontEngine->fontDef.family : QString();
|
||||||
return QString();
|
|
||||||
|
|
||||||
return d->fontEngine->fontDef.family;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -440,10 +411,7 @@ QString QRawFont::familyName() const
|
|||||||
*/
|
*/
|
||||||
QString QRawFont::styleName() const
|
QString QRawFont::styleName() const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
return d->isValid() ? d->fontEngine->fontDef.styleName : QString();
|
||||||
return QString();
|
|
||||||
|
|
||||||
return d->fontEngine->fontDef.styleName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -453,10 +421,7 @@ QString QRawFont::styleName() const
|
|||||||
*/
|
*/
|
||||||
QFont::Style QRawFont::style() const
|
QFont::Style QRawFont::style() const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
return d->isValid() ? QFont::Style(d->fontEngine->fontDef.style) : QFont::StyleNormal;
|
||||||
return QFont::StyleNormal;
|
|
||||||
|
|
||||||
return QFont::Style(d->fontEngine->fontDef.style);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -466,10 +431,7 @@ QFont::Style QRawFont::style() const
|
|||||||
*/
|
*/
|
||||||
int QRawFont::weight() const
|
int QRawFont::weight() const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
return d->isValid() ? int(d->fontEngine->fontDef.weight) : -1;
|
||||||
return -1;
|
|
||||||
|
|
||||||
return int(d->fontEngine->fontDef.weight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -487,7 +449,7 @@ int QRawFont::weight() const
|
|||||||
*/
|
*/
|
||||||
QVector<quint32> QRawFont::glyphIndexesForString(const QString &text) const
|
QVector<quint32> QRawFont::glyphIndexesForString(const QString &text) const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
if (!d->isValid())
|
||||||
return QVector<quint32>();
|
return QVector<quint32>();
|
||||||
|
|
||||||
int nglyphs = text.size();
|
int nglyphs = text.size();
|
||||||
@ -519,7 +481,7 @@ QVector<quint32> QRawFont::glyphIndexesForString(const QString &text) const
|
|||||||
*/
|
*/
|
||||||
bool QRawFont::glyphIndexesForChars(const QChar *chars, int numChars, quint32 *glyphIndexes, int *numGlyphs) const
|
bool QRawFont::glyphIndexesForChars(const QChar *chars, int numChars, quint32 *glyphIndexes, int *numGlyphs) const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
if (!d->isValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QGlyphLayout glyphs;
|
QGlyphLayout glyphs;
|
||||||
@ -536,7 +498,7 @@ bool QRawFont::glyphIndexesForChars(const QChar *chars, int numChars, quint32 *g
|
|||||||
*/
|
*/
|
||||||
QVector<QPointF> QRawFont::advancesForGlyphIndexes(const QVector<quint32> &glyphIndexes) const
|
QVector<QPointF> QRawFont::advancesForGlyphIndexes(const QVector<quint32> &glyphIndexes) const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
if (!d->isValid())
|
||||||
return QVector<QPointF>();
|
return QVector<QPointF>();
|
||||||
|
|
||||||
int numGlyphs = glyphIndexes.size();
|
int numGlyphs = glyphIndexes.size();
|
||||||
@ -563,7 +525,7 @@ QVector<QPointF> QRawFont::advancesForGlyphIndexes(const QVector<quint32> &glyph
|
|||||||
*/
|
*/
|
||||||
bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs) const
|
bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *advances, int numGlyphs) const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
if (!d->isValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QGlyphLayout glyphs;
|
QGlyphLayout glyphs;
|
||||||
@ -589,10 +551,7 @@ bool QRawFont::advancesForGlyphIndexes(const quint32 *glyphIndexes, QPointF *adv
|
|||||||
*/
|
*/
|
||||||
QFont::HintingPreference QRawFont::hintingPreference() const
|
QFont::HintingPreference QRawFont::hintingPreference() const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
return d->isValid() ? d->hintingPreference : QFont::PreferDefaultHinting;
|
||||||
return QFont::PreferDefaultHinting;
|
|
||||||
|
|
||||||
return d->hintingPreference;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -603,7 +562,7 @@ QFont::HintingPreference QRawFont::hintingPreference() const
|
|||||||
*/
|
*/
|
||||||
QByteArray QRawFont::fontTable(const char *tagName) const
|
QByteArray QRawFont::fontTable(const char *tagName) const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
if (!d->isValid())
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
|
|
||||||
const quint32 *tagId = reinterpret_cast<const quint32 *>(tagName);
|
const quint32 *tagId = reinterpret_cast<const quint32 *>(tagName);
|
||||||
@ -626,9 +585,9 @@ extern QList<QFontDatabase::WritingSystem> qt_determine_writing_systems_from_tru
|
|||||||
*/
|
*/
|
||||||
QList<QFontDatabase::WritingSystem> QRawFont::supportedWritingSystems() const
|
QList<QFontDatabase::WritingSystem> QRawFont::supportedWritingSystems() const
|
||||||
{
|
{
|
||||||
if (isValid()) {
|
if (d->isValid()) {
|
||||||
QByteArray os2Table = fontTable("OS/2");
|
QByteArray os2Table = fontTable("OS/2");
|
||||||
if (!os2Table.isEmpty() && os2Table.size() > 86) {
|
if (os2Table.size() > 86) {
|
||||||
char *data = os2Table.data();
|
char *data = os2Table.data();
|
||||||
quint32 *bigEndianUnicodeRanges = reinterpret_cast<quint32 *>(data + 42);
|
quint32 *bigEndianUnicodeRanges = reinterpret_cast<quint32 *>(data + 42);
|
||||||
quint32 *bigEndianCodepageRanges = reinterpret_cast<quint32 *>(data + 78);
|
quint32 *bigEndianCodepageRanges = reinterpret_cast<quint32 *>(data + 78);
|
||||||
@ -656,10 +615,7 @@ QList<QFontDatabase::WritingSystem> QRawFont::supportedWritingSystems() const
|
|||||||
*/
|
*/
|
||||||
bool QRawFont::supportsCharacter(const QChar &character) const
|
bool QRawFont::supportsCharacter(const QChar &character) const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
return d->isValid() && d->fontEngine->canRender(&character, 1);
|
||||||
return false;
|
|
||||||
|
|
||||||
return d->fontEngine->canRender(&character, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -669,7 +625,7 @@ bool QRawFont::supportsCharacter(const QChar &character) const
|
|||||||
*/
|
*/
|
||||||
bool QRawFont::supportsCharacter(quint32 ucs4) const
|
bool QRawFont::supportsCharacter(quint32 ucs4) const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
if (!d->isValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QString str = QString::fromUcs4(&ucs4, 1);
|
QString str = QString::fromUcs4(&ucs4, 1);
|
||||||
@ -688,6 +644,7 @@ extern int qt_script_for_writing_system(QFontDatabase::WritingSystem writingSyst
|
|||||||
*/
|
*/
|
||||||
QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writingSystem)
|
QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writingSystem)
|
||||||
{
|
{
|
||||||
|
QRawFont rawFont;
|
||||||
#if defined(Q_WS_MAC)
|
#if defined(Q_WS_MAC)
|
||||||
QTextLayout layout(QFontDatabase::writingSystemSample(writingSystem), font);
|
QTextLayout layout(QFontDatabase::writingSystemSample(writingSystem), font);
|
||||||
layout.beginLayout();
|
layout.beginLayout();
|
||||||
@ -698,14 +655,12 @@ QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writ
|
|||||||
// Pick the one matches the family name we originally requested,
|
// Pick the one matches the family name we originally requested,
|
||||||
// if none of them match, just pick the first one
|
// if none of them match, just pick the first one
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
QGlyphRun glyphs = list.at(i);
|
rawfont = list.at(i).rawFont();
|
||||||
QRawFont rawfont = glyphs.rawFont();
|
|
||||||
if (rawfont.familyName() == font.family())
|
if (rawfont.familyName() == font.family())
|
||||||
return rawfont;
|
return rawfont;
|
||||||
}
|
}
|
||||||
return list.at(0).rawFont();
|
return list.at(0).rawFont();
|
||||||
}
|
}
|
||||||
return QRawFont();
|
|
||||||
#else
|
#else
|
||||||
QFontPrivate *font_d = QFontPrivate::get(font);
|
QFontPrivate *font_d = QFontPrivate::get(font);
|
||||||
int script = qt_script_for_writing_system(writingSystem);
|
int script = qt_script_for_writing_system(writingSystem);
|
||||||
@ -721,15 +676,12 @@ QRawFont QRawFont::fromFont(const QFont &font, QFontDatabase::WritingSystem writ
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fe != 0) {
|
if (fe != 0) {
|
||||||
QRawFont rawFont;
|
|
||||||
rawFont.d.data()->fontEngine = fe;
|
rawFont.d.data()->fontEngine = fe;
|
||||||
rawFont.d.data()->fontEngine->ref.ref();
|
rawFont.d.data()->fontEngine->ref.ref();
|
||||||
rawFont.d.data()->hintingPreference = font.hintingPreference();
|
rawFont.d.data()->hintingPreference = font.hintingPreference();
|
||||||
return rawFont;
|
|
||||||
} else {
|
|
||||||
return QRawFont();
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
return rawFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -740,7 +692,7 @@ void QRawFont::setPixelSize(qreal pixelSize)
|
|||||||
if (d->fontEngine == 0)
|
if (d->fontEngine == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
detach();
|
d.detach();
|
||||||
QFontEngine *oldFontEngine = d->fontEngine;
|
QFontEngine *oldFontEngine = d->fontEngine;
|
||||||
|
|
||||||
d->fontEngine = d->fontEngine->cloneWithSize(pixelSize);
|
d->fontEngine = d->fontEngine->cloneWithSize(pixelSize);
|
||||||
@ -752,15 +704,6 @@ void QRawFont::setPixelSize(qreal pixelSize)
|
|||||||
delete oldFontEngine;
|
delete oldFontEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
\internal
|
|
||||||
*/
|
|
||||||
void QRawFont::detach()
|
|
||||||
{
|
|
||||||
if (d->ref != 1)
|
|
||||||
d.detach();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\internal
|
\internal
|
||||||
*/
|
*/
|
||||||
|
@ -140,8 +140,6 @@ private:
|
|||||||
friend class QRawFontPrivate;
|
friend class QRawFontPrivate;
|
||||||
friend class QTextLayout;
|
friend class QTextLayout;
|
||||||
|
|
||||||
void detach();
|
|
||||||
|
|
||||||
QExplicitlySharedDataPointer<QRawFontPrivate> d;
|
QExplicitlySharedDataPointer<QRawFontPrivate> d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -54,7 +54,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "qrawfont.h"
|
#include "qrawfont.h"
|
||||||
|
|
||||||
#include "qfontengine_p.h"
|
#include "qfontengine_p.h"
|
||||||
|
#include <QtCore/qthread.h>
|
||||||
#include <QtCore/qthreadstorage.h>
|
#include <QtCore/qthreadstorage.h>
|
||||||
|
|
||||||
#if !defined(QT_NO_RAWFONT)
|
#if !defined(QT_NO_RAWFONT)
|
||||||
@ -96,6 +98,12 @@ public:
|
|||||||
cleanUp();
|
cleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool isValid() const
|
||||||
|
{
|
||||||
|
Q_ASSERT(thread == 0 || thread == QThread::currentThread());
|
||||||
|
return fontEngine != 0;
|
||||||
|
}
|
||||||
|
|
||||||
void cleanUp();
|
void cleanUp();
|
||||||
void platformCleanUp();
|
void platformCleanUp();
|
||||||
void platformLoadFromData(const QByteArray &fontData,
|
void platformLoadFromData(const QByteArray &fontData,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user