summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextlayout.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2011-03-22 09:57:59 (GMT)
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2011-04-15 10:56:26 (GMT)
commit1348f4f0853155182d2ea5836902794d1e43980c (patch)
treef51a9882326ff3d89876902a65af0493436d3146 /src/gui/text/qtextlayout.cpp
parent3bff1637cd49617d334c1be63c20e008fac93be1 (diff)
downloadQt-1348f4f0853155182d2ea5836902794d1e43980c.zip
Qt-1348f4f0853155182d2ea5836902794d1e43980c.tar.gz
Qt-1348f4f0853155182d2ea5836902794d1e43980c.tar.bz2
Long live QRawFont!
The QGlyphs API was initially attempted with a bastardization of QFont which was meant to encapsulate a single, physical font instance (a QFontEngine) where a set of glyph indexes would make sense. This is not how QFont was intended to be used, and it caused several issues. At the same time, the requirement for loading a font from ttf/otf data and be able to access it and use it without polluting the rest of the process with the font arose. To support these two APIs we introduce QRawFont, which is an abstraction on top of a single physical font. Done-with: Jiang Jiang
Diffstat (limited to 'src/gui/text/qtextlayout.cpp')
-rw-r--r--src/gui/text/qtextlayout.cpp58
1 files changed, 47 insertions, 11 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index afe6949..93f71d3 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -54,12 +54,18 @@
#include "qpainterpath.h"
#include "qglyphs.h"
#include "qglyphs_p.h"
+#include "qrawfont.h"
+#include "qrawfont_p.h"
#include <limits.h>
#include <qdebug.h>
#include "qfontengine_p.h"
+#if !defined(QT_NO_FREETYPE)
+# include "qfontengine_ft_p.h"
+#endif
+
QT_BEGIN_NAMESPACE
#define ObjectSelectionBrush (QTextFormat::ForegroundBrush + 1)
@@ -1158,6 +1164,7 @@ static inline QRectF clipIfValid(const QRectF &rect, const QRectF &clip)
\sa draw(), QPainter::drawGlyphs()
*/
+#if !defined(QT_NO_RAWFONT)
QList<QGlyphs> QTextLayout::glyphs() const
{
QList<QGlyphs> glyphs;
@@ -1166,6 +1173,7 @@ QList<QGlyphs> QTextLayout::glyphs() const
return glyphs;
}
+#endif // QT_NO_RAWFONT
/*!
Draws the whole layout on the painter \a p at the position specified by \a pos.
@@ -2257,6 +2265,7 @@ namespace {
\sa QTextLayout::glyphs()
*/
+#if !defined(QT_NO_RAWFONT)
QList<QGlyphs> QTextLine::glyphs(int from, int length) const
{
const QScriptLine &line = eng->lines[i];
@@ -2331,7 +2340,35 @@ QList<QGlyphs> QTextLine::glyphs(int from, int length) const
QFontEngine *fontEngine = keys.at(i);
// Make a font for this particular engine
- QFont font = fontEngine->createExplicitFont();
+ QRawFont font;
+ QRawFontPrivate *fontD = QRawFontPrivate::get(font);
+ fontD->fontEngine = fontEngine;
+ fontD->fontEngine->ref.ref();
+
+#if defined(Q_WS_WIN)
+ if (fontEngine->supportsSubPixelPositions())
+ fontD->hintingPreference = QFont::PreferVerticalHinting;
+ else
+ fontD->hintingPreference = QFont::PreferFullHinting;
+#elif defined(Q_WS_MAC)
+ fontD->hintingPreference = QFont::PreferNoHinting;
+#elif !defined(QT_NO_FREETYPE)
+ if (fontEngine->type() == QFontEngine::Freetype) {
+ QFontEngineFT *freeTypeEngine = static_cast<QFontEngineFT *>(fontEngine);
+ switch (freeTypeEngine->defaultHintStyle()) {
+ case QFontEngineFT::HintNone:
+ fontD->hintingPreference = QFont::PreferNoHinting;
+ break;
+ case QFontEngineFT::HintLight:
+ fontD->hintingPreference = QFont::PreferVerticalHinting;
+ break;
+ case QFontEngineFT::HintMedium:
+ case QFontEngineFT::HintFull:
+ fontD->hintingPreference = QFont::PreferFullHinting;
+ break;
+ };
+ }
+#endif
QList<GlyphInfo> glyphLayouts = glyphLayoutHash.values(fontEngine);
for (int j=0; j<glyphLayouts.size(); ++j) {
@@ -2339,10 +2376,6 @@ QList<QGlyphs> QTextLine::glyphs(int from, int length) const
const QGlyphLayout &glyphLayout = glyphLayouts.at(j).glyphLayout;
const QTextItem::RenderFlags &flags = glyphLayouts.at(j).flags;
- font.setOverline(flags.testFlag(QTextItem::Overline));
- font.setUnderline(flags.testFlag(QTextItem::Underline));
- font.setStrikeOut(flags.testFlag(QTextItem::StrikeOut));
-
QVarLengthArray<glyph_t> glyphsArray;
QVarLengthArray<QFixedPoint> positionsArray;
@@ -2361,19 +2394,22 @@ QList<QGlyphs> QTextLine::glyphs(int from, int length) const
glyphIndexes.setGlyphIndexes(glyphs);
glyphIndexes.setPositions(positions);
- QPair<QFontEngine *, int> key(fontEngine, int(flags));
+ glyphIndexes.setOverline(flags.testFlag(QTextItem::Overline));
+ glyphIndexes.setUnderline(flags.testFlag(QTextItem::Underline));
+ glyphIndexes.setStrikeOut(flags.testFlag(QTextItem::StrikeOut));
+ glyphIndexes.setFont(font);
+ QPair<QFontEngine *, int> key(fontEngine, int(flags));
if (!glyphsHash.contains(key))
- glyphsHash.insert(key, QGlyphs());
-
- QGlyphs &target = glyphsHash[key];
- target += glyphIndexes;
- target.setFont(font);
+ glyphsHash.insert(key, glyphIndexes);
+ else
+ glyphsHash[key] += glyphIndexes;
}
}
return glyphsHash.values();
}
+#endif // QT_NO_RAWFONT
/*!
\fn void QTextLine::draw(QPainter *painter, const QPointF &position, const QTextLayout::FormatRange *selection) const