210void QTextBlockGroup::blockInserted(
const QTextBlock &block)
212 Q_D(QTextBlockGroup);
213 QTextBlockGroupPrivate::BlockList::Iterator it = std::lower_bound(d->blocks.begin(), d->blocks.end(), block);
214 d->blocks.insert(it, block);
215 d->markBlocksDirty();
494 Q_ASSERT(!fragment_start);
495 fragment_start = fragment;
497 Q_ASSERT(!fragment_end);
498 fragment_end = fragment;
499 }
else if (type == QChar::ObjectReplacementCharacter) {
500 Q_ASSERT(!fragment_start);
501 Q_ASSERT(!fragment_end);
502 fragment_start = fragment;
503 fragment_end = fragment;
513 Q_ASSERT(fragment_start == fragment);
516 Q_ASSERT(fragment_end == fragment);
518 }
else if (type == QChar::ObjectReplacementCharacter) {
519 Q_ASSERT(fragment_start == fragment);
520 Q_ASSERT(fragment_end == fragment);
533 if (fragment_start == 0 && fragment_end == 0
535 QTextDocumentPrivate::get(q->document())->deleteObject(q);
542 int index = parentFrame->d_func()->childFrames.indexOf(q);
545 for (
int i = 0; i < childFrames.size(); ++i) {
546 QTextFrame *c = childFrames.at(i);
547 parentFrame->d_func()->childFrames.insert(index, c);
548 c->d_func()->parentFrame = parentFrame;
551 Q_ASSERT(parentFrame->d_func()->childFrames.at(index) == q);
552 parentFrame->d_func()->childFrames.removeAt(index);
555 parentFrame =
nullptr;
640QTextFrame::iterator &QTextFrame::iterator::operator++()
642 const QTextDocumentPrivate *priv = QTextDocumentPrivate::get(f);
643 const QTextDocumentPrivate::BlockMap &map = priv->blockMap();
645 int end = cf->lastPosition() + 1;
646 cb = map.findNode(end);
653 if (!f->d_func()->childFrames.isEmpty()) {
654 int pos = map.position(cb);
656 QTextDocumentPrivate::FragmentIterator frag = priv->find(pos-1);
657 if (priv->buffer().at(frag->stringPosition) != QChar::ParagraphSeparator) {
658 QTextFrame *nf = qobject_cast<QTextFrame *>(priv->objectForFormat(frag->format));
678QTextFrame::iterator &QTextFrame::iterator::operator--()
680 const QTextDocumentPrivate *priv = QTextDocumentPrivate::get(f);
681 const QTextDocumentPrivate::BlockMap &map = priv->blockMap();
683 int start = cf->firstPosition() - 1;
684 cb = map.findNode(start);
690 int pos = map.position(cb);
692 QTextDocumentPrivate::FragmentIterator frag = priv->find(pos-1);
693 if (priv->buffer().at(frag->stringPosition) != QChar::ParagraphSeparator) {
694 QTextFrame *pf = qobject_cast<QTextFrame *>(priv->objectForFormat(frag->format));
698 }
else if (priv->buffer().at(frag->stringPosition) ==
QTextEndOfFrame) {
707 cb = map.previous(cb);
1069Qt::LayoutDirection QTextBlock::textDirection()
const
1071 Qt::LayoutDirection dir = blockFormat().layoutDirection();
1072 if (dir != Qt::LayoutDirectionAuto)
1075 dir = p->defaultTextOption.textDirection();
1076 if (dir != Qt::LayoutDirectionAuto)
1079 const QString buffer = p->buffer();
1081 const int pos = position();
1082 QTextDocumentPrivate::FragmentIterator it = p->find(pos);
1083 QTextDocumentPrivate::FragmentIterator end = p->find(pos + length() - 1);
1084 for (; it != end; ++it) {
1085 const QTextFragmentData *
const frag = it.value();
1086 const QChar *p = buffer.constData() + frag->stringPosition;
1087 const QChar *
const end = p + frag->size_array[0];
1089 uint ucs4 = p->unicode();
1090 if (QChar::isHighSurrogate(ucs4) && p + 1 < end) {
1091 ushort low = p[1].unicode();
1092 if (QChar::isLowSurrogate(low)) {
1093 ucs4 = QChar::surrogateToUcs4(ucs4, low);
1097 switch (QChar::direction(ucs4)) {
1099 return Qt::LeftToRight;
1102 return Qt::RightToLeft;
1109 return Qt::LeftToRight;
1117QString QTextBlock::text()
const
1122 const QString buffer = p->buffer();
1124 text.reserve(length());
1126 const int pos = position();
1127 QTextDocumentPrivate::FragmentIterator it = p->find(pos);
1128 QTextDocumentPrivate::FragmentIterator end = p->find(pos + length() - 1);
1129 for (; it != end; ++it) {
1130 const QTextFragmentData *
const frag = it.value();
1131 text += QStringView(buffer.constData() + frag->stringPosition, frag->size_array[0]);
1146QList<QTextLayout::FormatRange> QTextBlock::textFormats()
const
1148 QList<QTextLayout::FormatRange> formats;
1152 const QTextFormatCollection *formatCollection = p->formatCollection();
1158 const int pos = position();
1159 QTextDocumentPrivate::FragmentIterator it = p->find(pos);
1160 QTextDocumentPrivate::FragmentIterator end = p->find(pos + length() - 1);
1161 for (; it != end; ++it) {
1162 const QTextFragmentData *
const frag = it.value();
1163 if (format != it.value()->format) {
1164 if (cur - start > 0) {
1165 QTextLayout::FormatRange range;
1166 range.start = start;
1167 range.length = cur - start;
1168 range.format = formatCollection->charFormat(format);
1169 formats.append(range);
1172 format = frag->format;
1175 cur += frag->size_array[0];
1177 if (cur - start > 0) {
1178 QTextLayout::FormatRange range;
1179 range.start = start;
1180 range.length = cur - start;
1181 range.format = formatCollection->charFormat(format);
1182 formats.append(range);
1521QTextBlock::iterator &QTextBlock::iterator::operator--()
1523 n = p->fragmentMap().previous(n);
1528 int formatIndex = p->fragmentMap().fragment(n)->format;
1531 while (n != b && p->fragmentMap().fragment(n)->format != formatIndex) {
1533 n = p->fragmentMap().previous(n);
1643QList<QGlyphRun> QTextFragment::glyphRuns(
int pos,
int len)
const
1646 return QList<QGlyphRun>();
1648 int blockNode = p->blockMap().findNode(position());
1650 const QTextBlockData *blockData = p->blockMap().fragment(blockNode);
1651 QTextLayout *layout = blockData->layout;
1653 int blockPosition = p->blockMap().position(blockNode);
1655 pos = position() - blockPosition;
1659 return QList<QGlyphRun>();
1661 QList<QGlyphRun> ret;
1662 for (
int i=0; i<layout->lineCount(); ++i) {
1663 QTextLine textLine = layout->lineAt(i);
1664 ret += textLine.glyphRuns(pos, len);
1745QString QTextFragment::text()
const
1751 QString buffer = p->buffer();
1754 const QTextFragmentData *
const frag = p->fragmentMap().fragment(f);
1755 result += QString(buffer.constData() + frag->stringPosition, frag->size_array[0]);
1756 f = p->fragmentMap().next(f);
#define QTextBeginningOfFrame