OSDN Git Service

de-duplicate QFontDatabase code
authorIvailo Monev <xakepa10@gmail.com>
Sat, 19 Nov 2022 01:48:13 +0000 (03:48 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Sat, 19 Nov 2022 01:48:13 +0000 (03:48 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/gui/text/qfontdatabase.cpp
src/gui/text/qfontdatabase_p.h

index be98aed..3bf7209 100644 (file)
@@ -74,6 +74,10 @@ static inline bool isStyleMatch(const QString &style, const QString &otherstyle)
     return false;
 }
 
+static inline bool isWeightBold(const int weight)
+{
+    return (weight >= FC_WEIGHT_BOLD); // or FC_WEIGHT_DEMIBOLD?
+}
 
 static double qt_pixelSize(double pointSize, int dpi)
 {
@@ -668,7 +672,6 @@ QFontDatabase::QFontDatabase()
         fontfamily.style = QString::fromUtf8((const char *)style_value);
         fontfamily.fixedpitch = (spacing_value >= FC_MONO);
         fontfamily.italic = (slant_value >= FC_SLANT_ITALIC);
-        fontfamily.bold = (weight_value >= FC_WEIGHT_BOLD); // or FC_WEIGHT_DEMIBOLD?
         fontfamily.weight = weight_value;
         fontfamily.pixelsize = pixelsize_value;
         fontfamily.preference = -weight_value;
@@ -856,7 +859,6 @@ bool QFontDatabase::isScalable(const QString &family, const QString &style) cons
 }
 
 /*!
-    \fn QList<int> QFontDatabase::pointSizes(const QString &family, const QString &style)
     Returns a list of the point sizes available for the font with the
     given \a family and \a style. The list may be empty.
 
@@ -864,6 +866,19 @@ bool QFontDatabase::isScalable(const QString &family, const QString &style) cons
 */
 QList<int> QFontDatabase::pointSizes(const QString &family, const QString &style)
 {
+    return smoothSizes(family, style);
+}
+
+/*!
+    Returns the point sizes of a font with the given \a family and \a style
+    that will look attractive. The list may be empty.
+    For non-scalable fonts and bitmap scalable fonts, this function
+    is equivalent to pointSizes().
+
+    \sa pointSizes(), standardSizes()
+*/
+QList<int> QFontDatabase::smoothSizes(const QString &family, const QString &style)
+{
     QString parsedfamily, parsedfoundry;
     QFontDatabasePrivate::parseFontName(family, parsedfoundry, parsedfamily);
 
@@ -906,7 +921,7 @@ QFont QFontDatabase::font(const QString &family, const QString &style,
 
         result = QFont(fontfamily.family, pointSize, fontfamily.weight, fontfamily.italic);
         result.setStyleName(fontfamily.style);
-        result.setBold(fontfamily.bold);
+        result.setBold(isWeightBold(fontfamily.weight));
         result.setFixedPitch(fontfamily.fixedpitch);
         if (fontfamily.pixelsize != -1) {
             result.setPixelSize(fontfamily.pixelsize);
@@ -917,35 +932,6 @@ QFont QFontDatabase::font(const QString &family, const QString &style,
 }
 
 /*!
-    \fn QList<int> QFontDatabase::smoothSizes(const QString &family, const QString &style)
-    Returns the point sizes of a font with the given \a family and \a style
-    that will look attractive. The list may be empty.
-    For non-scalable fonts and bitmap scalable fonts, this function
-    is equivalent to pointSizes().
-
-  \sa pointSizes(), standardSizes()
-*/
-QList<int> QFontDatabase::smoothSizes(const QString &family, const QString &style)
-{
-    QString parsedfamily, parsedfoundry;
-    QFontDatabasePrivate::parseFontName(family, parsedfoundry, parsedfamily);
-
-    const QString familyalias = QFontDatabasePrivate::resolveFontFamilyAlias(parsedfamily);
-
-    QList<int> result;
-    foreach (const QFontFamily &fontfamily, d_ptr->fontfamilies) {
-        if (fontfamily.family.compare(familyalias, Qt::CaseInsensitive) != 0
-            || (!parsedfoundry.isEmpty() && fontfamily.foundry.compare(parsedfoundry, Qt::CaseInsensitive) != 0)
-            || (!style.isEmpty() && !isStyleMatch(fontfamily.style, style))) {
-            continue;
-        }
-        result = standardSizes();
-        break;
-    }
-    return result;
-}
-
-/*!
     Returns true if the font that has family \a family and style \a
     style is italic; otherwise returns false.
 
@@ -980,25 +966,9 @@ bool QFontDatabase::italic(const QString &family, const QString &style) const
 */
 bool QFontDatabase::bold(const QString &family, const QString &style) const
 {
-    QString parsedfamily, parsedfoundry;
-    QFontDatabasePrivate::parseFontName(family, parsedfoundry, parsedfamily);
-
-    const QString familyalias = QFontDatabasePrivate::resolveFontFamilyAlias(parsedfamily);
-
-    bool result = false;
-    foreach (const QFontFamily &fontfamily, d_ptr->fontfamilies) {
-        if (fontfamily.family.compare(familyalias, Qt::CaseInsensitive) != 0
-            || (!parsedfoundry.isEmpty() && fontfamily.foundry.compare(parsedfoundry, Qt::CaseInsensitive) != 0)
-            || (!style.isEmpty() && !isStyleMatch(fontfamily.style, style))) {
-            continue;
-        }
-        result = fontfamily.bold;
-        break;
-    }
-    return result;
+    return isWeightBold(weight(family, style));
 }
 
-
 /*!
     Returns the weight of the font that has family \a family and style
     \a style. If there is no such family and style combination,
index 79c0282..690539e 100644 (file)
@@ -45,7 +45,6 @@ struct QFontFamily
     QString style;
     bool fixedpitch;
     bool italic;
-    bool bold;
     int weight;
     double pixelsize;