本文整理汇总了C++中QTextLine::glyphRuns方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextLine::glyphRuns方法的具体用法?C++ QTextLine::glyphRuns怎么用?C++ QTextLine::glyphRuns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextLine
的用法示例。
在下文中一共展示了QTextLine::glyphRuns方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setUnicodeText
void setUnicodeText(const QString &text, const QFont &font, const QColor &color)
{
deleteContent();
QRawFont raw_font = QRawFont::fromFont(font, QFontDatabase::Latin);
qreal line_width = raw_font.averageCharWidth() * text.size();
QSGRenderContext *sgr = QQuickItemPrivate::get(m_owner)->sceneGraphRenderContext();
QTextLayout layout(text,font);
layout.beginLayout();
QTextLine line = layout.createLine();
line.setLineWidth(line_width);
//Q_ASSERT(!layout.createLine().isValid());
layout.endLayout();
QList<QGlyphRun> glyphRuns = line.glyphRuns();
qreal xpos = 0;
for (int i = 0; i < glyphRuns.size(); i++) {
QSGGlyphNode *node = sgr->sceneGraphContext()->createGlyphNode(sgr, false);
node->setOwnerElement(m_owner);
node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern);
node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern);
node->setGlyphs(QPointF(xpos, raw_font.ascent()), glyphRuns.at(i));
node->setStyle(QQuickText::Normal);
node->setColor(color);
xpos += raw_font.averageCharWidth() * glyphRuns.at(i).positions().size();
node->update();
appendChildNode(node);
}
}
示例2: position
QList<QGlyphRun> QTextFragment::glyphRuns(int pos, int len) const
{
if (!p || !n)
return QList<QGlyphRun>();
int blockNode = p->blockMap().findNode(position());
const QTextBlockData *blockData = p->blockMap().fragment(blockNode);
QTextLayout *layout = blockData->layout;
int blockPosition = p->blockMap().position(blockNode);
if (pos < 0)
pos = position() - blockPosition;
if (len < 0)
len = length();
if (len == 0)
return QList<QGlyphRun>();
QList<QGlyphRun> ret;
for (int i=0; i<layout->lineCount(); ++i) {
QTextLine textLine = layout->lineAt(i);
ret += textLine.glyphRuns(pos, len);
}
return ret;
}