summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/text/freetype/qfreetypefontdatabase.cpp2
-rw-r--r--src/gui/text/qcssparser.cpp2
-rw-r--r--src/gui/text/qfont.cpp111
-rw-r--r--src/gui/text/qfont.h23
-rw-r--r--src/gui/text/qfont_p.h37
-rw-r--r--src/gui/text/qfontdatabase.cpp2
-rw-r--r--src/gui/text/qfontdatabase_p.h2
-rw-r--r--src/gui/text/qplatformfontdatabase.cpp29
-rw-r--r--src/gui/text/qplatformfontdatabase.h1
-rw-r--r--src/gui/text/qtextdocument.cpp4
-rw-r--r--src/gui/text/qtextformat.cpp2
-rw-r--r--src/gui/text/qtextodfwriter.cpp2
-rw-r--r--src/gui/text/unix/qfontconfigdatabase.cpp9
-rw-r--r--src/gui/text/windows/qwindowsdirectwritefontdatabase.cpp2
-rw-r--r--src/gui/text/windows/qwindowsfontdatabase.cpp6
-rw-r--r--src/gui/text/windows/qwindowsfontdatabase_ft.cpp2
-rw-r--r--src/gui/text/windows/qwindowsfontdatabasebase.cpp8
-rw-r--r--src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp3
-rw-r--r--src/tools/uic/cpp/cppwriteinitialization.cpp53
-rw-r--r--src/tools/uic/ui4.cpp13
-rw-r--r--src/tools/uic/ui4.h13
-rw-r--r--tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp4
-rw-r--r--tests/auto/gui/text/qfont/tst_qfont.cpp16
-rw-r--r--tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp55
-rw-r--r--tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp4
-rw-r--r--tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp2
-rw-r--r--tests/auto/other/lancelot/scripts/gradientxform_device.qps2
-rw-r--r--tests/auto/other/lancelot/scripts/gradientxform_logical.qps2
-rw-r--r--tests/auto/other/lancelot/scripts/gradientxform_object.qps2
-rw-r--r--tests/auto/tools/uic/baseline/authenticationdialog.ui.h2
30 files changed, 263 insertions, 152 deletions
diff --git a/src/gui/text/freetype/qfreetypefontdatabase.cpp b/src/gui/text/freetype/qfreetypefontdatabase.cpp
index c0b93389c6..ac7520c495 100644
--- a/src/gui/text/freetype/qfreetypefontdatabase.cpp
+++ b/src/gui/text/freetype/qfreetypefontdatabase.cpp
@@ -169,7 +169,7 @@ QStringList QFreeTypeFontDatabase::addTTFile(const QByteArray &fontData, const Q
writingSystems = QPlatformFontDatabase::writingSystemsFromTrueTypeBits(unicodeRange, codePageRange);
if (os2->usWeightClass) {
- weight = QPlatformFontDatabase::weightFromInteger(os2->usWeightClass);
+ weight = static_cast<QFont::Weight>(os2->usWeightClass);
} else if (os2->panose[2]) {
int w = os2->panose[2];
if (w <= 1)
diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp
index 86d3f77fee..f67c0f485a 100644
--- a/src/gui/text/qcssparser.cpp
+++ b/src/gui/text/qcssparser.cpp
@@ -1192,7 +1192,7 @@ static bool setFontWeightFromValue(const QCss::Value &value, QFont *font)
}
if (value.type != Value::Number)
return false;
- font->setWeight(qMin(value.variant.toInt() / 8, 99));
+ font->setWeight(QFont::Weight(value.variant.toInt()));
return true;
}
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp
index a618179f98..195904a4b1 100644
--- a/src/gui/text/qfont.cpp
+++ b/src/gui/text/qfont.cpp
@@ -179,6 +179,47 @@ Q_GUI_EXPORT int qt_defaultDpi()
return qt_defaultDpiY();
}
+/* Helper function to convert between legacy Qt and OpenType font weights. */
+static int convertWeights(int weight, bool inverted)
+{
+ static const QVarLengthArray<QPair<int, int>, 9> legacyToOpenTypeMap = {
+ { 0, QFont::Thin }, { 12, QFont::ExtraLight }, { 25, QFont::Light },
+ { 50, QFont::Normal }, { 57, QFont::Medium }, { 63, QFont::DemiBold },
+ { 75, QFont::Bold }, { 81, QFont::ExtraBold }, { 87, QFont::Black },
+ };
+
+ int closestDist = INT_MAX;
+ int result = -1;
+
+ // Go through and find the closest mapped value
+ for (auto mapping : legacyToOpenTypeMap) {
+ const int weightOld = inverted ? mapping.second : mapping.first;
+ const int weightNew = inverted ? mapping.first : mapping.second;
+ const int dist = qAbs(weightOld - weight);
+ if (dist < closestDist) {
+ result = weightNew;
+ closestDist = dist;
+ } else {
+ // Break early since following values will be further away
+ break;
+ }
+ }
+
+ return result;
+}
+
+/* Converts from legacy Qt font weight (Qt < 6.0) to OpenType font weight (Qt >= 6.0) */
+Q_GUI_EXPORT int qt_legacyToOpenTypeWeight(int weight)
+{
+ return convertWeights(weight, false);
+}
+
+/* Converts from OpenType font weight (Qt >= 6.0) to legacy Qt font weight (Qt < 6.0) */
+Q_GUI_EXPORT int qt_openTypeToLegacyWeight(int weight)
+{
+ return convertWeights(weight, true);
+}
+
QFontPrivate::QFontPrivate()
: engineData(nullptr), dpi(qt_defaultDpi()),
underline(false), overline(false), strikeOut(false), kerning(true),
@@ -1066,29 +1107,28 @@ void QFont::setStyle(Style style)
\sa setWeight(), Weight, QFontInfo
*/
-int QFont::weight() const
+QFont::Weight QFont::weight() const
{
- return d->request.weight;
+ return static_cast<Weight>(d->request.weight);
}
/*!
\enum QFont::Weight
- Qt uses a weighting scale from 0 to 99 similar to, but not the
- same as, the scales used in Windows or CSS. A weight of 0 will be
- thin, whilst 99 will be extremely black.
+ Qt uses a weighting scale from 1 to 1000 compatible with OpenType. A weight of 1 will be
+ thin, whilst 1000 will be extremely black.
This enum contains the predefined font weights:
- \value Thin 0
- \value ExtraLight 12
- \value Light 25
- \value Normal 50
- \value Medium 57
- \value DemiBold 63
- \value Bold 75
- \value ExtraBold 81
- \value Black 87
+ \value Thin 100
+ \value ExtraLight 200
+ \value Light 300
+ \value Normal 400
+ \value Medium 500
+ \value DemiBold 600
+ \value Bold 700
+ \value ExtraBold 800
+ \value Black 900
*/
/*!
@@ -1099,16 +1139,20 @@ int QFont::weight() const
\sa weight(), QFontInfo
*/
-void QFont::setWeight(int weight)
+void QFont::setWeight(QFont::Weight weight)
{
- Q_ASSERT_X(weight >= 0 && weight <= 99, "QFont::setWeight", "Weight must be between 0 and 99");
+ const int weightValue = qBound(QFONT_WEIGHT_MIN, static_cast<int>(weight), QFONT_WEIGHT_MAX);
+ if (weightValue != static_cast<int>(weight)) {
+ qWarning() << "QFont::setWeight: Weight must be between 1 and 1000, attempted to set "
+ << static_cast<int>(weight);
+ }
- if ((resolve_mask & QFont::WeightResolved) && d->request.weight == weight)
+ if ((resolve_mask & QFont::WeightResolved) && d->request.weight == weightValue)
return;
detach();
- d->request.weight = weight;
+ d->request.weight = weightValue;
resolve_mask |= QFont::WeightResolved;
}
@@ -2040,7 +2084,7 @@ bool QFont::fromString(const QString &descrip)
setPointSizeF(l[1].toDouble());
if (count == 9) {
setStyleHint((StyleHint) l[2].toInt());
- setWeight(qMax(qMin(99, l[3].toInt()), 0));
+ setWeight(QFont::Weight(l[3].toInt()));
setItalic(l[4].toInt());
setUnderline(l[5].toInt());
setStrikeOut(l[6].toInt());
@@ -2049,7 +2093,7 @@ bool QFont::fromString(const QString &descrip)
if (l[2].toInt() > 0)
setPixelSize(l[2].toInt());
setStyleHint((StyleHint) l[3].toInt());
- setWeight(qMax(qMin(99, l[4].toInt()), 0));
+ setWeight(QFont::Weight(l[4].toInt()));
setStyle((QFont::Style)l[5].toInt());
setUnderline(l[6].toInt());
setStrikeOut(l[7].toInt());
@@ -2214,9 +2258,13 @@ QDataStream &operator<<(QDataStream &s, const QFont &font)
else
s << (quint8) font.d->request.styleStrategy;
}
- s << (quint8) 0
- << (quint8) font.d->request.weight
- << get_font_bits(s.version(), font.d.data());
+
+ if (s.version() < QDataStream::Qt_6_0)
+ s << quint8(0) << quint8(qt_openTypeToLegacyWeight(font.d->request.weight));
+ else
+ s << quint16(font.d->request.weight);
+
+ s << get_font_bits(s.version(), font.d.data());
if (s.version() >= QDataStream::Qt_4_3)
s << (quint16)font.d->request.stretch;
if (s.version() >= QDataStream::Qt_4_4)
@@ -2248,7 +2296,7 @@ QDataStream &operator>>(QDataStream &s, QFont &font)
font.d = new QFontPrivate;
font.resolve_mask = QFont::AllPropertiesResolved;
- quint8 styleHint, charSet, weight, bits;
+ quint8 styleHint, bits;
quint16 styleStrategy = QFont::PreferDefault;
if (s.version() == 1) {
@@ -2288,13 +2336,22 @@ QDataStream &operator>>(QDataStream &s, QFont &font)
}
}
- s >> charSet;
- s >> weight;
+ if (s.version() < QDataStream::Qt_6_0) {
+ quint8 charSet;
+ quint8 weight;
+ s >> charSet;
+ s >> weight;
+ font.d->request.weight = qt_legacyToOpenTypeWeight(weight);
+ } else {
+ quint16 weight;
+ s >> weight;
+ font.d->request.weight = weight;
+ }
+
s >> bits;
font.d->request.styleHint = styleHint;
font.d->request.styleStrategy = styleStrategy;
- font.d->request.weight = weight;
set_font_bits(s.version(), bits, font.d.data());
diff --git a/src/gui/text/qfont.h b/src/gui/text/qfont.h
index b520421e89..65d126374e 100644
--- a/src/gui/text/qfont.h
+++ b/src/gui/text/qfont.h
@@ -94,17 +94,16 @@ public:
};
Q_ENUM(HintingPreference)
- // Mapping OpenType weight value.
enum Weight {
- Thin = 0, // 100
- ExtraLight = 12, // 200
- Light = 25, // 300
- Normal = 50, // 400
- Medium = 57, // 500
- DemiBold = 63, // 600
- Bold = 75, // 700
- ExtraBold = 81, // 800
- Black = 87 // 900
+ Thin = 100,
+ ExtraLight = 200,
+ Light = 300,
+ Normal = 400,
+ Medium = 500,
+ DemiBold = 600,
+ Bold = 700,
+ ExtraBold = 800,
+ Black = 900
};
Q_ENUM(Weight)
@@ -197,8 +196,8 @@ public:
int pixelSize() const;
void setPixelSize(int);
- int weight() const;
- void setWeight(int);
+ Weight weight() const;
+ void setWeight(Weight weight);
inline bool bold() const;
inline void setBold(bool);
diff --git a/src/gui/text/qfont_p.h b/src/gui/text/qfont_p.h
index d2d240b134..abf6d000e7 100644
--- a/src/gui/text/qfont_p.h
+++ b/src/gui/text/qfont_p.h
@@ -66,14 +66,24 @@ QT_BEGIN_NAMESPACE
class QFontCache;
class QFontEngine;
+#define QFONT_WEIGHT_MIN 1
+#define QFONT_WEIGHT_MAX 1000
+
struct QFontDef
{
inline QFontDef()
- : pointSize(-1.0), pixelSize(-1),
- styleStrategy(QFont::PreferDefault), styleHint(QFont::AnyStyle),
- weight(50), fixedPitch(false), style(QFont::StyleNormal), stretch(QFont::AnyStretch),
- hintingPreference(QFont::PreferDefaultHinting), ignorePitch(true),
- fixedPitchComputed(0), reserved(0)
+ : pointSize(-1.0),
+ pixelSize(-1),
+ styleStrategy(QFont::PreferDefault),
+ stretch(QFont::AnyStretch),
+ style(QFont::StyleNormal),
+ hintingPreference(QFont::PreferDefaultHinting),
+ styleHint(QFont::AnyStyle),
+ weight(QFont::Normal),
+ fixedPitch(false),
+ ignorePitch(true),
+ fixedPitchComputed(0),
+ reserved(0)
{
}
@@ -86,18 +96,18 @@ struct QFontDef
qreal pointSize;
qreal pixelSize;
+ // Note: Variable ordering matters to make sure no variable overlaps two 32-bit registers.
uint styleStrategy : 16;
- uint styleHint : 8;
+ uint stretch : 12; // 0-4000
+ uint style : 2;
+ uint hintingPreference : 2;
- uint weight : 7; // 0-99
+ uint styleHint : 8;
+ uint weight : 10; // 1-1000
uint fixedPitch : 1;
- uint style : 2;
- uint stretch : 12; // 0-4000
-
- uint hintingPreference : 2;
uint ignorePitch : 1;
uint fixedPitchComputed : 1; // for Mac OS X only
- uint reserved : 14; // for future extensions
+ uint reserved : 11; // for future extensions
bool exactMatch(const QFontDef &other) const;
bool operator==(const QFontDef &other) const
@@ -297,6 +307,9 @@ Q_GUI_EXPORT int qt_defaultDpiX();
Q_GUI_EXPORT int qt_defaultDpiY();
Q_GUI_EXPORT int qt_defaultDpi();
+Q_GUI_EXPORT int qt_legacyToOpenTypeWeight(int weight);
+Q_GUI_EXPORT int qt_openTypeToLegacyWeight(int weight);
+
QT_END_NAMESPACE
#endif // QFONT_P_H
diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp
index 550215ee64..1afaedaa09 100644
--- a/src/gui/text/qfontdatabase.cpp
+++ b/src/gui/text/qfontdatabase.cpp
@@ -888,7 +888,7 @@ static QtFontStyle *bestStyle(QtFontFoundry *foundry, const QtFontStyle::Key &st
break;
}
- int d = qAbs( styleKey.weight - style->key.weight );
+ int d = qAbs( (int(styleKey.weight) - int(style->key.weight)) / 10 );
if ( styleKey.stretch != 0 && style->key.stretch != 0 ) {
d += qAbs( styleKey.stretch - style->key.stretch );
diff --git a/src/gui/text/qfontdatabase_p.h b/src/gui/text/qfontdatabase_p.h
index f60671ccb3..6b7d9c2f47 100644
--- a/src/gui/text/qfontdatabase_p.h
+++ b/src/gui/text/qfontdatabase_p.h
@@ -113,7 +113,7 @@ struct Q_GUI_EXPORT QtFontStyle
{}
uint style : 2;
- signed int weight : 8;
+ uint weight : 10;
signed int stretch : 12;
bool operator==(const Key &other) const noexcept
diff --git a/src/gui/text/qplatformfontdatabase.cpp b/src/gui/text/qplatformfontdatabase.cpp
index e101f8b3e5..d54bda4941 100644
--- a/src/gui/text/qplatformfontdatabase.cpp
+++ b/src/gui/text/qplatformfontdatabase.cpp
@@ -603,35 +603,6 @@ QSupportedWritingSystems QPlatformFontDatabase::writingSystemsFromTrueTypeBits(q
}
/*!
- Helper function that returns the Qt font weight matching
- a given opentype integer value. Converts the integer
- \a weight (0 ~ 1000) to QFont::Weight and returns it.
-
- \since 5.5
-*/
-
-QFont::Weight QPlatformFontDatabase::weightFromInteger(int weight)
-{
- if (weight < 150)
- return QFont::Thin;
- if (weight < 250)
- return QFont::ExtraLight;
- if (weight < 350)
- return QFont::Light;
- if (weight < 450)
- return QFont::Normal;
- if (weight < 550)
- return QFont::Medium;
- if (weight < 650)
- return QFont::DemiBold;
- if (weight < 750)
- return QFont::Bold;
- if (weight < 850)
- return QFont::ExtraBold;
- return QFont::Black;
-}
-
-/*!
Helper function that register the \a alias for the \a familyName.
\since 5.2
diff --git a/src/gui/text/qplatformfontdatabase.h b/src/gui/text/qplatformfontdatabase.h
index 045b3c964e..e464855bfd 100644
--- a/src/gui/text/qplatformfontdatabase.h
+++ b/src/gui/text/qplatformfontdatabase.h
@@ -131,7 +131,6 @@ public:
// helper
static QSupportedWritingSystems writingSystemsFromTrueTypeBits(quint32 unicodeRange[4], quint32 codePageRange[2]);
static QSupportedWritingSystems writingSystemsFromOS2Table(const char *os2Table, size_t length);
- static QFont::Weight weightFromInteger(int weight);
//callback
static void registerFont(const QString &familyname, const QString &stylename,
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp
index f066853792..a4ecbd157f 100644
--- a/src/gui/text/qtextdocument.cpp
+++ b/src/gui/text/qtextdocument.cpp
@@ -2308,7 +2308,7 @@ QString QTextHtmlExporter::toHtml(ExportMode mode)
}
html += QLatin1String(" font-weight:");
- html += QString::number(defaultCharFormat.fontWeight() * 8);
+ html += QString::number(defaultCharFormat.fontWeight());
html += QLatin1Char(';');
html += QLatin1String(" font-style:");
@@ -2421,7 +2421,7 @@ bool QTextHtmlExporter::emitCharFormatStyle(const QTextCharFormat &format)
if (format.hasProperty(QTextFormat::FontWeight)
&& format.fontWeight() != defaultCharFormat.fontWeight()) {
html += QLatin1String(" font-weight:");
- html += QString::number(format.fontWeight() * 8);
+ html += QString::number(format.fontWeight());
html += QLatin1Char(';');
attributesEmitted = true;
}
diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp
index faf1765219..043a5c9102 100644
--- a/src/gui/text/qtextformat.cpp
+++ b/src/gui/text/qtextformat.cpp
@@ -375,7 +375,7 @@ void QTextFormatPrivate::recalcFont() const
const QVariant weightValue = props.at(i).value;
int weight = weightValue.toInt();
if (weight >= 0 && weightValue.isValid())
- f.setWeight(weight);
+ f.setWeight(QFont::Weight(weight));
break; }
case QTextFormat::FontItalic:
f.setItalic(props.at(i).value.toBool());
diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp
index ef51c967b0..953c05c74c 100644
--- a/src/gui/text/qtextodfwriter.cpp
+++ b/src/gui/text/qtextodfwriter.cpp
@@ -681,7 +681,7 @@ void QTextOdfWriter::writeCharacterFormat(QXmlStreamWriter &writer, QTextCharFor
if (format.fontWeight() == QFont::Bold)
value = QString::fromLatin1("bold");
else
- value = QString::number(format.fontWeight() * 10);
+ value = QString::number(format.fontWeight());
writer.writeAttribute(foNS, QString::fromLatin1("font-weight"), value);
}
if (format.hasProperty(QTextFormat::FontFamily))
diff --git a/src/gui/text/unix/qfontconfigdatabase.cpp b/src/gui/text/unix/qfontconfigdatabase.cpp
index f54af2e59e..a8e28618f4 100644
--- a/src/gui/text/unix/qfontconfigdatabase.cpp
+++ b/src/gui/text/unix/qfontconfigdatabase.cpp
@@ -65,8 +65,6 @@
QT_BEGIN_NAMESPACE
-static const int maxWeight = 99;
-
static inline int mapToQtWeightForRange(int fcweight, int fcLower, int fcUpper, int qtLower, int qtUpper)
{
return qtLower + ((fcweight - fcLower) * (qtUpper - qtLower)) / (fcUpper - fcLower);
@@ -75,7 +73,7 @@ static inline int mapToQtWeightForRange(int fcweight, int fcLower, int fcUpper,
static inline int weightFromFcWeight(int fcweight)
{
// Font Config uses weights from 0 to 215 (the highest enum value) while QFont ranges from
- // 0 to 99. The spacing between the values for the enums are uneven so a linear mapping from
+ // 1 to 1000. The spacing between the values for the enums are uneven so a linear mapping from
// Font Config values to Qt would give surprising results. So, we do a piecewise linear
// mapping. This ensures that where there is a corresponding enum on both sides (for example
// FC_WEIGHT_DEMIBOLD and QFont::DemiBold) we map one to the other but other values map
@@ -100,8 +98,9 @@ static inline int weightFromFcWeight(int fcweight)
if (fcweight <= FC_WEIGHT_BLACK)
return mapToQtWeightForRange(fcweight, FC_WEIGHT_ULTRABOLD, FC_WEIGHT_BLACK, QFont::ExtraBold, QFont::Black);
if (fcweight <= FC_WEIGHT_ULTRABLACK)
- return mapToQtWeightForRange(fcweight, FC_WEIGHT_BLACK, FC_WEIGHT_ULTRABLACK, QFont::Black, maxWeight);
- return maxWeight;
+ return mapToQtWeightForRange(fcweight, FC_WEIGHT_BLACK, FC_WEIGHT_ULTRABLACK, QFont::Black,
+ QFONT_WEIGHT_MAX);
+ return QFONT_WEIGHT_MAX;
}
static inline int stretchFromFcWidth(int fcwidth)
diff --git a/src/gui/text/windows/qwindowsdirectwritefontdatabase.cpp b/src/gui/text/windows/qwindowsdirectwritefontdatabase.cpp
index 6033e8aeb9..c0d9e820c6 100644
--- a/src/gui/text/windows/qwindowsdirectwritefontdatabase.cpp
+++ b/src/gui/text/windows/qwindowsdirectwritefontdatabase.cpp
@@ -100,7 +100,7 @@ static QFont::Stretch fromDirectWriteStretch(DWRITE_FONT_STRETCH stretch)
static QFont::Weight fromDirectWriteWeight(DWRITE_FONT_WEIGHT weight)
{
- return QPlatformFontDatabase::weightFromInteger(int(weight));
+ return static_cast<QFont::Weight>(weight);
}
static DWRITE_FONT_STYLE toDirectWriteStyle(QFont::Style style)
diff --git a/src/gui/text/windows/qwindowsfontdatabase.cpp b/src/gui/text/windows/qwindowsfontdatabase.cpp
index 003d61d805..f180e91e97 100644
--- a/src/gui/text/windows/qwindowsfontdatabase.cpp
+++ b/src/gui/text/windows/qwindowsfontdatabase.cpp
@@ -526,7 +526,7 @@ static bool addFontToDatabase(QString familyName,
const int size = scalable ? SMOOTH_SCALABLE : textmetric->tmHeight;
const QFont::Style style = textmetric->tmItalic ? QFont::StyleItalic : QFont::StyleNormal;
const bool antialias = false;
- const QFont::Weight weight = QPlatformFontDatabase::weightFromInteger(textmetric->tmWeight);
+ const QFont::Weight weight = static_cast<QFont::Weight>(textmetric->tmWeight);
const QFont::Stretch stretch = QFont::Unstretched;
#ifndef QT_NO_DEBUG_OUTPUT
@@ -995,7 +995,7 @@ QStringList QWindowsFontDatabase::addApplicationFont(const QByteArray &fontData,
if (applicationFont != nullptr) {
QFontDatabasePrivate::ApplicationFont::Properties properties;
properties.style = values.isItalic ? QFont::StyleItalic : QFont::StyleNormal;
- properties.weight = QPlatformFontDatabase::weightFromInteger(values.weight);
+ properties.weight = static_cast<int>(values.weight);
properties.familyName = familyName;
properties.styleName = styleName;
@@ -1042,7 +1042,7 @@ QStringList QWindowsFontDatabase::addApplicationFont(const QByteArray &fontData,
QFontDatabasePrivate::ApplicationFont::Properties properties;
properties.style = values.isItalic ? QFont::StyleItalic : QFont::StyleNormal;
- properties.weight = QPlatformFontDatabase::weightFromInteger(values.weight);
+ properties.weight = static_cast<int>(values.weight);
properties.familyName = familyName;
properties.styleName = styleName;
diff --git a/src/gui/text/windows/qwindowsfontdatabase_ft.cpp b/src/gui/text/windows/qwindowsfontdatabase_ft.cpp
index a576302dda..91d3b5b74d 100644
--- a/src/gui/text/windows/qwindowsfontdatabase_ft.cpp
+++ b/src/gui/text/windows/qwindowsfontdatabase_ft.cpp
@@ -187,7 +187,7 @@ static bool addFontToDatabase(QString familyName,
const int size = scalable ? SMOOTH_SCALABLE : textmetric->tmHeight;
const QFont::Style style = textmetric->tmItalic ? QFont::StyleItalic : QFont::StyleNormal;
const bool antialias = false;
- const QFont::Weight weight = QPlatformFontDatabase::weightFromInteger(textmetric->tmWeight);
+ const QFont::Weight weight = static_cast<QFont::Weight>(textmetric->tmWeight);
const QFont::Stretch stretch = QFont::Unstretched;
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/gui/text/windows/qwindowsfontdatabasebase.cpp b/src/gui/text/windows/qwindowsfontdatabasebase.cpp
index 52149d3b8f..9a7c1c3578 100644
--- a/src/gui/text/windows/qwindowsfontdatabasebase.cpp
+++ b/src/gui/text/windows/qwindowsfontdatabasebase.cpp
@@ -226,7 +226,7 @@ void QWindowsFontDatabaseBase::EmbeddedFont::updateFromOS2Table(QFontEngine *fon
else
fontEngine->fontDef.style = QFont::StyleNormal;
- fontEngine->fontDef.weight = QPlatformFontDatabase::weightFromInteger(qFromBigEndian<quint16>(os2Table->weightClass));
+ fontEngine->fontDef.weight = qFromBigEndian<quint16>(os2Table->weightClass);
}
}
@@ -642,10 +642,10 @@ LOGFONT QWindowsFontDatabaseBase::fontDefToLOGFONT(const QFontDef &request, cons
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
- if (request.weight == 50)
+ if (request.weight == QFont::Normal)
lf.lfWeight = FW_DONTCARE;
else
- lf.lfWeight = (request.weight*900)/99;
+ lf.lfWeight = request.weight;
lf.lfItalic = request.style != QFont::StyleNormal;
lf.lfCharSet = DEFAULT_CHARSET;
@@ -735,7 +735,7 @@ QFont QWindowsFontDatabaseBase::LOGFONT_to_QFont(const LOGFONT& logFont, int ver
QFont qFont(QString::fromWCharArray(logFont.lfFaceName));
qFont.setItalic(logFont.lfItalic);
if (logFont.lfWeight != FW_DONTCARE)
- qFont.setWeight(QPlatformFontDatabase::weightFromInteger(logFont.lfWeight));
+ qFont.setWeight(QFont::Weight(logFont.lfWeight));
const qreal logFontHeight = qAbs(logFont.lfHeight);
qFont.setPointSizeF(logFontHeight * 72.0 / qreal(verticalDPI_In));
qFont.setUnderline(logFont.lfUnderline);
diff --git a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp
index 65564b59a1..258c4305ff 100644
--- a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp
+++ b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp
@@ -575,8 +575,7 @@ static QFont qt_fontFromString(const QString &name)
if (!family.isEmpty())
font.setFamily(family);
- const int weight = pango_font_description_get_weight(desc);
- font.setWeight(QPlatformFontDatabase::weightFromInteger(weight));
+ font.setWeight(QFont::Weight(pango_font_description_get_weight(desc)));
PangoStyle style = pango_font_description_get_style(desc);
if (style == PANGO_STYLE_ITALIC)
diff --git a/src/tools/uic/cpp/cppwriteinitialization.cpp b/src/tools/uic/cpp/cppwriteinitialization.cpp
index 29c054bc22..2a3c9bdd70 100644
--- a/src/tools/uic/cpp/cppwriteinitialization.cpp
+++ b/src/tools/uic/cpp/cppwriteinitialization.cpp
@@ -1623,8 +1623,57 @@ QString WriteInitialization::writeFontProperties(const DomFont *f)
<< language::boolValue(f->elementUnderline()) << ')' << language::eol;
}
if (f->hasElementWeight() && f->elementWeight() > 0) {
- m_output << m_indent << fontName << ".setWeight("
- << f->elementWeight() << ")" << language::eol;
+ int weight = f->elementWeight();
+ if (!f->hasAttributeScale()) {
+ // Convert from old Qt scale to OpenType scale.
+ // (not a linear conversion, so we adapt the known values and approximate the others).
+ // Note that we cannot use qt_legacyToOpenTypeWeight from qfont_p.h here due to
+ // dependency issues.
+
+ switch (f->elementWeight()) {
+ case 0:
+ weight = 100;
+ break;
+ case 12:
+ weight = 200;
+ break;
+ case 25:
+ weight = 300;
+ break;
+ case 50:
+ weight = 400;
+ break;
+ case 57:
+ weight = 500;
+ break;
+ case 63:
+ weight = 600;
+ break;
+ case 75:
+ weight = 700;
+ break;
+ case 81:
+ weight = 800;
+ break;
+ case 87:
+ weight = 900;
+ break;
+ default:
+ weight *= 8;
+ weight += 100;
+ break;
+ }
+ }
+
+ switch (language::language()) {
+ case Language::Cpp:
+ m_output << m_indent << fontName << ".setWeight(QFont::Weight(" << weight << "))"
+ << language::eol;
+ break;
+ case Language::Python:
+ m_output << m_indent << fontName << ".setWeight(" << weight << ")" << language::eol;
+ break;
+ }
}
if (f->hasElementStrikeOut()) {
m_output << m_indent << fontName << ".setStrikeOut("
diff --git a/src/tools/uic/ui4.cpp b/src/tools/uic/ui4.cpp
index a155df9b6c..8a535582b9 100644
--- a/src/tools/uic/ui4.cpp
+++ b/src/tools/uic/ui4.cpp
@@ -3099,6 +3099,16 @@ DomFont::~DomFont() = default;
void DomFont::read(QXmlStreamReader &reader)
{
+ const QXmlStreamAttributes &attributes = reader.attributes();
+ for (const QXmlStreamAttribute &attribute : attributes) {
+ const auto name = attribute.name();
+ if (name == QLatin1String("scale")) {
+ setAttributeScale(attribute.value().toString());
+ continue;
+ }
+ reader.raiseError(QLatin1String("Unexpected attribute ") + name);
+ }
+
while (!reader.hasError()) {
switch (reader.readNext()) {
case QXmlStreamReader::StartElement : {
@@ -3158,6 +3168,9 @@ void DomFont::write(QXmlStreamWriter &writer, const QString &tagName) const
{
writer.writeStartElement(tagName.isEmpty() ? QStringLiteral("font") : tagName.toLower());
+ if (hasAttributeScale())
+ writer.writeAttribute(QStringLiteral("scale"), attributeScale());
+
if (m_children & Family)
writer.writeTextElement(QStringLiteral("family"), m_family);
diff --git a/src/tools/uic/ui4.h b/src/tools/uic/ui4.h
index a5ac51f521..41f11644bd 100644
--- a/src/tools/uic/ui4.h
+++ b/src/tools/uic/ui4.h
@@ -1619,6 +1619,16 @@ public:
void read(QXmlStreamReader &reader);
void write(QXmlStreamWriter &writer, const QString &tagName = QString()) const;
+ // attribute accessors
+ inline bool hasAttributeScale() const { return m_has_attr_scale; }
+ inline QString attributeScale() const { return m_attr_scale; }
+ inline void setAttributeScale(const QString &a)
+ {
+ m_attr_scale = a;
+ m_has_attr_scale = true;
+ }
+ inline void clearAttributeScale() { m_has_attr_scale = false; }
+
// child element accessors
inline QString elementFamily() const { return m_family; }
void setElementFamily(const QString &a);
@@ -1671,6 +1681,9 @@ public:
void clearElementKerning();
private:
+ // attribute data
+ QString m_attr_scale;
+ bool m_has_attr_scale = false;
// child element data
uint m_children = 0;
diff --git a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
index 4983db579a..382f17d519 100644
--- a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
+++ b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
@@ -334,7 +334,7 @@ void tst_QGuiVariant::toFont_data()
QTest::addColumn<QFont>("result");
QFont f("times",12,-1,false);
- QTest::newRow( "string" ) << QVariant( QString( "times,12,-1,5,50,0,0,0,0,0" ) ) << f;
+ QTest::newRow( "string" ) << QVariant( QString( "times,12,-1,5,400,0,0,0,0,0" ) ) << f;
}
void tst_QGuiVariant::toFont()
@@ -384,7 +384,7 @@ void tst_QGuiVariant::toString_data()
#endif
QFont font( "times", 12 );
- QTest::newRow("qfont") << QVariant::fromValue(font) << QString("times,12,-1,5,50,0,0,0,0,0,0,0,0,0,0,1");
+ QTest::newRow("qfont") << QVariant::fromValue(font) << QString("times,12,-1,5,400,0,0,0,0,0,0,0,0,0,0,1");
QTest::newRow( "qcolor" ) << QVariant::fromValue( QColor( 10, 10, 10 ) ) << QString( "#0a0a0a" );
}
diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp
index 5e4fdfcdc9..93fcd71bb6 100644
--- a/tests/auto/gui/text/qfont/tst_qfont.cpp
+++ b/tests/auto/gui/text/qfont/tst_qfont.cpp
@@ -425,7 +425,7 @@ void tst_QFont::serialize_data()
QTest::newRow("stretch") << font << QDataStream::Qt_4_3;
font = basicFont;
- font.setWeight(99);
+ font.setWeight(QFont::Light);
QTest::newRow("weight") << font << QDataStream::Qt_1_0;
font = basicFont;
@@ -591,7 +591,7 @@ void tst_QFont::toAndFromString()
// Since Qt 6.0 it was changed to include more information in the description, so
// this checks for compatibility
- const QString fontStringFrom515(QLatin1String("Times New Roman,18,-1,5,75,1,0,0,1,0,Regular"));
+ const QString fontStringFrom515(QLatin1String("Times New Roman,18,-1,5,700,1,0,0,1,0,Regular"));
QFont fontFrom515("Times New Roman", 18);
fontFrom515.setBold(true);
fontFrom515.setItalic(true);
@@ -601,7 +601,8 @@ void tst_QFont::toAndFromString()
from515String.fromString(fontStringFrom515);
QCOMPARE(from515String, fontFrom515);
- const QString fontStringFrom60(QLatin1String("Times New Roman,18,-1,5,75,1,0,0,1,0,1,0,150.5,2.5,50,2,Regular"));
+ const QString fontStringFrom60(
+ QLatin1String("Times New Roman,18,-1,5,700,1,0,0,1,0,1,0,150.5,2.5,50,2,Regular"));
QFont fontFrom60 = fontFrom515;
fontFrom60.setStyleStrategy(QFont::PreferBitmap);
fontFrom60.setCapitalization(QFont::AllUppercase);
@@ -617,17 +618,18 @@ void tst_QFont::toAndFromString()
void tst_QFont::fromStringWithoutStyleName()
{
QFont font1;
- font1.fromString("Noto Sans,12,-1,5,50,0,0,0,0,0,Regular");
+ font1.fromString("Noto Sans,12,-1,5,400,0,0,0,0,0,Regular");
QFont font2 = font1;
- const QString str = "Times,16,-1,5,50,0,0,0,0,0,0,0,0,0,0,1";
+ const QString str = "Times,16,-1,5,400,0,0,0,0,0,0,0,0,0,0,1";
font2.fromString(str);
QCOMPARE(font2.toString(), str);
- const QString fontStringFrom60(QLatin1String("Times New Roman,18,-1,5,75,1,0,0,1,0,1,0,150.5,2.5,50,2"));
+ const QString fontStringFrom60(
+ QLatin1String("Times New Roman,18,-1,5,700,1,0,0,1,0,1,0,150.5,2.5,50,2"));
QFont font3;
- font3.fromString("Noto Sans,12,-1,5,50,0,0,0,0,0,Regular");
+ font3.fromString("Noto Sans,12,-1,5,400,0,0,0,0,0,Regular");
QFont font4 = font3;
font4.fromString(fontStringFrom60);
QCOMPARE(font4.toString(), fontStringFrom60);
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
index 4e51ccea43..04f8a9aa38 100644
--- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
@@ -285,11 +285,10 @@ void tst_QTextDocument::init()
"p, li { white-space: pre-wrap; }\n"
"</style></head>"
"<body style=\" font-family:'%1'; font-size:%2; font-weight:%3; font-style:%4;\">\n");
- htmlHead = htmlHead
- .arg(defaultFont.family())
- .arg(cssFontSizeString(defaultFont))
- .arg(defaultFont.weight() * 8)
- .arg((defaultFont.italic() ? "italic" : "normal"));
+ htmlHead = htmlHead.arg(defaultFont.family())
+ .arg(cssFontSizeString(defaultFont))
+ .arg(defaultFont.weight())
+ .arg((defaultFont.italic() ? "italic" : "normal"));
htmlTail = QString("</body></html>");
}
@@ -999,7 +998,7 @@ void tst_QTextDocument::toHtml_data()
CREATE_DOC_AND_CURSOR();
QTextCharFormat fmt;
- fmt.setFontWeight(40);
+ fmt.setFontWeight(320);
cursor.insertText("Blah", fmt);
QTest::newRow("font-weight") << QTextDocumentFragment(&doc)
@@ -1854,11 +1853,10 @@ void tst_QTextDocument::toHtmlBodyBgColor()
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
"</body></html>");
- expectedHtml = expectedHtml
- .arg(defaultFont.family())
- .arg(cssFontSizeString(defaultFont))
- .arg(defaultFont.weight() * 8)
- .arg((defaultFont.italic() ? "italic" : "normal"));
+ expectedHtml = expectedHtml.arg(defaultFont.family())
+ .arg(cssFontSizeString(defaultFont))
+ .arg(defaultFont.weight())
+ .arg((defaultFont.italic() ? "italic" : "normal"));
QCOMPARE(doc.toHtml(), expectedHtml);
}
@@ -1884,9 +1882,9 @@ void tst_QTextDocument::toHtmlBodyBgColorRgba()
"</body></html>");
expectedHtml = expectedHtml.arg(defaultFont.family())
- .arg(cssFontSizeString(defaultFont))
- .arg(defaultFont.weight() * 8)
- .arg((defaultFont.italic() ? "italic" : "normal"));
+ .arg(cssFontSizeString(defaultFont))
+ .arg(defaultFont.weight())
+ .arg((defaultFont.italic() ? "italic" : "normal"));
QCOMPARE(doc.toHtml(), expectedHtml);
}
@@ -1911,11 +1909,10 @@ void tst_QTextDocument::toHtmlBodyBgColorTransparent()
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
"</body></html>");
- expectedHtml = expectedHtml
- .arg(defaultFont.family())
- .arg(cssFontSizeString(defaultFont))
- .arg(defaultFont.weight() * 8)
- .arg((defaultFont.italic() ? "italic" : "normal"));
+ expectedHtml = expectedHtml.arg(defaultFont.family())
+ .arg(cssFontSizeString(defaultFont))
+ .arg(defaultFont.weight())
+ .arg((defaultFont.italic() ? "italic" : "normal"));
QCOMPARE(doc.toHtml(), expectedHtml);
}
@@ -1989,7 +1986,7 @@ void tst_QTextDocument::toHtmlDefaultFontSpacingProperties()
"</body></html>");
expectedOutput = expectedOutput.arg(defaultFont.family())
.arg(cssFontSizeString(defaultFont))
- .arg(defaultFont.weight() * 8)
+ .arg(defaultFont.weight())
.arg((defaultFont.italic() ? "italic" : "normal"));
QCOMPARE(doc.toHtml(), expectedOutput);
@@ -2615,10 +2612,11 @@ void tst_QTextDocument::html_defaultFont()
doc->setDefaultFont(f);
doc->setPlainText("Test");
- QString bodyPart = QString::fromLatin1("<body style=\" font-family:'%1'; font-size:%2; font-weight:%3; font-style:italic;\">")
- .arg(f.family())
- .arg(cssFontSizeString(f))
- .arg(f.weight() * 8);
+ QString bodyPart = QString::fromLatin1("<body style=\" font-family:'%1'; font-size:%2; "
+ "font-weight:%3; font-style:italic;\">")
+ .arg(f.family())
+ .arg(cssFontSizeString(f))
+ .arg(f.weight());
QString html = doc->toHtml();
if (!html.contains(bodyPart)) {
@@ -2760,11 +2758,10 @@ void tst_QTextDocument::backgroundImage_checkExpectedHtml(const QTextDocument &d
"\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
"</td></tr></table></body></html>");
- expectedHtml = expectedHtml
- .arg(defaultFont.family())
- .arg(cssFontSizeString(defaultFont))
- .arg(defaultFont.weight() * 8)
- .arg((defaultFont.italic() ? "italic" : "normal"));
+ expectedHtml = expectedHtml.arg(defaultFont.family())
+ .arg(cssFontSizeString(defaultFont))
+ .arg(defaultFont.weight())
+ .arg((defaultFont.italic() ? "italic" : "normal"));
writeActualAndExpected(QTest::currentTestFunction(), doc.toHtml(), expectedHtml);
diff --git a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
index 3b4c55d406..159effbd8f 100644
--- a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
+++ b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
@@ -2427,7 +2427,7 @@ void tst_QTextDocumentFragment::defaultFont()
doc->setDefaultFont(f);
doc->setPlainText("Hello World");
const QString html = doc->toHtml();
- QLatin1String str("<body style=\" font-family:'Courier New'; font-size:100pt; font-weight:600; font-style:italic;\">");
+ QLatin1String str("<body style=\" font-family:'Courier New'; font-size:100pt; font-weight:700; font-style:italic;\">");
QVERIFY(html.contains(str));
}
@@ -2756,7 +2756,7 @@ void tst_QTextDocumentFragment::css_fontWeight()
{
setHtml("<p style=\"font-weight:bold\">blah</p>");
QCOMPARE(doc->begin().charFormat().fontWeight(), int(QFont::Bold));
- setHtml("<p style=\"font-weight:600\">blah</p>");
+ setHtml("<p style=\"font-weight:700\">blah</p>");
QCOMPARE(doc->begin().charFormat().fontWeight(), int(QFont::Bold));
}
diff --git a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
index 474b2def60..bc9dc1b695 100644
--- a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
+++ b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
@@ -326,7 +326,7 @@ void tst_QTextMarkdownImporter::nestedSpans()
<< "monospace" << QFontInfo(fmt.font()).fixedPitch() // depends on installed fonts (QTBUG-75649)
<< fmt.fontFixedPitch() // returns false even when font family is "monospace"
<< fmt.hasProperty(QTextFormat::FontFixedPitch); // works
- QCOMPARE(fmt.fontWeight() > 50, expectedFormat.testFlag(Bold));
+ QCOMPARE(fmt.fontWeight() > QFont::Normal, expectedFormat.testFlag(Bold));
QCOMPARE(fmt.fontItalic(), expectedFormat.testFlag(Italic));
QCOMPARE(fmt.fontStrikeOut(), expectedFormat.testFlag(Strikeout));
QCOMPARE(fmt.isAnchor(), expectedFormat.testFlag(Link));
diff --git a/tests/auto/other/lancelot/scripts/gradientxform_device.qps b/tests/auto/other/lancelot/scripts/gradientxform_device.qps
index 82ebb536bb..cd8b55d5b6 100644
--- a/tests/auto/other/lancelot/scripts/gradientxform_device.qps
+++ b/tests/auto/other/lancelot/scripts/gradientxform_device.qps
@@ -24,7 +24,7 @@ setPen brush 30
setBrush lightblue
drawRect 175 15 70 70
-setFont "times" 110 99
+setFont "times" 110 1000
drawText 270 100 "X"
restore
diff --git a/tests/auto/other/lancelot/scripts/gradientxform_logical.qps b/tests/auto/other/lancelot/scripts/gradientxform_logical.qps
index 1bb157b635..1bba63a929 100644
--- a/tests/auto/other/lancelot/scripts/gradientxform_logical.qps
+++ b/tests/auto/other/lancelot/scripts/gradientxform_logical.qps
@@ -24,7 +24,7 @@ setPen brush 30
setBrush lightblue
drawRect 175 15 70 70
-setFont "times" 110 99
+setFont "times" 110 1000
drawText 270 100 "X"
restore
diff --git a/tests/auto/other/lancelot/scripts/gradientxform_object.qps b/tests/auto/other/lancelot/scripts/gradientxform_object.qps
index dcc718072f..e34da24d46 100644
--- a/tests/auto/other/lancelot/scripts/gradientxform_object.qps
+++ b/tests/auto/other/lancelot/scripts/gradientxform_object.qps
@@ -26,7 +26,7 @@ translate 110 0
drawRect 65 15 70 70
translate 110 0
-setFont "times" 110 99
+setFont "times" 110 1000
drawText 50 100 "X"
restore
diff --git a/tests/auto/tools/uic/baseline/authenticationdialog.ui.h b/tests/auto/tools/uic/baseline/authenticationdialog.ui.h
index 1d475005bf..3ff68e25e3 100644
--- a/tests/auto/tools/uic/baseline/authenticationdialog.ui.h
+++ b/tests/auto/tools/uic/baseline/authenticationdialog.ui.h
@@ -84,7 +84,7 @@ public:
siteDescription->setObjectName(QString::fromUtf8("siteDescription"));
QFont font;
font.setBold(true);
- font.setWeight(75);
+ font.setWeight(QFont::Weight(700));
siteDescription->setFont(font);
siteDescription->setWordWrap(true);