From 353c12f3e6c97d7059365dcf9b1f2dd9aa484545 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 28 Sep 2011 12:36:39 +0200 Subject: Register whether a glyph run goes from RTL or LTR This is needed by scene graph when embedding text objects in RTL text. Since the number of flags required for QGlyphRun is increasing, I've also refactored the underline/overline/strikethrough settings to use a common QFlags interface. Task-number: QTBUG-20917 Change-Id: I070649c014f4a51cfd66a9579d2d221a8f22302f Reviewed-on: http://codereview.qt-project.org/5739 Reviewed-by: Qt Sanity Bot Reviewed-by: Jiang Jiang --- src/gui/text/qglyphrun.cpp | 122 +++++++++++++++++++++++++++++++++---------- src/gui/text/qglyphrun.h | 15 ++++++ src/gui/text/qglyphrun_p.h | 12 ++--- src/gui/text/qtextlayout.cpp | 4 ++ 4 files changed, 116 insertions(+), 37 deletions(-) diff --git a/src/gui/text/qglyphrun.cpp b/src/gui/text/qglyphrun.cpp index 90efc4db21..a4e9048678 100644 --- a/src/gui/text/qglyphrun.cpp +++ b/src/gui/text/qglyphrun.cpp @@ -85,6 +85,22 @@ QT_BEGIN_NAMESPACE QRawFont is considered invalid and inaccessible in this case. */ +/*! + \enum QGlyphRun::GlyphRunFlag + \since 5.0 + + This enum describes flags that alter the way the run of glyphs might be presented or behave in + a visual layout. The layout which generates the glyph runs can set these flags based on relevant + internal data, to retain information needed to present the text as intended by the user of the + layout. + + \value Overline Indicates that the glyphs should be visualized together with an overline. + \value Underline Indicates that the glyphs should be visualized together with an underline. + \value StrikeOut Indicates that the glyphs should be struck out visually. + \value RightToLeft Indicates that the glyphs are ordered right to left. This can affect the + positioning of other screen elements that are relative to the glyph run, such as an inline + text object. +*/ /*! Constructs an empty QGlyphRun object. @@ -154,10 +170,7 @@ bool QGlyphRun::operator==(const QGlyphRun &other) const } } - return (d->overline == other.d->overline - && d->underline == other.d->underline - && d->strikeOut == other.d->strikeOut - && d->rawFont == other.d->rawFont); + return (d->flags == other.d->flags && d->rawFont == other.d->rawFont); } /*! @@ -251,9 +264,7 @@ void QGlyphRun::clear() { detach(); d->rawFont = QRawFont(); - d->strikeOut = false; - d->overline = false; - d->underline = false; + d->flags = 0; setPositions(QVector()); setGlyphIndexes(QVector()); @@ -282,76 +293,131 @@ void QGlyphRun::setRawData(const quint32 *glyphIndexArray, const QPointF *glyphP /*! Returns true if this QGlyphRun should be painted with an overline decoration. - \sa setOverline() + \sa setOverline(), flags() */ bool QGlyphRun::overline() const { - return d->overline; + return d->flags & Overline; } /*! Indicates that this QGlyphRun should be painted with an overline decoration if \a overline is true. Otherwise the QGlyphRun should be painted with no overline decoration. - \sa overline() + \sa overline(), setFlag(), setFlags() */ void QGlyphRun::setOverline(bool overline) { - if (d->overline == overline) - return; - - detach(); - d->overline = overline; + setFlag(Overline, overline); } /*! Returns true if this QGlyphRun should be painted with an underline decoration. - \sa setUnderline() + \sa setUnderline(), flags() */ bool QGlyphRun::underline() const { - return d->underline; + return d->flags & Underline; } /*! Indicates that this QGlyphRun should be painted with an underline decoration if \a underline is true. Otherwise the QGlyphRun should be painted with no underline decoration. - \sa underline() + \sa underline(), setFlag(), setFlags() */ void QGlyphRun::setUnderline(bool underline) { - if (d->underline == underline) - return; - - detach(); - d->underline = underline; + setFlag(Underline, underline); } /*! Returns true if this QGlyphRun should be painted with a strike out decoration. - \sa setStrikeOut() + \sa setStrikeOut(), flags() */ bool QGlyphRun::strikeOut() const { - return d->strikeOut; + return d->flags & StrikeOut; } /*! Indicates that this QGlyphRun should be painted with an strike out decoration if \a strikeOut is true. Otherwise the QGlyphRun should be painted with no strike out decoration. - \sa strikeOut() + \sa strikeOut(), setFlag(), setFlags() */ void QGlyphRun::setStrikeOut(bool strikeOut) { - if (d->strikeOut == strikeOut) + setFlag(StrikeOut, strikeOut); +} + +/*! + Returns true if this QGlyphRun contains glyphs that are painted from the right to the left. + + \since 5.0 + \sa setRightToLeft(), flags() +*/ +bool QGlyphRun::isRightToLeft() const +{ + return d->flags & RightToLeft; +} + +/*! + Indicates that this QGlyphRun contains glyphs that should be ordered from the right to left + if \a rightToLeft is true. Otherwise the order of the glyphs is assumed to be left to right. + + \since 5.0 + \sa isRightToLeft(), setFlag(), setFlags() +*/ +void QGlyphRun::setRightToLeft(bool rightToLeft) +{ + setFlag(RightToLeft, rightToLeft); +} + +/*! + Returns the flags set for this QGlyphRun. + + \since 5.0 + \sa setFlag(), setFlag() +*/ +QGlyphRun::GlyphRunFlags QGlyphRun::flags() const +{ + return d->flags; +} + +/*! + If \a enabled is true, then \a flag is enabled; otherwise, it is disabled. + + \since 5.0 + \sa flags(), setFlags() +*/ +void QGlyphRun::setFlag(GlyphRunFlag flag, bool enabled) +{ + if (d->flags.testFlag(flag) == enabled) + return; + + detach(); + if (enabled) + d->flags |= flag; + else + d->flags &= ~flag; +} + +/*! + Sets the flags of this QGlyphRun to \a flags. + + \since 5.0 + \sa setFlag(), flags() +*/ +void QGlyphRun::setFlags(GlyphRunFlags flags) +{ + if (d->flags == flags) return; detach(); - d->strikeOut = strikeOut; + d->flags = flags; } /*! diff --git a/src/gui/text/qglyphrun.h b/src/gui/text/qglyphrun.h index 81783a8653..5a55eacbcb 100644 --- a/src/gui/text/qglyphrun.h +++ b/src/gui/text/qglyphrun.h @@ -59,6 +59,14 @@ class QGlyphRunPrivate; class Q_GUI_EXPORT QGlyphRun { public: + enum GlyphRunFlag { + Overline = 0x1, + Underline = 0x2, + StrikeOut = 0x4, + RightToLeft = 0x8 + }; + Q_DECLARE_FLAGS(GlyphRunFlags, GlyphRunFlag) + QGlyphRun(); QGlyphRun(const QGlyphRun &other); ~QGlyphRun(); @@ -93,6 +101,13 @@ public: void setStrikeOut(bool strikeOut); bool strikeOut() const; + void setRightToLeft(bool on); + bool isRightToLeft() const; + + void setFlag(GlyphRunFlag flag, bool enabled = true); + void setFlags(GlyphRunFlags flags); + GlyphRunFlags flags() const; + void setBoundingRect(const QRectF &boundingRect); QRectF boundingRect() const; diff --git a/src/gui/text/qglyphrun_p.h b/src/gui/text/qglyphrun_p.h index 96a80bebe9..863b9d883e 100644 --- a/src/gui/text/qglyphrun_p.h +++ b/src/gui/text/qglyphrun_p.h @@ -68,9 +68,7 @@ class QGlyphRunPrivate: public QSharedData { public: QGlyphRunPrivate() - : overline(false) - , underline(false) - , strikeOut(false) + : flags(0) , glyphIndexData(glyphIndexes.constData()) , glyphIndexDataSize(0) , glyphPositionData(glyphPositions.constData()) @@ -84,9 +82,7 @@ public: , glyphPositions(other.glyphPositions) , rawFont(other.rawFont) , boundingRect(other.boundingRect) - , overline(other.overline) - , underline(other.underline) - , strikeOut(other.strikeOut) + , flags(other.flags) , glyphIndexData(other.glyphIndexData) , glyphIndexDataSize(other.glyphIndexDataSize) , glyphPositionData(other.glyphPositionData) @@ -99,9 +95,7 @@ public: QRawFont rawFont; QRectF boundingRect; - uint overline : 1; - uint underline : 1; - uint strikeOut : 1; + QGlyphRun::GlyphRunFlags flags; const quint32 *glyphIndexData; int glyphIndexDataSize; diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 00206ba624..e1bbca609e 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1022,6 +1022,8 @@ QList QTextLayout::glyphRuns(int from, int length) const flags |= QTextItem::Overline; if (glyphRun.strikeOut()) flags |= QTextItem::StrikeOut; + if (glyphRun.isRightToLeft()) + flags |= QTextItem::RightToLeft; QPair key(fontEngine, int(flags)); // merge the glyph runs using the same font if (glyphRunHash.contains(key)) { @@ -2181,6 +2183,8 @@ static QGlyphRun glyphRunWithInfo(QFontEngine *fontEngine, const QGlyphLayout &g glyphRun.setOverline(flags.testFlag(QTextItem::Overline)); glyphRun.setUnderline(flags.testFlag(QTextItem::Underline)); glyphRun.setStrikeOut(flags.testFlag(QTextItem::StrikeOut)); + if (flags.testFlag(QTextItem::RightToLeft)) + glyphRun.setRightToLeft(true); glyphRun.setRawFont(font); glyphRun.setBoundingRect(QRectF(selectionX.toReal(), minY, selectionWidth.toReal(), height)); -- cgit v1.2.3