Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-76084

QPainter ignores font weight for certain fonts

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.12.3
    • None
    • Gentoo Linux, KDE
    • Linux/X11

    Description

      When rendering text with different weights using the Source Code Pro font on Gentoo Linux, all text looks the same. On Windows and Ubuntu Linux everything is fine.

      Here is a simple demo:

      #include <QApplication>
      #include <QWidget>
      #include <QPainter>
      
      class Widget : public QWidget
      {
      protected:
          void paintEvent(QPaintEvent *)
          {
              const auto weights = {
                  QFont::Thin,
                  QFont::ExtraLight,
                  QFont::Light,
                  QFont::Normal,
                  QFont::Medium,
                  QFont::DemiBold,
                  QFont::Bold,
                  QFont::ExtraBold,
                  QFont::Black
              };
      
              QPainter p(this);
              p.fillRect(rect(), Qt::white);
              p.setPen(Qt::black);
      
              int y = 30;
              for (const auto weight : weights) {
                  QFont f("Source Code Pro", 14, weight);
                  Q_ASSERT(f.weight() == weight);
      
                  p.setFont(f);
                  p.drawText(5, y, QString("Qt Framework (%1)").arg(weight));
                  y += p.fontMetrics().height();
              }
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          Widget w;
          w.setMinimumSize(200, 300);
          w.show();
      
          return a.exec();
      }
      
      

      Additional info:

      ~> fc-match monospace
      SourceCodePro-Regular.ttf: "Source Code Pro" "Regular"
      ~> fc-match monospace:bold
      SourceCodePro-Bold.ttf: "Source Code Pro" "Bold"
      ~> fc-list 'Source Code Pro'
      /usr/share/fonts/source-code-pro/SourceCodePro-BoldIt.ttf: Source Code Pro:style=Bold Italic
      /usr/share/fonts/source-code-pro/SourceCodePro-Light.ttf: Source Code Pro,Source Code Pro Light:style=Light,Regular
      /usr/share/fonts/source-code-pro/SourceCodePro-ExtraLightIt.ttf: Source Code Pro,Source Code Pro ExtraLight:style=ExtraLight Italic,Italic
      /usr/share/fonts/source-code-pro/SourceCodePro-Bold.ttf: Source Code Pro:style=Bold
      /usr/share/fonts/source-code-pro/SourceCodePro-ExtraLight.ttf: Source Code Pro,Source Code Pro ExtraLight:style=ExtraLight,Regular
      /usr/share/fonts/source-code-pro/SourceCodePro-Black.ttf: Source Code Pro,Source Code Pro Black:style=Black,Regular
      /usr/share/fonts/source-code-pro/SourceCodePro-Semibold.ttf: Source Code Pro,Source Code Pro Semibold:style=Semibold,Regular
      /usr/share/fonts/source-code-pro/SourceCodePro-LightIt.ttf: Source Code Pro,Source Code Pro Light:style=Light Italic,Italic
      /usr/share/fonts/source-code-pro/SourceCodePro-Medium.ttf: Source Code Pro,Source Code Pro Medium:style=Medium,Regular
      /usr/share/fonts/source-code-pro/SourceCodePro-It.ttf: Source Code Pro:style=Italic
      /usr/share/fonts/source-code-pro/SourceCodePro-Regular.ttf: Source Code Pro:style=Regular
      /usr/share/fonts/source-code-pro/SourceCodePro-MediumIt.ttf: Source Code Pro,Source Code Pro Medium:style=Medium Italic,Italic
      /usr/share/fonts/source-code-pro/SourceCodePro-SemiboldIt.ttf: Source Code Pro,Source Code Pro Semibold:style=Semibold Italic,Italic
      /usr/share/fonts/source-code-pro/SourceCodePro-BlackIt.ttf: Source Code Pro,Source Code Pro Black:style=Black Italic,Italic
      ~> eselect fontconfig list | grep \*
      Available fontconfig .conf files (* is enabled):
        [5]   10-hinting-slight.conf *
        [18]  30-metric-aliases.conf *
        [19]  40-nonlatin.conf *
        [20]  45-generic.conf *
        [21]  45-latin.conf *
        [22]  49-sansserif.conf *
        [23]  50-user.conf *
        [24]  51-local.conf *
        [28]  60-generic.conf *
        [29]  60-latin.conf *
        [32]  65-nonlatin.conf *
        [37]  70-no-bitmaps.conf *
      

      Attachments

        1. gentoo.png
          gentoo.png
          26 kB
        2. win10.png
          win10.png
          33 kB
        3. ubuntu.png
          ubuntu.png
          68 kB
        4. fira_mono_font.png
          fira_mono_font.png
          39 kB

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              vgt Eirik Aavitsland
              razrfalcon Evgeniy
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes