QGlyphRun Class
QGlyphRun 类可直接访问字体的内部字形。更多
头文件: | #include <QGlyphRun> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
- 所有成员(包括继承成员)的列表
- QGlyphRun 属于隐式共享类。
公共类型
enum | GlyphRunFlag { Overline, Underline, StrikeOut, RightToLeft, SplitLigature } |
flags | GlyphRunFlags |
公共函数
QGlyphRun() | |
QGlyphRun(const QGlyphRun &other) | |
~QGlyphRun() | |
QRectF | boundingRect() const |
void | clear() |
QGlyphRun::GlyphRunFlags | flags() const |
QList<quint32> | glyphIndexes() const |
bool | isEmpty() const |
bool | isRightToLeft() const |
bool | overline() const |
QList<QPointF> | positions() const |
QRawFont | rawFont() const |
void | setBoundingRect(const QRectF &boundingRect) |
void | setFlag(QGlyphRun::GlyphRunFlag flag, bool enabled = true) |
void | setFlags(QGlyphRun::GlyphRunFlags flags) |
void | setGlyphIndexes(const QList<quint32> &glyphIndexes) |
void | setOverline(bool overline) |
void | setPositions(const QList<QPointF> &positions) |
void | setRawData(const quint32 *glyphIndexArray, const QPointF *glyphPositionArray, int size) |
void | setRawFont(const QRawFont &rawFont) |
void | setRightToLeft(bool rightToLeft) |
(since 6.5) void | setSourceString(const QString &sourceString) |
void | setStrikeOut(bool strikeOut) |
(since 6.5) void | setStringIndexes(const QList<qsizetype> &stringIndexes) |
void | setUnderline(bool underline) |
(since 6.5) QString | sourceString() const |
bool | strikeOut() const |
(since 6.5) QList<qsizetype> | stringIndexes() const |
void | swap(QGlyphRun &other) |
bool | underline() const |
bool | operator!=(const QGlyphRun &other) const |
QGlyphRun & | operator=(const QGlyphRun &other) |
bool | operator==(const QGlyphRun &other) const |
详细说明
当 Qt 显示以 Unicode 编码的文本字符串时,它会首先将 Unicode 点转换为字形索引列表和基于一种或多种字体的位置列表。在这种情况下,文本的 Unicode 表示法和QFont 对象将作为一个方便的抽象概念,隐藏在屏幕上显示文本时实际发生的细节。例如,当文本实际显示在屏幕上时,除了用户指定的字体外,可能还有其他字体,如最初选择的字体不支持文本中包含的所有书写系统。
在某些情况下,作为应用程序开发人员,可以对特定字体中的哪些字形绘制到屏幕上进行更底层的控制。例如,在与 Qt 一起使用外部字体引擎和文本整形器的应用程序中就会出现这种情况。QGlyphRun 为在屏幕上显示文本所需的原始数据提供了一个接口。它包含一个字形索引列表、每个字形的位置和字体。
用户有责任确保所选字体确实包含所提供的字形索引。
QTextLayout::glyphRuns() 或QTextFragment::glyphRuns() 可用于将 unicode 编码文本转换为 QGlyphRun 对象列表,而QPainter::drawGlyphRun() 可用于绘制字形。
成员类型文档
枚举 QGlyphRun::GlyphRunFlag
flags QGlyphRun::GlyphRunFlags
此枚举描述了可改变字形运行在可视化布局中的显示或行为方式的标志。生成字形运行的布局可根据相关的内部数据设置这些标志,以保留布局用户按其意图显示文本所需的信息。
常量 | 值 | 说明 |
---|---|---|
QGlyphRun::Overline | 0x01 | 表示字形应与叠线一起可视化。 |
QGlyphRun::Underline | 0x02 | 表示字形应与下划线一起可视化。 |
QGlyphRun::StrikeOut | 0x04 | 表示字形应在视觉上被删除。 |
QGlyphRun::RightToLeft | 0x08 | 表示字形从右向左排序。这会影响与字形运行相对的其他屏幕元素(如内嵌文本对象)的定位。 |
QGlyphRun::SplitLigature | 0x10 | 表示字形运行分割了一个连接字形。这意味着字形运行中包含了一个连线字形,但其所代表的字符仅对应于该连线的一部分。在这种情况下,可以使用字形运行的boundingRect() 函数来检索与字形运行所代表的字符相对应的字形所覆盖的区域。在对字形进行可视化时,需要注意剪辑到该边界矩形,以确保只绘制出连接线的相应部分。尤其是从QTextLayout 中检索特定字符范围的字形运行时,例如检索QTextLayout 的选定区域时,可能会出现这种情况。 |
GlyphRunFlags 类型是QFlags<GlyphRunFlag> 的类型定义。它存储 GlyphRunFlag 值的 OR 组合。
成员函数文档
QGlyphRun::QGlyphRun()
构造一个空的 QGlyphRun 对象。
QGlyphRun::QGlyphRun(const QGlyphRun &other)
构造一个 QGlyphRun 对象,它是other 的副本。
[noexcept]
QGlyphRun::~QGlyphRun()
摧毁QGlyphRun.
QRectF QGlyphRun::boundingRect() const
返回包含QGlyphRun 中所有字形的最小矩形。如果已使用setBoundingRect() 设置了边界矩形,则将返回该矩形。否则,将根据字形运行中字形的字体度量来计算边界矩形。
另请参阅 setBoundingRect()。
void QGlyphRun::clear()
清除QGlyphRun 对象中的所有数据。
QGlyphRun::GlyphRunFlags QGlyphRun::flags() const
返回为QGlyphRun 设置的标志。
另请参阅 setFlags()、setFlag() 和setFlag()。
QList<quint32> QGlyphRun::glyphIndexes() const
返回QGlyphRun 对象的字形索引。
另请参阅 setGlyphIndexes() 和setPositions()。
bool QGlyphRun::isEmpty() const
如果QGlyphRun 不包含任何字形,则返回true
。
bool QGlyphRun::isRightToLeft() const
如果QGlyphRun 包含从右向左绘制的字形,则返回true
。
另请参阅 setRightToLeft() 和flags()。
bool QGlyphRun::overline() const
如果QGlyphRun 应使用叠线装饰,则返回true
。
另请参阅 setOverline() 和flags()。
QList<QPointF> QGlyphRun::positions() const
返回这组字形索引中每个字形的基线边缘位置。
另请参阅 setPositions()。
QRawFont QGlyphRun::rawFont() const
返回为QGlyphRun 对象选择的字体。
另请参阅 setRawFont()。
void QGlyphRun::setBoundingRect(const QRectF &boundingRect)
将QGlyphRun 中字形的边界矩形设置为boundingRect 。boundingRect() 将返回该矩形,除非该矩形为空,在这种情况下,将返回字形运行中字形的边界矩形。
注意: 除非您正在执行文本整形,否则不需要使用此函数。当QGlyphRun 所代表的区域小于其所包含的字形区域时,才会使用该函数。例如,如果通过调用QTextLayout::glyphRuns() 来获取字形运行,而指定的范围只包括一个连字(两个或多个字符合并为一个字形)的一部分,就会出现这种情况。在这种情况下,根据连字中字符的平均宽度计算,边界矩形应只包括连字字形的适当部分。
为了支持这种情况(例如,应使用与主文本颜色不同的颜色绘制选区),有必要将绘制机制夹在boundingRect() 返回的矩形中,以避免绘制整个连字字形。
另请参见 boundingRect()。
void QGlyphRun::setFlag(QGlyphRun::GlyphRunFlag flag, bool enabled = true)
如果enabled 为真,则启用flag ;否则,禁用 。
void QGlyphRun::setFlags(QGlyphRun::GlyphRunFlags flags)
将QGlyphRun 的标志设置为flags 。
void QGlyphRun::setGlyphIndexes(const QList<quint32> &glyphIndexes)
将QGlyphRun 对象的字形索引设置为glyphIndexes 。字形索引必须对所选字体有效。
另请参阅 glyphIndexes()。
void QGlyphRun::setOverline(bool overline)
如果overline 为 true,则表示该QGlyphRun 应使用换行装饰。否则,QGlyphRun 将不带换行装饰。
另请参阅 overline()、setFlag() 和setFlags()。
void QGlyphRun::setPositions(const QList<QPointF> &positions)
将这组字形索引中每个字形的基线边缘位置设置为positions 。
另请参阅 positions().
void QGlyphRun::setRawData(const quint32 *glyphIndexArray, const QPointF *glyphPositionArray, int size)
设置QGlyphRun 的字形索引和位置,以使用数组glyphIndexArray 和glyphPositionArray 中的第一个size 元素。数据不会被复制。调用者必须保证,只要该QGlyphRun 及其副本存在,数组就不会被删除。
另请参阅 setGlyphIndexes() 和setPositions()。
void QGlyphRun::setRawFont(const QRawFont &rawFont)
将查找字形索引的字体设置为rawFont 。
另请参阅 rawFont() 和setGlyphIndexes()。
void QGlyphRun::setRightToLeft(bool rightToLeft)
如果rightToLeft 为 true,则表示该QGlyphRun 包含的字形应从右向左排序。否则,假定字形顺序为从左到右。
另请参阅 isRightToLeft()、setFlag() 和setFlags()。
[since 6.5]
void QGlyphRun::setSourceString(const QString &sourceString)
将字形运行对应的字符串设置为sourceString 。如果设置了该字符串,则stringIndexes() 返回的索引应是该字符串的索引。
此函数在 Qt 6.5 中引入。
另请参阅 sourceString() 和stringIndexes()。
void QGlyphRun::setStrikeOut(bool strikeOut)
如果strikeOut 为 true,则表示该QGlyphRun 应涂上删除线装饰。否则,该QGlyphRun 就不应该使用 "剔除 "装饰。
另请参阅 strikeOut()、setFlag() 和setFlags()。
[since 6.5]
void QGlyphRun::setStringIndexes(const QList<qsizetype> &stringIndexes)
将与字形索引相对应的字符串索引列表设置为stringIndexes
有关该列表约定的更多详情,请参阅stringIndexes() 。
此函数在 Qt 6.5 中引入。
另请参阅 stringIndexes() 和sourceString()。
void QGlyphRun::setUnderline(bool underline)
如果underline 为 true,则表示该QGlyphRun 应使用下划线装饰。否则,QGlyphRun 将不带下划线装饰。
另请参阅 underline()、setFlag() 和setFlags()。
[since 6.5]
QString QGlyphRun::sourceString() const
如果字形运行是通过字符串创建的,且该字符串已从布局中请求,则返回与字形运行相对应的字符串。
此函数在 Qt 6.5 中引入。
另请参阅 setSourceString()、stringIndexes() 和QTextLayout::glyphRuns()。
bool QGlyphRun::strikeOut() const
如果该QGlyphRun 应使用删除线装饰,则返回true
。
另请参阅 setStrikeOut() 和flags()。
[since 6.5]
QList<qsizetype> QGlyphRun::stringIndexes() const
如果字形运行是由字符串构建的,且已从布局中请求了字符串索引,则返回每个字形索引对应的字符串索引。在这种情况下,返回向量的长度将与glyphIndexes() 的长度一致。在其他情况下,它将是空的。
由于单个字形可能对应源字符串中的多个字符,因此字符串索引列表中可能会出现空白。例如,如果 "first "字符串是由包含 "fi "字符对连字符的字体处理的,那么这个五个字符的字符串将生成一个仅由四个字形组成的字形流。在这种情况下,字形索引可能是(1, 2, 3, 4)(四个任意的字形索引),而字符串索引则是(0, 2, 3, 4)。字形是按照字符串的逻辑顺序排列的,因此在这种情况下,第一个字形就意味着跨越了字符 0 和 1。
相反,单个字符也可能产生多个字形,在这种情况下,字符串索引列表中会出现重复条目。
字符串索引与字符串相对应,可选择通过sourceString() 获取。
此函数在 Qt 6.5 中引入。
另请参见 setStringIndexes()、sourceString() 和QTextLayout::glyphRuns()。
[noexcept]
void QGlyphRun::swap(QGlyphRun &other)
将此字形运行实例与other 互换。该操作速度非常快,从未出现过故障。
bool QGlyphRun::underline() const
如果QGlyphRun 应使用下划线装饰,则返回true
。
另请参阅 setUnderline() 和flags()。
bool QGlyphRun::operator!=(const QGlyphRun &other) const
将other 与此QGlyphRun 对象进行比较。如果字形索引列表、位置列表或字体有任何不同,则返回true
,否则返回false
。
QGlyphRun &QGlyphRun::operator=(const QGlyphRun &other)
为QGlyphRun 对象指定other 。
bool QGlyphRun::operator==(const QGlyphRun &other) const
将other 与此QGlyphRun 对象进行比较。如果字形索引列表、位置列表和字体都相等,则返回true
,否则返回false
。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.