Try allowing correct   handling.

This commit is contained in:
John Preston 2023-04-20 13:36:15 +04:00
parent 9395714537
commit 56945859e3
3 changed files with 28 additions and 15 deletions

View file

@ -185,6 +185,7 @@ public:
private: private:
void parseWords(QFixed minResizeWidth, int blockFrom); void parseWords(QFixed minResizeWidth, int blockFrom);
bool isLineBreak(const QCharAttributes *attributes, int index); bool isLineBreak(const QCharAttributes *attributes, int index);
bool isSpaceBreak(const QCharAttributes *attributes, int index);
TextBlock *block; TextBlock *block;
QTextEngine *eng; QTextEngine *eng;
@ -257,7 +258,17 @@ void BlockParser::parseWords(QFixed minResizeWidth, int blockFrom) {
} }
const QScriptItem &current = eng->layoutData->items[item]; const QScriptItem &current = eng->layoutData->items[item];
if (attributes[lbh.currentPosition].whiteSpace) { const auto atSpaceBreak = [&] {
for (auto index = lbh.currentPosition; index < end; ++index) {
if (!attributes[index].whiteSpace) {
return false;
} else if (isSpaceBreak(attributes, index)) {
return true;
}
}
return false;
}();
if (atSpaceBreak) {
while (lbh.currentPosition < end && attributes[lbh.currentPosition].whiteSpace) while (lbh.currentPosition < end && attributes[lbh.currentPosition].whiteSpace)
addNextCluster(lbh.currentPosition, end, lbh.spaceData, lbh.glyphCount, addNextCluster(lbh.currentPosition, end, lbh.spaceData, lbh.glyphCount,
current, lbh.logClusters, lbh.glyphs); current, lbh.logClusters, lbh.glyphs);
@ -281,7 +292,7 @@ void BlockParser::parseWords(QFixed minResizeWidth, int blockFrom) {
current, lbh.logClusters, lbh.glyphs); current, lbh.logClusters, lbh.glyphs);
if (lbh.currentPosition >= eng->layoutData->string.length() if (lbh.currentPosition >= eng->layoutData->string.length()
|| attributes[lbh.currentPosition].whiteSpace || isSpaceBreak(attributes, lbh.currentPosition)
|| isLineBreak(attributes, lbh.currentPosition)) { || isLineBreak(attributes, lbh.currentPosition)) {
lbh.calculateRightBearing(); lbh.calculateRightBearing();
block->_words.push_back(TextWord(wordStart + blockFrom, lbh.tmpData.textWidth, -lbh.negativeRightBearing())); block->_words.push_back(TextWord(wordStart + blockFrom, lbh.tmpData.textWidth, -lbh.negativeRightBearing()));
@ -330,14 +341,19 @@ void BlockParser::parseWords(QFixed minResizeWidth, int blockFrom) {
bool BlockParser::isLineBreak( bool BlockParser::isLineBreak(
const QCharAttributes *attributes, const QCharAttributes *attributes,
int index) { int index) {
bool lineBreak = attributes[index].lineBreak; // Don't break after / in links.
if (lineBreak return attributes[index].lineBreak
&& block->lnkIndex() > 0 && (block->lnkIndex() <= 0
&& index > 0 || index <= 0
&& str.at(index - 1) == '/') { || str[index - 1] != '/');
return false; // don't break after / in links }
}
return lineBreak; bool BlockParser::isSpaceBreak(
const QCharAttributes *attributes,
int index) {
// Don't break on &nbsp;
return attributes[index].whiteSpace
&& (str[index] != QChar::Nbsp);
} }
AbstractBlock::AbstractBlock( AbstractBlock::AbstractBlock(

View file

@ -422,7 +422,7 @@ void Parser::parseCurrentChar() {
_emojiLookback = 0; _emojiLookback = 0;
const auto inCustomEmoji = !_customEmojiData.isEmpty(); const auto inCustomEmoji = !_customEmojiData.isEmpty();
const auto isNewLine = !inCustomEmoji && _multiline && IsNewline(_ch); const auto isNewLine = !inCustomEmoji && _multiline && IsNewline(_ch);
const auto isSpace = IsSpace(_ch); const auto replaceWithSpace = IsSpace(_ch) && (_ch != QChar::Nbsp);
const auto isDiac = IsDiac(_ch); const auto isDiac = IsDiac(_ch);
const auto isTilde = !inCustomEmoji && _checkTilde && (_ch == '~'); const auto isTilde = !inCustomEmoji && _checkTilde && (_ch == '~');
const auto skip = [&] { const auto skip = [&] {
@ -487,7 +487,7 @@ void Parser::parseCurrentChar() {
} }
if (isNewLine) { if (isNewLine) {
createNewlineBlock(); createNewlineBlock();
} else if (isSpace) { } else if (replaceWithSpace) {
_t->_text.push_back(QChar::Space); _t->_text.push_back(QChar::Space);
_allowDiacritic = false; _allowDiacritic = false;
} else { } else {

View file

@ -1974,9 +1974,6 @@ QString InputField::getTextPart(
if (IsNewline(*ch) && ch->unicode() != '\r') { if (IsNewline(*ch) && ch->unicode() != '\r') {
*ch = QLatin1Char('\n'); *ch = QLatin1Char('\n');
} else switch (ch->unicode()) { } else switch (ch->unicode()) {
case QChar::Nbsp: {
*ch = QLatin1Char(' ');
} break;
case QChar::ObjectReplacementCharacter: { case QChar::ObjectReplacementCharacter: {
if (ch > begin) { if (ch > begin) {
result.append(begin, ch - begin); result.append(begin, ch - begin);