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

Deal with a font face at index 0 as Regular for Variable fonts

    XMLWordPrintable

Details

    • Linux/Wayland, Linux/X11
    • 185add27b (dev), 1b9047498 (6.7)

    Description

      This happens on the fontconfig backend which is used on most Linux environments.
      For a short description of the problem, due to a lack of variable fonts support in Qt, Qt always deals with a font face at index 0 as Regular and this can be a problem on some variable fonts which has different styles at index 0, such as Noto CJK fonts.

      Detailed description:

      fontconfig supports variable fonts and it appears in results of FcPattern. they have a special pattern which contains variable=true. for example, let's see:

       

      $ fc-query -b /usr/share/fonts/google-noto-vf/Noto
      Sans\[wght\].ttf
      
      [...]
      Pattern has 19 elts (size 32)
              family: "Noto Sans"(s)
              familylang: "en"(s)
              slant: 0(i)(s)
              weight: [80 200](s)
              width: 100(f)(s)
              foundry: "GOOG"(s)
              file: "/usr/share/fonts/google-noto-vf/NotoSans[wght].ttf"(s)
              index: 0(i)(s)
              outline: True(s)
              scalable: True(s)
              fontversion: 131727(i)(s)
              capability: "otlayout:DFLT otlayout:cyrl otlayout:grek otlayout:latn"(s)
              fontformat: "TrueType"(s)
              decorative: False(s)
              color: False(s)
              symbol: False(s)
              variable: True(s)
              fonthashint: True(s)
              order: 0(i)(s)

       
      This is almost the same how a font metadata is recorded into fontconfig cache. as you can see, 'weight' has a range. in this case, this means this font has a weight axis. also, this doesn't have style property because it can be changed according to weight. so it isn't stored into a cache.

      Alright. let me back to the problem description.

      For the above characteristic, Qt misprocess this variable pattern and fills in blanks with default values. Unfortunately they deal with this FcPattern as Regular and then this doesn't work for some variable fonts which has non-Regular style at index 0. for example, like this:

      Pattern has 24 elts (size 32)
              family: "Noto Sans CJK JP"(s)
              familylang: "en"(s)
              style: "Thin"(s) "Regular"(s)
              stylelang: "en"(s) "en"(s)
              fullname: "Noto Sans CJK JP"(s)
              fullnamelang: "en"(s)
              slant: 0(i)(s)
              weight: 0(i)(w)
              width: 100(f)(s)
              foundry: "ADBO"(s)
              file: "/usr/share/fonts/google-noto-sans-cjk-vf-fonts/NotoSansCJK-VF.ttc"(s)
              index: 0(i)(s)
              outline: True(s)
              scalable: True(s)
              fontversion: 131334(i)(s)
              capability: "otlayout:DFLT otlayout:cyrl otlayout:grek otlayout:hang otlayout:hani otlayout:kana otlayout:latn"(s)
              fontformat: "CFF"(s)
              decorative: False(s)
              postscriptname: "NotoSansCJKjp-Thin"(s)
              color: False(s)
              symbol: False(s)
              variable: False(s)
              fonthashint: False(s)
              order: 0(i)(s)
      
      [...]
      
      Pattern has 19 elts (size 32)
              family: "Noto Sans CJK JP"(s)
              familylang: "en"(s)
              slant: 0(i)(s)
              weight: [0 210](s)
              width: 100(f)(s)
              foundry: "ADBO"(s)
              file: "/usr/share/fonts/google-noto-sans-cjk-vf-fonts/NotoSansCJK-VF.ttc"(s)
              index: 0(i)(s)
              outline: True(s)
              scalable: True(s)
              fontversion: 131334(i)(s)
              capability: "otlayout:DFLT otlayout:cyrl otlayout:grek otlayout:hang otlayout:hani otlayout:kana otlayout:latn"(s)
              fontformat: "CFF"(s)
              decorative: False(s)
              color: False(s)
              symbol: False(s)
              variable: True(s)
              fonthashint: False(s)
              order: 0(i)(s)
       

       

      Proposed Change:

      I'm not familiar with the Qt's workflow. so let me just paste the one line patch to work around:

      diff -pruN qtbase-everywhere-src-5.15.8.orig/src/platformsupport/fontdatabases/fontconfig/qfontconfigdata
      base.cpp qtbase-everywhere-src-5.15.8/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cp
      p
      --- qtbase-everywhere-src-5.15.8.orig/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cp
      p       2023-03-16 16:21:48.574489839 +0900
      +++ qtbase-everywhere-src-5.15.8/src/platformsupport/fontdatabases/fontconfig/qfontconfigdatabase.cpp   2
      023-03-17 15:58:39.312498612 +0900
      @@ -564,6 +564,7 @@ void QFontconfigDatabase::populateFontDa
                   FcObjectSetAdd(os, *p);
                   ++p;
               }
      +        FcPatternAddBool(pattern, FC_VARIABLE, FcFalse);
               fonts = FcFontList(nullptr, pattern, os);
               FcObjectSetDestroy(os);
               FcPatternDestroy(pattern); 

       

      Attachments

        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
              tagoh Akira TAGOH
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes