diff options
Diffstat (limited to 'src/gui/text')
-rw-r--r-- | src/gui/text/qcssparser.cpp | 50 | ||||
-rw-r--r-- | src/gui/text/qcssparser_p.h | 14 | ||||
-rw-r--r-- | src/gui/text/qfontdatabase.cpp | 31 | ||||
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 48 | ||||
-rw-r--r-- | src/gui/text/qtextdocument.h | 6 | ||||
-rw-r--r-- | src/gui/text/qtexthtmlparser.cpp | 55 |
6 files changed, 192 insertions, 12 deletions
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index 916e96ea63..7886d9ba91 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -36,6 +36,7 @@ struct QCssKnownValue quint64 id; }; +// This array is sorted alphabetically. static const QCssKnownValue properties[NumProperties - 1] = { { "-qt-background-role", QtBackgroundRole }, { "-qt-block-indent", QtBlockIndent }, @@ -47,6 +48,11 @@ static const QCssKnownValue properties[NumProperties - 1] = { { "-qt-list-number-suffix", QtListNumberSuffix }, { "-qt-paragraph-type", QtParagraphType }, { "-qt-stroke-color", QtStrokeColor }, + { "-qt-stroke-dasharray", QtStrokeDashArray }, + { "-qt-stroke-dashoffset", QtStrokeDashOffset }, + { "-qt-stroke-linecap", QtStrokeLineCap }, + { "-qt-stroke-linejoin", QtStrokeLineJoin }, + { "-qt-stroke-miterlimit", QtStrokeMiterLimit }, { "-qt-stroke-width", QtStrokeWidth }, { "-qt-style-features", QtStyleFeatures }, { "-qt-table-type", QtTableType }, @@ -160,6 +166,7 @@ static const QCssKnownValue values[NumKnownValues - 1] = { { "always", Value_Always }, { "auto", Value_Auto }, { "base", Value_Base }, + { "beveljoin", Value_BevelJoin}, { "bold", Value_Bold }, { "bottom", Value_Bottom }, { "bright-text", Value_BrightText }, @@ -176,6 +183,7 @@ static const QCssKnownValue values[NumKnownValues - 1] = { { "dot-dot-dash", Value_DotDotDash }, { "dotted", Value_Dotted }, { "double", Value_Double }, + { "flatcap", Value_FlatCap}, { "groove", Value_Groove }, { "highlight", Value_Highlight }, { "highlighted-text", Value_HighlightedText }, @@ -194,6 +202,7 @@ static const QCssKnownValue values[NumKnownValues - 1] = { { "mid", Value_Mid }, { "middle", Value_Middle }, { "midlight", Value_Midlight }, + { "miterjoin", Value_MiterJoin}, { "native", Value_Native }, { "none", Value_None }, { "normal", Value_Normal }, @@ -208,14 +217,18 @@ static const QCssKnownValue values[NumKnownValues - 1] = { { "pre-wrap", Value_PreWrap }, { "ridge", Value_Ridge }, { "right", Value_Right }, + { "roundcap", Value_RoundCap}, + { "roundjoin", Value_RoundJoin}, { "selected", Value_Selected }, { "shadow", Value_Shadow }, { "small" , Value_Small }, { "small-caps", Value_SmallCaps }, { "solid", Value_Solid }, { "square", Value_Square }, + { "squarecap", Value_SquareCap}, { "sub", Value_Sub }, { "super", Value_Super }, + { "svgmiterjoin", Value_SvgMiterJoin}, { "text", Value_Text }, { "top", Value_Top }, { "transparent", Value_Transparent }, @@ -231,10 +244,10 @@ static const QCssKnownValue values[NumKnownValues - 1] = { }; //Map id to strings as they appears in the 'values' array above -static const short indexOfId[NumKnownValues] = { 0, 41, 48, 42, 49, 50, 55, 35, 26, 71, 72, 25, 43, 5, 64, 48, - 29, 59, 60, 27, 52, 62, 6, 10, 39, 56, 19, 13, 17, 18, 20, 21, 51, 24, 46, 68, 37, 3, 2, 40, 63, 16, - 11, 58, 14, 32, 65, 33, 66, 56, 67, 34, 70, 8, 28, 38, 12, 36, 61, 7, 9, 4, 69, 54, 22, 23, 30, 31, - 1, 15, 0, 53, 45, 44 }; +static const short indexOfId[NumKnownValues] = { 0, 44, 51, 45, 52, 53, 60, 37, 28, 78, 79, 27, 46, 6, 71, 50, + 31, 65, 66, 29, 55, 69, 7, 11, 42, 62, 20, 14, 18, 19, 21, 23, 54, 26, 49, 75, 39, 3, 2, 43, 70, 17, 12, + 63, 15, 34, 72, 35, 73, 61, 74, 36, 64, 22, 56, 41, 5, 57, 67, 77, 9, 30, 40, 13, 38, 68, 8, 10, 4, 76, + 59, 24, 25, 32, 33, 1, 16, 0, 58, 48, 47 }; QString Value::toString() const { @@ -1835,6 +1848,35 @@ bool Declaration::borderCollapseValue() const return d->values.at(0).toString() == "collapse"_L1; } +QList<qreal> Declaration::dashArray() const +{ + if (d->propertyId != Property::QtStrokeDashArray || d->values.empty()) + return QList<qreal>(); + + bool isValid = true; + QList<qreal> dashes; + for (int i = 0; i < d->values.size(); i++) { + Value v = d->values[i]; + // Separators must be at odd indices and Numbers at even indices. + bool isValidSeparator = (i & 1) && v.type == Value::TermOperatorComma; + bool isValidNumber = !(i & 1) && v.type == Value::Number; + if (!isValidNumber && !isValidSeparator) { + isValid = false; + break; + } else if (isValidNumber) { + bool ok; + dashes.append(v.variant.toReal(&ok)); + if (!ok) { + isValid = false; + break; + } + } + } + + isValid &= !(dashes.size() & 1); + return isValid ? dashes : QList<qreal>(); +} + QIcon Declaration::iconValue() const { if (d->parsed.isValid()) diff --git a/src/gui/text/qcssparser_p.h b/src/gui/text/qcssparser_p.h index 7742271e41..ba4a611df3 100644 --- a/src/gui/text/qcssparser_p.h +++ b/src/gui/text/qcssparser_p.h @@ -169,6 +169,11 @@ enum Property { QtAccent, QtStrokeWidth, QtStrokeColor, + QtStrokeLineCap, + QtStrokeLineJoin, + QtStrokeMiterLimit, + QtStrokeDashArray, + QtStrokeDashOffset, QtForeground, NumProperties }; @@ -226,6 +231,13 @@ enum KnownValue { Value_SmallCaps, Value_Uppercase, Value_Lowercase, + Value_SquareCap, + Value_FlatCap, + Value_RoundCap, + Value_MiterJoin, + Value_BevelJoin, + Value_RoundJoin, + Value_SvgMiterJoin, /* keep these in same order as QPalette::ColorRole */ Value_FirstColorRole, @@ -451,6 +463,8 @@ struct Q_GUI_EXPORT Declaration void borderImageValue(QString *image, int *cuts, TileMode *h, TileMode *v) const; bool borderCollapseValue() const; + + QList<qreal> dashArray() const; }; QT_CSS_DECLARE_TYPEINFO(Declaration, Q_RELOCATABLE_TYPE) diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index d3a13d801b..3d6d3b7886 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -670,7 +670,7 @@ static QStringList fallbacksForFamily(const QString &family, QFont::Style style, return *fallbacks; // make sure that the db has all fallback families - QStringList userFallbacks = db->applicationFallbackFontFamilies.value(script == QChar::Script_Common ? QChar::Script_Latin : script); + QStringList userFallbacks = db->applicationFallbackFontFamilies.value(script == QChar::Script_Latin ? QChar::Script_Common : script); QStringList retList = userFallbacks + QGuiApplicationPrivate::platformIntegration()->fontDatabase()->fallbacksForFamily(family,style,styleHint,script); QStringList::iterator i; @@ -2187,6 +2187,8 @@ int QFontDatabasePrivate::addAppFont(const QByteArray &fontData, const QString & // loaded, so it has to be flushed. QFontCache::instance()->clear(); + fallbacksCache.clear(); + emit qApp->fontDatabaseChanged(); return i; @@ -2386,23 +2388,32 @@ bool QFontDatabase::removeAllApplicationFonts() be prioritized in reverse order, so that the last family added will be checked first and so on. + \note Qt's font matching algorithm considers \c{QChar::Script_Common} (undetermined script) + and \c{QChar::Script_Latin} the same. Adding a fallback for either of these will also apply + to the other. + \sa setApplicationFallbackFontFamilies(), removeApplicationFallbackFontFamily(), applicationFallbackFontFamilies() */ void QFontDatabase::addApplicationFallbackFontFamily(QChar::Script script, const QString &familyName) { QMutexLocker locker(fontDatabaseMutex()); - if (script < QChar::Script_Latin) { + if (script < QChar::Script_Common) { qCWarning(lcFontDb) << "Invalid script passed to addApplicationFallbackFontFamily:" << script; return; } + if (script == QChar::Script_Latin) + script = QChar::Script_Common; + auto *db = QFontDatabasePrivate::instance(); auto it = db->applicationFallbackFontFamilies.find(script); if (it == db->applicationFallbackFontFamilies.end()) it = db->applicationFallbackFontFamilies.insert(script, QStringList{}); it->prepend(familyName); + + QFontCache::instance()->clear(); db->fallbacksCache.clear(); } @@ -2420,6 +2431,14 @@ bool QFontDatabase::removeApplicationFallbackFontFamily(QChar::Script script, co { QMutexLocker locker(fontDatabaseMutex()); + if (script < QChar::Script_Common) { + qCWarning(lcFontDb) << "Invalid script passed to removeApplicationFallbackFontFamily:" << script; + return false; + } + + if (script == QChar::Script_Latin) + script = QChar::Script_Common; + auto *db = QFontDatabasePrivate::instance(); auto it = db->applicationFallbackFontFamilies.find(script); if (it != db->applicationFallbackFontFamilies.end()) { @@ -2452,11 +2471,14 @@ void QFontDatabase::setApplicationFallbackFontFamilies(QChar::Script script, con { QMutexLocker locker(fontDatabaseMutex()); - if (script < QChar::Script_Latin) { + if (script < QChar::Script_Common) { qCWarning(lcFontDb) << "Invalid script passed to setApplicationFallbackFontFamilies:" << script; return; } + if (script == QChar::Script_Latin) + script = QChar::Script_Common; + auto *db = QFontDatabasePrivate::instance(); db->applicationFallbackFontFamilies[script] = familyNames; @@ -2476,6 +2498,9 @@ QStringList QFontDatabase::applicationFallbackFontFamilies(QChar::Script script) { QMutexLocker locker(fontDatabaseMutex()); + if (script == QChar::Script_Latin) + script = QChar::Script_Common; + auto *db = QFontDatabasePrivate::instance(); return db->applicationFallbackFontFamilies.value(script); } diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index ab788a5f9b..c39d3514c5 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -53,6 +53,9 @@ namespace { QTextDocument::ResourceProvider qt_defaultResourceProvider; }; +QAbstractUndoItem::~QAbstractUndoItem() + = default; + /*! \fn bool Qt::mightBeRichText(QAnyStringView text) @@ -2757,6 +2760,51 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) html += " -qt-stroke-width:"_L1; html += QString::number(outlinePen.widthF()); html += "px;"_L1; + + html += " -qt-stroke-linecap:"_L1; + if (outlinePen.capStyle() == Qt::SquareCap) + html += "squarecap;"_L1; + else if (outlinePen.capStyle() == Qt::FlatCap) + html += "flatcap;"_L1; + else if (outlinePen.capStyle() == Qt::RoundCap) + html += "roundcap;"_L1; + + html += " -qt-stroke-linejoin:"_L1; + if (outlinePen.joinStyle() == Qt::MiterJoin) + html += "miterjoin;"_L1; + else if (outlinePen.joinStyle() == Qt::SvgMiterJoin) + html += "svgmiterjoin;"_L1; + else if (outlinePen.joinStyle() == Qt::BevelJoin) + html += "beveljoin;"_L1; + else if (outlinePen.joinStyle() == Qt::RoundJoin) + html += "roundjoin;"_L1; + + if (outlinePen.joinStyle() == Qt::MiterJoin || + outlinePen.joinStyle() == Qt::SvgMiterJoin) { + html += " -qt-stroke-miterlimit:"_L1; + html += QString::number(outlinePen.miterLimit()); + html += u';'; + } + + if (outlinePen.style() == Qt::CustomDashLine && !outlinePen.dashPattern().empty()) { + html += " -qt-stroke-dasharray:"_L1; + QString dashArrayString; + QList<qreal> dashes = outlinePen.dashPattern(); + + for (int i = 0; i < dashes.length() - 1; i++) { + qreal dash = dashes[i]; + dashArrayString += QString::number(dash) + u','; + } + + dashArrayString += QString::number(dashes.last()); + html += dashArrayString; + html += u';'; + + html += " -qt-stroke-dashoffset:"_L1; + html += QString::number(outlinePen.dashOffset()); + html += u';'; + } + attributesEmitted = true; } diff --git a/src/gui/text/qtextdocument.h b/src/gui/text/qtextdocument.h index b6253bfa46..11a8abcb50 100644 --- a/src/gui/text/qtextdocument.h +++ b/src/gui/text/qtextdocument.h @@ -45,15 +45,11 @@ namespace Qt class Q_GUI_EXPORT QAbstractUndoItem { public: - virtual ~QAbstractUndoItem() = 0; + virtual ~QAbstractUndoItem(); virtual void undo() = 0; virtual void redo() = 0; }; -inline QAbstractUndoItem::~QAbstractUndoItem() -{ -} - class QTextDocumentPrivate; class Q_GUI_EXPORT QTextDocument : public QObject diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index bc2200697d..54c291b82e 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -1422,6 +1422,61 @@ void QTextHtmlParserNode::applyCssDeclarations(const QList<QCss::Declaration> &d } break; } + case QCss::QtStrokeLineCap: + { + QPen pen = charFormat.textOutline(); + switch (identifier) { + case QCss::Value_SquareCap: pen.setCapStyle(Qt::SquareCap); break; + case QCss::Value_FlatCap: pen.setCapStyle(Qt::FlatCap); break; + case QCss::Value_RoundCap: pen.setCapStyle(Qt::RoundCap); break; + default: break; + } + charFormat.setTextOutline(pen); + break; + } + case QCss::QtStrokeLineJoin: + { + QPen pen = charFormat.textOutline(); + switch (identifier) { + case QCss::Value_MiterJoin: pen.setJoinStyle(Qt::MiterJoin); break; + case QCss::Value_BevelJoin: pen.setJoinStyle(Qt::BevelJoin); break; + case QCss::Value_RoundJoin: pen.setJoinStyle(Qt::RoundJoin); break; + case QCss::Value_SvgMiterJoin: pen.setJoinStyle(Qt::SvgMiterJoin); break; + default: break; + } + charFormat.setTextOutline(pen); + break; + } + case QCss::QtStrokeMiterLimit: + { + qreal miterLimit; + if (decl.realValue(&miterLimit)) { + QPen pen = charFormat.textOutline(); + pen.setMiterLimit(miterLimit); + charFormat.setTextOutline(pen); + } + break; + } + case QCss::QtStrokeDashArray: + { + QList<qreal> dashes = decl.dashArray(); + if (!dashes.empty()) { + QPen pen = charFormat.textOutline(); + pen.setDashPattern(dashes); + charFormat.setTextOutline(pen); + } + break; + } + case QCss::QtStrokeDashOffset: + { + qreal dashOffset; + if (decl.realValue(&dashOffset)) { + QPen pen = charFormat.textOutline(); + pen.setDashOffset(dashOffset); + charFormat.setTextOutline(pen); + } + break; + } case QCss::QtForeground: { QBrush brush = decl.brushValue(); |