diff options
Diffstat (limited to 'src/gui/text/qtextengine.cpp')
-rw-r--r-- | src/gui/text/qtextengine.cpp | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index b7459bf826..6336fadf74 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -258,7 +258,7 @@ struct QBidiAlgorithm { for (int i = 0; i < length; ++i) { int pos = i; uint uc = text[i].unicode(); - if (QChar::isHighSurrogate(uc) && i < length - 1) { + if (QChar::isHighSurrogate(uc) && i < length - 1 && text[i + 1].isLowSurrogate()) { ++i; analysis[i].bidiDirection = QChar::DirNSM; uc = QChar::surrogateToUcs4(ushort(uc), text[i].unicode()); @@ -1373,9 +1373,15 @@ static void applyVisibilityRules(ushort ucs, QGlyphLayout *glyphs, uint glyphPos if (!fontEngine->symbol) { // U+00AD [SOFT HYPHEN] is a default ignorable codepoint, // so we replace its glyph and metrics with ones for - // U+002D [HYPHEN-MINUS] and make it visible if it appears at line-break + // U+002D [HYPHEN-MINUS] or U+2010 [HYPHEN] and make + // it visible if it appears at line-break const uint engineIndex = glyphs->glyphs[glyphPosition] & 0xff000000; - glyphs->glyphs[glyphPosition] = fontEngine->glyphIndex('-'); + glyph_t glyph = fontEngine->glyphIndex(0x002d); + if (glyph == 0) + glyph = fontEngine->glyphIndex(0x2010); + if (glyph == 0) + glyph = fontEngine->glyphIndex(0x00ad); + glyphs->glyphs[glyphPosition] = glyph; if (Q_LIKELY(glyphs->glyphs[glyphPosition] != 0)) { glyphs->glyphs[glyphPosition] |= engineIndex; QGlyphLayout tmp = glyphs->mid(glyphPosition, 1); @@ -1547,12 +1553,27 @@ void QTextEngine::shapeText(int item) const } else { si.num_glyphs = shapeTextWithHarfbuzz(si, string, itemLength, fontEngine, itemBoundaries, kerningEnabled); } + if (Q_UNLIKELY(si.num_glyphs == 0)) { - Q_UNREACHABLE(); // ### report shaping errors somehow + if (Q_UNLIKELY(!ensureSpace(si.glyph_data_offset + 1))) { + qWarning() << "Unable to allocate space for place-holder glyph"; + return; + } + + si.num_glyphs = 1; + + // Overwrite with 0 token to indicate failure + QGlyphLayout g = availableGlyphs(&si); + g.glyphs[0] = 0; + g.attributes[0].clusterStart = true; + + ushort *log_clusters = logClusters(&si); + for (int i = 0; i < itemLength; ++i) + log_clusters[i] = 0; + return; } - layoutData->used += si.num_glyphs; QGlyphLayout glyphs = shapedGlyphs(&si); @@ -2164,20 +2185,35 @@ void QTextEngine::itemize() const QTextDocumentPrivate::FragmentIterator end = p->find(block.position() + block.length() - 1); // -1 to omit the block separator char int format = it.value()->format; + int preeditPosition = s ? s->preeditPosition : INT_MAX; int prevPosition = 0; int position = prevPosition; while (1) { const QTextFragmentData * const frag = it.value(); if (it == end || format != frag->format) { - if (s && position >= s->preeditPosition) { + if (s && position >= preeditPosition) { position += s->preeditText.length(); - s = nullptr; + preeditPosition = INT_MAX; } Q_ASSERT(position <= length); QFont::Capitalization capitalization = formatCollection()->charFormat(format).hasProperty(QTextFormat::FontCapitalization) ? formatCollection()->charFormat(format).fontCapitalization() : formatCollection()->defaultFont().capitalization(); + if (s) { + for (const auto &range : qAsConst(s->formats)) { + if (range.start + range.length <= prevPosition || range.start >= position) + continue; + if (range.format.hasProperty(QTextFormat::FontCapitalization)) { + if (range.start > prevPosition) + itemizer.generate(prevPosition, range.start - prevPosition, capitalization); + int newStart = std::max(prevPosition, range.start); + int newEnd = std::min(position, range.start + range.length); + itemizer.generate(newStart, newEnd - newStart, range.format.fontCapitalization()); + prevPosition = newEnd; + } + } + } itemizer.generate(prevPosition, position - prevPosition, capitalization); if (it == end) { if (position < length) |