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 <qt_sanity_bot@ovi.com>
Reviewed-by: Jiang Jiang <jiang.jiang@nokia.com>
bb10
Eskil Abrahamsen Blomfeldt 2011-09-28 12:36:39 +02:00 committed by Qt by Nokia
parent e316deffef
commit 353c12f3e6
4 changed files with 116 additions and 37 deletions

View File

@ -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<QPointF>());
setGlyphIndexes(QVector<quint32>());
@ -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();
d->strikeOut = strikeOut;
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->flags = flags;
}
/*!

View File

@ -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;

View File

@ -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;

View File

@ -1022,6 +1022,8 @@ QList<QGlyphRun> QTextLayout::glyphRuns(int from, int length) const
flags |= QTextItem::Overline;
if (glyphRun.strikeOut())
flags |= QTextItem::StrikeOut;
if (glyphRun.isRightToLeft())
flags |= QTextItem::RightToLeft;
QPair<QFontEngine *, int> 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));