LayoutRect InlineTextBox::localSelectionRect(int startPos, int endPos) const { int sPos = std::max(startPos - m_start, 0); int ePos = std::min(endPos - m_start, (int)m_len); if (sPos > ePos) return LayoutRect(); FontCachePurgePreventer fontCachePurgePreventer; LayoutUnit selTop = root().selectionTop(); LayoutUnit selHeight = root().selectionHeight(); const ComputedStyle& styleToUse = lineLayoutItem().styleRef(isFirstLineStyle()); const Font& font = styleToUse.font(); StringBuilder charactersWithHyphen; bool respectHyphen = ePos == m_len && hasHyphen(); TextRun textRun = constructTextRun(styleToUse, font, respectHyphen ? &charactersWithHyphen : 0); LayoutPoint startingPoint = LayoutPoint(logicalLeft(), selTop); LayoutRect r; if (sPos || ePos != static_cast<int>(m_len)) { r = LayoutRect(enclosingIntRect(font.selectionRectForText(textRun, FloatPoint(startingPoint), selHeight, sPos, ePos))); } else { // Avoid computing the font width when the entire line box is selected as an optimization. // FIXME: the call to rawValue() below is temporary and should be removed once the transition // to LayoutUnit-based types is complete (crbug.com/321237) r = LayoutRect(enclosingIntRect(LayoutRect(startingPoint, LayoutSize(m_logicalWidth, selHeight)))); } LayoutUnit logicalWidth = r.width(); if (r.x() > logicalRight()) logicalWidth = 0; else if (r.maxX() > logicalRight()) logicalWidth = logicalRight() - r.x(); LayoutPoint topPoint; LayoutUnit width; LayoutUnit height; if (isHorizontal()) { topPoint = LayoutPoint(r.x(), selTop); width = logicalWidth; height = selHeight; if (hasWrappedSelectionNewline()) { if (!isLeftToRightDirection()) topPoint.setX(topPoint.x() - newlineSpaceWidth()); width += newlineSpaceWidth(); } } else { topPoint = LayoutPoint(selTop, r.x()); width = selHeight; height = logicalWidth; // TODO(wkorman): RTL text embedded in top-to-bottom text can create // bottom-to-top situations. Add tests and ensure we handle correctly. if (hasWrappedSelectionNewline()) height += newlineSpaceWidth(); } return LayoutRect(topPoint, LayoutSize(width, height)); }
bool SpellChecker::spellCheck() { if ((spell_checker1 == 0) && (spell_checker2 == 0)) { QPixmap icon; icon.load(":/warning.png"); QMessageBox messageBox(QMessageBox::NoIcon, "YAGF", QObject::trUtf8("Required spelling dictionary (%1) is not found.\nSpell-checking is disabled.\nTry to install an appropriate aspell dictionary.").arg(bad_language), QMessageBox::Ok, 0); messageBox.setIconPixmap(icon); messageBox.exec(); return false; } QTextCursor cursor(m_textEdit->document()); while (!cursor.isNull() && !cursor.atEnd()) { if (hasLongHyphen(&cursor)) { cursor.select(QTextCursor::WordUnderCursor); QString word1 = cursor.selectedText(); word1.truncate(word1.length()-1); cursor.movePosition(QTextCursor::NextWord); cursor.select(QTextCursor::WordUnderCursor); QString word2 = cursor.selectedText(); word1 = word1 +word2; if (checkWordSpelling(word1)) { cursor.movePosition(QTextCursor::PreviousWord); cursor.select(QTextCursor::WordUnderCursor); cursor.removeSelectedText(); cursor.select(QTextCursor::WordUnderCursor); cursor.removeSelectedText(); cursor.insertText(word1); } } cursor.select(QTextCursor::WordUnderCursor); QString word = cursor.selectedText(); if (word == QString::fromUtf8("—")) { cursor.removeSelectedText(); cursor.insertText(QString::fromUtf8("—")); } if (hasHyphen(&cursor)) { QString cc = checkConcatenation(&cursor); if (!cc.isEmpty()) { cursor.movePosition(QTextCursor::PreviousWord); cursor.movePosition(QTextCursor::PreviousWord); cursor.select(QTextCursor::WordUnderCursor); cursor.removeSelectedText(); cursor.select(QTextCursor::WordUnderCursor); cursor.removeSelectedText(); cursor.movePosition(QTextCursor::NextWord); cursor.select(QTextCursor::WordUnderCursor); cursor.removeSelectedText(); cursor.insertText(cc); } } _checkWord(&cursor); QTextCursor oldc = cursor; if (!cursor.movePosition(QTextCursor::NextWord, QTextCursor::MoveAnchor)) break; //cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::MoveAnchor); //cursor = m_textEdit->document()->find(*m_regExp, cursor); int oldpos = oldc.position(); int newpos = cursor.position(); if (abs(newpos - oldpos) < 3) cursor.setPosition(newpos + 1); } if (!cursor.isNull()) _checkWord(&cursor); return true; }