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

QFont::DemiBold can behave differently with GDI compared to DirectWrite

    XMLWordPrintable

Details

    • Windows

    Description

      A font without any DemiBold (weight 600) style but with Normal (400) and Bold (700) styles shows the Bold one with DirectWrite, but the Normal one + DWRITE_FONT_SIMULATIONS_BOLD with GDI.

      "Times New Roman" is such a font on Windows. The following example illustrates the differences when running with fontengine=gdi vs. no options (i.e. DirectWrite is used).

      #include <QApplication>
      #include <QLabel>
      
      int main(int argc, char **argv) {
        QApplication app(argc, argv);
        QLabel lbl("BoldText");
        
        auto font = lbl.font();
        font.setFamily("Times New Roman");
        font.setWeight(QFont::DemiBold); // or QFont::Bold
        lbl.setFont(font);
      
        lbl.show();
      
        return QApplication::exec();
      }
      
      Fontengine Bold DemiBold
      GDI
      DirectWrite

      As you can see, DemiBold is thicker on GDI compared to DirectWrite. "Times New Roman" actually uses DirectWrite in all cases, even when the fontengine is GDI, because the font-face created from CreateFontFaceFromHdc has simulations (DWRITE_FONT_SIMULATIONS_BOLD).

      What's surprising is that the returned font-face claims to have a weight of 700.
      Constructing a font of weight 700 (Bold) and enabling the bold-simulation results in text that's too thick (compared to GDI):

      However, when using a font of weight 400 (Normal) and enabling the bold-simulation, the result is the same as with GDI (goal):

      Attachments

        1. gdi_demibold.png
          gdi_demibold.png
          1 kB
        2. gdi_bold.png
          gdi_bold.png
          1 kB
        3. dw_demibold.png
          dw_demibold.png
          1 kB
        4. dw_bold.png
          dw_bold.png
          1 kB
        5. dw_700_simulate_bold.png
          dw_700_simulate_bold.png
          1 kB
        6. dw_400_simulate_bold.png
          dw_400_simulate_bold.png
          1 kB

        Issue Links

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

          Activity

            People

              esabraha Eskil Abrahamsen Blomfeldt
              nerixyz Tom Fors
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes