summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/painting/qpainter.cpp34
-rw-r--r--src/gui/text/qtextengine.cpp16
-rw-r--r--src/gui/text/qtextengine_p.h1
-rw-r--r--src/gui/text/qtextlayout.cpp19
4 files changed, 37 insertions, 33 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index 76ac7db..3735e7c 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -95,10 +95,10 @@ static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const
const QTextItem::RenderFlags flags, qreal width,
const QTextCharFormat &charFormat);
// Helper function to calculate left most position, width and flags for decoration drawing
-static void drawDecorationForGlyphs(QPainter *painter, const glyph_t *glyphArray,
- const QFixedPoint *positions, int glyphCount,
- QFontEngine *fontEngine, const QFont &font,
- const QTextCharFormat &charFormat);
+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);
static inline QGradient::CoordinateMode coordinateMode(const QBrush &brush)
{
@@ -5937,9 +5937,9 @@ void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText
}
d->extended->drawStaticTextItem(item);
- drawDecorationForGlyphs(this, item->glyphs, item->glyphPositions,
- item->numGlyphs, item->fontEngine(), staticText_d->font,
- QTextCharFormat());
+ qt_draw_decoration_for_glyphs(this, item->glyphs, item->glyphPositions,
+ item->numGlyphs, item->fontEngine(), staticText_d->font,
+ QTextCharFormat());
}
if (currentColor != oldPen.color())
setPen(oldPen);
@@ -6383,10 +6383,10 @@ static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const
painter->setBrush(oldBrush);
}
-static void drawDecorationForGlyphs(QPainter *painter, const glyph_t *glyphArray,
- const QFixedPoint *positions, int glyphCount,
- QFontEngine *fontEngine, const QFont &font,
- const QTextCharFormat &charFormat)
+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)
{
if (!(font.underline() || font.strikeOut() || font.overline()))
return;
@@ -8097,12 +8097,16 @@ start_lengthVariant:
QTextLine line = textLayout.lineAt(i);
qreal advance = line.horizontalAdvance();
- if (tf & Qt::AlignRight)
- xoff = r.width() - advance;
+ xoff = 0;
+ if (tf & Qt::AlignRight) {
+ QTextEngine *eng = textLayout.engine();
+ xoff = r.width() - advance -
+ eng->leadingSpaceWidth(eng->lines[line.lineNumber()]).toReal();
+ }
else if (tf & Qt::AlignHCenter)
- xoff = (r.width() - advance)/2;
+ xoff = (r.width() - advance) / 2;
- line.draw(painter, QPointF(r.x() + xoff + line.x(), r.y() + yoff));
+ line.draw(painter, QPointF(r.x() + xoff, r.y() + yoff));
}
if (restore) {
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 4378c62..4f86cff 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -2681,6 +2681,22 @@ void QTextEngine::resolveAdditionalFormats() const
specialData->resolvedFormatIndices = indices;
}
+QFixed QTextEngine::leadingSpaceWidth(const QScriptLine &line)
+{
+ if (!line.hasTrailingSpaces
+ || (option.flags() & QTextOption::IncludeTrailingSpaces)
+ || !isRightToLeft())
+ return QFixed();
+
+ int pos = line.length;
+ const HB_CharAttributes *attributes = this->attributes();
+ if (!attributes)
+ return QFixed();
+ while (pos > 0 && attributes[line.from + pos - 1].whiteSpace)
+ --pos;
+ return width(line.from + pos, line.length - pos);
+}
+
QStackTextEngine::QStackTextEngine(const QString &string, const QFont &f)
: QTextEngine(string, f),
_layoutData(string, _memory, MemSize)
diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h
index 34723ab..67d7453 100644
--- a/src/gui/text/qtextengine_p.h
+++ b/src/gui/text/qtextengine_p.h
@@ -592,6 +592,7 @@ public:
QString elidedText(Qt::TextElideMode mode, const QFixed &width, int flags = 0) const;
void shapeLine(const QScriptLine &line);
+ QFixed leadingSpaceWidth(const QScriptLine &line);
private:
void setBoundary(int strPos) const;
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index 905f81b..692620f 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -64,23 +64,6 @@ QT_BEGIN_NAMESPACE
#define SuppressText 0x5012
#define SuppressBackground 0x513
-static inline QFixed leadingSpaceWidth(QTextEngine *eng, const QScriptLine &line)
-{
- if (!line.hasTrailingSpaces
- || (eng->option.flags() & QTextOption::IncludeTrailingSpaces)
- || !(eng->option.alignment() & Qt::AlignRight)
- || !eng->isRightToLeft())
- return QFixed();
-
- int pos = line.length;
- const HB_CharAttributes *attributes = eng->attributes();
- if (!attributes)
- return QFixed();
- while (pos > 0 && attributes[line.from + pos - 1].whiteSpace)
- --pos;
- return eng->width(line.from + pos, line.length - pos);
-}
-
static QFixed alignLine(QTextEngine *eng, const QScriptLine &line)
{
QFixed x = 0;
@@ -91,7 +74,7 @@ static QFixed alignLine(QTextEngine *eng, const QScriptLine &line)
if (align & Qt::AlignJustify && eng->isRightToLeft())
align = Qt::AlignRight;
if (align & Qt::AlignRight)
- x = line.width - (line.textAdvance + leadingSpaceWidth(eng, line));
+ x = line.width - (line.textAdvance + eng->leadingSpaceWidth(line));
else if (align & Qt::AlignHCenter)
x = (line.width - line.textAdvance)/2;
}