Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #302114: Wrong default GUI font under Windows #5791

Conversation

Spire42
Copy link
Contributor

@Spire42 Spire42 commented Mar 8, 2020

Resolves: #302114

Worked around a problem in Qt that caused MuseScore to use the wrong default GUI font on Windows. Qt 5.x and below use the deprecated function GetStockObject() with DEFAULT_GUI_FONT, which returns MS Shell Dlg 2 in 8 pt. MS Shell Dlg 2 is a virtual font that maps to Tahoma, which has not been the default Windows GUI font since 2006.

The correct way to determine the default GUI font is to call SystemParametersInfoW() with SPI_GETNONCLIENTMETRICS and use the returned lfMessageFont structure. On all versions of Windows from Windows Vista through Windows 10, this typically returns Segoe UI in 9 pt.

This problem is slated to be fixed in Qt 6. For details, see QTBUG-58610.

In the meantime, we can work around the problem by having Qt use the "QMessageBox" font instead, which is already being initialized the correct way.

There are two parts to this fix:

  1. Override Qt's detection of the default GUI font. To do this, we ask Qt for the "QMessageBox" font and then tell Qt to use that as the default GUI font as well.

  2. Detect existing settings files that have been saved with the incorrect default GUI font, and reset the incorrect font settings so that the correct font can be picked up automatically by existing MuseScore installations. Note that this will have the side effect of making the MS Shell Dlg 2 font no longer “stick” if the user explicitly selects it. However, this is a virtual placeholder font that shouldn't be explicitly selected anyway, and any users who prefer its look can always explicitly select the actual underlying font, Tahoma.

  • I signed CLA
  • I made sure the code in the PR follows the coding rules
  • I made sure the code compiles on my machine
  • I made sure there are no unnecessary changes in the code
  • I made sure the title of the PR reflects the core meaning of the issue you are solving
  • I made sure the commit message(s) contain a description and answer the question "Why do those changes fix that particular issue?" or "Why are those changes really necessary as improvements?"
  • I made sure the commit message title starts with "fix #424242:" if there is a related issue
  • I created the test (mtest, vtest, script test) to verify the changes I made

mscore/preferences.cpp Outdated Show resolved Hide resolved
mscore/preferences.cpp Outdated Show resolved Hide resolved
@Spire42 Spire42 force-pushed the #302114-wrong-default-GUI-font-under-Windows branch from 2d5f165 to 0d77752 Compare March 8, 2020 10:05
mscore/preferences.cpp Outdated Show resolved Hide resolved
@Spire42 Spire42 force-pushed the #302114-wrong-default-GUI-font-under-Windows branch from 0d77752 to e9d9fce Compare March 9, 2020 01:10
Worked around a problem in Qt that caused MuseScore to use the wrong default GUI font on Windows. Qt 5.x and below use the deprecated function GetStockObject() with DEFAULT_GUI_FONT, which returns MS Shell Dlg 2 in 8 pt. MS Shell Dlg 2 is a virtual font that maps to Tahoma, which has not been the default Windows GUI font since 2006.

The correct way to determine the default GUI font is to call SystemParametersInfoW() with SPI_GETNONCLIENTMETRICS and use the returned lfMessageFont structure. On all versions of Windows from Windows Vista through Windows 10, this typically returns Segoe UI in 9 pt.

This problem is slated to be fixed in Qt 6, For details, see: https://bugreports.qt.io/browse/QTBUG-58610

In the meantime, we can work around the problem by having Qt use the "QMessageBox" font instead, which is already being initialized the correct way.

There are two parts to this fix:

1. Override Qt's detection of the default GUI font. To do this, we ask Qt for the "QMessageBox" font and then tell Qt to use that as the default GUI font as well.

2. Detect existing settings files that have been saved with the incorrect default GUI font, and reset the incorrect font settings so that the correct font can be picked up automatically by existing MuseScore installations. Note that this will have the side effect of making the MS Shell Dlg 2 font no longer “stick” if the user explicitly selects it. However, this is a virtual placeholder font that shouldn't be explicitly selected anyway, and any users who prefer its look can always explicitly select the actual underlying font, Tahoma.
@Spire42 Spire42 force-pushed the #302114-wrong-default-GUI-font-under-Windows branch from e9d9fce to 9ddc8ce Compare March 9, 2020 17:20
@Spire42
Copy link
Contributor Author

Spire42 commented Mar 9, 2020

I did some more digging and I found a better workaround.

It turns out that there's already an existing code path in the Qt codebase that's initializing fonts the correct way; specifically, it's the code in QWindowsTheme::refreshFonts() that initializes the default fonts for specific classes, such as QMessageBox. So all we need to do is ask Qt for the "QMessageBox" font and then tell Qt to use that as the default GUI font as well. This has the exact same result as doing it manually ourselves.

I've just updated the code in this PR with this better workaround.

@Spire42 Spire42 closed this Mar 15, 2020
@Spire42 Spire42 deleted the #302114-wrong-default-GUI-font-under-Windows branch March 15, 2020 17:42
@Spire42
Copy link
Contributor Author

Spire42 commented Mar 15, 2020

Refiled as #5820.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants