43 #include <private/qstatictext_p.h> 44 #include <private/qfontengine_p.h> 45 #include <private/qtextengine_p.h> 46 #include <private/qpainter_p.h> 47 #include <private/qpaintengineex_p.h> 70 DrawTextItemRecorder(
bool untransformedCoordinates,
bool useBackendOptimizations)
71 : m_inertText(0), m_dirtyPen(
false), m_useBackendOptimizations(useBackendOptimizations),
72 m_untransformedCoordinates(untransformedCoordinates), m_currentColor(
Qt::black)
79 && newState.
pen().
color() != m_currentColor) {
81 m_currentColor = newState.
pen().
color();
87 int glyphOffset = m_inertText->glyphs.size();
88 int positionOffset = m_inertText->glyphs.size();
89 int charOffset = m_inertText->chars.size();
93 bool needFreshCurrentItem =
true;
94 if (!m_inertText->items.isEmpty()) {
95 QStaticTextItem &last = m_inertText->items[m_inertText->items.count() - 1];
98 (!m_dirtyPen || last.
color == state->pen().color())) {
99 needFreshCurrentItem =
false;
106 if (needFreshCurrentItem) {
118 currentItem.
color = m_currentColor;
120 m_inertText->items.append(currentItem);
132 int size = glyphs.
size();
136 m_inertText->glyphs.resize(m_inertText->glyphs.size() + size);
137 m_inertText->positions.resize(m_inertText->glyphs.size());
138 m_inertText->chars.resize(m_inertText->chars.size() + ti.
num_chars);
140 glyph_t *glyphsDestination = m_inertText->glyphs.data() + glyphOffset;
143 QFixedPoint *positionsDestination = m_inertText->positions.data() + positionOffset;
146 QChar *charsDestination = m_inertText->chars.data() + charOffset;
151 virtual void drawPolygon(
const QPointF *,
int , PolygonDrawMode )
157 virtual bool end() {
return true; }
173 bool m_useBackendOptimizations;
174 bool m_untransformedCoordinates;
181 DrawTextItemDevice(
bool untransformedCoordinates,
bool useBackendOptimizations)
183 m_paintEngine =
new DrawTextItemRecorder(untransformedCoordinates,
184 useBackendOptimizations);
187 ~DrawTextItemDevice()
189 delete m_paintEngine;
193 m_paintEngine->begin(t);
196 int metric(PaintDeviceMetric m)
const 207 case PdmPhysicalDpiX:
211 case PdmPhysicalDpiY:
222 qWarning(
"DrawTextItemDevice::metric: Invalid metric command");
229 return m_paintEngine;
233 DrawTextItemRecorder *m_paintEngine;
236 struct InertTextPainter {
238 : device(
true,
true), painter(&device)
243 DrawTextItemDevice device;
316 InertTextPainter *itp = inertTextPainter();
317 itp->device.begin(
d);
325 for (
int ii = 0; ii < itemCount; ++ii) {
346 bool paintEngineSupportsTransformations = priv->
extended &&
365 for (
int item = 0; item < itemCount; ++item) {
368 for (
int ii = 0; ii < textItem.
numGlyphs; ++ii) {
380 QColor defaultColor = currentColor;
381 for (
int ii = 0; ii < itemCount; ++ii) {
387 currentColor = item.
color;
388 }
else if (!item.
color.
isValid() && currentColor != defaultColor) {
391 currentColor = defaultColor;
392 painter->
setPen(currentColor);
400 if (currentColor != oldPen.
color())
The QPainter class performs low-level painting on widgets and other paint devices.
The QColor class provides colors based on RGB, HSV or CMYK values.
const T * constData() const
QPaintEngine::DirtyFlags state() const
Returns a combination of flags identifying the set of properties that need to be updated when updatin...
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
QPaintEngineEx * extended
QVector< glyph_t > glyphs
#define QT_END_NAMESPACE
This macro expands to.
QFontEngine * fontEngine() const
QFixedPoint * glyphPositions
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Q_GUI_EXPORT int qt_defaultDpiY()
~QDeclarativeTextLayout()
Q_GUI_EXPORT int qt_defaultDpiX()
The QPointF class defines a point in the plane using floating point precision.
QColor color() const
Returns the color of this pen's brush.
The QString class provides a Unicode character string.
static QFixed fromReal(qreal r)
The QPen class defines how a QPainter should draw lines and outlines of shapes.
QFont font() const
Returns the current font that is used for the layout, or a default font if none is set...
QVector< QFixedPoint > positions
The QChar class provides a 16-bit Unicode character.
void setFontEngine(QFontEngine *fe)
qreal x() const
Returns the x-coordinate of this point.
QString text() const
Returns the layout's text.
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QRectF class defines a rectangle in the plane using floating point precision. ...
char useBackendOptimizations
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
static const QCssKnownValue positions[NumKnownPositionModes - 1]
const QFont & font() const
Returns the currently set font used for drawing text.
virtual Type type() const =0
Reimplement this function to return the paint engine Type.
QDeclarativeTextLayoutPrivate()
void getGlyphPositions(const QGlyphLayout &glyphs, const QTransform &matrix, QTextItem::RenderFlags flags, QVarLengthArray< glyph_t > &glyphs_out, QVarLengthArray< QFixedPoint > &positions)
Q_CORE_EXPORT void qWarning(const char *,...)
void draw(QPainter *p, const QPointF &pos, const QVector< FormatRange > &selections=QVector< FormatRange >(), const QRectF &clip=QRectF()) const
Draws the whole layout on the painter p at the position specified by pos.
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
void * qMemCopy(void *dest, const void *src, size_t n)
The QTextLayout class is used to lay out and render text.
The QFont class specifies a font used for drawing text.
QVector< QStaticTextItem > items
static QPainterPrivate * get(QPainter *painter)
virtual void drawStaticTextItem(QStaticTextItem *)
Q_GUI_EXPORT void qt_draw_decoration_for_glyphs(QPainter *painter, const glyph_t *glyphArray, const QFixedPoint *positions, int glyphCount, QFontEngine *fontEngine, const QFont &font, const QTextCharFormat &charFormat)
void setPen(const QColor &color)
Sets the painter's pen to have style Qt::SolidLine, width 0 and the specified color.
qreal y() const
Returns the y-coordinate of this point.
The QPixmap class is an off-screen image representation that can be used as a paint device...
void clearLayout()
Clears the line information in the layout.
The QPaintEngineState class provides information about the active paint engine's current state...
T * data()
Returns a pointer to the data stored in the vector.
QPen pen() const
Returns the pen in the current paint engine state.
bool isValid() const
Returns true if the color is valid; otherwise returns false.
QDeclarativeTextLayoutPrivate * d
The QTextItem class provides all the information required to draw text in a custom paint engine...
Q_GLOBAL_STATIC(InertTextPainter, inertTextPainter)
void draw(QPainter *, const QPointF &=QPointF())
static const KeyPair *const end
QFont font() const
Returns the font that should be used to draw the text.
void beginLayout()
Begins the layout process.