summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qpainter.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-19 07:59:46 (GMT)
commit47819dc7257c60e0feb1d02177622593ec0c2d15 (patch)
treed97eff0acbe7f7361c8d7f805b4af7313dcfcc90 /src/gui/painting/qpainter.cpp
parent404568a382d09e603013734533239e18d2bf8957 (diff)
downloadQt-47819dc7257c60e0feb1d02177622593ec0c2d15.zip
Qt-47819dc7257c60e0feb1d02177622593ec0c2d15.tar.gz
Qt-47819dc7257c60e0feb1d02177622593ec0c2d15.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/painting/qpainter.cpp')
-rw-r--r--src/gui/painting/qpainter.cpp54
1 files changed, 19 insertions, 35 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index 50d65e6..bef6b7d 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -75,6 +75,7 @@
#include <private/qstatictext_p.h>
#include <private/qglyphs_p.h>
#include <private/qstylehelper_p.h>
+#include <private/qrawfont_p.h>
QT_BEGIN_NAMESPACE
@@ -5790,12 +5791,14 @@ void QPainter::drawImage(const QRectF &targetRect, const QImage &image, const QR
\sa QGlyphs::setFont(), QGlyphs::setPositions(), QGlyphs::setGlyphIndexes()
*/
+#if !defined(QT_NO_RAWFONT)
void QPainter::drawGlyphs(const QPointF &position, const QGlyphs &glyphs)
{
Q_D(QPainter);
- QFont oldFont = d->state->font;
- d->state->font = glyphs.font();
+ QRawFont font = glyphs.font();
+ if (!font.isValid())
+ return;
QVector<quint32> glyphIndexes = glyphs.glyphIndexes();
QVector<QPointF> glyphPositions = glyphs.positions();
@@ -5814,39 +5817,20 @@ void QPainter::drawGlyphs(const QPointF &position, const QGlyphs &glyphs)
fixedPointPositions[i] = QFixedPoint::fromPointF(processedPosition);
}
- d->drawGlyphs(glyphIndexes.data(), fixedPointPositions.data(), count);
-
- d->state->font = oldFont;
+ d->drawGlyphs(glyphIndexes.data(), fixedPointPositions.data(), count, font, glyphs.overline(),
+ glyphs.underline(), glyphs.strikeOut());
}
-void qt_draw_glyphs(QPainter *painter, const quint32 *glyphArray, const QPointF *positionArray,
- int glyphCount)
-{
- QVarLengthArray<QFixedPoint, 128> positions(glyphCount);
- for (int i=0; i<glyphCount; ++i)
- positions[i] = QFixedPoint::fromPointF(positionArray[i]);
-
- QPainterPrivate *painter_d = QPainterPrivate::get(painter);
- painter_d->drawGlyphs(const_cast<quint32 *>(glyphArray), positions.data(), glyphCount);
-}
-
-void QPainterPrivate::drawGlyphs(quint32 *glyphArray, QFixedPoint *positions, int glyphCount)
+void QPainterPrivate::drawGlyphs(quint32 *glyphArray, QFixedPoint *positions, int glyphCount,
+ const QRawFont &font, bool overline, bool underline,
+ bool strikeOut)
{
Q_Q(QPainter);
updateState(state);
- QFontEngine *fontEngine = state->font.d->engineForScript(QUnicodeTables::Common);
-
- while (fontEngine->type() == QFontEngine::Multi) {
- // Pick engine based on first glyph in array if we are using a multi engine.
- // (all glyphs must be for same font)
- int engineIdx = 0;
- if (glyphCount > 0)
- engineIdx = glyphArray[0] >> 24;
-
- fontEngine = static_cast<QFontEngineMulti *>(fontEngine)->engine(engineIdx);
- }
+ QRawFontPrivate *fontD = QRawFontPrivate::get(font);
+ QFontEngine *fontEngine = fontD->fontEngine;
QFixed leftMost;
QFixed rightMost;
@@ -5881,7 +5865,6 @@ void QPainterPrivate::drawGlyphs(quint32 *glyphArray, QFixedPoint *positions, in
extended->drawStaticTextItem(&staticTextItem);
} else {
QTextItemInt textItem;
- textItem.f = &state->font;
textItem.fontEngine = fontEngine;
QVarLengthArray<QFixed, 128> advances(glyphCount);
@@ -5903,20 +5886,21 @@ void QPainterPrivate::drawGlyphs(quint32 *glyphArray, QFixedPoint *positions, in
}
QTextItemInt::RenderFlags flags;
- if (state->font.underline())
+ if (underline)
flags |= QTextItemInt::Underline;
- if (state->font.overline())
+ if (overline)
flags |= QTextItemInt::Overline;
- if (state->font.strikeOut())
+ if (strikeOut)
flags |= QTextItemInt::StrikeOut;
drawTextItemDecoration(q, QPointF(leftMost.toReal(), baseLine.toReal()),
fontEngine,
- (state->font.underline()
- ? QTextCharFormat::SingleUnderline
- : QTextCharFormat::NoUnderline),
+ (underline
+ ? QTextCharFormat::SingleUnderline
+ : QTextCharFormat::NoUnderline),
flags, width.toReal(), QTextCharFormat());
}
+#endif // QT_NO_RAWFONT
/*!