From 25c1820914c4b336042daf2d2c79c92453d51e7e Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Tue, 21 Mar 2023 15:51:17 +0800 Subject: [PATCH 1/2] qt6.qtbase: add patch to fix handling of variable fonts --- pkgs/development/libraries/qt-6/default.nix | 1 + .../qt-6/patches/qtbase-variable-fonts.patch | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 pkgs/development/libraries/qt-6/patches/qtbase-variable-fonts.patch diff --git a/pkgs/development/libraries/qt-6/default.nix b/pkgs/development/libraries/qt-6/default.nix index 2577806b5c43..f0cfc91ac014 100644 --- a/pkgs/development/libraries/qt-6/default.nix +++ b/pkgs/development/libraries/qt-6/default.nix @@ -59,6 +59,7 @@ let ./patches/qtbase-qmake-mkspecs-mac.patch ./patches/qtbase-qmake-pkg-config.patch ./patches/qtbase-tzdir.patch + ./patches/qtbase-variable-fonts.patch # Remove symlink check causing build to bail out and fail. # https://gitlab.kitware.com/cmake/cmake/-/issues/23251 (fetchpatch { diff --git a/pkgs/development/libraries/qt-6/patches/qtbase-variable-fonts.patch b/pkgs/development/libraries/qt-6/patches/qtbase-variable-fonts.patch new file mode 100644 index 000000000000..96952d1ad160 --- /dev/null +++ b/pkgs/development/libraries/qt-6/patches/qtbase-variable-fonts.patch @@ -0,0 +1,26 @@ +From 9ba9c690fb16188ff524b53def104e68e45cf5c3 Mon Sep 17 00:00:00 2001 +From: Nick Cao +Date: Tue, 21 Mar 2023 15:48:49 +0800 +Subject: [PATCH] Deal with a font face at index 0 as Regular for Variable + fonts + +Reference: https://bugreports.qt.io/browse/QTBUG-111994 +--- + src/gui/text/unix/qfontconfigdatabase.cpp | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/gui/text/unix/qfontconfigdatabase.cpp b/src/gui/text/unix/qfontconfigdatabase.cpp +index 9b60cf2963..5a42ef6a68 100644 +--- a/src/gui/text/unix/qfontconfigdatabase.cpp ++++ b/src/gui/text/unix/qfontconfigdatabase.cpp +@@ -554,6 +554,7 @@ void QFontconfigDatabase::populateFontDatabase() + FcObjectSetAdd(os, *p); + ++p; + } ++ FcPatternAddBool(pattern, FC_VARIABLE, FcFalse); + fonts = FcFontList(nullptr, pattern, os); + FcObjectSetDestroy(os); + FcPatternDestroy(pattern); +-- +2.39.2 + From f4385d6010a6de5e78f495436917431654d09410 Mon Sep 17 00:00:00 2001 From: oxalica Date: Tue, 21 Mar 2023 15:59:24 +0800 Subject: [PATCH 2/2] nixosTests.noto-fonts-cjk-qt-default-weight: init --- nixos/tests/all-tests.nix | 1 + .../noto-fonts-cjk-qt-default-weight.nix | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 nixos/tests/noto-fonts-cjk-qt-default-weight.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index ff2549395a0b..7e089801cd37 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -487,6 +487,7 @@ in { nomad = handleTest ./nomad.nix {}; non-default-filesystems = handleTest ./non-default-filesystems.nix {}; noto-fonts = handleTest ./noto-fonts.nix {}; + noto-fonts-cjk-qt-default-weight = handleTest ./noto-fonts-cjk-qt-default-weight.nix {}; novacomd = handleTestOn ["x86_64-linux"] ./novacomd.nix {}; nscd = handleTest ./nscd.nix {}; nsd = handleTest ./nsd.nix {}; diff --git a/nixos/tests/noto-fonts-cjk-qt-default-weight.nix b/nixos/tests/noto-fonts-cjk-qt-default-weight.nix new file mode 100644 index 000000000000..678013cf3ab9 --- /dev/null +++ b/nixos/tests/noto-fonts-cjk-qt-default-weight.nix @@ -0,0 +1,30 @@ +import ./make-test-python.nix ({ pkgs, lib, ... }: { + name = "noto-fonts-cjk-qt"; + meta.maintainers = with lib.maintainers; [ oxalica ]; + + nodes.machine = { + imports = [ ./common/x11.nix ]; + fonts = { + enableDefaultFonts = false; + fonts = [ pkgs.noto-fonts-cjk-sans ]; + }; + }; + + testScript = + let + script = pkgs.writers.writePython3 "qt-default-weight" { + libraries = [ pkgs.python3Packages.pyqt6 ]; + } '' + from PyQt6.QtWidgets import QApplication + from PyQt6.QtGui import QFont, QRawFont + + app = QApplication([]) + f = QRawFont.fromFont(QFont("Noto Sans CJK SC", 20)) + + assert f.styleName() == "Regular", f.styleName() + ''; + in '' + machine.wait_for_x() + machine.succeed("${script}") + ''; +})