diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-04-11 15:54:50 +0200 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2022-04-28 05:58:52 +0200 |
commit | 7b6b133746aa8bf23e08753851d7e23cc9d76170 (patch) | |
tree | 472044ff758e685d88618996fbccc76bbfe930b6 /src/gui/text | |
parent | 852bb436057be518f864fb57fc1efc9d6a95f8c1 (diff) |
QtGui: use _L1 for for creating Latin-1 string literals
Task-number: QTBUG-98434
Change-Id: Idcb71c1d27125333a53b6bdd3e1af0d4c66617fa
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/gui/text')
-rw-r--r-- | src/gui/text/coretext/qcoretextfontdatabase.mm | 6 | ||||
-rw-r--r-- | src/gui/text/freetype/qfontengine_ft.cpp | 6 | ||||
-rw-r--r-- | src/gui/text/freetype/qfreetypefontdatabase.cpp | 12 | ||||
-rw-r--r-- | src/gui/text/qcssparser.cpp | 57 | ||||
-rw-r--r-- | src/gui/text/qdistancefield.cpp | 4 | ||||
-rw-r--r-- | src/gui/text/qfontdatabase.cpp | 49 | ||||
-rw-r--r-- | src/gui/text/qfontsubset.cpp | 8 | ||||
-rw-r--r-- | src/gui/text/qplatformfontdatabase.cpp | 6 | ||||
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 420 | ||||
-rw-r--r-- | src/gui/text/qtextdocumentfragment.cpp | 8 | ||||
-rw-r--r-- | src/gui/text/qtexthtmlparser.cpp | 189 | ||||
-rw-r--r-- | src/gui/text/qtextimagehandler.cpp | 12 | ||||
-rw-r--r-- | src/gui/text/qtextlist.cpp | 6 | ||||
-rw-r--r-- | src/gui/text/qtextmarkdownimporter.cpp | 8 | ||||
-rw-r--r-- | src/gui/text/qtextmarkdownwriter.cpp | 14 | ||||
-rw-r--r-- | src/gui/text/qtextodfwriter.cpp | 36 | ||||
-rw-r--r-- | src/gui/text/qtexttable.cpp | 4 | ||||
-rw-r--r-- | src/gui/text/windows/qwindowsfontdatabase.cpp | 8 | ||||
-rw-r--r-- | src/gui/text/windows/qwindowsfontdatabase_ft.cpp | 13 | ||||
-rw-r--r-- | src/gui/text/windows/qwindowsfontdatabasebase.cpp | 4 |
20 files changed, 450 insertions, 420 deletions
diff --git a/src/gui/text/coretext/qcoretextfontdatabase.mm b/src/gui/text/coretext/qcoretextfontdatabase.mm index a47f7a64f5..bdcd5d62b8 100644 --- a/src/gui/text/coretext/qcoretextfontdatabase.mm +++ b/src/gui/text/coretext/qcoretextfontdatabase.mm @@ -64,6 +64,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + QT_IMPL_METATYPE_EXTERN_TAGGED(QCFType<CGFontRef>, QCFType_CGFontRef) QT_IMPL_METATYPE_EXTERN_TAGGED(QCFType<CFURLRef>, QCFType_CFURLRef) @@ -537,7 +539,7 @@ QStringList QCoreTextFontDatabase::fallbacksForFamily(const QString &family, QFo Q_UNUSED(style); qCDebug(lcQpaFonts).nospace() << "Resolving fallbacks families for" - << (!family.isEmpty() ? qPrintable(QLatin1String(" family '%1' with").arg(family)) : "") + << (!family.isEmpty() ? qPrintable(" family '%1' with"_L1.arg(family)) : "") << " style hint " << styleHint; QMacAutoReleasePool pool; @@ -653,7 +655,7 @@ QStringList QCoreTextFontDatabase::addApplicationFont(const QByteArray &fontData bool QCoreTextFontDatabase::isPrivateFontFamily(const QString &family) const { - if (family.startsWith(u'.') || family == QLatin1String("LastResort")) + if (family.startsWith(u'.') || family == "LastResort"_L1) return true; return QPlatformFontDatabase::isPrivateFontFamily(family); diff --git a/src/gui/text/freetype/qfontengine_ft.cpp b/src/gui/text/freetype/qfontengine_ft.cpp index b4f29cc269..fa6d273c6c 100644 --- a/src/gui/text/freetype/qfontengine_ft.cpp +++ b/src/gui/text/freetype/qfontengine_ft.cpp @@ -89,6 +89,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #define FLOOR(x) ((x) & -64) #define CEIL(x) (((x)+63) & -64) #define TRUNC(x) ((x) >> 6) @@ -804,7 +806,7 @@ bool QFontEngineFT::init(FaceId faceId, bool antialias, GlyphFormat format, PS_FontInfoRec psrec; // don't assume that type1 fonts are symbol fonts by default if (FT_Get_PS_Font_Info(freetype->face, &psrec) == FT_Err_Ok) { - symbol = !fontDef.families.isEmpty() && bool(fontDef.families.first().contains(QLatin1String("symbol"), Qt::CaseInsensitive)); + symbol = !fontDef.families.isEmpty() && bool(fontDef.families.first().contains("symbol"_L1, Qt::CaseInsensitive)); } freetype->computeSize(fontDef, &xsize, &ysize, &defaultGlyphSet.outline_drawing, &scalableBitmapScaleFactor); @@ -867,7 +869,7 @@ bool QFontEngineFT::init(FaceId faceId, bool antialias, GlyphFormat format, metrics.ascender = face->size->metrics.ascender; metrics.descender = face->size->metrics.descender; if (metrics.descender > 0 - && QString::fromUtf8(face->family_name) == QLatin1String("Courier New")) { + && QString::fromUtf8(face->family_name) == "Courier New"_L1) { metrics.descender *= -1; } metrics.height = metrics.ascender - metrics.descender + leading; diff --git a/src/gui/text/freetype/qfreetypefontdatabase.cpp b/src/gui/text/freetype/qfreetypefontdatabase.cpp index 21be28dba4..750707ad0a 100644 --- a/src/gui/text/freetype/qfreetypefontdatabase.cpp +++ b/src/gui/text/freetype/qfreetypefontdatabase.cpp @@ -56,6 +56,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + void QFreeTypeFontDatabase::populateFontDatabase() { QString fontpath = fontDir(); @@ -69,11 +71,11 @@ void QFreeTypeFontDatabase::populateFontDatabase() } QStringList nameFilters; - nameFilters << QLatin1String("*.ttf") - << QLatin1String("*.ttc") - << QLatin1String("*.pfa") - << QLatin1String("*.pfb") - << QLatin1String("*.otf"); + nameFilters << "*.ttf"_L1 + << "*.ttc"_L1 + << "*.pfa"_L1 + << "*.pfb"_L1 + << "*.otf"_L1; const auto fis = dir.entryInfoList(nameFilters, QDir::Files); for (const QFileInfo &fi : fis) { diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index e762697b56..57b20c403e 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -55,6 +55,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + QT_IMPL_METATYPE_EXTERN_TAGGED(QCss::BackgroundData, QCss__BackgroundData) QT_IMPL_METATYPE_EXTERN_TAGGED(QCss::LengthData, QCss__LengthData) QT_IMPL_METATYPE_EXTERN_TAGGED(QCss::BorderData, QCss__BorderData) @@ -734,7 +736,7 @@ static ColorData parseColorValue(QCss::Value v) return ColorData(); const QString &identifier = lst.at(0); - if ((identifier.compare(QLatin1String("palette"), Qt::CaseInsensitive)) == 0) { + if ((identifier.compare("palette"_L1, Qt::CaseInsensitive)) == 0) { int role = findKnownValue(lst.at(1).trimmed(), values, NumKnownValues); if (role >= Value_FirstColorRole && role <= Value_LastColorRole) return (QPalette::ColorRole)(role-Value_FirstColorRole); @@ -742,9 +744,9 @@ static ColorData parseColorValue(QCss::Value v) return ColorData(); } - const bool rgb = identifier.startsWith(QLatin1String("rgb")); - const bool hsv = !rgb && identifier.startsWith(QLatin1String("hsv")); - const bool hsl = !rgb && !hsv && identifier.startsWith(QLatin1String("hsl")); + const bool rgb = identifier.startsWith("rgb"_L1); + const bool hsv = !rgb && identifier.startsWith("hsv"_L1); + const bool hsl = !rgb && !hsv && identifier.startsWith("hsl"_L1); if (!rgb && !hsv && !hsl) return ColorData(); @@ -831,7 +833,7 @@ static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal) return BrushData(); QStringList gradFuncs; - gradFuncs << QLatin1String("qlineargradient") << QLatin1String("qradialgradient") << QLatin1String("qconicalgradient") << QLatin1String("qgradient"); + gradFuncs << "qlineargradient"_L1 << "qradialgradient"_L1 << "qconicalgradient"_L1 << "qgradient"_L1; int gradType = -1; if ((gradType = gradFuncs.indexOf(lst.at(0).toLower())) == -1) @@ -842,7 +844,7 @@ static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal) int spread = -1; QStringList spreads; - spreads << QLatin1String("pad") << QLatin1String("reflect") << QLatin1String("repeat"); + spreads << "pad"_L1 << "reflect"_L1 << "repeat"_L1; bool dependsOnThePalette = false; Parser parser(lst.at(1)); @@ -855,7 +857,7 @@ static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal) if (!parser.test(COLON)) return BrushData(); parser.skipSpace(); - if (attr.compare(QLatin1String("stop"), Qt::CaseInsensitive) == 0) { + if (attr.compare("stop"_L1, Qt::CaseInsensitive) == 0) { QCss::Value stop, color; parser.next(); if (!parser.parseTerm(&stop)) return BrushData(); @@ -870,7 +872,7 @@ static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal) parser.next(); QCss::Value value; (void)parser.parseTerm(&value); - if (attr.compare(QLatin1String("spread"), Qt::CaseInsensitive) == 0) { + if (attr.compare("spread"_L1, Qt::CaseInsensitive) == 0) { spread = spreads.indexOf(value.variant.toString()); } else { vars[attr] = value.variant.toReal(); @@ -881,8 +883,8 @@ static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal) } if (gradType == 0) { - QLinearGradient lg(vars.value(QLatin1String("x1")), vars.value(QLatin1String("y1")), - vars.value(QLatin1String("x2")), vars.value(QLatin1String("y2"))); + QLinearGradient lg(vars.value("x1"_L1), vars.value("y1"_L1), + vars.value("x2"_L1), vars.value("y2"_L1)); lg.setCoordinateMode(QGradient::ObjectBoundingMode); lg.setStops(stops); if (spread != -1) @@ -894,9 +896,9 @@ static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal) } if (gradType == 1) { - QRadialGradient rg(vars.value(QLatin1String("cx")), vars.value(QLatin1String("cy")), - vars.value(QLatin1String("radius")), vars.value(QLatin1String("fx")), - vars.value(QLatin1String("fy"))); + QRadialGradient rg(vars.value("cx"_L1), vars.value("cy"_L1), + vars.value("radius"_L1), vars.value("fx"_L1), + vars.value("fy"_L1)); rg.setCoordinateMode(QGradient::ObjectBoundingMode); rg.setStops(stops); if (spread != -1) @@ -908,8 +910,7 @@ static BrushData parseBrushValue(const QCss::Value &v, const QPalette &pal) } if (gradType == 2) { - QConicalGradient cg(vars.value(QLatin1String("cx")), vars.value(QLatin1String("cy")), - vars.value(QLatin1String("angle"))); + QConicalGradient cg(vars.value("cx"_L1), vars.value("cy"_L1), vars.value("angle"_L1)); cg.setCoordinateMode(QGradient::ObjectBoundingMode); cg.setStops(stops); if (spread != -1) @@ -1145,14 +1146,14 @@ static bool setFontSizeFromValue(QCss::Value value, QFont *font, int *fontSizeAd bool valid = false; QString s = value.variant.toString(); - if (s.endsWith(QLatin1String("pt"), Qt::CaseInsensitive)) { + if (s.endsWith("pt"_L1, Qt::CaseInsensitive)) { s.chop(2); value.variant = s; if (value.variant.convert(QMetaType::fromType<qreal>())) { font->setPointSizeF(qBound(qreal(0), value.variant.toReal(), qreal(1 << 24) - 1)); valid = true; } - } else if (s.endsWith(QLatin1String("px"), Qt::CaseInsensitive)) { + } else if (s.endsWith("px"_L1, Qt::CaseInsensitive)) { s.chop(2); value.variant = s; if (value.variant.convert(QMetaType::fromType<int>())) { @@ -1264,12 +1265,12 @@ static void setLetterSpacingFromValue(const QCss::Value &value, QFont *font) QString s = value.variant.toString(); qreal val; bool ok = false; - if (s.endsWith(QLatin1String("em"), Qt::CaseInsensitive)) { + if (s.endsWith("em"_L1, Qt::CaseInsensitive)) { s.chop(2); val = s.toDouble(&ok); if (ok) font->setLetterSpacing(QFont::PercentageSpacing, (val + 1.0) * 100); - } else if (s.endsWith(QLatin1String("px"), Qt::CaseInsensitive)) { + } else if (s.endsWith("px"_L1, Qt::CaseInsensitive)) { s.chop(2); val = s.toDouble(&ok); if (ok) @@ -1280,7 +1281,7 @@ static void setLetterSpacingFromValue(const QCss::Value &value, QFont *font) static void setWordSpacingFromValue(const QCss::Value &value, QFont *font) { QString s = value.variant.toString(); - if (s.endsWith(QLatin1String("px"), Qt::CaseInsensitive)) { + if (s.endsWith("px"_L1, Qt::CaseInsensitive)) { s.chop(2); qreal val; bool ok = false; @@ -1650,7 +1651,7 @@ QRect Declaration::rectValue() const if (v.type != Value::Function) return QRect(); const QStringList func = v.variant.toStringList(); - if (func.count() != 2 || func.at(0).compare(QLatin1String("rect")) != 0) + if (func.count() != 2 || func.at(0).compare("rect"_L1) != 0) return QRect(); const auto args = QStringView{func[1]}.split(u' ', Qt::SkipEmptyParts); if (args.count() != 4) @@ -1835,7 +1836,7 @@ bool Declaration::borderCollapseValue() const if (d->values.count() != 1) return false; else - return d->values.at(0).toString() == QLatin1String("collapse"); + return d->values.at(0).toString() == "collapse"_L1; } QIcon Declaration::iconValue() const @@ -1993,7 +1994,7 @@ bool StyleSelector::nodeNameEquals(NodePtr node, const QString& nodeName) const QStringList StyleSelector::nodeIds(NodePtr node) const { - return QStringList(attributeValue(node, QCss::AttributeSelector{QLatin1String("id"), {}, AttributeSelector::NoMatch})); + return QStringList(attributeValue(node, QCss::AttributeSelector{"id"_L1, {}, AttributeSelector::NoMatch})); } bool StyleSelector::selectorMatches(const Selector &selector, NodePtr node) @@ -2357,7 +2358,7 @@ void Parser::init(const QString &css, bool isFile) bool Parser::parse(StyleSheet *styleSheet, Qt::CaseSensitivity nameCaseSensitivity) { - if (testTokenAndEndsWith(ATKEYWORD_SYM, QLatin1String("charset"))) { + if (testTokenAndEndsWith(ATKEYWORD_SYM, "charset"_L1)) { while (test(S) || test(CDO) || test(CDC)) {} if (!next(STRING)) return false; if (!next(SEMICOLON)) return false; @@ -2621,7 +2622,7 @@ bool Parser::parseSimpleSelector(BasicSelector *basicSel) } else if (testClass()) { onceMore = true; AttributeSelector a; - a.name = QLatin1String("class"); + a.name = "class"_L1; a.valueMatchCriterium = AttributeSelector::MatchIncludes; if (!parseClass(&a.value)) return false; basicSel->attributeSelectors.append(a); @@ -2732,7 +2733,7 @@ bool Parser::testPrio() index = rewind; return false; } - if (lexem().compare(QLatin1String("important"), Qt::CaseInsensitive) != 0) { + if (lexem().compare("important"_L1, Qt::CaseInsensitive) != 0) { index = rewind; return false; } @@ -2835,7 +2836,7 @@ bool Parser::parseTerm(Value *value) } else if (testFunction()) { QString name, args; if (!parseFunction(&name, &args)) return false; - if (name == QLatin1String("url")) { + if (name == "url"_L1) { value->type = Value::Uri; removeOptionalQuotes(&args); if (QFileInfo(args).isRelative() && !sourcePath.isEmpty()) { @@ -2896,7 +2897,7 @@ bool Parser::testAndParseUri(QString *uri) index = rewind; return false; } - if (name.compare(QLatin1String("url"), Qt::CaseInsensitive) != 0) { + if (name.compare("url"_L1, Qt::CaseInsensitive) != 0) { index = rewind; return false; } diff --git a/src/gui/text/qdistancefield.cpp b/src/gui/text/qdistancefield.cpp index a3fdfd63d1..cef65d4ef3 100644 --- a/src/gui/text/qdistancefield.cpp +++ b/src/gui/text/qdistancefield.cpp @@ -45,6 +45,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + Q_LOGGING_CATEGORY(lcDistanceField, "qt.distanceField"); namespace @@ -796,7 +798,7 @@ bool qt_fontHasNarrowOutlines(const QRawFont &f) if (!font.isValid()) return false; - QList<quint32> glyphIndices = font.glyphIndexesForString(QLatin1String("O")); + QList<quint32> glyphIndices = font.glyphIndexesForString("O"_L1); if (glyphIndices.isEmpty() || glyphIndices[0] == 0) return false; diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index 00e4567472..c3188b5ef9 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -68,6 +68,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + Q_LOGGING_CATEGORY(lcFontDb, "qt.text.font.db") Q_LOGGING_CATEGORY(lcFontMatch, "qt.text.font.match") @@ -94,41 +96,40 @@ static int getFontWeight(const QString &weightString) // // A simple string test is the cheapest, so let's do that first. // Test in decreasing order of commonness - if (s == QLatin1String("normal") || s == QLatin1String("regular")) + if (s == "normal"_L1 || s == "regular"_L1) return QFont::Normal; - if (s == QLatin1String("bold")) + if (s == "bold"_L1) return QFont::Bold; - if (s == QLatin1String("semibold") || s == QLatin1String("semi bold") - || s == QLatin1String("demibold") || s == QLatin1String("demi bold")) + if (s == "semibold"_L1 || s == "semi bold"_L1 || s == "demibold"_L1 || s == "demi bold"_L1) return QFont::DemiBold; - if (s == QLatin1String("medium")) + if (s == "medium"_L1) return QFont::Medium; - if (s == QLatin1String("black")) + if (s == "black"_L1) return QFont::Black; - if (s == QLatin1String("light")) + if (s == "light"_L1) return QFont::Light; - if (s == QLatin1String("thin")) + if (s == "thin"_L1) return QFont::Thin; const QStringView s2 = QStringView{s}.mid(2); - if (s.startsWith(QLatin1String("ex")) || s.startsWith(QLatin1String("ul"))) { - if (s2 == QLatin1String("tralight") || s == QLatin1String("tra light")) + if (s.startsWith("ex"_L1) || s.startsWith("ul"_L1)) { + if (s2 == "tralight"_L1 || s == "tra light"_L1) return QFont::ExtraLight; - if (s2 == QLatin1String("trabold") || s2 == QLatin1String("tra bold")) + if (s2 == "trabold"_L1 || s2 == "tra bold"_L1) return QFont::ExtraBold; } // Next up, let's see if contains() matches: slightly more expensive, but // still fast enough. - if (s.contains(QLatin1String("bold"))) { - if (s.contains(QLatin1String("demi"))) + if (s.contains("bold"_L1)) { + if (s.contains("demi"_L1)) return QFont::DemiBold; return QFont::Bold; } - if (s.contains(QLatin1String("thin"))) + if (s.contains("thin"_L1)) return QFont::Thin; - if (s.contains(QLatin1String("light"))) + if (s.contains("light"_L1)) return QFont::Light; - if (s.contains(QLatin1String("black"))) + if (s.contains("black"_L1)) return QFont::Black; // Now, we perform string translations & comparisons with those. @@ -185,9 +186,9 @@ QtFontStyle::Key::Key(const QString &styleString) if (!styleString.isEmpty()) { // First the straightforward no-translation checks, these are fast. - if (styleString.contains(QLatin1String("Italic"))) + if (styleString.contains("Italic"_L1)) style = QFont::StyleItalic; - else if (styleString.contains(QLatin1String("Oblique"))) + else if (styleString.contains("Oblique"_L1)) style = QFont::StyleOblique; // Then the translation checks. These aren't as fast. @@ -502,7 +503,7 @@ static void initFontDef(const QtFontDesc &desc, const QFontDef &request, QFontDe QString family; family = desc.family->name; if (! desc.foundry->name.isEmpty() && desc.family->count > 1) - family += QLatin1String(" [") + desc.foundry->name + u']'; + family += " ["_L1 + desc.foundry->name + u']'; fontDef->families = QStringList(family); if (desc.style->smoothScalable @@ -669,7 +670,7 @@ QStringList QPlatformFontDatabase::fallbacksForFamily(const QString &family, QFo for (int k = 0; k < foundry->count; ++k) { QString name = foundry->name.isEmpty() ? f->name - : f->name + QLatin1String(" [") + foundry->name + u']'; + : f->name + " ["_L1 + foundry->name + u']'; if (style == foundry->styles[k]->key.style) preferredFallbacks.append(name); else @@ -1469,7 +1470,7 @@ QStringList QFontDatabase::families(WritingSystem writingSystem) QString str = f->name; QString foundry = f->foundries[j]->name; if (!foundry.isEmpty()) { - str += QLatin1String(" ["); + str += " ["_L1; str += foundry; str += u']'; } @@ -2179,7 +2180,7 @@ int QFontDatabasePrivate::addAppFont(const QByteArray &fontData, const QString & } if (font.fileName.isEmpty() && !fontData.isEmpty()) - font.fileName = QLatin1String(":qmemoryfonts/") + QString::number(i); + font.fileName = ":qmemoryfonts/"_L1 + QString::number(i); auto *platformFontDatabase = QGuiApplicationPrivate::platformIntegration()->fontDatabase(); platformFontDatabase->addApplicationFont(font.data, font.fileName, &font); @@ -2387,7 +2388,7 @@ QFontEngine *QFontDatabasePrivate::findFont(const QFontDef &req, #if defined(QT_BUILD_INTERNAL) // For testing purpose only, emulates an exact-matching monospace font - if (qt_enable_test_font && request.families.first() == QLatin1String("__Qt__Box__Engine__")) { + if (qt_enable_test_font && request.families.first() == "__Qt__Box__Engine__"_L1) { engine = new QTestFontEngine(request.pixelSize); engine->fontDef = request; return engine; @@ -2471,7 +2472,7 @@ QFontEngine *QFontDatabasePrivate::findFont(const QFontDef &req, if (!engine) { QtFontDesc desc; do { - index = match(multi ? QChar::Script_Common : script, def, def.families.first(), QLatin1String(""), &desc, blackListed); + index = match(multi ? QChar::Script_Common : script, def, def.families.first(), ""_L1, &desc, blackListed); if (index >= 0) { QFontDef loadDef = def; if (loadDef.families.isEmpty()) diff --git a/src/gui/text/qfontsubset.cpp b/src/gui/text/qfontsubset.cpp index 8417dfa7fd..91775ef987 100644 --- a/src/gui/text/qfontsubset.cpp +++ b/src/gui/text/qfontsubset.cpp @@ -49,6 +49,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #ifndef QT_NO_PDF // This map is used for symbol fonts to get the correct glyph names for the latin range @@ -639,7 +641,7 @@ static QTtfTable generateName(const qttf_name_table &name) list.append(rec); rec.nameId = 4; rec.value = name.family; - if (name.subfamily != QLatin1String("Regular")) + if (name.subfamily != "Regular"_L1) rec.value += u' ' + name.subfamily; list.append(rec); rec.nameId = 6; @@ -1244,11 +1246,11 @@ QByteArray QFontSubset::toTruetype() const if (name_table.data.isEmpty()) { qttf_name_table name; if (noEmbed) - name.copyright = QLatin1String("Fake font"); + name.copyright = "Fake font"_L1; else name.copyright = QLatin1String(properties.copyright); name.family = fontEngine->fontDef.families.first(); - name.subfamily = QLatin1String("Regular"); // ###### + name.subfamily = "Regular"_L1; // ###### name.postscript_name = QLatin1String(properties.postscriptName); name_table = generateName(name); } diff --git a/src/gui/text/qplatformfontdatabase.cpp b/src/gui/text/qplatformfontdatabase.cpp index ff678da322..adb3c859e1 100644 --- a/src/gui/text/qplatformfontdatabase.cpp +++ b/src/gui/text/qplatformfontdatabase.cpp @@ -53,6 +53,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + Q_LOGGING_CATEGORY(lcQpaFonts, "qt.qpa.fonts") void qt_registerFont(const QString &familyname, const QString &stylename, @@ -357,7 +359,7 @@ QString QPlatformFontDatabase::fontDir() const { QString fontpath = QString::fromLocal8Bit(qgetenv("QT_QPA_FONTDIR")); if (fontpath.isEmpty()) - fontpath = QLibraryInfo::path(QLibraryInfo::LibrariesPath) + QLatin1String("/fonts"); + fontpath = QLibraryInfo::path(QLibraryInfo::LibrariesPath) + "/fonts"_L1; return fontpath; } @@ -381,7 +383,7 @@ bool QPlatformFontDatabase::isPrivateFontFamily(const QString &family) const QFont QPlatformFontDatabase::defaultFont() const { - return QFont(QLatin1String("Helvetica")); + return QFont("Helvetica"_L1); } diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 403184c8c1..71568e5ba6 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -78,6 +78,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + Q_CORE_EXPORT Q_DECL_CONST_FUNCTION unsigned int qt_int_sqrt(unsigned int n); namespace { @@ -105,7 +107,7 @@ bool Qt::mightBeRichText(const QString& text) ++start; // skip a leading <?xml ... ?> as for example with xhtml - if (QStringView{text}.mid(start, 5).compare(QLatin1String("<?xml")) == 0) { + if (QStringView{text}.mid(start, 5).compare("<?xml"_L1) == 0) { while (start < text.length()) { if (text.at(start) == u'?' && start + 2 < text.length() @@ -120,12 +122,12 @@ bool Qt::mightBeRichText(const QString& text) ++start; } - if (QStringView{text}.mid(start, 5).compare(QLatin1String("<!doc"), Qt::CaseInsensitive) == 0) + if (QStringView{text}.mid(start, 5).compare("<!doc"_L1, Qt::CaseInsensitive) == 0) return true; int open = start; while (open < text.length() && text.at(open) != u'<' && text.at(open) != u'\n') { - if (text.at(open) == u'&' && QStringView{text}.mid(open + 1, 3) == QLatin1String("lt;")) + if (text.at(open) == u'&' && QStringView{text}.mid(open + 1, 3) == "lt;"_L1) return true; // support desperate attempt of user to see <...> ++open; } @@ -167,7 +169,7 @@ QString Qt::convertFromPlainText(const QString &plain, Qt::WhiteSpaceMode mode) { int col = 0; QString rich; - rich += QLatin1String("<p>"); + rich += "<p>"_L1; for (int i = 0; i < plain.length(); ++i) { if (plain[i] == u'\n'){ int c = 1; @@ -176,12 +178,12 @@ QString Qt::convertFromPlainText(const QString &plain, Qt::WhiteSpaceMode mode) c++; } if (c == 1) - rich += QLatin1String("<br>\n"); + rich += "<br>\n"_L1; else { - rich += QLatin1String("</p>\n"); + rich += "</p>\n"_L1; while (--c > 1) - rich += QLatin1String("<br>\n"); - rich += QLatin1String("<p>"); + rich += "<br>\n"_L1; + rich += "<p>"_L1; } col = 0; } else { @@ -196,18 +198,18 @@ QString Qt::convertFromPlainText(const QString &plain, Qt::WhiteSpaceMode mode) else if (mode == Qt::WhiteSpacePre && plain[i].isSpace()) rich += QChar::Nbsp; else if (plain[i] == u'<') - rich += QLatin1String("<"); + rich += "<"_L1; else if (plain[i] == u'>') - rich += QLatin1String(">"); + rich += ">"_L1; else if (plain[i] == u'&') - rich += QLatin1String("&"); + rich += "&"_L1; else rich += plain[i]; ++col; } } if (col != 0) - rich += QLatin1String("</p>"); + rich += "</p>"_L1; return rich; } @@ -2240,7 +2242,7 @@ QVariant QTextDocument::loadResource(int type, const QUrl &name) } // handle data: URLs - if (r.isNull() && name.scheme().compare(QLatin1String("data"), Qt::CaseInsensitive) == 0) { + if (r.isNull() && name.scheme().compare("data"_L1, Qt::CaseInsensitive) == 0) { QString mimetype; QByteArray payload; if (qDecodeDataUrl(name, mimetype, payload)) @@ -2256,7 +2258,7 @@ QVariant QTextDocument::loadResource(int type, const QUrl &name) // For the second case QUrl can merge "#someanchor" with "foo.html" // correctly to "foo.html#someanchor" if (!(currentURL.isRelative() - || (currentURL.scheme() == QLatin1String("file") + || (currentURL.scheme() == "file"_L1 && !QFileInfo(currentURL.toLocalFile()).isAbsolute())) || (name.hasFragment() && name.path().isEmpty())) { resourceUrl = currentURL.resolved(name); @@ -2269,7 +2271,7 @@ QVariant QTextDocument::loadResource(int type, const QUrl &name) resourceUrl = QUrl::fromLocalFile(fi.absolutePath() + QDir::separator()).resolved(name); } else if (currentURL.isEmpty()) { - resourceUrl.setScheme(QLatin1String("file")); + resourceUrl.setScheme("file"_L1); } } } @@ -2332,7 +2334,7 @@ static QString colorValue(QColor color) .arg(color.blue()) .arg(alphaValue); } else { - result = QLatin1String("transparent"); + result = "transparent"_L1; } return result; @@ -2357,9 +2359,9 @@ static QStringList resolvedFontFamilies(const QTextCharFormat &format) */ QString QTextHtmlExporter::toHtml(ExportMode mode) { - html = QLatin1String("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" " - "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" - "<html><head><meta name=\"qrichtext\" content=\"1\" />"); + html = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" " + "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" + "<html><head><meta name=\"qrichtext\" content=\"1\" />"_L1; html.reserve(QTextDocumentPrivate::get(doc)->length()); fragmentMarkers = (mode == ExportFragment); @@ -2369,70 +2371,70 @@ QString QTextHtmlExporter::toHtml(ExportMode mode) QString title = doc->metaInformation(QTextDocument::DocumentTitle); if (!title.isEmpty()) html += QString::fromLatin1("<title>") + title + QString::fromLatin1("</title>"); - html += QLatin1String("<style type=\"text/css\">\n"); - html += QLatin1String("p, li { white-space: pre-wrap; }\n"); - html += QLatin1String("hr { height: 1px; border-width: 0; }\n"); - html += QLatin1String("</style>"); - html += QLatin1String("</head><body"); + html += "<style type=\"text/css\">\n"_L1; + html += "p, li { white-space: pre-wrap; }\n"_L1; + html += "hr { height: 1px; border-width: 0; }\n"_L1; + html += "</style>"_L1; + html += "</head><body"_L1; if (mode == ExportEntireDocument) { - html += QLatin1String(" style=\""); + html += " style=\""_L1; emitFontFamily(resolvedFontFamilies(defaultCharFormat)); if (defaultCharFormat.hasProperty(QTextFormat::FontPointSize)) { - html += QLatin1String(" font-size:"); + html += " font-size:"_L1; html += QString::number(defaultCharFormat.fontPointSize()); - html += QLatin1String("pt;"); + html += "pt;"_L1; } else if (defaultCharFormat.hasProperty(QTextFormat::FontPixelSize)) { - html += QLatin1String(" font-size:"); + html += " font-size:"_L1; html += QString::number(defaultCharFormat.intProperty(QTextFormat::FontPixelSize)); - html += QLatin1String("px;"); + html += "px;"_L1; } - html += QLatin1String(" font-weight:"); + html += " font-weight:"_L1; html += QString::number(defaultCharFormat.fontWeight()); html += u';'; - html += QLatin1String(" font-style:"); - html += (defaultCharFormat.fontItalic() ? QLatin1String("italic") : QLatin1String("normal")); + html += " font-style:"_L1; + html += (defaultCharFormat.fontItalic() ? "italic"_L1 : "normal"_L1); html += u';'; const bool percentSpacing = (defaultCharFormat.fontLetterSpacingType() == QFont::PercentageSpacing); if (defaultCharFormat.hasProperty(QTextFormat::FontLetterSpacing) && (!percentSpacing || defaultCharFormat.fontLetterSpacing() != 0.0)) { - html += QLatin1String(" letter-spacing:"); + html += " letter-spacing:"_L1; qreal value = defaultCharFormat.fontLetterSpacing(); if (percentSpacing) // Map to em (100% == 0em) value = (value / 100) - 1; html += QString::number(value); - html += percentSpacing ? QLatin1String("em;") : QLatin1String("px;"); + html += percentSpacing ? "em;"_L1 : "px;"_L1; } if (defaultCharFormat.hasProperty(QTextFormat::FontWordSpacing) && defaultCharFormat.fontWordSpacing() != 0.0) { - html += QLatin1String(" word-spacing:"); + html += " word-spacing:"_L1; html += QString::number(defaultCharFormat.fontWordSpacing()); - html += QLatin1String("px;"); + html += "px;"_L1; } - QString decorationTag(QLatin1String(" text-decoration:")); + QString decorationTag(" text-decoration:"_L1); bool atLeastOneDecorationSet = false; if (defaultCharFormat.hasProperty(QTextFormat::FontUnderline) || defaultCharFormat.hasProperty(QTextFormat::TextUnderlineStyle)) { if (defaultCharFormat.fontUnderline()) { - decorationTag += QLatin1String(" underline"); + decorationTag += " underline"_L1; atLeastOneDecorationSet = true; } } if (defaultCharFormat.hasProperty(QTextFormat::FontOverline)) { if (defaultCharFormat.fontOverline()) { - decorationTag += QLatin1String(" overline"); + decorationTag += " overline"_L1; atLeastOneDecorationSet = true; } } if (defaultCharFormat.hasProperty(QTextFormat::FontStrikeOut)) { if (defaultCharFormat.fontStrikeOut()) { - decorationTag += QLatin1String(" line-through"); + decorationTag += " line-through"_L1; atLeastOneDecorationSet = true; } } @@ -2460,7 +2462,7 @@ QString QTextHtmlExporter::toHtml(ExportMode mode) else emitTextFrame(doc->rootFrame()); - html += QLatin1String("</body></html>"); + html += "</body></html>"_L1; return html; } @@ -2468,7 +2470,7 @@ void QTextHtmlExporter::emitAttribute(const char *attribute, const QString &valu { html += u' '; html += QLatin1String(attribute); - html += QLatin1String("=\""); + html += "=\""_L1; html += value.toHtmlEscaped(); html += u'"'; } @@ -2487,9 +2489,9 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) if (format.hasProperty(QTextFormat::FontPointSize) && format.fontPointSize() != defaultCharFormat.fontPointSize()) { - html += QLatin1String(" font-size:"); + html += " font-size:"_L1; html += QString::number(format.fontPointSize()); - html += QLatin1String("pt;"); + html += "pt;"_L1; attributesEmitted = true; } else if (format.hasProperty(QTextFormat::FontSizeAdjustment)) { static const char sizeNameData[] = @@ -2509,21 +2511,21 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) name = sizeNameData + sizeNameOffsets[idx]; } if (name) { - html += QLatin1String(" font-size:"); + html += " font-size:"_L1; html += QLatin1String(name); html += u';'; attributesEmitted = true; } } else if (format.hasProperty(QTextFormat::FontPixelSize)) { - html += QLatin1String(" font-size:"); + html += " font-size:"_L1; html += QString::number(format.intProperty(QTextFormat::FontPixelSize)); - html += QLatin1String("px;"); + html += "px;"_L1; attributesEmitted = true; } if (format.hasProperty(QTextFormat::FontWeight) && format.fontWeight() != defaultCharFormat.fontWeight()) { - html += QLatin1String(" font-weight:"); + html += " font-weight:"_L1; html += QString::number(format.fontWeight()); html += u';'; attributesEmitted = true; @@ -2531,13 +2533,13 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) if (format.hasProperty(QTextFormat::FontItalic) && format.fontItalic() != defaultCharFormat.fontItalic()) { - html += QLatin1String(" font-style:"); - html += (format.fontItalic() ? QLatin1String("italic") : QLatin1String("normal")); + html += " font-style:"_L1; + html += (format.fontItalic() ? "italic"_L1 : "normal"_L1); html += u';'; attributesEmitted = true; } - QLatin1String decorationTag(" text-decoration:"); + const auto decorationTag = " text-decoration:"_L1; html += decorationTag; bool hasDecoration = false; bool atLeastOneDecorationSet = false; @@ -2546,7 +2548,7 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) && format.fontUnderline() != defaultCharFormat.fontUnderline()) { hasDecoration = true; if (format.fontUnderline()) { - html += QLatin1String(" underline"); + html += " underline"_L1; atLeastOneDecorationSet = true; } } @@ -2555,7 +2557,7 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) && format.fontOverline() != defaultCharFormat.fontOverline()) { hasDecoration = true; if (format.fontOverline()) { - html += QLatin1String(" overline"); + html += " overline"_L1; atLeastOneDecorationSet = true; } } @@ -2564,17 +2566,17 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) && format.fontStrikeOut() != defaultCharFormat.fontStrikeOut()) { hasDecoration = true; if (format.fontStrikeOut()) { - html += QLatin1String(" line-through"); + html += " line-through"_L1; atLeastOneDecorationSet = true; } } if (hasDecoration) { if (!atLeastOneDecorationSet) - html += QLatin1String("none"); + html += "none"_L1; html += u';'; if (format.hasProperty(QTextFormat::TextUnderlineColor)) { - html += QLatin1String(" text-decoration-color:"); + html += " text-decoration-color:"_L1; html += colorValue(format.underlineColor()); html += u';'; } @@ -2590,11 +2592,11 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) const bool isPixmap = qHasPixmapTexture(brush); const qint64 cacheKey = isPixmap ? brush.texture().cacheKey() : brush.textureImage().cacheKey(); - html += QLatin1String(" -qt-fg-texture-cachekey:"); + html += " -qt-fg-texture-cachekey:"_L1; html += QString::number(cacheKey); - html += QLatin1String(";"); + html += ";"_L1; } else { - html += QLatin1String(" color:"); + html += " color:"_L1; html += colorValue(brush.color()); html += u';'; } @@ -2603,7 +2605,7 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) if (format.background() != defaultCharFormat.background() && format.background().style() == Qt::SolidPattern) { - html += QLatin1String(" background-color:"); + html += " background-color:"_L1; html += colorValue(format.background().color()); html += u';'; attributesEmitted = true; @@ -2612,19 +2614,19 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) if (format.verticalAlignment() != defaultCharFormat.verticalAlignment() && format.verticalAlignment() != QTextCharFormat::AlignNormal) { - html += QLatin1String(" vertical-align:"); + html += " vertical-align:"_L1; QTextCharFormat::VerticalAlignment valign = format.verticalAlignment(); if (valign == QTextCharFormat::AlignSubScript) - html += QLatin1String("sub"); + html += "sub"_L1; else if (valign == QTextCharFormat::AlignSuperScript) - html += QLatin1String("super"); + html += "super"_L1; else if (valign == QTextCharFormat::AlignMiddle) - html += QLatin1String("middle"); + html += "middle"_L1; else if (valign == QTextCharFormat::AlignTop) - html += QLatin1String("top"); + html += "top"_L1; else if (valign == QTextCharFormat::AlignBottom) - html += QLatin1String("bottom"); + html += "bottom"_L1; html += u';'; attributesEmitted = true; @@ -2633,18 +2635,18 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format) if (format.fontCapitalization() != QFont::MixedCase) { const QFont::Capitalization caps = format.fontCapitalization(); if (caps == QFont::AllUppercase) - html += QLatin1String(" text-transform:uppercase;"); + html += " text-transform:uppercase;"_L1; else if (caps == QFont::AllLowercase) - html += QLatin1String(" text-transform:lowercase;"); + html += " text-transform:lowercase;"_L1; else if (caps == QFont::SmallCaps) - html += QLatin1String(" font-variant:small-caps;"); + html += " font-variant:small-caps;"_L1; attributesEmitted = true; } if (format.fontWordSpacing() != 0.0) { - html += QLatin1String(" word-spacing:"); + html += " word-spacing:"_L1; html += QString::number(format.fontWordSpacing()); - html += QLatin1String("px;"); + html += "px;"_L1; attributesEmitted = true; } @@ -2658,11 +2660,11 @@ void QTextHtmlExporter::emitTextLength(const char *attribute, const QTextLength html += u' '; html += QLatin1String(attribute); - html += QLatin1String("=\""); + html += "=\""_L1; html += QString::number(length.rawValue()); if (length.type() == QTextLength::PercentageLength) - html += QLatin1String("%\""); + html += "%\""_L1; else html += u'\"'; } @@ -2672,11 +2674,11 @@ void QTextHtmlExporter::emitAlignment(Qt::Alignment align) if (align & Qt::AlignLeft) return; else if (align & Qt::AlignRight) - html += QLatin1String(" align=\"right\""); + html += " align=\"right\""_L1; else if (align & Qt::AlignHCenter) - html += QLatin1String(" align=\"center\""); + html += " align=\"center\""_L1; else if (align & Qt::AlignJustify) - html += QLatin1String(" align=\"justify\""); + html += " align=\"justify\""_L1; } void QTextHtmlExporter::emitFloatStyle(QTextFrameFormat::Position pos, StyleMode mode) @@ -2685,14 +2687,14 @@ void QTextHtmlExporter::emitFloatStyle(QTextFrameFormat::Position pos, StyleMode return; if (mode == EmitStyleTag) - html += QLatin1String(" style=\"float:"); + html += " style=\"float:"_L1; else - html += QLatin1String(" float:"); + html += " float:"_L1; if (pos == QTextFrameFormat::FloatLeft) - html += QLatin1String(" left;"); + html += " left;"_L1; else if (pos == QTextFrameFormat::FloatRight) - html += QLatin1String(" right;"); + html += " right;"_L1; else Q_ASSERT_X(0, "QTextHtmlExporter::emitFloatStyle()", "pos should be a valid enum type"); @@ -2704,38 +2706,38 @@ static QLatin1String richtextBorderStyleToHtmlBorderStyle(QTextFrameFormat::Bord { switch (style) { case QTextFrameFormat::BorderStyle_None: - return QLatin1String("none"); + return "none"_L1; case QTextFrameFormat::BorderStyle_Dotted: - return QLatin1String("dotted"); + return "dotted"_L1; case QTextFrameFormat::BorderStyle_Dashed: - return QLatin1String("dashed"); + return "dashed"_L1; case QTextFrameFormat::BorderStyle_Solid: - return QLatin1String("solid"); + return "solid"_L1; case QTextFrameFormat::BorderStyle_Double: - return QLatin1String("double"); + return "double"_L1; case QTextFrameFormat::BorderStyle_DotDash: - return QLatin1String("dot-dash"); + return "dot-dash"_L1; case QTextFrameFormat::BorderStyle_DotDotDash: - return QLatin1String("dot-dot-dash"); + return "dot-dot-dash"_L1; case QTextFrameFormat::BorderStyle_Groove: - return QLatin1String("groove"); + return "groove"_L1; case QTextFrameFormat::BorderStyle_Ridge: - return QLatin1String("ridge"); + return "ridge"_L1; case QTextFrameFormat::BorderStyle_Inset: - return QLatin1String("inset"); + return "inset"_L1; case QTextFrameFormat::BorderStyle_Outset: - return QLatin1String("outset"); + return "outset"_L1; default: Q_UNREACHABLE(); }; - return QLatin1String(""); + return ""_L1; } void QTextHtmlExporter::emitBorderStyle(QTextFrameFormat::BorderStyle style) { Q_ASSERT(style <= QTextFrameFormat::BorderStyle_Outset); - html += QLatin1String(" border-style:"); + html += " border-style:"_L1; html += richtextBorderStyleToHtmlBorderStyle(style); html += u';'; } @@ -2743,24 +2745,24 @@ void QTextHtmlExporter::emitBorderStyle(QTextFrameFormat::BorderStyle style) void QTextHtmlExporter::emitPageBreakPolicy(QTextFormat::PageBreakFlags policy) { if (policy & QTextFormat::PageBreak_AlwaysBefore) - html += QLatin1String(" page-break-before:always;"); + html += " page-break-before:always;"_L1; if (policy & QTextFormat::PageBreak_AlwaysAfter) - html += QLatin1String(" page-break-after:always;"); + html += " page-break-after:always;"_L1; } void QTextHtmlExporter::emitFontFamily(const QStringList &families) { - html += QLatin1String(" font-family:"); + html += " font-family:"_L1; bool first = true; for (const QString &family : families) { - QLatin1String quote("\'"); + auto quote = "\'"_L1; if (family.contains(u'\'')) - quote = QLatin1String("""); + quote = """_L1; if (!first) - html += QLatin1String(","); + html += ","_L1; else first = false; html += quote; @@ -2772,21 +2774,21 @@ void QTextHtmlExporter::emitFontFamily(const QStringList &families) void QTextHtmlExporter::emitMargins(const QString &top, const QString &bottom, const QString &left, const QString &right) { - html += QLatin1String(" margin-top:"); + html += " margin-top:"_L1; html += top; - html += QLatin1String("px;"); + html += "px;"_L1; - html += QLatin1String(" margin-bottom:"); + html += " margin-bottom:"_L1; html += bottom; - html += QLatin1String("px;"); + html += "px;"_L1; - html += QLatin1String(" margin-left:"); + html += " margin-left:"_L1; html += left; - html += QLatin1String("px;"); + html += "px;"_L1; - html += QLatin1String(" margin-right:"); + html += " margin-right:"_L1; html += right; - html += QLatin1String("px;"); + html += "px;"_L1; } void QTextHtmlExporter::emitFragment(const QTextFragment &fragment) @@ -2798,15 +2800,15 @@ void QTextHtmlExporter::emitFragment(const QTextFragment &fragment) if (format.isAnchor()) { const auto names = format.anchorNames(); if (!names.isEmpty()) { - html += QLatin1String("<a name=\""); + html += "<a name=\""_L1; html += names.constFirst().toHtmlEscaped(); - html += QLatin1String("\"></a>"); + html += "\"></a>"_L1; } const QString href = format.anchorHref(); if (!href.isEmpty()) { - html += QLatin1String("<a href=\""); + html += "<a href=\""_L1; html += href.toHtmlEscaped(); - html += QLatin1String("\">"); + html += "\">"_L1; closeAnchor = true; } } @@ -2815,14 +2817,14 @@ void QTextHtmlExporter::emitFragment(const QTextFragment &fragment) const bool isObject = txt.contains(QChar::ObjectReplacementCharacter); const bool isImage = isObject && format.isImageFormat(); - QLatin1String styleTag("<span style=\""); + const auto styleTag = "<span style=\""_L1; html += styleTag; bool attributesEmitted = false; if (!isImage) attributesEmitted = emitCharFormatStyle(format); if (attributesEmitted) - html += QLatin1String("\">"); + html += "\">"_L1; else html.chop(styleTag.size()); @@ -2830,7 +2832,7 @@ void QTextHtmlExporter::emitFragment(const QTextFragment &fragment) for (int i = 0; isImage && i < txt.length(); ++i) { QTextImageFormat imgFmt = format.toImageFormat(); - html += QLatin1String("<img"); + html += "<img"_L1; if (imgFmt.hasProperty(QTextFormat::ImageName)) emitAttribute("src", imgFmt.name()); @@ -2848,14 +2850,14 @@ void QTextHtmlExporter::emitFragment(const QTextFragment &fragment) emitAttribute("height", QString::number(imgFmt.height())); if (imgFmt.verticalAlignment() == QTextCharFormat::AlignMiddle) - html += QLatin1String(" style=\"vertical-align: middle;\""); + html += " style=\"vertical-align: middle;\""_L1; else if (imgFmt.verticalAlignment() == QTextCharFormat::AlignTop) - html += QLatin1String(" style=\"vertical-align: top;\""); + html += " style=\"vertical-align: top;\""_L1; if (QTextFrame *imageFrame = qobject_cast<QTextFrame *>(doc->objectForFormat(imgFmt))) emitFloatStyle(imageFrame->frameFormat().position()); - html += QLatin1String(" />"); + html += " />"_L1; } } else { Q_ASSERT(!txt.contains(QChar::ObjectReplacementCharacter)); @@ -2864,16 +2866,16 @@ void QTextHtmlExporter::emitFragment(const QTextFragment &fragment) // split for [\n{LineSeparator}] // space in BR on purpose for compatibility with old-fashioned browsers - txt.replace(u'\n', QLatin1String("<br />")); - txt.replace(QChar::LineSeparator, QLatin1String("<br />")); + txt.replace(u'\n', "<br />"_L1); + txt.replace(QChar::LineSeparator, "<br />"_L1); html += txt; } if (attributesEmitted) - html += QLatin1String("</span>"); + html += "</span>"_L1; if (closeAnchor) - html += QLatin1String("</a>"); + html += "</a>"_L1; } static bool isOrderedList(int style) @@ -2891,16 +2893,16 @@ void QTextHtmlExporter::emitBlockAttributes(const QTextBlock &block) emitAlignment(format.alignment()); // assume default to not bloat the html too much - // html += QLatin1String(" dir='ltr'"); + // html += " dir='ltr'"_L1; if (block.textDirection() == Qt::RightToLeft) - html += QLatin1String(" dir='rtl'"); + html += " dir='rtl'"_L1; - QLatin1String style(" style=\""); + const auto style = " style=\""_L1; html += style; const bool emptyBlock = block.begin().atEnd(); if (emptyBlock) { - html += QLatin1String("-qt-paragraph-type:empty;"); + html += "-qt-paragraph-type:empty;"_L1; } emitMargins(QString::number(format.topMargin()), @@ -2908,38 +2910,38 @@ void QTextHtmlExporter::emitBlockAttributes(const QTextBlock &block) QString::number(format.leftMargin()), QString::number(format.rightMargin())); - html += QLatin1String(" -qt-block-indent:"); + html += " -qt-block-indent:"_L1; html += QString::number(format.indent()); html += u';'; - html += QLatin1String(" text-indent:"); + html += " text-indent:"_L1; html += QString::number(format.textIndent()); - html += QLatin1String("px;"); + html += "px;"_L1; if (block.userState() != -1) { - html += QLatin1String(" -qt-user-state:"); + html += " -qt-user-state:"_L1; html += QString::number(block.userState()); html += u';'; } if (format.lineHeightType() != QTextBlockFormat::SingleHeight) { - html += QLatin1String(" line-height:") + html += " line-height:"_L1 + QString::number(format.lineHeight()); switch (format.lineHeightType()) { case QTextBlockFormat::ProportionalHeight: - html += QLatin1String("%;"); + html += "%;"_L1; break; case QTextBlockFormat::FixedHeight: - html += QLatin1String("; -qt-line-height-type: fixed;"); + html += "; -qt-line-height-type: fixed;"_L1; break; case QTextBlockFormat::MinimumHeight: - html += QLatin1String("px;"); + html += "px;"_L1; break; case QTextBlockFormat::LineDistanceHeight: - html += QLatin1String("; -qt-line-height-type: line-distance;"); + html += "; -qt-line-height-type: line-distance;"_L1; break; default: - html += QLatin1String(";"); + html += ";"_L1; break; // Should never reach here } } @@ -2993,30 +2995,30 @@ void QTextHtmlExporter::emitBlock(const QTextBlock &block) const QTextListFormat format = list->format(); const int style = format.style(); switch (style) { - case QTextListFormat::ListDecimal: html += QLatin1String("<ol"); break; - case QTextListFormat::ListDisc: html += QLatin1String("<ul"); break; - case QTextListFormat::ListCircle: html += QLatin1String("<ul type=\"circle\""); break; - case QTextListFormat::ListSquare: html += QLatin1String("<ul type=\"square\""); break; - case QTextListFormat::ListLowerAlpha: html += QLatin1String("<ol type=\"a\""); break; - case QTextListFormat::ListUpperAlpha: html += QLatin1String("<ol type=\"A\""); break; - case QTextListFormat::ListLowerRoman: html += QLatin1String("<ol type=\"i\""); break; - case QTextListFormat::ListUpperRoman: html += QLatin1String("<ol type=\"I\""); break; - default: html += QLatin1String("<ul"); // ### should not happen + case QTextListFormat::ListDecimal: html += "<ol"_L1; break; + case QTextListFormat::ListDisc: html += "<ul"_L1; break; + case QTextListFormat::ListCircle: html += "<ul type=\"circle\""_L1; break; + case QTextListFormat::ListSquare: html += "<ul type=\"square\""_L1; break; + case QTextListFormat::ListLowerAlpha: html += "<ol type=\"a\""_L1; break; + case QTextListFormat::ListUpperAlpha: html += "<ol type=\"A\""_L1; break; + case QTextListFormat::ListLowerRoman: html += "<ol type=\"i\""_L1; break; + case QTextListFormat::ListUpperRoman: html += "<ol type=\"I\""_L1; break; + default: html += "<ul"_L1; // ### should not happen } QString styleString = QString::fromLatin1("margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px;"); if (format.hasProperty(QTextFormat::ListIndent)) { - styleString += QLatin1String(" -qt-list-indent: "); + styleString += " -qt-list-indent: "_L1; styleString += QString::number(format.indent()); styleString += u';'; } if (format.hasProperty(QTextFormat::ListNumberPrefix)) { QString numberPrefix = format.numberPrefix(); - numberPrefix.replace(u'"', QLatin1String("\\22")); - numberPrefix.replace(u'\'', QLatin1String("\\27")); // FIXME: There's a problem in the CSS parser the prevents this from being correctly restored - styleString += QLatin1String(" -qt-list-number-prefix: "); + numberPrefix.replace(u'"', "\\22"_L1); + numberPrefix.replace(u'\'', "\\27"_L1); // FIXME: There's a problem in the CSS parser the prevents this from being correctly restored + styleString += " -qt-list-number-prefix: "_L1; styleString += u'\''; styleString += numberPrefix; styleString += u'\''; @@ -3024,11 +3026,11 @@ void QTextHtmlExporter::emitBlock(const QTextBlock &block) } if (format.hasProperty(QTextFormat::ListNumberSuffix)) { - if (format.numberSuffix() != QLatin1String(".")) { // this is our default + if (format.numberSuffix() != "."_L1) { // this is our default QString numberSuffix = format.numberSuffix(); - numberSuffix.replace(u'"', QLatin1String("\\22")); - numberSuffix.replace(u'\'', QLatin1String("\\27")); // see above - styleString += QLatin1String(" -qt-list-number-suffix: "); + numberSuffix.replace(u'"', "\\22"_L1); + numberSuffix.replace(u'\'', "\\27"_L1); // see above + styleString += " -qt-list-number-suffix: "_L1; styleString += u'\''; styleString += numberSuffix; styleString += u'\''; @@ -3036,16 +3038,16 @@ void QTextHtmlExporter::emitBlock(const QTextBlock &block) } } - html += QLatin1String(" style=\""); + html += " style=\""_L1; html += styleString; - html += QLatin1String("\">"); + html += "\">"_L1; } - html += QLatin1String("<li"); + html += "<li"_L1; const QTextCharFormat blockFmt = formatDifference(defaultCharFormat, block.charFormat()).toCharFormat(); if (!blockFmt.properties().isEmpty()) { - html += QLatin1String(" style=\""); + html += " style=\""_L1; emitCharFormatStyle(blockFmt); html += u'\"'; @@ -3055,7 +3057,7 @@ void QTextHtmlExporter::emitBlock(const QTextBlock &block) const QTextBlockFormat blockFormat = block.blockFormat(); if (blockFormat.hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth)) { - html += QLatin1String("<hr"); + html += "<hr"_L1; QTextLength width = blockFormat.lengthProperty(QTextFormat::BlockTrailingHorizontalRulerWidth); if (width.type() != QTextLength::VariableLength) @@ -3063,14 +3065,14 @@ void QTextHtmlExporter::emitBlock(const QTextBlock &block) html += u' '; if (blockFormat.hasProperty(QTextFormat::BackgroundBrush)) { - html += QLatin1String("style=\""); - html += QLatin1String("background-color:"); + html += "style=\""_L1; + html += "background-color:"_L1; html += colorValue(qvariant_cast<QBrush>(blockFormat.property(QTextFormat::BackgroundBrush)).color()); html += u';'; html += u'\"'; } - html += QLatin1String("/>"); + html += "/>"_L1; return; } @@ -3078,51 +3080,51 @@ void QTextHtmlExporter::emitBlock(const QTextBlock &block) if (pre) { if (list) html += u'>'; - html += QLatin1String("<pre"); + html += "<pre"_L1; } else if (!list) { int headingLevel = blockFormat.headingLevel(); if (headingLevel > 0 && headingLevel <= 6) - html += QLatin1String("<h") + QString::number(headingLevel); + html += "<h"_L1 + QString::number(headingLevel); else - html += QLatin1String("<p"); + html += "<p"_L1; } emitBlockAttributes(block); html += u'>'; if (block.begin().atEnd()) - html += QLatin1String("<br />"); + html += "<br />"_L1; QTextBlock::Iterator it = block.begin(); if (fragmentMarkers && !it.atEnd() && block == doc->begin()) - html += QLatin1String("<!--StartFragment-->"); + html += "<!--StartFragment-->"_L1; for (; !it.atEnd(); ++it) emitFragment(it.fragment()); if (fragmentMarkers && block.position() + block.length() == QTextDocumentPrivate::get(doc)->length()) - html += QLatin1String("<!--EndFragment-->"); + html += "<!--EndFragment-->"_L1; QString closeTags; if (pre) - html += QLatin1String("</pre>"); + html += "</pre>"_L1; else if (list) - closeTags += QLatin1String("</li>"); + closeTags += "</li>"_L1; else { int headingLevel = blockFormat.headingLevel(); if (headingLevel > 0 && headingLevel <= 6) - html += QLatin1String("</h") + QString::number(headingLevel) + u'>'; + html += QString::asprintf("</h%d>", headingLevel); else - html += QLatin1String("</p>"); + html += "</p>"_L1; } if (list) { if (list->itemNumber(block) == list->count() - 1) { // last item? close list if (isOrderedList(list->format().style())) - closeTags += QLatin1String("</ol>"); + closeTags += "</ol>"_L1; else - closeTags += QLatin1String("</ul>"); + closeTags += "</ul>"_L1; } const QTextBlock nextBlock = block.next(); // If the next block is the beginning of a new deeper nested list, then we don't @@ -3218,7 +3220,7 @@ void QTextHtmlExporter::emitTable(const QTextTable *table) { QTextTableFormat format = table->format(); - html += QLatin1String("\n<table"); + html += "\n<table"_L1; if (format.hasProperty(QTextFormat::FrameBorder)) emitAttribute("border", QString::number(format.border())); @@ -3253,10 +3255,10 @@ void QTextHtmlExporter::emitTable(const QTextTable *table) const int headerRowCount = qMin(format.headerRowCount(), rows); if (headerRowCount > 0) - html += QLatin1String("<thead>"); + html += "<thead>"_L1; for (int row = 0; row < rows; ++row) { - html += QLatin1String("\n<tr>"); + html += "\n<tr>"_L1; for (int col = 0; col < columns; ++col) { const QTextTableCell cell = table->cellAt(row, col); @@ -3268,7 +3270,7 @@ void QTextHtmlExporter::emitTable(const QTextTable *table) if (cell.column() != col) continue; - html += QLatin1String("\n<td"); + html += "\n<td"_L1; if (!widthEmittedForColumn[col] && cell.columnSpan() == 1) { emitTextLength("width", columnWidths.at(col)); @@ -3290,16 +3292,16 @@ void QTextHtmlExporter::emitTable(const QTextTable *table) QString styleString; if (valign >= QTextCharFormat::AlignMiddle && valign <= QTextCharFormat::AlignBottom) { - styleString += QLatin1String(" vertical-align:"); + styleString += " vertical-align:"_L1; switch (valign) { case QTextCharFormat::AlignMiddle: - styleString += QLatin1String("middle"); + styleString += "middle"_L1; break; case QTextCharFormat::AlignTop: - styleString += QLatin1String("top"); + styleString += "top"_L1; break; case QTextCharFormat::AlignBottom: - styleString += QLatin1String("bottom"); + styleString += "bottom"_L1; break; default: break; @@ -3312,59 +3314,59 @@ void QTextHtmlExporter::emitTable(const QTextTable *table) } if (cellFormat.hasProperty(QTextFormat::TableCellLeftPadding)) - styleString += QLatin1String(" padding-left:") + QString::number(cellFormat.leftPadding()) + u';'; + styleString += " padding-left:"_L1 + QString::number(cellFormat.leftPadding()) + u';'; if (cellFormat.hasProperty(QTextFormat::TableCellRightPadding)) - styleString += QLatin1String(" padding-right:") + QString::number(cellFormat.rightPadding()) + u';'; + styleString += " padding-right:"_L1 + QString::number(cellFormat.rightPadding()) + u';'; if (cellFormat.hasProperty(QTextFormat::TableCellTopPadding)) - styleString += QLatin1String(" padding-top:") + QString::number(cellFormat.topPadding()) + u';'; + styleString += " padding-top:"_L1 + QString::number(cellFormat.topPadding()) + u';'; if (cellFormat.hasProperty(QTextFormat::TableCellBottomPadding)) - styleString += QLatin1String(" padding-bottom:") + QString::number(cellFormat.bottomPadding()) + u';'; + styleString += " padding-bottom:"_L1 + QString::number(cellFormat.bottomPadding()) + u';'; if (cellFormat.hasProperty(QTextFormat::TableCellTopBorder)) - styleString += QLatin1String(" border-top:") + QString::number(cellFormat.topBorder()) + QLatin1String("px;"); + styleString += " border-top:"_L1 + QString::number(cellFormat.topBorder()) + "px;"_L1; if (cellFormat.hasProperty(QTextFormat::TableCellRightBorder)) - styleString += QLatin1String(" border-right:") + QString::number(cellFormat.rightBorder()) + QLatin1String("px;"); + styleString += " border-right:"_L1 + QString::number(cellFormat.rightBorder()) + "px;"_L1; if (cellFormat.hasProperty(QTextFormat::TableCellBottomBorder)) - styleString += QLatin1String(" border-bottom:") + QString::number(cellFormat.bottomBorder()) + QLatin1String("px;"); + styleString += " border-bottom:"_L1 + QString::number(cellFormat.bottomBorder()) + "px;"_L1; if (cellFormat.hasProperty(QTextFormat::TableCellLeftBorder)) - styleString += QLatin1String(" border-left:") + QString::number(cellFormat.leftBorder()) + QLatin1String("px;"); + styleString += " border-left:"_L1 + QString::number(cellFormat.leftBorder()) + "px;"_L1; if (cellFormat.hasProperty(QTextFormat::TableCellTopBorderBrush)) - styleString += QLatin1String(" border-top-color:") + cellFormat.topBorderBrush().color().name() + u';'; + styleString += " border-top-color:"_L1 + cellFormat.topBorderBrush().color().name() + u';'; if (cellFormat.hasProperty(QTextFormat::TableCellRightBorderBrush)) - styleString += QLatin1String(" border-right-color:") + cellFormat.rightBorderBrush().color().name() + u';'; + styleString += " border-right-color:"_L1 + cellFormat.rightBorderBrush().color().name() + u';'; if (cellFormat.hasProperty(QTextFormat::TableCellBottomBorderBrush)) - styleString += QLatin1String(" border-bottom-color:") + cellFormat.bottomBorderBrush().color().name() + u';'; + styleString += " border-bottom-color:"_L1 + cellFormat.bottomBorderBrush().color().name() + u';'; if (cellFormat.hasProperty(QTextFormat::TableCellLeftBorderBrush)) - styleString += QLatin1String(" border-left-color:") + cellFormat.leftBorderBrush().color().name() + u';'; + styleString += " border-left-color:"_L1 + cellFormat.leftBorderBrush().color().name() + u';'; if (cellFormat.hasProperty(QTextFormat::TableCellTopBorderStyle)) - styleString += QLatin1String(" border-top-style:") + richtextBorderStyleToHtmlBorderStyle(cellFormat.topBorderStyle()) + u';'; + styleString += " border-top-style:"_L1 + richtextBorderStyleToHtmlBorderStyle(cellFormat.topBorderStyle()) + u';'; if (cellFormat.hasProperty(QTextFormat::TableCellRightBorderStyle)) - styleString += QLatin1String(" border-right-style:") + richtextBorderStyleToHtmlBorderStyle(cellFormat.rightBorderStyle()) + u';'; + styleString += " border-right-style:"_L1 + richtextBorderStyleToHtmlBorderStyle(cellFormat.rightBorderStyle()) + u';'; if (cellFormat.hasProperty(QTextFormat::TableCellBottomBorderStyle)) - styleString += QLatin1String(" border-bottom-style:") + richtextBorderStyleToHtmlBorderStyle(cellFormat.bottomBorderStyle()) + u';'; + styleString += " border-bottom-style:"_L1 + richtextBorderStyleToHtmlBorderStyle(cellFormat.bottomBorderStyle()) + u';'; if (cellFormat.hasProperty(QTextFormat::TableCellLeftBorderStyle)) - styleString += QLatin1String(" border-left-style:") + richtextBorderStyleToHtmlBorderStyle(cellFormat.leftBorderStyle()) + u';'; + styleString += " border-left-style:"_L1 + richtextBorderStyleToHtmlBorderStyle(cellFormat.leftBorderStyle()) + u';'; if (!styleString.isEmpty()) - html += QLatin1String(" style=\"") + styleString + u'\"'; + html += " style=\""_L1 + styleString + u'\"'; html += u'>'; emitFrame(cell.begin()); - html += QLatin1String("</td>"); + html += "</td>"_L1; defaultCharFormat = oldDefaultCharFormat; } - html += QLatin1String("</tr>"); + html += "</tr>"_L1; if (headerRowCount > 0 && row == headerRowCount - 1) - html += QLatin1String("</thead>"); + html += "</thead>"_L1; } - html += QLatin1String("</table>"); + html += "</table>"_L1; } void QTextHtmlExporter::emitFrame(const QTextFrame::Iterator &frameIt) @@ -3397,7 +3399,7 @@ void QTextHtmlExporter::emitTextFrame(const QTextFrame *f) { FrameType frameType = f->parentFrame() ? TextFrame : RootFrame; - html += QLatin1String("\n<table"); + html += "\n<table"_L1; QTextFrameFormat format = f->frameFormat(); if (format.hasProperty(QTextFormat::FrameBorder)) @@ -3413,21 +3415,21 @@ void QTextHtmlExporter::emitTextFrame(const QTextFrame *f) emitBackgroundAttribute(format); html += u'>'; - html += QLatin1String("\n<tr>\n<td style=\"border: none;\">"); + html += "\n<tr>\n<td style=\"border: none;\">"_L1; emitFrame(f->begin()); - html += QLatin1String("</td></tr></table>"); + html += "</td></tr></table>"_L1; } void QTextHtmlExporter::emitFrameStyle(const QTextFrameFormat &format, FrameType frameType) { - QLatin1String styleAttribute(" style=\""); + const auto styleAttribute = " style=\""_L1; html += styleAttribute; const int originalHtmlLength = html.length(); if (frameType == TextFrame) - html += QLatin1String("-qt-table-type: frame;"); + html += "-qt-table-type: frame;"_L1; else if (frameType == RootFrame) - html += QLatin1String("-qt-table-type: root;"); + html += "-qt-table-type: root;"_L1; const QTextFrameFormat defaultFormat; @@ -3435,7 +3437,7 @@ void QTextHtmlExporter::emitFrameStyle(const QTextFrameFormat &format, FrameType emitPageBreakPolicy(format.pageBreakPolicy()); if (format.borderBrush() != defaultFormat.borderBrush()) { - html += QLatin1String(" border-color:"); + html += " border-color:"_L1; html += colorValue(format.borderBrush().color()); html += u';'; } @@ -3454,7 +3456,7 @@ void QTextHtmlExporter::emitFrameStyle(const QTextFrameFormat &format, FrameType QString::number(format.rightMargin())); if (format.property(QTextFormat::TableBorderCollapse).toBool()) - html += QLatin1String(" border-collapse:collapse;"); + html += " border-collapse:collapse;"_L1; if (html.length() == originalHtmlLength) // nothing emitted? html.chop(styleAttribute.size()); diff --git a/src/gui/text/qtextdocumentfragment.cpp b/src/gui/text/qtextdocumentfragment.cpp index e91ed48a55..348916dd04 100644 --- a/src/gui/text/qtextdocumentfragment.cpp +++ b/src/gui/text/qtextdocumentfragment.cpp @@ -49,6 +49,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + QTextCopyHelper::QTextCopyHelper(const QTextCursor &_source, const QTextCursor &_destination, bool forceCharFormat, const QTextCharFormat &fmt) #if defined(Q_CC_DIAB) // compiler bug : formatCollection(*_destination.d->priv->formatCollection()), originalText((const QString)_source.d->priv->buffer()) @@ -445,14 +447,14 @@ QTextHtmlImporter::QTextHtmlImporter(QTextDocument *_doc, const QString &_html, wsm = QTextHtmlParserNode::WhiteSpaceNormal; QString html = _html; - const int startFragmentPos = html.indexOf(QLatin1String("<!--StartFragment-->")); + const int startFragmentPos = html.indexOf("<!--StartFragment-->"_L1); if (startFragmentPos != -1) { - const QLatin1String qt3RichTextHeader("<meta name=\"qrichtext\" content=\"1\" />"); + const auto qt3RichTextHeader = "<meta name=\"qrichtext\" content=\"1\" />"_L1; // Hack for Qt3 const bool hasQtRichtextMetaTag = html.contains(qt3RichTextHeader); - const int endFragmentPos = html.indexOf(QLatin1String("<!--EndFragment-->")); + const int endFragmentPos = html.indexOf("<!--EndFragment-->"_L1); if (startFragmentPos < endFragmentPos) html = html.mid(startFragmentPos, endFragmentPos - startFragmentPos); else diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index de48a86da7..eaa2bd679f 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -57,6 +57,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + // see also tst_qtextdocumentfragment.cpp #define MAX_ENTITY 258 static const struct QTextHtmlEntity { const char name[9]; char16_t code; } entities[]= { @@ -479,7 +481,7 @@ int QTextHtmlParser::lookupElement(const QString &element) static QString quoteNewline(const QString &s) { QString n = s; - n.replace(u'\n', QLatin1String("\\n")); + n.replace(u'\n', "\\n"_L1); return n; } @@ -787,7 +789,7 @@ void QTextHtmlParser::parseExclamationTag() if (hasPrefix(u'-') && hasPrefix(u'-', 1)) { pos += 2; // eat comments - int end = txt.indexOf(QLatin1String("-->"), pos); + int end = txt.indexOf("-->"_L1, pos); pos = (end >= 0 ? end + 3 : len); } else { // eat internal tags @@ -849,7 +851,7 @@ QString QTextHtmlParser::parseEntity() } error: pos = recover; - return QLatin1String("&"); + return "&"_L1; } // parses one word, possibly quoted, and returns it @@ -916,13 +918,13 @@ QTextHtmlParserNode *QTextHtmlParser::resolveParent() QTextHtmlParserNode *table = nodes[nodes.count() - 3]; table->parent = p; table->id = Html_table; - table->tag = QLatin1String("table"); + table->tag = "table"_L1; table->children.append(nodes.count() - 2); // add row as child QTextHtmlParserNode *row = nodes[nodes.count() - 2]; row->parent = nodes.count() - 3; // table as parent row->id = Html_tr; - row->tag = QLatin1String("tr"); + row->tag = "tr"_L1; p = nodes.count() - 2; node = nodes.last(); // re-initialize pointer @@ -939,7 +941,7 @@ QTextHtmlParserNode *QTextHtmlParser::resolveParent() QTextHtmlParserNode *table = nodes[nodes.count() - 2]; table->parent = p; table->id = Html_table; - table->tag = QLatin1String("table"); + table->tag = "table"_L1; p = nodes.count() - 2; node = nodes.last(); // re-initialize pointer } @@ -1065,7 +1067,7 @@ void QTextHtmlParserNode::initializeProperties(const QTextHtmlParserNode *parent case Html_a: for (int i = 0; i < attributes.count(); i += 2) { const QString key = attributes.at(i); - if (key.compare(QLatin1String("href"), Qt::CaseInsensitive) == 0 + if (key.compare("href"_L1, Qt::CaseInsensitive) == 0 && !attributes.at(i + 1).isEmpty()) { hasHref = true; } @@ -1272,13 +1274,13 @@ void QTextHtmlParserNode::applyCssDeclarations(const QList<QCss::Declaration> &d case QCss::QtLineHeightType: { QString lineHeightTypeName = decl.d->values.first().variant.toString(); QTextBlockFormat::LineHeightTypes lineHeightType; - if (lineHeightTypeName.compare(QLatin1String("proportional"), Qt::CaseInsensitive) == 0) + if (lineHeightTypeName.compare("proportional"_L1, Qt::CaseInsensitive) == 0) lineHeightType = QTextBlockFormat::ProportionalHeight; - else if (lineHeightTypeName.compare(QLatin1String("fixed"), Qt::CaseInsensitive) == 0) + else if (lineHeightTypeName.compare("fixed"_L1, Qt::CaseInsensitive) == 0) lineHeightType = QTextBlockFormat::FixedHeight; - else if (lineHeightTypeName.compare(QLatin1String("minimum"), Qt::CaseInsensitive) == 0) + else if (lineHeightTypeName.compare("minimum"_L1, Qt::CaseInsensitive) == 0) lineHeightType = QTextBlockFormat::MinimumHeight; - else if (lineHeightTypeName.compare(QLatin1String("line-distance"), Qt::CaseInsensitive) == 0) + else if (lineHeightTypeName.compare("line-distance"_L1, Qt::CaseInsensitive) == 0) lineHeightType = QTextBlockFormat::LineDistanceHeight; else lineHeightType = QTextBlockFormat::SingleHeight; @@ -1331,13 +1333,13 @@ void QTextHtmlParserNode::applyCssDeclarations(const QList<QCss::Declaration> &d hasCssListIndent = true; break; case QCss::QtParagraphType: - if (decl.d->values.first().variant.toString().compare(QLatin1String("empty"), Qt::CaseInsensitive) == 0) + if (decl.d->values.first().variant.toString().compare("empty"_L1, Qt::CaseInsensitive) == 0) isEmptyParagraph = true; break; case QCss::QtTableType: - if (decl.d->values.first().variant.toString().compare(QLatin1String("frame"), Qt::CaseInsensitive) == 0) + if (decl.d->values.first().variant.toString().compare("frame"_L1, Qt::CaseInsensitive) == 0) isTextFrame = true; - else if (decl.d->values.first().variant.toString().compare(QLatin1String("root"), Qt::CaseInsensitive) == 0) { + else if (decl.d->values.first().variant.toString().compare("root"_L1, Qt::CaseInsensitive) == 0) { isTextFrame = true; isRootFrame = true; } @@ -1567,7 +1569,7 @@ static void setWidthAttribute(QTextLength *width, const QString &valueStr) #ifndef QT_NO_CSSPARSER void QTextHtmlParserNode::parseStyleAttribute(const QString &value, const QTextDocument *resourceProvider) { - const QString css = QLatin1String("* {") + value + u'}'; + const QString css = "* {"_L1 + value + u'}'; QCss::Parser parser(css); QCss::StyleSheet sheet; parser.parse(&sheet, Qt::CaseInsensitive); @@ -1585,7 +1587,7 @@ QStringList QTextHtmlParser::parseAttributes() if (hasPrefix(u'>') || hasPrefix(u'/')) break; QString key = parseWord().toLower(); - QString value = QLatin1String("1"); + QString value = "1"_L1; if (key.size() == 0) break; eatSpace(); @@ -1621,12 +1623,12 @@ void QTextHtmlParser::applyAttributes(const QStringList &attributes) switch (node->id) { case Html_font: // the infamous font tag - if (key == QLatin1String("size") && value.size()) { + if (key == "size"_L1 && value.size()) { int n = value.toInt(); if (value.at(0) != u'+' && value.at(0) != u'-') n -= 3; node->charFormat.setProperty(QTextFormat::FontSizeAdjustment, n); - } else if (key == QLatin1String("face")) { + } else if (key == "face"_L1) { if (value.contains(u',')) { const QStringList values = value.split(u','); QStringList families; @@ -1636,7 +1638,7 @@ void QTextHtmlParser::applyAttributes(const QStringList &attributes) } else { node->charFormat.setFontFamilies(QStringList(value)); } - } else if (key == QLatin1String("color")) { + } else if (key == "color"_L1) { QColor c = QColor::fromString(value); if (!c.isValid()) qWarning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); @@ -1645,153 +1647,147 @@ void QTextHtmlParser::applyAttributes(const QStringList &attributes) break; case Html_ol: case Html_ul: - if (key == QLatin1String("type")) { + if (key == "type"_L1) { node->hasOwnListStyle = true; - if (value == QLatin1String("1")) { + if (value == "1"_L1) { node->listStyle = QTextListFormat::ListDecimal; - } else if (value == QLatin1String("a")) { + } else if (value == "a"_L1) { node->listStyle = QTextListFormat::ListLowerAlpha; - } else if (value == QLatin1String("A")) { + } else if (value == "A"_L1) { node->listStyle = QTextListFormat::ListUpperAlpha; - } else if (value == QLatin1String("i")) { + } else if (value == "i"_L1) { node->listStyle = QTextListFormat::ListLowerRoman; - } else if (value == QLatin1String("I")) { + } else if (value == "I"_L1) { node->listStyle = QTextListFormat::ListUpperRoman; } else { value = std::move(value).toLower(); - if (value == QLatin1String("square")) + if (value == "square"_L1) node->listStyle = QTextListFormat::ListSquare; - else if (value == QLatin1String("disc")) + else if (value == "disc"_L1) node->listStyle = QTextListFormat::ListDisc; - else if (value == QLatin1String("circle")) + else if (value == "circle"_L1) node->listStyle = QTextListFormat::ListCircle; - else if (value == QLatin1String("none")) + else if (value == "none"_L1) node->listStyle = QTextListFormat::ListStyleUndefined; } } break; case Html_a: - if (key == QLatin1String("href")) + if (key == "href"_L1) node->charFormat.setAnchorHref(value); - else if (key == QLatin1String("name")) + else if (key == "name"_L1) node->charFormat.setAnchorNames({value}); break; case Html_img: - if (key == QLatin1String("src") || key == QLatin1String("source")) { + if (key == "src"_L1 || key == "source"_L1) { node->imageName = value; - } else if (key == QLatin1String("width")) { + } else if (key == "width"_L1) { node->imageWidth = -2; // register that there is a value for it. setFloatAttribute(&node->imageWidth, value); - } else if (key == QLatin1String("height")) { + } else if (key == "height"_L1) { node->imageHeight = -2; // register that there is a value for it. setFloatAttribute(&node->imageHeight, value); - } else if (key == QLatin1String("alt")) { + } else if (key == "alt"_L1) { node->imageAlt = value; - } else if (key == QLatin1String("title")) { + } else if (key == "title"_L1) { node->text = value; } break; case Html_tr: case Html_body: - if (key == QLatin1String("bgcolor")) { + if (key == "bgcolor"_L1) { QColor c = QColor::fromString(value); if (!c.isValid()) qWarning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); node->charFormat.setBackground(c); - } else if (key == QLatin1String("background")) { + } else if (key == "background"_L1) { node->applyBackgroundImage(value, resourceProvider); } break; case Html_th: case Html_td: - if (key == QLatin1String("width")) { + if (key == "width"_L1) { setWidthAttribute(&node->width, value); - } else if (key == QLatin1String("bgcolor")) { + } else if (key == "bgcolor"_L1) { QColor c = QColor::fromString(value); if (!c.isValid()) qWarning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); node->charFormat.setBackground(c); - } else if (key == QLatin1String("background")) { + } else if (key == "background"_L1) { node->applyBackgroundImage(value, resourceProvider); - } else if (key == QLatin1String("rowspan")) { + } else if (key == "rowspan"_L1) { if (setIntAttribute(&node->tableCellRowSpan, value)) node->tableCellRowSpan = qMax(1, node->tableCellRowSpan); - } else if (key == QLatin1String("colspan")) { + } else if (key == "colspan"_L1) { if (setIntAttribute(&node->tableCellColSpan, value)) node->tableCellColSpan = qBound(1, node->tableCellColSpan, 20480); } break; case Html_table: - if (key == QLatin1String("border")) { + if (key == "border"_L1) { setFloatAttribute(&node->tableBorder, value); - } else if (key == QLatin1String("bgcolor")) { + } else if (key == "bgcolor"_L1) { QColor c = QColor::fromString(value); if (!c.isValid()) qWarning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); node->charFormat.setBackground(c); - } else if (key == QLatin1String("bordercolor")) { + } else if (key == "bordercolor"_L1) { QColor c = QColor::fromString(value); if (!c.isValid()) qWarning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData()); node->borderBrush = c; - } else if (key == QLatin1String("background")) { + } else if (key == "background"_L1) { node->applyBackgroundImage(value, resourceProvider); - } else if (key == QLatin1String("cellspacing")) { + } else if (key == "cellspacing"_L1) { setFloatAttribute(&node->tableCellSpacing, value); - } else if (key == QLatin1String("cellpadding")) { + } else if (key == "cellpadding"_L1) { setFloatAttribute(&node->tableCellPadding, value); - } else if (key == QLatin1String("width")) { + } else if (key == "width"_L1) { setWidthAttribute(&node->width, value); - } else if (key == QLatin1String("height")) { + } else if (key == "height"_L1) { setWidthAttribute(&node->height, value); } break; case Html_meta: - if (key == QLatin1String("name") - && value == QLatin1String("qrichtext")) { + if (key == "name"_L1 && value == "qrichtext"_L1) seenQt3Richtext = true; - } - - if (key == QLatin1String("content") - && value == QLatin1String("1") - && seenQt3Richtext) { + if (key == "content"_L1 && value == "1"_L1 && seenQt3Richtext) textEditMode = true; - } break; case Html_hr: - if (key == QLatin1String("width")) + if (key == "width"_L1) setWidthAttribute(&node->width, value); break; case Html_link: - if (key == QLatin1String("href")) + if (key == "href"_L1) linkHref = value; - else if (key == QLatin1String("type")) + else if (key == "type"_L1) linkType = value; break; case Html_pre: - if (key == QLatin1String("class") && value.startsWith(QLatin1String("language-"))) + if (key == "class"_L1 && value.startsWith("language-"_L1)) node->blockFormat.setProperty(QTextFormat::BlockCodeLanguage, value.mid(9)); break; default: break; } - if (key == QLatin1String("style")) { + if (key == "style"_L1) { #ifndef QT_NO_CSSPARSER node->parseStyleAttribute(value, resourceProvider); #endif - } else if (key == QLatin1String("align")) { + } else if (key == "align"_L1) { value = std::move(value).toLower(); bool alignmentSet = true; - if (value == QLatin1String("left")) + if (value == "left"_L1) node->blockFormat.setAlignment(Qt::AlignLeft|Qt::AlignAbsolute); - else if (value == QLatin1String("right")) + else if (value == "right"_L1) node->blockFormat.setAlignment(Qt::AlignRight|Qt::AlignAbsolute); - else if (value == QLatin1String("center")) + else if (value == "center"_L1) node->blockFormat.setAlignment(Qt::AlignHCenter); - else if (value == QLatin1String("justify")) + else if (value == "justify"_L1) node->blockFormat.setAlignment(Qt::AlignJustify); else alignmentSet = false; @@ -1803,36 +1799,36 @@ void QTextHtmlParser::applyAttributes(const QStringList &attributes) node->cssFloat = QTextFrameFormat::FloatLeft; else if (node->blockFormat.alignment() & Qt::AlignRight) node->cssFloat = QTextFrameFormat::FloatRight; - } else if (value == QLatin1String("middle")) { + } else if (value == "middle"_L1) { node->charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); - } else if (value == QLatin1String("top")) { + } else if (value == "top"_L1) { node->charFormat.setVerticalAlignment(QTextCharFormat::AlignTop); } } - } else if (key == QLatin1String("valign")) { + } else if (key == "valign"_L1) { value = std::move(value).toLower(); - if (value == QLatin1String("top")) + if (value == "top"_L1) node->charFormat.setVerticalAlignment(QTextCharFormat::AlignTop); - else if (value == QLatin1String("middle")) + else if (value == "middle"_L1) node->charFormat.setVerticalAlignment(QTextCharFormat::AlignMiddle); - else if (value == QLatin1String("bottom")) + else if (value == "bottom"_L1) node->charFormat.setVerticalAlignment(QTextCharFormat::AlignBottom); - } else if (key == QLatin1String("dir")) { + } else if (key == "dir"_L1) { value = std::move(value).toLower(); - if (value == QLatin1String("ltr")) + if (value == "ltr"_L1) node->blockFormat.setLayoutDirection(Qt::LeftToRight); - else if (value == QLatin1String("rtl")) + else if (value == "rtl"_L1) node->blockFormat.setLayoutDirection(Qt::RightToLeft); - } else if (key == QLatin1String("title")) { + } else if (key == "title"_L1) { node->charFormat.setToolTip(value); - } else if (key == QLatin1String("id")) { + } else if (key == "id"_L1) { node->charFormat.setAnchor(true); node->charFormat.setAnchorNames({value}); } } #ifndef QT_NO_CSSPARSER - if (resourceProvider && !linkHref.isEmpty() && linkType == QLatin1String("text/css")) + if (resourceProvider && !linkHref.isEmpty() && linkType == "text/css"_L1) importStyleSheet(linkHref); #endif } @@ -1934,8 +1930,7 @@ void QTextHtmlParser::resolveStyleSheetImports(const QCss::StyleSheet &sheet) { for (int i = 0; i < sheet.importRules.count(); ++i) { const QCss::ImportRule &rule = sheet.importRules.at(i); - if (rule.media.isEmpty() - || rule.media.contains(QLatin1String("screen"), Qt::CaseInsensitive)) + if (rule.media.isEmpty() || rule.media.contains("screen"_L1, Qt::CaseInsensitive)) importStyleSheet(rule.href); } } @@ -1977,13 +1972,13 @@ QList<QCss::Declaration> standardDeclarationForNode(const QTextHtmlParserNode &n if (node.id == Html_a) { for (int i = 0; i < node.attributes.count(); i += 2) { const QString key = node.attributes.at(i); - if (key.compare(QLatin1String("href"), Qt::CaseInsensitive) == 0 + if (key.compare("href"_L1, Qt::CaseInsensitive) == 0 && !node.attributes.at(i + 1).isEmpty()) { needsUnderline = true; - decl.d->property = QLatin1String("color"); + decl.d->property = "color"_L1; decl.d->propertyId = QCss::Color; val.type = QCss::Value::Function; - val.variant = QStringList() << QLatin1String("palette") << QLatin1String("link"); + val.variant = QStringList() << "palette"_L1 << "link"_L1; decl.d->values = QList<QCss::Value> { val }; decl.d->inheritable = true; decls << decl; @@ -1993,7 +1988,7 @@ QList<QCss::Declaration> standardDeclarationForNode(const QTextHtmlParserNode &n } if (needsUnderline) { decl = QCss::Declaration(); - decl.d->property = QLatin1String("text-decoration"); + decl.d->property = "text-decoration"_L1; decl.d->propertyId = QCss::TextDecoration; val.type = QCss::Value::KnownIdentifier; val.variant = QVariant(QCss::Value_Underline); @@ -2012,7 +2007,7 @@ QList<QCss::Declaration> standardDeclarationForNode(const QTextHtmlParserNode &n case Html_h5: case Html_th: decl = QCss::Declaration(); - decl.d->property = QLatin1String("font-weight"); + decl.d->property = "font-weight"_L1; decl.d->propertyId = QCss::FontWeight; val.type = QCss::Value::KnownIdentifier; val.variant = QVariant(QCss::Value_Bold); @@ -2026,7 +2021,7 @@ QList<QCss::Declaration> standardDeclarationForNode(const QTextHtmlParserNode &n case Html_small: if (node.id != Html_th) { decl = QCss::Declaration(); - decl.d->property = QLatin1String("font-size"); + decl.d->property = "font-size"_L1; decl.d->propertyId = QCss::FontSize; decl.d->inheritable = false; val.type = QCss::Value::KnownIdentifier; @@ -2046,7 +2041,7 @@ QList<QCss::Declaration> standardDeclarationForNode(const QTextHtmlParserNode &n case Html_center: case Html_td: decl = QCss::Declaration(); - decl.d->property = QLatin1String("text-align"); + decl.d->property = "text-align"_L1; decl.d->propertyId = QCss::TextAlignment; val.type = QCss::Value::KnownIdentifier; val.variant = (node.id == Html_td) ? QVariant(QCss::Value_Left) : QVariant(QCss::Value_Center); @@ -2056,7 +2051,7 @@ QList<QCss::Declaration> standardDeclarationForNode(const QTextHtmlParserNode &n break; case Html_s: decl = QCss::Declaration(); - decl.d->property = QLatin1String("text-decoration"); + decl.d->property = "text-decoration"_L1; decl.d->propertyId = QCss::TextDecoration; val.type = QCss::Value::KnownIdentifier; val.variant = QVariant(QCss::Value_LineThrough); @@ -2071,7 +2066,7 @@ QList<QCss::Declaration> standardDeclarationForNode(const QTextHtmlParserNode &n case Html_var: case Html_dfn: decl = QCss::Declaration(); - decl.d->property = QLatin1String("font-style"); + decl.d->property = "font-style"_L1; decl.d->propertyId = QCss::FontStyle; val.type = QCss::Value::KnownIdentifier; val.variant = QVariant(QCss::Value_Italic); @@ -2082,7 +2077,7 @@ QList<QCss::Declaration> standardDeclarationForNode(const QTextHtmlParserNode &n case Html_sub: case Html_sup: decl = QCss::Declaration(); - decl.d->property = QLatin1String("vertical-align"); + decl.d->property = "vertical-align"_L1; decl.d->propertyId = QCss::VerticalAlignment; val.type = QCss::Value::KnownIdentifier; val.variant = (node.id == Html_sub) ? QVariant(QCss::Value_Sub) : QVariant(QCss::Value_Super); @@ -2093,7 +2088,7 @@ QList<QCss::Declaration> standardDeclarationForNode(const QTextHtmlParserNode &n case Html_ul: case Html_ol: decl = QCss::Declaration(); - decl.d->property = QLatin1String("list-style"); + decl.d->property = "list-style"_L1; decl.d->propertyId = QCss::ListStyle; val.type = QCss::Value::KnownIdentifier; val.variant = (node.id == Html_ul) ? QVariant(QCss::Value_Disc) : QVariant(QCss::Value_Decimal); @@ -2107,7 +2102,7 @@ QList<QCss::Declaration> standardDeclarationForNode(const QTextHtmlParserNode &n case Html_samp: case Html_pre: { decl = QCss::Declaration(); - decl.d->property = QLatin1String("font-family"); + decl.d->property = "font-family"_L1; decl.d->propertyId = QCss::FontFamily; QList<QCss::Value> values; val.type = QCss::Value::String; @@ -2123,7 +2118,7 @@ QList<QCss::Declaration> standardDeclarationForNode(const QTextHtmlParserNode &n case Html_br: case Html_nobr: decl = QCss::Declaration(); - decl.d->property = QLatin1String("whitespace"); + decl.d->property = "whitespace"_L1; decl.d->propertyId = QCss::Whitespace; val.type = QCss::Value::KnownIdentifier; switch (node.id) { @@ -2161,7 +2156,7 @@ QList<QCss::Declaration> QTextHtmlParser::declarationsForNode(int node) const for (int i = 0; i < inlineStyleSheets.count(); ++i, ++idx) selector.styleSheets[idx] = inlineStyleSheets.at(i); - selector.medium = resourceProvider ? resourceProvider->metaInformation(QTextDocument::CssMedia) : QLatin1String("screen"); + selector.medium = resourceProvider ? resourceProvider->metaInformation(QTextDocument::CssMedia) : "screen"_L1; QCss::StyleSelector::NodePtr n; n.id = node; diff --git a/src/gui/text/qtextimagehandler.cpp b/src/gui/text/qtextimagehandler.cpp index 2872366208..e6e1d8b164 100644 --- a/src/gui/text/qtextimagehandler.cpp +++ b/src/gui/text/qtextimagehandler.cpp @@ -51,13 +51,15 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + extern QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio, qreal *sourceDevicePixelRatio); static inline QUrl fromLocalfileOrResources(QString path) { - if (path.startsWith(QLatin1String(":/"))) // auto-detect resources and convert them to url - path.prepend(QLatin1String("qrc")); + if (path.startsWith(":/"_L1)) // auto-detect resources and convert them to url + path.prepend("qrc"_L1); return QUrl(path); } @@ -78,13 +80,13 @@ static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format, con if (pm.isNull()) { QImage img; if (name.isEmpty() || !img.load(name)) - return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png")); + return QPixmap(":/qt-project.org/styles/commonstyle/images/file-16.png"_L1); pm = QPixmap::fromImage(img); doc->addResource(QTextDocument::ImageResource, url, pm); } - if (name.contains(QLatin1String("@2x"))) + if (name.contains("@2x"_L1)) pm.setDevicePixelRatio(sourcePixelRatio); return pm; @@ -147,7 +149,7 @@ static QImage getImage(QTextDocument *doc, const QTextImageFormat &format, const if (image.isNull()) { if (name.isEmpty() || !image.load(name)) - return QImage(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png")); + return QImage(":/qt-project.org/styles/commonstyle/images/file-16.png"_L1); doc->addResource(QTextDocument::ImageResource, url, image); } diff --git a/src/gui/text/qtextlist.cpp b/src/gui/text/qtextlist.cpp index c9bbe687b2..3a48e92414 100644 --- a/src/gui/text/qtextlist.cpp +++ b/src/gui/text/qtextlist.cpp @@ -46,6 +46,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + class QTextListPrivate : public QTextBlockGroupPrivate { public: @@ -179,7 +181,7 @@ QString QTextList::itemText(const QTextBlock &blockIt) const const int style = format().style(); QString numberPrefix; - QString numberSuffix = QLatin1String("."); + QString numberSuffix = "."_L1; if (format().hasProperty(QTextFormat::ListNumberPrefix)) numberPrefix = format().numberPrefix(); @@ -248,7 +250,7 @@ QString QTextList::itemText(const QTextBlock &blockIt) const result = QString::fromLatin1(romanNumeral); } else { - result = QLatin1String("?"); + result = "?"_L1; } } diff --git a/src/gui/text/qtextmarkdownimporter.cpp b/src/gui/text/qtextmarkdownimporter.cpp index a0f7cb2857..23a851bece 100644 --- a/src/gui/text/qtextmarkdownimporter.cpp +++ b/src/gui/text/qtextmarkdownimporter.cpp @@ -56,6 +56,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + Q_LOGGING_CATEGORY(lcMD, "qt.text.markdown") static const QChar Newline = u'\n'; @@ -559,12 +561,12 @@ int QTextMarkdownImporter::cbText(int textType, const char *text, unsigned size) QTextBlockFormat bfmt = m_cursor->blockFormat(); QString debugInfo; if (m_cursor->currentList()) - debugInfo = QLatin1String("in list at depth ") + QString::number(m_cursor->currentList()->format().indent()); + debugInfo = "in list at depth "_L1 + QString::number(m_cursor->currentList()->format().indent()); if (bfmt.hasProperty(QTextFormat::BlockQuoteLevel)) - debugInfo += QLatin1String("in blockquote at depth ") + + debugInfo += "in blockquote at depth "_L1 + QString::number(bfmt.intProperty(QTextFormat::BlockQuoteLevel)); if (bfmt.hasProperty(QTextFormat::BlockCodeLanguage)) - debugInfo += QLatin1String("in a code block"); + debugInfo += "in a code block"_L1; qCDebug(lcMD) << textType << "in block" << m_blockType << s << qPrintable(debugInfo) << "bindent" << bfmt.indent() << "tindent" << bfmt.textIndent() << "margins" << bfmt.leftMargin() << bfmt.topMargin() << bfmt.bottomMargin() << bfmt.rightMargin(); diff --git a/src/gui/text/qtextmarkdownwriter.cpp b/src/gui/text/qtextmarkdownwriter.cpp index 1d4d82087e..81684c606a 100644 --- a/src/gui/text/qtextmarkdownwriter.cpp +++ b/src/gui/text/qtextmarkdownwriter.cpp @@ -53,6 +53,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + Q_LOGGING_CATEGORY(lcMDW, "qt.text.markdown.writer") static const QChar Space = u' '; @@ -442,7 +444,7 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign if (!m_fencedCodeBlock) { QString fenceChar = blockFmt.stringProperty(QTextFormat::BlockCodeFence); if (fenceChar.isEmpty()) - fenceChar = QLatin1String("`"); + fenceChar = "`"_L1; m_codeBlockFence = QString(3, fenceChar.at(0)); if (blockFmt.hasProperty(QTextFormat::BlockIndent)) m_codeBlockFence = QString(m_wrappedLineIndent, Space) + m_codeBlockFence; @@ -504,8 +506,8 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign QTextImageFormat ifmt = fmt.toImageFormat(); QString desc = ifmt.stringProperty(QTextFormat::ImageAltText); if (desc.isEmpty()) - desc = QLatin1String("image"); - QString s = QLatin1String("![") + desc + QLatin1String("](") + ifmt.name(); + desc = "image"_L1; + QString s = "!["_L1 + desc + "]("_L1 + ifmt.name(); QString title = ifmt.stringProperty(QTextFormat::ImageTitle); if (!title.isEmpty()) s += Space + DoubleQuote + title + DoubleQuote; @@ -517,7 +519,7 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign m_stream << s; col += s.length(); } else if (fmt.hasProperty(QTextFormat::AnchorHref)) { - QString s = u'[' + fragmentText + QLatin1String("](") + + QString s = u'[' + fragmentText + "]("_L1 + fmt.property(QTextFormat::AnchorHref).toString(); if (fmt.hasProperty(QTextFormat::TextToolTip)) { s += Space; @@ -545,7 +547,7 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign } if (!blockFmt.headingLevel() && !mono) { if (fontInfo.bold() != bold) { - markers += QLatin1String("**"); + markers += "**"_L1; bold = fontInfo.bold(); } if (fontInfo.italic() != italic) { @@ -553,7 +555,7 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign italic = fontInfo.italic(); } if (fontInfo.strikeOut() != strikeOut) { - markers += QLatin1String("~~"); + markers += "~~"_L1; strikeOut = fontInfo.strikeOut(); } if (fontInfo.underline() != underline) { diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp index 4e3e8a6fd9..66699a4655 100644 --- a/src/gui/text/qtextodfwriter.cpp +++ b/src/gui/text/qtextodfwriter.cpp @@ -60,11 +60,13 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + /// Convert pixels to postscript point units static QString pixelToPoint(qreal pixels) { // we hardcode 96 DPI, we do the same in the ODF importer to have a perfect roundtrip. - return QString::number(pixels * 72 / 96) + QLatin1String("pt"); + return QString::number(pixels * 72 / 96) + "pt"_L1; } // strategies @@ -454,8 +456,8 @@ void QTextOdfWriter::writeInlineCharacter(QXmlStreamWriter &writer, const QTextF QImage image; QString name = imageFormat.name(); - if (name.startsWith(QLatin1String(":/"))) // auto-detect resources - name.prepend(QLatin1String("qrc")); + if (name.startsWith(":/"_L1)) // auto-detect resources + name.prepend("qrc"_L1); QUrl url = QUrl(name); const QVariant variant = m_document->resource(QTextDocument::ImageResource, url); if (variant.userType() == QMetaType::QPixmap || variant.userType() == QMetaType::QImage) { @@ -867,7 +869,7 @@ void QTextOdfWriter::writeTableFormat(QXmlStreamWriter &writer, QTextTableFormat writer.writeAttribute(tableNS, QString::fromLatin1("align"), QString::fromLatin1(align)); if (format.width().rawValue()) { writer.writeAttribute(styleNS, QString::fromLatin1("width"), - QString::number(format.width().rawValue()) + QLatin1String("pt")); + QString::number(format.width().rawValue()) + "pt"_L1); } writer.writeEndElement(); // start writing table-column style element @@ -883,14 +885,14 @@ void QTextOdfWriter::writeTableFormat(QXmlStreamWriter &writer, QTextTableFormat QString columnWidth; if (format.columnWidthConstraints().at(colit).type() == QTextLength::PercentageLength) { columnWidth = QString::number(format.columnWidthConstraints().at(colit).rawValue()) - + QLatin1String("%"); + + "%"_L1; } else if (format.columnWidthConstraints().at(colit).type() == QTextLength::FixedLength) { columnWidth = QString::number(format.columnWidthConstraints().at(colit).rawValue()) - + QLatin1String("pt"); + + "pt"_L1; } else { //!! HARD-CODING variableWidth Constraints to 100% / nr constraints columnWidth = QString::number(100 / format.columnWidthConstraints().size()) - + QLatin1String("%"); + + "%"_L1; } writer.writeAttribute(styleNS, QString::fromLatin1("column-width"), columnWidth); writer.writeEndElement(); @@ -932,8 +934,8 @@ void QTextOdfWriter::tableCellStyleElement(QXmlStreamWriter &writer, const int & writer.writeEmptyElement(styleNS, QString::fromLatin1("table-cell-properties")); if (hasBorder) { writer.writeAttribute(foNS, QString::fromLatin1("border"), - pixelToPoint(tableFormatTmp.border()) + QLatin1String(" ") - + borderStyleName(tableFormatTmp.borderStyle()) + QLatin1String(" ") + pixelToPoint(tableFormatTmp.border()) + " "_L1 + + borderStyleName(tableFormatTmp.borderStyle()) + " "_L1 + tableFormatTmp.borderBrush().color().name(QColor::HexRgb)); } qreal topPadding = format.topPadding(); @@ -984,14 +986,14 @@ void QTextOdfWriter::tableCellStyleElement(QXmlStreamWriter &writer, const int & /////////////////////// QTextOdfWriter::QTextOdfWriter(const QTextDocument &document, QIODevice *device) - : officeNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:office:1.0")), - textNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:text:1.0")), - styleNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:style:1.0")), - foNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0")), - tableNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:table:1.0")), - drawNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:drawing:1.0")), - xlinkNS (QLatin1String("http://www.w3.org/1999/xlink")), - svgNS (QLatin1String("urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0")), + : officeNS ("urn:oasis:names:tc:opendocument:xmlns:office:1.0"_L1), + textNS ("urn:oasis:names:tc:opendocument:xmlns:text:1.0"_L1), + styleNS ("urn:oasis:names:tc:opendocument:xmlns:style:1.0"_L1), + foNS ("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"_L1), + tableNS ("urn:oasis:names:tc:opendocument:xmlns:table:1.0"_L1), + drawNS ("urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"_L1), + xlinkNS ("http://www.w3.org/1999/xlink"_L1), + svgNS ("urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"_L1), m_document(&document), m_device(device), m_strategy(nullptr), diff --git a/src/gui/text/qtexttable.cpp b/src/gui/text/qtexttable.cpp index 1db6ff897f..8c186420fb 100644 --- a/src/gui/text/qtexttable.cpp +++ b/src/gui/text/qtexttable.cpp @@ -50,6 +50,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + /*! \class QTextTableCell \reentrant @@ -1110,7 +1112,7 @@ void QTextTable::mergeCells(int row, int column, int numRows, int numCols) QTextCursorPrivate::fromPosition(p, insertPos++).insertBlock(); p->move(pos + 1, insertPos, nextPos - pos); } else if (rowHasText) { - QTextCursorPrivate::fromPosition(p, insertPos++).insertText(QLatin1String(" ")); + QTextCursorPrivate::fromPosition(p, insertPos++).insertText(" "_L1); p->move(pos + 1, insertPos, nextPos - pos); } else { p->move(pos, insertPos, nextPos - pos); diff --git a/src/gui/text/windows/qwindowsfontdatabase.cpp b/src/gui/text/windows/qwindowsfontdatabase.cpp index 8bac0eda41..039f6f5540 100644 --- a/src/gui/text/windows/qwindowsfontdatabase.cpp +++ b/src/gui/text/windows/qwindowsfontdatabase.cpp @@ -67,6 +67,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #if QT_CONFIG(directwrite) static inline bool useDirectWrite(QFont::HintingPreference hintingPreference, const QString &familyName = QString(), @@ -78,7 +80,7 @@ static inline bool useDirectWrite(QFont::HintingPreference hintingPreference, // At some scales, GDI will misrender the MingLiU font, so we force use of // DirectWrite to work around the issue. - if (Q_UNLIKELY(familyName.startsWith(QLatin1String("MingLiU")))) + if (Q_UNLIKELY(familyName.startsWith("MingLiU"_L1))) return true; if (isColorFont) @@ -509,7 +511,7 @@ static bool addFontToDatabase(QString familyName, StoreFontPayload *sfp) { // the "@family" fonts are just the same as "family". Ignore them. - if (familyName.isEmpty() || familyName.at(0) == u'@' || familyName.startsWith(QLatin1String("WST_"))) + if (familyName.isEmpty() || familyName.at(0) == u'@' || familyName.startsWith("WST_"_L1)) return false; uchar charSet = logFont.lfCharSet; @@ -584,7 +586,7 @@ static bool addFontToDatabase(QString familyName, // display Thai text by default. As a temporary work around, we special case Segoe UI // and remove the Thai script from its list of supported writing systems. if (writingSystems.supported(QFontDatabase::Thai) && - familyName == QLatin1String("Segoe UI")) + familyName == "Segoe UI"_L1) writingSystems.setSupported(QFontDatabase::Thai, false); } else { const QFontDatabase::WritingSystem ws = writingSystemFromCharSet(charSet); diff --git a/src/gui/text/windows/qwindowsfontdatabase_ft.cpp b/src/gui/text/windows/qwindowsfontdatabase_ft.cpp index 6258535ac7..ce69cb4fc0 100644 --- a/src/gui/text/windows/qwindowsfontdatabase_ft.cpp +++ b/src/gui/text/windows/qwindowsfontdatabase_ft.cpp @@ -60,6 +60,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + static inline QFontDatabase::WritingSystem writingSystemFromCharSet(uchar charSet) { switch (charSet) { @@ -176,7 +178,7 @@ static bool addFontToDatabase(QString familyName, int type) { // the "@family" fonts are just the same as "family". Ignore them. - if (familyName.isEmpty() || familyName.at(0) == u'@' || familyName.startsWith(QLatin1String("WST_"))) + if (familyName.isEmpty() || familyName.at(0) == u'@' || familyName.startsWith("WST_"_L1)) return false; uchar charSet = logFont.lfCharSet; @@ -242,8 +244,7 @@ static bool addFontToDatabase(QString familyName, // Since it's the default UI font on this platform, most widgets will be unable to // display Thai text by default. As a temporary work around, we special case Segoe UI // and remove the Thai script from its list of supported writing systems. - if (writingSystems.supported(QFontDatabase::Thai) && - faceName == QLatin1String("Segoe UI")) + if (writingSystems.supported(QFontDatabase::Thai) && faceName == "Segoe UI"_L1) writingSystems.setSupported(QFontDatabase::Thai, false); } else { const QFontDatabase::WritingSystem ws = writingSystemFromCharSet(charSet); @@ -259,8 +260,8 @@ static bool addFontToDatabase(QString familyName, QLocale systemLocale = QLocale::system(); if (systemLocale.language() != QLocale::C && systemLocale.language() != QLocale::English - && styleName != QLatin1String("Italic") - && styleName != QLatin1String("Bold")) { + && styleName != "Italic"_L1 + && styleName != "Bold"_L1) { key = findFontKey(qt_getEnglishName(fullName, true), &index); } if (!key) @@ -431,7 +432,7 @@ QStringList QWindowsFontDatabaseFT::fallbacksForFamily(const QString &family, QF } QString QWindowsFontDatabaseFT::fontDir() const { - const QString result = QLatin1String(qgetenv("windir")) + QLatin1String("/Fonts");//QPlatformFontDatabase::fontDir(); + const QString result = QLatin1String(qgetenv("windir")) + "/Fonts"_L1;//QPlatformFontDatabase::fontDir(); qCDebug(lcQpaFonts) << __FUNCTION__ << result; return result; } diff --git a/src/gui/text/windows/qwindowsfontdatabasebase.cpp b/src/gui/text/windows/qwindowsfontdatabasebase.cpp index 566941eca9..9d0797da1c 100644 --- a/src/gui/text/windows/qwindowsfontdatabasebase.cpp +++ b/src/gui/text/windows/qwindowsfontdatabasebase.cpp @@ -55,6 +55,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + // Helper classes for creating font engines directly from font data namespace { @@ -940,7 +942,7 @@ QFontDef QWindowsFontDatabaseBase::sanitizeRequest(QFontDef request) const if (fam.isEmpty()) req.families[0] = QStringLiteral("MS Sans Serif"); - if (fam == QLatin1String("MS Sans Serif")) { + if (fam == "MS Sans Serif"_L1) { int height = -qRound(request.pixelSize); // MS Sans Serif has bearing problems in italic, and does not scale if (request.style == QFont::StyleItalic || (height > 18 && height != 24)) |