From a160bd4fccaebafb5453a642f43bdefafc1e2565 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Thu, 5 May 2016 02:17:56 -0700 Subject: Fix bugs causing Thin font weights to be ignored or mishandled. Task-number: QTBUG-53196 Change-Id: If12b3cab3d8de5e0e452fca844b0a484c29e9e86 Reviewed-by: Allan Sandfeld Jensen --- src/gui/text/qfontdatabase.cpp | 3 +-- src/gui/text/qfontengine.cpp | 3 +-- src/gui/text/qtextformat.cpp | 7 ++++--- src/gui/text/qtextformat.h | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) (limited to 'src/gui/text') diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 928d1e4eb5..c4b849878c 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -2730,8 +2730,7 @@ void QFontDatabase::load(const QFontPrivate *d, int script) } if (req.pointSize < 0) req.pointSize = req.pixelSize*72.0/d->dpi; - if (req.weight == 0) - req.weight = QFont::Normal; + req.weight = QFont::Normal; if (req.stretch == 0) req.stretch = 100; diff --git a/src/gui/text/qfontengine.cpp b/src/gui/text/qfontengine.cpp index 39348a52b0..5e8aac82b8 100644 --- a/src/gui/text/qfontengine.cpp +++ b/src/gui/text/qfontengine.cpp @@ -1840,8 +1840,7 @@ QFontEngine *QFontEngineMulti::loadEngine(int at) request.family = fallbackFamilyAt(at - 1); if (QFontEngine *engine = QFontDatabase::findFont(request, m_script)) { - if (request.weight > QFont::Normal) - engine->fontDef.weight = request.weight; + engine->fontDef.weight = request.weight; if (request.style > QFont::StyleNormal) engine->fontDef.style = request.style; return engine; diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index 7dcd060ba1..4b31b49df2 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -357,9 +357,10 @@ void QTextFormatPrivate::recalcFont() const f.setPixelSize(props.at(i).value.toInt()); break; case QTextFormat::FontWeight: { - int weight = props.at(i).value.toInt(); - if (weight == 0) weight = QFont::Normal; - f.setWeight(weight); + const QVariant weightValue = props.at(i).value; + int weight = weightValue.toInt(); + if (weight >= 0 && weightValue.isValid()) + f.setWeight(weight); break; } case QTextFormat::FontItalic: f.setItalic(props.at(i).value.toBool()); diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h index 6c1b75aa35..dbc50f70f9 100644 --- a/src/gui/text/qtextformat.h +++ b/src/gui/text/qtextformat.h @@ -424,9 +424,9 @@ public: { return doubleProperty(FontPointSize); } inline void setFontWeight(int weight) - { if (weight == QFont::Normal) weight = 0; setProperty(FontWeight, weight); } + { setProperty(FontWeight, weight); } inline int fontWeight() const - { int weight = intProperty(FontWeight); if (weight == 0) weight = QFont::Normal; return weight; } + { return hasProperty(FontWeight) ? intProperty(FontWeight) : QFont::Normal; } inline void setFontItalic(bool italic) { setProperty(FontItalic, italic); } inline bool fontItalic() const -- cgit v1.2.3 From a24b90a21c4f2feb61630ca6a1684312556a6bc7 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Thu, 14 Apr 2016 14:55:44 +0300 Subject: Gui: use const (and const APIs) more For CoW types, prefer const methods to avoid needless detach()ing. Change-Id: I88d08d499e1be72c1f6d983fecdcee513df18aa2 Reviewed-by: Edward Welbourne --- src/gui/text/qcssparser.cpp | 3 ++- src/gui/text/qtextdocument_p.cpp | 21 +++++++++++---------- src/gui/text/qtextdocumentfragment.cpp | 6 +++--- src/gui/text/qtextdocumentlayout.cpp | 24 ++++++++++++------------ src/gui/text/qtextengine.cpp | 4 ++-- src/gui/text/qtextformat.cpp | 2 +- src/gui/text/qtexthtmlparser.cpp | 2 +- src/gui/text/qtextodfwriter.cpp | 8 ++++---- src/gui/text/qtexttable.cpp | 20 +++++++++++--------- 9 files changed, 47 insertions(+), 43 deletions(-) (limited to 'src/gui/text') diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index 53d4e3fa36..d455a74d96 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -1507,7 +1507,7 @@ QRect Declaration::rectValue() const const QCss::Value &v = d->values.at(0); if (v.type != Value::Function) return QRect(); - QStringList func = v.variant.toStringList(); + const QStringList func = v.variant.toStringList(); if (func.count() != 2 || func.at(0).compare(QLatin1String("rect")) != 0) return QRect(); QStringList args = func[1].split(QLatin1Char(' '), QString::SkipEmptyParts); @@ -1653,6 +1653,7 @@ Qt::Alignment Declaration::alignmentValue() const void Declaration::borderImageValue(QString *image, int *cuts, TileMode *h, TileMode *v) const { + const DeclarationData *d = this->d.data(); // make it const and shadow d *image = uriValue(); for (int i = 0; i < 4; i++) cuts[i] = -1; diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp index 93071aaf59..ffc5d7418b 100644 --- a/src/gui/text/qtextdocument_p.cpp +++ b/src/gui/text/qtextdocument_p.cpp @@ -1006,9 +1006,9 @@ int QTextDocumentPrivate::undoRedo(bool undo) bool inBlock = ( undoState > 0 && undoState < undoStack.size() - && undoStack[undoState].block_part - && undoStack[undoState-1].block_part - && !undoStack[undoState-1].block_end + && undoStack.at(undoState).block_part + && undoStack.at(undoState - 1).block_part + && !undoStack.at(undoState - 1).block_end ); if (!inBlock) break; @@ -1074,12 +1074,13 @@ void QTextDocumentPrivate::appendUndoItem(const QTextUndoCommand &c) if (!undoStack.isEmpty() && modified) { - QTextUndoCommand &last = undoStack[undoState - 1]; + const int lastIdx = undoState - 1; + const QTextUndoCommand &last = undoStack.at(lastIdx); if ( (last.block_part && c.block_part && !last.block_end) // part of the same block => can merge || (!c.block_part && !last.block_part)) { // two single undo items => can merge - if (last.tryMerge(c)) + if (undoStack[lastIdx].tryMerge(c)) return; } } @@ -1101,7 +1102,7 @@ void QTextDocumentPrivate::clearUndoRedoStacks(QTextDocument::Stacks stacksToCle bool redoCommandsAvailable = undoState != undoStack.size(); if (stacksToClear == QTextDocument::UndoStack && undoCommandsAvailable) { for (int i = 0; i < undoState; ++i) { - QTextUndoCommand c = undoStack[undoState]; + QTextUndoCommand c = undoStack.at(undoState); if (c.command & QTextUndoCommand::Custom) delete c.custom; } @@ -1113,7 +1114,7 @@ void QTextDocumentPrivate::clearUndoRedoStacks(QTextDocument::Stacks stacksToCle } else if (stacksToClear == QTextDocument::RedoStack && redoCommandsAvailable) { for (int i = undoState; i < undoStack.size(); ++i) { - QTextUndoCommand c = undoStack[i]; + QTextUndoCommand c = undoStack.at(i); if (c.command & QTextUndoCommand::Custom) delete c.custom; } @@ -1123,7 +1124,7 @@ void QTextDocumentPrivate::clearUndoRedoStacks(QTextDocument::Stacks stacksToCle } else if (stacksToClear == QTextDocument::UndoAndRedoStacks && !undoStack.isEmpty()) { for (int i = 0; i < undoStack.size(); ++i) { - QTextUndoCommand c = undoStack[i]; + QTextUndoCommand c = undoStack.at(i); if (c.command & QTextUndoCommand::Custom) delete c.custom; } @@ -1186,8 +1187,8 @@ void QTextDocumentPrivate::endEditBlock() return; if (undoEnabled && undoState > 0) { - const bool wasBlocking = !undoStack[undoState - 1].block_end; - if (undoStack[undoState - 1].block_part) { + const bool wasBlocking = !undoStack.at(undoState - 1).block_end; + if (undoStack.at(undoState - 1).block_part) { undoStack[undoState - 1].block_end = true; if (wasBlocking) emit document()->undoCommandAdded(); diff --git a/src/gui/text/qtextdocumentfragment.cpp b/src/gui/text/qtextdocumentfragment.cpp index f8f4e454e0..a1a562c839 100644 --- a/src/gui/text/qtextdocumentfragment.cpp +++ b/src/gui/text/qtextdocumentfragment.cpp @@ -882,7 +882,7 @@ QTextHtmlImporter::Table QTextHtmlImporter::scanTable(int tableNodeIdx) if (at(cell).isTableCell()) { // skip all columns with spans from previous rows while (colsInRow < rowColSpanForColumn.size()) { - const RowColSpanInfo &spanInfo = rowColSpanForColumn[colsInRow]; + const RowColSpanInfo &spanInfo = rowColSpanForColumn.at(colsInRow); if (spanInfo.row + spanInfo.rowSpan > effectiveRow) { Q_ASSERT(spanInfo.col == colsInRow); @@ -1081,8 +1081,8 @@ QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processBlockNode() && indent != 0 && (lists.isEmpty() || !hasBlock - || !lists.last().list - || lists.last().list->itemNumber(cursor.block()) == -1 + || !lists.constLast().list + || lists.constLast().list->itemNumber(cursor.block()) == -1 ) ) { block.setIndent(indent); diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index 9863955a55..b6cbd9617f 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -265,7 +265,7 @@ void QTextTableData::updateTableSize() const QFixed effectiveLeftMargin = this->leftMargin + border + padding; const QFixed effectiveRightMargin = this->rightMargin + border + padding; size.height = contentsHeight == -1 - ? rowPositions.last() + heights.last() + padding + border + cellSpacing + effectiveBottomMargin + ? rowPositions.constLast() + heights.constLast() + padding + border + cellSpacing + effectiveBottomMargin : effectiveTopMargin + contentsHeight + effectiveBottomMargin; size.width = effectiveLeftMargin + contentsWidth + effectiveRightMargin; } @@ -1238,7 +1238,7 @@ void QTextDocumentLayoutPrivate::drawFlow(const QPointF &offset, QPainter *paint // if we're past what is already laid out then we're better off // not trying to draw things that may not be positioned correctly yet - if (currentPosInDoc >= checkPoints.last().positionInFrame) + if (currentPosInDoc >= checkPoints.constLast().positionInFrame) break; if (lastVisibleCheckPoint != checkPoints.end() @@ -1798,7 +1798,7 @@ recalc_minmax_widths: td->columnPositions[i] = td->columnPositions.at(i-1) + td->widths.at(i-1) + 2 * td->border + cellSpacing; // - margin to compensate the + margin in columnPositions[0] - const QFixed contentsWidth = td->columnPositions.last() + td->widths.last() + td->padding + td->border + cellSpacing - leftMargin; + const QFixed contentsWidth = td->columnPositions.constLast() + td->widths.constLast() + td->padding + td->border + cellSpacing - leftMargin; // if the table is too big and causes an overflow re-do the layout with WrapAnywhere as wrap // mode @@ -1845,14 +1845,14 @@ recalc_minmax_widths: td->calcRowPosition(r); const int tableStartPage = (absoluteTableY / pageHeight).truncate(); - const int currentPage = ((td->rowPositions[r] + absoluteTableY) / pageHeight).truncate(); + const int currentPage = ((td->rowPositions.at(r) + absoluteTableY) / pageHeight).truncate(); const QFixed pageBottom = (currentPage + 1) * pageHeight - td->effectiveBottomMargin - absoluteTableY - cellSpacing - td->border; const QFixed pageTop = currentPage * pageHeight + td->effectiveTopMargin - absoluteTableY + cellSpacing + td->border; const QFixed nextPageTop = pageTop + pageHeight; - if (td->rowPositions[r] > pageBottom) + if (td->rowPositions.at(r) > pageBottom) td->rowPositions[r] = nextPageTop; - else if (td->rowPositions[r] < pageTop) + else if (td->rowPositions.at(r) < pageTop) td->rowPositions[r] = pageTop; bool dropRowToNextPage = true; @@ -1863,7 +1863,7 @@ recalc_minmax_widths: QFixed dropDistance = 0; relayout: - const int rowStartPage = ((td->rowPositions[r] + absoluteTableY) / pageHeight).truncate(); + const int rowStartPage = ((td->rowPositions.at(r) + absoluteTableY) / pageHeight).truncate(); // if any of the header rows or the first non-header row start on the next page // then the entire header should be dropped if (r <= headerRowCount && rowStartPage > tableStartPage && !hasDroppedTable) { @@ -1927,13 +1927,13 @@ relayout: } if (rowCellCount > 0 && dropRowToNextPage) { - dropDistance = nextPageTop - td->rowPositions[r]; + dropDistance = nextPageTop - td->rowPositions.at(r); td->rowPositions[r] = nextPageTop; td->heights[r] = 0; dropRowToNextPage = false; cellHeights.resize(cellCountBeforeRow); if (r > headerRowCount) - td->heights[r-1] = pageBottom - td->rowPositions[r-1]; + td->heights[r - 1] = pageBottom - td->rowPositions.at(r - 1); goto relayout; } @@ -1944,7 +1944,7 @@ relayout: } if (r == headerRowCount - 1) { - td->headerHeight = td->rowPositions[r] + td->heights[r] - td->rowPositions[0] + td->cellSpacing + 2 * td->border; + td->headerHeight = td->rowPositions.at(r) + td->heights.at(r) - td->rowPositions.at(0) + td->cellSpacing + 2 * td->border; td->headerHeight -= td->headerHeight * (td->headerHeight / pageHeight).truncate(); td->effectiveTopMargin += td->headerHeight; } @@ -2304,7 +2304,7 @@ void QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::Iterator it, QTextLayout docPos = it.currentBlock().position(); if (inRootFrame) { - if (qAbs(layoutStruct->y - checkPoints.last().y) > 2000) { + if (qAbs(layoutStruct->y - checkPoints.constLast().y) > 2000) { QFixed left, right; floatMargins(layoutStruct->y, layoutStruct, &left, &right); if (left == layoutStruct->x_left && right == layoutStruct->x_right) { @@ -2554,7 +2554,7 @@ void QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::Iterator it, QTextLayout checkPoints.append(cp); checkPoints.reserve(checkPoints.size()); } else { - currentLazyLayoutPosition = checkPoints.last().positionInFrame; + currentLazyLayoutPosition = checkPoints.constLast().positionInFrame; // ####### //checkPoints.last().positionInFrame = q->document()->docHandle()->length(); } diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 7864975091..7ee02b71c9 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -3274,7 +3274,7 @@ int QTextEngine::endOfLine(int lineNum) insertionPointsForLine(lineNum, insertionPoints); if (insertionPoints.size() > 0) - return insertionPoints.last(); + return insertionPoints.constLast(); return 0; } @@ -3284,7 +3284,7 @@ int QTextEngine::beginningOfLine(int lineNum) insertionPointsForLine(lineNum, insertionPoints); if (insertionPoints.size() > 0) - return insertionPoints.first(); + return insertionPoints.constFirst(); return 0; } diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index 49ec9ca768..402bd75a76 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -3462,7 +3462,7 @@ void QTextFormatCollection::setDefaultFont(const QFont &f) { defaultFnt = f; for (int i = 0; i < formats.count(); ++i) - if (formats[i].d) + if (formats.at(i).d) formats[i].d->resolveFont(defaultFnt); } diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index 576ff7d935..103a208c26 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -665,7 +665,7 @@ void QTextHtmlParser::parseTag() if (hasPrefix(QLatin1Char('/'))) { if (nodes.last().id == Html_style) { #ifndef QT_NO_CSSPARSER - QCss::Parser parser(nodes.last().text); + QCss::Parser parser(nodes.constLast().text); QCss::StyleSheet sheet; sheet.origin = QCss::StyleSheetOrigin_Author; parser.parse(&sheet, Qt::CaseInsensitive); diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp index bd2a9d5183..ad537b7126 100644 --- a/src/gui/text/qtextodfwriter.cpp +++ b/src/gui/text/qtextodfwriter.cpp @@ -812,10 +812,10 @@ bool QTextOdfWriter::writeAll() } // add objects for lists, frames and tables - QVector allFormats = m_document->allFormats(); - QList copy = formats.toList(); - for (QList::Iterator iter = copy.begin(); iter != copy.end(); ++iter) { - QTextObject *object = m_document->objectForFormat(allFormats[*iter]); + const QVector allFormats = m_document->allFormats(); + const QList copy = formats.toList(); + for (auto index : copy) { + QTextObject *object = m_document->objectForFormat(allFormats[index]); if (object) formats << object->formatIndex(); } diff --git a/src/gui/text/qtexttable.cpp b/src/gui/text/qtexttable.cpp index 2d5636e1d9..e4a3c2b915 100644 --- a/src/gui/text/qtexttable.cpp +++ b/src/gui/text/qtexttable.cpp @@ -824,7 +824,7 @@ void QTextTable::insertColumns(int pos, int num) QVector columnWidths = tfmt.columnWidthConstraints(); if (! columnWidths.isEmpty()) { for (int i = num; i > 0; --i) - columnWidths.insert(pos, columnWidths[qMax(0, pos-1)]); + columnWidths.insert(pos, columnWidths.at(qMax(0, pos - 1))); } tfmt.setColumnWidthConstraints (columnWidths); QTextObject::setFormat(tfmt); @@ -1046,11 +1046,12 @@ void QTextTable::mergeCells(int row, int column, int numRows, int numCols) // find the position at which to insert the contents of the merged cells QFragmentFindHelper helper(origCellPosition, p->fragmentMap()); - const auto it = std::lower_bound(d->cells.begin(), d->cells.end(), helper); + const auto begin = d->cells.cbegin(); + const auto it = std::lower_bound(begin, d->cells.cend(), helper); Q_ASSERT(it != d->cells.end()); Q_ASSERT(!(helper < *it)); Q_ASSERT(*it == cellFragment); - const int insertCellIndex = it - d->cells.begin(); + const int insertCellIndex = it - begin; int insertFragment = d->cells.value(insertCellIndex + 1, d->fragment_end); uint insertPos = p->fragmentMap().position(insertFragment); @@ -1079,11 +1080,12 @@ void QTextTable::mergeCells(int row, int column, int numRows, int numCols) if (firstCellIndex == -1) { QFragmentFindHelper helper(pos, p->fragmentMap()); - const auto it = std::lower_bound(d->cells.begin(), d->cells.end(), helper); + const auto begin = d->cells.cbegin(); + const auto it = std::lower_bound(begin, d->cells.cend(), helper); Q_ASSERT(it != d->cells.end()); Q_ASSERT(!(helper < *it)); Q_ASSERT(*it == fragment); - firstCellIndex = cellIndex = it - d->cells.begin(); + firstCellIndex = cellIndex = it - begin; } ++cellIndex; @@ -1136,7 +1138,7 @@ void QTextTable::mergeCells(int row, int column, int numRows, int numCols) } } - d->fragment_start = d->cells.first(); + d->fragment_start = d->cells.constFirst(); fmt.setTableCellRowSpan(numRows); fmt.setTableCellColumnSpan(numCols); @@ -1212,9 +1214,9 @@ void QTextTable::splitCell(int row, int column, int numRows, int numCols) for (int r = row + 1; r < row + rowSpan; ++r) { // find the cell before which to insert the new cell markers int gridIndex = r * d->nCols + column; - QVector::iterator it = std::upper_bound(d->cellIndices.begin(), d->cellIndices.end(), gridIndex); - int cellIndex = it - d->cellIndices.begin(); - int fragment = d->cells.value(cellIndex, d->fragment_end); + const auto begin = d->cellIndices.cbegin(); + const auto it = std::upper_bound(begin, d->cellIndices.cend(), gridIndex); + int fragment = d->cells.value(it - begin, d->fragment_end); rowPositions[r - row] = p->fragmentMap().position(fragment); } -- cgit v1.2.3 From 8fb29ed259393a83e8fb5545c419543a85fc7bc9 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 31 May 2016 10:56:25 +0200 Subject: Don't alter input string in QTextLayout with ShowLineAndParagraphSeparators When ShowLineAndParagraphSeparators was set, we would replace the separator character in the user's string in some cases, since we never detached from the input string and just const_cast the pointer to the shared buffer. [ChangeLog][QtGui][Text] Fixed bug where a QTextLayout with ShowLineAndParagraphSeparators would modify the layout's input string. Task-number: QTBUG-42033 Change-Id: I92f9100b750f16e52b38b718245c13e5c4a0ebb9 Reviewed-by: Lars Knoll Reviewed-by: Konstantin Ritt --- src/gui/text/qtextengine.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/gui/text') diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index d0c2779a65..17a91f5a6a 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -1635,8 +1635,14 @@ void QTextEngine::itemize() const if (analysis->bidiLevel % 2) --analysis->bidiLevel; analysis->flags = QScriptAnalysis::LineOrParagraphSeparator; - if (option.flags() & QTextOption::ShowLineAndParagraphSeparators) + if (option.flags() & QTextOption::ShowLineAndParagraphSeparators) { + const int offset = uc - string; + layoutData->string.detach(); + string = reinterpret_cast(layoutData->string.unicode()); + uc = string + offset; + e = uc + length; *const_cast(uc) = 0x21B5; // visual line separator + } break; case QChar::Tabulation: analysis->flags = QScriptAnalysis::Tab; -- cgit v1.2.3 From 90988a2c6713e41937241e0848043a2e28973d68 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Thu, 2 Jun 2016 11:36:44 +0300 Subject: QFontDatabase: append substitutes directly to the family list Don't create tmp list. Change-Id: I1aa80f1fb5589eb01ad2a41cf028b920a618a636 Reviewed-by: Edward Welbourne --- src/gui/text/qfontdatabase.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/gui/text') diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index e4c9b45dc2..359c461ad3 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -709,13 +709,8 @@ static QStringList familyList(const QFontDef &req) } // append the substitute list for each family in family_list - QStringList subs_list; - QStringList::ConstIterator it = family_list.constBegin(), end = family_list.constEnd(); - for (; it != end; ++it) - subs_list += QFont::substitutes(*it); -// qDebug() << "adding substs: " << subs_list; - - family_list += subs_list; + for (int i = 0, size = family_list.size(); i < size; ++i) + family_list += QFont::substitutes(family_list.at(i)); return family_list; } -- cgit v1.2.3 From 6030e63037cdc09d43ad372ecbcfeece72b6e353 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Thu, 31 Mar 2016 17:34:32 +0300 Subject: QtGui: use QStringRef to optimize memory allocation Replace substring functions that return QString with corresponding functions that return QStringRef where it's possible. Create QString from QStringRef only where necessary. Change-Id: Id83c60cc7568b20ef008b51c582cfdf466a47e35 Reviewed-by: Edward Welbourne --- src/gui/text/qcssparser.cpp | 7 +++---- src/gui/text/qfont.cpp | 4 ++-- src/gui/text/qfontdatabase.cpp | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) (limited to 'src/gui/text') diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index d455a74d96..c237d80d34 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -1510,7 +1510,7 @@ QRect Declaration::rectValue() const const QStringList func = v.variant.toStringList(); if (func.count() != 2 || func.at(0).compare(QLatin1String("rect")) != 0) return QRect(); - QStringList args = func[1].split(QLatin1Char(' '), QString::SkipEmptyParts); + const auto args = func[1].splitRef(QLatin1Char(' '), QString::SkipEmptyParts); if (args.count() != 4) return QRect(); QRect rect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt()); @@ -1915,9 +1915,8 @@ bool StyleSelector::basicSelectorMatches(const BasicSelector &sel, NodePtr node) return false; if (a.valueMatchCriterium == QCss::AttributeSelector::MatchContains) { - - QStringList lst = attrValue.split(QLatin1Char(' ')); - if (!lst.contains(a.value)) + const auto lst = attrValue.splitRef(QLatin1Char(' ')); + if (!lst.contains(QStringRef(&a.value))) return false; } else if ( (a.valueMatchCriterium == QCss::AttributeSelector::MatchEqual diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index f92e4ab457..828dbc318c 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -2033,7 +2033,7 @@ uint qHash(const QFont &font, uint seed) Q_DECL_NOTHROW */ bool QFont::fromString(const QString &descrip) { - QStringList l(descrip.split(QLatin1Char(','))); + const auto l = descrip.splitRef(QLatin1Char(',')); int count = l.count(); if (!count || (count > 2 && count < 9) || count > 11) { @@ -2042,7 +2042,7 @@ bool QFont::fromString(const QString &descrip) return false; } - setFamily(l[0]); + setFamily(l[0].toString()); if (count > 1 && l[1].toDouble() > 0.0) setPointSizeF(l[1].toDouble()); if (count == 9) { diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 359c461ad3..9b50581bea 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -697,15 +697,15 @@ static QStringList familyList(const QFontDef &req) if (req.family.isEmpty()) return family_list; - QStringList list = req.family.split(QLatin1Char(',')); + const auto list = req.family.splitRef(QLatin1Char(',')); const int numFamilies = list.size(); family_list.reserve(numFamilies); for (int i = 0; i < numFamilies; ++i) { - QString str = list.at(i).trimmed(); + QStringRef str = list.at(i).trimmed(); if ((str.startsWith(QLatin1Char('"')) && str.endsWith(QLatin1Char('"'))) || (str.startsWith(QLatin1Char('\'')) && str.endsWith(QLatin1Char('\'')))) str = str.mid(1, str.length() - 2); - family_list << str; + family_list << str.toString(); } // append the substitute list for each family in family_list -- cgit v1.2.3 From f046205526031fd42f4492ada28194cedcda1a4c Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Thu, 2 Jun 2016 12:14:44 +0300 Subject: QTextDocument: use QL1S::size() to get size of internal string ... instead of call of qstrlen(), because of ctor of QL1S already do this work for us. The old code is Qt4 legacy. Change-Id: I449ce7ea481af0efeade258d2cd5652db1f1a8b1 Reviewed-by: Edward Welbourne Reviewed-by: Konstantin Ritt --- src/gui/text/qtextdocument.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/gui/text') diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index febd5da488..bb4f031415 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2430,7 +2430,7 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) html += QLatin1Char(';'); attributesEmitted = true; } else { - html.chop(qstrlen(decorationTag.latin1())); + html.chop(decorationTag.size()); } if (format.foreground() != defaultCharFormat.foreground() @@ -2665,7 +2665,7 @@ void QTextHtmlExporter::emitFragment(const QTextFragment &fragment) if (attributesEmitted) html += QLatin1String("\">"); else - html.chop(qstrlen(styleTag.latin1())); + html.chop(styleTag.size()); if (isObject) { for (int i = 0; isImage && i < txt.length(); ++i) { @@ -3227,7 +3227,7 @@ void QTextHtmlExporter::emitFrameStyle(const QTextFrameFormat &format, FrameType QString::number(format.rightMargin())); if (html.length() == originalHtmlLength) // nothing emitted? - html.chop(qstrlen(styleAttribute.latin1())); + html.chop(styleAttribute.size()); else html += QLatin1Char('\"'); } -- cgit v1.2.3 From 84bd6a83a02f6357978dbf3e8b3a553a96d22772 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Thu, 2 Jun 2016 10:53:38 +0300 Subject: QTextDocument: use QString::replace() for replacing ... instead of homebrew algorithm. Saves some memory allocations and some text size. Change-Id: I3abb49d3b247dbb132688ea99e6eae731e31615c Reviewed-by: Edward Welbourne --- src/gui/text/qtextdocument.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/gui/text') diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index bb4f031415..723918ae69 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2700,13 +2700,8 @@ void QTextHtmlExporter::emitFragment(const QTextFragment &fragment) // split for [\n{LineSeparator}] QString forcedLineBreakRegExp = QString::fromLatin1("[\\na]"); forcedLineBreakRegExp[3] = QChar::LineSeparator; - - const QStringList lines = txt.split(QRegExp(forcedLineBreakRegExp)); - for (int i = 0; i < lines.count(); ++i) { - if (i > 0) - html += QLatin1String("
"); // space on purpose for compatibility with Netscape, Lynx & Co. - html += lines.at(i); - } + // space in BR on purpose for compatibility with old-fashioned browsers + html += txt.replace(QRegExp(forcedLineBreakRegExp), QLatin1String("
")); } if (attributesEmitted) -- cgit v1.2.3 From d5ac97e36fb35761576f25c84372d5c477189a0f Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 2 Jun 2016 11:22:32 +0200 Subject: Fix font-weight regression Do not override the requested font-weight. This was a wrong rewrite of a now redundant if-statement. Change-Id: I20a745cac02d896fdeaa853f20c6b6647084fceb Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/gui/text/qfontdatabase.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/gui/text') diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index c4b849878c..7b88a73c61 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -2730,7 +2730,6 @@ void QFontDatabase::load(const QFontPrivate *d, int script) } if (req.pointSize < 0) req.pointSize = req.pixelSize*72.0/d->dpi; - req.weight = QFont::Normal; if (req.stretch == 0) req.stretch = 100; -- cgit v1.2.3 From 0a78d918f0f411e0da2242a84a396f169154f5d6 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 5 Jun 2015 00:41:36 +0200 Subject: Replace qAllocMore with a pair of more useful functions The first is "exact", not "more": qCalculateBlockSize. It ensures that there's no overflow in multiplying, adding the header size or when converting back to an int. The second is the replacement for qAllocMore: it calculates the block size like the first, but increases the block size to accommodate future appends. The number of elements that fit in the block is also returned. Task-number: QTBUG-41230 Change-Id: I52dd43c12685407bb9a6ffff13f5da09f816e667 Reviewed-by: Lars Knoll --- src/gui/text/qfragmentmap_p.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/gui/text') diff --git a/src/gui/text/qfragmentmap_p.h b/src/gui/text/qfragmentmap_p.h index 4cf17aadc7..b54d7261d0 100644 --- a/src/gui/text/qfragmentmap_p.h +++ b/src/gui/text/qfragmentmap_p.h @@ -255,14 +255,11 @@ uint QFragmentMapData::createFragment() uint freePos = head->freelist; if (freePos == head->allocated) { // need to create some free space - if (freePos >= uint(MaxAllocSize) / fragmentSize) - qBadAlloc(); - uint needed = qAllocMore((freePos+1)*fragmentSize, 0); - Q_ASSERT(needed/fragmentSize > head->allocated); - Fragment *newFragments = (Fragment *)realloc(fragments, needed); + auto blockInfo = qCalculateGrowingBlockSize(freePos + 1, fragmentSize); + Fragment *newFragments = (Fragment *)realloc(fragments, blockInfo.size); Q_CHECK_PTR(newFragments); fragments = newFragments; - head->allocated = needed/fragmentSize; + head->allocated = quint32(blockInfo.elementCount); F(freePos).right = 0; } -- cgit v1.2.3